atomaric 0.0.63 → 0.0.64
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/build/atomaric.js +1 -0
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +1 -1
- package/types/enums.ts +0 -6
package/build/atomaric.js
CHANGED
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(y,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(y=typeof globalThis<"u"?globalThis:y||self,l(y.atomaric={}))})(this,function(y){"use strict";var l=(e=>(e[e.None=0]="None",e[e.Simple=1]="Simple",e[e.Middle=2]="Middle",e[e.Strong=3]="Strong",e))(l||{});let X=()=>{throw"call configureAtomaric() before all!"};const N={},le=e=>{N.useSyncExternalStore=X=e.useSyncExternalStore,N.keyPathSeparator=e.keyPathSeparator,N.securifyKeyLevel=e.securifyKeyLevel,N.securifyValueLevel=e.securifyValueLevel},Y=e=>X(e.subscribe,e.get),Z=e=>e.set,fe=e=>e.setDeferred,ae=e=>e.get,de=e=>e.do,ge=e=>[Y(e),Z(e)],ye=(e,t)=>new te(e,t),he=(e,t)=>{const c=(f,p,b)=>new Proxy(f,{get:(s,r,o)=>{const u=b===0&&t.get!=null?t.get(s,r,o):s[r];return typeof u=="object"&&u!==null?c(Array.isArray(u)?u.slice(0):{...u},p.concat(Array.isArray(s)?+r:r),b+1):u},set:(s,r,o)=>(t.onSet(s,p,r,o,s[r])&&(s[r]=o),!0)});return c(e,[],0)},pe=(e,t,c)=>{let f=null;if(typeof e=="number")f=q(t,s=>({increment:r=>{s.set(+s.get()+(r??0))}}));else if(typeof e=="boolean")f=q(t,s=>({toggle:()=>{s.set(!s.get())}}));else if(Array.isArray(e))f=q(t,s=>({push:(...r)=>{s.set(s.get().concat(r))},unshift:(...r)=>{s.set(r.concat(s.get()))},update:r=>{const o=s.get(),u=O(o,r);u!==o&&s.set(u)},filter:r=>{s.set(s.get().filter(r??Se))},add:r=>{s.get().includes(r)||s.set(s.get().concat([r]))},remove:r=>{const o=s.get().indexOf(r);if(o<0)return;const u=s.get().slice(0);u.splice(o,1),s.set(u)},toggle:(r,o)=>{const u=s.get().slice(),g=u.indexOf(r);g<0?o?u.unshift(r):u.push(r):u.splice(g,1),s.set(u)}}));else if(e instanceof Set)f=q(t,s=>({add:r=>{s.set(new Set(s.get()).add(r))},delete:r=>{const o=new Set(s.get());o.delete(r),s.set(o)},toggle:r=>{const o=new Set(s.get());o.has(r)?o.delete(r):o.add(r),s.set(o)},clear:()=>{s.set(new Set)}}));else if(e instanceof Object){const s=N.keyPathSeparator||".";f=q(t,r=>({setPartial:o=>r.set(u=>({...u,...typeof o=="function"?o(r.get()):o})),update:o=>{const u=r.get(),g=O(u,o);g!==u&&r.set(g)},setDeepPartial:(o,u,g,$=s)=>{if(!$)return;if(o.includes($)){let T=o.split($);const A=T[T.length-1];T=T.slice(0,-1);const G={...r.get()};let h=G,V=g;for(const x of T){V=V==null?void 0:V[Array.isArray(V)?"0":x];const D=h[ee(h,x)]??(Array.isArray(V)?[]:{});if(D==null||typeof D!="object"){if(g==null)throw"Incorrect path for setDeepPartial";const L=typeof u=="function"?u(void 0):u;r.get()[o]!==L&&r.do.setPartial({[o]:L});return}h=h[ee(h,x)]=Array.isArray(D)?[...D]:{...D}}const w=h[A];h[A]=typeof u=="function"?u(h[A]):u,w!==h[A]&&r.set(G);return}const S=r.get()[o],m=typeof u=="function"?u(S):u;m!==S&&r.do.setPartial({[o]:m})}}))}const p=typeof c=="object"&&c!=null&&"do"in c?c.do((s,r)=>t.set(s,r),()=>t.get(),t,(s,r,o)=>t.setDeferred(s,r,o)):null,b={};return p&&Object.keys(p).forEach(s=>Object.defineProperty(b,s,{get:()=>p[s]})),f&&Object.keys(f).forEach(s=>Object.defineProperty(b,s,{get:()=>f[s]})),b},Se=e=>e,q=(e,t,c)=>t(e),O=(e,t)=>{const c=Array.isArray(e)?e.slice(0):{...e};let f=!1;const p=he(e,{onSet:(b,s,r,o,u)=>{if(o===u)return!0;let g=c;f=!0;for(const $ of s){const S=g[$];g=g[$]=Array.isArray(S)?S.slice(0):{...S}}return g[r]=o,!0}});return t(p),f?c:e},ee=(e,t)=>Array.isArray(e)?`${+t}`:t;class te{constructor(t,c){const f=n=>u=n,p=()=>u,b=new Set,s=n=>n(S());let r=!0,o=!1,u=t,g,$=()=>{},S=()=>p(),m=null,T=()=>{const n=pe(t,A,c);return T=()=>n,n};const A=new Proxy(this,{get:(n,d)=>d==="do"?T():n[d],set:we}),G=()=>{r=!0,o!==!0&&$(S()),o=!1;try{H.postMessage({key:a,value:p()})}catch{}},h=(n,d)=>{const j=typeof n=="function"?n(S()):n;j!==S()&&(f(j),o=d,r&&(r=!1,b.forEach(s),queueMicrotask(G)))};this.set=(n,d)=>h(n,d),this.get=()=>S(),this.initialValue=t,this.isInitialValue=()=>t===p(),this.subscribe=n=>(b.add(n),()=>{b.delete(n)}),this.reset=()=>{h(t,!0)};const V=(n,d)=>{h(n,d),g=void 0};if(this.setDeferred=(n,d=500,j,C=!0)=>{C&&g===void 0&&h(n,j),clearTimeout(g),g=setTimeout(V,d,n,j)},c==null)return A;let w=null,x=null,D=!0,L=!0,k=!1,P=l.None,E=l.None,ce=-1,z=t instanceof Set?n=>new Set(n):n=>n,R=t instanceof Set?n=>{if(n instanceof Set)return Array.from(n);throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof c=="string")w=c;else if("storeKey"in c)D=c.warnOnDuplicateStoreKey??D,L=c.listenStorageChanges??L,w=c.storeKey,z=c.unzipValue??z,R=c.zipValue??R,k=c.unchangable??k,P=c.securifyKeyLevel??N.securifyKeyLevel??P,E=c.securifyValueLevel??N.securifyValueLevel??E,x=c.exp??x;else return A;const v=P?M(w,P):w,a=`${E?J:_}${v}`;if(P){const n=`${_}${w}`;n in i&&(i[a]=i[n],delete i[n])}else{const n=`${_}${M(w,P)}`;n in i&&(i[a]=i[n],delete i[n])}const K=x===null||!(x(A,a in i)instanceof Date)?n=>M([R(n)],l.None):n=>(m??(m={}),m.exp=x(A,a in i).getTime(),m.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ce),clearTimeout(ne[a]),ce=setTimeout(()=>this.reset(),m.exp-Date.now())),m.exp=Math.trunc(m.exp/1e3),M([R(n),m],l.None));if(E){const n=`${_}${v}`,d=R,j=z;if(R=C=>{try{return M([d(C)],E)}catch{return delete i[a],""}},n in i){const C=`${_}${M(w,P)}`;try{i[C]=K(z(W(i[n],l.None)[0])),delete i[n]}catch{}}z=C=>{try{return j(W(C,E)[0])}catch{return delete i[a],""}}}else delete i[`${J}${v}`];const ie=n=>{const d=W(n,l.None);return m=d[1],z(d[0])};let oe=!0;if(B[a]=A,i[`atom/${w}`]&&(i[a]||(i[a]=`[${i[`atom/${w}`]}]`),delete i[`atom/${w}`]),S=()=>{if(S=p,oe){oe=!1;try{f(a in i?ie(i[a]):t)}catch{console.warn("Invalid json value",i[a])}}return p()},$=n=>{if(n===t){this.reset();return}i[a]=K(n)},this.reset=()=>{delete i[a],h(t,!0)},D&&I[a]!==void 0&&console.warn("Duplicate Atom key",w),L)if(k){let n=!1,d;U[a]=this,I[a]=()=>{clearTimeout(d),d=setTimeout(()=>n=!1,10),!n&&(n=!0,i[a]=K(p()))}}else I[a]=n=>{if(n.newValue===null){this.reset();return}try{h(ie(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return A}}let H;try{H=new BroadcastChannel("updateHere"),H.addEventListener("message",e=>{var t;(t=U[e.data.key])==null||t.set(e.data.value,!0)})}catch{}const i=localStorage,I={},U={},we=(e,t)=>{throw`${t} is readonly property`};window.addEventListener("storage",e=>{var t;e.key===null||e.newValue===e.oldValue||(t=I[e.key])==null||t.call(I,e)});const Ae=i.setItem.bind(i),be=i.removeItem.bind(i);i.setItem=(e,t)=>{U[e]===void 0&&Ae.call(i,e,t)},i.removeItem=e=>{U[e]===void 0&&be.call(i,e)};const me=/"exp":\s*(\d+)/,_="atom\\",J="atom`s\\",B={},ne={},re=/[a-z]/gi,F=5,Q={};for(let e=54;e<80;e++){if(e===68||e===72||e===55)continue;const t=String.fromCharCode(e+43).toUpperCase(),c=String.fromCharCode(e+43).toLowerCase();Q[t]=c,Q[c]=t}const se=e=>Q[e]??e,M=(()=>{const e={[l.None]:t=>JSON.stringify(t),[l.Simple]:t=>btoa(encodeURI(e[l.None](t))),[l.Middle]:t=>{const c=e[l.Simple](t);return`${c.slice(0,F)}${c.slice(F).replace(re,se)}`},[l.Strong]:t=>btoa(e[l.Middle](t))};return(t,c)=>{try{return e[c](t)}catch(f){if(c===l.None)throw f;return e[l.None](t)}}})(),W=(()=>{const e={[l.None]:t=>JSON.parse(t),[l.Simple]:t=>e[l.None](decodeURI(atob(t))),[l.Middle]:t=>e[l.Simple](`${t.slice(0,F)}${t.slice(F).replace(re,se)}`),[l.Strong]:t=>e[l.Middle](atob(t))};return(t,c)=>{try{return e[c](t)}catch(f){if(c===l.None)throw f;return e[l.None](t)}}})();setTimeout(()=>{Object.keys(i).forEach(e=>{var f;if(typeof i[e]!="string"||!e.startsWith(_)&&!e.startsWith(J))return;const t=+((f=i[e].match(me))==null?void 0:f[1]);if(!t||t*1e3-Date.now()>24*60*60*1e3)return;const c=W(i[e],l.None);!Array.isArray(c)||c[1]==null||!("exp"in c[1])||c[1].exp!==t||(ne[e]=setTimeout(()=>{B[e]?B[e].reset():delete i[e]},t*1e3-Date.now()))})},1e3),y.Atom=te,y.AtomSecureLevel=l,y.atom=ye,y.configureAtomaric=le,y.configuredOptions=N,y.useAtom=ge,y.useAtomDo=de,y.useAtomGet=ae,y.useAtomSet=Z,y.useAtomSetDeferred=fe,y.useAtomValue=Y,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED