@yakocloud/state-vocab 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -331,7 +331,6 @@ createRoot(document.getElementById('root')!).render(
331
331
  | `storage` | `Storage \| (() => Storage) \| undefined` | `undefined` (in-memory) |
332
332
  | `defaultValue` | `T \| undefined` | `undefined` |
333
333
  | `bidirectional` | `true \| undefined` | `undefined` |
334
- | `autoSet` | `true \| undefined` | `undefined` |
335
334
  | `serialize` | `(v: T) => string` | `JSON.stringify` |
336
335
  | `deserialize` | `(v: string) => T` | `JSON.parse` |
337
336
 
@@ -351,6 +350,5 @@ React context provider. Must be an ancestor of any component using `.useState()`
351
350
  | `options.delayedSet` | `number \| undefined` | Debounce delay for `onSet` in ms |
352
351
  | `options.onSet` | `(next: D, prev: D) => void \| undefined` | Callback after state change |
353
352
  | `options.bidirectional` | `true \| undefined` | bidirectional state update to sync tabs |
354
- | `options.autoSet` | `true \| undefined` | set the passed default value |
355
353
 
356
354
  Returns `[value, setValue, resetValue]`.
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),te=Symbol("state-def"),C=Symbol("state-path"),z=Symbol("state-ssr-support");function ie(t,s,o){if(!s)return t;const a=s.split(".");let r=t;for(const c of a)if(r!==null&&typeof r=="object"&&c in r)r=r[c];else return o;return r===void 0?o:r}function fe(t,s,o){const a=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(let c=0;c<a.length-1;c++){const u=a[c],l=a[c+1];(r[u]===void 0||r[u]===null)&&(r[u]=/^\d+$/.test(l)?[]:{}),r=r[u]}return r[a[a.length-1]]=o,t}function de(t,s=0){let o;return function(...a){o!==void 0&&clearTimeout(o),o=setTimeout(()=>{o=void 0,t.apply(this,a)},s)}}function me(t,s,o=[]){return S.useMemo(()=>de(t,s),o)}function be(t){const s=JSON.stringify(t,null,2).split(`
2
- `),o=[],a=[];for(const r of s){const c=r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(c){const[,u,l,_,d]=c;o.push(`${u}%c"${l}"%c${_}%c${d}`),a.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else o.push(`%c${r}`),a.push("color: #cccccc")}console.log(o.join(`
3
- `),...a,t)}var V={exports:{}},O={};var B;function ve(){if(B)return O;B=1;var t=Symbol.for("react.transitional.element"),s=Symbol.for("react.fragment");function o(a,r,c){var u=null;if(c!==void 0&&(u=""+c),r.key!==void 0&&(u=""+r.key),"key"in r){c={};for(var l in r)l!=="key"&&(c[l]=r[l])}else c=r;return r=c.ref,{$$typeof:t,type:a,key:u,ref:r!==void 0?r:null,props:c}}return O.Fragment=s,O.jsx=o,O.jsxs=o,O}var A={};var H;function Ee(){return H||(H=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ce?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case E:return"Fragment";case P:return"Profiler";case g:return"StrictMode";case x:return"Suspense";case oe:return"SuspenseList";case se:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case k:return"Portal";case h:return e.displayName||"Context";case v:return(e._context.displayName||"Context")+".Consumer";case I:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ae:return n=e.displayName||null,n!==null?n:t(e.type)||"Memo";case M:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function s(e){return""+e}function o(e){try{s(e);var n=!1}catch{n=!0}if(n){n=console;var i=n.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),s(e)}}function a(e){if(e===E)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===M)return"<...>";try{var n=t(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function r(){var e=Y.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function u(e){if(W.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function l(e,n){function i(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",n))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function _(){var e=t(this.type);return U[e]||(U[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function d(e,n,i,m,j,F){var b=i.ref;return e={$$typeof:T,type:e,key:n,props:i,_owner:m},(b!==void 0?b:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:_}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:j}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:F}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function f(e,n,i,m,j,F){var b=n.children;if(b!==void 0)if(m)if(ue(b)){for(m=0;m<b.length;m++)p(b[m]);Object.freeze&&Object.freeze(b)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else p(b);if(W.call(n,"key")){b=t(e);var w=Object.keys(n).filter(function(le){return le!=="key"});m=0<w.length?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}",X[b+m]||(w=0<w.length?"{"+w.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),te=Symbol("state-def"),C=Symbol("state-path"),L=Symbol("state-ssr");function fe(t,a,s){if(!a)return t;const n=a.split(".");let r=t;for(const c of n)if(r!==null&&typeof r=="object"&&c in r)r=r[c];else return s;return r===void 0?s:r}function de(t,a,s){const n=a.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(let c=0;c<n.length-1;c++){const i=n[c],b=n[c+1];(r[i]===void 0||r[i]===null)&&(r[i]=/^\d+$/.test(b)?[]:{}),r=r[i]}return r[n[n.length-1]]=s,t}function me(t,a=0){let s;return function(...n){s!==void 0&&clearTimeout(s),s=setTimeout(()=>{s=void 0,t.apply(this,n)},a)}}function be(t,a,s=[]){return S.useMemo(()=>me(t,a),s)}function ve(t){const a=JSON.stringify(t,null,2).split(`
2
+ `),s=[],n=[];for(const r of a){const c=r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(c){const[,i,b,v,u]=c;s.push(`${i}%c"${b}"%c${v}%c${u}`),n.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else s.push(`%c${r}`),n.push("color: #cccccc")}console.log(s.join(`
3
+ `),...n,t)}var V={exports:{}},x={};var B;function Ee(){if(B)return x;B=1;var t=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function s(n,r,c){var i=null;if(c!==void 0&&(i=""+c),r.key!==void 0&&(i=""+r.key),"key"in r){c={};for(var b in r)b!=="key"&&(c[b]=r[b])}else c=r;return r=c.ref,{$$typeof:t,type:n,key:i,ref:r!==void 0?r:null,props:c}}return x.Fragment=a,x.jsx=s,x.jsxs=s,x}var O={};var H;function Se(){return H||(H=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ue?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case h:return"Fragment";case m:return"Profiler";case k:return"StrictMode";case oe:return"Suspense";case ae:return"SuspenseList";case ce:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case _:return"Portal";case $:return e.displayName||"Context";case g:return(e._context.displayName||"Context")+".Consumer";case w:var o=e.render;return e=e.displayName,e||(e=o.displayName||o.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case se:return o=e.displayName||null,o!==null?o:t(e.type)||"Memo";case I:o=e._payload,e=e._init;try{return t(e(o))}catch{}}return null}function a(e){return""+e}function s(e){try{a(e);var o=!1}catch{o=!0}if(o){o=console;var l=o.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),a(e)}}function n(e){if(e===h)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===I)return"<...>";try{var o=t(e);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function r(){var e=M.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function i(e){if(W.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function b(e,o){function l(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",o))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function v(){var e=t(this.type);return U[e]||(U[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function u(e,o,l,f,j,D){var d=l.ref;return e={$$typeof:T,type:e,key:o,props:l,_owner:f},(d!==void 0?d:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:v}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:j}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function y(e,o,l,f,j,D){var d=o.children;if(d!==void 0)if(f)if(le(d)){for(f=0;f<d.length;f++)E(d[f]);Object.freeze&&Object.freeze(d)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else E(d);if(W.call(o,"key")){d=t(e);var P=Object.keys(o).filter(function(ie){return ie!=="key"});f=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",X[d+f]||(P=0<P.length?"{"+P.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
4
4
  let props = %s;
5
5
  <%s {...props} />
6
6
  React keys must be passed directly to JSX without using spread:
7
7
  let props = %s;
8
- <%s key={someKey} {...props} />`,m,b,w,b),X[b+m]=!0)}if(b=null,i!==void 0&&(o(i),b=""+i),u(n)&&(o(n.key),b=""+n.key),"key"in n){i={};for(var L in n)L!=="key"&&(i[L]=n[L])}else i=n;return b&&l(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),d(e,b,i,r(),j,F)}function p(e){R(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===M&&(e._payload.status==="fulfilled"?R(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function R(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}var y=S,T=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),P=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),h=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),Y=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,ue=Array.isArray,D=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(e){return e()}};var J,U={},q=y.react_stack_bottom_frame.bind(y,c)(),G=D(a(c)),X={};A.Fragment=E,A.jsx=function(e,n,i){var m=1e4>Y.recentlyCreatedOwnerStacks++;return f(e,n,i,!1,m?Error("react-stack-top-frame"):q,m?D(a(e)):G)},A.jsxs=function(e,n,i){var m=1e4>Y.recentlyCreatedOwnerStacks++;return f(e,n,i,!0,m?Error("react-stack-top-frame"):q,m?D(a(e)):G)}})()),A}var Z;function Se(){return Z||(Z=1,process.env.NODE_ENV==="production"?V.exports=ve():V.exports=Ee()),V.exports}var pe=Se();const re=S.createContext({stateVocab:{},setStateVocab:()=>{}});function _e(){return S.useContext(re)}const Re=t=>{const{children:s,verbose:o}=t,[a,r]=S.useState({});return o&&be(a),pe.jsx(re.Provider,{value:{stateVocab:a,setStateVocab:r},children:s})},N=(t,s)=>o=>{const a={...o};return fe(a,t,s),a},Q=t=>{const{serialized:s,defaultValue:o,superDefaultValue:a,deserialize:r}=t;if(s===null){const c=$(o)??a;return typeof c>"u"?void 0:c}return r(s)},Te=t=>typeof t=="function",ye=t=>typeof t=="function",$=t=>ye(t)?t():t,ge=typeof window>"u";function he(t={}){const{serialize:s=JSON.stringify,deserialize:o=JSON.parse}=t,a=t.defaultValue,r=t.bidirectional,c=t.autoSet,u=ge?void 0:$(t.storage);return{[te]:!0,[z]:!1,[C]:"",useState(l){l??={};const _=me(l.onSet??(()=>{}),l.delayedSet,[]),d=_e(),f=this[C],p=this[z],[R,y]=S.useState(!p);S.useEffect(()=>y(!0),[]);const T=S.useMemo(()=>{if(!R||!u)return;const v=u.getItem(f);return Q({defaultValue:l.defaultValue,serialized:v,superDefaultValue:a,deserialize:o})},[f,R]),k=S.useMemo(()=>ie(d.stateVocab,f,T??$(l.defaultValue)??a),[d.stateVocab,T,f]);S.useEffect(()=>{!u||typeof T>"u"||d.setStateVocab(N(f,T))},[T]),S.useEffect(()=>{if(!l.bidirectional&&!r)return;const v=h=>{if(h.key!==f)return;const I=h.newValue,x=Q({defaultValue:l.defaultValue,superDefaultValue:a,serialized:I,deserialize:o});d.setStateVocab(N(f,x)),_(x,E.current),E.current=x};return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)},[f,l.bidirectional,r]);const E=S.useRef(k),g=v=>{const h=Te(v)?v(E.current):v;d.setStateVocab(N(f,h)),_(h,E.current),u&&u.setItem(f,s(h)),E.current=h},P=()=>{const v=$(l.defaultValue)??a;if(typeof v>"u"){u?.removeItem(f);return}d.setStateVocab(N(f,v)),_(v,E.current),E.current=v,u&&u.setItem(f,s(v))};return S.useEffect(()=>{(l.autoSet||c)&&g(k)},[]),[k,g,P]},toString(){return this[C]}}}const K=new WeakMap,ee=new WeakMap;function ne(t,s){s??={};const{path:o="",ssr:a}=s;let r=K.get(t);r||(r=new Map,K.set(t,r));const c=r.get(o);if(c)return c;const u=new Proxy(t,{get(l,_){const d=l[_],f=o?`${o}.${String(_)}`:String(_);if(d&&typeof d=="object"&&te in d){const p=d;let R=ee.get(p);R||(R=new Map,ee.set(p,R));const y=R.get(f);if(y)return y;const T=Reflect.ownKeys(p).filter(g=>typeof p[g]=="function"),k=Object.fromEntries(T.map(g=>[g,(...P)=>p[g].call({...p,[C]:f,[z]:a},...P)])),E={...p,...k};return R.set(f,E),E}return d&&typeof d=="object"?ne(d,{path:f,ssr:a}):d}});return r.set(o,u),u}function ke(t,s){return ne(t,s)}exports.StorageProvider=Re;exports.defineState=he;exports.setupStorage=ke;
8
+ <%s key={someKey} {...props} />`,f,d,P,d),X[d+f]=!0)}if(d=null,l!==void 0&&(s(l),d=""+l),i(o)&&(s(o.key),d=""+o.key),"key"in o){l={};for(var F in o)F!=="key"&&(l[F]=o[F])}else l=o;return d&&b(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),u(e,d,l,r(),j,D)}function E(e){p(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===I&&(e._payload.status==="fulfilled"?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}var R=S,T=Symbol.for("react.transitional.element"),_=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),m=Symbol.for("react.profiler"),g=Symbol.for("react.consumer"),$=Symbol.for("react.context"),w=Symbol.for("react.forward_ref"),oe=Symbol.for("react.suspense"),ae=Symbol.for("react.suspense_list"),se=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),ce=Symbol.for("react.activity"),ue=Symbol.for("react.client.reference"),M=R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,le=Array.isArray,Y=console.createTask?console.createTask:function(){return null};R={react_stack_bottom_frame:function(e){return e()}};var J,U={},q=R.react_stack_bottom_frame.bind(R,c)(),G=Y(n(c)),X={};O.Fragment=h,O.jsx=function(e,o,l){var f=1e4>M.recentlyCreatedOwnerStacks++;return y(e,o,l,!1,f?Error("react-stack-top-frame"):q,f?Y(n(e)):G)},O.jsxs=function(e,o,l){var f=1e4>M.recentlyCreatedOwnerStacks++;return y(e,o,l,!0,f?Error("react-stack-top-frame"):q,f?Y(n(e)):G)}})()),O}var Z;function _e(){return Z||(Z=1,process.env.NODE_ENV==="production"?V.exports=Ee():V.exports=Se()),V.exports}var pe=_e();const re=S.createContext({stateVocab:{},setStateVocab:()=>{}});function Re(){return S.useContext(re)}const Te=t=>{const{children:a,verbose:s}=t,[n,r]=S.useState({});return s&&ve(n),pe.jsx(re.Provider,{value:{stateVocab:n,setStateVocab:r},children:a})},N=(t,a)=>s=>{const n={...s};return de(n,t,a),n},Q=t=>{const{serialized:a,deserialize:s}=t;return a===null?null:s(a)},ye=t=>typeof t=="function",ge=t=>typeof t=="function",z=t=>typeof t<"u",A=t=>ge(t)?t():t,he=typeof window>"u";function ke(t={}){const a=he?void 0:A(t.storage),s=t.bidirectional;return{[te]:!0,[L]:!1,[C]:"",useState(n){const r=t.serialize??JSON.stringify,c=t.deserialize??JSON.parse,i=t.defaultValue;n??={};const b=be(n.onSet??(()=>{}),n.delayedSet,[]),v=Re(),u=this[C],y=this[L],[E,p]=S.useState(!y);S.useEffect(()=>p(!0),[]);const R=S.useMemo(()=>{if(!E||!a)return;const m=a.getItem(u);return Q({deserialize:c,serialized:m})??A(n.defaultValue)??i},[E]),T=S.useMemo(()=>fe(v.stateVocab,u,R??A(n.defaultValue)??i),[v.stateVocab,R,u]);S.useEffect(()=>{z(T)&&v.setStateVocab(N(u,T))},[T]),S.useEffect(()=>{if(!n.bidirectional&&!s)return;const m=g=>{if(g.key!==u)return;const $=g.newValue,w=Q({serialized:$,deserialize:c})??A(n.defaultValue)??i;z(w)&&(v.setStateVocab(N(u,w)),b(w,_.current),_.current=w)};return window.addEventListener("storage",m),()=>window.removeEventListener("storage",m)},[u,n.bidirectional,s]);const _=S.useRef(T);return[T,m=>{const g=ye(m)?m(_.current):m;v.setStateVocab(N(u,g)),b(g,_.current),a&&a.setItem(u,r(g)),_.current=g},()=>{const m=A(n.defaultValue)??i;if(!z(m)){a?.removeItem(u);return}v.setStateVocab(N(u,m)),b(m,_.current),_.current=m,a&&a.setItem(u,r(m))}]},toString(){return this[C]}}}const K=new WeakMap,ee=new WeakMap;function ne(t,a){a??={};const{path:s="",ssr:n}=a;let r=K.get(t);r||(r=new Map,K.set(t,r));const c=r.get(s);if(c)return c;const i=new Proxy(t,{get(b,v){const u=b[v],y=s?`${s}.${String(v)}`:String(v);if(u&&typeof u=="object"&&te in u){const E=u;let p=ee.get(E);p||(p=new Map,ee.set(E,p));const R=p.get(y);if(R)return R;const T=Reflect.ownKeys(E).filter(k=>typeof E[k]=="function"),_=Object.fromEntries(T.map(k=>[k,(...m)=>E[k].call({...E,[C]:y,[L]:n},...m)])),h={...E,..._};return p.set(y,h),h}return u&&typeof u=="object"?ne(u,{path:y,ssr:n}):u}});return r.set(s,i),i}function we(t,a){return ne(t,a)}exports.StorageProvider=Te;exports.defineState=ke;exports.setupStorage=we;
@@ -1,203 +1,203 @@
1
- import de, { useMemo as z, createContext as me, useState as re, useContext as be, useEffect as V, useRef as ve } from "react";
2
- const ne = Symbol("state-def"), C = Symbol("state-path"), W = Symbol("state-ssr-support");
3
- function Ee(t, s, o) {
4
- if (!s)
1
+ import me, { useMemo as L, createContext as be, useState as re, useContext as ve, useEffect as M, useRef as Ee } from "react";
2
+ const ne = Symbol("state-def"), N = Symbol("state-path"), W = Symbol("state-ssr");
3
+ function _e(t, a, s) {
4
+ if (!a)
5
5
  return t;
6
- const a = s.split(".");
6
+ const n = a.split(".");
7
7
  let r = t;
8
- for (const c of a)
8
+ for (const c of n)
9
9
  if (r !== null && typeof r == "object" && c in r)
10
10
  r = r[c];
11
11
  else
12
- return o;
13
- return r === void 0 ? o : r;
12
+ return s;
13
+ return r === void 0 ? s : r;
14
14
  }
15
- function pe(t, s, o) {
16
- const a = s.replace(/\[(\d+)\]/g, ".$1").split(".");
15
+ function pe(t, a, s) {
16
+ const n = a.replace(/\[(\d+)\]/g, ".$1").split(".");
17
17
  let r = t;
18
- for (let c = 0; c < a.length - 1; c++) {
19
- const u = a[c], l = a[c + 1];
20
- (r[u] === void 0 || r[u] === null) && (r[u] = /^\d+$/.test(l) ? [] : {}), r = r[u];
18
+ for (let c = 0; c < n.length - 1; c++) {
19
+ const i = n[c], b = n[c + 1];
20
+ (r[i] === void 0 || r[i] === null) && (r[i] = /^\d+$/.test(b) ? [] : {}), r = r[i];
21
21
  }
22
- return r[a[a.length - 1]] = o, t;
22
+ return r[n[n.length - 1]] = s, t;
23
23
  }
24
- function _e(t, s = 0) {
25
- let o;
26
- return function(...a) {
27
- o !== void 0 && clearTimeout(o), o = setTimeout(() => {
28
- o = void 0, t.apply(this, a);
29
- }, s);
24
+ function Se(t, a = 0) {
25
+ let s;
26
+ return function(...n) {
27
+ s !== void 0 && clearTimeout(s), s = setTimeout(() => {
28
+ s = void 0, t.apply(this, n);
29
+ }, a);
30
30
  };
31
31
  }
32
- function Se(t, s, o = []) {
33
- return z(
34
- () => _e(t, s),
32
+ function Re(t, a, s = []) {
33
+ return L(
34
+ () => Se(t, a),
35
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
36
- o
36
+ s
37
37
  );
38
38
  }
39
- function Re(t) {
40
- const s = JSON.stringify(t, null, 2).split(`
41
- `), o = [], a = [];
42
- for (const r of s) {
39
+ function Te(t) {
40
+ const a = JSON.stringify(t, null, 2).split(`
41
+ `), s = [], n = [];
42
+ for (const r of a) {
43
43
  const c = r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
44
  if (c) {
45
- const [, u, l, _, d] = c;
46
- o.push(`${u}%c"${l}"%c${_}%c${d}`), a.push(
45
+ const [, i, b, v, u] = c;
46
+ s.push(`${i}%c"${b}"%c${v}%c${u}`), n.push(
47
47
  "color: #9cdcfe; font-weight: bold",
48
48
  "color: #cccccc",
49
49
  "color: #ce9178"
50
50
  );
51
51
  } else
52
- o.push(`%c${r}`), a.push("color: #cccccc");
52
+ s.push(`%c${r}`), n.push("color: #cccccc");
53
53
  }
54
- console.log(o.join(`
55
- `), ...a, t);
54
+ console.log(s.join(`
55
+ `), ...n, t);
56
56
  }
57
- var j = { exports: {} }, x = {};
57
+ var j = { exports: {} }, P = {};
58
58
  var H;
59
- function Te() {
60
- if (H) return x;
59
+ function ye() {
60
+ if (H) return P;
61
61
  H = 1;
62
- var t = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
63
- function o(a, r, c) {
64
- var u = null;
65
- if (c !== void 0 && (u = "" + c), r.key !== void 0 && (u = "" + r.key), "key" in r) {
62
+ var t = Symbol.for("react.transitional.element"), a = Symbol.for("react.fragment");
63
+ function s(n, r, c) {
64
+ var i = null;
65
+ if (c !== void 0 && (i = "" + c), r.key !== void 0 && (i = "" + r.key), "key" in r) {
66
66
  c = {};
67
- for (var l in r)
68
- l !== "key" && (c[l] = r[l]);
67
+ for (var b in r)
68
+ b !== "key" && (c[b] = r[b]);
69
69
  } else c = r;
70
70
  return r = c.ref, {
71
71
  $$typeof: t,
72
- type: a,
73
- key: u,
72
+ type: n,
73
+ key: i,
74
74
  ref: r !== void 0 ? r : null,
75
75
  props: c
76
76
  };
77
77
  }
78
- return x.Fragment = s, x.jsx = o, x.jsxs = o, x;
78
+ return P.Fragment = a, P.jsx = s, P.jsxs = s, P;
79
79
  }
80
- var A = {};
80
+ var x = {};
81
81
  var Z;
82
- function ye() {
82
+ function he() {
83
83
  return Z || (Z = 1, process.env.NODE_ENV !== "production" && (function() {
84
84
  function t(e) {
85
85
  if (e == null) return null;
86
86
  if (typeof e == "function")
87
- return e.$$typeof === le ? null : e.displayName || e.name || null;
87
+ return e.$$typeof === ie ? null : e.displayName || e.name || null;
88
88
  if (typeof e == "string") return e;
89
89
  switch (e) {
90
- case E:
90
+ case h:
91
91
  return "Fragment";
92
- case w:
92
+ case m:
93
93
  return "Profiler";
94
- case y:
94
+ case g:
95
95
  return "StrictMode";
96
- case P:
97
- return "Suspense";
98
96
  case se:
97
+ return "Suspense";
98
+ case ce:
99
99
  return "SuspenseList";
100
- case ue:
100
+ case le:
101
101
  return "Activity";
102
102
  }
103
103
  if (typeof e == "object")
104
104
  switch (typeof e.tag == "number" && console.error(
105
105
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
106
106
  ), e.$$typeof) {
107
- case g:
107
+ case _:
108
108
  return "Portal";
109
- case h:
109
+ case C:
110
110
  return e.displayName || "Context";
111
- case v:
111
+ case y:
112
112
  return (e._context.displayName || "Context") + ".Consumer";
113
- case I:
114
- var n = e.render;
115
- return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
116
- case ce:
117
- return n = e.displayName || null, n !== null ? n : t(e.type) || "Memo";
118
- case Y:
119
- n = e._payload, e = e._init;
113
+ case k:
114
+ var o = e.render;
115
+ return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
116
+ case ue:
117
+ return o = e.displayName || null, o !== null ? o : t(e.type) || "Memo";
118
+ case $:
119
+ o = e._payload, e = e._init;
120
120
  try {
121
- return t(e(n));
121
+ return t(e(o));
122
122
  } catch {
123
123
  }
124
124
  }
125
125
  return null;
126
126
  }
127
- function s(e) {
127
+ function a(e) {
128
128
  return "" + e;
129
129
  }
130
- function o(e) {
130
+ function s(e) {
131
131
  try {
132
- s(e);
133
- var n = !1;
132
+ a(e);
133
+ var o = !1;
134
134
  } catch {
135
- n = !0;
135
+ o = !0;
136
136
  }
137
- if (n) {
138
- n = console;
139
- var i = n.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
140
- return i.call(
141
- n,
137
+ if (o) {
138
+ o = console;
139
+ var l = o.error, f = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
140
+ return l.call(
141
+ o,
142
142
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
143
- m
144
- ), s(e);
143
+ f
144
+ ), a(e);
145
145
  }
146
146
  }
147
- function a(e) {
148
- if (e === E) return "<>";
149
- if (typeof e == "object" && e !== null && e.$$typeof === Y)
147
+ function n(e) {
148
+ if (e === h) return "<>";
149
+ if (typeof e == "object" && e !== null && e.$$typeof === $)
150
150
  return "<...>";
151
151
  try {
152
- var n = t(e);
153
- return n ? "<" + n + ">" : "<...>";
152
+ var o = t(e);
153
+ return o ? "<" + o + ">" : "<...>";
154
154
  } catch {
155
155
  return "<...>";
156
156
  }
157
157
  }
158
158
  function r() {
159
- var e = D.A;
159
+ var e = I.A;
160
160
  return e === null ? null : e.getOwner();
161
161
  }
162
162
  function c() {
163
163
  return Error("react-stack-top-frame");
164
164
  }
165
- function u(e) {
165
+ function i(e) {
166
166
  if (J.call(e, "key")) {
167
- var n = Object.getOwnPropertyDescriptor(e, "key").get;
168
- if (n && n.isReactWarning) return !1;
167
+ var o = Object.getOwnPropertyDescriptor(e, "key").get;
168
+ if (o && o.isReactWarning) return !1;
169
169
  }
170
170
  return e.key !== void 0;
171
171
  }
172
- function l(e, n) {
173
- function i() {
172
+ function b(e, o) {
173
+ function l() {
174
174
  U || (U = !0, console.error(
175
175
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
176
- n
176
+ o
177
177
  ));
178
178
  }
179
- i.isReactWarning = !0, Object.defineProperty(e, "key", {
180
- get: i,
179
+ l.isReactWarning = !0, Object.defineProperty(e, "key", {
180
+ get: l,
181
181
  configurable: !0
182
182
  });
183
183
  }
184
- function _() {
184
+ function v() {
185
185
  var e = t(this.type);
186
186
  return q[e] || (q[e] = !0, console.error(
187
187
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
188
188
  )), e = this.props.ref, e !== void 0 ? e : null;
189
189
  }
190
- function d(e, n, i, m, O, M) {
191
- var b = i.ref;
190
+ function u(e, o, l, f, O, D) {
191
+ var d = l.ref;
192
192
  return e = {
193
193
  $$typeof: R,
194
194
  type: e,
195
- key: n,
196
- props: i,
197
- _owner: m
198
- }, (b !== void 0 ? b : null) !== null ? Object.defineProperty(e, "ref", {
195
+ key: o,
196
+ props: l,
197
+ _owner: f
198
+ }, (d !== void 0 ? d : null) !== null ? Object.defineProperty(e, "ref", {
199
199
  enumerable: !1,
200
- get: _
200
+ get: v
201
201
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
202
202
  configurable: !1,
203
203
  enumerable: !1,
@@ -217,276 +217,259 @@ function ye() {
217
217
  configurable: !1,
218
218
  enumerable: !1,
219
219
  writable: !0,
220
- value: M
220
+ value: D
221
221
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
222
222
  }
223
- function f(e, n, i, m, O, M) {
224
- var b = n.children;
225
- if (b !== void 0)
226
- if (m)
227
- if (ie(b)) {
228
- for (m = 0; m < b.length; m++)
229
- p(b[m]);
230
- Object.freeze && Object.freeze(b);
223
+ function T(e, o, l, f, O, D) {
224
+ var d = o.children;
225
+ if (d !== void 0)
226
+ if (f)
227
+ if (fe(d)) {
228
+ for (f = 0; f < d.length; f++)
229
+ E(d[f]);
230
+ Object.freeze && Object.freeze(d);
231
231
  } else
232
232
  console.error(
233
233
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
234
234
  );
235
- else p(b);
236
- if (J.call(n, "key")) {
237
- b = t(e);
238
- var k = Object.keys(n).filter(function(fe) {
239
- return fe !== "key";
235
+ else E(d);
236
+ if (J.call(o, "key")) {
237
+ d = t(e);
238
+ var w = Object.keys(o).filter(function(de) {
239
+ return de !== "key";
240
240
  });
241
- m = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", B[b + m] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
241
+ f = 0 < w.length ? "{key: someKey, " + w.join(": ..., ") + ": ...}" : "{key: someKey}", B[d + f] || (w = 0 < w.length ? "{" + w.join(": ..., ") + ": ...}" : "{}", console.error(
242
242
  `A props object containing a "key" prop is being spread into JSX:
243
243
  let props = %s;
244
244
  <%s {...props} />
245
245
  React keys must be passed directly to JSX without using spread:
246
246
  let props = %s;
247
247
  <%s key={someKey} {...props} />`,
248
- m,
249
- b,
250
- k,
251
- b
252
- ), B[b + m] = !0);
248
+ f,
249
+ d,
250
+ w,
251
+ d
252
+ ), B[d + f] = !0);
253
253
  }
254
- if (b = null, i !== void 0 && (o(i), b = "" + i), u(n) && (o(n.key), b = "" + n.key), "key" in n) {
255
- i = {};
256
- for (var L in n)
257
- L !== "key" && (i[L] = n[L]);
258
- } else i = n;
259
- return b && l(
260
- i,
254
+ if (d = null, l !== void 0 && (s(l), d = "" + l), i(o) && (s(o.key), d = "" + o.key), "key" in o) {
255
+ l = {};
256
+ for (var F in o)
257
+ F !== "key" && (l[F] = o[F]);
258
+ } else l = o;
259
+ return d && b(
260
+ l,
261
261
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
262
- ), d(
262
+ ), u(
263
263
  e,
264
- b,
265
- i,
264
+ d,
265
+ l,
266
266
  r(),
267
267
  O,
268
- M
268
+ D
269
269
  );
270
270
  }
271
- function p(e) {
272
- S(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === Y && (e._payload.status === "fulfilled" ? S(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
271
+ function E(e) {
272
+ p(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === $ && (e._payload.status === "fulfilled" ? p(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
273
273
  }
274
- function S(e) {
274
+ function p(e) {
275
275
  return typeof e == "object" && e !== null && e.$$typeof === R;
276
276
  }
277
- var T = de, R = Symbol.for("react.transitional.element"), g = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), w = Symbol.for("react.profiler"), v = Symbol.for("react.consumer"), h = Symbol.for("react.context"), I = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), se = Symbol.for("react.suspense_list"), ce = Symbol.for("react.memo"), Y = Symbol.for("react.lazy"), ue = Symbol.for("react.activity"), le = Symbol.for("react.client.reference"), D = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ie = Array.isArray, F = console.createTask ? console.createTask : function() {
277
+ var S = me, R = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), m = Symbol.for("react.profiler"), y = Symbol.for("react.consumer"), C = Symbol.for("react.context"), k = Symbol.for("react.forward_ref"), se = Symbol.for("react.suspense"), ce = Symbol.for("react.suspense_list"), ue = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ie = Symbol.for("react.client.reference"), I = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, fe = Array.isArray, Y = console.createTask ? console.createTask : function() {
278
278
  return null;
279
279
  };
280
- T = {
280
+ S = {
281
281
  react_stack_bottom_frame: function(e) {
282
282
  return e();
283
283
  }
284
284
  };
285
- var U, q = {}, G = T.react_stack_bottom_frame.bind(
286
- T,
285
+ var U, q = {}, G = S.react_stack_bottom_frame.bind(
286
+ S,
287
287
  c
288
- )(), X = F(a(c)), B = {};
289
- A.Fragment = E, A.jsx = function(e, n, i) {
290
- var m = 1e4 > D.recentlyCreatedOwnerStacks++;
291
- return f(
288
+ )(), X = Y(n(c)), B = {};
289
+ x.Fragment = h, x.jsx = function(e, o, l) {
290
+ var f = 1e4 > I.recentlyCreatedOwnerStacks++;
291
+ return T(
292
292
  e,
293
- n,
294
- i,
293
+ o,
294
+ l,
295
295
  !1,
296
- m ? Error("react-stack-top-frame") : G,
297
- m ? F(a(e)) : X
296
+ f ? Error("react-stack-top-frame") : G,
297
+ f ? Y(n(e)) : X
298
298
  );
299
- }, A.jsxs = function(e, n, i) {
300
- var m = 1e4 > D.recentlyCreatedOwnerStacks++;
301
- return f(
299
+ }, x.jsxs = function(e, o, l) {
300
+ var f = 1e4 > I.recentlyCreatedOwnerStacks++;
301
+ return T(
302
302
  e,
303
- n,
304
- i,
303
+ o,
304
+ l,
305
305
  !0,
306
- m ? Error("react-stack-top-frame") : G,
307
- m ? F(a(e)) : X
306
+ f ? Error("react-stack-top-frame") : G,
307
+ f ? Y(n(e)) : X
308
308
  );
309
309
  };
310
- })()), A;
310
+ })()), x;
311
311
  }
312
312
  var Q;
313
- function he() {
314
- return Q || (Q = 1, process.env.NODE_ENV === "production" ? j.exports = Te() : j.exports = ye()), j.exports;
313
+ function ge() {
314
+ return Q || (Q = 1, process.env.NODE_ENV === "production" ? j.exports = ye() : j.exports = he()), j.exports;
315
315
  }
316
- var ge = he();
317
- const oe = me({
316
+ var ke = ge();
317
+ const oe = be({
318
318
  stateVocab: {},
319
319
  setStateVocab: () => {
320
320
  }
321
321
  });
322
- function ke() {
323
- return be(oe);
322
+ function we() {
323
+ return ve(oe);
324
324
  }
325
- const Oe = (t) => {
326
- const { children: s, verbose: o } = t, [a, r] = re({});
327
- return o && Re(a), /* @__PURE__ */ ge.jsx(oe.Provider, { value: { stateVocab: a, setStateVocab: r }, children: s });
328
- }, N = (t, s) => (o) => {
329
- const a = { ...o };
330
- return pe(a, t, s), a;
325
+ const je = (t) => {
326
+ const { children: a, verbose: s } = t, [n, r] = re({});
327
+ return s && Te(n), /* @__PURE__ */ ke.jsx(oe.Provider, { value: { stateVocab: n, setStateVocab: r }, children: a });
328
+ }, V = (t, a) => (s) => {
329
+ const n = { ...s };
330
+ return pe(n, t, a), n;
331
331
  }, K = (t) => {
332
- const { serialized: s, defaultValue: o, superDefaultValue: a, deserialize: r } = t;
333
- if (s === null) {
334
- const c = $(o) ?? a;
335
- return typeof c > "u" ? void 0 : c;
336
- }
337
- return r(s);
338
- }, we = (t) => typeof t == "function", Pe = (t) => typeof t == "function", $ = (t) => Pe(t) ? t() : t, xe = typeof window > "u";
332
+ const { serialized: a, deserialize: s } = t;
333
+ return a === null ? null : s(a);
334
+ }, Pe = (t) => typeof t == "function", xe = (t) => typeof t == "function", z = (t) => typeof t < "u", A = (t) => xe(t) ? t() : t, Ae = typeof window > "u";
339
335
  function Ve(t = {}) {
340
- const {
341
- serialize: s = JSON.stringify,
342
- deserialize: o = JSON.parse
343
- } = t, a = t.defaultValue, r = t.bidirectional, c = t.autoSet, u = xe ? void 0 : $(t.storage);
336
+ const a = Ae ? void 0 : A(t.storage), s = t.bidirectional;
344
337
  return {
345
338
  [ne]: !0,
346
339
  // marks this object as a leaf in the router tree
347
340
  [W]: !1,
348
341
  // placeholder; injected at runtime by injectPaths()
349
- [C]: "",
342
+ [N]: "",
350
343
  // placeholder; injected at runtime by injectPaths()
351
- useState(l) {
352
- l ??= {};
353
- const _ = Se(
354
- l.onSet ?? (() => {
344
+ useState(n) {
345
+ const r = t.serialize ?? JSON.stringify, c = t.deserialize ?? JSON.parse, i = t.defaultValue;
346
+ n ??= {};
347
+ const b = Re(
348
+ n.onSet ?? (() => {
355
349
  }),
356
- l.delayedSet,
350
+ n.delayedSet,
357
351
  []
358
- ), d = ke(), f = this[C], p = this[W], [S, T] = re(!p);
359
- V(() => T(!0), []);
360
- const R = z(
352
+ ), v = we(), u = this[N], T = this[W], [E, p] = re(!T);
353
+ M(() => p(!0), []);
354
+ const S = L(
361
355
  () => {
362
- if (!S || !u)
356
+ if (!E || !a)
363
357
  return;
364
- const v = u.getItem(f);
365
- return K({
366
- defaultValue: l.defaultValue,
367
- serialized: v,
368
- superDefaultValue: a,
369
- deserialize: o
370
- });
358
+ const m = a.getItem(u);
359
+ return K({ deserialize: c, serialized: m }) ?? A(n.defaultValue) ?? i;
371
360
  },
372
361
  // eslint-disable-next-line react-hooks/exhaustive-deps
373
- [f, S]
374
- ), g = z(
375
- () => Ee(
376
- d.stateVocab,
377
- f,
378
- R ?? $(l.defaultValue) ?? a
362
+ [E]
363
+ ), R = L(
364
+ () => _e(
365
+ v.stateVocab,
366
+ u,
367
+ // 3rd argument in order to avoid waiting for useEffect execution
368
+ S ?? A(n.defaultValue) ?? i
379
369
  ),
380
370
  // eslint-disable-next-line react-hooks/exhaustive-deps
381
371
  [
382
- d.stateVocab,
383
- R,
384
- f
372
+ v.stateVocab,
373
+ S,
374
+ u
385
375
  ]
386
376
  );
387
- V(
377
+ M(
388
378
  () => {
389
- !u || typeof R > "u" || d.setStateVocab(N(f, R));
379
+ z(R) && v.setStateVocab(V(u, R));
390
380
  },
391
381
  // eslint-disable-next-line react-hooks/exhaustive-deps
392
382
  [R]
393
- ), V(() => {
394
- if (!l.bidirectional && !r)
383
+ ), M(() => {
384
+ if (!n.bidirectional && !s)
395
385
  return;
396
- const v = (h) => {
397
- if (h.key !== f)
386
+ const m = (y) => {
387
+ if (y.key !== u)
398
388
  return;
399
- const I = h.newValue, P = K({
400
- defaultValue: l.defaultValue,
401
- superDefaultValue: a,
402
- serialized: I,
403
- deserialize: o
404
- });
405
- d.setStateVocab(N(f, P)), _(P, E.current), E.current = P;
389
+ const C = y.newValue, k = K({ serialized: C, deserialize: c }) ?? A(n.defaultValue) ?? i;
390
+ z(k) && (v.setStateVocab(V(u, k)), b(k, _.current), _.current = k);
406
391
  };
407
- return window.addEventListener("storage", v), () => window.removeEventListener("storage", v);
392
+ return window.addEventListener("storage", m), () => window.removeEventListener("storage", m);
408
393
  }, [
409
- f,
410
- l.bidirectional,
411
- r
394
+ u,
395
+ n.bidirectional,
396
+ s
412
397
  ]);
413
- const E = ve(g), y = (v) => {
414
- const h = we(v) ? v(E.current) : v;
415
- d.setStateVocab(N(f, h)), _(h, E.current), u && u.setItem(f, s(h)), E.current = h;
416
- }, w = () => {
417
- const v = $(l.defaultValue) ?? a;
418
- if (typeof v > "u") {
419
- u?.removeItem(f);
420
- return;
398
+ const _ = Ee(R);
399
+ return [
400
+ R,
401
+ (m) => {
402
+ const y = Pe(m) ? m(_.current) : m;
403
+ v.setStateVocab(V(u, y)), b(y, _.current), a && a.setItem(u, r(y)), _.current = y;
404
+ },
405
+ () => {
406
+ const m = A(n.defaultValue) ?? i;
407
+ if (!z(m)) {
408
+ a?.removeItem(u);
409
+ return;
410
+ }
411
+ v.setStateVocab(V(u, m)), b(m, _.current), _.current = m, a && a.setItem(u, r(m));
421
412
  }
422
- d.setStateVocab(N(f, v)), _(v, E.current), E.current = v, u && u.setItem(f, s(v));
423
- };
424
- return V(() => {
425
- (l.autoSet || c) && y(g);
426
- }, []), [
427
- g,
428
- y,
429
- w
430
413
  ];
431
414
  },
432
415
  /** Returns the fully qualified job name (dot-separated path). */
433
416
  toString() {
434
- return this[C];
417
+ return this[N];
435
418
  }
436
419
  };
437
420
  }
438
421
  const ee = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap();
439
- function ae(t, s) {
440
- s ??= {};
422
+ function ae(t, a) {
423
+ a ??= {};
441
424
  const {
442
- path: o = "",
443
- ssr: a
444
- } = s;
425
+ path: s = "",
426
+ ssr: n
427
+ } = a;
445
428
  let r = ee.get(t);
446
429
  r || (r = /* @__PURE__ */ new Map(), ee.set(t, r));
447
- const c = r.get(o);
430
+ const c = r.get(s);
448
431
  if (c)
449
432
  return c;
450
- const u = new Proxy(t, {
451
- get(l, _) {
452
- const d = l[_], f = o ? `${o}.${String(_)}` : String(_);
453
- if (d && typeof d == "object" && ne in d) {
454
- const p = d;
455
- let S = te.get(p);
456
- S || (S = /* @__PURE__ */ new Map(), te.set(p, S));
457
- const T = S.get(f);
458
- if (T)
459
- return T;
460
- const R = Reflect.ownKeys(p).filter(
461
- (y) => typeof p[y] == "function"
462
- ), g = Object.fromEntries(
463
- R.map((y) => [
464
- y,
465
- (...w) => p[y].call(
433
+ const i = new Proxy(t, {
434
+ get(b, v) {
435
+ const u = b[v], T = s ? `${s}.${String(v)}` : String(v);
436
+ if (u && typeof u == "object" && ne in u) {
437
+ const E = u;
438
+ let p = te.get(E);
439
+ p || (p = /* @__PURE__ */ new Map(), te.set(E, p));
440
+ const S = p.get(T);
441
+ if (S)
442
+ return S;
443
+ const R = Reflect.ownKeys(E).filter(
444
+ (g) => typeof E[g] == "function"
445
+ ), _ = Object.fromEntries(
446
+ R.map((g) => [
447
+ g,
448
+ (...m) => E[g].call(
466
449
  {
467
- ...p,
468
- [C]: f,
469
- [W]: a
450
+ ...E,
451
+ [N]: T,
452
+ [W]: n
470
453
  },
471
- ...w
454
+ ...m
472
455
  )
473
456
  ])
474
- ), E = { ...p, ...g };
475
- return S.set(f, E), E;
457
+ ), h = { ...E, ..._ };
458
+ return p.set(T, h), h;
476
459
  }
477
- return d && typeof d == "object" ? ae(d, {
478
- path: f,
479
- ssr: a
480
- }) : d;
460
+ return u && typeof u == "object" ? ae(u, {
461
+ path: T,
462
+ ssr: n
463
+ }) : u;
481
464
  }
482
465
  });
483
- return r.set(o, u), u;
466
+ return r.set(s, i), i;
484
467
  }
485
- function je(t, s) {
486
- return ae(t, s);
468
+ function Ne(t, a) {
469
+ return ae(t, a);
487
470
  }
488
471
  export {
489
- Oe as StorageProvider,
472
+ je as StorageProvider,
490
473
  Ve as defineState,
491
- je as setupStorage
474
+ Ne as setupStorage
492
475
  };
@@ -1,3 +1,3 @@
1
1
  export declare const STATE_DEFINITION: unique symbol;
2
2
  export declare const STATE_PATH: unique symbol;
3
- export declare const STATE_SSR_SUPPORT: unique symbol;
3
+ export declare const STATE_SSR: unique symbol;
@@ -1,24 +1,22 @@
1
- import { STATE_DEFINITION, STATE_PATH, STATE_SSR_SUPPORT } from "./constants";
2
- import type { ValueOrFactory, ValueOrTransformer } from "./types";
1
+ import { STATE_DEFINITION, STATE_PATH, STATE_SSR } from "./constants";
2
+ import type { Deserialize, Serialize, ValueOrFactory, ValueOrTransformer } from "./state.types";
3
3
  export declare function defineState<T>(definitionOptions?: {
4
4
  storage?: ValueOrFactory<Storage>;
5
5
  defaultValue?: T;
6
6
  bidirectional?: true;
7
- autoSet?: true;
8
- serialize?: (v: T) => string;
9
- deserialize?: (v: string) => T;
7
+ serialize?: Serialize<T>;
8
+ deserialize?: Deserialize<T>;
10
9
  }): {
11
10
  [STATE_DEFINITION]: boolean;
12
- [STATE_SSR_SUPPORT]: boolean;
11
+ [STATE_SSR]: boolean;
13
12
  [STATE_PATH]: string;
14
13
  useState<D = T>(this: {
15
14
  [STATE_PATH]: string;
16
- [STATE_SSR_SUPPORT]: boolean;
15
+ [STATE_SSR]: boolean;
17
16
  }, options?: {
18
17
  defaultValue?: ValueOrFactory<D>;
19
18
  delayedSet?: number;
20
19
  bidirectional?: true;
21
- autoSet?: true;
22
20
  onSet?(nextValue: NoInfer<D>, prevValue: NoInfer<D>): void;
23
21
  }): readonly [D, (nextValue: ValueOrTransformer<D>) => void, () => void];
24
22
  /** Returns the fully qualified job name (dot-separated path). */
@@ -1,3 +1,5 @@
1
+ export type Serialize<V = unknown> = (v: V) => string;
2
+ export type Deserialize<V = unknown> = (v: string) => V;
1
3
  export type Transformer<V> = (prev: V) => V;
2
4
  export type ValueOrTransformer<V> = V | Transformer<V>;
3
5
  export type Factory<V> = () => V;
@@ -1,13 +1,12 @@
1
1
  import type { Vocab } from "./context";
2
- import type { ValueOrTransformer, Transformer, ValueOrFactory } from "./types";
2
+ import type { ValueOrTransformer, Transformer, ValueOrFactory } from "./state.types";
3
3
  export declare const embed: <D>(statePath: string, value: D) => (vocab: Vocab<D>) => {
4
4
  [x: string]: D;
5
5
  };
6
6
  export declare const genStoredValue: <V>(options: {
7
7
  serialized: string | null;
8
- defaultValue: ValueOrFactory<V>;
9
- superDefaultValue: unknown;
10
8
  deserialize: (v: string) => V;
11
9
  }) => V;
12
10
  export declare const isTransformer: <V>(v: ValueOrTransformer<V>) => v is Transformer<V>;
11
+ export declare const isValueDefined: <V>(v: V | undefined) => v is V;
13
12
  export declare const valueOrFactory: <V>(input: ValueOrFactory<V>) => V;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "main": "dist/state-vocab.cjs.js",
5
5
  "module": "dist/state-vocab.es.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "scripts": {
20
20
  "dev": "vite",
21
- "build": "tsc -b && vite build ; tsc --project tsconfig.types.json",
21
+ "build": "tsc --project tsconfig.build.json && vite build ; tsc",
22
22
  "lint": "eslint .",
23
- "type-check": "tsc --project tsconfig.types.json",
23
+ "type-check": "tsc",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest",
26
26
  "test:report": "npx vitest run --reporter=verbose"
@@ -33,6 +33,7 @@
33
33
  "@eslint/js": "^9.39.1",
34
34
  "@testing-library/jest-dom": "^6.9.1",
35
35
  "@testing-library/react": "^16.3.2",
36
+ "@types/jest": "^30.0.0",
36
37
  "@types/node": "^24.10.1",
37
38
  "@types/react": "^19.2.5",
38
39
  "@types/react-dom": "^19.2.3",
@@ -1 +0,0 @@
1
- export {};