devstar插件

This commit is contained in:
2025-07-26 16:40:29 +08:00
commit 30033daafe
4387 changed files with 1041101 additions and 0 deletions

2
node_modules/preact/hooks/dist/hooks.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
var n,t,r,u,o=require("preact"),i=0,f=[],c=o.options,e=c.__b,a=c.__r,v=c.diffed,s=c.__c,l=c.unmount,p=c.__;function x(n,r){c.__h&&c.__h(t,n,i||r),i=0;var u=t.__H||(t.__H={__:[],__h:[]});return n>=u.__.length&&u.__.push({}),u.__[n]}function m(n){return i=1,d(b,n)}function d(r,u,o){var i=x(n++,2);if(i.t=r,!i.__c&&(i.__=[o?o(u):b(void 0,u),function(n){var t=i.__N?i.__N[0]:i.__[0],r=i.t(t,n);t!==r&&(i.__N=[r,i.__[1]],i.__c.setState({}))}],i.__c=t,!t.__f)){var f=function(n,t,r){if(!i.__c.__H)return!0;var u=i.__c.__H.__.filter(function(n){return!!n.__c});if(u.every(function(n){return!n.__N}))return!c||c.call(this,n,t,r);var o=i.__c.props!==n;return u.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(o=!0)}}),c&&c.call(this,n,t,r)||o};t.__f=!0;var c=t.shouldComponentUpdate,e=t.componentWillUpdate;t.componentWillUpdate=function(n,t,r){if(this.__e){var u=c;c=void 0,f(n,t,r),c=u}e&&e.call(this,n,t,r)},t.shouldComponentUpdate=f}return i.__N||i.__}function h(r,u){var o=x(n++,4);!c.__s&&P(o.__H,u)&&(o.__=r,o.u=u,t.__h.push(o))}function y(t,r){var u=x(n++,7);return P(u.__H,r)&&(u.__=t(),u.__H=r,u.__h=t),u.__}function _(){for(var n;n=f.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(F),n.__H.__h.forEach(T),n.__H.__h=[]}catch(t){n.__H.__h=[],c.__e(t,n.__v)}}c.__b=function(n){t=null,e&&e(n)},c.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),p&&p(n,t)},c.__r=function(u){a&&a(u),n=0;var o=(t=u.__c).__H;o&&(r===t?(o.__h=[],t.__h=[],o.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(o.__h.forEach(F),o.__h.forEach(T),o.__h=[],n=0)),r=t},c.diffed=function(n){v&&v(n);var o=n.__c;o&&o.__H&&(o.__H.__h.length&&(1!==f.push(o)&&u===c.requestAnimationFrame||((u=c.requestAnimationFrame)||A)(_)),o.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),r=t=null},c.__c=function(n,t){t.some(function(n){try{n.__h.forEach(F),n.__h=n.__h.filter(function(n){return!n.__||T(n)})}catch(r){t.some(function(n){n.__h&&(n.__h=[])}),t=[],c.__e(r,n.__v)}}),s&&s(n,t)},c.unmount=function(n){l&&l(n);var t,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{F(n)}catch(n){t=n}}),r.__H=void 0,t&&c.__e(t,r.__v))};var q="function"==typeof requestAnimationFrame;function A(n){var t,r=function(){clearTimeout(u),q&&cancelAnimationFrame(t),setTimeout(n)},u=setTimeout(r,35);q&&(t=requestAnimationFrame(r))}function F(n){var r=t,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),t=r}function T(n){var r=t;n.__c=n.__(),t=r}function P(n,t){return!n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function b(n,t){return"function"==typeof t?t(n):t}exports.useCallback=function(n,t){return i=8,y(function(){return n},t)},exports.useContext=function(r){var u=t.context[r.__c],o=x(n++,9);return o.c=r,u?(null==o.__&&(o.__=!0,u.sub(t)),u.props.value):r.__},exports.useDebugValue=function(n,t){c.useDebugValue&&c.useDebugValue(t?t(n):n)},exports.useEffect=function(r,u){var o=x(n++,3);!c.__s&&P(o.__H,u)&&(o.__=r,o.u=u,t.__H.__h.push(o))},exports.useErrorBoundary=function(r){var u=x(n++,10),o=m();return u.__=r,t.componentDidCatch||(t.componentDidCatch=function(n,t){u.__&&u.__(n,t),o[1](n)}),[o[0],function(){o[1](void 0)}]},exports.useId=function(){var r=x(n++,11);if(!r.__){for(var u=t.__v;null!==u&&!u.__m&&null!==u.__;)u=u.__;var o=u.__m||(u.__m=[0,0]);r.__="P"+o[0]+"-"+o[1]++}return r.__},exports.useImperativeHandle=function(n,t,r){i=6,h(function(){if("function"==typeof n){var r=n(t());return function(){n(null),r&&"function"==typeof r&&r()}}if(n)return n.current=t(),function(){return n.current=null}},null==r?r:r.concat(n))},exports.useLayoutEffect=h,exports.useMemo=y,exports.useReducer=d,exports.useRef=function(n){return i=5,y(function(){return{current:n}},[])},exports.useState=m;
//# sourceMappingURL=hooks.js.map

1
node_modules/preact/hooks/dist/hooks.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
node_modules/preact/hooks/dist/hooks.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{options as n}from"preact";var t,r,u,i,o=0,f=[],c=n,e=c.__b,a=c.__r,v=c.diffed,l=c.__c,m=c.unmount,s=c.__;function p(n,t){c.__h&&c.__h(r,n,o||t),o=0;var u=r.__H||(r.__H={__:[],__h:[]});return n>=u.__.length&&u.__.push({}),u.__[n]}function d(n){return o=1,h(D,n)}function h(n,u,i){var o=p(t++,2);if(o.t=n,!o.__c&&(o.__=[i?i(u):D(void 0,u),function(n){var t=o.__N?o.__N[0]:o.__[0],r=o.t(t,n);t!==r&&(o.__N=[r,o.__[1]],o.__c.setState({}))}],o.__c=r,!r.__f)){var f=function(n,t,r){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(n){return!!n.__c});if(u.every(function(n){return!n.__N}))return!c||c.call(this,n,t,r);var i=o.__c.props!==n;return u.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(i=!0)}}),c&&c.call(this,n,t,r)||i};r.__f=!0;var c=r.shouldComponentUpdate,e=r.componentWillUpdate;r.componentWillUpdate=function(n,t,r){if(this.__e){var u=c;c=void 0,f(n,t,r),c=u}e&&e.call(this,n,t,r)},r.shouldComponentUpdate=f}return o.__N||o.__}function y(n,u){var i=p(t++,3);!c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__H.__h.push(i))}function _(n,u){var i=p(t++,4);!c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__h.push(i))}function A(n){return o=5,T(function(){return{current:n}},[])}function F(n,t,r){o=6,_(function(){if("function"==typeof n){var r=n(t());return function(){n(null),r&&"function"==typeof r&&r()}}if(n)return n.current=t(),function(){return n.current=null}},null==r?r:r.concat(n))}function T(n,r){var u=p(t++,7);return C(u.__H,r)&&(u.__=n(),u.__H=r,u.__h=n),u.__}function q(n,t){return o=8,T(function(){return n},t)}function x(n){var u=r.context[n.__c],i=p(t++,9);return i.c=n,u?(null==i.__&&(i.__=!0,u.sub(r)),u.props.value):n.__}function P(n,t){c.useDebugValue&&c.useDebugValue(t?t(n):n)}function b(n){var u=p(t++,10),i=d();return u.__=n,r.componentDidCatch||(r.componentDidCatch=function(n,t){u.__&&u.__(n,t),i[1](n)}),[i[0],function(){i[1](void 0)}]}function g(){var n=p(t++,11);if(!n.__){for(var u=r.__v;null!==u&&!u.__m&&null!==u.__;)u=u.__;var i=u.__m||(u.__m=[0,0]);n.__="P"+i[0]+"-"+i[1]++}return n.__}function j(){for(var n;n=f.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(z),n.__H.__h.forEach(B),n.__H.__h=[]}catch(t){n.__H.__h=[],c.__e(t,n.__v)}}c.__b=function(n){r=null,e&&e(n)},c.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),s&&s(n,t)},c.__r=function(n){a&&a(n),t=0;var i=(r=n.__c).__H;i&&(u===r?(i.__h=[],r.__h=[],i.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(i.__h.forEach(z),i.__h.forEach(B),i.__h=[],t=0)),u=r},c.diffed=function(n){v&&v(n);var t=n.__c;t&&t.__H&&(t.__H.__h.length&&(1!==f.push(t)&&i===c.requestAnimationFrame||((i=c.requestAnimationFrame)||w)(j)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),u=r=null},c.__c=function(n,t){t.some(function(n){try{n.__h.forEach(z),n.__h=n.__h.filter(function(n){return!n.__||B(n)})}catch(r){t.some(function(n){n.__h&&(n.__h=[])}),t=[],c.__e(r,n.__v)}}),l&&l(n,t)},c.unmount=function(n){m&&m(n);var t,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{z(n)}catch(n){t=n}}),r.__H=void 0,t&&c.__e(t,r.__v))};var k="function"==typeof requestAnimationFrame;function w(n){var t,r=function(){clearTimeout(u),k&&cancelAnimationFrame(t),setTimeout(n)},u=setTimeout(r,35);k&&(t=requestAnimationFrame(r))}function z(n){var t=r,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),r=t}function B(n){var t=r;n.__c=n.__(),r=t}function C(n,t){return!n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function D(n,t){return"function"==typeof t?t(n):t}export{q as useCallback,x as useContext,P as useDebugValue,y as useEffect,b as useErrorBoundary,g as useId,F as useImperativeHandle,_ as useLayoutEffect,T as useMemo,h as useReducer,A as useRef,d as useState};
//# sourceMappingURL=hooks.module.js.map

2
node_modules/preact/hooks/dist/hooks.module.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{options as n}from"preact";var t,r,u,i,o=0,f=[],c=n,e=c.__b,a=c.__r,v=c.diffed,l=c.__c,m=c.unmount,s=c.__;function p(n,t){c.__h&&c.__h(r,n,o||t),o=0;var u=r.__H||(r.__H={__:[],__h:[]});return n>=u.__.length&&u.__.push({}),u.__[n]}function d(n){return o=1,h(D,n)}function h(n,u,i){var o=p(t++,2);if(o.t=n,!o.__c&&(o.__=[i?i(u):D(void 0,u),function(n){var t=o.__N?o.__N[0]:o.__[0],r=o.t(t,n);t!==r&&(o.__N=[r,o.__[1]],o.__c.setState({}))}],o.__c=r,!r.__f)){var f=function(n,t,r){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(n){return!!n.__c});if(u.every(function(n){return!n.__N}))return!c||c.call(this,n,t,r);var i=o.__c.props!==n;return u.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(i=!0)}}),c&&c.call(this,n,t,r)||i};r.__f=!0;var c=r.shouldComponentUpdate,e=r.componentWillUpdate;r.componentWillUpdate=function(n,t,r){if(this.__e){var u=c;c=void 0,f(n,t,r),c=u}e&&e.call(this,n,t,r)},r.shouldComponentUpdate=f}return o.__N||o.__}function y(n,u){var i=p(t++,3);!c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__H.__h.push(i))}function _(n,u){var i=p(t++,4);!c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__h.push(i))}function A(n){return o=5,T(function(){return{current:n}},[])}function F(n,t,r){o=6,_(function(){if("function"==typeof n){var r=n(t());return function(){n(null),r&&"function"==typeof r&&r()}}if(n)return n.current=t(),function(){return n.current=null}},null==r?r:r.concat(n))}function T(n,r){var u=p(t++,7);return C(u.__H,r)&&(u.__=n(),u.__H=r,u.__h=n),u.__}function q(n,t){return o=8,T(function(){return n},t)}function x(n){var u=r.context[n.__c],i=p(t++,9);return i.c=n,u?(null==i.__&&(i.__=!0,u.sub(r)),u.props.value):n.__}function P(n,t){c.useDebugValue&&c.useDebugValue(t?t(n):n)}function b(n){var u=p(t++,10),i=d();return u.__=n,r.componentDidCatch||(r.componentDidCatch=function(n,t){u.__&&u.__(n,t),i[1](n)}),[i[0],function(){i[1](void 0)}]}function g(){var n=p(t++,11);if(!n.__){for(var u=r.__v;null!==u&&!u.__m&&null!==u.__;)u=u.__;var i=u.__m||(u.__m=[0,0]);n.__="P"+i[0]+"-"+i[1]++}return n.__}function j(){for(var n;n=f.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(z),n.__H.__h.forEach(B),n.__H.__h=[]}catch(t){n.__H.__h=[],c.__e(t,n.__v)}}c.__b=function(n){r=null,e&&e(n)},c.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),s&&s(n,t)},c.__r=function(n){a&&a(n),t=0;var i=(r=n.__c).__H;i&&(u===r?(i.__h=[],r.__h=[],i.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(i.__h.forEach(z),i.__h.forEach(B),i.__h=[],t=0)),u=r},c.diffed=function(n){v&&v(n);var t=n.__c;t&&t.__H&&(t.__H.__h.length&&(1!==f.push(t)&&i===c.requestAnimationFrame||((i=c.requestAnimationFrame)||w)(j)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),u=r=null},c.__c=function(n,t){t.some(function(n){try{n.__h.forEach(z),n.__h=n.__h.filter(function(n){return!n.__||B(n)})}catch(r){t.some(function(n){n.__h&&(n.__h=[])}),t=[],c.__e(r,n.__v)}}),l&&l(n,t)},c.unmount=function(n){m&&m(n);var t,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{z(n)}catch(n){t=n}}),r.__H=void 0,t&&c.__e(t,r.__v))};var k="function"==typeof requestAnimationFrame;function w(n){var t,r=function(){clearTimeout(u),k&&cancelAnimationFrame(t),setTimeout(n)},u=setTimeout(r,35);k&&(t=requestAnimationFrame(r))}function z(n){var t=r,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),r=t}function B(n){var t=r;n.__c=n.__(),r=t}function C(n,t){return!n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function D(n,t){return"function"==typeof t?t(n):t}export{q as useCallback,x as useContext,P as useDebugValue,y as useEffect,b as useErrorBoundary,g as useId,F as useImperativeHandle,_ as useLayoutEffect,T as useMemo,h as useReducer,A as useRef,d as useState};
//# sourceMappingURL=hooks.module.js.map

1
node_modules/preact/hooks/dist/hooks.module.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
node_modules/preact/hooks/dist/hooks.umd.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t((n||self).preactHooks={},n.preact)}(this,function(n,t){var u,i,r,o,f=0,c=[],e=t.options,a=e.__b,v=e.__r,l=e.diffed,d=e.__c,s=e.unmount,p=e.__;function y(n,t){e.__h&&e.__h(i,n,f||t),f=0;var u=i.__H||(i.__H={__:[],__h:[]});return n>=u.__.length&&u.__.push({}),u.__[n]}function h(n){return f=1,m(j,n)}function m(n,t,r){var o=y(u++,2);if(o.t=n,!o.__c&&(o.__=[r?r(t):j(void 0,t),function(n){var t=o.__N?o.__N[0]:o.__[0],u=o.t(t,n);t!==u&&(o.__N=[u,o.__[1]],o.__c.setState({}))}],o.__c=i,!i.__f)){var f=function(n,t,u){if(!o.__c.__H)return!0;var i=o.__c.__H.__.filter(function(n){return!!n.__c});if(i.every(function(n){return!n.__N}))return!c||c.call(this,n,t,u);var r=o.__c.props!==n;return i.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(r=!0)}}),c&&c.call(this,n,t,u)||r};i.__f=!0;var c=i.shouldComponentUpdate,e=i.componentWillUpdate;i.componentWillUpdate=function(n,t,u){if(this.__e){var i=c;c=void 0,f(n,t,u),c=i}e&&e.call(this,n,t,u)},i.shouldComponentUpdate=f}return o.__N||o.__}function T(n,t){var r=y(u++,4);!e.__s&&g(r.__H,t)&&(r.__=n,r.u=t,i.__h.push(r))}function _(n,t){var i=y(u++,7);return g(i.__H,t)&&(i.__=n(),i.__H=t,i.__h=n),i.__}function b(){for(var n;n=c.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(A),n.__H.__h.forEach(F),n.__H.__h=[]}catch(t){n.__H.__h=[],e.__e(t,n.__v)}}e.__b=function(n){i=null,a&&a(n)},e.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),p&&p(n,t)},e.__r=function(n){v&&v(n),u=0;var t=(i=n.__c).__H;t&&(r===i?(t.__h=[],i.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(A),t.__h.forEach(F),t.__h=[],u=0)),r=i},e.diffed=function(n){l&&l(n);var t=n.__c;t&&t.__H&&(t.__H.__h.length&&(1!==c.push(t)&&o===e.requestAnimationFrame||((o=e.requestAnimationFrame)||x)(b)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),r=i=null},e.__c=function(n,t){t.some(function(n){try{n.__h.forEach(A),n.__h=n.__h.filter(function(n){return!n.__||F(n)})}catch(u){t.some(function(n){n.__h&&(n.__h=[])}),t=[],e.__e(u,n.__v)}}),d&&d(n,t)},e.unmount=function(n){s&&s(n);var t,u=n.__c;u&&u.__H&&(u.__H.__.forEach(function(n){try{A(n)}catch(n){t=n}}),u.__H=void 0,t&&e.__e(t,u.__v))};var q="function"==typeof requestAnimationFrame;function x(n){var t,u=function(){clearTimeout(i),q&&cancelAnimationFrame(t),setTimeout(n)},i=setTimeout(u,35);q&&(t=requestAnimationFrame(u))}function A(n){var t=i,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),i=t}function F(n){var t=i;n.__c=n.__(),i=t}function g(n,t){return!n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function j(n,t){return"function"==typeof t?t(n):t}n.useCallback=function(n,t){return f=8,_(function(){return n},t)},n.useContext=function(n){var t=i.context[n.__c],r=y(u++,9);return r.c=n,t?(null==r.__&&(r.__=!0,t.sub(i)),t.props.value):n.__},n.useDebugValue=function(n,t){e.useDebugValue&&e.useDebugValue(t?t(n):n)},n.useEffect=function(n,t){var r=y(u++,3);!e.__s&&g(r.__H,t)&&(r.__=n,r.u=t,i.__H.__h.push(r))},n.useErrorBoundary=function(n){var t=y(u++,10),r=h();return t.__=n,i.componentDidCatch||(i.componentDidCatch=function(n,u){t.__&&t.__(n,u),r[1](n)}),[r[0],function(){r[1](void 0)}]},n.useId=function(){var n=y(u++,11);if(!n.__){for(var t=i.__v;null!==t&&!t.__m&&null!==t.__;)t=t.__;var r=t.__m||(t.__m=[0,0]);n.__="P"+r[0]+"-"+r[1]++}return n.__},n.useImperativeHandle=function(n,t,u){f=6,T(function(){if("function"==typeof n){var u=n(t());return function(){n(null),u&&"function"==typeof u&&u()}}if(n)return n.current=t(),function(){return n.current=null}},null==u?u:u.concat(n))},n.useLayoutEffect=T,n.useMemo=_,n.useReducer=m,n.useRef=function(n){return f=5,_(function(){return{current:n}},[])},n.useState=h});
//# sourceMappingURL=hooks.umd.js.map

1
node_modules/preact/hooks/dist/hooks.umd.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

35
node_modules/preact/hooks/package.json generated vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "preact-hooks",
"amdName": "preactHooks",
"version": "0.1.0",
"private": true,
"description": "Hook addon for Preact",
"main": "dist/hooks.js",
"module": "dist/hooks.module.js",
"umd:main": "dist/hooks.umd.js",
"source": "src/index.js",
"license": "MIT",
"types": "src/index.d.ts",
"scripts": {
"build": "microbundle build --raw",
"dev": "microbundle watch --raw --format cjs",
"test": "npm-run-all build --parallel test:karma",
"test:karma": "karma start test/karma.conf.js --single-run",
"test:karma:watch": "karma start test/karma.conf.js --no-single-run"
},
"peerDependencies": {
"preact": "^10.0.0"
},
"mangle": {
"regex": "^_"
},
"exports": {
".": {
"types": "./src/index.d.ts",
"browser": "./dist/hooks.module.js",
"umd": "./dist/hooks.umd.js",
"import": "./dist/hooks.mjs",
"require": "./dist/hooks.js"
}
}
}

145
node_modules/preact/hooks/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,145 @@
// Intentionally not using a relative path to take advantage of
// the TS version resolution mechanism
import { ErrorInfo, PreactContext, Ref, RefObject } from 'preact';
type Inputs = ReadonlyArray<unknown>;
export type Dispatch<A> = (value: A) => void;
export type StateUpdater<S> = S | ((prevState: S) => S);
/**
* Returns a stateful value, and a function to update it.
* @param initialState The initial value (or a function that returns the initial value)
*/
export function useState<S>(
initialState: S | (() => S)
): [S, Dispatch<StateUpdater<S>>];
export function useState<S = undefined>(): [
S | undefined,
Dispatch<StateUpdater<S | undefined>>
];
export type Reducer<S, A> = (prevState: S, action: A) => S;
/**
* An alternative to `useState`.
*
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
* multiple sub-values. It also lets you optimize performance for components that trigger deep
* updates because you can pass `dispatch` down instead of callbacks.
* @param reducer Given the current state and an action, returns the new state
* @param initialState The initial value to store as state
*/
export function useReducer<S, A>(
reducer: Reducer<S, A>,
initialState: S
): [S, Dispatch<A>];
/**
* An alternative to `useState`.
*
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
* multiple sub-values. It also lets you optimize performance for components that trigger deep
* updates because you can pass `dispatch` down instead of callbacks.
* @param reducer Given the current state and an action, returns the new state
* @param initialArg The initial argument to pass to the `init` function
* @param init A function that, given the `initialArg`, returns the initial value to store as state
*/
export function useReducer<S, A, I>(
reducer: Reducer<S, A>,
initialArg: I,
init: (arg: I) => S
): [S, Dispatch<A>];
/** @deprecated Use the `Ref` type instead. */
type PropRef<T> = MutableRef<T>;
interface MutableRef<T> {
current: T;
}
/**
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
* (`initialValue`). The returned object will persist for the full lifetime of the component.
*
* Note that `useRef()` is useful for more than the `ref` attribute. Its handy for keeping any mutable
* value around similar to how youd use instance fields in classes.
*
* @param initialValue the initial value to store in the ref object
*/
export function useRef<T>(initialValue: T): MutableRef<T>;
export function useRef<T>(initialValue: T | null): RefObject<T>;
export function useRef<T = undefined>(): MutableRef<T | undefined>;
type EffectCallback = () => void | (() => void);
/**
* Accepts a function that contains imperative, possibly effectful code.
* The effects run after browser paint, without blocking it.
*
* @param effect Imperative function that can return a cleanup function
* @param inputs If present, effect will only activate if the values in the list change (using ===).
*/
export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
type CreateHandle = () => object;
/**
* @param ref The ref that will be mutated
* @param create The function that will be executed to get the value that will be attached to
* ref.current
* @param inputs If present, effect will only activate if the values in the list change (using ===).
*/
export function useImperativeHandle<T, R extends T>(
ref: Ref<T>,
create: () => R,
inputs?: Inputs
): void;
/**
* Accepts a function that contains imperative, possibly effectful code.
* Use this to read layout from the DOM and synchronously re-render.
* Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
* Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
*
* @param effect Imperative function that can return a cleanup function
* @param inputs If present, effect will only activate if the values in the list change (using ===).
*/
export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
/**
* Returns a memoized version of the callback that only changes if one of the `inputs`
* has changed (using ===).
*/
export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
/**
* Pass a factory function and an array of inputs.
* useMemo will only recompute the memoized value when one of the inputs has changed.
* This optimization helps to avoid expensive calculations on every render.
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
*/
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
/**
* Returns the current context value, as given by the nearest context provider for the given context.
* When the provider updates, this Hook will trigger a rerender with the latest context value.
*
* @param context The context you want to use
*/
export function useContext<T>(context: PreactContext<T>): T;
/**
* Customize the displayed value in the devtools panel.
*
* @param value Custom hook name or object that is passed to formatter
* @param formatter Formatter to modify value before sending it to the devtools
*/
export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
export function useErrorBoundary(
callback?: (error: any, errorInfo: ErrorInfo) => Promise<void> | void
): [any, () => void];
export function useId(): string;

555
node_modules/preact/hooks/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,555 @@
import { options as _options } from 'preact';
/** @type {number} */
let currentIndex;
/** @type {import('./internal').Component} */
let currentComponent;
/** @type {import('./internal').Component} */
let previousComponent;
/** @type {number} */
let currentHook = 0;
/** @type {Array<import('./internal').Component>} */
let afterPaintEffects = [];
// Cast to use internal Options type
const options = /** @type {import('./internal').Options} */ (_options);
let oldBeforeDiff = options._diff;
let oldBeforeRender = options._render;
let oldAfterDiff = options.diffed;
let oldCommit = options._commit;
let oldBeforeUnmount = options.unmount;
let oldRoot = options._root;
// We take the minimum timeout for requestAnimationFrame to ensure that
// the callback is invoked after the next frame. 35ms is based on a 30hz
// refresh rate, which is the minimum rate for a smooth user experience.
const RAF_TIMEOUT = 35;
let prevRaf;
/** @type {(vnode: import('./internal').VNode) => void} */
options._diff = vnode => {
currentComponent = null;
if (oldBeforeDiff) oldBeforeDiff(vnode);
};
options._root = (vnode, parentDom) => {
if (vnode && parentDom._children && parentDom._children._mask) {
vnode._mask = parentDom._children._mask;
}
if (oldRoot) oldRoot(vnode, parentDom);
};
/** @type {(vnode: import('./internal').VNode) => void} */
options._render = vnode => {
if (oldBeforeRender) oldBeforeRender(vnode);
currentComponent = vnode._component;
currentIndex = 0;
const hooks = currentComponent.__hooks;
if (hooks) {
if (previousComponent === currentComponent) {
hooks._pendingEffects = [];
currentComponent._renderCallbacks = [];
hooks._list.forEach(hookItem => {
if (hookItem._nextValue) {
hookItem._value = hookItem._nextValue;
}
hookItem._pendingArgs = hookItem._nextValue = undefined;
});
} else {
hooks._pendingEffects.forEach(invokeCleanup);
hooks._pendingEffects.forEach(invokeEffect);
hooks._pendingEffects = [];
currentIndex = 0;
}
}
previousComponent = currentComponent;
};
/** @type {(vnode: import('./internal').VNode) => void} */
options.diffed = vnode => {
if (oldAfterDiff) oldAfterDiff(vnode);
const c = vnode._component;
if (c && c.__hooks) {
if (c.__hooks._pendingEffects.length) afterPaint(afterPaintEffects.push(c));
c.__hooks._list.forEach(hookItem => {
if (hookItem._pendingArgs) {
hookItem._args = hookItem._pendingArgs;
}
hookItem._pendingArgs = undefined;
});
}
previousComponent = currentComponent = null;
};
// TODO: Improve typing of commitQueue parameter
/** @type {(vnode: import('./internal').VNode, commitQueue: any) => void} */
options._commit = (vnode, commitQueue) => {
commitQueue.some(component => {
try {
component._renderCallbacks.forEach(invokeCleanup);
component._renderCallbacks = component._renderCallbacks.filter(cb =>
cb._value ? invokeEffect(cb) : true
);
} catch (e) {
commitQueue.some(c => {
if (c._renderCallbacks) c._renderCallbacks = [];
});
commitQueue = [];
options._catchError(e, component._vnode);
}
});
if (oldCommit) oldCommit(vnode, commitQueue);
};
/** @type {(vnode: import('./internal').VNode) => void} */
options.unmount = vnode => {
if (oldBeforeUnmount) oldBeforeUnmount(vnode);
const c = vnode._component;
if (c && c.__hooks) {
let hasErrored;
c.__hooks._list.forEach(s => {
try {
invokeCleanup(s);
} catch (e) {
hasErrored = e;
}
});
c.__hooks = undefined;
if (hasErrored) options._catchError(hasErrored, c._vnode);
}
};
/**
* Get a hook's state from the currentComponent
* @param {number} index The index of the hook to get
* @param {number} type The index of the hook to get
* @returns {any}
*/
function getHookState(index, type) {
if (options._hook) {
options._hook(currentComponent, index, currentHook || type);
}
currentHook = 0;
// Largely inspired by:
// * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs
// * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs
// Other implementations to look at:
// * https://codesandbox.io/s/mnox05qp8
const hooks =
currentComponent.__hooks ||
(currentComponent.__hooks = {
_list: [],
_pendingEffects: []
});
if (index >= hooks._list.length) {
hooks._list.push({});
}
return hooks._list[index];
}
/**
* @template {unknown} S
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} [initialState]
* @returns {[S, (state: S) => void]}
*/
export function useState(initialState) {
currentHook = 1;
return useReducer(invokeOrReturn, initialState);
}
/**
* @template {unknown} S
* @template {unknown} A
* @param {import('./index').Reducer<S, A>} reducer
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} initialState
* @param {(initialState: any) => void} [init]
* @returns {[ S, (state: S) => void ]}
*/
export function useReducer(reducer, initialState, init) {
/** @type {import('./internal').ReducerHookState} */
const hookState = getHookState(currentIndex++, 2);
hookState._reducer = reducer;
if (!hookState._component) {
hookState._value = [
!init ? invokeOrReturn(undefined, initialState) : init(initialState),
action => {
const currentValue = hookState._nextValue
? hookState._nextValue[0]
: hookState._value[0];
const nextValue = hookState._reducer(currentValue, action);
if (currentValue !== nextValue) {
hookState._nextValue = [nextValue, hookState._value[1]];
hookState._component.setState({});
}
}
];
hookState._component = currentComponent;
if (!currentComponent._hasScuFromHooks) {
currentComponent._hasScuFromHooks = true;
let prevScu = currentComponent.shouldComponentUpdate;
const prevCWU = currentComponent.componentWillUpdate;
// If we're dealing with a forced update `shouldComponentUpdate` will
// not be called. But we use that to update the hook values, so we
// need to call it.
currentComponent.componentWillUpdate = function (p, s, c) {
if (this._force) {
let tmp = prevScu;
// Clear to avoid other sCU hooks from being called
prevScu = undefined;
updateHookState(p, s, c);
prevScu = tmp;
}
if (prevCWU) prevCWU.call(this, p, s, c);
};
// This SCU has the purpose of bailing out after repeated updates
// to stateful hooks.
// we store the next value in _nextValue[0] and keep doing that for all
// state setters, if we have next states and
// all next states within a component end up being equal to their original state
// we are safe to bail out for this specific component.
/**
*
* @type {import('./internal').Component["shouldComponentUpdate"]}
*/
// @ts-ignore - We don't use TS to downtranspile
// eslint-disable-next-line no-inner-declarations
function updateHookState(p, s, c) {
if (!hookState._component.__hooks) return true;
/** @type {(x: import('./internal').HookState) => x is import('./internal').ReducerHookState} */
const isStateHook = x => !!x._component;
const stateHooks =
hookState._component.__hooks._list.filter(isStateHook);
const allHooksEmpty = stateHooks.every(x => !x._nextValue);
// When we have no updated hooks in the component we invoke the previous SCU or
// traverse the VDOM tree further.
if (allHooksEmpty) {
return prevScu ? prevScu.call(this, p, s, c) : true;
}
// We check whether we have components with a nextValue set that
// have values that aren't equal to one another this pushes
// us to update further down the tree
let shouldUpdate = hookState._component.props !== p;
stateHooks.forEach(hookItem => {
if (hookItem._nextValue) {
const currentValue = hookItem._value[0];
hookItem._value = hookItem._nextValue;
hookItem._nextValue = undefined;
if (currentValue !== hookItem._value[0]) shouldUpdate = true;
}
});
return prevScu
? prevScu.call(this, p, s, c) || shouldUpdate
: shouldUpdate;
}
currentComponent.shouldComponentUpdate = updateHookState;
}
}
return hookState._nextValue || hookState._value;
}
/**
* @param {import('./internal').Effect} callback
* @param {unknown[]} args
* @returns {void}
*/
export function useEffect(callback, args) {
/** @type {import('./internal').EffectHookState} */
const state = getHookState(currentIndex++, 3);
if (!options._skipEffects && argsChanged(state._args, args)) {
state._value = callback;
state._pendingArgs = args;
currentComponent.__hooks._pendingEffects.push(state);
}
}
/**
* @param {import('./internal').Effect} callback
* @param {unknown[]} args
* @returns {void}
*/
export function useLayoutEffect(callback, args) {
/** @type {import('./internal').EffectHookState} */
const state = getHookState(currentIndex++, 4);
if (!options._skipEffects && argsChanged(state._args, args)) {
state._value = callback;
state._pendingArgs = args;
currentComponent._renderCallbacks.push(state);
}
}
/** @type {(initialValue: unknown) => unknown} */
export function useRef(initialValue) {
currentHook = 5;
return useMemo(() => ({ current: initialValue }), []);
}
/**
* @param {object} ref
* @param {() => object} createHandle
* @param {unknown[]} args
* @returns {void}
*/
export function useImperativeHandle(ref, createHandle, args) {
currentHook = 6;
useLayoutEffect(
() => {
if (typeof ref == 'function') {
const result = ref(createHandle());
return () => {
ref(null);
if (result && typeof result == 'function') result();
};
} else if (ref) {
ref.current = createHandle();
return () => (ref.current = null);
}
},
args == null ? args : args.concat(ref)
);
}
/**
* @template {unknown} T
* @param {() => T} factory
* @param {unknown[]} args
* @returns {T}
*/
export function useMemo(factory, args) {
/** @type {import('./internal').MemoHookState<T>} */
const state = getHookState(currentIndex++, 7);
if (argsChanged(state._args, args)) {
state._value = factory();
state._args = args;
state._factory = factory;
}
return state._value;
}
/**
* @param {() => void} callback
* @param {unknown[]} args
* @returns {() => void}
*/
export function useCallback(callback, args) {
currentHook = 8;
return useMemo(() => callback, args);
}
/**
* @param {import('./internal').PreactContext} context
*/
export function useContext(context) {
const provider = currentComponent.context[context._id];
// We could skip this call here, but than we'd not call
// `options._hook`. We need to do that in order to make
// the devtools aware of this hook.
/** @type {import('./internal').ContextHookState} */
const state = getHookState(currentIndex++, 9);
// The devtools needs access to the context object to
// be able to pull of the default value when no provider
// is present in the tree.
state._context = context;
if (!provider) return context._defaultValue;
// This is probably not safe to convert to "!"
if (state._value == null) {
state._value = true;
provider.sub(currentComponent);
}
return provider.props.value;
}
/**
* Display a custom label for a custom hook for the devtools panel
* @type {<T>(value: T, cb?: (value: T) => string | number) => void}
*/
export function useDebugValue(value, formatter) {
if (options.useDebugValue) {
options.useDebugValue(
formatter ? formatter(value) : /** @type {any}*/ (value)
);
}
}
/**
* @param {(error: unknown, errorInfo: import('preact').ErrorInfo) => void} cb
* @returns {[unknown, () => void]}
*/
export function useErrorBoundary(cb) {
/** @type {import('./internal').ErrorBoundaryHookState} */
const state = getHookState(currentIndex++, 10);
const errState = useState();
state._value = cb;
if (!currentComponent.componentDidCatch) {
currentComponent.componentDidCatch = (err, errorInfo) => {
if (state._value) state._value(err, errorInfo);
errState[1](err);
};
}
return [
errState[0],
() => {
errState[1](undefined);
}
];
}
/** @type {() => string} */
export function useId() {
/** @type {import('./internal').IdHookState} */
const state = getHookState(currentIndex++, 11);
if (!state._value) {
// Grab either the root node or the nearest async boundary node.
/** @type {import('./internal').VNode} */
let root = currentComponent._vnode;
while (root !== null && !root._mask && root._parent !== null) {
root = root._parent;
}
let mask = root._mask || (root._mask = [0, 0]);
state._value = 'P' + mask[0] + '-' + mask[1]++;
}
return state._value;
}
/**
* After paint effects consumer.
*/
function flushAfterPaintEffects() {
let component;
while ((component = afterPaintEffects.shift())) {
if (!component._parentDom || !component.__hooks) continue;
try {
component.__hooks._pendingEffects.forEach(invokeCleanup);
component.__hooks._pendingEffects.forEach(invokeEffect);
component.__hooks._pendingEffects = [];
} catch (e) {
component.__hooks._pendingEffects = [];
options._catchError(e, component._vnode);
}
}
}
let HAS_RAF = typeof requestAnimationFrame == 'function';
/**
* Schedule a callback to be invoked after the browser has a chance to paint a new frame.
* Do this by combining requestAnimationFrame (rAF) + setTimeout to invoke a callback after
* the next browser frame.
*
* Also, schedule a timeout in parallel to the the rAF to ensure the callback is invoked
* even if RAF doesn't fire (for example if the browser tab is not visible)
*
* @param {() => void} callback
*/
function afterNextFrame(callback) {
const done = () => {
clearTimeout(timeout);
if (HAS_RAF) cancelAnimationFrame(raf);
setTimeout(callback);
};
const timeout = setTimeout(done, RAF_TIMEOUT);
let raf;
if (HAS_RAF) {
raf = requestAnimationFrame(done);
}
}
// Note: if someone used options.debounceRendering = requestAnimationFrame,
// then effects will ALWAYS run on the NEXT frame instead of the current one, incurring a ~16ms delay.
// Perhaps this is not such a big deal.
/**
* Schedule afterPaintEffects flush after the browser paints
* @param {number} newQueueLength
* @returns {void}
*/
function afterPaint(newQueueLength) {
if (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {
prevRaf = options.requestAnimationFrame;
(prevRaf || afterNextFrame)(flushAfterPaintEffects);
}
}
/**
* @param {import('./internal').HookState} hook
* @returns {void}
*/
function invokeCleanup(hook) {
// A hook cleanup can introduce a call to render which creates a new root, this will call options.vnode
// and move the currentComponent away.
const comp = currentComponent;
let cleanup = hook._cleanup;
if (typeof cleanup == 'function') {
hook._cleanup = undefined;
cleanup();
}
currentComponent = comp;
}
/**
* Invoke a Hook's effect
* @param {import('./internal').EffectHookState} hook
* @returns {void}
*/
function invokeEffect(hook) {
// A hook call can introduce a call to render which creates a new root, this will call options.vnode
// and move the currentComponent away.
const comp = currentComponent;
hook._cleanup = hook._value();
currentComponent = comp;
}
/**
* @param {unknown[]} oldArgs
* @param {unknown[]} newArgs
* @returns {boolean}
*/
function argsChanged(oldArgs, newArgs) {
return (
!oldArgs ||
oldArgs.length !== newArgs.length ||
newArgs.some((arg, index) => arg !== oldArgs[index])
);
}
/**
* @template Arg
* @param {Arg} arg
* @param {(arg: Arg) => any} f
* @returns {any}
*/
function invokeOrReturn(arg, f) {
return typeof f == 'function' ? f(arg) : f;
}

103
node_modules/preact/hooks/src/internal.d.ts generated vendored Normal file
View File

@@ -0,0 +1,103 @@
import {
Options as PreactOptions,
Component as PreactComponent,
VNode as PreactVNode,
PreactContext,
HookType,
ErrorInfo,
} from '../../src/internal';
import { Reducer, StateUpdater } from '.';
export { PreactContext };
export interface Options extends PreactOptions {
/** Attach a hook that is invoked before a vnode is diffed. */
_diff?(vnode: VNode): void;
diffed?(vnode: VNode): void;
/** Attach a hook that is invoked before a vnode has rendered. */
_render?(vnode: VNode): void;
/** Attach a hook that is invoked after a tree was mounted or was updated. */
_commit?(vnode: VNode, commitQueue: Component[]): void;
_unmount?(vnode: VNode): void;
/** Attach a hook that is invoked before a hook's state is queried. */
_hook?(component: Component, index: number, type: HookType): void;
}
// Hook tracking
export interface ComponentHooks {
/** The list of hooks a component uses */
_list: HookState[];
/** List of Effects to be invoked after the next frame is rendered */
_pendingEffects: EffectHookState[];
}
export interface Component extends Omit<PreactComponent<any, any>, '_renderCallbacks'> {
__hooks?: ComponentHooks;
// Extend to include HookStates
_renderCallbacks?: Array<HookState | (() => void)>;
_hasScuFromHooks?: boolean;
}
export interface VNode extends Omit<PreactVNode, '_component'> {
_mask?: [number, number];
_component?: Component; // Override with our specific Component type
}
export type HookState =
| EffectHookState
| MemoHookState
| ReducerHookState
| ContextHookState
| ErrorBoundaryHookState
| IdHookState;
interface BaseHookState {
_value?: unknown;
_nextValue?: unknown;
_pendingValue?: unknown;
_args?: unknown;
_pendingArgs?: unknown;
_component?: unknown;
_cleanup?: unknown;
}
export type Effect = () => void | Cleanup;
export type Cleanup = () => void;
export interface EffectHookState extends BaseHookState {
_value?: Effect;
_args?: unknown[];
_pendingArgs?: unknown[];
_cleanup?: Cleanup | void;
}
export interface MemoHookState<T = unknown> extends BaseHookState {
_value?: T;
_pendingValue?: T;
_args?: unknown[];
_pendingArgs?: unknown[];
_factory?: () => T;
}
export interface ReducerHookState<S = unknown, A = unknown>
extends BaseHookState {
_nextValue?: [S, StateUpdater<S>];
_value?: [S, StateUpdater<S>];
_component?: Component;
_reducer?: Reducer<S, A>;
}
export interface ContextHookState extends BaseHookState {
/** Whether this hooks as subscribed to updates yet */
_value?: boolean;
_context?: PreactContext;
}
export interface ErrorBoundaryHookState extends BaseHookState {
_value?: (error: unknown, errorInfo: ErrorInfo) => void;
}
export interface IdHookState extends BaseHookState {
_value?: string;
}