2 lines
7.4 KiB
JavaScript
2 lines
7.4 KiB
JavaScript
System.register(["jotai/vanilla"],(function(x){"use strict";var m;return{setters:[function(O){m=O.atom}],execute:(function(){x({atomFamily:$,atomWithDefault:X,atomWithLazy:lt,atomWithObservable:nt,atomWithReducer:P,atomWithRefresh:ct,atomWithReset:J,atomWithStorage:tt,createJSONStorage:V,freezeAtom:T,freezeAtomCreator:q,loadable:ut,selectAtom:K,splitAtom:U,unstable_withStorageValidator:Y,unwrap:_});const O=x("RESET",Symbol(""));function J(t){const e=m(t,(s,a,u)=>{const c=typeof u=="function"?u(s(e)):u;a(e,c===O?t:c)});return e}function P(t,e){return m(t,function(s,a,u){a(this,e(s(this),u))})}function $(t,e){let s=null;const a=new Map,u=new Set,c=i=>{let n;if(e===void 0)n=a.get(i);else for(const[l,f]of a)if(e(l,i)){n=f;break}if(n!==void 0)if(s!=null&&s(n[1],i))c.remove(i);else return n[0];const o=t(i);return a.set(i,[o,Date.now()]),r("CREATE",i,o),o},r=(i,n,o)=>{for(const l of u)l({type:i,param:n,atom:o})};return c.unstable_listen=i=>(u.add(i),()=>{u.delete(i)}),c.getParams=()=>a.keys(),c.remove=i=>{if(e===void 0){if(!a.has(i))return;const[n]=a.get(i);a.delete(i),r("REMOVE",i,n)}else for(const[n,[o]]of a)if(e(n,i)){a.delete(n),r("REMOVE",n,o);break}},c.setShouldRemove=i=>{if(s=i,!!s)for(const[n,[o,l]]of a)s(l,n)&&(a.delete(n),r("REMOVE",n,o))},c}const I=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),C=new WeakMap,F=(t,e,s,a)=>{const u=I(()=>new WeakMap,C,e),c=I(()=>new WeakMap,u,s);return I(t,c,a)};function K(t,e,s=Object.is){return F(()=>{const a=Symbol(),u=([r,i])=>{if(i===a)return e(r);const n=e(r,i);return s(i,n)?i:n},c=m(r=>{const i=r(c),n=r(t);return u([n,i])});return c.init=a,c},t,e,s)}const R=new WeakSet,L=t=>{if(typeof t!="object"||t===null)return t;Object.freeze(t);const e=Object.getOwnPropertyNames(t);for(const s of e)L(t[s]);return t};function T(t){if(R.has(t))return t;R.add(t);const e=t.read;if(t.read=function(s,a){return L(e.call(this,s,a))},"write"in t){const s=t.write;t.write=function(a,u,...c){return s.call(this,a,(...r)=>(r[0]===t&&(r[1]=L(r[1])),u(...r)),...c)}}return t}function q(t){return((...e)=>T(t(...e)))}const j=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),B=new WeakMap,G=(t,e,s)=>{const a=j(()=>new WeakMap,B,e);return j(t,a,s)},H={},N=t=>!!t.write,Q=t=>typeof t=="function";function U(t,e){return G(()=>{const s=new WeakMap,a=(r,i)=>{let n=s.get(r);if(n)return n;const o=i&&s.get(i),l=[],f=[];return r.forEach((w,v)=>{const d=e?e(w):v;f[v]=d;const g=o&&o.atomList[o.keyList.indexOf(d)];if(g){l[v]=g;return}const W=b=>{const y=b(u),h=b(t),S=a(h,y==null?void 0:y.arr).keyList.indexOf(d);if(S<0||S>=h.length){const p=r[a(r).keyList.indexOf(d)];if(p)return p;throw new Error("splitAtom: index out of bounds for read")}return h[S]},E=(b,y,h)=>{const S=b(u),p=b(t),k=a(p,S==null?void 0:S.arr).keyList.indexOf(d);if(k<0||k>=p.length)throw new Error("splitAtom: index out of bounds for write");const D=Q(h)?h(p[k]):h;Object.is(p[k],D)||y(t,[...p.slice(0,k),D,...p.slice(k+1)])};l[v]=N(t)?m(W,E):m(W)}),o&&o.keyList.length===f.length&&o.keyList.every((w,v)=>w===f[v])?n=o:n={arr:r,atomList:l,keyList:f},s.set(r,n),n},u=m(r=>{const i=r(u),n=r(t);return a(n,i==null?void 0:i.arr)});u.init=void 0;const c=N(t)?m(r=>r(u).atomList,(r,i,n)=>{switch(n.type){case"remove":{const o=r(c).indexOf(n.atom);if(o>=0){const l=r(t);i(t,[...l.slice(0,o),...l.slice(o+1)])}break}case"insert":{const o=n.before?r(c).indexOf(n.before):r(c).length;if(o>=0){const l=r(t);i(t,[...l.slice(0,o),n.value,...l.slice(o)])}break}case"move":{const o=r(c).indexOf(n.atom),l=n.before?r(c).indexOf(n.before):r(c).length;if(o>=0&&l>=0){const f=r(t);o<l?i(t,[...f.slice(0,o),...f.slice(o+1,l),f[o],...f.slice(l)]):i(t,[...f.slice(0,l),f[o],...f.slice(l,o),...f.slice(o+1)])}break}}}):m(r=>r(u).atomList);return c},t,e||H)}function X(t){const e=Symbol(),s=m(e),a=m((u,c)=>{const r=u(s);return r!==e?r:t(u,c)},(u,c,r)=>{const i=typeof r=="function"?r(u(a)):r;c(s,i===O?e:i)});return a}const M=t=>typeof(t==null?void 0:t.then)=="function";function Y(t){return e=>({...e,getItem:(s,a)=>{const u=r=>t(r)?r:a,c=e.getItem(s,a);return M(c)?c.then(u):u(c)}})}function V(t=()=>{try{return window.localStorage}catch(s){return}},e){var s;let a,u;const c={getItem:(n,o)=>{var l,f;const w=d=>{if(d=d||"",a!==d){try{u=JSON.parse(d,e==null?void 0:e.reviver)}catch(g){return o}a=d}return u},v=(f=(l=t())==null?void 0:l.getItem(n))!=null?f:null;return M(v)?v.then(w):w(v)},setItem:(n,o)=>{var l;return(l=t())==null?void 0:l.setItem(n,JSON.stringify(o,e==null?void 0:e.replacer))},removeItem:n=>{var o;return(o=t())==null?void 0:o.removeItem(n)}},r=n=>(o,l,f)=>n(o,w=>{let v;try{v=JSON.parse(w||"")}catch(d){v=f}l(v)});let i;try{i=(s=t())==null?void 0:s.subscribe}catch(n){}return!i&&typeof window!="undefined"&&typeof window.addEventListener=="function"&&window.Storage&&(i=(n,o)=>{if(!(t()instanceof window.Storage))return()=>{};const l=f=>{f.storageArea===t()&&f.key===n&&o(f.newValue)};return window.addEventListener("storage",l),()=>{window.removeEventListener("storage",l)}}),i&&(c.subscribe=r(i)),c}const Z=V();function tt(t,e,s=Z,a){const u=a==null?void 0:a.getOnInit,c=m(u?s.getItem(t,e):e);return c.onMount=r=>{var i;return r(s.getItem(t,e)),(i=s.subscribe)==null?void 0:i.call(s,t,r,e)},m(r=>r(c),(r,i,n)=>{const o=typeof n=="function"?n(r(c)):n;return o===O?(i(c,e),s.removeItem(t)):M(o)?o.then(l=>(i(c,l),s.setItem(t,l))):(i(c,o),s.setItem(t,o))})}const et=t=>typeof(t==null?void 0:t.then)=="function";function nt(t,e){const s=u=>{if("e"in u)throw u.e;return u.d},a=m(u=>{var c;const r=t(u),i=((c=r[Symbol.observable])==null?void 0:c.call(r))||r;let n;const o=()=>new Promise(h=>{n=h}),l=e&&"initialValue"in e?{d:typeof e.initialValue=="function"?e.initialValue():e.initialValue}:o();let f,w;const v=h=>{w=h,n==null||n(h),f==null||f(h)};let d,g;const W=()=>!f,E=()=>{d&&(d.unsubscribe(),d=void 0)},b=()=>{d&&(clearTimeout(g),d.unsubscribe()),d=i.subscribe({next:h=>v({d:h}),error:h=>v({e:h}),complete:()=>{}}),W()&&e!=null&&e.unstable_timeout&&(g=setTimeout(E,e.unstable_timeout))};b();const y=m(w||l);return y.onMount=h=>(f=h,w&&h(w),d?clearTimeout(g):b(),()=>{f=void 0,e!=null&&e.unstable_timeout?g=setTimeout(E,e.unstable_timeout):E()}),[y,r,o,b,W]});return m(u=>{const[c]=u(a),r=u(c);return et(r)?r.then(s):s(r)},(u,c,r)=>{const[i,n,o,l,f]=u(a);if("next"in n)f()&&(c(i,o()),l()),n.next(r);else throw new Error("observable is not subject")})}const z=(t,e,s)=>(e.has(s)?e:e.set(s,t())).get(s),rt=new WeakMap,ot=(t,e,s)=>{const a=z(()=>new WeakMap,rt,e);return z(t,a,s)},it=t=>typeof(t==null?void 0:t.then)=="function",st=()=>{};function _(t,e=st){return ot(()=>{const s=new WeakMap,a=new WeakMap,u=m(0),c=m([]);c.INTERNAL_onInit=i=>{i.set(c,[()=>i.set(u,n=>n+1)])};const r=m(i=>{i(u);let n;try{n=i(r)}catch(l){}const o=i(t);if(!it(o))return{v:o};if(o!==(n==null?void 0:n.p)&&o.then(l=>{a.set(o,l);const[f]=i(c);f()},l=>{s.set(o,l);const[f]=i(c);f()}),s.has(o))throw s.get(o);return a.has(o)?{p:o,v:a.get(o)}:n&&"v"in n?{p:o,f:e(n.v),v:n.v}:{p:o,f:e()}});return r.init=void 0,m(i=>{const n=i(r);return"f"in n?n.f:n.v},(i,n,...o)=>n(t,...o))},t,e)}const A=new WeakMap,at=(t,e)=>(A.has(e)?A:A.set(e,t())).get(e);function ut(t){return at(()=>{const e={state:"loading"},s=_(t,()=>e);return m(a=>{try{const u=a(s);return u===e?e:{state:"hasData",data:u}}catch(u){return{state:"hasError",error:u}}})},t)}function ct(t,e){const s=m(0);return m((a,u)=>(a(s),t(a,u)),(a,u,...c)=>{if(c.length===0)u(s,r=>r+1);else if(e)return e(a,u,...c)})}function lt(t){const e=m(void 0);return delete e.init,Object.defineProperty(e,"init",{get(){return t()}}),e}})}}));
|