tempest.games 0.2.21 → 0.2.23

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,24 @@
1
1
  # tempest.games
2
2
 
3
+ ## 0.2.23
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [208b4a9]
8
+ - Updated dependencies [208b4a9]
9
+ - Updated dependencies [208b4a9]
10
+ - Updated dependencies [208b4a9]
11
+ - Updated dependencies [208b4a9]
12
+ - atom.io@0.33.14
13
+
14
+ ## 0.2.22
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [6fc9abf]
19
+ - Updated dependencies [6fc9abf]
20
+ - atom.io@0.33.13
21
+
3
22
  ## 0.2.21
4
23
 
5
24
  ### Patch Changes
@@ -19,7 +19,7 @@ ${S.trace}`:`No previous disposal trace for ${n} was found.`);return}const o=t.m
19
19
  ${v.trace}`:`No previous disposal trace for ${o} was found.`),n}const d=Ze(e),h=c.molecules.get(d);if(!h){const v=t.disposalTraces.buffer.find(S=>S?.key===d);return t.logger.error("❌","molecule",n,"claim failed:",`Could not allocate to ${d} in store "${t.config.name}".`,v?`
20
20
  ${d} was most recently disposed
21
21
  ${v.trace}`:`No previous disposal trace for ${d} was found.`),n}const p=t.moleculeGraph.getRelationEntries({downstreamMoleculeKey:u.stringKey}).filter(([,{source:v}])=>v!==o).map(([v])=>ds(v));r&&c.moleculeGraph.delete(o),c.moleculeGraph.set({upstreamMoleculeKey:h.stringKey,downstreamMoleculeKey:u.stringKey},{source:h.stringKey});const y={type:"molecule_transfer",key:u.key,from:p,to:[h.key]};return Yt(c)&&c.transactionMeta.phase==="building"&&c.transactionMeta.update.updates.push(y),n}function oM(t,e,n){switch(e){case"newValue":{l1(t,n);break}case"oldValue":{Xu(n,t.token);break}}}function aM(t,e,n){switch(e){case"newValue":{Xu(n,t.token);break}case"oldValue":{l1(t,n),t.subType==="atom"&&n.valueMap.set(t.token.key,t.value);break}}}function l1(t,e){const{family:n}=t.token;if(n){const r=e.families.get(n.key);r&&Jt(e,r,ds(n.subKey))}}function lM(t,e,n){switch(e){case"newValue":pl(n,t.provenance,t.key);break;case"oldValue":ml(n,t.key);break}}function cM(t,e,n){switch(e){case"newValue":ml(n,t.key);break;case"oldValue":{const r=t.provenance.map(ds);pl(n,r,t.key);for(const[o,c]of t.values){const u=n.families.get(o);if(u){Jt(n,u,t.key);const d=`${o}(${Ze(t.key)})`;n.valueMap.set(d,c)}}}break}}function uM(t,e,n){switch(e){case"newValue":{const r=t.to.length===1?t.to[0]:t.to;wu(n,r,t.key,"exclusive")}break;case"oldValue":{const r=t.from.length===1?t.from[0]:t.from;wu(n,r,t.key,"exclusive")}break}}function co(t,e,n){const r=t==="newValue"?e.updates:[...e.updates].reverse();for(const o of r)switch(o.type){case"atom_update":case"selector_update":nM(t,o,n);break;case"state_creation":oM(o,t,n);break;case"state_disposal":aM(o,t,n);break;case"molecule_creation":lM(o,t,n);break;case"molecule_disposal":cM(o,t,n);break;case"molecule_transfer":uM(o,t,n);break;case"transaction_update":co(t,o,n);break}}function c1(t,e){return t.transactionMeta.actionContinuities.getRelatedKey(e)}function u1(t,e){return t.transactionMeta.epoch.get(e)}function fM(t,e){if(!mi(t))return;const r=c1(t,e);if(r!==void 0)return u1(t,r)}function Pm(t,e,n){mi(t)&&e&&t.transactionMeta.epoch.set(e,n)}function dM(t,e,n){if(!mi(t))return;const o=c1(t,e);o!==void 0&&t.transactionMeta.epoch.set(o,n)}const hM=(t,e)=>{const n=pe(e),{parent:r}=n;if(r===null||!Yt(n)||n.transactionMeta?.phase!=="building"){e.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;e.logger.info("🛄","transaction",n.transactionMeta.update.key,`Applying transaction with ${o.length} updates:`,o),co("newValue",n.transactionMeta.update,r),mi(r)?(dM(r,n.transactionMeta.update.key,n.transactionMeta.update.epoch),Tt(e,{key:n.transactionMeta.update.key,type:"transaction"})?.subject.next(n.transactionMeta.update),e.logger.info("🛬","transaction",n.transactionMeta.update.key,"Finished applying transaction.")):Yt(r)&&r.transactionMeta.update.updates.push(n.transactionMeta.update),r.on.transactionApplying.next(null)};function f1(t,e,n){if(!mi(t))return;const{epoch:o,actionContinuities:c}=t.transactionMeta;c.set(e,n),o.has(e)||o.set(e,-1)}function pM(t){return{store:t}}function zn(t,...e){let n,r,o;if(e.length===1?n=e[0]:(r=e[0],o=e[1],n=Jt(t,r,o)),"counterfeit"in n&&"family"in n){r=t.families.get(n.family.key);const c=n.family.subKey,u=t.disposalTraces.buffer.find(d=>d?.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}".`,u?`This state was previously disposed:
22
- ${u.trace}`:"No previous disposal trace was found."),r.type){case"atom_family":case"mutable_atom_family":return t.defaults.get(r.key);case"readonly_pure_selector_family":case"writable_pure_selector_family":case"readonly_held_selector_family":case"writable_held_selector_family":{if(t.defaults.has(r.key))return t.defaults.get(n.family.key);const d=Tt(t,r).default(c);return t.defaults.set(r.key,d),d}}}return Yu(t,Tt(t,n))}var ii=class extends Map{deleted=new Set;source;constructor(t){super(),this.source=t}get(t){if(super.has(t))return super.get(t);if(!this.deleted.has(t)&&this.source.has(t))return this.source.get(t)}set(t,e){return this.deleted.delete(t),super.set(t,e)}hasOwn(t){return super.has(t)}has(t){return!this.deleted.has(t)&&(super.has(t)||this.source.has(t))}delete(t){return this.deleted.add(t),super.delete(t)}};const mM=(t,e,n,r)=>{const o=pe(t),c={parent:o,child:null,on:o.on,loggers:o.loggers,logger:o.logger,config:o.config,atoms:new ii(o.atoms),atomsThatAreDefault:new Set(o.atomsThatAreDefault),families:new ii(o.families),joins:new ii(o.joins),operation:{open:!1},readonlySelectors:new ii(o.readonlySelectors),timelines:new ii(o.timelines),timelineTopics:new Qt(o.timelineTopics.toJSON()),trackers:new Map,transactions:new ii(o.transactions),selectorAtoms:new Qt(o.selectorAtoms.toJSON()),selectorGraph:new Qt(o.selectorGraph.toJSON(),{makeContentKey:(...p)=>p.sort().join(":")}),writableSelectors:new ii(o.writableSelectors),valueMap:new ii(o.valueMap),defaults:o.defaults,disposalTraces:t.disposalTraces.copy(),molecules:new ii(o.molecules),moleculeGraph:new Qt(o.moleculeGraph.toJSON(),{makeContentKey:o.moleculeGraph.makeContentKey}),moleculeData:new Qt(o.moleculeData.toJSON(),{makeContentKey:o.moleculeData.makeContentKey}),moleculeJoins:new Qt(o.moleculeJoins.toJSON(),{makeContentKey:o.moleculeJoins.makeContentKey}),miscResources:new ii(o.miscResources)},u=fM(t,e),d={phase:"building",update:{type:"transaction_update",key:e,id:r,epoch:u===void 0?NaN:u+1,updates:[],params:n,output:void 0},toolkit:{get:(...p)=>zn(h,...p),set:(...p)=>{Et(h,...p)},run:(p,y=Gu())=>$m(h,p,y),find:(...p)=>Jt(t,...p),json:p=>ps(h,p),dispose:(...p)=>{Xu(h,...p)},env:()=>pM(h)}},h=Object.assign(c,{transactionMeta:d});return o.child=h,t.logger.info("🛫","transaction",e,"Building transaction with params:",n),h};function d1(t,e){const n={key:e.key,type:"transaction",run:(c,u)=>{const d=mM(t,e.key,c,u);try{const h=pe(t),{toolkit:p}=d.transactionMeta,y=e.do(p,...c);return hM(y,h),y}catch(h){throw qk(r),t.logger.warn("💥","transaction",e.key,"caught:",h),h}},install:c=>d1(c,e),subject:new tt},r=pe(t);r.transactions.set(n.key,n);const o=Eo(n);return t.on.transactionCreation.next(o),o}var yM=class{parent=null;child=null;valueMap=new Map;defaults=new Map;atoms=new Map;writableSelectors=new Map;readonlySelectors=new Map;atomsThatAreDefault=new Set;selectorAtoms=new Qt({between:["selectorKey","atomKey"],cardinality:"n:n"});selectorGraph=new Qt({between:["upstreamSelectorKey","downstreamSelectorKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});trackers=new Map;families=new Map;joins=new Map;transactions=new Map;transactionMeta={epoch:new Map,actionContinuities:new Qt({between:["continuity","action"],cardinality:"1:n"})};timelines=new Map;timelineTopics=new Qt({between:["timelineKey","topicKey"],cardinality:"1:n"});disposalTraces=new Vk(100);molecules=new Map;moleculeJoins=new Qt({between:["moleculeKey","joinKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});moleculeGraph=new Qt({between:["upstreamMoleculeKey","downstreamMoleculeKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});moleculeData=new Qt({between:["moleculeKey","stateFamilyKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});miscResources=new Map;on={atomCreation:new tt,atomDisposal:new tt,selectorCreation:new tt,selectorDisposal:new tt,timelineCreation:new tt,transactionCreation:new tt,transactionApplying:new Kk(null),operationClose:new tt,moleculeCreation:new tt,moleculeDisposal:new tt};operation={open:!1};config={name:"IMPLICIT_STORE",lifespan:"ephemeral"};loggers=[new Ck("warn",(t,e,n)=>!OM(n))];logger={error:(...t)=>{for(const e of this.loggers)e.error(...t)},info:(...t)=>{for(const e of this.loggers)e.info(...t)},warn:(...t)=>{for(const e of this.loggers)e.warn(...t)}};constructor(t,e=null){if(this.config={...e?.config,...t},e!==null){this.valueMap=new Map(e?.valueMap),this.operation={...e?.operation},mi(e)&&(this.transactionMeta={epoch:new Map(e?.transactionMeta.epoch),actionContinuities:new Qt(e?.transactionMeta.actionContinuities.toJSON())});for(const[,r]of e.families)r.internalRoles?.includes("mutable")||r.internalRoles?.includes("join")||r.install(this);const n=new Set;for(const[,r]of e.atoms)if(!n.has(r.key)&&(r.install(this),r.type==="mutable_atom")){const o=ps(e,r),c=y1(r);n.add(o.key),n.add(c.key)}for(const[,r]of e.readonlySelectors)r.install(this);for(const[,r]of e.writableSelectors)n.has(r.key)||r.install(this);for(const[,r]of e.transactions)r.install(this);for(const[,r]of e.timelines)r.install(this)}}};const yt={get STORE(){return globalThis.ATOM_IO_IMPLICIT_STORE??=new yM({name:"IMPLICIT_STORE",lifespan:"ephemeral"}),globalThis.ATOM_IO_IMPLICIT_STORE}};function Tt(t,e){let n,r=t;for(;r!==null;){switch(e.type){case"atom":case"mutable_atom":n=r.atoms.get(e.key);break;case"writable_pure_selector":case"writable_held_selector":n=r.writableSelectors.get(e.key);break;case"readonly_pure_selector":case"readonly_held_selector":n=r.readonlySelectors.get(e.key);break;case"atom_family":case"mutable_atom_family":case"writable_pure_selector_family":case"readonly_pure_selector_family":case"writable_held_selector_family":case"readonly_held_selector_family":n=r.families.get(e.key);break;case"timeline":n=r.timelines.get(e.key);break;case"transaction":n=r.transactions.get(e.key);break}if(n)return n;r=r.child}throw new Nm(e,t)}const gM=(t,e)=>{const n=pe(t);return n.operation.open?n.operation.prev.get(e.key):n.valueMap.get(e.key)};function bM(t,e,n,r=Gu()){switch(e.type){case"atom":case"mutable_atom":case"readonly_pure_selector":case"readonly_held_selector":case"writable_pure_selector":case"writable_held_selector":return Ro(t,e,r,n);case"transaction":return p1(t,e,r,n);case"timeline":return h1(t,e,r,n)}}const Q0=(t,e)=>{const n=pe(t);return Jk(e,t).map(o=>{const c=n.atoms.get(o);if(c===void 0)throw new Error(`Atom "${o}", a dependency of selector "${e.key}", not found in store "${t.config.name}".`);return c.subject.subscribe(`${e.type}:${e.key}`,u=>{t.logger.info("📢",e.type,e.key,"root",o,"went",u.oldValue,"->",u.newValue);const d=gM(n,e),h=Yu(n,e);t.logger.info("✨",e.type,e.key,"went",d,"->",h),e.subject.next({newValue:h,oldValue:d})})})};function Ro(t,e,n,r){function o(g){if(t.operation.open){const v=t.on.operationClose.subscribe(`state subscription ${n}`,()=>{v(),r(g)})}else r(g)}const c=Tt(t,e);t.logger.info("👀",c.type,c.key,`Adding subscription "${n}"`);const u=c.type==="writable_pure_selector"||c.type==="readonly_pure_selector";let d=null,h=o;u&&(d=Q0(t,c),h=g=>{d&&(d.length=0,d.push(...Q0(t,c))),o(g)});const p=c.subject.subscribe(n,h);return()=>{if(t.logger.info("🙈",c.type,c.key,`Removing subscription "${n}"`),p(),d)for(const g of d)g()}}const h1=(t,e,n,r)=>{const o=Tt(t,e);t.logger.info("👀","timeline",e.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","timeline",e.key,`Removing subscription "${n}" from timeline`),c()}},p1=(t,e,n,r)=>{const o=Tt(t,e);t.logger.info("👀","transaction",e.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","transaction",e.key,`Removing subscription "${n}"`),c()}};var Im=class{initializeState(t,e){const n=`*${t.key}`;e.atoms.delete(n),e.valueMap.delete(n);const r=t.family?{key:`*${t.family.key}`,subKey:t.family.subKey}:void 0,o=Zu(e,{key:n,default:null},r);if(e.parent?.valueMap.has(n)){const c=e.parent.valueMap.get(n);e.valueMap.set(n,c)}return o}unsubscribeFromInnerValue;unsubscribeFromState;observeCore(t,e,n){const r=`tracker:${n.config.name}:${Yt(n)?n.transactionMeta.update.key:"main"}:${t.key}`,o=zn(n,t);this.unsubscribeFromInnerValue=o.subscribe(r,c=>{Et(n,e,c)}),this.unsubscribeFromState=Ro(n,t,r,c=>{c.newValue!==c.oldValue&&(this.unsubscribeFromInnerValue(),this.unsubscribeFromInnerValue=c.newValue.subscribe(r,u=>{Et(n,e,u)}))})}updateCore(t,e,n){const r=`tracker:${n.config.name}:${Yt(n)?n.transactionMeta.update.key:"main"}:${t.key}`;Ro(n,e,r,({newValue:o,oldValue:c})=>{const u=n.timelineTopics.getRelatedKey(e.key);if(u&&n.timelines.get(u)?.timeTraveling){const p=h1(n,{key:u,type:"timeline"},r,y=>{p(),Et(n,t,g=>(y==="redo"&&o?g.do(o):y==="undo"&&c&&g.undo(c),g))});return}const d=n.on.operationClose.subscribe(r,()=>{d();const h=zn(n,t),p=o===null?-1:h.getUpdateNumber(o),y=p-h.cacheUpdateNumber;o&&y===1?Et(n,t,g=>(g.do(o),g)):n.logger.info("❌","mutable_atom",t.key,`could not be updated. Expected update number ${h.cacheUpdateNumber+1}, but got ${p}`)})})}mutableState;latestUpdateState;[Symbol.dispose];constructor(t,e){this.mutableState=t;const n=pe(e);this.latestUpdateState=this.initializeState(t,n),this.observeCore(t,this.latestUpdateState,n),this.updateCore(t,this.latestUpdateState,n),n.trackers.set(t.key,this),this[Symbol.dispose]=()=>{this.unsubscribeFromInnerValue(),this.unsubscribeFromState(),n.trackers.delete(t.key)}}};function Hm(t,e,n){t.logger.info("🔨","atom",e.key,`creating in store "${t.config.name}"`);const r=pe(t),{key:o,default:c}=e,u=r.atoms.get(o),d="mutable_atom";if(u&&u.type===d)return t.logger.error("❌",d,o,"Tried to create atom, but it already exists in the store."),Eo(u);const h=new tt,p={...e,type:d,install:v=>(v.logger.info("🛠️","atom",o,`installing in store "${v.config.name}"`),Hm(v,e,n)),subject:h};n&&(p.family=n);const y=c();r.atoms.set(p.key,p),b1(t,o),fi(r,o,y,h);const g=Eo(p);if(e.effects){let v=0;const S=[];for(const T of e.effects){const w=T({setSelf:D=>{Et(t,g,D)},onSet:D=>Ro(t,g,`effect[${v}]`,D)});w&&S.push(w),++v}p.cleanup=()=>{for(const T of S)T()}}return new Im(g,t),n||Rk(g,e,t),g}var vM=class{trackers=new Map;latestUpdateAtoms;mutableAtoms;constructor(t,e){const n=Bm(e,{key:`*${t.key}`,default:null},["mutable","updates"]);this.latestUpdateAtoms=Tt(e,n),this.mutableAtoms=t,this.mutableAtoms.subject.subscribe(`store=${e.config.name}::tracker-atom-family`,r=>{const{type:o,token:c}=r;if(c.family){const u=ds(c.family.subKey);switch(o){case"state_creation":this.trackers.set(u,new Im(c,e));break;case"state_disposal":{const d=this.trackers.get(u);d&&(d[Symbol.dispose](),this.trackers.delete(u))}break}}})}};function m1(t,e,n){const r={key:e.key,type:"mutable_atom_family"},o=t.families.get(e.key);o&&t.logger.error("❗","mutable_atom_family",e.key,`Overwriting an existing ${hs(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 tt,d=Object.assign(h=>{const p=Ze(h),y={key:e.key,subKey:p},g=`${e.key}(${p})`,v=pe(t),S={key:g,default:()=>e.default(h),toJson:e.toJson,fromJson:e.fromJson,mutable:!0};e.effects&&(S.effects=e.effects(h));const T=Hm(v,S,y);return c.next({type:"state_creation",token:T}),T},r,{subject:c,install:h=>m1(h,e),toJson:e.toJson,fromJson:e.fromJson,internalRoles:n});return t.families.set(e.key,d),Ok(t,d,e),new vM(d,t),r}const W0=(t,e)=>{const n=pe(e),r=`${t.key}:JSON`;return n.families.get(r)},ps=(t,e)=>{if(e.family){const r=pe(t),c={key:`${e.family.key}:JSON`,type:"writable_pure_selector_family"},u=Tt(r,c),d=JSON.parse(e.family.subKey);return Jt(t,u,d)}return{type:"writable_pure_selector",key:`${e.key}:JSON`}},y1=t=>{const n={type:"atom",key:`*${t.key}`};return t.family&&(n.family={key:`*${t.family.key}`,subKey:t.family.subKey}),n};function SM(t){return typeof t=="object"&&t!==null&&"do"in t&&"undo"in t&&"subscribe"in t}function kp(t,e,n){const r=n.valueMap.get(e.key),o=t.valueMap.get(e.key);if(r!==o)return o;if(r===void 0)return e.default();n.logger.info("📃","atom",e.key,"copying");const c=e.toJson(r),u=e.fromJson(c);return t.valueMap.set(e.key,u),new Im(e,n),u}function fi(t,e,n,r){const o=t.valueMap.get(e);if(o instanceof Ap){const c=o;return n instanceof Promise?c:(t.valueMap.set(e,n),n)}if(n instanceof Promise){const c=new Ap(n);return t.valueMap.set(e,c),c.then(u=>{if(t.valueMap.get(e)===c){fi(t,e,u,r);const h=t.atoms.get(e);if(h)Ep(t,h),Op(t,h),Rp(t);else{const p=t.writableSelectors.get(e)??t.readonlySelectors.get(e);p&&(Ep(t,p),Ik(t,p),Rp(t))}r.next({newValue:u,oldValue:c})}}).catch(u=>{t.logger.error("💥","state",e,"rejected:",u)}),c}return t.valueMap.set(e,n),n}const xM=(t,e)=>{let n=e.valueMap.get(t.key);if(t.type==="mutable_atom"&&Yt(e)){const{parent:r}=e;n=kp(e,t,r)}return n},g1=(t,e)=>{const n=e.valueMap.get(t);if(n instanceof Ap){const r=n,o=e.writableSelectors.get(t)??e.readonlySelectors.get(t);o&&r.use(o.get());return}e.operation.open&&e.operation.prev.set(t,n),e.valueMap.delete(t),e.logger.info("🗑","state",t,"evicted")},wM=(t,e)=>pe(t).atomsThatAreDefault.has(e),b1=(t,e)=>{const n=pe(t);n.atomsThatAreDefault=new Set(n.atomsThatAreDefault).add(e)},TM=(t,e)=>{const n=pe(t);n.atomsThatAreDefault=new Set(pe(t).atomsThatAreDefault),n.atomsThatAreDefault.delete(e)};function Zu(t,e,n){const r="atom",{key:o,default:c}=e;t.logger.info("🔨","atom",o,`creating in store "${t.config.name}"`);const u=pe(t),d=u.atoms.get(o);if(d&&d.type===r)return t.logger.error("❌","atom",o,"Tried to create atom, but it already exists in the store."),Eo(d);const h=new tt,p={...e,type:r,install:v=>(v.logger.info("🛠️",r,o,`installing in store "${v.config.name}"`),Zu(v,e,n)),subject:h};n&&(p.family=n);let y=c;c instanceof Function&&(y=c()),u.atoms.set(o,p),b1(t,o),fi(u,o,y,h);const g=Eo(p);if(e.effects){let v=0;const S=[];for(const T of e.effects){const w=T({setSelf:D=>{Et(t,g,D)},onSet:D=>Ro(t,g,`effect[${v}]`,D)});w&&S.push(w),++v}p.cleanup=()=>{for(const T of S)T()}}return g}function AM(t,e){if("mutable"in e){const o=Hm(t,e,void 0);return t.on.atomCreation.next(o),o}const r=Zu(t,e,void 0);return t.on.atomCreation.next(r),r}function Fm(t,e){const n=pe(t),{key:r,family:o}=e,c=Tt(n,e);if(!o)t.logger.error("❌","atom",r,"Standalone atoms cannot be disposed.");else{c.cleanup?.();const u=t.valueMap.get(c.key),d=Tt(t,{key:o.key,type:"atom_family"}),h={type:"state_disposal",subType:"atom",token:e,value:u};d.subject.next(h);const p=Yt(n);if(n.atoms.delete(r),n.valueMap.delete(r),n.selectorAtoms.delete(r),n.atomsThatAreDefault.delete(r),t.timelineTopics.delete(r),e.type==="mutable_atom"){const y=y1(e);Fm(t,y),t.trackers.delete(r)}if(t.logger.info("🔥","atom",r,"deleted"),p&&n.transactionMeta.phase==="building"){const y=n.transactionMeta.update.updates.at(-1);y?.type==="molecule_disposal"&&y.values.some(([S])=>S===c.family?.key)||n.transactionMeta.update.updates.push(h)}else t.on.atomDisposal.next(e)}}var v1=class{toolkit;options;defaultContent;molecules=new Map;relations;states;core;transact(t,e){const n=this.toolkit;this.toolkit=t,e(this),this.toolkit=n}store;realm;[Symbol.dispose](){}constructor(t,e,n=yt.STORE){this.store=n,this.realm=new Nk(n),this.options=t,this.defaultContent=e,this.store.miscResources.set(`join:${t.key}`,this),this.realm.allocate("root",t.key),this.toolkit={get:(...C)=>zn(n,...C),set:(...C)=>{Et(n,...C)},find:(...C)=>Jt(n,...C),json:C=>ps(n,C)};const r=t.between[0],o=t.between[1],c=m1(n,{key:`${t.key}/relatedKeys`,default:()=>new Ao,mutable:!0,fromJson:C=>Ao.fromJSON(C),toJson:C=>C.toJSON()},["join","relations"]);this.core={relatedKeysAtoms:c};const u=({get:C},O)=>C(c,O),d=({set:C},O,X)=>{this.store.molecules.has(Ze(O))||this.realm.allocate(t.key,O),C(c,O,F=>F.add(X)),C(c,X,F=>F.add(O))},h=({set:C},O,X)=>{C(c,O,F=>(F.delete(X),F)),C(c,X,F=>(F.delete(O),F))},p=(C,O,X)=>{const{find:F,get:G,set:te}=C,oe=F(c,O),ue=G(oe);for(const me of ue)X.includes(me)||te(c,me,ce=>(ce.delete(O),ce));te(oe,me=>(me.transaction(be=>{be.clear();for(const ce of X){const Z=u(C,ce),B=Z.has(O);if(this.relations.cardinality==="1:n"){const P=[];for(const q of Z){if(q===O)continue;const W=u(C,q);W.delete(ce),W.size===0&&P.push(q)}!B&&Z.size>0&&Z.clear();for(const q of P){const W=[ce,q].sort(),A=`"${W[0]}:${W[1]}"`;this.molecules.delete(A)}}B||Z.add(O),be.add(ce)}return!0}),me))},y=(C,O,X)=>{const{set:F}=C;F(c,O,G=>(G.transaction(te=>{for(const oe of X)te.add(oe);return!0}),G));for(const G of X)F(c,G,te=>(te.add(O),te));return!0},g=(C,O,X)=>{const F=u(C,O);return X?F.has(X):F.size>0},v={getRelatedKeys:C=>u(this.toolkit,C),addRelation:(C,O)=>{this.store.moleculeJoins.set(C,t.key),this.store.moleculeJoins.set(O,t.key),d(this.toolkit,C,O)},deleteRelation:(C,O)=>{h(this.toolkit,C,O)},replaceRelationsSafely:(C,O)=>{p(this.toolkit,C,O)},replaceRelationsUnsafely:(C,O)=>{y(this.toolkit,C,O)},has:(C,O)=>g(this.toolkit,C,O)};let S,T;if(e){T=Bm(n,{key:`${t.key}/content`,default:e},["join","content"]);const C=({get:F},G)=>F(T,G),O=({set:F},G,te)=>{F(T,G,te)};S=Object.assign(v,{getContent:F=>C(this.toolkit,F),setContent:(F,G)=>{O(this.toolkit,F,G)},deleteContent:F=>{this.realm.deallocate(F)}})}else S=v;const w=new Qt(t,{externalStore:S,isAType:t.isAType,isBType:t.isBType,makeContentKey:(...C)=>{const[O,X]=C,F=C.sort(),G=`${F[0]}:${F[1]}`,te=n.molecules.get(Ze(O)),oe=n.molecules.get(Ze(X));return te||this.realm.allocate(t.key,O),oe||this.realm.allocate(t.key,X),this.realm.allocate(O,G,"all"),this.realm.claim(X,G),this.store.moleculeJoins.set(G,t.key),G}}),D=()=>lo(n,{key:`${t.key}/singleRelatedKey`,get:C=>({get:O})=>{const X=O(c,C);for(const F of X)return F;return null}},["join","keys"]),$=()=>lo(n,{key:`${t.key}/multipleRelatedKeys`,get:C=>({get:O})=>{const X=W0(c,n);return O(X,C).members}},["join","keys"]),_=()=>lo(n,{key:`${t.key}/singleRelatedEntry`,get:C=>({get:O})=>{const X=O(c,C);for(const F of X){let G=w.isAType?.(C)?C:void 0,te=G===void 0?C:void 0;G??=F,te??=F;const oe=w.makeContentKey(G,te),ue=O(T,oe);return[F,ue]}return null}},["join","entries"]),k=()=>lo(n,{key:`${t.key}/multipleRelatedEntries`,get:C=>({get:O})=>{const X=W0(c,n);return O(X,C).members.map(G=>{let te=w.isAType?.(C)?C:void 0,oe=te===void 0?C:void 0;te??=G,oe??=G;const ue=w.makeContentKey(te,oe),me=O(T,ue);return[G,me]})}},["join","entries"]);switch(t.cardinality){case"1:1":{const C=D(),O=`${r}KeyOf${ln(o)}`,X=`${o}KeyOf${ln(r)}`,F={[O]:C,[X]:C};let G;if(e){const te=_(),oe=`${r}EntryOf${ln(o)}`,ue=`${o}EntryOf${ln(r)}`,me={[oe]:te,[ue]:te};G=Object.assign(F,me)}else G=F;this.relations=w,this.states=G;break}case"1:n":{const C=D(),O=$(),X=`${r}KeyOf${ln(o)}`,F=`${o}KeysOf${ln(r)}`,G={[X]:C,[F]:O};let te;if(e){const oe=_(),ue=k(),me=`${r}EntryOf${ln(o)}`,be=`${o}EntriesOf${ln(r)}`,ce={[me]:oe,[be]:ue};te=Object.assign(G,ce)}else te=G;this.relations=w,this.states=te;break}case"n:n":{const C=$(),O=`${r}KeysOf${ln(o)}`,X=`${o}KeysOf${ln(r)}`,F={[O]:C,[X]:C};let G;if(e){const te=k(),oe=`${r}EntriesOf${ln(o)}`,ue=`${o}EntriesOf${ln(r)}`,me={[oe]:te,[ue]:te};G=Object.assign(F,me)}else G=F;this.relations=w,this.states=G}}}};function EM(t,e){let n=e.joins.get(t.key);if(n===void 0){const o=yt.STORE.joins.get(t.key);if(o===void 0)throw new Error(`Join "${t.key}" not found in store "${e.config.name}"`);n=new v1(o.options,o.defaultContent,e),e.joins.set(t.key,n)}return n}function RM(t,e){return EM(t,e).core.relatedKeysAtoms}function OM(t){return t.startsWith("🔍 ")}var Bh={exports:{}},xe={};/**
22
+ ${u.trace}`:"No previous disposal trace was found."),r.type){case"atom_family":case"mutable_atom_family":return t.defaults.get(r.key);case"readonly_pure_selector_family":case"writable_pure_selector_family":case"readonly_held_selector_family":case"writable_held_selector_family":{if(t.defaults.has(r.key))return t.defaults.get(n.family.key);const d=Tt(t,r).default(c);return t.defaults.set(r.key,d),d}}}return Yu(t,Tt(t,n))}var ii=class extends Map{deleted=new Set;source;constructor(t){super(),this.source=t}get(t){if(super.has(t))return super.get(t);if(!this.deleted.has(t)&&this.source.has(t))return this.source.get(t)}set(t,e){return this.deleted.delete(t),super.set(t,e)}hasOwn(t){return super.has(t)}has(t){return!this.deleted.has(t)&&(super.has(t)||this.source.has(t))}delete(t){return this.deleted.add(t),super.delete(t)}};const mM=(t,e,n,r)=>{const o=pe(t),c={parent:o,child:null,on:o.on,loggers:o.loggers,logger:o.logger,config:o.config,atoms:new ii(o.atoms),atomsThatAreDefault:new Set(o.atomsThatAreDefault),families:new ii(o.families),joins:new ii(o.joins),operation:{open:!1},readonlySelectors:new ii(o.readonlySelectors),timelines:new ii(o.timelines),timelineTopics:new Qt(o.timelineTopics.toJSON()),trackers:new Map,transactions:new ii(o.transactions),selectorAtoms:new Qt(o.selectorAtoms.toJSON()),selectorGraph:new Qt(o.selectorGraph.toJSON(),{makeContentKey:(...p)=>p.sort().join(":")}),writableSelectors:new ii(o.writableSelectors),valueMap:new ii(o.valueMap),defaults:o.defaults,disposalTraces:t.disposalTraces.copy(),molecules:new ii(o.molecules),moleculeGraph:new Qt(o.moleculeGraph.toJSON(),{makeContentKey:o.moleculeGraph.makeContentKey}),moleculeData:new Qt(o.moleculeData.toJSON(),{makeContentKey:o.moleculeData.makeContentKey}),moleculeJoins:new Qt(o.moleculeJoins.toJSON(),{makeContentKey:o.moleculeJoins.makeContentKey}),miscResources:new ii(o.miscResources)},u=fM(t,e),d={phase:"building",update:{type:"transaction_update",key:e,id:r,epoch:u===void 0?NaN:u+1,updates:[],params:n,output:void 0},toolkit:{get:(...p)=>zn(h,...p),set:(...p)=>{Et(h,...p)},run:(p,y=Gu())=>$m(h,p,y),find:(...p)=>Jt(t,...p),json:p=>ps(h,p),dispose:(...p)=>{Xu(h,...p)},env:()=>pM(h)}},h=Object.assign(c,{transactionMeta:d});return o.child=h,t.logger.info("🛫","transaction",e,"Building transaction with params:",n),h};function d1(t,e){const{key:n}=e,r=t.transactions.has(n),o={key:n,type:"transaction",run:(d,h)=>{const p=mM(t,n,d,h);try{const y=pe(t),{toolkit:g}=p.transactionMeta,v=e.do(g,...d);return hM(v,y),v}catch(y){throw qk(c),t.logger.warn("💥","transaction",n,"caught:",y),y}},install:d=>d1(d,e),subject:new tt},c=pe(t);c.transactions.set(n,o);const u=Eo(o);return r||t.on.transactionCreation.next(u),u}var yM=class{parent=null;child=null;valueMap=new Map;defaults=new Map;atoms=new Map;writableSelectors=new Map;readonlySelectors=new Map;atomsThatAreDefault=new Set;selectorAtoms=new Qt({between:["selectorKey","atomKey"],cardinality:"n:n"});selectorGraph=new Qt({between:["upstreamSelectorKey","downstreamSelectorKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});trackers=new Map;families=new Map;joins=new Map;transactions=new Map;transactionMeta={epoch:new Map,actionContinuities:new Qt({between:["continuity","action"],cardinality:"1:n"})};timelines=new Map;timelineTopics=new Qt({between:["timelineKey","topicKey"],cardinality:"1:n"});disposalTraces=new Vk(100);molecules=new Map;moleculeJoins=new Qt({between:["moleculeKey","joinKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});moleculeGraph=new Qt({between:["upstreamMoleculeKey","downstreamMoleculeKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});moleculeData=new Qt({between:["moleculeKey","stateFamilyKey"],cardinality:"n:n"},{makeContentKey:(...t)=>t.sort().join(":")});miscResources=new Map;on={atomCreation:new tt,atomDisposal:new tt,selectorCreation:new tt,selectorDisposal:new tt,timelineCreation:new tt,transactionCreation:new tt,transactionApplying:new Kk(null),operationClose:new tt,moleculeCreation:new tt,moleculeDisposal:new tt};operation={open:!1};config={name:"IMPLICIT_STORE",lifespan:"ephemeral"};loggers=[new Ck("warn",(t,e,n)=>!OM(n))];logger={error:(...t)=>{for(const e of this.loggers)e.error(...t)},info:(...t)=>{for(const e of this.loggers)e.info(...t)},warn:(...t)=>{for(const e of this.loggers)e.warn(...t)}};constructor(t,e=null){if(this.config={...e?.config,...t},e!==null){this.valueMap=new Map(e?.valueMap),this.operation={...e?.operation},mi(e)&&(this.transactionMeta={epoch:new Map(e?.transactionMeta.epoch),actionContinuities:new Qt(e?.transactionMeta.actionContinuities.toJSON())});for(const[,r]of e.families)r.internalRoles?.includes("mutable")||r.internalRoles?.includes("join")||r.install(this);const n=new Set;for(const[,r]of e.atoms)if(!n.has(r.key)&&(r.install(this),r.type==="mutable_atom")){const o=ps(e,r),c=y1(r);n.add(o.key),n.add(c.key)}for(const[,r]of e.readonlySelectors)r.install(this);for(const[,r]of e.writableSelectors)n.has(r.key)||r.install(this);for(const[,r]of e.transactions)r.install(this);for(const[,r]of e.timelines)r.install(this)}}};const yt={get STORE(){return globalThis.ATOM_IO_IMPLICIT_STORE??=new yM({name:"IMPLICIT_STORE",lifespan:"ephemeral"}),globalThis.ATOM_IO_IMPLICIT_STORE}};function Tt(t,e){let n,r=t;for(;r!==null;){switch(e.type){case"atom":case"mutable_atom":n=r.atoms.get(e.key);break;case"writable_pure_selector":case"writable_held_selector":n=r.writableSelectors.get(e.key);break;case"readonly_pure_selector":case"readonly_held_selector":n=r.readonlySelectors.get(e.key);break;case"atom_family":case"mutable_atom_family":case"writable_pure_selector_family":case"readonly_pure_selector_family":case"writable_held_selector_family":case"readonly_held_selector_family":n=r.families.get(e.key);break;case"timeline":n=r.timelines.get(e.key);break;case"transaction":n=r.transactions.get(e.key);break}if(n)return n;r=r.child}throw new Nm(e,t)}const gM=(t,e)=>{const n=pe(t);return n.operation.open?n.operation.prev.get(e.key):n.valueMap.get(e.key)};function bM(t,e,n,r=Gu()){switch(e.type){case"atom":case"mutable_atom":case"readonly_pure_selector":case"readonly_held_selector":case"writable_pure_selector":case"writable_held_selector":return Ro(t,e,r,n);case"transaction":return p1(t,e,r,n);case"timeline":return h1(t,e,r,n)}}const Q0=(t,e)=>{const n=pe(t);return Jk(e,t).map(o=>{const c=n.atoms.get(o);if(c===void 0)throw new Error(`Atom "${o}", a dependency of selector "${e.key}", not found in store "${t.config.name}".`);return c.subject.subscribe(`${e.type}:${e.key}`,u=>{t.logger.info("📢",e.type,e.key,"root",o,"went",u.oldValue,"->",u.newValue);const d=gM(n,e),h=Yu(n,e);t.logger.info("✨",e.type,e.key,"went",d,"->",h),e.subject.next({newValue:h,oldValue:d})})})};function Ro(t,e,n,r){function o(g){if(t.operation.open){const v=t.on.operationClose.subscribe(`state subscription ${n}`,()=>{v(),r(g)})}else r(g)}const c=Tt(t,e);t.logger.info("👀",c.type,c.key,`Adding subscription "${n}"`);const u=c.type==="writable_pure_selector"||c.type==="readonly_pure_selector";let d=null,h=o;u&&(d=Q0(t,c),h=g=>{d&&(d.length=0,d.push(...Q0(t,c))),o(g)});const p=c.subject.subscribe(n,h);return()=>{if(t.logger.info("🙈",c.type,c.key,`Removing subscription "${n}"`),p(),d)for(const g of d)g()}}const h1=(t,e,n,r)=>{const o=Tt(t,e);t.logger.info("👀","timeline",e.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","timeline",e.key,`Removing subscription "${n}" from timeline`),c()}},p1=(t,e,n,r)=>{const o=Tt(t,e);t.logger.info("👀","transaction",e.key,`Adding subscription "${n}"`);const c=o.subject.subscribe(n,r);return()=>{t.logger.info("🙈","transaction",e.key,`Removing subscription "${n}"`),c()}};var Im=class{initializeState(t,e){const n=`*${t.key}`;e.atoms.delete(n),e.valueMap.delete(n);const r=t.family?{key:`*${t.family.key}`,subKey:t.family.subKey}:void 0,o=Zu(e,{key:n,default:null},r);if(e.parent?.valueMap.has(n)){const c=e.parent.valueMap.get(n);e.valueMap.set(n,c)}return o}unsubscribeFromInnerValue;unsubscribeFromState;observeCore(t,e,n){const r=`tracker:${n.config.name}:${Yt(n)?n.transactionMeta.update.key:"main"}:${t.key}`,o=zn(n,t);this.unsubscribeFromInnerValue=o.subscribe(r,c=>{Et(n,e,c)}),this.unsubscribeFromState=Ro(n,t,r,c=>{c.newValue!==c.oldValue&&(this.unsubscribeFromInnerValue(),this.unsubscribeFromInnerValue=c.newValue.subscribe(r,u=>{Et(n,e,u)}))})}updateCore(t,e,n){const r=`tracker:${n.config.name}:${Yt(n)?n.transactionMeta.update.key:"main"}:${t.key}`;Ro(n,e,r,({newValue:o,oldValue:c})=>{const u=n.timelineTopics.getRelatedKey(e.key);if(u&&n.timelines.get(u)?.timeTraveling){const p=h1(n,{key:u,type:"timeline"},r,y=>{p(),Et(n,t,g=>(y==="redo"&&o?g.do(o):y==="undo"&&c&&g.undo(c),g))});return}const d=n.on.operationClose.subscribe(r,()=>{d();const h=zn(n,t),p=o===null?-1:h.getUpdateNumber(o),y=p-h.cacheUpdateNumber;o&&y===1?Et(n,t,g=>(g.do(o),g)):n.logger.info("❌","mutable_atom",t.key,`could not be updated. Expected update number ${h.cacheUpdateNumber+1}, but got ${p}`)})})}mutableState;latestUpdateState;[Symbol.dispose];constructor(t,e){this.mutableState=t;const n=pe(e);this.latestUpdateState=this.initializeState(t,n),this.observeCore(t,this.latestUpdateState,n),this.updateCore(t,this.latestUpdateState,n),n.trackers.set(t.key,this),this[Symbol.dispose]=()=>{this.unsubscribeFromInnerValue(),this.unsubscribeFromState(),n.trackers.delete(t.key)}}};function Hm(t,e,n){t.logger.info("🔨","atom",e.key,`creating in store "${t.config.name}"`);const r=pe(t),{key:o,default:c}=e,u=r.atoms.get(o),d="mutable_atom";if(u&&u.type===d)return t.logger.error("❌",d,o,"Tried to create atom, but it already exists in the store."),Eo(u);const h=new tt,p={...e,type:d,install:v=>(v.logger.info("🛠️","atom",o,`installing in store "${v.config.name}"`),Hm(v,e,n)),subject:h};n&&(p.family=n);const y=c();r.atoms.set(p.key,p),b1(t,o),fi(r,o,y,h);const g=Eo(p);if(e.effects){let v=0;const S=[];for(const T of e.effects){const w=T({setSelf:D=>{Et(t,g,D)},onSet:D=>Ro(t,g,`effect[${v}]`,D)});w&&S.push(w),++v}p.cleanup=()=>{for(const T of S)T()}}return new Im(g,t),n||Rk(g,e,t),g}var vM=class{trackers=new Map;latestUpdateAtoms;mutableAtoms;constructor(t,e){const n=Bm(e,{key:`*${t.key}`,default:null},["mutable","updates"]);this.latestUpdateAtoms=Tt(e,n),this.mutableAtoms=t,this.mutableAtoms.subject.subscribe(`store=${e.config.name}::tracker-atom-family`,r=>{const{type:o,token:c}=r;if(c.family){const u=ds(c.family.subKey);switch(o){case"state_creation":this.trackers.set(u,new Im(c,e));break;case"state_disposal":{const d=this.trackers.get(u);d&&(d[Symbol.dispose](),this.trackers.delete(u))}break}}})}};function m1(t,e,n){const r={key:e.key,type:"mutable_atom_family"},o=t.families.get(e.key);o&&t.logger.error("❗","mutable_atom_family",e.key,`Overwriting an existing ${hs(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 tt,d=Object.assign(h=>{const p=Ze(h),y={key:e.key,subKey:p},g=`${e.key}(${p})`,v=pe(t),S={key:g,default:()=>e.default(h),toJson:e.toJson,fromJson:e.fromJson,mutable:!0};e.effects&&(S.effects=e.effects(h));const T=Hm(v,S,y);return c.next({type:"state_creation",token:T}),T},r,{subject:c,install:h=>m1(h,e),toJson:e.toJson,fromJson:e.fromJson,internalRoles:n});return t.families.set(e.key,d),Ok(t,d,e),new vM(d,t),r}const W0=(t,e)=>{const n=pe(e),r=`${t.key}:JSON`;return n.families.get(r)},ps=(t,e)=>{if(e.family){const r=pe(t),c={key:`${e.family.key}:JSON`,type:"writable_pure_selector_family"},u=Tt(r,c),d=JSON.parse(e.family.subKey);return Jt(t,u,d)}return{type:"writable_pure_selector",key:`${e.key}:JSON`}},y1=t=>{const n={type:"atom",key:`*${t.key}`};return t.family&&(n.family={key:`*${t.family.key}`,subKey:t.family.subKey}),n};function SM(t){return typeof t=="object"&&t!==null&&"do"in t&&"undo"in t&&"subscribe"in t}function kp(t,e,n){const r=n.valueMap.get(e.key),o=t.valueMap.get(e.key);if(r!==o)return o;if(r===void 0)return e.default();n.logger.info("📃","atom",e.key,"copying");const c=e.toJson(r),u=e.fromJson(c);return t.valueMap.set(e.key,u),new Im(e,n),u}function fi(t,e,n,r){const o=t.valueMap.get(e);if(o instanceof Ap){const c=o;return n instanceof Promise?c:(t.valueMap.set(e,n),n)}if(n instanceof Promise){const c=new Ap(n);return t.valueMap.set(e,c),c.then(u=>{if(t.valueMap.get(e)===c){fi(t,e,u,r);const h=t.atoms.get(e);if(h)Ep(t,h),Op(t,h),Rp(t);else{const p=t.writableSelectors.get(e)??t.readonlySelectors.get(e);p&&(Ep(t,p),Ik(t,p),Rp(t))}r.next({newValue:u,oldValue:c})}}).catch(u=>{t.logger.error("💥","state",e,"rejected:",u)}),c}return t.valueMap.set(e,n),n}const xM=(t,e)=>{let n=e.valueMap.get(t.key);if(t.type==="mutable_atom"&&Yt(e)){const{parent:r}=e;n=kp(e,t,r)}return n},g1=(t,e)=>{const n=e.valueMap.get(t);if(n instanceof Ap){const r=n,o=e.writableSelectors.get(t)??e.readonlySelectors.get(t);o&&r.use(o.get());return}e.operation.open&&e.operation.prev.set(t,n),e.valueMap.delete(t),e.logger.info("🗑","state",t,"evicted")},wM=(t,e)=>pe(t).atomsThatAreDefault.has(e),b1=(t,e)=>{const n=pe(t);n.atomsThatAreDefault=new Set(n.atomsThatAreDefault).add(e)},TM=(t,e)=>{const n=pe(t);n.atomsThatAreDefault=new Set(pe(t).atomsThatAreDefault),n.atomsThatAreDefault.delete(e)};function Zu(t,e,n){const r="atom",{key:o,default:c}=e;t.logger.info("🔨","atom",o,`creating in store "${t.config.name}"`);const u=pe(t),d=u.atoms.get(o);if(d&&d.type===r)return t.logger.error("❌","atom",o,"Tried to create atom, but it already exists in the store."),Eo(d);const h=new tt,p={...e,type:r,install:v=>(v.logger.info("🛠️",r,o,`installing in store "${v.config.name}"`),Zu(v,e,n)),subject:h};n&&(p.family=n);let y=c;c instanceof Function&&(y=c()),u.atoms.set(o,p),b1(t,o),fi(u,o,y,h);const g=Eo(p);if(e.effects){let v=0;const S=[];for(const T of e.effects){const w=T({setSelf:D=>{Et(t,g,D)},onSet:D=>Ro(t,g,`effect[${v}]`,D)});w&&S.push(w),++v}p.cleanup=()=>{for(const T of S)T()}}return g}function AM(t,e){if("mutable"in e){const o=Hm(t,e,void 0);return t.on.atomCreation.next(o),o}const r=Zu(t,e,void 0);return t.on.atomCreation.next(r),r}function Fm(t,e){const n=pe(t),{key:r,family:o}=e,c=Tt(n,e);if(!o)t.logger.error("❌","atom",r,"Standalone atoms cannot be disposed.");else{c.cleanup?.();const u=t.valueMap.get(c.key),d=Tt(t,{key:o.key,type:"atom_family"}),h={type:"state_disposal",subType:"atom",token:e,value:u};d.subject.next(h);const p=Yt(n);if(n.atoms.delete(r),n.valueMap.delete(r),n.selectorAtoms.delete(r),n.atomsThatAreDefault.delete(r),t.timelineTopics.delete(r),e.type==="mutable_atom"){const y=y1(e);Fm(t,y),t.trackers.delete(r)}if(t.logger.info("🔥","atom",r,"deleted"),p&&n.transactionMeta.phase==="building"){const y=n.transactionMeta.update.updates.at(-1);y?.type==="molecule_disposal"&&y.values.some(([S])=>S===c.family?.key)||n.transactionMeta.update.updates.push(h)}else t.on.atomDisposal.next(e)}}var v1=class{toolkit;options;defaultContent;molecules=new Map;relations;states;core;transact(t,e){const n=this.toolkit;this.toolkit=t,e(this),this.toolkit=n}store;realm;[Symbol.dispose](){}constructor(t,e,n=yt.STORE){this.store=n,this.realm=new Nk(n),this.options=t,this.defaultContent=e,this.store.miscResources.set(`join:${t.key}`,this),this.realm.allocate("root",t.key),this.toolkit={get:(...C)=>zn(n,...C),set:(...C)=>{Et(n,...C)},find:(...C)=>Jt(n,...C),json:C=>ps(n,C)};const r=t.between[0],o=t.between[1],c=m1(n,{key:`${t.key}/relatedKeys`,default:()=>new Ao,mutable:!0,fromJson:C=>Ao.fromJSON(C),toJson:C=>C.toJSON()},["join","relations"]);this.core={relatedKeysAtoms:c};const u=({get:C},O)=>C(c,O),d=({set:C},O,X)=>{this.store.molecules.has(Ze(O))||this.realm.allocate(t.key,O),C(c,O,F=>F.add(X)),C(c,X,F=>F.add(O))},h=({set:C},O,X)=>{C(c,O,F=>(F.delete(X),F)),C(c,X,F=>(F.delete(O),F))},p=(C,O,X)=>{const{find:F,get:G,set:te}=C,oe=F(c,O),ue=G(oe);for(const me of ue)X.includes(me)||te(c,me,ce=>(ce.delete(O),ce));te(oe,me=>(me.transaction(be=>{be.clear();for(const ce of X){const Z=u(C,ce),B=Z.has(O);if(this.relations.cardinality==="1:n"){const P=[];for(const q of Z){if(q===O)continue;const W=u(C,q);W.delete(ce),W.size===0&&P.push(q)}!B&&Z.size>0&&Z.clear();for(const q of P){const W=[ce,q].sort(),A=`"${W[0]}:${W[1]}"`;this.molecules.delete(A)}}B||Z.add(O),be.add(ce)}return!0}),me))},y=(C,O,X)=>{const{set:F}=C;F(c,O,G=>(G.transaction(te=>{for(const oe of X)te.add(oe);return!0}),G));for(const G of X)F(c,G,te=>(te.add(O),te));return!0},g=(C,O,X)=>{const F=u(C,O);return X?F.has(X):F.size>0},v={getRelatedKeys:C=>u(this.toolkit,C),addRelation:(C,O)=>{this.store.moleculeJoins.set(C,t.key),this.store.moleculeJoins.set(O,t.key),d(this.toolkit,C,O)},deleteRelation:(C,O)=>{h(this.toolkit,C,O)},replaceRelationsSafely:(C,O)=>{p(this.toolkit,C,O)},replaceRelationsUnsafely:(C,O)=>{y(this.toolkit,C,O)},has:(C,O)=>g(this.toolkit,C,O)};let S,T;if(e){T=Bm(n,{key:`${t.key}/content`,default:e},["join","content"]);const C=({get:F},G)=>F(T,G),O=({set:F},G,te)=>{F(T,G,te)};S=Object.assign(v,{getContent:F=>C(this.toolkit,F),setContent:(F,G)=>{O(this.toolkit,F,G)},deleteContent:F=>{this.realm.deallocate(F)}})}else S=v;const w=new Qt(t,{externalStore:S,isAType:t.isAType,isBType:t.isBType,makeContentKey:(...C)=>{const[O,X]=C,F=C.sort(),G=`${F[0]}:${F[1]}`,te=n.molecules.get(Ze(O)),oe=n.molecules.get(Ze(X));return te||this.realm.allocate(t.key,O),oe||this.realm.allocate(t.key,X),this.realm.allocate(O,G,"all"),this.realm.claim(X,G),this.store.moleculeJoins.set(G,t.key),G}}),D=()=>lo(n,{key:`${t.key}/singleRelatedKey`,get:C=>({get:O})=>{const X=O(c,C);for(const F of X)return F;return null}},["join","keys"]),$=()=>lo(n,{key:`${t.key}/multipleRelatedKeys`,get:C=>({get:O})=>{const X=W0(c,n);return O(X,C).members}},["join","keys"]),_=()=>lo(n,{key:`${t.key}/singleRelatedEntry`,get:C=>({get:O})=>{const X=O(c,C);for(const F of X){let G=w.isAType?.(C)?C:void 0,te=G===void 0?C:void 0;G??=F,te??=F;const oe=w.makeContentKey(G,te),ue=O(T,oe);return[F,ue]}return null}},["join","entries"]),k=()=>lo(n,{key:`${t.key}/multipleRelatedEntries`,get:C=>({get:O})=>{const X=W0(c,n);return O(X,C).members.map(G=>{let te=w.isAType?.(C)?C:void 0,oe=te===void 0?C:void 0;te??=G,oe??=G;const ue=w.makeContentKey(te,oe),me=O(T,ue);return[G,me]})}},["join","entries"]);switch(t.cardinality){case"1:1":{const C=D(),O=`${r}KeyOf${ln(o)}`,X=`${o}KeyOf${ln(r)}`,F={[O]:C,[X]:C};let G;if(e){const te=_(),oe=`${r}EntryOf${ln(o)}`,ue=`${o}EntryOf${ln(r)}`,me={[oe]:te,[ue]:te};G=Object.assign(F,me)}else G=F;this.relations=w,this.states=G;break}case"1:n":{const C=D(),O=$(),X=`${r}KeyOf${ln(o)}`,F=`${o}KeysOf${ln(r)}`,G={[X]:C,[F]:O};let te;if(e){const oe=_(),ue=k(),me=`${r}EntryOf${ln(o)}`,be=`${o}EntriesOf${ln(r)}`,ce={[me]:oe,[be]:ue};te=Object.assign(G,ce)}else te=G;this.relations=w,this.states=te;break}case"n:n":{const C=$(),O=`${r}KeysOf${ln(o)}`,X=`${o}KeysOf${ln(r)}`,F={[O]:C,[X]:C};let G;if(e){const te=k(),oe=`${r}EntriesOf${ln(o)}`,ue=`${o}EntriesOf${ln(r)}`,me={[oe]:te,[ue]:te};G=Object.assign(F,me)}else G=F;this.relations=w,this.states=G}}}};function EM(t,e){let n=e.joins.get(t.key);if(n===void 0){const o=yt.STORE.joins.get(t.key);if(o===void 0)throw new Error(`Join "${t.key}" not found in store "${e.config.name}"`);n=new v1(o.options,o.defaultContent,e),e.joins.set(t.key,n)}return n}function RM(t,e){return EM(t,e).core.relatedKeysAtoms}function OM(t){return t.startsWith("🔍 ")}var Bh={exports:{}},xe={};/**
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-DikmBhXT.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CxZfwqZY.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-ki_mruCb.css">
10
10
  </head>
11
11
  <body>