tempest.games 0.1.39 → 0.1.40

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # tempest.games
2
2
 
3
+ ## 0.1.40
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [23a9345]
8
+ - atom.io@0.32.4
9
+
3
10
  ## 0.1.39
4
11
 
5
12
  ### Patch Changes
@@ -19,7 +19,7 @@ ${N.trace}`:`No previous disposal trace for ${n} was found.`);return}const o=t.m
19
19
  ${k.trace}`:`No previous disposal trace for ${o} was found.`),n}const p=Ye(s),m=c.molecules.get(p);if(!m){const k=t.disposalTraces.buffer.find(N=>(N==null?void 0:N.key)===p);return t.logger.error("❌","molecule",n,"claim failed:",`Could not allocate to ${p} in store "${t.config.name}".`,k?`
20
20
  ${p} was most recently disposed
21
21
  ${k.trace}`:`No previous disposal trace for ${p} was found.`),n}const y=t.moleculeGraph.getRelationEntries({downstreamMoleculeKey:h.stringKey}).filter(([,{source:k}])=>k!==o).map(([k])=>Ps(k));r&&c.moleculeGraph.delete(o),c.moleculeGraph.set({upstreamMoleculeKey:m.stringKey,downstreamMoleculeKey:h.stringKey},{source:m.stringKey});const v={type:"molecule_transfer",key:h.key,from:y,to:[m.key]};return wt(c)&&c.transactionMeta.phase==="building"&&c.transactionMeta.update.updates.push(v),n}function EA(t,s,n){switch(s){case"newValue":{eb(t,n);break}case"oldValue":{mo(n,t.token);break}}}function xA(t,s,n){switch(s){case"newValue":{mo(n,t.token);break}case"oldValue":{eb(t,n),t.subType==="atom"&&n.valueMap.set(t.token.key,t.value);break}}}function eb(t,s){const{family:n}=t.token;if(n){const r=s.families.get(n.key);r&&Et(s,r,Ps(n.subKey))}}function OA(t,s,n){switch(s){case"newValue":pa(n,t.provenance,t.key);break;case"oldValue":ma(n,t.key);break}}function _A(t,s,n){switch(s){case"newValue":ma(n,t.key);break;case"oldValue":{const r=t.provenance.map(Ps);pa(n,r,t.key);for(const[o,c]of t.values){const h=n.families.get(o);if(h){Et(n,h,t.key);const p=`${o}(${Ye(t.key)})`;n.valueMap.set(p,c)}}}break}}function TA(t,s,n){switch(s){case"newValue":{const r=t.to.length===1?t.to[0]:t.to;no(n,r,t.key,"exclusive")}break;case"oldValue":{const r=t.from.length===1?t.from[0]:t.from;no(n,r,t.key,"exclusive")}break}}function Ls(t,s,n){const r=t==="newValue"?s.updates:[...s.updates].reverse();for(const o of r)switch(o.type){case"atom_update":case"selector_update":vA(t,o,n);break;case"state_creation":EA(o,t,n);break;case"state_disposal":xA(o,t,n);break;case"molecule_creation":OA(o,t,n);break;case"molecule_disposal":_A(o,t,n);break;case"molecule_transfer":TA(o,t,n);break;case"transaction_update":Ls(t,o,n);break}}function tb(t,s){return t.transactionMeta.actionContinuities.getRelatedKey(s)}function nb(t,s){return t.transactionMeta.epoch.get(s)}function RA(t,s){if(!Yn(t))return;const r=tb(t,s);if(r!==void 0)return nb(t,r)}function Ff(t,s,n){Yn(t)&&s&&t.transactionMeta.epoch.set(s,n)}function NA(t,s,n){if(!Yn(t))return;const o=tb(t,s);o!==void 0&&t.transactionMeta.epoch.set(o,n)}const kA=(t,s)=>{var c;const n=ce(s),{parent:r}=n;if(r===null||!wt(n)||((c=n.transactionMeta)==null?void 0:c.phase)!=="building"){s.logger.warn("🐞","transaction","???","applyTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}n.transactionMeta.phase="applying",n.transactionMeta.update.output=t,r.child=null,r.on.transactionApplying.next(n.transactionMeta);const{updates:o}=n.transactionMeta.update;if(s.logger.info("🛄","transaction",n.transactionMeta.update.key,`Applying transaction with ${o.length} updates:`,o),Ls("newValue",n.transactionMeta.update,r),Yn(r)){NA(r,n.transactionMeta.update.key,n.transactionMeta.update.epoch);const h=ht(s,{key:n.transactionMeta.update.key,type:"transaction"});h==null||h.subject.next(n.transactionMeta.update),s.logger.info("🛬","transaction",n.transactionMeta.update.key,"Finished applying transaction.")}else wt(r)&&r.transactionMeta.update.updates.push(n.transactionMeta.update);r.on.transactionApplying.next(null)};function ib(t,s,n){if(!Yn(t))return;const{epoch:o,actionContinuities:c}=t.transactionMeta;c.set(s,n),o.has(s)||o.set(s,-1)}function MA(t){return{store:t}}function ln(t,...s){let n,r,o;if(s.length===1?n=s[0]:(r=s[0],o=s[1],n=Et(t,r,o)),"counterfeit"in n&&"family"in n){r=t.families.get(n.family.key);const c=n.family.subKey,h=t.disposalTraces.buffer.find(p=>(p==null?void 0:p.key)===c);switch(t.logger.error("❌",n.type,n.key,`could not be retrieved because it was not found in the store "${t.config.name}".`,h?`This state was previously disposed:
22
- ${h.trace}`:"No previous disposal trace was found."),r.type){case"atom_family":case"mutable_atom_family":return t.defaults.get(r.key);case"selector_family":case"readonly_selector_family":{if(t.defaults.has(r.key))return t.defaults.get(n.family.key);const p=ht(t,r).default(c);return t.defaults.set(r.key,p),p}}}return po(t,ht(t,n))}class Tt{constructor(s,n){g(this,"a");g(this,"b");g(this,"cardinality");g(this,"relations",new Map);g(this,"contents",new Map);g(this,"isAType");g(this,"isBType");g(this,"isContent");g(this,"makeContentKey",(s,n)=>`${s}:${n}`);g(this,"warn");var r,o;if(this.a=s.between[0],this.b=s.between[1],this.cardinality=s.cardinality,n!=null&&n.externalStore||(this.relations=new Map((r=s.relations)==null?void 0:r.map(([c,h])=>[c,new Set(h)])),this.contents=new Map(s.contents)),this.isAType=(n==null?void 0:n.isAType)??null,this.isBType=(n==null?void 0:n.isBType)??null,this.isContent=(n==null?void 0:n.isContent)??null,n!=null&&n.makeContentKey&&(this.makeContentKey=n.makeContentKey),n!=null&&n.externalStore){const c=n.externalStore;this.has=(h,p)=>c.has(h,p),this.addRelation=(h,p)=>{c.addRelation(h,p)},this.deleteRelation=(h,p)=>{c.deleteRelation(h,p)},this.replaceRelationsSafely=(h,p)=>{c.replaceRelationsSafely(h,p)},this.replaceRelationsUnsafely=(h,p)=>{c.replaceRelationsUnsafely(h,p)},this.getRelatedKeys=h=>c.getRelatedKeys(h),c.getContent&&(this.getContentInternal=h=>c.getContent(h),this.setContent=(h,p)=>{c.setContent(h,p)},this.deleteContent=h=>{c.deleteContent(h)});for(const[h,p]of s.relations??[]){let m=(o=this.isAType)!=null&&o.call(this,h)?h:void 0,y=m===void 0?h:void 0;for(const v of p)m??(m=v),y??(y=v),this.addRelation(m,y)}for(const[h,p]of s.contents??[])this.setContent(h,p)}n!=null&&n.warn&&(this.warn=n.warn)}getRelatedKeys(s){return this.relations.get(s)}addRelation(s,n){let r=this.relations.get(s),o=this.relations.get(n);r?r.add(n):(r=new Set([n]),this.relations.set(s,r)),o?o.add(s):(o=new Set([s]),this.relations.set(n,o))}deleteRelation(s,n){const r=this.relations.get(s);if(r){r.delete(n),r.size===0&&this.relations.delete(s);const o=this.relations.get(n);o&&(o.delete(s),o.size===0&&this.relations.delete(n))}}replaceRelationsUnsafely(s,n){this.relations.set(s,new Set(n));for(const r of n){const o=new Set().add(s);this.relations.set(r,o)}}replaceRelationsSafely(s,n){var h;const r=this.relations.get(s);let o=(h=this.isAType)!=null&&h.call(this,s)?s:void 0,c=o===void 0?s:void 0;if(r)for(const p of r){o??(o=p),c??(c=p);const m=this.relations.get(p);m&&(m.size===1?this.relations.delete(p):m.delete(s),this.contents.delete(this.makeContentKey(o,c)))}this.relations.set(s,new Set(n));for(const p of n){let m=this.relations.get(p);m?m.add(s):(m=new Set().add(s),this.relations.set(p,m))}}getContentInternal(s){return this.contents.get(s)}setContent(s,n){this.contents.set(s,n)}deleteContent(s){this.contents.delete(s)}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([s,n])=>[s,[...n]]),contents:[...this.contents.entries()]}}set(...s){let n,r,o;switch(s.length){case 1:{const c=s[0];n=c[this.a],r=c[this.b],o=void 0;break}case 2:{const c=s[0];typeof c=="string"?[n,r]=s:(n=c[this.a],r=c[this.b],o=s[1]);break}default:{n=s[0],r=s[1],o=s[2];break}}switch(this.cardinality){case"1:1":{const c=this.getRelatedKey(n);c&&c!==r&&this.delete(n,c)}case"1:n":{const c=this.getRelatedKey(r);c&&c!==n&&this.delete(c,r)}break}if(o){const c=this.makeContentKey(n,r);this.setContent(c,o)}return this.addRelation(n,r),this}delete(s,n){n=typeof n=="string"?n:s[this.b];const r=typeof s=="string"?s:s[this.a];if(r===void 0&&typeof n=="string"){const o=this.getRelatedKeys(n);if(o)for(const c of o)this.delete(c,n)}if(typeof r=="string"&&n===void 0){const o=this.getRelatedKeys(r);if(o)for(const c of o)this.delete(r,c)}if(typeof r=="string"&&typeof n=="string"){this.deleteRelation(r,n);const o=this.makeContentKey(r,n);this.deleteContent(o)}return this}getRelatedKey(s){var r;const n=this.getRelatedKeys(s);if(n){n.size>1&&((r=this.warn)==null||r.call(this,`${n.size} related keys were found for key "${s}": (${[...n].map(c=>`"${c}"`).join(", ")}). Only one related key was expected.`));let o;for(const c of n){o=c;break}return o}}replaceRelations(s,n,r){const o=!Array.isArray(n),c=o?Object.keys(n):n;if(r!=null&&r.reckless?this.replaceRelationsUnsafely(s,c):this.replaceRelationsSafely(s,c),o)for(const h of c){const p=this.makeContentKey(s,h),m=n[h];this.setContent(p,m)}return this}getContent(s,n){const r=this.makeContentKey(s,n);return this.getContentInternal(r)}getRelationEntries(s){const n=s[this.a],r=s[this.b];if(n!==void 0&&r===void 0){const o=this.getRelatedKeys(n);if(o)return[...o].map(c=>[c,this.getContent(n,c)])}if(n===void 0&&r!==void 0){const o=this.getRelatedKeys(r);if(o)return[...o].map(c=>[c,this.getContent(c,r)])}return[]}has(s,n){if(n){const r=this.getRelatedKeys(s);return(r==null?void 0:r.has(n))??!1}return this.relations.has(s)}}class Sn extends Map{constructor(n){super();g(this,"deleted",new Set);g(this,"source");this.source=n}get(n){if(super.has(n))return super.get(n);if(!this.deleted.has(n)&&this.source.has(n))return this.source.get(n)}set(n,r){return this.deleted.delete(n),super.set(n,r)}hasOwn(n){return super.has(n)}has(n){return!this.deleted.has(n)&&(super.has(n)||this.source.has(n))}delete(n){return this.deleted.add(n),super.delete(n)}}const $A=(t,s,n,r)=>{const o=ce(t),c={parent:o,child:null,on:o.on,loggers:o.loggers,logger:o.logger,config:o.config,atoms:new Sn(o.atoms),atomsThatAreDefault:new Set(o.atomsThatAreDefault),families:new Sn(o.families),joins:new Sn(o.joins),operation:{open:!1},readonlySelectors:new Sn(o.readonlySelectors),timelines:new Sn(o.timelines),timelineTopics:new Tt(o.timelineTopics.toJSON()),trackers:new Map,transactions:new Sn(o.transactions),selectorAtoms:new Tt(o.selectorAtoms.toJSON()),selectorGraph:new Tt(o.selectorGraph.toJSON(),{makeContentKey:(...y)=>y.sort().join(":")}),selectors:new Sn(o.selectors),valueMap:new Sn(o.valueMap),defaults:o.defaults,disposalTraces:t.disposalTraces.copy(),molecules:new Sn(o.molecules),moleculeGraph:new Tt(o.moleculeGraph.toJSON(),{makeContentKey:o.moleculeGraph.makeContentKey}),moleculeData:new Tt(o.moleculeData.toJSON(),{makeContentKey:o.moleculeData.makeContentKey}),moleculeJoins:new Tt(o.moleculeJoins.toJSON(),{makeContentKey:o.moleculeJoins.makeContentKey}),miscResources:new Sn(o.miscResources)},h=RA(t,s),p={phase:"building",update:{type:"transaction_update",key:s,id:r,epoch:h===void 0?Number.NaN:h+1,updates:[],params:n,output:void 0},toolkit:{get:(...y)=>ln(m,...y),set:(...y)=>{Pe(m,...y)},run:(y,v=Fg())=>Xf(m,y,v),find:(y,v)=>Et(m,y,v),json:y=>Qi(m,y),dispose:(...y)=>{mo(m,...y)},env:()=>MA(m)}},m=Object.assign(c,{transactionMeta:p});return o.child=m,t.logger.info("🛫","transaction",s,"Building transaction with params:",n),m};function sb(t,s){const n={key:s.key,type:"transaction",run:(c,h)=>{const p=$A(t,s.key,c,h);try{const m=ce(t),{toolkit:y}=p.transactionMeta,v=s.do(y,...c);return kA(v,m),v}catch(m){throw hA(r),t.logger.warn("💥","transaction",s.key,"caught:",m),m}},install:c=>sb(c,s),subject:new We},r=ce(t);r.transactions.set(n.key,n);const o=Is(n);return t.on.transactionCreation.next(o),o}function DA(t){return sb(tt.STORE,t)}function CA(t,s=Fg()){return Xf(tt.STORE,t,s)}class zA{constructor(s,n=null){g(this,"parent",null);g(this,"child",null);g(this,"valueMap",new Map);g(this,"defaults",new Map);g(this,"atoms",new Map);g(this,"selectors",new Map);g(this,"readonlySelectors",new Map);g(this,"atomsThatAreDefault",new Set);g(this,"selectorAtoms",new Tt({between:["selectorKey","atomKey"],cardinality:"n:n"}));g(this,"selectorGraph",new Tt({between:["upstreamSelectorKey","downstreamSelectorKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"trackers",new Map);g(this,"families",new Map);g(this,"joins",new Map);g(this,"transactions",new Map);g(this,"transactionMeta",{epoch:new Map,actionContinuities:new Tt({between:["continuity","action"],cardinality:"1:n"})});g(this,"timelines",new Map);g(this,"timelineTopics",new Tt({between:["timelineKey","topicKey"],cardinality:"1:n"}));g(this,"disposalTraces",new Jf(100));g(this,"molecules",new Map);g(this,"moleculeJoins",new Tt({between:["moleculeKey","joinKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"moleculeGraph",new Tt({between:["upstreamMoleculeKey","downstreamMoleculeKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"moleculeData",new Tt({between:["moleculeKey","stateFamilyKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"miscResources",new Map);g(this,"on",{atomCreation:new We,atomDisposal:new We,selectorCreation:new We,selectorDisposal:new We,timelineCreation:new We,transactionCreation:new We,transactionApplying:new tA(null),operationClose:new We,moleculeCreation:new We,moleculeDisposal:new We});g(this,"operation",{open:!1});g(this,"config",{name:"IMPLICIT_STORE",lifespan:"ephemeral"});g(this,"loggers",[new oA("warn",(s,n,r)=>!iw(r))]);g(this,"logger",{error:(...s)=>{for(const n of this.loggers)n.error(...s)},info:(...s)=>{for(const n of this.loggers)n.info(...s)},warn:(...s)=>{for(const n of this.loggers)n.warn(...s)}});var r,o;if(this.config={...n==null?void 0:n.config,...s},n!==null){this.valueMap=new Map(n==null?void 0:n.valueMap),this.operation={...n==null?void 0:n.operation},Yn(n)&&(this.transactionMeta={epoch:new Map(n==null?void 0:n.transactionMeta.epoch),actionContinuities:new Tt(n==null?void 0:n.transactionMeta.actionContinuities.toJSON())});for(const[,h]of n.families)(r=h.internalRoles)!=null&&r.includes("mutable")||(o=h.internalRoles)!=null&&o.includes("join")||h.install(this);const c=new Set;for(const[,h]of n.atoms)if(!c.has(h.key)&&(h.install(this),h.type==="mutable_atom")){const p=Qi(n,h),m=ub(h);c.add(p.key),c.add(m.key)}for(const[,h]of n.readonlySelectors)h.install(this);for(const[,h]of n.selectors)c.has(h.key)||h.install(this);for(const[,h]of n.transactions)h.install(this);for(const[,h]of n.timelines)h.install(this)}}}const tt={get STORE(){return globalThis.ATOM_IO_IMPLICIT_STORE??(globalThis.ATOM_IO_IMPLICIT_STORE=new zA({name:"IMPLICIT_STORE",lifespan:"ephemeral"})),globalThis.ATOM_IO_IMPLICIT_STORE}};function ht(t,s){let n,r=t;for(;r!==null;){switch(s.type){case"atom":case"mutable_atom":n=r.atoms.get(s.key);break;case"selector":n=r.selectors.get(s.key);break;case"readonly_selector":n=r.readonlySelectors.get(s.key);break;case"atom_family":case"mutable_atom_family":case"selector_family":case"readonly_selector_family":n=r.families.get(s.key);break;case"timeline":n=r.timelines.get(s.key);break;case"transaction":n=r.transactions.get(s.key);break}if(n)return n;r=r.child}throw new Zf(s,t)}function UA(t,s,n){const r=t.families.get(s.key);if(r===void 0)throw new Zf(s,t);const o=r(n),c=ce(t);if(o.family)if(Yn(c))switch(o.type){case"atom":case"mutable_atom":t.on.atomCreation.next(o);break;case"selector":case"readonly_selector":t.on.selectorCreation.next(o);break}else wt(c)&&c.on.transactionApplying.state===null&&c.transactionMeta.update.updates.push({type:"state_creation",token:o});return o}function BA(t,s,n){const r=Ye(n),o=`${s.key}(${r})`,c=ce(t);let h;switch(s.type){case"atom_family":case"mutable_atom_family":h=c.atoms.get(o);break;case"selector_family":h=c.selectors.get(o);break;case"readonly_selector_family":h=c.readonlySelectors.get(o);break}return h&&Is(h)}function Et(t,s,n){let r=BA(t,s,n);if(r)return r;const o=Ye(n),c=t.molecules.get(o);if(!c&&t.config.lifespan==="immortal"){const h=sA(s,n);return t.logger.error("❌",h.type,h.key,`was not found in store "${t.config.name}"; returned a counterfeit token.`),h}return r=UA(t,s,n),c&&ce(t).moleculeData.set(o,s.key),r}function mo(t,...s){let n;if(s.length===1)n=s[0];else{const r=s[0],o=s[1];n=Et(t,r,o)}try{ht(t,n)}catch{t.logger.error("❌",n.type,n.key,`could not be disposed because it was not found in the store "${t.config.name}".`);return}switch(n.type){case"atom":case"mutable_atom":sh(t,n);break;case"selector":case"readonly_selector":VA(t,n);break}}const Wf=(t,s)=>ce(t).atoms.has(s),qA=(t,s)=>ce(t).selectors.has(s),jA=(t,s)=>ce(t).readonlySelectors.has(s),KA=(t,s)=>Wf(t,s)||qA(t,s)||jA(t,s),df=(t,s)=>ce(s).selectorGraph.getRelationEntries({downstreamSelectorKey:t}).filter(([r,{source:o}])=>o!==t).map(([r,{source:o}])=>o).filter(r=>KA(s,r)),rb=(t,s,n)=>{const r=[],o=df(t,n);for(;o.length>0;){const c=o.shift();s.has(c)||(s.add(c),Wf(n,c)?r.includes(c)||r.push(c):o.push(...df(c,n)))}return r},LA=(t,s)=>{const n=t.key,r=df(n,s),o=new Set;return r.flatMap(c=>Wf(s,c)?c:rb(c,o,s))},HA=(t,s,n,r)=>{const o=ce(r);if(s.type==="atom"||s.type==="mutable_atom")o.selectorAtoms.set({selectorKey:t,atomKey:s.key}),r.logger.info("🔍","selector",t,`discovers root atom "${s.key}"`);else{const c=rb(s.key,n,r);r.logger.info("🔍","selector",t,`discovers root atoms: [ ${c.map(h=>`"${h}"`).join(", ")} ]`);for(const h of c)o.selectorAtoms=o.selectorAtoms.set({selectorKey:t,atomKey:h})}n.add(s.key)},ab=(t,s,n)=>({get:(...r)=>{const o=ce(n);let c;if(r.length===2){const[m,y]=r;c=Et(n,m,y)}else[c]=r;const h=ht(n,c),p=po(n,h);return n.logger.info("🔌","selector",t,`registers dependency ( "${c.key}" =`,p,")"),o.selectorGraph.set({upstreamSelectorKey:c.key,downstreamSelectorKey:t},{source:c.key}),HA(t,c,s,n),p},set:(...r)=>{let o,c;if(r.length===2)o=r[0],c=r[1];else{const m=r[0],y=r[1];c=r[2],o=Et(n,m,y)}const h=ce(n),p=ht(h,o);Pg(h,p,c)},find:(r,o)=>Et(n,r,o),json:r=>Qi(n,r)}),Pf=(t,s,n)=>{const r=ce(t),o=new We,c=new Set,{get:h,find:p,json:m}=ab(s.key,c,r),y=()=>{const N=s.get({get:h,find:p,json:m});return Ji(ce(t),s.key,N,o),c.clear(),N},v={...s,subject:o,install:N=>Pf(N,s,n),get:y,type:"readonly_selector",...n&&{family:n}};r.readonlySelectors.set(s.key,v);const E=y();t.logger.info("✨",v.type,v.key,"=",E);const k={key:s.key,type:"readonly_selector"};return n&&(k.family=n),k},eh=(t,s,n)=>{const r=ce(t),o=new We,c=new Set,h=ab(s.key,c,r),{find:p,get:m,json:y}=h,v={find:p,get:m,json:y},E=(X=s.get,F=ce(t))=>{const le=X(v);return Ji(F,s.key,le,o),c.clear(),le},N={...s,subject:o,install:X=>eh(X,s,n),get:E,set:X=>{const F=ce(t),le=E(s.get,F),ve=Wg(X)(le);t.logger.info("📝","selector",s.key,"set (",le,"->",ve,")"),Ji(F,s.key,ve,o),Qf(F,s.key),Yn(F)&&o.next({newValue:ve,oldValue:le}),s.set(h,ve)},type:"selector",...n&&{family:n}};r.selectors.set(s.key,N);const B=E();t.logger.info("✨",N.type,N.key,"=",B);const j={key:s.key,type:"selector"};return n&&(j.family=n),j};function lb(t,s){if("set"in s){const o=eh(t,s,void 0);return t.on.selectorCreation.next(o),o}const r=Pf(t,s,void 0);return t.on.selectorCreation.next(r),r}function VA(t,s){const n=ce(t),{key:r}=s,o=ht(n,s);if(!o.family)t.logger.error("❌","selector",r,"Standalone selectors cannot be disposed.");else{n.molecules.get(o.family.subKey)&&n.moleculeData.delete(o.family.subKey,o.family.key);let h;switch(s.type){case"selector":n.selectors.delete(r),h={key:o.family.key,type:"selector_family"},ht(t,h).subject.next({type:"state_disposal",subType:"selector",token:s});break;case"readonly_selector":n.readonlySelectors.delete(r),h={key:o.family.key,type:"readonly_selector_family"},ht(t,h).subject.next({type:"state_disposal",subType:"selector",token:s});break}n.valueMap.delete(r),n.selectorAtoms.delete(r),n.selectorGraph.delete(r),t.logger.info("🔥",s.type,r,"deleted"),wt(n)&&n.transactionMeta.phase==="building"?n.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:s}):t.on.selectorDisposal.next(s)}}function th(t,s,n){const r={key:s.key,type:"selector_family"},o=t.families.get(s.key);o&&t.logger.error("❗","selector_family",s.key,`Overwriting an existing ${da(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new We,p=Object.assign(m=>{const y=Ye(m),v={key:s.key,subKey:y},E=`${s.key}(${y})`,k=ce(t),N=eh(k,{key:E,get:s.get(m),set:s.set(m)},v);return c.next({type:"state_creation",token:N}),N},r,{internalRoles:n,subject:c,install:m=>th(m,s),default:m=>s.get(m)({get:(...v)=>ln(t,...v),find:(v,E)=>Et(t,v,E),json:v=>Qi(t,v)})});return t.families.set(s.key,p),r}function GA(t,s,n){return th(t,{key:`${s.key}:JSON`,get:o=>({get:c})=>{const h=c(s,o);return n.toJson(h)},set:o=>({set:c},h)=>{c(s,o,n.fromJson(h))}},["mutable","json"])}const Ps=t=>JSON.parse(t),Ye=t=>JSON.stringify(t),YA=(t,s)=>{const n=ce(t);return n.operation.open?n.operation.prev.get(s.key):n.valueMap.get(s.key)},Ty=(t,s)=>{const n=ce(t);return LA(s,t).map(o=>{const c=n.atoms.get(o);if(c===void 0)throw new Error(`Atom "${o}", a dependency of selector "${s.key}", not found in store "${t.config.name}".`);return c.subject.subscribe(`${s.type}:${s.key}`,h=>{t.logger.info("📢",s.type,s.key,"root",o,"went",h.oldValue,"->",h.newValue);const p=YA(n,s),m=po(n,s);t.logger.info("✨",s.type,s.key,"went",p,"->",m),s.subject.next({newValue:m,oldValue:p})})})};function ua(t,s,n,r){function o(E){if(t.operation.open){const k=t.on.operationClose.subscribe(`state subscription ${n}`,()=>{k(),r(E)})}else r(E)}const c=ht(t,s);t.logger.info("👀",c.type,c.key,`Adding subscription "${n}"`);const h=c.type==="selector"||c.type==="readonly_selector";let p=null,m=o;h&&(p=Ty(t,c),m=E=>{p&&(p.length=0,p.push(...Ty(t,c))),o(E)});const y=c.subject.subscribe(n,m);return()=>{if(t.logger.info("🙈",c.type,c.key,`Removing subscription "${n}"`),y(),p)for(const E of p)E()}}const JA=(t,s,n,r)=>{const o=ht(t,s);t.logger.info("👀","timeline",s.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","timeline",s.key,`Removing subscription "${n}" from timeline`),c()}},IA=(t,s,n,r)=>{const o=ht(t,s);t.logger.info("👀","transaction",s.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","transaction",s.key,`Removing subscription "${n}"`),c()}};var Bg;Bg=Symbol.dispose;class nh{constructor(s,n){g(this,"Update");g(this,"unsubscribeFromInnerValue");g(this,"unsubscribeFromState");g(this,"mutableState");g(this,"latestUpdateState");g(this,Bg);this.mutableState=s;const r=ce(n);this.latestUpdateState=this.initializeState(s,r),this.observeCore(s,this.latestUpdateState,r),this.updateCore(s,this.latestUpdateState,r),r.trackers.set(s.key,this),this[Symbol.dispose]=()=>{this.unsubscribeFromInnerValue(),this.unsubscribeFromState(),r.trackers.delete(s.key)}}initializeState(s,n){var h;const r=`*${s.key}`;n.atoms.delete(r),n.valueMap.delete(r);const o=s.family?{key:`*${s.family.key}`,subKey:s.family.subKey}:void 0,c=yo(n,{key:r,default:null},o);if((h=n.parent)!=null&&h.valueMap.has(r)){const p=n.parent.valueMap.get(r);n.valueMap.set(r,p)}return c}observeCore(s,n,r){const o=`tracker:${r.config.name}:${wt(r)?r.transactionMeta.update.key:"main"}:${s.key}`,c=ln(r,s);this.unsubscribeFromInnerValue=c.subscribe(o,h=>{Pe(r,n,h)}),this.unsubscribeFromState=ua(r,s,o,h=>{h.newValue!==h.oldValue&&(this.unsubscribeFromInnerValue(),this.unsubscribeFromInnerValue=h.newValue.subscribe(o,p=>{Pe(r,n,p)}))})}updateCore(s,n,r){const o=`tracker:${r.config.name}:${wt(r)?r.transactionMeta.update.key:"main"}:${s.key}`;ua(r,n,o,({newValue:c,oldValue:h})=>{const p=r.timelineTopics.getRelatedKey(n.key);if(p){const y=r.timelines.get(p);if(y!=null&&y.timeTraveling){const v=JA(r,{key:p,type:"timeline"},o,E=>{v(),Pe(r,s,k=>(E==="redo"&&c?k.do(c):E==="undo"&&h&&k.undo(h),k))});return}}const m=r.on.operationClose.subscribe(o,()=>{m();const y=ln(r,s),v=c===null?-1:y.getUpdateNumber(c),E=v-y.cacheUpdateNumber;c&&E===1?Pe(r,s,k=>(k.do(c),k)):r.logger.info("❌","mutable_atom",s.key,`could not be updated. Expected update number ${y.cacheUpdateNumber+1}, but got ${v}`)})})}}function ih(t,s,n){t.logger.info("🔨","atom",s.key,`creating in store "${t.config.name}"`);const r=ce(t),o=r.atoms.get(s.key);if(o&&o.type==="mutable_atom")return t.logger.error("❌","atom",s.key,"Tried to create atom, but it already exists in the store."),Is(o);const c=new We,h={...s,type:"mutable_atom",install:y=>(y.logger.info("🛠️","atom",s.key,`installing in store "${y.config.name}"`),ih(y,s,n)),subject:c};n&&(h.family=n);const p=s.default();r.atoms.set(h.key,h),cb(t,s.key),Ji(r,s.key,p,c);const m=Is(h);if(s.effects){let y=0;const v=[];for(const E of s.effects){const k=E({setSelf:N=>{Pe(t,m,N)},onSet:N=>ua(t,m,`effect[${y}]`,N)});k&&v.push(k),++y}h.cleanup=()=>{for(const E of v)E()}}return new nh(m,t),n||eA(m,s,t),m}class ZA{constructor(s,n){g(this,"trackers",new Map);g(this,"Update");g(this,"latestUpdateAtoms");g(this,"mutableAtoms");const r=Yf(n,{key:`*${s.key}`,default:null},["mutable","updates"]);this.latestUpdateAtoms=ht(n,r),this.mutableAtoms=s,this.mutableAtoms.subject.subscribe(`store=${n.config.name}::tracker-atom-family`,o=>{const{type:c,token:h}=o;if(h.family){const p=Ps(h.family.subKey);switch(c){case"state_creation":this.trackers.set(p,new nh(h,n));break;case"state_disposal":{const m=this.trackers.get(p);m&&(m[Symbol.dispose](),this.trackers.delete(p))}break}}})}}function ob(t,s,n){const r={key:s.key,type:"mutable_atom_family"},o=t.families.get(s.key);o&&t.logger.error("❗","mutable_atom_family",s.key,`Overwriting an existing ${da(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new We,p=Object.assign(m=>{const y=Ye(m),v={key:s.key,subKey:y},E=`${s.key}(${y})`,k=ce(t),N={key:E,default:()=>s.default(m),toJson:s.toJson,fromJson:s.fromJson,mutable:!0};s.effects&&(N.effects=s.effects(m));const B=ih(k,N,v);return c.next({type:"state_creation",token:B}),B},r,{subject:c,install:m=>ob(m,s),toJson:s.toJson,fromJson:s.fromJson,internalRoles:n});return t.families.set(s.key,p),GA(t,p,s),new ZA(p,t),r}const Ry=(t,s)=>{const n=ce(s),r=`${t.key}:JSON`;return n.families.get(r)},Qi=(t,s)=>{if(s.family){const r=ce(t),c={key:`${s.family.key}:JSON`,type:"selector_family"},h=ht(r,c),p=JSON.parse(s.family.subKey);return Et(t,h,p)}return{type:"selector",key:`${s.key}:JSON`}},ub=t=>{const n={type:"atom",key:`*${t.key}`};return t.family&&(n.family={key:`*${t.family.key}`,subKey:t.family.subKey}),n};function XA(t){return typeof t=="object"&&t!==null&&"do"in t&&"undo"in t&&"subscribe"in t}function pf(t,s,n){const r=n.valueMap.get(s.key),o=t.valueMap.get(s.key);if(r!==o)return o;if(r===void 0)return s.default();n.logger.info("📃","atom",s.key,"copying");const c=s.toJson(r),h=s.fromJson(c);return t.valueMap.set(s.key,h),new nh(s,n),h}function Ji(t,s,n,r){const o=t.valueMap.get(s);if(o instanceof ff&&o.use(n),n instanceof Promise){const c=new ff(n);return t.valueMap.set(s,c),c.then(h=>{Ji(t,s,h,r),r.next({newValue:h,oldValue:c})}).catch(h=>{t.logger.error("💥","state",s,"rejected:",h)}),c}return t.valueMap.set(s,n),n}const QA=(t,s)=>{let n=s.valueMap.get(t.key);if(t.type==="mutable_atom"&&wt(s)){const{parent:r}=s;n=pf(s,t,r)}return n},FA=(t,s)=>{const n=s.valueMap.get(t);if(n instanceof ff){const r=n,o=s.selectors.get(t)??s.readonlySelectors.get(t);o&&r.use(o.get());return}s.operation.open&&s.operation.prev.set(t,n),s.valueMap.delete(t),s.logger.info("🗑","state",t,"evicted")},WA=(t,s)=>ce(t).atomsThatAreDefault.has(s),cb=(t,s)=>{const n=ce(t);n.atomsThatAreDefault=new Set(n.atomsThatAreDefault).add(s)},PA=(t,s)=>{const n=ce(t);n.atomsThatAreDefault=new Set(ce(t).atomsThatAreDefault),n.atomsThatAreDefault.delete(s)};function yo(t,s,n){t.logger.info("🔨","atom",s.key,`creating in store "${t.config.name}"`);const r=ce(t),o=r.atoms.get(s.key);if(o&&o.type==="atom")return t.logger.error("❌","atom",s.key,"Tried to create atom, but it already exists in the store."),Is(o);const c=new We,h={...s,type:"atom",install:y=>(y.logger.info("🛠️","atom",s.key,`installing in store "${y.config.name}"`),yo(y,s,n)),subject:c};n&&(h.family=n);let p=s.default;s.default instanceof Function&&(p=s.default()),r.atoms.set(h.key,h),cb(t,s.key),Ji(r,s.key,p,c);const m=Is(h);if(s.effects){let y=0;const v=[];for(const E of s.effects){const k=E({setSelf:N=>{Pe(t,m,N)},onSet:N=>ua(t,m,`effect[${y}]`,N)});k&&v.push(k),++y}h.cleanup=()=>{for(const E of v)E()}}return m}function ew(t,s){if("mutable"in s){const o=ih(t,s,void 0);return t.on.atomCreation.next(o),o}const r=yo(t,s,void 0);return t.on.atomCreation.next(r),r}function sh(t,s){var h;const n=ce(t),{key:r,family:o}=s,c=ht(n,s);if(!o)t.logger.error("❌","atom",r,"Standalone atoms cannot be disposed.");else{(h=c.cleanup)==null||h.call(c);const p=t.valueMap.get(c.key),m=ht(t,{key:o.key,type:"atom_family"}),y={type:"state_disposal",subType:"atom",token:s,value:p};m.subject.next(y);const v=wt(n);if(n.atoms.delete(r),n.valueMap.delete(r),n.selectorAtoms.delete(r),n.atomsThatAreDefault.delete(r),t.timelineTopics.delete(r),s.type==="mutable_atom"){const E=ub(s);sh(t,E),t.trackers.delete(r)}if(t.logger.info("🔥","atom",r,"deleted"),v&&n.transactionMeta.phase==="building"){const E=n.transactionMeta.update.updates.at(-1);(E==null?void 0:E.type)==="molecule_disposal"&&E.values.some(([B])=>{var j;return B===((j=c.family)==null?void 0:j.key)})||n.transactionMeta.update.updates.push(y)}else t.on.atomDisposal.next(s)}}class An extends Set{constructor(n,r=0){super(n);g(this,"mode","record");g(this,"subject",new We);g(this,"cacheLimit",0);g(this,"cache",[]);g(this,"cacheIdx",-1);g(this,"cacheUpdateNumber",-1);g(this,"parent");g(this,"child",null);g(this,"transactionUpdates",null);n instanceof An&&(this.parent=n,this.cacheUpdateNumber=n.cacheUpdateNumber),r&&(this.cacheLimit=r,this.cache=new Array(r),this.subscribe("auto cache",o=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=o}))}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(n){const r=new An(n.members,n.cacheLimit);return r.cache=n.cache,r.cacheIdx=n.cacheIdx,r.cacheUpdateNumber=n.cacheUpdateNumber,r}add(n){const r=super.add(n);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`add:${Ye(n)}`)),r}clear(){const n=this.mode==="record"?[...this]:null;super.clear(),n&&(this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(n)}`))}delete(n){const r=super.delete(n);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`del:${Ye(n)}`)),r}transaction(n){this.mode="transaction",this.transactionUpdates=[],this.child=new An(this);const r=this.child._subscribe("transaction",o=>{var c;(c=this.transactionUpdates)==null||c.push(o)});try{if(n(this.child)){for(const c of this.transactionUpdates)this.doStep(c);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(o){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",o),o}finally{r(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(n,r){return this.subject.subscribe(n,r)}subscribe(n,r){return this.subject.subscribe(n,o=>{r(`${this.cacheUpdateNumber}=${o}`)})}emit(n){this.subject.next(n)}doStep(n){const r=n.indexOf(":"),o=n.substring(0,r),c=n.substring(r+1);switch(o){case"add":this.add(JSON.parse(c));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(c));break;case"tx":for(const h of c.split(";"))this.doStep(h)}}getUpdateNumber(n){const r=n.indexOf("=");return Number(n.substring(0,r))}do(n){const r=n.indexOf("="),o=Number(n.substring(0,r)),c=o-this.cacheUpdateNumber;if(c>0){if(c===1){this.mode="playback";const p=n.substring(r+1);return this.doStep(p),this.mode="record",this.cacheUpdateNumber=o,null}return this.cacheUpdateNumber+1}if(Math.abs(c)<this.cacheLimit){const p=this.cacheIdx+c;if(this.cache[p]===n)return null;this.mode="playback";let y=!1;for(;!y;){this.cacheIdx%=this.cacheLimit;const E=this.cache[this.cacheIdx];if(this.cacheIdx--,!E)return"OUT_OF_RANGE";this.undo(E),y=this.cacheIdx===p-1}const v=n.substring(r+1);return this.doStep(v),this.mode="record",this.cacheUpdateNumber=o,null}return"OUT_OF_RANGE"}undoStep(n){const r=n.indexOf(":"),o=n.substring(0,r),c=n.substring(r+1);switch(o){case"add":this.delete(JSON.parse(c));break;case"del":this.add(JSON.parse(c));break;case"clear":{const h=JSON.parse(c);for(const p of h)this.add(p);break}case"tx":{const h=c.split(";");for(let p=h.length-1;p>=0;p--)this.undoStep(h[p])}}}undo(n){const r=n.indexOf("=");if(Number(n.substring(0,r))===this.cacheUpdateNumber){this.mode="playback";const c=n.substring(r+1);return this.undoStep(c),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}}class fb{constructor(s,n,r=tt.STORE){g(this,"toolkit");g(this,"options");g(this,"defaultContent");g(this,"molecules",new Map);g(this,"relations");g(this,"states");g(this,"core");g(this,"store");g(this,"realm");this.store=r,this.realm=new cA(r),this.options=s,this.defaultContent=n,this.store.miscResources.set(`join:${s.key}`,this),this.realm.allocate("root",s.key),this.toolkit={get:(...z)=>ln(r,...z),set:(...z)=>{Pe(r,...z)},find:(...z)=>Et(r,...z),json:z=>Qi(r,z)};const o=s.between[0],c=s.between[1],h=ob(r,{key:`${s.key}/relatedKeys`,default:()=>new An,mutable:!0,fromJson:z=>An.fromJSON(z),toJson:z=>z.toJSON()},["join","relations"]);this.core={relatedKeysAtoms:h};const p=({get:z},G)=>z(h,G),m=({set:z},G,re)=>{this.store.molecules.has(Ye(G))||this.realm.allocate(s.key,G),z(h,G,I=>I.add(re)),z(h,re,I=>I.add(G))},y=({set:z},G,re)=>{z(h,G,I=>(I.delete(re),I)),z(h,re,I=>(I.delete(G),I))},v=(z,G,re)=>{const{find:I,get:ie,set:me}=z,_e=I(h,G),Te=ie(_e);for(const Le of Te)re.includes(Le)||me(h,Le,Ce=>(Ce.delete(G),Ce));me(_e,Le=>(Le.transaction(bt=>{bt.clear();for(const Ce of re){const M=p(z,Ce),H=M.has(G);if(this.relations.cardinality==="1:n"){const W=[];for(const be of M){if(be===G)continue;const A=p(z,be);A.delete(Ce),A.size===0&&W.push(be)}!H&&M.size>0&&M.clear();for(const be of W){const A=[Ce,be].sort(),U=`"${A[0]}:${A[1]}"`;this.molecules.delete(U)}}H||M.add(G),bt.add(Ce)}return!0}),Le))},E=(z,G,re)=>{const{set:I}=z;I(h,G,ie=>(ie.transaction(me=>{for(const _e of re)me.add(_e);return!0}),ie));for(const ie of re)I(h,ie,me=>(me.add(G),me));return!0},k=(z,G,re)=>{const I=p(z,G);return re?I.has(re):I.size>0},N={getRelatedKeys:z=>p(this.toolkit,z),addRelation:(z,G)=>{this.store.moleculeJoins.set(z,s.key),this.store.moleculeJoins.set(G,s.key),m(this.toolkit,z,G)},deleteRelation:(z,G)=>{y(this.toolkit,z,G)},replaceRelationsSafely:(z,G)=>{v(this.toolkit,z,G)},replaceRelationsUnsafely:(z,G)=>{E(this.toolkit,z,G)},has:(z,G)=>k(this.toolkit,z,G)};let B,j;if(n){j=Yf(r,{key:`${s.key}/content`,default:n},["join","content"]);const z=({get:I},ie)=>I(j,ie),G=({set:I},ie,me)=>{I(j,ie,me)};B=Object.assign(N,{getContent:I=>z(this.toolkit,I),setContent:(I,ie)=>{G(this.toolkit,I,ie)},deleteContent:I=>{this.realm.deallocate(I)}})}else B=N;const X=new Tt(s,{externalStore:B,isAType:s.isAType,isBType:s.isBType,makeContentKey:(...z)=>{const[G,re]=z,I=z.sort(),ie=`${I[0]}:${I[1]}`,me=r.molecules.get(Ye(G)),_e=r.molecules.get(Ye(re));return me||this.realm.allocate(s.key,G),_e||this.realm.allocate(s.key,re),this.realm.allocate(G,ie,"all"),this.realm.claim(re,ie),this.store.moleculeJoins.set(ie,s.key),ie}}),F=()=>Ks(r,{key:`${s.key}/singleRelatedKey`,get:z=>({get:G})=>{const re=G(h,z);for(const I of re)return I;return null}},["join","keys"]),le=()=>Ks(r,{key:`${s.key}/multipleRelatedKeys`,get:z=>({get:G})=>{const re=Ry(h,r);return G(re,z).members}},["join","keys"]),ve=()=>Ks(r,{key:`${s.key}/singleRelatedEntry`,get:z=>({get:G})=>{var I;const re=G(h,z);for(const ie of re){let me=(I=X.isAType)!=null&&I.call(X,z)?z:void 0,_e=me===void 0?z:void 0;me??(me=ie),_e??(_e=ie);const Te=X.makeContentKey(me,_e),Le=G(j,Te);return[ie,Le]}return null}},["join","entries"]),gt=()=>Ks(r,{key:`${s.key}/multipleRelatedEntries`,get:z=>({get:G})=>{const re=Ry(h,r);return G(re,z).members.map(ie=>{var bt;let me=(bt=X.isAType)!=null&&bt.call(X,z)?z:void 0,_e=me===void 0?z:void 0;me??(me=ie),_e??(_e=ie);const Te=X.makeContentKey(me,_e),Le=G(j,Te);return[ie,Le]})}},["join","entries"]);switch(s.cardinality){case"1:1":{const z=F(),G=`${o}KeyOf${Jt(c)}`,re=`${c}KeyOf${Jt(o)}`,I={[G]:z,[re]:z};let ie;if(n){const me=ve(),_e=`${o}EntryOf${Jt(c)}`,Te=`${c}EntryOf${Jt(o)}`,Le={[_e]:me,[Te]:me};ie=Object.assign(I,Le)}else ie=I;this.relations=X,this.states=ie;break}case"1:n":{const z=F(),G=le(),re=`${o}KeyOf${Jt(c)}`,I=`${c}KeysOf${Jt(o)}`,ie={[re]:z,[I]:G};let me;if(n){const _e=ve(),Te=gt(),Le=`${o}EntryOf${Jt(c)}`,bt=`${c}EntriesOf${Jt(o)}`,Ce={[Le]:_e,[bt]:Te};me=Object.assign(ie,Ce)}else me=ie;this.relations=X,this.states=me;break}case"n:n":{const z=le(),G=`${o}KeysOf${Jt(c)}`,re=`${c}KeysOf${Jt(o)}`,I={[G]:z,[re]:z};let ie;if(n){const me=gt(),_e=`${o}EntriesOf${Jt(c)}`,Te=`${c}EntriesOf${Jt(o)}`,Le={[_e]:me,[Te]:me};ie=Object.assign(I,Le)}else ie=I;this.relations=X,this.states=ie}}}transact(s,n){const r=this.toolkit;this.toolkit=s,n(this),this.toolkit=r}[Symbol.dispose](){}}function tw(t,s){let n=s.joins.get(t.key);if(n===void 0){const o=tt.STORE.joins.get(t.key);if(o===void 0)throw new Error(`Join "${t.key}" not found in store "${s.config.name}"`);n=new fb(o.options,o.defaultContent,s),s.joins.set(t.key,n)}return n}function nw(t,s){return tw(t,s).core.relatedKeysAtoms}function iw(t){return t.startsWith("🔍 ")}var Jc={exports:{}},ue={};/**
22
+ ${h.trace}`:"No previous disposal trace was found."),r.type){case"atom_family":case"mutable_atom_family":return t.defaults.get(r.key);case"selector_family":case"readonly_selector_family":{if(t.defaults.has(r.key))return t.defaults.get(n.family.key);const p=ht(t,r).default(c);return t.defaults.set(r.key,p),p}}}return po(t,ht(t,n))}class Tt{constructor(s,n){g(this,"a");g(this,"b");g(this,"cardinality");g(this,"relations",new Map);g(this,"contents",new Map);g(this,"isAType");g(this,"isBType");g(this,"isContent");g(this,"makeContentKey",(s,n)=>`${s}:${n}`);g(this,"warn");var r,o;if(this.a=s.between[0],this.b=s.between[1],this.cardinality=s.cardinality,n!=null&&n.externalStore||(this.relations=new Map((r=s.relations)==null?void 0:r.map(([c,h])=>[c,new Set(h)])),this.contents=new Map(s.contents)),this.isAType=(n==null?void 0:n.isAType)??null,this.isBType=(n==null?void 0:n.isBType)??null,this.isContent=(n==null?void 0:n.isContent)??null,n!=null&&n.makeContentKey&&(this.makeContentKey=n.makeContentKey),n!=null&&n.externalStore){const c=n.externalStore;this.has=(h,p)=>c.has(h,p),this.addRelation=(h,p)=>{c.addRelation(h,p)},this.deleteRelation=(h,p)=>{c.deleteRelation(h,p)},this.replaceRelationsSafely=(h,p)=>{c.replaceRelationsSafely(h,p)},this.replaceRelationsUnsafely=(h,p)=>{c.replaceRelationsUnsafely(h,p)},this.getRelatedKeys=h=>c.getRelatedKeys(h),c.getContent&&(this.getContentInternal=h=>c.getContent(h),this.setContent=(h,p)=>{c.setContent(h,p)},this.deleteContent=h=>{c.deleteContent(h)});for(const[h,p]of s.relations??[]){let m=(o=this.isAType)!=null&&o.call(this,h)?h:void 0,y=m===void 0?h:void 0;for(const v of p)m??(m=v),y??(y=v),this.addRelation(m,y)}for(const[h,p]of s.contents??[])this.setContent(h,p)}n!=null&&n.warn&&(this.warn=n.warn)}getRelatedKeys(s){return this.relations.get(s)}addRelation(s,n){let r=this.relations.get(s),o=this.relations.get(n);r?r.add(n):(r=new Set([n]),this.relations.set(s,r)),o?o.add(s):(o=new Set([s]),this.relations.set(n,o))}deleteRelation(s,n){const r=this.relations.get(s);if(r){r.delete(n),r.size===0&&this.relations.delete(s);const o=this.relations.get(n);o&&(o.delete(s),o.size===0&&this.relations.delete(n))}}replaceRelationsUnsafely(s,n){this.relations.set(s,new Set(n));for(const r of n){const o=new Set().add(s);this.relations.set(r,o)}}replaceRelationsSafely(s,n){var h;const r=this.relations.get(s);let o=(h=this.isAType)!=null&&h.call(this,s)?s:void 0,c=o===void 0?s:void 0;if(r)for(const p of r){o??(o=p),c??(c=p);const m=this.relations.get(p);m&&(m.size===1?this.relations.delete(p):m.delete(s),this.contents.delete(this.makeContentKey(o,c)))}this.relations.set(s,new Set(n));for(const p of n){let m=this.relations.get(p);m?m.add(s):(m=new Set().add(s),this.relations.set(p,m))}}getContentInternal(s){return this.contents.get(s)}setContent(s,n){this.contents.set(s,n)}deleteContent(s){this.contents.delete(s)}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([s,n])=>[s,[...n]]),contents:[...this.contents.entries()]}}set(...s){let n,r,o;switch(s.length){case 1:{const c=s[0];n=c[this.a],r=c[this.b],o=void 0;break}case 2:{const c=s[0];typeof c=="string"?[n,r]=s:(n=c[this.a],r=c[this.b],o=s[1]);break}default:{n=s[0],r=s[1],o=s[2];break}}switch(this.cardinality){case"1:1":{const c=this.getRelatedKey(n);c&&c!==r&&this.delete(n,c)}case"1:n":{const c=this.getRelatedKey(r);c&&c!==n&&this.delete(c,r)}break}if(o){const c=this.makeContentKey(n,r);this.setContent(c,o)}return this.addRelation(n,r),this}delete(s,n){n=typeof n=="string"?n:s[this.b];const r=typeof s=="string"?s:s[this.a];if(r===void 0&&typeof n=="string"){const o=this.getRelatedKeys(n);if(o)for(const c of o)this.delete(c,n)}if(typeof r=="string"&&n===void 0){const o=this.getRelatedKeys(r);if(o)for(const c of o)this.delete(r,c)}if(typeof r=="string"&&typeof n=="string"){this.deleteRelation(r,n);const o=this.makeContentKey(r,n);this.deleteContent(o)}return this}getRelatedKey(s){var r;const n=this.getRelatedKeys(s);if(n){n.size>1&&((r=this.warn)==null||r.call(this,`${n.size} related keys were found for key "${s}": (${[...n].map(c=>`"${c}"`).join(", ")}). Only one related key was expected.`));let o;for(const c of n){o=c;break}return o}}replaceRelations(s,n,r){const o=!Array.isArray(n),c=o?Object.keys(n):n;if(r!=null&&r.reckless?this.replaceRelationsUnsafely(s,c):this.replaceRelationsSafely(s,c),o)for(const h of c){const p=this.makeContentKey(s,h),m=n[h];this.setContent(p,m)}return this}getContent(s,n){const r=this.makeContentKey(s,n);return this.getContentInternal(r)}getRelationEntries(s){const n=s[this.a],r=s[this.b];if(n!==void 0&&r===void 0){const o=this.getRelatedKeys(n);if(o)return[...o].map(c=>[c,this.getContent(n,c)])}if(n===void 0&&r!==void 0){const o=this.getRelatedKeys(r);if(o)return[...o].map(c=>[c,this.getContent(c,r)])}return[]}has(s,n){if(n){const r=this.getRelatedKeys(s);return(r==null?void 0:r.has(n))??!1}return this.relations.has(s)}}class Sn extends Map{constructor(n){super();g(this,"deleted",new Set);g(this,"source");this.source=n}get(n){if(super.has(n))return super.get(n);if(!this.deleted.has(n)&&this.source.has(n))return this.source.get(n)}set(n,r){return this.deleted.delete(n),super.set(n,r)}hasOwn(n){return super.has(n)}has(n){return!this.deleted.has(n)&&(super.has(n)||this.source.has(n))}delete(n){return this.deleted.add(n),super.delete(n)}}const $A=(t,s,n,r)=>{const o=ce(t),c={parent:o,child:null,on:o.on,loggers:o.loggers,logger:o.logger,config:o.config,atoms:new Sn(o.atoms),atomsThatAreDefault:new Set(o.atomsThatAreDefault),families:new Sn(o.families),joins:new Sn(o.joins),operation:{open:!1},readonlySelectors:new Sn(o.readonlySelectors),timelines:new Sn(o.timelines),timelineTopics:new Tt(o.timelineTopics.toJSON()),trackers:new Map,transactions:new Sn(o.transactions),selectorAtoms:new Tt(o.selectorAtoms.toJSON()),selectorGraph:new Tt(o.selectorGraph.toJSON(),{makeContentKey:(...y)=>y.sort().join(":")}),selectors:new Sn(o.selectors),valueMap:new Sn(o.valueMap),defaults:o.defaults,disposalTraces:t.disposalTraces.copy(),molecules:new Sn(o.molecules),moleculeGraph:new Tt(o.moleculeGraph.toJSON(),{makeContentKey:o.moleculeGraph.makeContentKey}),moleculeData:new Tt(o.moleculeData.toJSON(),{makeContentKey:o.moleculeData.makeContentKey}),moleculeJoins:new Tt(o.moleculeJoins.toJSON(),{makeContentKey:o.moleculeJoins.makeContentKey}),miscResources:new Sn(o.miscResources)},h=RA(t,s),p={phase:"building",update:{type:"transaction_update",key:s,id:r,epoch:h===void 0?Number.NaN:h+1,updates:[],params:n,output:void 0},toolkit:{get:(...y)=>ln(m,...y),set:(...y)=>{Pe(m,...y)},run:(y,v=Fg())=>Xf(m,y,v),find:(...y)=>Et(t,...y),json:y=>Qi(m,y),dispose:(...y)=>{mo(m,...y)},env:()=>MA(m)}},m=Object.assign(c,{transactionMeta:p});return o.child=m,t.logger.info("🛫","transaction",s,"Building transaction with params:",n),m};function sb(t,s){const n={key:s.key,type:"transaction",run:(c,h)=>{const p=$A(t,s.key,c,h);try{const m=ce(t),{toolkit:y}=p.transactionMeta,v=s.do(y,...c);return kA(v,m),v}catch(m){throw hA(r),t.logger.warn("💥","transaction",s.key,"caught:",m),m}},install:c=>sb(c,s),subject:new We},r=ce(t);r.transactions.set(n.key,n);const o=Is(n);return t.on.transactionCreation.next(o),o}function DA(t){return sb(tt.STORE,t)}function CA(t,s=Fg()){return Xf(tt.STORE,t,s)}class zA{constructor(s,n=null){g(this,"parent",null);g(this,"child",null);g(this,"valueMap",new Map);g(this,"defaults",new Map);g(this,"atoms",new Map);g(this,"selectors",new Map);g(this,"readonlySelectors",new Map);g(this,"atomsThatAreDefault",new Set);g(this,"selectorAtoms",new Tt({between:["selectorKey","atomKey"],cardinality:"n:n"}));g(this,"selectorGraph",new Tt({between:["upstreamSelectorKey","downstreamSelectorKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"trackers",new Map);g(this,"families",new Map);g(this,"joins",new Map);g(this,"transactions",new Map);g(this,"transactionMeta",{epoch:new Map,actionContinuities:new Tt({between:["continuity","action"],cardinality:"1:n"})});g(this,"timelines",new Map);g(this,"timelineTopics",new Tt({between:["timelineKey","topicKey"],cardinality:"1:n"}));g(this,"disposalTraces",new Jf(100));g(this,"molecules",new Map);g(this,"moleculeJoins",new Tt({between:["moleculeKey","joinKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"moleculeGraph",new Tt({between:["upstreamMoleculeKey","downstreamMoleculeKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"moleculeData",new Tt({between:["moleculeKey","stateFamilyKey"],cardinality:"n:n"},{makeContentKey:(...s)=>s.sort().join(":")}));g(this,"miscResources",new Map);g(this,"on",{atomCreation:new We,atomDisposal:new We,selectorCreation:new We,selectorDisposal:new We,timelineCreation:new We,transactionCreation:new We,transactionApplying:new tA(null),operationClose:new We,moleculeCreation:new We,moleculeDisposal:new We});g(this,"operation",{open:!1});g(this,"config",{name:"IMPLICIT_STORE",lifespan:"ephemeral"});g(this,"loggers",[new oA("warn",(s,n,r)=>!iw(r))]);g(this,"logger",{error:(...s)=>{for(const n of this.loggers)n.error(...s)},info:(...s)=>{for(const n of this.loggers)n.info(...s)},warn:(...s)=>{for(const n of this.loggers)n.warn(...s)}});var r,o;if(this.config={...n==null?void 0:n.config,...s},n!==null){this.valueMap=new Map(n==null?void 0:n.valueMap),this.operation={...n==null?void 0:n.operation},Yn(n)&&(this.transactionMeta={epoch:new Map(n==null?void 0:n.transactionMeta.epoch),actionContinuities:new Tt(n==null?void 0:n.transactionMeta.actionContinuities.toJSON())});for(const[,h]of n.families)(r=h.internalRoles)!=null&&r.includes("mutable")||(o=h.internalRoles)!=null&&o.includes("join")||h.install(this);const c=new Set;for(const[,h]of n.atoms)if(!c.has(h.key)&&(h.install(this),h.type==="mutable_atom")){const p=Qi(n,h),m=ub(h);c.add(p.key),c.add(m.key)}for(const[,h]of n.readonlySelectors)h.install(this);for(const[,h]of n.selectors)c.has(h.key)||h.install(this);for(const[,h]of n.transactions)h.install(this);for(const[,h]of n.timelines)h.install(this)}}}const tt={get STORE(){return globalThis.ATOM_IO_IMPLICIT_STORE??(globalThis.ATOM_IO_IMPLICIT_STORE=new zA({name:"IMPLICIT_STORE",lifespan:"ephemeral"})),globalThis.ATOM_IO_IMPLICIT_STORE}};function ht(t,s){let n,r=t;for(;r!==null;){switch(s.type){case"atom":case"mutable_atom":n=r.atoms.get(s.key);break;case"selector":n=r.selectors.get(s.key);break;case"readonly_selector":n=r.readonlySelectors.get(s.key);break;case"atom_family":case"mutable_atom_family":case"selector_family":case"readonly_selector_family":n=r.families.get(s.key);break;case"timeline":n=r.timelines.get(s.key);break;case"transaction":n=r.transactions.get(s.key);break}if(n)return n;r=r.child}throw new Zf(s,t)}function UA(t,s,n){const r=t.families.get(s.key);if(r===void 0)throw new Zf(s,t);const o=r(n),c=ce(t);if(o.family)if(Yn(c))switch(o.type){case"atom":case"mutable_atom":t.on.atomCreation.next(o);break;case"selector":case"readonly_selector":t.on.selectorCreation.next(o);break}else wt(c)&&c.on.transactionApplying.state===null&&c.transactionMeta.update.updates.push({type:"state_creation",token:o});return o}function BA(t,s,n){const r=Ye(n),o=`${s.key}(${r})`,c=ce(t);let h;switch(s.type){case"atom_family":case"mutable_atom_family":h=c.atoms.get(o);break;case"selector_family":h=c.selectors.get(o);break;case"readonly_selector_family":h=c.readonlySelectors.get(o);break}return h&&Is(h)}function Et(t,s,n){let r=BA(t,s,n);if(r)return r;const o=Ye(n),c=t.molecules.get(o);if(!c&&t.config.lifespan==="immortal"){const h=sA(s,n);return t.logger.error("❌",h.type,h.key,`was not found in store "${t.config.name}"; returned a counterfeit token.`),h}return r=UA(t,s,n),c&&ce(t).moleculeData.set(o,s.key),r}function mo(t,...s){let n;if(s.length===1)n=s[0];else{const r=s[0],o=s[1];n=Et(t,r,o)}try{ht(t,n)}catch{t.logger.error("❌",n.type,n.key,`could not be disposed because it was not found in the store "${t.config.name}".`);return}switch(n.type){case"atom":case"mutable_atom":sh(t,n);break;case"selector":case"readonly_selector":VA(t,n);break}}const Wf=(t,s)=>ce(t).atoms.has(s),qA=(t,s)=>ce(t).selectors.has(s),jA=(t,s)=>ce(t).readonlySelectors.has(s),KA=(t,s)=>Wf(t,s)||qA(t,s)||jA(t,s),df=(t,s)=>ce(s).selectorGraph.getRelationEntries({downstreamSelectorKey:t}).filter(([r,{source:o}])=>o!==t).map(([r,{source:o}])=>o).filter(r=>KA(s,r)),rb=(t,s,n)=>{const r=[],o=df(t,n);for(;o.length>0;){const c=o.shift();s.has(c)||(s.add(c),Wf(n,c)?r.includes(c)||r.push(c):o.push(...df(c,n)))}return r},LA=(t,s)=>{const n=t.key,r=df(n,s),o=new Set;return r.flatMap(c=>Wf(s,c)?c:rb(c,o,s))},HA=(t,s,n,r)=>{const o=ce(r);if(s.type==="atom"||s.type==="mutable_atom")o.selectorAtoms.set({selectorKey:t,atomKey:s.key}),r.logger.info("🔍","selector",t,`discovers root atom "${s.key}"`);else{const c=rb(s.key,n,r);r.logger.info("🔍","selector",t,`discovers root atoms: [ ${c.map(h=>`"${h}"`).join(", ")} ]`);for(const h of c)o.selectorAtoms=o.selectorAtoms.set({selectorKey:t,atomKey:h})}n.add(s.key)},ab=(t,s,n)=>({get:(...r)=>{const o=ce(n);let c;if(r.length===2){const[m,y]=r;c=Et(n,m,y)}else[c]=r;const h=ht(n,c),p=po(n,h);return n.logger.info("🔌","selector",t,`registers dependency ( "${c.key}" =`,p,")"),o.selectorGraph.set({upstreamSelectorKey:c.key,downstreamSelectorKey:t},{source:c.key}),HA(t,c,s,n),p},set:(...r)=>{let o,c;if(r.length===2)o=r[0],c=r[1];else{const m=r[0],y=r[1];c=r[2],o=Et(n,m,y)}const h=ce(n),p=ht(h,o);Pg(h,p,c)},find:(...r)=>Et(n,...r),json:r=>Qi(n,r)}),Pf=(t,s,n)=>{const r=ce(t),o=new We,c=new Set,{get:h,find:p,json:m}=ab(s.key,c,r),y=()=>{const N=s.get({get:h,find:p,json:m});return Ji(ce(t),s.key,N,o),c.clear(),N},v={...s,subject:o,install:N=>Pf(N,s,n),get:y,type:"readonly_selector",...n&&{family:n}};r.readonlySelectors.set(s.key,v);const E=y();t.logger.info("✨",v.type,v.key,"=",E);const k={key:s.key,type:"readonly_selector"};return n&&(k.family=n),k},eh=(t,s,n)=>{const r=ce(t),o=new We,c=new Set,h=ab(s.key,c,r),{find:p,get:m,json:y}=h,v={find:p,get:m,json:y},E=(X=s.get,F=ce(t))=>{const le=X(v);return Ji(F,s.key,le,o),c.clear(),le},N={...s,subject:o,install:X=>eh(X,s,n),get:E,set:X=>{const F=ce(t),le=E(s.get,F),ve=Wg(X)(le);t.logger.info("📝","selector",s.key,"set (",le,"->",ve,")"),Ji(F,s.key,ve,o),Qf(F,s.key),Yn(F)&&o.next({newValue:ve,oldValue:le}),s.set(h,ve)},type:"selector",...n&&{family:n}};r.selectors.set(s.key,N);const B=E();t.logger.info("✨",N.type,N.key,"=",B);const j={key:s.key,type:"selector"};return n&&(j.family=n),j};function lb(t,s){if("set"in s){const o=eh(t,s,void 0);return t.on.selectorCreation.next(o),o}const r=Pf(t,s,void 0);return t.on.selectorCreation.next(r),r}function VA(t,s){const n=ce(t),{key:r}=s,o=ht(n,s);if(!o.family)t.logger.error("❌","selector",r,"Standalone selectors cannot be disposed.");else{n.molecules.get(o.family.subKey)&&n.moleculeData.delete(o.family.subKey,o.family.key);let h;switch(s.type){case"selector":n.selectors.delete(r),h={key:o.family.key,type:"selector_family"},ht(t,h).subject.next({type:"state_disposal",subType:"selector",token:s});break;case"readonly_selector":n.readonlySelectors.delete(r),h={key:o.family.key,type:"readonly_selector_family"},ht(t,h).subject.next({type:"state_disposal",subType:"selector",token:s});break}n.valueMap.delete(r),n.selectorAtoms.delete(r),n.selectorGraph.delete(r),t.logger.info("🔥",s.type,r,"deleted"),wt(n)&&n.transactionMeta.phase==="building"?n.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:s}):t.on.selectorDisposal.next(s)}}function th(t,s,n){const r={key:s.key,type:"selector_family"},o=t.families.get(s.key);o&&t.logger.error("❗","selector_family",s.key,`Overwriting an existing ${da(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new We,p=Object.assign(m=>{const y=Ye(m),v={key:s.key,subKey:y},E=`${s.key}(${y})`,k=ce(t),N=eh(k,{key:E,get:s.get(m),set:s.set(m)},v);return c.next({type:"state_creation",token:N}),N},r,{internalRoles:n,subject:c,install:m=>th(m,s),default:m=>s.get(m)({get:(...v)=>ln(t,...v),find:(...v)=>Et(t,...v),json:v=>Qi(t,v)})});return t.families.set(s.key,p),r}function GA(t,s,n){return th(t,{key:`${s.key}:JSON`,get:o=>({get:c})=>{const h=c(s,o);return n.toJson(h)},set:o=>({set:c},h)=>{c(s,o,n.fromJson(h))}},["mutable","json"])}const Ps=t=>JSON.parse(t),Ye=t=>JSON.stringify(t),YA=(t,s)=>{const n=ce(t);return n.operation.open?n.operation.prev.get(s.key):n.valueMap.get(s.key)},Ty=(t,s)=>{const n=ce(t);return LA(s,t).map(o=>{const c=n.atoms.get(o);if(c===void 0)throw new Error(`Atom "${o}", a dependency of selector "${s.key}", not found in store "${t.config.name}".`);return c.subject.subscribe(`${s.type}:${s.key}`,h=>{t.logger.info("📢",s.type,s.key,"root",o,"went",h.oldValue,"->",h.newValue);const p=YA(n,s),m=po(n,s);t.logger.info("✨",s.type,s.key,"went",p,"->",m),s.subject.next({newValue:m,oldValue:p})})})};function ua(t,s,n,r){function o(E){if(t.operation.open){const k=t.on.operationClose.subscribe(`state subscription ${n}`,()=>{k(),r(E)})}else r(E)}const c=ht(t,s);t.logger.info("👀",c.type,c.key,`Adding subscription "${n}"`);const h=c.type==="selector"||c.type==="readonly_selector";let p=null,m=o;h&&(p=Ty(t,c),m=E=>{p&&(p.length=0,p.push(...Ty(t,c))),o(E)});const y=c.subject.subscribe(n,m);return()=>{if(t.logger.info("🙈",c.type,c.key,`Removing subscription "${n}"`),y(),p)for(const E of p)E()}}const JA=(t,s,n,r)=>{const o=ht(t,s);t.logger.info("👀","timeline",s.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","timeline",s.key,`Removing subscription "${n}" from timeline`),c()}},IA=(t,s,n,r)=>{const o=ht(t,s);t.logger.info("👀","transaction",s.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","transaction",s.key,`Removing subscription "${n}"`),c()}};var Bg;Bg=Symbol.dispose;class nh{constructor(s,n){g(this,"Update");g(this,"unsubscribeFromInnerValue");g(this,"unsubscribeFromState");g(this,"mutableState");g(this,"latestUpdateState");g(this,Bg);this.mutableState=s;const r=ce(n);this.latestUpdateState=this.initializeState(s,r),this.observeCore(s,this.latestUpdateState,r),this.updateCore(s,this.latestUpdateState,r),r.trackers.set(s.key,this),this[Symbol.dispose]=()=>{this.unsubscribeFromInnerValue(),this.unsubscribeFromState(),r.trackers.delete(s.key)}}initializeState(s,n){var h;const r=`*${s.key}`;n.atoms.delete(r),n.valueMap.delete(r);const o=s.family?{key:`*${s.family.key}`,subKey:s.family.subKey}:void 0,c=yo(n,{key:r,default:null},o);if((h=n.parent)!=null&&h.valueMap.has(r)){const p=n.parent.valueMap.get(r);n.valueMap.set(r,p)}return c}observeCore(s,n,r){const o=`tracker:${r.config.name}:${wt(r)?r.transactionMeta.update.key:"main"}:${s.key}`,c=ln(r,s);this.unsubscribeFromInnerValue=c.subscribe(o,h=>{Pe(r,n,h)}),this.unsubscribeFromState=ua(r,s,o,h=>{h.newValue!==h.oldValue&&(this.unsubscribeFromInnerValue(),this.unsubscribeFromInnerValue=h.newValue.subscribe(o,p=>{Pe(r,n,p)}))})}updateCore(s,n,r){const o=`tracker:${r.config.name}:${wt(r)?r.transactionMeta.update.key:"main"}:${s.key}`;ua(r,n,o,({newValue:c,oldValue:h})=>{const p=r.timelineTopics.getRelatedKey(n.key);if(p){const y=r.timelines.get(p);if(y!=null&&y.timeTraveling){const v=JA(r,{key:p,type:"timeline"},o,E=>{v(),Pe(r,s,k=>(E==="redo"&&c?k.do(c):E==="undo"&&h&&k.undo(h),k))});return}}const m=r.on.operationClose.subscribe(o,()=>{m();const y=ln(r,s),v=c===null?-1:y.getUpdateNumber(c),E=v-y.cacheUpdateNumber;c&&E===1?Pe(r,s,k=>(k.do(c),k)):r.logger.info("❌","mutable_atom",s.key,`could not be updated. Expected update number ${y.cacheUpdateNumber+1}, but got ${v}`)})})}}function ih(t,s,n){t.logger.info("🔨","atom",s.key,`creating in store "${t.config.name}"`);const r=ce(t),o=r.atoms.get(s.key);if(o&&o.type==="mutable_atom")return t.logger.error("❌","atom",s.key,"Tried to create atom, but it already exists in the store."),Is(o);const c=new We,h={...s,type:"mutable_atom",install:y=>(y.logger.info("🛠️","atom",s.key,`installing in store "${y.config.name}"`),ih(y,s,n)),subject:c};n&&(h.family=n);const p=s.default();r.atoms.set(h.key,h),cb(t,s.key),Ji(r,s.key,p,c);const m=Is(h);if(s.effects){let y=0;const v=[];for(const E of s.effects){const k=E({setSelf:N=>{Pe(t,m,N)},onSet:N=>ua(t,m,`effect[${y}]`,N)});k&&v.push(k),++y}h.cleanup=()=>{for(const E of v)E()}}return new nh(m,t),n||eA(m,s,t),m}class ZA{constructor(s,n){g(this,"trackers",new Map);g(this,"Update");g(this,"latestUpdateAtoms");g(this,"mutableAtoms");const r=Yf(n,{key:`*${s.key}`,default:null},["mutable","updates"]);this.latestUpdateAtoms=ht(n,r),this.mutableAtoms=s,this.mutableAtoms.subject.subscribe(`store=${n.config.name}::tracker-atom-family`,o=>{const{type:c,token:h}=o;if(h.family){const p=Ps(h.family.subKey);switch(c){case"state_creation":this.trackers.set(p,new nh(h,n));break;case"state_disposal":{const m=this.trackers.get(p);m&&(m[Symbol.dispose](),this.trackers.delete(p))}break}}})}}function ob(t,s,n){const r={key:s.key,type:"mutable_atom_family"},o=t.families.get(s.key);o&&t.logger.error("❗","mutable_atom_family",s.key,`Overwriting an existing ${da(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new We,p=Object.assign(m=>{const y=Ye(m),v={key:s.key,subKey:y},E=`${s.key}(${y})`,k=ce(t),N={key:E,default:()=>s.default(m),toJson:s.toJson,fromJson:s.fromJson,mutable:!0};s.effects&&(N.effects=s.effects(m));const B=ih(k,N,v);return c.next({type:"state_creation",token:B}),B},r,{subject:c,install:m=>ob(m,s),toJson:s.toJson,fromJson:s.fromJson,internalRoles:n});return t.families.set(s.key,p),GA(t,p,s),new ZA(p,t),r}const Ry=(t,s)=>{const n=ce(s),r=`${t.key}:JSON`;return n.families.get(r)},Qi=(t,s)=>{if(s.family){const r=ce(t),c={key:`${s.family.key}:JSON`,type:"selector_family"},h=ht(r,c),p=JSON.parse(s.family.subKey);return Et(t,h,p)}return{type:"selector",key:`${s.key}:JSON`}},ub=t=>{const n={type:"atom",key:`*${t.key}`};return t.family&&(n.family={key:`*${t.family.key}`,subKey:t.family.subKey}),n};function XA(t){return typeof t=="object"&&t!==null&&"do"in t&&"undo"in t&&"subscribe"in t}function pf(t,s,n){const r=n.valueMap.get(s.key),o=t.valueMap.get(s.key);if(r!==o)return o;if(r===void 0)return s.default();n.logger.info("📃","atom",s.key,"copying");const c=s.toJson(r),h=s.fromJson(c);return t.valueMap.set(s.key,h),new nh(s,n),h}function Ji(t,s,n,r){const o=t.valueMap.get(s);if(o instanceof ff&&o.use(n),n instanceof Promise){const c=new ff(n);return t.valueMap.set(s,c),c.then(h=>{Ji(t,s,h,r),r.next({newValue:h,oldValue:c})}).catch(h=>{t.logger.error("💥","state",s,"rejected:",h)}),c}return t.valueMap.set(s,n),n}const QA=(t,s)=>{let n=s.valueMap.get(t.key);if(t.type==="mutable_atom"&&wt(s)){const{parent:r}=s;n=pf(s,t,r)}return n},FA=(t,s)=>{const n=s.valueMap.get(t);if(n instanceof ff){const r=n,o=s.selectors.get(t)??s.readonlySelectors.get(t);o&&r.use(o.get());return}s.operation.open&&s.operation.prev.set(t,n),s.valueMap.delete(t),s.logger.info("🗑","state",t,"evicted")},WA=(t,s)=>ce(t).atomsThatAreDefault.has(s),cb=(t,s)=>{const n=ce(t);n.atomsThatAreDefault=new Set(n.atomsThatAreDefault).add(s)},PA=(t,s)=>{const n=ce(t);n.atomsThatAreDefault=new Set(ce(t).atomsThatAreDefault),n.atomsThatAreDefault.delete(s)};function yo(t,s,n){t.logger.info("🔨","atom",s.key,`creating in store "${t.config.name}"`);const r=ce(t),o=r.atoms.get(s.key);if(o&&o.type==="atom")return t.logger.error("❌","atom",s.key,"Tried to create atom, but it already exists in the store."),Is(o);const c=new We,h={...s,type:"atom",install:y=>(y.logger.info("🛠️","atom",s.key,`installing in store "${y.config.name}"`),yo(y,s,n)),subject:c};n&&(h.family=n);let p=s.default;s.default instanceof Function&&(p=s.default()),r.atoms.set(h.key,h),cb(t,s.key),Ji(r,s.key,p,c);const m=Is(h);if(s.effects){let y=0;const v=[];for(const E of s.effects){const k=E({setSelf:N=>{Pe(t,m,N)},onSet:N=>ua(t,m,`effect[${y}]`,N)});k&&v.push(k),++y}h.cleanup=()=>{for(const E of v)E()}}return m}function ew(t,s){if("mutable"in s){const o=ih(t,s,void 0);return t.on.atomCreation.next(o),o}const r=yo(t,s,void 0);return t.on.atomCreation.next(r),r}function sh(t,s){var h;const n=ce(t),{key:r,family:o}=s,c=ht(n,s);if(!o)t.logger.error("❌","atom",r,"Standalone atoms cannot be disposed.");else{(h=c.cleanup)==null||h.call(c);const p=t.valueMap.get(c.key),m=ht(t,{key:o.key,type:"atom_family"}),y={type:"state_disposal",subType:"atom",token:s,value:p};m.subject.next(y);const v=wt(n);if(n.atoms.delete(r),n.valueMap.delete(r),n.selectorAtoms.delete(r),n.atomsThatAreDefault.delete(r),t.timelineTopics.delete(r),s.type==="mutable_atom"){const E=ub(s);sh(t,E),t.trackers.delete(r)}if(t.logger.info("🔥","atom",r,"deleted"),v&&n.transactionMeta.phase==="building"){const E=n.transactionMeta.update.updates.at(-1);(E==null?void 0:E.type)==="molecule_disposal"&&E.values.some(([B])=>{var j;return B===((j=c.family)==null?void 0:j.key)})||n.transactionMeta.update.updates.push(y)}else t.on.atomDisposal.next(s)}}class An extends Set{constructor(n,r=0){super(n);g(this,"mode","record");g(this,"subject",new We);g(this,"cacheLimit",0);g(this,"cache",[]);g(this,"cacheIdx",-1);g(this,"cacheUpdateNumber",-1);g(this,"parent");g(this,"child",null);g(this,"transactionUpdates",null);n instanceof An&&(this.parent=n,this.cacheUpdateNumber=n.cacheUpdateNumber),r&&(this.cacheLimit=r,this.cache=new Array(r),this.subscribe("auto cache",o=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=o}))}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(n){const r=new An(n.members,n.cacheLimit);return r.cache=n.cache,r.cacheIdx=n.cacheIdx,r.cacheUpdateNumber=n.cacheUpdateNumber,r}add(n){const r=super.add(n);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`add:${Ye(n)}`)),r}clear(){const n=this.mode==="record"?[...this]:null;super.clear(),n&&(this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(n)}`))}delete(n){const r=super.delete(n);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`del:${Ye(n)}`)),r}transaction(n){this.mode="transaction",this.transactionUpdates=[],this.child=new An(this);const r=this.child._subscribe("transaction",o=>{var c;(c=this.transactionUpdates)==null||c.push(o)});try{if(n(this.child)){for(const c of this.transactionUpdates)this.doStep(c);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(o){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",o),o}finally{r(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(n,r){return this.subject.subscribe(n,r)}subscribe(n,r){return this.subject.subscribe(n,o=>{r(`${this.cacheUpdateNumber}=${o}`)})}emit(n){this.subject.next(n)}doStep(n){const r=n.indexOf(":"),o=n.substring(0,r),c=n.substring(r+1);switch(o){case"add":this.add(JSON.parse(c));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(c));break;case"tx":for(const h of c.split(";"))this.doStep(h)}}getUpdateNumber(n){const r=n.indexOf("=");return Number(n.substring(0,r))}do(n){const r=n.indexOf("="),o=Number(n.substring(0,r)),c=o-this.cacheUpdateNumber;if(c>0){if(c===1){this.mode="playback";const p=n.substring(r+1);return this.doStep(p),this.mode="record",this.cacheUpdateNumber=o,null}return this.cacheUpdateNumber+1}if(Math.abs(c)<this.cacheLimit){const p=this.cacheIdx+c;if(this.cache[p]===n)return null;this.mode="playback";let y=!1;for(;!y;){this.cacheIdx%=this.cacheLimit;const E=this.cache[this.cacheIdx];if(this.cacheIdx--,!E)return"OUT_OF_RANGE";this.undo(E),y=this.cacheIdx===p-1}const v=n.substring(r+1);return this.doStep(v),this.mode="record",this.cacheUpdateNumber=o,null}return"OUT_OF_RANGE"}undoStep(n){const r=n.indexOf(":"),o=n.substring(0,r),c=n.substring(r+1);switch(o){case"add":this.delete(JSON.parse(c));break;case"del":this.add(JSON.parse(c));break;case"clear":{const h=JSON.parse(c);for(const p of h)this.add(p);break}case"tx":{const h=c.split(";");for(let p=h.length-1;p>=0;p--)this.undoStep(h[p])}}}undo(n){const r=n.indexOf("=");if(Number(n.substring(0,r))===this.cacheUpdateNumber){this.mode="playback";const c=n.substring(r+1);return this.undoStep(c),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}}class fb{constructor(s,n,r=tt.STORE){g(this,"toolkit");g(this,"options");g(this,"defaultContent");g(this,"molecules",new Map);g(this,"relations");g(this,"states");g(this,"core");g(this,"store");g(this,"realm");this.store=r,this.realm=new cA(r),this.options=s,this.defaultContent=n,this.store.miscResources.set(`join:${s.key}`,this),this.realm.allocate("root",s.key),this.toolkit={get:(...z)=>ln(r,...z),set:(...z)=>{Pe(r,...z)},find:(...z)=>Et(r,...z),json:z=>Qi(r,z)};const o=s.between[0],c=s.between[1],h=ob(r,{key:`${s.key}/relatedKeys`,default:()=>new An,mutable:!0,fromJson:z=>An.fromJSON(z),toJson:z=>z.toJSON()},["join","relations"]);this.core={relatedKeysAtoms:h};const p=({get:z},G)=>z(h,G),m=({set:z},G,re)=>{this.store.molecules.has(Ye(G))||this.realm.allocate(s.key,G),z(h,G,I=>I.add(re)),z(h,re,I=>I.add(G))},y=({set:z},G,re)=>{z(h,G,I=>(I.delete(re),I)),z(h,re,I=>(I.delete(G),I))},v=(z,G,re)=>{const{find:I,get:ie,set:me}=z,_e=I(h,G),Te=ie(_e);for(const Le of Te)re.includes(Le)||me(h,Le,Ce=>(Ce.delete(G),Ce));me(_e,Le=>(Le.transaction(bt=>{bt.clear();for(const Ce of re){const M=p(z,Ce),H=M.has(G);if(this.relations.cardinality==="1:n"){const W=[];for(const be of M){if(be===G)continue;const A=p(z,be);A.delete(Ce),A.size===0&&W.push(be)}!H&&M.size>0&&M.clear();for(const be of W){const A=[Ce,be].sort(),U=`"${A[0]}:${A[1]}"`;this.molecules.delete(U)}}H||M.add(G),bt.add(Ce)}return!0}),Le))},E=(z,G,re)=>{const{set:I}=z;I(h,G,ie=>(ie.transaction(me=>{for(const _e of re)me.add(_e);return!0}),ie));for(const ie of re)I(h,ie,me=>(me.add(G),me));return!0},k=(z,G,re)=>{const I=p(z,G);return re?I.has(re):I.size>0},N={getRelatedKeys:z=>p(this.toolkit,z),addRelation:(z,G)=>{this.store.moleculeJoins.set(z,s.key),this.store.moleculeJoins.set(G,s.key),m(this.toolkit,z,G)},deleteRelation:(z,G)=>{y(this.toolkit,z,G)},replaceRelationsSafely:(z,G)=>{v(this.toolkit,z,G)},replaceRelationsUnsafely:(z,G)=>{E(this.toolkit,z,G)},has:(z,G)=>k(this.toolkit,z,G)};let B,j;if(n){j=Yf(r,{key:`${s.key}/content`,default:n},["join","content"]);const z=({get:I},ie)=>I(j,ie),G=({set:I},ie,me)=>{I(j,ie,me)};B=Object.assign(N,{getContent:I=>z(this.toolkit,I),setContent:(I,ie)=>{G(this.toolkit,I,ie)},deleteContent:I=>{this.realm.deallocate(I)}})}else B=N;const X=new Tt(s,{externalStore:B,isAType:s.isAType,isBType:s.isBType,makeContentKey:(...z)=>{const[G,re]=z,I=z.sort(),ie=`${I[0]}:${I[1]}`,me=r.molecules.get(Ye(G)),_e=r.molecules.get(Ye(re));return me||this.realm.allocate(s.key,G),_e||this.realm.allocate(s.key,re),this.realm.allocate(G,ie,"all"),this.realm.claim(re,ie),this.store.moleculeJoins.set(ie,s.key),ie}}),F=()=>Ks(r,{key:`${s.key}/singleRelatedKey`,get:z=>({get:G})=>{const re=G(h,z);for(const I of re)return I;return null}},["join","keys"]),le=()=>Ks(r,{key:`${s.key}/multipleRelatedKeys`,get:z=>({get:G})=>{const re=Ry(h,r);return G(re,z).members}},["join","keys"]),ve=()=>Ks(r,{key:`${s.key}/singleRelatedEntry`,get:z=>({get:G})=>{var I;const re=G(h,z);for(const ie of re){let me=(I=X.isAType)!=null&&I.call(X,z)?z:void 0,_e=me===void 0?z:void 0;me??(me=ie),_e??(_e=ie);const Te=X.makeContentKey(me,_e),Le=G(j,Te);return[ie,Le]}return null}},["join","entries"]),gt=()=>Ks(r,{key:`${s.key}/multipleRelatedEntries`,get:z=>({get:G})=>{const re=Ry(h,r);return G(re,z).members.map(ie=>{var bt;let me=(bt=X.isAType)!=null&&bt.call(X,z)?z:void 0,_e=me===void 0?z:void 0;me??(me=ie),_e??(_e=ie);const Te=X.makeContentKey(me,_e),Le=G(j,Te);return[ie,Le]})}},["join","entries"]);switch(s.cardinality){case"1:1":{const z=F(),G=`${o}KeyOf${Jt(c)}`,re=`${c}KeyOf${Jt(o)}`,I={[G]:z,[re]:z};let ie;if(n){const me=ve(),_e=`${o}EntryOf${Jt(c)}`,Te=`${c}EntryOf${Jt(o)}`,Le={[_e]:me,[Te]:me};ie=Object.assign(I,Le)}else ie=I;this.relations=X,this.states=ie;break}case"1:n":{const z=F(),G=le(),re=`${o}KeyOf${Jt(c)}`,I=`${c}KeysOf${Jt(o)}`,ie={[re]:z,[I]:G};let me;if(n){const _e=ve(),Te=gt(),Le=`${o}EntryOf${Jt(c)}`,bt=`${c}EntriesOf${Jt(o)}`,Ce={[Le]:_e,[bt]:Te};me=Object.assign(ie,Ce)}else me=ie;this.relations=X,this.states=me;break}case"n:n":{const z=le(),G=`${o}KeysOf${Jt(c)}`,re=`${c}KeysOf${Jt(o)}`,I={[G]:z,[re]:z};let ie;if(n){const me=gt(),_e=`${o}EntriesOf${Jt(c)}`,Te=`${c}EntriesOf${Jt(o)}`,Le={[_e]:me,[Te]:me};ie=Object.assign(I,Le)}else ie=I;this.relations=X,this.states=ie}}}transact(s,n){const r=this.toolkit;this.toolkit=s,n(this),this.toolkit=r}[Symbol.dispose](){}}function tw(t,s){let n=s.joins.get(t.key);if(n===void 0){const o=tt.STORE.joins.get(t.key);if(o===void 0)throw new Error(`Join "${t.key}" not found in store "${s.config.name}"`);n=new fb(o.options,o.defaultContent,s),s.joins.set(t.key,n)}return n}function nw(t,s){return tw(t,s).core.relatedKeysAtoms}function iw(t){return t.startsWith("🔍 ")}var Jc={exports:{}},ue={};/**
23
23
  * @license React
24
24
  * react.production.js
25
25
  *
package/app/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>TEMPEST</title>
8
- <script type="module" crossorigin src="/assets/index-HtWKEKQB.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-BvW-zGjV.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-k4NBGR4H.css">
10
10
  </head>
11
11
  <body>