@yakocloud/state-vocab 2.0.2 → 2.1.0

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
@@ -12,7 +12,7 @@ Most state managers treat persistence as an afterthought — you manage state fi
12
12
  // declare once — works everywhere
13
13
  const storage = setupStorage({
14
14
  theme: defineState({ storage: localStorage, defaultValue: 'Dark' }),
15
- session: defineState({ storage: sessionStorage }),
15
+ session: defineState({ storage: () => sessionStorage }),
16
16
  inMemory: defineState({ defaultValue: 0 }),
17
17
  })
18
18
  ```
@@ -77,9 +77,11 @@ defineState({
77
77
  ## Installation
78
78
 
79
79
  ```bash
80
- npm install @yakocloud/state-vocab
80
+ npm install @yakocloud/state-vocab react react-dom
81
81
  ```
82
82
 
83
+ > `react` and `react-dom` are peer dependencies and must be installed separately.
84
+
83
85
  ## Quick Start
84
86
 
85
87
  ```tsx
@@ -125,7 +127,7 @@ Defines a state node. Options:
125
127
 
126
128
  | Option | Type | Description |
127
129
  |---|---|---|
128
- | `storage` | `Storage` | Where to persist the value. Omit for in-memory only. |
130
+ | `storage` | `Storage \| (() => Storage) \| undefined` | Where to persist the value. Omit for in-memory only. |
129
131
  | `defaultValue` | `T` | Value used when storage has no entry. |
130
132
  | `serialize` | `(v: T) => string` | Custom serializer. Default: `JSON.stringify`. |
131
133
  | `deserialize` | `(v: string) => T` | Custom deserializer. Default: `JSON.parse`. |
@@ -136,13 +138,13 @@ const counter = defineState({ defaultValue: 0 })
136
138
 
137
139
  // localStorage with custom type
138
140
  const theme = defineState<'Dark' | 'White'>({
139
- storage: localStorage,
141
+ storage: () => localStorage,
140
142
  defaultValue: 'Dark',
141
143
  })
142
144
 
143
145
  // localStorage with custom serialization
144
146
  const birthday = defineState({
145
- storage: localStorage,
147
+ storage: () => localStorage,
146
148
  deserialize: (raw) => new Date(JSON.parse(raw)),
147
149
  })
148
150
  ```
@@ -322,7 +324,7 @@ createRoot(document.getElementById('root')!).render(
322
324
 
323
325
  | Option | Type | Default |
324
326
  |---|---|---|
325
- | `storage` | `Storage \| undefined` | `undefined` (in-memory) |
327
+ | `storage` | `Storage \| (() => Storage) \| undefined` | `undefined` (in-memory) |
326
328
  | `defaultValue` | `T \| undefined` | `undefined` |
327
329
  | `bidirectional` | `true \| undefined` | `undefined` |
328
330
  | `serialize` | `(v: T) => string` | `JSON.stringify` |
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),B=Symbol("state-def"),A=Symbol("state-path");function le(r,n,a){if(!n)return r;const s=n.split(".");let t=r;for(const c of s)if(t!==null&&typeof t=="object"&&c in t)t=t[c];else return a;return t===void 0?a:t}function ie(r,n,a){const s=n.replace(/\[(\d+)\]/g,".$1").split(".");let t=r;for(let c=0;c<s.length-1;c++){const f=s[c],u=s[c+1];(t[f]===void 0||t[f]===null)&&(t[f]=/^\d+$/.test(u)?[]:{}),t=t[f]}return t[s[s.length-1]]=a,r}function fe(r,n=0){let a;return function(...s){a!==void 0&&clearTimeout(a),a=setTimeout(()=>{a=void 0,r.apply(this,s)},n)}}function de(r,n,a=[]){return T.useMemo(()=>fe(r,n),a)}function me(r){const n=JSON.stringify(r,null,2).split(`
2
- `),a=[],s=[];for(const t of n){const c=t.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(c){const[,f,u,p,v]=c;a.push(`${f}%c"${u}"%c${p}%c${v}`),s.push("color: #9cdcfe; font-weight: bold","color: #cccccc","color: #ce9178")}else a.push(`%c${t}`),s.push("color: #cccccc")}console.log(a.join(`
3
- `),...s,r)}var x={exports:{}},k={};var W;function be(){if(W)return k;W=1;var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function a(s,t,c){var f=null;if(c!==void 0&&(f=""+c),t.key!==void 0&&(f=""+t.key),"key"in t){c={};for(var u in t)u!=="key"&&(c[u]=t[u])}else c=t;return t=c.ref,{$$typeof:r,type:s,key:f,ref:t!==void 0?t:null,props:c}}return k.Fragment=n,k.jsx=a,k.jsxs=a,k}var w={};var J;function ve(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===se?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case Q:return"Profiler";case h:return"StrictMode";case re:return"Suspense";case ne:return"SuspenseList";case ae: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 d:return"Portal";case ee:return e.displayName||"Context";case K:return(e._context.displayName||"Context")+".Consumer";case te:var o=e.render;return e=e.displayName,e||(e=o.displayName||o.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case oe:return o=e.displayName||null,o!==null?o:r(e.type)||"Memo";case j:o=e._payload,e=e._init;try{return r(e(o))}catch{}}return null}function n(e){return""+e}function a(e){try{n(e);var o=!1}catch{o=!0}if(o){o=console;var i=o.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),n(e)}}function s(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===j)return"<...>";try{var o=r(e);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function t(){var e=N.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function f(e){if(Y.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function u(e,o){function i(){M||(M=!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))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function p(){var e=r(this.type);return D[e]||(D[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 v(e,o,i,m,P,V){var b=i.ref;return e={$$typeof:_,type:e,key:o,props:i,_owner:m},(b!==void 0?b:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:p}):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:P}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function l(e,o,i,m,P,V){var b=o.children;if(b!==void 0)if(m)if(ce(b)){for(m=0;m<b.length;m++)R(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 R(b);if(Y.call(o,"key")){b=r(e);var g=Object.keys(o).filter(function(ue){return ue!=="key"});m=0<g.length?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}",z[b+m]||(g=0<g.length?"{"+g.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 y=require("react"),B=Symbol("state-def"),A=Symbol("state-path");function ie(t,c,o){if(!c)return t;const a=c.split(".");let r=t;for(const s of a)if(r!==null&&typeof r=="object"&&s in r)r=r[s];else return o;return r===void 0?o:r}function fe(t,c,o){const a=c.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(let s=0;s<a.length-1;s++){const f=a[s],u=a[s+1];(r[f]===void 0||r[f]===null)&&(r[f]=/^\d+$/.test(u)?[]:{}),r=r[f]}return r[a[a.length-1]]=o,t}function de(t,c=0){let o;return function(...a){o!==void 0&&clearTimeout(o),o=setTimeout(()=>{o=void 0,t.apply(this,a)},c)}}function me(t,c,o=[]){return y.useMemo(()=>de(t,c),o)}function be(t){const c=JSON.stringify(t,null,2).split(`
2
+ `),o=[],a=[];for(const r of c){const s=r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);if(s){const[,f,u,p,v]=s;o.push(`${f}%c"${u}"%c${p}%c${v}`),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 x={exports:{}},k={};var W;function ve(){if(W)return k;W=1;var t=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function o(a,r,s){var f=null;if(s!==void 0&&(f=""+s),r.key!==void 0&&(f=""+r.key),"key"in r){s={};for(var u in r)u!=="key"&&(s[u]=r[u])}else s=r;return r=s.ref,{$$typeof:t,type:a,key:f,ref:r!==void 0?r:null,props:s}}return k.Fragment=c,k.jsx=o,k.jsxs=o,k}var w={};var J;function Ee(){return J||(J=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 S:return"Fragment";case K:return"Profiler";case h:return"StrictMode";case ne: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 d:return"Portal";case te:return e.displayName||"Context";case ee:return(e._context.displayName||"Context")+".Consumer";case re: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 j:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function c(e){return""+e}function o(e){try{c(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),c(e)}}function a(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===j)return"<...>";try{var n=t(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function r(){var e=N.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function f(e){if(Y.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function u(e,n){function i(){M||(M=!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 p(){var e=t(this.type);return D[e]||(D[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 v(e,n,i,m,P,V){var b=i.ref;return e={$$typeof:_,type:e,key:n,props:i,_owner:m},(b!==void 0?b:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:p}):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:P}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function l(e,n,i,m,P,V){var b=n.children;if(b!==void 0)if(m)if(ue(b)){for(m=0;m<b.length;m++)R(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 R(b);if(Y.call(n,"key")){b=t(e);var g=Object.keys(n).filter(function(le){return le!=="key"});m=0<g.length?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}",z[b+m]||(g=0<g.length?"{"+g.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,g,b),z[b+m]=!0)}if(b=null,i!==void 0&&(a(i),b=""+i),f(o)&&(a(o.key),b=""+o.key),"key"in o){i={};for(var $ in o)$!=="key"&&(i[$]=o[$])}else i=o;return b&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),v(e,b,i,t(),P,V)}function R(e){y(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===j&&(e._payload.status==="fulfilled"?y(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function y(e){return typeof e=="object"&&e!==null&&e.$$typeof===_}var E=T,_=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),Q=Symbol.for("react.profiler"),K=Symbol.for("react.consumer"),ee=Symbol.for("react.context"),te=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),ne=Symbol.for("react.suspense_list"),oe=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),ae=Symbol.for("react.activity"),se=Symbol.for("react.client.reference"),N=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,ce=Array.isArray,C=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var M,D={},F=E.react_stack_bottom_frame.bind(E,c)(),L=C(s(c)),z={};w.Fragment=S,w.jsx=function(e,o,i){var m=1e4>N.recentlyCreatedOwnerStacks++;return l(e,o,i,!1,m?Error("react-stack-top-frame"):F,m?C(s(e)):L)},w.jsxs=function(e,o,i){var m=1e4>N.recentlyCreatedOwnerStacks++;return l(e,o,i,!0,m?Error("react-stack-top-frame"):F,m?C(s(e)):L)}})()),w}var U;function Ee(){return U||(U=1,process.env.NODE_ENV==="production"?x.exports=be():x.exports=ve()),x.exports}var pe=Ee();const H=T.createContext({stateVocab:{},setStateVocab:()=>{}});function _e(){return T.useContext(H)}const Se=r=>{const{children:n,verbose:a}=r,[s,t]=T.useState({});return a&&me(s),pe.jsx(H.Provider,{value:{stateVocab:s,setStateVocab:t},children:n})},O=(r,n)=>a=>{const s={...a};return ie(s,r,n),s},I=(r,n)=>typeof r=="function"?r():r??n,q=r=>{const{serialized:n,defaultValue:a,superDefaultValue:s,deserialize:t}=r;if(n===null){const c=I(a,s);return typeof c>"u"?void 0:c}return t(n)};function Re(r={}){const{storage:n,serialize:a=JSON.stringify,deserialize:s=JSON.parse}=r,t=r.defaultValue,c=r.bidirectional;return{[B]:!0,[A]:"",useState(f,u){u??={};const p=de(u.onSet??(()=>{}),u.delayedSet,[]),v=_e(),l=this[A],R=T.useMemo(()=>{if(!n)return;const _=n.getItem(l);return q({serialized:_,defaultValue:f,superDefaultValue:t,deserialize:s})},[l]),y=T.useMemo(()=>le(v.stateVocab,l,R??I(f,t)),[v.stateVocab,R,l]);T.useEffect(()=>{!n||typeof R>"u"||v.setStateVocab(O(l,R))},[R]),T.useEffect(()=>{if(!u.bidirectional&&!c)return;const _=d=>{if(d.key!==l)return;const S=d.newValue,h=q({serialized:S,defaultValue:f,superDefaultValue:t,deserialize:s});v.setStateVocab(O(l,h)),p(h,E.current),E.current=h};return window.addEventListener("storage",_),()=>window.removeEventListener("storage",_)},[l,u.bidirectional,c]);const E=T.useRef(y);return[y,function(d){const S=typeof d=="function"?d(E.current):d;v.setStateVocab(O(l,S)),p(S,E.current),n&&n.setItem(l,a(S)),E.current=S},function(){const d=I(f,t);if(typeof d>"u"){n?.removeItem(l);return}v.setStateVocab(O(l,d)),p(d,E.current),E.current=d,n&&n.setItem(l,a(d))}]},toString(){return this[A]}}}const G=new WeakMap,X=new WeakMap;function Z(r,n=""){let a=G.get(r);a||(a=new Map,G.set(r,a));const s=a.get(n);if(s)return s;const t=new Proxy(r,{get(c,f){const u=c[f],p=n?`${n}.${String(f)}`:String(f);if(u&&typeof u=="object"&&B in u){const v=u;let l=X.get(v);l||(l=new Map,X.set(v,l));const R=l.get(p);if(R)return R;const y=Reflect.ownKeys(v).filter(d=>typeof v[d]=="function"),E=Object.fromEntries(y.map(d=>[d,(...S)=>v[d].call({...v,[A]:p},...S)])),_={...v,...E};return l.set(p,_),_}return u&&typeof u=="object"?Z(u,p):u}});return a.set(n,t),t}function Te(r){return Z(r)}exports.StorageProvider=Se;exports.defineState=Re;exports.setupStorage=Te;
8
+ <%s key={someKey} {...props} />`,m,b,g,b),z[b+m]=!0)}if(b=null,i!==void 0&&(o(i),b=""+i),f(n)&&(o(n.key),b=""+n.key),"key"in n){i={};for(var $ in n)$!=="key"&&(i[$]=n[$])}else i=n;return b&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),v(e,b,i,r(),P,V)}function R(e){T(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===j&&(e._payload.status==="fulfilled"?T(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function T(e){return typeof e=="object"&&e!==null&&e.$$typeof===_}var E=y,_=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),K=Symbol.for("react.profiler"),ee=Symbol.for("react.consumer"),te=Symbol.for("react.context"),re=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),N=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,ue=Array.isArray,C=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var M,D={},F=E.react_stack_bottom_frame.bind(E,s)(),L=C(a(s)),z={};w.Fragment=S,w.jsx=function(e,n,i){var m=1e4>N.recentlyCreatedOwnerStacks++;return l(e,n,i,!1,m?Error("react-stack-top-frame"):F,m?C(a(e)):L)},w.jsxs=function(e,n,i){var m=1e4>N.recentlyCreatedOwnerStacks++;return l(e,n,i,!0,m?Error("react-stack-top-frame"):F,m?C(a(e)):L)}})()),w}var U;function pe(){return U||(U=1,process.env.NODE_ENV==="production"?x.exports=ve():x.exports=Ee()),x.exports}var _e=pe();const H=y.createContext({stateVocab:{},setStateVocab:()=>{}});function Se(){return y.useContext(H)}const Re=t=>{const{children:c,verbose:o}=t,[a,r]=y.useState({});return o&&be(a),_e.jsx(H.Provider,{value:{stateVocab:a,setStateVocab:r},children:c})},O=(t,c)=>o=>{const a={...o};return fe(a,t,c),a},I=(t,c)=>Z(t)??c,q=t=>{const{serialized:c,defaultValue:o,superDefaultValue:a,deserialize:r}=t;if(c===null){const s=I(o,a);return typeof s>"u"?void 0:s}return r(c)},ye=t=>typeof t=="function",Te=t=>typeof t=="function",Z=t=>Te(t)?t():t;function ge(t={}){const{serialize:c=JSON.stringify,deserialize:o=JSON.parse}=t,a=t.defaultValue,r=t.bidirectional,s=Z(t.storage);return{[B]:!0,[A]:"",useState(f,u){u??={};const p=me(u.onSet??(()=>{}),u.delayedSet,[]),v=Se(),l=this[A],R=y.useMemo(()=>{if(!s)return;const _=s.getItem(l);return q({serialized:_,defaultValue:f,superDefaultValue:a,deserialize:o})},[l]),T=y.useMemo(()=>ie(v.stateVocab,l,R??I(f,a)),[v.stateVocab,R,l]);y.useEffect(()=>{!s||typeof R>"u"||v.setStateVocab(O(l,R))},[R]),y.useEffect(()=>{if(!u.bidirectional&&!r)return;const _=d=>{if(d.key!==l)return;const S=d.newValue,h=q({serialized:S,defaultValue:f,superDefaultValue:a,deserialize:o});v.setStateVocab(O(l,h)),p(h,E.current),E.current=h};return window.addEventListener("storage",_),()=>window.removeEventListener("storage",_)},[l,u.bidirectional,r]);const E=y.useRef(T);return[T,function(d){const S=ye(d)?d(E.current):d;v.setStateVocab(O(l,S)),p(S,E.current),s&&s.setItem(l,c(S)),E.current=S},function(){const d=I(f,a);if(typeof d>"u"){s?.removeItem(l);return}v.setStateVocab(O(l,d)),p(d,E.current),E.current=d,s&&s.setItem(l,c(d))}]},toString(){return this[A]}}}const G=new WeakMap,X=new WeakMap;function Q(t,c=""){let o=G.get(t);o||(o=new Map,G.set(t,o));const a=o.get(c);if(a)return a;const r=new Proxy(t,{get(s,f){const u=s[f],p=c?`${c}.${String(f)}`:String(f);if(u&&typeof u=="object"&&B in u){const v=u;let l=X.get(v);l||(l=new Map,X.set(v,l));const R=l.get(p);if(R)return R;const T=Reflect.ownKeys(v).filter(d=>typeof v[d]=="function"),E=Object.fromEntries(T.map(d=>[d,(...S)=>v[d].call({...v,[A]:p},...S)])),_={...v,...E};return l.set(p,_),_}return u&&typeof u=="object"?Q(u,p):u}});return o.set(c,r),r}function he(t){return Q(t)}exports.StorageProvider=Re;exports.defineState=ge;exports.setupStorage=he;
@@ -1,103 +1,103 @@
1
- import ie, { useMemo as $, createContext as fe, useState as de, useContext as me, useEffect as W, useRef as be } from "react";
1
+ import fe, { useMemo as $, createContext as de, useState as me, useContext as be, useEffect as W, useRef as ve } from "react";
2
2
  const H = Symbol("state-def"), O = Symbol("state-path");
3
- function ve(r, n, a) {
4
- if (!n)
5
- return r;
6
- const s = n.split(".");
7
- let t = r;
8
- for (const c of s)
9
- if (t !== null && typeof t == "object" && c in t)
10
- t = t[c];
3
+ function Ee(t, c, o) {
4
+ if (!c)
5
+ return t;
6
+ const a = c.split(".");
7
+ let r = t;
8
+ for (const s of a)
9
+ if (r !== null && typeof r == "object" && s in r)
10
+ r = r[s];
11
11
  else
12
- return a;
13
- return t === void 0 ? a : t;
12
+ return o;
13
+ return r === void 0 ? o : r;
14
14
  }
15
- function Ee(r, n, a) {
16
- const s = n.replace(/\[(\d+)\]/g, ".$1").split(".");
17
- let t = r;
18
- for (let c = 0; c < s.length - 1; c++) {
19
- const f = s[c], u = s[c + 1];
20
- (t[f] === void 0 || t[f] === null) && (t[f] = /^\d+$/.test(u) ? [] : {}), t = t[f];
15
+ function pe(t, c, o) {
16
+ const a = c.replace(/\[(\d+)\]/g, ".$1").split(".");
17
+ let r = t;
18
+ for (let s = 0; s < a.length - 1; s++) {
19
+ const f = a[s], u = a[s + 1];
20
+ (r[f] === void 0 || r[f] === null) && (r[f] = /^\d+$/.test(u) ? [] : {}), r = r[f];
21
21
  }
22
- return t[s[s.length - 1]] = a, r;
22
+ return r[a[a.length - 1]] = o, t;
23
23
  }
24
- function pe(r, n = 0) {
25
- let a;
26
- return function(...s) {
27
- a !== void 0 && clearTimeout(a), a = setTimeout(() => {
28
- a = void 0, r.apply(this, s);
29
- }, n);
24
+ function _e(t, c = 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
+ }, c);
30
30
  };
31
31
  }
32
- function _e(r, n, a = []) {
32
+ function Se(t, c, o = []) {
33
33
  return $(
34
- () => pe(r, n),
34
+ () => _e(t, c),
35
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
36
- a
36
+ o
37
37
  );
38
38
  }
39
- function Se(r) {
40
- const n = JSON.stringify(r, null, 2).split(`
41
- `), a = [], s = [];
42
- for (const t of n) {
43
- const c = t.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
- if (c) {
45
- const [, f, u, p, v] = c;
46
- a.push(`${f}%c"${u}"%c${p}%c${v}`), s.push(
39
+ function Re(t) {
40
+ const c = JSON.stringify(t, null, 2).split(`
41
+ `), o = [], a = [];
42
+ for (const r of c) {
43
+ const s = r.match(/^(\s*)"([^"]+)"(\s*:\s*)(.+)$/);
44
+ if (s) {
45
+ const [, f, u, p, v] = s;
46
+ o.push(`${f}%c"${u}"%c${p}%c${v}`), a.push(
47
47
  "color: #9cdcfe; font-weight: bold",
48
48
  "color: #cccccc",
49
49
  "color: #ce9178"
50
50
  );
51
51
  } else
52
- a.push(`%c${t}`), s.push("color: #cccccc");
52
+ o.push(`%c${r}`), a.push("color: #cccccc");
53
53
  }
54
- console.log(a.join(`
55
- `), ...s, r);
54
+ console.log(o.join(`
55
+ `), ...a, t);
56
56
  }
57
57
  var x = { exports: {} }, h = {};
58
58
  var J;
59
- function Re() {
59
+ function Te() {
60
60
  if (J) return h;
61
61
  J = 1;
62
- var r = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
63
- function a(s, t, c) {
62
+ var t = Symbol.for("react.transitional.element"), c = Symbol.for("react.fragment");
63
+ function o(a, r, s) {
64
64
  var f = null;
65
- if (c !== void 0 && (f = "" + c), t.key !== void 0 && (f = "" + t.key), "key" in t) {
66
- c = {};
67
- for (var u in t)
68
- u !== "key" && (c[u] = t[u]);
69
- } else c = t;
70
- return t = c.ref, {
71
- $$typeof: r,
72
- type: s,
65
+ if (s !== void 0 && (f = "" + s), r.key !== void 0 && (f = "" + r.key), "key" in r) {
66
+ s = {};
67
+ for (var u in r)
68
+ u !== "key" && (s[u] = r[u]);
69
+ } else s = r;
70
+ return r = s.ref, {
71
+ $$typeof: t,
72
+ type: a,
73
73
  key: f,
74
- ref: t !== void 0 ? t : null,
75
- props: c
74
+ ref: r !== void 0 ? r : null,
75
+ props: s
76
76
  };
77
77
  }
78
- return h.Fragment = n, h.jsx = a, h.jsxs = a, h;
78
+ return h.Fragment = c, h.jsx = o, h.jsxs = o, h;
79
79
  }
80
80
  var k = {};
81
81
  var U;
82
- function Te() {
82
+ function ye() {
83
83
  return U || (U = 1, process.env.NODE_ENV !== "production" && (function() {
84
- function r(e) {
84
+ function t(e) {
85
85
  if (e == null) return null;
86
86
  if (typeof e == "function")
87
- return e.$$typeof === ce ? null : e.displayName || e.name || null;
87
+ return e.$$typeof === ue ? null : e.displayName || e.name || null;
88
88
  if (typeof e == "string") return e;
89
89
  switch (e) {
90
90
  case S:
91
91
  return "Fragment";
92
- case K:
92
+ case ee:
93
93
  return "Profiler";
94
94
  case g:
95
95
  return "StrictMode";
96
- case ne:
97
- return "Suspense";
98
96
  case oe:
97
+ return "Suspense";
98
+ case ae:
99
99
  return "SuspenseList";
100
- case se:
100
+ case ce:
101
101
  return "Activity";
102
102
  }
103
103
  if (typeof e == "object")
@@ -106,74 +106,74 @@ function Te() {
106
106
  ), e.$$typeof) {
107
107
  case d:
108
108
  return "Portal";
109
- case te:
109
+ case re:
110
110
  return e.displayName || "Context";
111
- case ee:
111
+ case te:
112
112
  return (e._context.displayName || "Context") + ".Consumer";
113
- case re:
114
- var o = e.render;
115
- return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
116
- case ae:
117
- return o = e.displayName || null, o !== null ? o : r(e.type) || "Memo";
113
+ case ne:
114
+ var n = e.render;
115
+ return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
116
+ case se:
117
+ return n = e.displayName || null, n !== null ? n : t(e.type) || "Memo";
118
118
  case A:
119
- o = e._payload, e = e._init;
119
+ n = e._payload, e = e._init;
120
120
  try {
121
- return r(e(o));
121
+ return t(e(n));
122
122
  } catch {
123
123
  }
124
124
  }
125
125
  return null;
126
126
  }
127
- function n(e) {
127
+ function c(e) {
128
128
  return "" + e;
129
129
  }
130
- function a(e) {
130
+ function o(e) {
131
131
  try {
132
- n(e);
133
- var o = !1;
132
+ c(e);
133
+ var n = !1;
134
134
  } catch {
135
- o = !0;
135
+ n = !0;
136
136
  }
137
- if (o) {
138
- o = console;
139
- var i = o.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
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
140
  return i.call(
141
- o,
141
+ n,
142
142
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
143
143
  m
144
- ), n(e);
144
+ ), c(e);
145
145
  }
146
146
  }
147
- function s(e) {
147
+ function a(e) {
148
148
  if (e === S) return "<>";
149
149
  if (typeof e == "object" && e !== null && e.$$typeof === A)
150
150
  return "<...>";
151
151
  try {
152
- var o = r(e);
153
- return o ? "<" + o + ">" : "<...>";
152
+ var n = t(e);
153
+ return n ? "<" + n + ">" : "<...>";
154
154
  } catch {
155
155
  return "<...>";
156
156
  }
157
157
  }
158
- function t() {
158
+ function r() {
159
159
  var e = j.A;
160
160
  return e === null ? null : e.getOwner();
161
161
  }
162
- function c() {
162
+ function s() {
163
163
  return Error("react-stack-top-frame");
164
164
  }
165
165
  function f(e) {
166
166
  if (Y.call(e, "key")) {
167
- var o = Object.getOwnPropertyDescriptor(e, "key").get;
168
- if (o && o.isReactWarning) return !1;
167
+ var n = Object.getOwnPropertyDescriptor(e, "key").get;
168
+ if (n && n.isReactWarning) return !1;
169
169
  }
170
170
  return e.key !== void 0;
171
171
  }
172
- function u(e, o) {
172
+ function u(e, n) {
173
173
  function i() {
174
174
  D || (D = !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
- o
176
+ n
177
177
  ));
178
178
  }
179
179
  i.isReactWarning = !0, Object.defineProperty(e, "key", {
@@ -182,17 +182,17 @@ function Te() {
182
182
  });
183
183
  }
184
184
  function p() {
185
- var e = r(this.type);
186
- return M[e] || (M[e] = !0, console.error(
185
+ var e = t(this.type);
186
+ return F[e] || (F[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 v(e, o, i, m, w, C) {
190
+ function v(e, n, i, m, w, C) {
191
191
  var b = i.ref;
192
192
  return e = {
193
193
  $$typeof: _,
194
194
  type: e,
195
- key: o,
195
+ key: n,
196
196
  props: i,
197
197
  _owner: m
198
198
  }, (b !== void 0 ? b : null) !== null ? Object.defineProperty(e, "ref", {
@@ -220,11 +220,11 @@ function Te() {
220
220
  value: C
221
221
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
222
222
  }
223
- function l(e, o, i, m, w, C) {
224
- var b = o.children;
223
+ function l(e, n, i, m, w, C) {
224
+ var b = n.children;
225
225
  if (b !== void 0)
226
226
  if (m)
227
- if (ue(b)) {
227
+ if (le(b)) {
228
228
  for (m = 0; m < b.length; m++)
229
229
  R(b[m]);
230
230
  Object.freeze && Object.freeze(b);
@@ -233,10 +233,10 @@ function Te() {
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
235
  else R(b);
236
- if (Y.call(o, "key")) {
237
- b = r(e);
238
- var y = Object.keys(o).filter(function(le) {
239
- return le !== "key";
236
+ if (Y.call(n, "key")) {
237
+ b = t(e);
238
+ var y = Object.keys(n).filter(function(ie) {
239
+ return ie !== "key";
240
240
  });
241
241
  m = 0 < y.length ? "{key: someKey, " + y.join(": ..., ") + ": ...}" : "{key: someKey}", z[b + m] || (y = 0 < y.length ? "{" + y.join(": ..., ") + ": ...}" : "{}", console.error(
242
242
  `A props object containing a "key" prop is being spread into JSX:
@@ -251,11 +251,11 @@ React keys must be passed directly to JSX without using spread:
251
251
  b
252
252
  ), z[b + m] = !0);
253
253
  }
254
- if (b = null, i !== void 0 && (a(i), b = "" + i), f(o) && (a(o.key), b = "" + o.key), "key" in o) {
254
+ if (b = null, i !== void 0 && (o(i), b = "" + i), f(n) && (o(n.key), b = "" + n.key), "key" in n) {
255
255
  i = {};
256
- for (var V in o)
257
- V !== "key" && (i[V] = o[V]);
258
- } else i = o;
256
+ for (var V in n)
257
+ V !== "key" && (i[V] = n[V]);
258
+ } else i = n;
259
259
  return b && u(
260
260
  i,
261
261
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
@@ -263,7 +263,7 @@ React keys must be passed directly to JSX without using spread:
263
263
  e,
264
264
  b,
265
265
  i,
266
- t(),
266
+ r(),
267
267
  w,
268
268
  C
269
269
  );
@@ -274,7 +274,7 @@ React keys must be passed directly to JSX without using spread:
274
274
  function T(e) {
275
275
  return typeof e == "object" && e !== null && e.$$typeof === _;
276
276
  }
277
- var E = ie, _ = Symbol.for("react.transitional.element"), d = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), K = Symbol.for("react.profiler"), ee = Symbol.for("react.consumer"), te = Symbol.for("react.context"), re = Symbol.for("react.forward_ref"), ne = Symbol.for("react.suspense"), oe = Symbol.for("react.suspense_list"), ae = Symbol.for("react.memo"), A = Symbol.for("react.lazy"), se = Symbol.for("react.activity"), ce = Symbol.for("react.client.reference"), j = E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, ue = Array.isArray, N = console.createTask ? console.createTask : function() {
277
+ var E = fe, _ = Symbol.for("react.transitional.element"), d = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), ee = Symbol.for("react.profiler"), te = Symbol.for("react.consumer"), re = Symbol.for("react.context"), ne = Symbol.for("react.forward_ref"), oe = Symbol.for("react.suspense"), ae = Symbol.for("react.suspense_list"), se = Symbol.for("react.memo"), A = Symbol.for("react.lazy"), ce = Symbol.for("react.activity"), ue = Symbol.for("react.client.reference"), j = E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, le = Array.isArray, N = console.createTask ? console.createTask : function() {
278
278
  return null;
279
279
  };
280
280
  E = {
@@ -282,66 +282,65 @@ React keys must be passed directly to JSX without using spread:
282
282
  return e();
283
283
  }
284
284
  };
285
- var D, M = {}, F = E.react_stack_bottom_frame.bind(
285
+ var D, F = {}, M = E.react_stack_bottom_frame.bind(
286
286
  E,
287
- c
288
- )(), L = N(s(c)), z = {};
289
- k.Fragment = S, k.jsx = function(e, o, i) {
287
+ s
288
+ )(), L = N(a(s)), z = {};
289
+ k.Fragment = S, k.jsx = function(e, n, i) {
290
290
  var m = 1e4 > j.recentlyCreatedOwnerStacks++;
291
291
  return l(
292
292
  e,
293
- o,
293
+ n,
294
294
  i,
295
295
  !1,
296
- m ? Error("react-stack-top-frame") : F,
297
- m ? N(s(e)) : L
296
+ m ? Error("react-stack-top-frame") : M,
297
+ m ? N(a(e)) : L
298
298
  );
299
- }, k.jsxs = function(e, o, i) {
299
+ }, k.jsxs = function(e, n, i) {
300
300
  var m = 1e4 > j.recentlyCreatedOwnerStacks++;
301
301
  return l(
302
302
  e,
303
- o,
303
+ n,
304
304
  i,
305
305
  !0,
306
- m ? Error("react-stack-top-frame") : F,
307
- m ? N(s(e)) : L
306
+ m ? Error("react-stack-top-frame") : M,
307
+ m ? N(a(e)) : L
308
308
  );
309
309
  };
310
310
  })()), k;
311
311
  }
312
312
  var q;
313
- function ye() {
314
- return q || (q = 1, process.env.NODE_ENV === "production" ? x.exports = Re() : x.exports = Te()), x.exports;
313
+ function ge() {
314
+ return q || (q = 1, process.env.NODE_ENV === "production" ? x.exports = Te() : x.exports = ye()), x.exports;
315
315
  }
316
- var ge = ye();
317
- const Z = fe({
316
+ var he = ge();
317
+ const Z = de({
318
318
  stateVocab: {},
319
319
  setStateVocab: () => {
320
320
  }
321
321
  });
322
- function he() {
323
- return me(Z);
322
+ function ke() {
323
+ return be(Z);
324
324
  }
325
- const we = (r) => {
326
- const { children: n, verbose: a } = r, [s, t] = de({});
327
- return a && Se(s), /* @__PURE__ */ ge.jsx(Z.Provider, { value: { stateVocab: s, setStateVocab: t }, children: n });
328
- }, P = (r, n) => (a) => {
329
- const s = { ...a };
330
- return Ee(s, r, n), s;
331
- }, I = (r, n) => typeof r == "function" ? r() : r ?? n, G = (r) => {
332
- const { serialized: n, defaultValue: a, superDefaultValue: s, deserialize: t } = r;
333
- if (n === null) {
334
- const c = I(a, s);
335
- return typeof c > "u" ? void 0 : c;
325
+ const Oe = (t) => {
326
+ const { children: c, verbose: o } = t, [a, r] = me({});
327
+ return o && Re(a), /* @__PURE__ */ he.jsx(Z.Provider, { value: { stateVocab: a, setStateVocab: r }, children: c });
328
+ }, P = (t, c) => (o) => {
329
+ const a = { ...o };
330
+ return pe(a, t, c), a;
331
+ }, I = (t, c) => Q(t) ?? c, G = (t) => {
332
+ const { serialized: c, defaultValue: o, superDefaultValue: a, deserialize: r } = t;
333
+ if (c === null) {
334
+ const s = I(o, a);
335
+ return typeof s > "u" ? void 0 : s;
336
336
  }
337
- return t(n);
338
- };
339
- function xe(r = {}) {
337
+ return r(c);
338
+ }, we = (t) => typeof t == "function", xe = (t) => typeof t == "function", Q = (t) => xe(t) ? t() : t;
339
+ function Ae(t = {}) {
340
340
  const {
341
- storage: n,
342
- serialize: a = JSON.stringify,
343
- deserialize: s = JSON.parse
344
- } = r, t = r.defaultValue, c = r.bidirectional;
341
+ serialize: c = JSON.stringify,
342
+ deserialize: o = JSON.parse
343
+ } = t, a = t.defaultValue, r = t.bidirectional, s = Q(t.storage);
345
344
  return {
346
345
  [H]: !0,
347
346
  // marks this object as a leaf in the router tree
@@ -349,30 +348,30 @@ function xe(r = {}) {
349
348
  // placeholder; injected at runtime by injectPaths()
350
349
  useState(f, u) {
351
350
  u ??= {};
352
- const p = _e(
351
+ const p = Se(
353
352
  u.onSet ?? (() => {
354
353
  }),
355
354
  u.delayedSet,
356
355
  []
357
- ), v = he(), l = this[O], R = $(
356
+ ), v = ke(), l = this[O], R = $(
358
357
  () => {
359
- if (!n)
358
+ if (!s)
360
359
  return;
361
- const _ = n.getItem(l);
360
+ const _ = s.getItem(l);
362
361
  return G({
363
362
  serialized: _,
364
363
  defaultValue: f,
365
- superDefaultValue: t,
366
- deserialize: s
364
+ superDefaultValue: a,
365
+ deserialize: o
367
366
  });
368
367
  },
369
368
  // eslint-disable-next-line react-hooks/exhaustive-deps
370
369
  [l]
371
370
  ), T = $(
372
- () => ve(
371
+ () => Ee(
373
372
  v.stateVocab,
374
373
  l,
375
- R ?? I(f, t)
374
+ R ?? I(f, a)
376
375
  ),
377
376
  // eslint-disable-next-line react-hooks/exhaustive-deps
378
377
  [
@@ -383,12 +382,12 @@ function xe(r = {}) {
383
382
  );
384
383
  W(
385
384
  () => {
386
- !n || typeof R > "u" || v.setStateVocab(P(l, R));
385
+ !s || typeof R > "u" || v.setStateVocab(P(l, R));
387
386
  },
388
387
  // eslint-disable-next-line react-hooks/exhaustive-deps
389
388
  [R]
390
389
  ), W(() => {
391
- if (!u.bidirectional && !c)
390
+ if (!u.bidirectional && !r)
392
391
  return;
393
392
  const _ = (d) => {
394
393
  if (d.key !== l)
@@ -396,8 +395,8 @@ function xe(r = {}) {
396
395
  const S = d.newValue, g = G({
397
396
  serialized: S,
398
397
  defaultValue: f,
399
- superDefaultValue: t,
400
- deserialize: s
398
+ superDefaultValue: a,
399
+ deserialize: o
401
400
  });
402
401
  v.setStateVocab(P(l, g)), p(g, E.current), E.current = g;
403
402
  };
@@ -405,22 +404,22 @@ function xe(r = {}) {
405
404
  }, [
406
405
  l,
407
406
  u.bidirectional,
408
- c
407
+ r
409
408
  ]);
410
- const E = be(T);
409
+ const E = ve(T);
411
410
  return [
412
411
  T,
413
412
  function(d) {
414
- const S = typeof d == "function" ? d(E.current) : d;
415
- v.setStateVocab(P(l, S)), p(S, E.current), n && n.setItem(l, a(S)), E.current = S;
413
+ const S = we(d) ? d(E.current) : d;
414
+ v.setStateVocab(P(l, S)), p(S, E.current), s && s.setItem(l, c(S)), E.current = S;
416
415
  },
417
416
  function() {
418
- const d = I(f, t);
417
+ const d = I(f, a);
419
418
  if (typeof d > "u") {
420
- n?.removeItem(l);
419
+ s?.removeItem(l);
421
420
  return;
422
421
  }
423
- v.setStateVocab(P(l, d)), p(d, E.current), E.current = d, n && n.setItem(l, a(d));
422
+ v.setStateVocab(P(l, d)), p(d, E.current), E.current = d, s && s.setItem(l, c(d));
424
423
  }
425
424
  ];
426
425
  },
@@ -431,15 +430,15 @@ function xe(r = {}) {
431
430
  };
432
431
  }
433
432
  const X = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap();
434
- function Q(r, n = "") {
435
- let a = X.get(r);
436
- a || (a = /* @__PURE__ */ new Map(), X.set(r, a));
437
- const s = a.get(n);
438
- if (s)
439
- return s;
440
- const t = new Proxy(r, {
441
- get(c, f) {
442
- const u = c[f], p = n ? `${n}.${String(f)}` : String(f);
433
+ function K(t, c = "") {
434
+ let o = X.get(t);
435
+ o || (o = /* @__PURE__ */ new Map(), X.set(t, o));
436
+ const a = o.get(c);
437
+ if (a)
438
+ return a;
439
+ const r = new Proxy(t, {
440
+ get(s, f) {
441
+ const u = s[f], p = c ? `${c}.${String(f)}` : String(f);
443
442
  if (u && typeof u == "object" && H in u) {
444
443
  const v = u;
445
444
  let l = B.get(v);
@@ -460,16 +459,16 @@ function Q(r, n = "") {
460
459
  ), _ = { ...v, ...E };
461
460
  return l.set(p, _), _;
462
461
  }
463
- return u && typeof u == "object" ? Q(u, p) : u;
462
+ return u && typeof u == "object" ? K(u, p) : u;
464
463
  }
465
464
  });
466
- return a.set(n, t), t;
465
+ return o.set(c, r), r;
467
466
  }
468
- function Pe(r) {
469
- return Q(r);
467
+ function je(t) {
468
+ return K(t);
470
469
  }
471
470
  export {
472
- we as StorageProvider,
473
- xe as defineState,
474
- Pe as setupStorage
471
+ Oe as StorageProvider,
472
+ Ae as defineState,
473
+ je as setupStorage
475
474
  };
@@ -0,0 +1,2 @@
1
+ export declare const STATE_DEFINITION: unique symbol;
2
+ export declare const STATE_PATH: unique symbol;
@@ -0,0 +1,11 @@
1
+ import { type SetStateAction, type PropsWithChildren, type Dispatch } from "react";
2
+ export type Vocab<T = unknown> = Record<string, T | null>;
3
+ type Context<V extends Vocab = Vocab> = {
4
+ stateVocab: V;
5
+ setStateVocab: Dispatch<SetStateAction<V>>;
6
+ };
7
+ export declare function useStateVocabContext<T>(): Context<Vocab<T>>;
8
+ export declare const StateVocabContextProvider: (props: PropsWithChildren<{
9
+ verbose?: boolean;
10
+ }>) => import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,3 @@
1
+ export { defineState } from "./state";
2
+ export { setupStorage } from "./setup";
3
+ export { StateVocabContextProvider as StorageProvider } from "./context";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function setupStorage<T extends object>(nativeRouter: T): T;
@@ -0,0 +1,23 @@
1
+ import { STATE_DEFINITION, STATE_PATH } from "./constants";
2
+ import type { ValueOrFactory, ValueOrTransformer } from "./types";
3
+ export declare function defineState<T>(definitionOptions?: {
4
+ storage?: ValueOrFactory<Storage>;
5
+ defaultValue?: T;
6
+ bidirectional?: true;
7
+ serialize?: (v: T) => string;
8
+ deserialize?: (v: string) => T;
9
+ }): {
10
+ [STATE_DEFINITION]: boolean;
11
+ [STATE_PATH]: string;
12
+ useState<D = T>(this: {
13
+ [STATE_PATH]: string;
14
+ }, defaultValue?: ValueOrFactory<D>, options?: {
15
+ delayedSet?: number;
16
+ bidirectional?: true;
17
+ onSet?(nextValue: NoInfer<D>, prevValue: NoInfer<D>): void;
18
+ }): readonly [D, (nextValue: ValueOrTransformer<D>) => void, () => void];
19
+ /** Returns the fully qualified job name (dot-separated path). */
20
+ toString(this: {
21
+ [STATE_PATH]: string;
22
+ }): string;
23
+ };
@@ -0,0 +1,14 @@
1
+ import type { Vocab } from "./context";
2
+ import type { ValueOrTransformer, Transformer, ValueOrFactory } from "./types";
3
+ export declare const embed: <D>(statePath: string, value: D) => (vocab: Vocab<D>) => {
4
+ [x: string]: D;
5
+ };
6
+ export declare const genDefaultValue: <V>(defaultValue: ValueOrFactory<V>, superDefaltValue: unknown) => V;
7
+ export declare const genStoredValue: <V>(options: {
8
+ serialized: string | null;
9
+ defaultValue: ValueOrFactory<V>;
10
+ superDefaultValue: unknown;
11
+ deserialize: (v: string) => V;
12
+ }) => V;
13
+ export declare const isTransformer: <V>(v: ValueOrTransformer<V>) => v is Transformer<V>;
14
+ export declare const valueOrFactory: <V>(input: ValueOrFactory<V>) => V;
@@ -0,0 +1,4 @@
1
+ export type Transformer<V> = (prev: V) => V;
2
+ export type ValueOrTransformer<V> = V | Transformer<V>;
3
+ export type Factory<V> = () => V;
4
+ export type ValueOrFactory<V> = V | Factory<V>;
@@ -0,0 +1,7 @@
1
+ import { type DependencyList } from "react";
2
+ export declare function get<T, Default = undefined>(obj: T, path: string, defaultValue?: Default): unknown | Default;
3
+ export declare function set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;
4
+ export declare function debounce<T extends (...args: never[]) => unknown>(func: T, wait?: number): (...args: Parameters<T>) => void;
5
+ export declare function useDebounce<T extends (...args: never[]) => unknown>(effect: T, wait: number | undefined, deps?: DependencyList): (...args: Parameters<T>) => void;
6
+ export declare const isJsonValid: (input: string) => boolean;
7
+ export declare function logStyled(obj: object): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakocloud/state-vocab",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
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,10 +18,11 @@
18
18
  },
19
19
  "scripts": {
20
20
  "dev": "vite",
21
- "build": "tsc -b && vite build",
21
+ "build": "tsc -b && vite build ; tsc --project tsconfig.types.json",
22
22
  "lint": "eslint .",
23
23
  "type-check": "tsc --project tsconfig.types.json",
24
- "build:types": "tsc --project tsconfig.types.json"
24
+ "test": "vitest run",
25
+ "test:watch": "vitest"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "react": "^19.2.1",
@@ -29,16 +30,20 @@
29
30
  },
30
31
  "devDependencies": {
31
32
  "@eslint/js": "^9.39.1",
33
+ "@testing-library/jest-dom": "^6.9.1",
34
+ "@testing-library/react": "^16.3.2",
32
35
  "@types/node": "^24.10.1",
33
36
  "@types/react": "^19.2.5",
34
37
  "@types/react-dom": "^19.2.3",
35
- "@vitejs/plugin-react": "^5.1.1",
38
+ "@vitejs/plugin-react": "^5.2.0",
36
39
  "eslint": "^9.39.1",
37
40
  "eslint-plugin-react-hooks": "^7.0.1",
38
41
  "eslint-plugin-react-refresh": "^0.4.24",
39
42
  "globals": "^16.5.0",
43
+ "jsdom": "^29.0.2",
40
44
  "typescript": "~5.9.3",
41
45
  "typescript-eslint": "^8.46.4",
42
- "vite": "^7.2.4"
46
+ "vite": "^7.2.4",
47
+ "vitest": "^4.1.5"
43
48
  }
44
49
  }