valdres 1.0.0-beta.24 → 1.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-r1v0nt42.js +2 -0
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-r1v0nt42.js +2 -0
- package/dist/development/equality.js +1 -0
- package/dist/development/index.js +1 -1
- package/dist/equality.js +1 -0
- package/dist/index.js +1 -1
- package/dist/types/equality.d.ts +9 -0
- package/dist/types/v1-internal/committed-store-tree/scope-node.d.ts +1 -0
- package/dist/types/v1-internal/selector-evaluator/types.d.ts +6 -0
- package/package.json +10 -1
- package/dist/chunk-13jzc8rs.js +0 -2
- package/dist/development/chunk-13jzc8rs.js +0 -2
package/README.md
CHANGED
|
@@ -32,10 +32,25 @@ A store also exposes `sub`, `reset`, `txn`, `scope`, and `dispose`. Store operat
|
|
|
32
32
|
|
|
33
33
|
`atom(initial, options)` and `atom.lazy(initialize, options)` create writable state. `selector(read, options)` creates synchronous derived state. Atom and selector options accept an inert diagnostic `name` and an `equal(previous, next)` comparator.
|
|
34
34
|
|
|
35
|
+
## Opt-in structural equality
|
|
36
|
+
|
|
37
|
+
`Object.is` remains the default comparator. Import `deepEqual` from the separate equality entry only where structurally equal replacements should retain the previous reference and stop notifications or downstream propagation:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { atom } from "valdres"
|
|
41
|
+
import { deepEqual } from "valdres/equality"
|
|
42
|
+
|
|
43
|
+
const documentAtom = atom({ blocks: [] }, { equal: deepEqual })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`deepEqual` recursively compares supported values using SameValueZero primitive leaves, own enumerable string and symbol properties, and native identity for Map keys and Set members. Non-binary objects require the same prototype. Matching binary brands compare visible bytes across realms and ignore attached properties. Functions, Promises, Errors, URLs, weak collections, other opaque platform objects, and DOM nodes compare only by identity. Cyclic structures are unsupported. Reached getters, Proxy traps, `valueOf`, and `toString` hooks can run and throw.
|
|
47
|
+
|
|
48
|
+
Structural comparison walks the compared values, so use it deliberately on allocation-heavy results where pruning redundant updates outweighs that work. The separate `valdres/equality` entry keeps it out of ordinary root bundles.
|
|
49
|
+
|
|
35
50
|
The versioned `valdres/adapter-internals/v1` entry is for framework bindings. It exports only `assertStore`, `read`, `subscribe`, and `readHydrationSnapshot`; application code should use Store methods directly.
|
|
36
51
|
|
|
37
52
|
## Beta compatibility
|
|
38
53
|
|
|
39
|
-
`valdres@1.0.0-beta.24` intentionally
|
|
54
|
+
`valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.5` is certified with core versions accepted by its `^1.0.0-beta.24` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
|
|
40
55
|
|
|
41
56
|
<!-- DOCS:END -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"../chunk-
|
|
1
|
+
import{o as e}from"../chunk-r1v0nt42.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Me=Object.freeze({kind:"not-thenable"}),lt=()=>{},ut=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ye extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ae extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ie extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class Q extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class X extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class J extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class be extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ke extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class we extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class se extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var R=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},O=(e)=>{try{ut(e.then,e.target,[void 0,lt])}catch{}},Z=(e)=>{let t=R(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return O(t),Object.freeze({kind:"error",error:new X})},ve=(e)=>{try{return Z(e())}catch(t){let n=R(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return O(n),Object.freeze({kind:"error",error:new X})}},ee=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},P=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},te=(e,t,n)=>ee(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ee(e,Object.freeze({kind:"transaction",transaction:t}),n),ae=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},ge=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ce=(e,t,n)=>{if(!n)throw new ie;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ye;throw We(e,n).latchControlFault(r),r}}return"invalid"},D=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return P(e,r,()=>L(e,t,r))},ne=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),de=(e,t)=>Object.freeze(ne({kind:e},t));class z extends Error{seal(){Object.freeze(this)}}class le extends z{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Te extends z{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class oe extends z{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class F extends z{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Re extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ue extends z{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class Oe extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}class S{#t=[];#n;#o=0;#i;#s=ft;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var ft=Object.freeze({kind:"none"});var Ue=Object.freeze({kind:"not-thenable"}),ht=()=>{},St=Reflect.apply,qe=Symbol("selector dependency path root"),$e=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},Qe=(e)=>{try{St(e.then,e.target,[void 0,ht])}catch{}},pt=(e)=>Object.freeze(e),mt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=mt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?yt:Object.freeze(r.map((i)=>i.node))})},yt=Object.freeze([]),Ge=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ke=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},Ye=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},fe=(e,t,n)=>{let{node:o}=e,r=[],i=t.getSelectorRecord(o),s=i?.dependencies,a=s===void 0?new Set:void 0,c,d=0,l=t.getComparisonBaseline(o),f=!0,b=()=>{let u=a;if(u!==void 0)return u;u=new Set;for(let p of r)u.add(p.node);return a=u,u};n.enter(t,o,r);let m=t.getSelectorGraphVersion(),v=n.getSelectorGraphPublicationCount(t),E=m,G=v,Pe=m,ze=v,pe=(u,p,k,y)=>k-u===y-p,Fe=(u=t.getSelectorGraphVersion(),p=n.getSelectorGraphPublicationCount(t),k=pe(E,G,u,p))=>{if(k){E=u,G=p;return}for(let y=0;y<r.length;y++){let I=r[y],N=Ge(I.node,o,t,n);if(!N)continue;if(a!==void 0)for(let A=r.length-1;A>=y;A--)a.delete(r[A].node);if(r.length=y,d++,n.getControlFault().kind==="fault")return;let M=new oe(o,[o,...N]);n.latchCycle(t,o,M);return}E=u,G=p},me=()=>{let u=t.getSelectorGraphVersion(),p=n.getSelectorGraphPublicationCount(t);Pe=u,ze=p;let k=pe(E,G,u,p);if(!k)n.revalidateAncestorPrefixes(t,o);Fe(u,p,k)};n.setPrefixRevalidator(t,o,Fe);let dt=(u)=>{if(!f)throw new Oe;let p=n.getControlFault();if(p.kind==="fault")throw p.error;let k=n.getCycle(t,o);if(k!==void 0)throw k;let y=n.activeCyclePath(t,u);if(y){let h=new oe(o,y);throw n.latchCycle(t,o,h),h}let I=r.length,N,j=!1;if(a===void 0){let h=s?.[I];if(h!==void 0&&Object.is(h.node,u))N=!1,j=!0;else N=b().has(u)}else N=a.has(u);if(!N&&!j&&s!==void 0&&s.length>0){let h=s[r.length];if(h!==void 0&&Object.is(h.node,u))j=!0;else{if(c===void 0){c=new Set;for(let B of s)c.add(B.node)}j=c.has(u)}}let M=d,A=t.serve(u,n);me();let _=n.getCycle(t,o);if(_!==void 0)throw _;let K=a!==void 0?a.has(u):d===M&&r.length===I?!1:b().has(u),x=Pe,H=ze,V=K||j&&x===m,re=s===void 0&&pe(m,v,x,H);if(!V&&!re){let h=Ge(u,o,t,n);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Ie=new oe(o,[o,...h]);throw n.latchCycle(t,o,Ie),Ie}}if(!K){let h=i?.dependencies[r.length];a?.add(u),r.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(E=x,G=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Y=n.getControlFault();if(Y.kind==="fault")throw Y.error;if(A.outcome.kind==="error")throw new Te(u,A.outcome.error);return A.outcome.value};try{let u,p,k=!1;try{u=e.get(dt)}catch(_){k=!0,p=_}finally{f=!1}if(k)p=Ke(p,"getter");let y=k?void 0:Ye(u,"getter");me();let I=n.getControlFault();if(I.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:I.error},r);let N=n.getCycle(t,o);if(N!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:N},r);if(k)return g(o,t.createOutcomeToken(),{kind:"error",error:p instanceof F?p:new le(o,p)},r);if(y===void 0)throw Error("Selector result classification was not completed");let j=n.getControlFault();if(j.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:j.error},r);if(y.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:y.error instanceof F?y.error:new le(o,y.error)},r);let M=y.value,A;if(l){let _=e.equal??Object.is,K,x,H=!1;try{K=_(l.value,M)}catch(B){H=!0,x=Ke(B,"comparator")}let V=H?void 0:Ye(K,"comparator");me();let re=n.getControlFault();if(re.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:re.error},r);let Y=n.getCycle(t,o);if(Y!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:Y},r);if(H)return g(o,t.createOutcomeToken(),{kind:"error",error:x instanceof F?x:new ue(o,x)},r);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:h.error},r);if(V.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:V.error instanceof F?V.error:new ue(o,V.error)},r);if(V.value!==!0&&V.value!==!1)return g(o,t.createOutcomeToken(),{kind:"error",error:new Re},r);if(V.value===!0)M=l.value,A=l.current?l.token:void 0}return g(o,A??t.createOutcomeToken(),{kind:"value",value:M},r)}finally{n.leave(t,o)}};var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;constructor(e,t){this.#t=e,this.#s=t}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>fe(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#d(),this.#n=this.#d()}get status(){return this.#u}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#d()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=te(n,t,()=>fe(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??At,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#d(),this.#s.set(o.node,r);r.add(e)}return!0}#d(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#u;#f;#h;#d;#b;#m;#S;#p;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#l(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#l();i.set(this.#n,o);let s=this.#l();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#l();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#l(),s=this.#l();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#l();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#u!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#u;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#d?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#l(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#d;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#l();s.set(this.#a,r);let a=this.#l();a.set(t,n),s.set(e,a),this.#b=s,this.#d=void 0,this.#a=void 0}return}let i=this.#u;if(i===void 0){this.#a=e,this.#c=t,this.#u=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#l();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#d=a}else{let s=this.#l(),a=this.#l();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#l();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#u=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#m,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#m,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#m=e,this.#S=t;return}if(Object.is(this.#m,e)){this.#S=t;return}let o=this.#l();o.set(this.#m,this.#S),o.set(e,t),this.#p=o,this.#m=void 0,this.#S=void 0}forEachFallback(e){if(this.#m!==void 0&&this.#S!==void 0)e(this.#m,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#d?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#u=void 0,this.#f=void 0,this.#h=void 0,this.#d=void 0,this.#b=void 0,this.#m=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#l(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=R(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q},et=(e)=>{let t=R(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q};var bt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},kt=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31});var wt=new WeakMap;var T=(e)=>Object.freeze({kind:"value",value:e}),vt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):vt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,De=2,rt=4,gt=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Tt=(e)=>(e.onAllocation?.(),new Set),Ee=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Rt=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Tt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Ot=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class at{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#u=0;#f;#h;#d;#b=1;#m=0;#S;#p;#e;#y;constructor(e,t){this.#e=e,this.#y=t===void 0?void 0:wt.get(t),this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[kt[e]]+=t}#l(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=D(this.#e,o,n),i=ge(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":D(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#d;if(a===void 0){if(a=new Map,this.#d=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return bt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#d,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#d=void 0}set(e,t,n){this.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)D(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#E(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#E(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#$(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function")throw TypeError("StoreTree.txn requires a callback function");let n=this.#l(),o=Ne(this,n,e),r;try{r=Be(this.#e,n.transaction,()=>t(o))}catch(i){throw n.close(),n.release(),i}n.close();try{let i=new S;ae(this.#e,i,()=>Ve(r)),this.#I(n)}finally{n.release()}return r}readHydrationSnapshot(e,t){let n=new S,o=t,r=D(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#l(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#G(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=D(this.#e,o,r);if(ce(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#x(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#P(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")D(this.#e,n,i);ce(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return ae(this.#e,f,()=>et(l))}let d=new S;return ae(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#E(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ke;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new we;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ie;throw new se}throw new se}#A(e){if(e.status!=="live")throw new be}#Y(e,t,n,o){let r=D(this.#e,t,n);C(this.#e,o),this.#A(e),this.#j(t,r,o)}#T(e,t,n,o,r){let i=t,s=new S;this.#Y(e,i,s,n);let a=this.#l();try{if(o==="set")this.#x(a,e,i,r,s);else if(o==="update")this.#P(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#I(a)}finally{a.release()}}#$(e){let t=this.#d,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#d=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=D(this.#e,n,o);ce(this.#e,e.transaction,e.active),this.#A(t),this.#j(n,i,r)}#j(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#x(e,t,n,o,r){let i=P(this.#e,r,()=>Z(o));if(i.kind==="error")throw i.error;let s=this.#O(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#P(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#O(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#O(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#O(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(P(this.#e,n,()=>ve(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#w(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#X(r,t,n,o)?t:n}#X(e,t,n,o){return P(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=R(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw O(a),new J}let i=R(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw O(i),new J;if(r!==!0&&r!==!1)throw new J;return r})}#J(e,t,n){return P(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=R(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw O(s),new X}let r=Z(o);if(r.kind==="error")throw r.error;return r.value})}#I(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=gt(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#M(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#M(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#_(e,r),i!==void 0)for(let a of i)this.#_(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let c=this.#H(a);s||=c}if(this.#B(r),i!==void 0)for(let a of i)this.#B(a);this.#ie();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#N(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let m=this.#N(o,f,b);if(m!==void 0)if(a===void 0)a=m;else c=[m]}if(o.affected!==void 0)for(let[m,v]of o.affected){let E=this.#N(o,m,v);if(E===void 0)continue;if(a===void 0)a=E;else{if(c===void 0)c=[];c.push(E)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#re(a,c)}catch(a){throw this.#v(),a}}#M(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#Z(e,s,o);return i}#_(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#B({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#ne(e.parent,t.atom))}#N(e,t,n){let o=Ee(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#Z(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Rt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(nt(i,s))continue;Ot(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#L(e,t,n,o){let r=Ee(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=Ee(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#ee(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#ee(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#te(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#w(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#ne(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#te(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#oe(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#oe(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#w(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(P(this.#e,t,()=>ve(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#w(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#re(e,t){if(e===void 0){this.#v();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#u=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#V(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#u=0,this.#f=void 0}this.#se(n)}#ie(){this.#S=void 0,this.#p=void 0,this.#m=this.#d===void 0?0:this.#b++}#v(){this.#m=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#m,o=this.#d?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#se(e){let t=this.#S;if(t===void 0){if(this.#v(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let d of i)r(d);if(this.#v(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let m=d(),v=R(m);if(v.kind==="thenable")O(v);else if(v.kind==="inspection-error")f=!0,b=v.error}catch(m){f=!0,b=m;let v=R(m);if(v.kind==="thenable")O(v)}})}catch(m){f=!0,b=m}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Ae(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#r===void 0)return;this.#V(e,t)}#V(e,t){if((this.#W(e,t)&(rt|De))!==0)return;this.#g(e,t,De);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#V(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,De)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#u;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#u=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#u=(this.#u|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#U(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#Q(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t){this.get=(n)=>e.get(t,n),this.sub=(n,o)=>e.sub(t,n,o),this.set=(n,o)=>e.set(t,n,o),this.update=(n,o)=>e.update(t,n,o),this.reset=(n)=>e.reset(t,n),this.txn=(n)=>e.txn(t,n),this.scope=function(n){return e.scope(t,arguments.length,n)},this.dispose=()=>e.dispose(t),t.installFacade(this),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return e.equal===void 0?{}:{equal:e.equal}},ct=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=P(t,l,()=>Z(c));if(f.kind==="error")throw f.error;let b=de("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=de("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=de("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(D(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw ge(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:()=>{C(t,"createStoreTree");let c=new at(t,e);return new xe(c,c.rootScope)}})};var Kt=ct();
|
|
2
|
+
export{ye as a,Ae as b,W as c,U as d,q as e,ie as f,Q as g,X as h,J as i,be as j,ke as k,we as l,se as m,oe as n,Kt as o};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"../chunk-
|
|
1
|
+
import{o as e}from"../chunk-r1v0nt42.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Me=Object.freeze({kind:"not-thenable"}),lt=()=>{},ut=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ye extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ae extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ie extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class Q extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class X extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class J extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class be extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ke extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class we extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class se extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var R=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},O=(e)=>{try{ut(e.then,e.target,[void 0,lt])}catch{}},Z=(e)=>{let t=R(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return O(t),Object.freeze({kind:"error",error:new X})},ve=(e)=>{try{return Z(e())}catch(t){let n=R(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return O(n),Object.freeze({kind:"error",error:new X})}},ee=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},P=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},te=(e,t,n)=>ee(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ee(e,Object.freeze({kind:"transaction",transaction:t}),n),ae=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},ge=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ce=(e,t,n)=>{if(!n)throw new ie;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ye;throw We(e,n).latchControlFault(r),r}}return"invalid"},D=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return P(e,r,()=>L(e,t,r))},ne=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),de=(e,t)=>Object.freeze(ne({kind:e},t));class z extends Error{seal(){Object.freeze(this)}}class le extends z{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Te extends z{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class oe extends z{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class F extends z{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Re extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ue extends z{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class Oe extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}class S{#t=[];#n;#o=0;#i;#s=ft;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var ft=Object.freeze({kind:"none"});var Ue=Object.freeze({kind:"not-thenable"}),ht=()=>{},St=Reflect.apply,qe=Symbol("selector dependency path root"),$e=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},Qe=(e)=>{try{St(e.then,e.target,[void 0,ht])}catch{}},pt=(e)=>Object.freeze(e),mt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=mt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?yt:Object.freeze(r.map((i)=>i.node))})},yt=Object.freeze([]),Ge=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ke=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},Ye=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},fe=(e,t,n)=>{let{node:o}=e,r=[],i=t.getSelectorRecord(o),s=i?.dependencies,a=s===void 0?new Set:void 0,c,d=0,l=t.getComparisonBaseline(o),f=!0,b=()=>{let u=a;if(u!==void 0)return u;u=new Set;for(let p of r)u.add(p.node);return a=u,u};n.enter(t,o,r);let m=t.getSelectorGraphVersion(),v=n.getSelectorGraphPublicationCount(t),E=m,G=v,Pe=m,ze=v,pe=(u,p,k,y)=>k-u===y-p,Fe=(u=t.getSelectorGraphVersion(),p=n.getSelectorGraphPublicationCount(t),k=pe(E,G,u,p))=>{if(k){E=u,G=p;return}for(let y=0;y<r.length;y++){let I=r[y],N=Ge(I.node,o,t,n);if(!N)continue;if(a!==void 0)for(let A=r.length-1;A>=y;A--)a.delete(r[A].node);if(r.length=y,d++,n.getControlFault().kind==="fault")return;let M=new oe(o,[o,...N]);n.latchCycle(t,o,M);return}E=u,G=p},me=()=>{let u=t.getSelectorGraphVersion(),p=n.getSelectorGraphPublicationCount(t);Pe=u,ze=p;let k=pe(E,G,u,p);if(!k)n.revalidateAncestorPrefixes(t,o);Fe(u,p,k)};n.setPrefixRevalidator(t,o,Fe);let dt=(u)=>{if(!f)throw new Oe;let p=n.getControlFault();if(p.kind==="fault")throw p.error;let k=n.getCycle(t,o);if(k!==void 0)throw k;let y=n.activeCyclePath(t,u);if(y){let h=new oe(o,y);throw n.latchCycle(t,o,h),h}let I=r.length,N,j=!1;if(a===void 0){let h=s?.[I];if(h!==void 0&&Object.is(h.node,u))N=!1,j=!0;else N=b().has(u)}else N=a.has(u);if(!N&&!j&&s!==void 0&&s.length>0){let h=s[r.length];if(h!==void 0&&Object.is(h.node,u))j=!0;else{if(c===void 0){c=new Set;for(let B of s)c.add(B.node)}j=c.has(u)}}let M=d,A=t.serve(u,n);me();let _=n.getCycle(t,o);if(_!==void 0)throw _;let K=a!==void 0?a.has(u):d===M&&r.length===I?!1:b().has(u),x=Pe,H=ze,V=K||j&&x===m,re=s===void 0&&pe(m,v,x,H);if(!V&&!re){let h=Ge(u,o,t,n);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Ie=new oe(o,[o,...h]);throw n.latchCycle(t,o,Ie),Ie}}if(!K){let h=i?.dependencies[r.length];a?.add(u),r.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(E=x,G=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Y=n.getControlFault();if(Y.kind==="fault")throw Y.error;if(A.outcome.kind==="error")throw new Te(u,A.outcome.error);return A.outcome.value};try{let u,p,k=!1;try{u=e.get(dt)}catch(_){k=!0,p=_}finally{f=!1}if(k)p=Ke(p,"getter");let y=k?void 0:Ye(u,"getter");me();let I=n.getControlFault();if(I.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:I.error},r);let N=n.getCycle(t,o);if(N!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:N},r);if(k)return g(o,t.createOutcomeToken(),{kind:"error",error:p instanceof F?p:new le(o,p)},r);if(y===void 0)throw Error("Selector result classification was not completed");let j=n.getControlFault();if(j.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:j.error},r);if(y.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:y.error instanceof F?y.error:new le(o,y.error)},r);let M=y.value,A;if(l){let _=e.equal??Object.is,K,x,H=!1;try{K=_(l.value,M)}catch(B){H=!0,x=Ke(B,"comparator")}let V=H?void 0:Ye(K,"comparator");me();let re=n.getControlFault();if(re.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:re.error},r);let Y=n.getCycle(t,o);if(Y!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:Y},r);if(H)return g(o,t.createOutcomeToken(),{kind:"error",error:x instanceof F?x:new ue(o,x)},r);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:h.error},r);if(V.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:V.error instanceof F?V.error:new ue(o,V.error)},r);if(V.value!==!0&&V.value!==!1)return g(o,t.createOutcomeToken(),{kind:"error",error:new Re},r);if(V.value===!0)M=l.value,A=l.current?l.token:void 0}return g(o,A??t.createOutcomeToken(),{kind:"value",value:M},r)}finally{n.leave(t,o)}};var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;constructor(e,t){this.#t=e,this.#s=t}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>fe(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#d(),this.#n=this.#d()}get status(){return this.#u}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#d()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=te(n,t,()=>fe(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??At,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#d(),this.#s.set(o.node,r);r.add(e)}return!0}#d(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#u;#f;#h;#d;#b;#m;#S;#p;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#l(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#l();i.set(this.#n,o);let s=this.#l();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#l();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#l(),s=this.#l();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#l();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#u!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#u;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#d?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#l(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#d;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#l();s.set(this.#a,r);let a=this.#l();a.set(t,n),s.set(e,a),this.#b=s,this.#d=void 0,this.#a=void 0}return}let i=this.#u;if(i===void 0){this.#a=e,this.#c=t,this.#u=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#l();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#d=a}else{let s=this.#l(),a=this.#l();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#l();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#u=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#m,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#m,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#m=e,this.#S=t;return}if(Object.is(this.#m,e)){this.#S=t;return}let o=this.#l();o.set(this.#m,this.#S),o.set(e,t),this.#p=o,this.#m=void 0,this.#S=void 0}forEachFallback(e){if(this.#m!==void 0&&this.#S!==void 0)e(this.#m,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#d?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#u=void 0,this.#f=void 0,this.#h=void 0,this.#d=void 0,this.#b=void 0,this.#m=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#l(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=R(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q},et=(e)=>{let t=R(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q};var bt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},kt=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31});var wt=new WeakMap;var T=(e)=>Object.freeze({kind:"value",value:e}),vt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):vt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,De=2,rt=4,gt=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Tt=(e)=>(e.onAllocation?.(),new Set),Ee=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Rt=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Tt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Ot=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class at{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#u=0;#f;#h;#d;#b=1;#m=0;#S;#p;#e;#y;constructor(e,t){this.#e=e,this.#y=t===void 0?void 0:wt.get(t),this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[kt[e]]+=t}#l(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=D(this.#e,o,n),i=ge(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":D(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#d;if(a===void 0){if(a=new Map,this.#d=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return bt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#d,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#d=void 0}set(e,t,n){this.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)D(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#E(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#E(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#$(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function")throw TypeError("StoreTree.txn requires a callback function");let n=this.#l(),o=Ne(this,n,e),r;try{r=Be(this.#e,n.transaction,()=>t(o))}catch(i){throw n.close(),n.release(),i}n.close();try{let i=new S;ae(this.#e,i,()=>Ve(r)),this.#I(n)}finally{n.release()}return r}readHydrationSnapshot(e,t){let n=new S,o=t,r=D(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#l(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#G(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=D(this.#e,o,r);if(ce(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#x(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#P(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")D(this.#e,n,i);ce(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return ae(this.#e,f,()=>et(l))}let d=new S;return ae(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#E(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ke;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new we;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ie;throw new se}throw new se}#A(e){if(e.status!=="live")throw new be}#Y(e,t,n,o){let r=D(this.#e,t,n);C(this.#e,o),this.#A(e),this.#j(t,r,o)}#T(e,t,n,o,r){let i=t,s=new S;this.#Y(e,i,s,n);let a=this.#l();try{if(o==="set")this.#x(a,e,i,r,s);else if(o==="update")this.#P(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#I(a)}finally{a.release()}}#$(e){let t=this.#d,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#d=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=D(this.#e,n,o);ce(this.#e,e.transaction,e.active),this.#A(t),this.#j(n,i,r)}#j(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#x(e,t,n,o,r){let i=P(this.#e,r,()=>Z(o));if(i.kind==="error")throw i.error;let s=this.#O(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#P(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#O(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#O(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#O(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(P(this.#e,n,()=>ve(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#w(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#X(r,t,n,o)?t:n}#X(e,t,n,o){return P(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=R(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw O(a),new J}let i=R(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw O(i),new J;if(r!==!0&&r!==!1)throw new J;return r})}#J(e,t,n){return P(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=R(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw O(s),new X}let r=Z(o);if(r.kind==="error")throw r.error;return r.value})}#I(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=gt(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#M(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#M(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#_(e,r),i!==void 0)for(let a of i)this.#_(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let c=this.#H(a);s||=c}if(this.#B(r),i!==void 0)for(let a of i)this.#B(a);this.#ie();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#N(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let m=this.#N(o,f,b);if(m!==void 0)if(a===void 0)a=m;else c=[m]}if(o.affected!==void 0)for(let[m,v]of o.affected){let E=this.#N(o,m,v);if(E===void 0)continue;if(a===void 0)a=E;else{if(c===void 0)c=[];c.push(E)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#re(a,c)}catch(a){throw this.#v(),a}}#M(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#Z(e,s,o);return i}#_(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#B({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#ne(e.parent,t.atom))}#N(e,t,n){let o=Ee(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#Z(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Rt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(nt(i,s))continue;Ot(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#L(e,t,n,o){let r=Ee(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=Ee(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#ee(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#ee(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#te(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#w(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#ne(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#te(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#oe(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#oe(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#w(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(P(this.#e,t,()=>ve(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#w(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#re(e,t){if(e===void 0){this.#v();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#u=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#V(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#u=0,this.#f=void 0}this.#se(n)}#ie(){this.#S=void 0,this.#p=void 0,this.#m=this.#d===void 0?0:this.#b++}#v(){this.#m=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#m,o=this.#d?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#se(e){let t=this.#S;if(t===void 0){if(this.#v(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let d of i)r(d);if(this.#v(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let m=d(),v=R(m);if(v.kind==="thenable")O(v);else if(v.kind==="inspection-error")f=!0,b=v.error}catch(m){f=!0,b=m;let v=R(m);if(v.kind==="thenable")O(v)}})}catch(m){f=!0,b=m}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Ae(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#r===void 0)return;this.#V(e,t)}#V(e,t){if((this.#W(e,t)&(rt|De))!==0)return;this.#g(e,t,De);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#V(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,De)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#u;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#u=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#u=(this.#u|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#U(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#Q(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t){this.get=(n)=>e.get(t,n),this.sub=(n,o)=>e.sub(t,n,o),this.set=(n,o)=>e.set(t,n,o),this.update=(n,o)=>e.update(t,n,o),this.reset=(n)=>e.reset(t,n),this.txn=(n)=>e.txn(t,n),this.scope=function(n){return e.scope(t,arguments.length,n)},this.dispose=()=>e.dispose(t),t.installFacade(this),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return e.equal===void 0?{}:{equal:e.equal}},ct=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=P(t,l,()=>Z(c));if(f.kind==="error")throw f.error;let b=de("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=de("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=de("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(D(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw ge(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:()=>{C(t,"createStoreTree");let c=new at(t,e);return new xe(c,c.rootScope)}})};var Kt=ct();
|
|
2
|
+
export{ye as a,Ae as b,W as c,U as d,q as e,ie as f,Q as g,X as h,J as i,be as j,ke as k,we as l,se as m,oe as n,Kt as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var P=typeof Map==="function",V=typeof Set==="function",W=typeof ArrayBuffer==="function"&&typeof ArrayBuffer.isView==="function",g=typeof SharedArrayBuffer==="function",D=typeof ArrayBuffer==="function"?ArrayBuffer.prototype:void 0,G=g?SharedArrayBuffer.prototype:void 0,c=(e,n)=>{if(e===void 0)return;return Object.getOwnPropertyDescriptor(e,n)?.get},R=c(D,"byteLength"),E=c(G,"byteLength"),Z=c(typeof DataView==="function"?DataView.prototype:void 0,"byteLength"),J=c(typeof Uint8Array==="function"?Object.getPrototypeOf(Uint8Array.prototype):void 0,Symbol.toStringTag),I=typeof Uint8Array==="function"?Object.getPrototypeOf(Uint8Array.prototype):void 0,Q=c(I,"buffer"),X=c(I,"byteOffset"),Y=c(I,"byteLength"),v=c(typeof DataView==="function"?DataView.prototype:void 0,"buffer"),j=c(typeof DataView==="function"?DataView.prototype:void 0,"byteOffset"),K=c(P?Map.prototype:void 0,"size"),ee=P?Map.prototype.keys:void 0,ne=P?Map.prototype.has:void 0,C=P?Map.prototype.get:void 0,M=c(V?Set.prototype:void 0,"size"),te=V?Set.prototype.values:void 0,re=V?Set.prototype.has:void 0,N=c(RegExp.prototype,"source"),oe=["hasIndices","global","ignoreCase","multiline","dotAll","unicode","unicodeSets","sticky"].map((e)=>c(RegExp.prototype,e)),T=Date.prototype.valueOf,fe=Number.prototype.valueOf,ae=String.prototype.valueOf,se=Boolean.prototype.valueOf,ue=typeof BigInt==="function"?BigInt.prototype.valueOf:void 0,ie=Symbol.prototype.valueOf,ye=Function.prototype.toString,F=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,B=(e,n)=>e===n||e!==e&&n!==n,ce=(e,n,t,f,o)=>{if(o===0)return!0;if(o>=64&&((n|f)&3)===0){let s=Math.floor(o/4),p=new Uint32Array(e,n,s),m=new Uint32Array(t,f,s);for(let k=s;k--!==0;)if(p[k]!==m[k])return!1;let i=s*4,b=o-i;if(b===0)return!0;n+=i,f+=i,o=b}let u=new Uint8Array(e,n,o),y=new Uint8Array(t,f,o);for(let s=o;s--!==0;)if(u[s]!==y[s])return!1;return!0},H=(e,n,t,f,o)=>{let u=0;for(let s=t.length;s--!==0;){let p=t[s];if(!h.call(e,p))continue;if(u++,!h.call(n,p))return!1;if(!w(e[p],n[p],o))return!1}let y=0;for(let s=f.length;s--!==0;)if(h.call(n,f[s]))y++;return u===y},S=(e,n,t)=>{let f=Object.keys(e);if(f.length!==Object.keys(n).length)return!1;for(let o=f.length;o--!==0;){let u=f[o];if(!F.call(n,u))return!1;if(!w(e[u],n[u],t))return!1}return H(e,n,Object.getOwnPropertySymbols(e),Object.getOwnPropertySymbols(n),t)},z=(e,n)=>{let t=Reflect.ownKeys(e);return t.length===n+1&&t[n]==="length"},d=(e,n)=>e.call(n),U=(e,n)=>e.call(n),pe=(e,n)=>{let t=Object.getPrototypeOf(e);while(t!==null){if(typeof Object.getOwnPropertyDescriptor(t,n)?.get==="function")return!0;t=Object.getPrototypeOf(t)}return!1},q=(e,n)=>{if(!W)return;if(ArrayBuffer.isView(e)){let t=J?.call(e);if(typeof t==="string")return{brand:t,buffer:U(Q,e),byteOffset:d(X,e),byteLength:d(Y,e)};return{brand:"DataView",buffer:U(v,e),byteOffset:d(j,e),byteLength:d(Z,e)}}if(e instanceof ArrayBuffer)return{brand:"ArrayBuffer",buffer:e,byteOffset:0,byteLength:d(R,e)};if(g&&e instanceof SharedArrayBuffer)return{brand:"SharedArrayBuffer",buffer:e,byteOffset:0,byteLength:d(E,e)};if(!n)return;if(!pe(e,"byteLength"))return;try{return{brand:"ArrayBuffer",buffer:e,byteOffset:0,byteLength:d(R,e)}}catch{}if(g)try{return{brand:"SharedArrayBuffer",buffer:e,byteOffset:0,byteLength:d(E,e)}}catch{return}return},_=(e)=>{if(typeof Node<"u"&&e instanceof Node)return!0;return typeof e.nodeType==="number"&&typeof e.nodeName==="string"&&typeof e.cloneNode==="function"&&"ownerDocument"in e},O=(e)=>{let n=Object.getPrototypeOf(e);if(n===null||n===Object.prototype)return!0;while(n!==null&&n!==Object.prototype){let t=Object.getOwnPropertyDescriptor(n,"constructor")?.value;if(typeof t==="function"&&/\{\s*\[native code\]\s*\}/.test(ye.call(t)))return!1;n=Object.getPrototypeOf(n)}return!0},w=(e,n,t)=>{if(B(e,n))return!0;if(e===null||n===null||typeof e!=="object"||typeof n!=="object")return!1;let f=e,o=n,u=Object.getPrototypeOf(f),y=Object.getPrototypeOf(o),s=u===y,p=q(f,!s||u!==null&&u!==Object.prototype&&u!==D&&(!g||u!==G)),m=q(o,!s||y!==null&&y!==Object.prototype&&y!==D&&(!g||y!==G));if(!s&&(p===void 0||m===void 0||p.brand!==m.brand))return!1;let i=t??{leftAncestors:[],rightAncestors:[]};if(i.leftAncestors.includes(f)||i.rightAncestors.includes(o))return!1;i.leftAncestors.push(f),i.rightAncestors.push(o);try{return le(f,o,i,p,m)}finally{i.leftAncestors.pop(),i.rightAncestors.pop()}},le=(e,n,t,f,o)=>{if(Array.isArray(e)){if(!Array.isArray(n))return!1;let r=e.length;if(r!==n.length)return!1;for(let a=r;a--!==0;)if(!w(e[a],n[a],t))return!1;if(!z(e,r)||!z(n,r))return S(e,n,t);return!0}if(P&&(e instanceof Map||n instanceof Map)){if(!(e instanceof Map)||!(n instanceof Map))return!1;let r,a;try{r=K.call(e),a=K.call(n)}catch{return!1}if(r!==a)return!1;for(let l of ee.call(e)){if(!ne.call(n,l))return!1;if(!w(C.call(e,l),C.call(n,l),t))return!1}return S(e,n,t)}if(V&&(e instanceof Set||n instanceof Set)){if(!(e instanceof Set)||!(n instanceof Set))return!1;let r,a;try{r=M.call(e),a=M.call(n)}catch{return!1}if(r!==a)return!1;for(let l of te.call(e))if(!re.call(n,l))return!1;return S(e,n,t)}if(f!==void 0||o!==void 0){if(f===void 0||o===void 0||f.brand!==o.brand||f.byteLength!==o.byteLength)return!1;return ce(f.buffer,f.byteOffset,o.buffer,o.byteOffset,f.byteLength)}if(e instanceof RegExp||n instanceof RegExp){if(!(e instanceof RegExp)||!(n instanceof RegExp))return!1;try{if(N.call(e)!==N.call(n))return!1;for(let r of oe)if(r!==void 0&&r.call(e)!==r.call(n))return!1}catch{return!1}return S(e,n,t)}if(e instanceof Date||n instanceof Date){if(!(e instanceof Date)||!(n instanceof Date))return!1;try{if(!B(T.call(e),T.call(n)))return!1}catch{return!1}return S(e,n,t)}let u=e instanceof Number||n instanceof Number?fe:e instanceof String||n instanceof String?ae:e instanceof Boolean||n instanceof Boolean?se:typeof BigInt==="function"&&(e instanceof BigInt||n instanceof BigInt)?ue:e instanceof Symbol||n instanceof Symbol?ie:void 0;if(u!==void 0){try{if(!B(u.call(e),u.call(n)))return!1}catch{return!1}return S(e,n,t)}let y=Object.getPrototypeOf(e),s=Object.getPrototypeOf(n),p=y===null||y===Object.prototype,m=s===null||s===Object.prototype;if(!p&&(_(e)||!O(e))||!m&&(_(n)||!O(n)))return!1;let i=e.valueOf,b=n.valueOf;if(typeof i==="function"&&i!==Object.prototype.valueOf||typeof b==="function"&&b!==Object.prototype.valueOf){if(typeof i!=="function"||typeof b!=="function")return!1;let r=i.call(e),a=b.call(n),l=r===null||typeof r!=="object"&&typeof r!=="function";if(l!==(a===null||typeof a!=="object"&&typeof a!=="function"))return!1;if(l&&!B(r,a))return!1}else{let r=e.toString,a=n.toString;if(typeof r==="function"&&r!==Object.prototype.toString||typeof a==="function"&&a!==Object.prototype.toString){if(typeof r!=="function"||typeof a!=="function"||r.call(e)!==a.call(n))return!1}}let A=Object.keys(e);if(A.length!==Object.keys(n).length)return!1;for(let r=A.length;r--!==0;)if(!F.call(n,A[r]))return!1;for(let r=A.length;r--!==0;){let a=A[r];if((a==="_owner"||a==="__v"||a==="__o")&&e.$$typeof)continue;if(!w(e[a],n[a],t))return!1}let L=Object.getOwnPropertySymbols(e),x=Object.getOwnPropertySymbols(n);if(L.length!==0||x.length!==0)return H(e,n,L,x,t);return!0},me=(e,n)=>w(e,n);export{me as deepEqual};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as a,c as n,d as l,e as p,f as c,g as i,h as s,i as u,j as y,k as v,l as E,m,n as S,o as t}from"./chunk-
|
|
1
|
+
import{a as o,b as a,c as n,d as l,e as p,f as c,g as i,h as s,i as u,j as y,k as v,l as E,m,n as S,o as t}from"./chunk-r1v0nt42.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=n,g=u,D=s,O=i,M=m,N=o,q=v,P=l,z=S,w=y,U=E,G=a,j=c,L=p;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
|
package/dist/equality.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var P=typeof Map==="function",V=typeof Set==="function",W=typeof ArrayBuffer==="function"&&typeof ArrayBuffer.isView==="function",g=typeof SharedArrayBuffer==="function",D=typeof ArrayBuffer==="function"?ArrayBuffer.prototype:void 0,G=g?SharedArrayBuffer.prototype:void 0,c=(e,n)=>{if(e===void 0)return;return Object.getOwnPropertyDescriptor(e,n)?.get},R=c(D,"byteLength"),E=c(G,"byteLength"),Z=c(typeof DataView==="function"?DataView.prototype:void 0,"byteLength"),J=c(typeof Uint8Array==="function"?Object.getPrototypeOf(Uint8Array.prototype):void 0,Symbol.toStringTag),I=typeof Uint8Array==="function"?Object.getPrototypeOf(Uint8Array.prototype):void 0,Q=c(I,"buffer"),X=c(I,"byteOffset"),Y=c(I,"byteLength"),v=c(typeof DataView==="function"?DataView.prototype:void 0,"buffer"),j=c(typeof DataView==="function"?DataView.prototype:void 0,"byteOffset"),K=c(P?Map.prototype:void 0,"size"),ee=P?Map.prototype.keys:void 0,ne=P?Map.prototype.has:void 0,C=P?Map.prototype.get:void 0,M=c(V?Set.prototype:void 0,"size"),te=V?Set.prototype.values:void 0,re=V?Set.prototype.has:void 0,N=c(RegExp.prototype,"source"),oe=["hasIndices","global","ignoreCase","multiline","dotAll","unicode","unicodeSets","sticky"].map((e)=>c(RegExp.prototype,e)),T=Date.prototype.valueOf,fe=Number.prototype.valueOf,ae=String.prototype.valueOf,se=Boolean.prototype.valueOf,ue=typeof BigInt==="function"?BigInt.prototype.valueOf:void 0,ie=Symbol.prototype.valueOf,ye=Function.prototype.toString,F=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,B=(e,n)=>e===n||e!==e&&n!==n,ce=(e,n,t,f,o)=>{if(o===0)return!0;if(o>=64&&((n|f)&3)===0){let s=Math.floor(o/4),p=new Uint32Array(e,n,s),m=new Uint32Array(t,f,s);for(let k=s;k--!==0;)if(p[k]!==m[k])return!1;let i=s*4,b=o-i;if(b===0)return!0;n+=i,f+=i,o=b}let u=new Uint8Array(e,n,o),y=new Uint8Array(t,f,o);for(let s=o;s--!==0;)if(u[s]!==y[s])return!1;return!0},H=(e,n,t,f,o)=>{let u=0;for(let s=t.length;s--!==0;){let p=t[s];if(!h.call(e,p))continue;if(u++,!h.call(n,p))return!1;if(!w(e[p],n[p],o))return!1}let y=0;for(let s=f.length;s--!==0;)if(h.call(n,f[s]))y++;return u===y},S=(e,n,t)=>{let f=Object.keys(e);if(f.length!==Object.keys(n).length)return!1;for(let o=f.length;o--!==0;){let u=f[o];if(!F.call(n,u))return!1;if(!w(e[u],n[u],t))return!1}return H(e,n,Object.getOwnPropertySymbols(e),Object.getOwnPropertySymbols(n),t)},z=(e,n)=>{let t=Reflect.ownKeys(e);return t.length===n+1&&t[n]==="length"},d=(e,n)=>e.call(n),U=(e,n)=>e.call(n),pe=(e,n)=>{let t=Object.getPrototypeOf(e);while(t!==null){if(typeof Object.getOwnPropertyDescriptor(t,n)?.get==="function")return!0;t=Object.getPrototypeOf(t)}return!1},q=(e,n)=>{if(!W)return;if(ArrayBuffer.isView(e)){let t=J?.call(e);if(typeof t==="string")return{brand:t,buffer:U(Q,e),byteOffset:d(X,e),byteLength:d(Y,e)};return{brand:"DataView",buffer:U(v,e),byteOffset:d(j,e),byteLength:d(Z,e)}}if(e instanceof ArrayBuffer)return{brand:"ArrayBuffer",buffer:e,byteOffset:0,byteLength:d(R,e)};if(g&&e instanceof SharedArrayBuffer)return{brand:"SharedArrayBuffer",buffer:e,byteOffset:0,byteLength:d(E,e)};if(!n)return;if(!pe(e,"byteLength"))return;try{return{brand:"ArrayBuffer",buffer:e,byteOffset:0,byteLength:d(R,e)}}catch{}if(g)try{return{brand:"SharedArrayBuffer",buffer:e,byteOffset:0,byteLength:d(E,e)}}catch{return}return},_=(e)=>{if(typeof Node<"u"&&e instanceof Node)return!0;return typeof e.nodeType==="number"&&typeof e.nodeName==="string"&&typeof e.cloneNode==="function"&&"ownerDocument"in e},O=(e)=>{let n=Object.getPrototypeOf(e);if(n===null||n===Object.prototype)return!0;while(n!==null&&n!==Object.prototype){let t=Object.getOwnPropertyDescriptor(n,"constructor")?.value;if(typeof t==="function"&&/\{\s*\[native code\]\s*\}/.test(ye.call(t)))return!1;n=Object.getPrototypeOf(n)}return!0},w=(e,n,t)=>{if(B(e,n))return!0;if(e===null||n===null||typeof e!=="object"||typeof n!=="object")return!1;let f=e,o=n,u=Object.getPrototypeOf(f),y=Object.getPrototypeOf(o),s=u===y,p=q(f,!s||u!==null&&u!==Object.prototype&&u!==D&&(!g||u!==G)),m=q(o,!s||y!==null&&y!==Object.prototype&&y!==D&&(!g||y!==G));if(!s&&(p===void 0||m===void 0||p.brand!==m.brand))return!1;let i=t??{leftAncestors:[],rightAncestors:[]};if(i.leftAncestors.includes(f)||i.rightAncestors.includes(o))return!1;i.leftAncestors.push(f),i.rightAncestors.push(o);try{return le(f,o,i,p,m)}finally{i.leftAncestors.pop(),i.rightAncestors.pop()}},le=(e,n,t,f,o)=>{if(Array.isArray(e)){if(!Array.isArray(n))return!1;let r=e.length;if(r!==n.length)return!1;for(let a=r;a--!==0;)if(!w(e[a],n[a],t))return!1;if(!z(e,r)||!z(n,r))return S(e,n,t);return!0}if(P&&(e instanceof Map||n instanceof Map)){if(!(e instanceof Map)||!(n instanceof Map))return!1;let r,a;try{r=K.call(e),a=K.call(n)}catch{return!1}if(r!==a)return!1;for(let l of ee.call(e)){if(!ne.call(n,l))return!1;if(!w(C.call(e,l),C.call(n,l),t))return!1}return S(e,n,t)}if(V&&(e instanceof Set||n instanceof Set)){if(!(e instanceof Set)||!(n instanceof Set))return!1;let r,a;try{r=M.call(e),a=M.call(n)}catch{return!1}if(r!==a)return!1;for(let l of te.call(e))if(!re.call(n,l))return!1;return S(e,n,t)}if(f!==void 0||o!==void 0){if(f===void 0||o===void 0||f.brand!==o.brand||f.byteLength!==o.byteLength)return!1;return ce(f.buffer,f.byteOffset,o.buffer,o.byteOffset,f.byteLength)}if(e instanceof RegExp||n instanceof RegExp){if(!(e instanceof RegExp)||!(n instanceof RegExp))return!1;try{if(N.call(e)!==N.call(n))return!1;for(let r of oe)if(r!==void 0&&r.call(e)!==r.call(n))return!1}catch{return!1}return S(e,n,t)}if(e instanceof Date||n instanceof Date){if(!(e instanceof Date)||!(n instanceof Date))return!1;try{if(!B(T.call(e),T.call(n)))return!1}catch{return!1}return S(e,n,t)}let u=e instanceof Number||n instanceof Number?fe:e instanceof String||n instanceof String?ae:e instanceof Boolean||n instanceof Boolean?se:typeof BigInt==="function"&&(e instanceof BigInt||n instanceof BigInt)?ue:e instanceof Symbol||n instanceof Symbol?ie:void 0;if(u!==void 0){try{if(!B(u.call(e),u.call(n)))return!1}catch{return!1}return S(e,n,t)}let y=Object.getPrototypeOf(e),s=Object.getPrototypeOf(n),p=y===null||y===Object.prototype,m=s===null||s===Object.prototype;if(!p&&(_(e)||!O(e))||!m&&(_(n)||!O(n)))return!1;let i=e.valueOf,b=n.valueOf;if(typeof i==="function"&&i!==Object.prototype.valueOf||typeof b==="function"&&b!==Object.prototype.valueOf){if(typeof i!=="function"||typeof b!=="function")return!1;let r=i.call(e),a=b.call(n),l=r===null||typeof r!=="object"&&typeof r!=="function";if(l!==(a===null||typeof a!=="object"&&typeof a!=="function"))return!1;if(l&&!B(r,a))return!1}else{let r=e.toString,a=n.toString;if(typeof r==="function"&&r!==Object.prototype.toString||typeof a==="function"&&a!==Object.prototype.toString){if(typeof r!=="function"||typeof a!=="function"||r.call(e)!==a.call(n))return!1}}let A=Object.keys(e);if(A.length!==Object.keys(n).length)return!1;for(let r=A.length;r--!==0;)if(!F.call(n,A[r]))return!1;for(let r=A.length;r--!==0;){let a=A[r];if((a==="_owner"||a==="__v"||a==="__o")&&e.$$typeof)continue;if(!w(e[a],n[a],t))return!1}let L=Object.getOwnPropertySymbols(e),x=Object.getOwnPropertySymbols(n);if(L.length!==0||x.length!==0)return H(e,n,L,x,t);return!0},me=(e,n)=>w(e,n);export{me as deepEqual};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as a,c as n,d as l,e as p,f as c,g as i,h as s,i as u,j as y,k as v,l as E,m,n as S,o as t}from"./chunk-
|
|
1
|
+
import{a as o,b as a,c as n,d as l,e as p,f as c,g as i,h as s,i as u,j as y,k as v,l as E,m,n as S,o as t}from"./chunk-r1v0nt42.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=n,g=u,D=s,O=i,M=m,N=o,q=v,P=l,z=S,w=y,U=E,G=a,j=c,L=p;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares supported values recursively. Primitive leaves use SameValueZero,
|
|
3
|
+
* object properties are limited to own enumerable string and symbol keys, and
|
|
4
|
+
* Map keys plus Set members retain their native identity semantics.
|
|
5
|
+
*
|
|
6
|
+
* Circular structures are unsupported. Getters, Proxy traps, `valueOf`, and
|
|
7
|
+
* `toString` hooks reached during comparison may run and may throw.
|
|
8
|
+
*/
|
|
9
|
+
export declare const deepEqual: (left: unknown, right: unknown) => boolean;
|
|
@@ -83,6 +83,7 @@ export declare class StoreScopeNode implements SelectorEvaluationHost<AnyState,
|
|
|
83
83
|
serve(node: AnyState, session: SelectorEvaluationSession<AnyState>): ServedSelectorOutcome<OutcomeToken>;
|
|
84
84
|
serveKnownLocal(node: AnyState, session: SelectorEvaluationSession<AnyState>): ServedSelectorOutcome<OutcomeToken>;
|
|
85
85
|
getSelectorRecord(node: AnyState): SelectorRecordView<AnyState, OutcomeToken> | undefined;
|
|
86
|
+
getSelectorDependencyNodes(node: AnyState): readonly AnySelector[] | undefined;
|
|
86
87
|
getSelectorGraphVersion(): number;
|
|
87
88
|
getComparisonBaseline(node: AnyState): SelectorComparisonBaseline<OutcomeToken> | undefined;
|
|
88
89
|
createOutcomeToken(): OutcomeToken;
|
|
@@ -62,6 +62,12 @@ export interface SelectorEvaluationHost<Node, Token extends object> {
|
|
|
62
62
|
* may point to that absent node.
|
|
63
63
|
*/
|
|
64
64
|
getSelectorRecord(node: Node): SelectorRecordView<Node, Token> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Optional selector-only adjacency lookup used exclusively by closure
|
|
67
|
+
* proofs. When implemented, `undefined` identifies a terminal node rather
|
|
68
|
+
* than requesting fallback to `getSelectorRecord`.
|
|
69
|
+
*/
|
|
70
|
+
getSelectorDependencyNodes?(node: Node): readonly Node[] | undefined;
|
|
65
71
|
/**
|
|
66
72
|
* Monotonic version advanced for every selector-graph publication or
|
|
67
73
|
* interleavable record removal/clear.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valdres",
|
|
3
3
|
"description": "Fast atom-based state management for JavaScript. Inspired by Recoil and Jotai.",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Eigil Sagafos"
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./equality": {
|
|
24
|
+
"types": "./dist/types/equality.d.ts",
|
|
25
|
+
"development": "./dist/development/equality.js",
|
|
26
|
+
"import": "./dist/equality.js",
|
|
27
|
+
"default": "./dist/equality.js"
|
|
28
|
+
},
|
|
23
29
|
"./adapter-internals/v1": {
|
|
24
30
|
"types": "./dist/types/adapter-internals/v1.d.ts",
|
|
25
31
|
"development": "./dist/development/adapter-internals/v1.js",
|
|
@@ -39,6 +45,9 @@
|
|
|
39
45
|
"types": "./dist/types/index.d.ts",
|
|
40
46
|
"typesVersions": {
|
|
41
47
|
"*": {
|
|
48
|
+
"equality": [
|
|
49
|
+
"dist/types/equality.d.ts"
|
|
50
|
+
],
|
|
42
51
|
"adapter-internals/v1": [
|
|
43
52
|
"dist/types/adapter-internals/v1.d.ts"
|
|
44
53
|
]
|
package/dist/chunk-13jzc8rs.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var Me=Object.freeze({kind:"not-thenable"}),lt=()=>{},ut=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ye extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ae extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ie extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class Q extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class X extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class J extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class be extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ke extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class we extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class se extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var R=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},O=(e)=>{try{ut(e.then,e.target,[void 0,lt])}catch{}},Z=(e)=>{let t=R(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return O(t),Object.freeze({kind:"error",error:new X})},ve=(e)=>{try{return Z(e())}catch(t){let n=R(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return O(n),Object.freeze({kind:"error",error:new X})}},ee=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},P=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},te=(e,t,n)=>ee(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ee(e,Object.freeze({kind:"transaction",transaction:t}),n),ae=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},ge=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ce=(e,t,n)=>{if(!n)throw new ie;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ye;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return P(e,r,()=>L(e,t,r))},ne=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),de=(e,t)=>Object.freeze(ne({kind:e},t));class z extends Error{seal(){Object.freeze(this)}}class le extends z{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Te extends z{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class oe extends z{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class F extends z{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Re extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ue extends z{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class Oe extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}class S{#t=[];#n;#o=0;#r;#s=ft;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#r??(this.#r=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#r?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#a(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#a(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#i(e,t);o.cycleError??=n}getCycle(e,t){return this.#a(e,t).cycleError}#a(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#i(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var ft=Object.freeze({kind:"none"});var Ue=Object.freeze({kind:"not-thenable"}),ht=()=>{},St=Reflect.apply,qe=Symbol("selector dependency path root"),$e=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},Qe=(e)=>{try{St(e.then,e.target,[void 0,ht])}catch{}},mt=(e)=>Object.freeze(e),pt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=pt(o);return Object.freeze({selector:e,token:t,outcome:mt(n),dependencies:r,attemptedPrefix:n.kind==="value"?yt:Object.freeze(r.map((i)=>i.node))})},yt=Object.freeze([]),Ge=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ke=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},Ye=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},fe=(e,t,n)=>{let{node:o}=e,r=[],i=t.getSelectorRecord(o),s=i?.dependencies,a=s===void 0?new Set:void 0,c,d=0,l=t.getComparisonBaseline(o),f=!0,b=()=>{let u=a;if(u!==void 0)return u;u=new Set;for(let m of r)u.add(m.node);return a=u,u};n.enter(t,o,r);let p=t.getSelectorGraphVersion(),v=n.getSelectorGraphPublicationCount(t),D=p,G=v,Pe=p,ze=v,me=(u,m,k,y)=>k-u===y-m,Fe=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),k=me(D,G,u,m))=>{if(k){D=u,G=m;return}for(let y=0;y<r.length;y++){let I=r[y],V=Ge(I.node,o,t,n);if(!V)continue;if(a!==void 0)for(let A=r.length-1;A>=y;A--)a.delete(r[A].node);if(r.length=y,d++,n.getControlFault().kind==="fault")return;let M=new oe(o,[o,...V]);n.latchCycle(t,o,M);return}D=u,G=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,ze=m;let k=me(D,G,u,m);if(!k)n.revalidateAncestorPrefixes(t,o);Fe(u,m,k)};n.setPrefixRevalidator(t,o,Fe);let dt=(u)=>{if(!f)throw new Oe;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let k=n.getCycle(t,o);if(k!==void 0)throw k;let y=n.activeCyclePath(t,u);if(y){let h=new oe(o,y);throw n.latchCycle(t,o,h),h}let I=r.length,V,j=!1;if(a===void 0){let h=s?.[I];if(h!==void 0&&Object.is(h.node,u))V=!1,j=!0;else V=b().has(u)}else V=a.has(u);if(!V&&!j&&s!==void 0&&s.length>0){let h=s[r.length];if(h!==void 0&&Object.is(h.node,u))j=!0;else{if(c===void 0){c=new Set;for(let B of s)c.add(B.node)}j=c.has(u)}}let M=d,A=t.serve(u,n);pe();let _=n.getCycle(t,o);if(_!==void 0)throw _;let K=a!==void 0?a.has(u):d===M&&r.length===I?!1:b().has(u),x=Pe,H=ze,N=K||j&&x===p,re=s===void 0&&me(p,v,x,H);if(!N&&!re){let h=Ge(u,o,t,n);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Ie=new oe(o,[o,...h]);throw n.latchCycle(t,o,Ie),Ie}}if(!K){let h=i?.dependencies[r.length];a?.add(u),r.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(D=x,G=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Y=n.getControlFault();if(Y.kind==="fault")throw Y.error;if(A.outcome.kind==="error")throw new Te(u,A.outcome.error);return A.outcome.value};try{let u,m,k=!1;try{u=e.get(dt)}catch(_){k=!0,m=_}finally{f=!1}if(k)m=Ke(m,"getter");let y=k?void 0:Ye(u,"getter");pe();let I=n.getControlFault();if(I.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:I.error},r);let V=n.getCycle(t,o);if(V!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:V},r);if(k)return g(o,t.createOutcomeToken(),{kind:"error",error:m instanceof F?m:new le(o,m)},r);if(y===void 0)throw Error("Selector result classification was not completed");let j=n.getControlFault();if(j.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:j.error},r);if(y.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:y.error instanceof F?y.error:new le(o,y.error)},r);let M=y.value,A;if(l){let _=e.equal??Object.is,K,x,H=!1;try{K=_(l.value,M)}catch(B){H=!0,x=Ke(B,"comparator")}let N=H?void 0:Ye(K,"comparator");pe();let re=n.getControlFault();if(re.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:re.error},r);let Y=n.getCycle(t,o);if(Y!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:Y},r);if(H)return g(o,t.createOutcomeToken(),{kind:"error",error:x instanceof F?x:new ue(o,x)},r);if(N===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:h.error},r);if(N.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:N.error instanceof F?N.error:new ue(o,N.error)},r);if(N.value!==!0&&N.value!==!1)return g(o,t.createOutcomeToken(),{kind:"error",error:new Re},r);if(N.value===!0)M=l.value,A=l.current?l.token:void 0}return g(o,A??t.createOutcomeToken(),{kind:"value",value:M},r)}finally{n.leave(t,o)}};var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#r=new Map;#s;#a=1;#i=0;constructor(e,t){this.#t=e,this.#s=t}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#r.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>fe(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#i++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#i}getComparisonBaseline(e){let t=this.#r.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??Xe,this.#r.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#a++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#r=new WeakMap;#s=new WeakSet;#a=0;#i;#c="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#c}get facade(){if(this.#i===void 0)throw Error("Store scope facade is not installed");return this.#i}installFacade(e){if(this.#i!==void 0)throw Error("Store scope facade is already installed");this.#i=e}markDisposing(){if(this.#c==="live")this.#c="disposing"}markDisposed(){this.#c="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#s.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#s.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#r.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#s.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#r=new WeakMap,this.#s=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#s.has(r))return i.served;let s=te(n,t,()=>fe(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#u(e,o?.dependencies??At,t.dependencies),this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#s.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#u(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return}for(let o of t){let r=this.#r.get(o.node);if(r?.delete(e),r?.isEmpty())this.#r.delete(o.node)}for(let o of n){let r=this.#r.get(o.node);if(r===void 0)r=this.#l(),this.#r.set(o.node,r);r.add(e)}}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#r;#s;#a;#i;#c;#f;#u;#l;#h;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#r!==void 0||this.#s!==void 0||this.#a!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#r===void 0?this.#o:void 0}stage(e,t){let n=this.#a;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#d(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#d();i.set(this.#n,o);let s=this.#d();s.set(t.atom,t),i.set(e,s),this.#a=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#r;if(i===void 0){this.#r=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#r=t,this.#y();return}let s=this.#d();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#d(),s=this.#d();if(s.set(r.atom,r),this.#r!==void 0)s.set(this.#r.atom,this.#r);i.set(this.#n,s);let a=this.#d();a.set(t.atom,t),i.set(e,a),this.#a=i,this.#n=void 0}this.#o=void 0,this.#r=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#r!==void 0)e(this.#n,this.#r);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#a;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#r;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#a?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#f!==void 0&&Object.is(this.#i,e)&&Object.is(this.#c,t))return this.#f;if(this.#l!==void 0&&Object.is(this.#i,e)&&Object.is(this.#u,t))return this.#l;if(Object.is(this.#i,e))return this.#h?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#d(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#h;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#d();s.set(this.#i,r);let a=this.#d();a.set(t,n),s.set(e,a),this.#b=s,this.#h=void 0,this.#i=void 0}return}let i=this.#f;if(i===void 0){this.#i=e,this.#c=t,this.#f=n;return}if(Object.is(this.#i,e)&&Object.is(this.#c,t))return;if(Object.is(this.#i,e)){let s=this.#l;if(s===void 0){this.#u=t,this.#l=n;return}if(Object.is(this.#u,t))return;let a=this.#d();a.set(this.#c,i),a.set(this.#u,s),a.set(t,n),this.#h=a}else{let s=this.#d(),a=this.#d();if(a.set(this.#c,i),this.#u!==void 0&&this.#l!==void 0)a.set(this.#u,this.#l);s.set(this.#i,a);let c=this.#d();c.set(t,n),s.set(e,c),this.#b=s,this.#i=void 0}this.#c=void 0,this.#f=void 0,this.#u=void 0,this.#l=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#d();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#a!==void 0){for(let e of this.#a.values())e.clear();this.#a.clear()}if(this.#h?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#r=void 0,this.#s=void 0,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#f=void 0,this.#u=void 0,this.#l=void 0,this.#h=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#d(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ve=(e,t,n)=>new Ze(e,t,n),Ne=(e)=>{let t=R(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q},et=(e)=>{let t=R(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q};var bt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},kt=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31});var wt=new WeakMap;var T=(e)=>Object.freeze({kind:"value",value:e}),vt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):vt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,gt=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Tt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Rt=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Tt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Ot=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class at{#t=new WeakMap;#n;#o=1;#r=0;#s=!1;#a;#i;#c;#f=0;#u;#l;#h;#b=1;#p=0;#S;#m;#e;#y;constructor(e,t){this.#e=e,this.#y=t===void 0?void 0:wt.get(t),this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[kt[e]]+=t}#d(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=ge(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#h;if(a===void 0){if(a=new Map,this.#h=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return bt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#h,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#h=void 0}set(e,t,n){this.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#D(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#D(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#$(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function")throw TypeError("StoreTree.txn requires a callback function");let n=this.#d(),o=Ve(this,n,e),r;try{r=Be(this.#e,n.transaction,()=>t(o))}catch(i){throw n.close(),n.release(),i}n.close();try{let i=new S;ae(this.#e,i,()=>Ne(r)),this.#I(n)}finally{n.release()}return r}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#d(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#G(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ce(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#x(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#P(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ce(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ve(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return ae(this.#e,f,()=>et(l))}let d=new S;return ae(this.#e,d,()=>Ne(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#E(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#E(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#E(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#D(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ke;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new we;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ie;throw new se}throw new se}#A(e){if(e.status!=="live")throw new be}#Y(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#j(t,r,o)}#T(e,t,n,o,r){let i=t,s=new S;this.#Y(e,i,s,n);let a=this.#d();try{if(o==="set")this.#x(a,e,i,r,s);else if(o==="update")this.#P(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#I(a)}finally{a.release()}}#$(e){let t=this.#h,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#h=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ce(this.#e,e.transaction,e.active),this.#A(t),this.#j(n,i,r)}#j(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#x(e,t,n,o,r){let i=P(this.#e,r,()=>Z(o));if(i.kind==="error")throw i.error;let s=this.#O(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#P(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#O(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#O(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#O(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(P(this.#e,n,()=>ve(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#w(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#X(r,t,n,o)?t:n}#X(e,t,n,o){return P(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=R(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw O(a),new J}let i=R(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw O(i),new J;if(r!==!0&&r!==!1)throw new J;return r})}#J(e,t,n){return P(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=R(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw O(s),new X}let r=Z(o);if(r.kind==="error")throw r.error;return r.value})}#I(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=gt(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#M(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#M(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#_(e,r),i!==void 0)for(let a of i)this.#_(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let c=this.#H(a);s||=c}if(this.#B(r),i!==void 0)for(let a of i)this.#B(a);this.#ie();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let p=this.#V(o,f,b);if(p!==void 0)if(a===void 0)a=p;else c=[p]}if(o.affected!==void 0)for(let[p,v]of o.affected){let D=this.#V(o,p,v);if(D===void 0)continue;if(a===void 0)a=D;else{if(c===void 0)c=[];c.push(D)}}if(s)this.#r+=1,this.recordCounter("sourceEpoch");this.#re(a,c)}catch(a){throw this.#v(),a}}#M(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#Z(e,s,o);return i}#_(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#B({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#ne(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#Z(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Rt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(nt(i,s))continue;Ot(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#L(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#ee(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#ee(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#te(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#w(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#ne(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#te(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#oe(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#oe(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#w(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(P(this.#e,t,()=>ve(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#w(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#re(e,t){if(e===void 0){this.#v();return}this.recordCounter("propagationSettlements"),this.#a=[],this.#i=void 0,this.#c=void 0,this.#f=0,this.#u=void 0,this.#l=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#a.length){let r=this.#a[o++],i=this.#a[o++];this.#N(r,i)}}finally{n=this.#l,this.#l=void 0,this.#s=!1,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#f=0,this.#u=void 0}this.#se(n)}#ie(){this.#S=void 0,this.#m=void 0,this.#p=this.#h===void 0?0:this.#b++}#v(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#h?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#se(e){let t=this.#S;if(t===void 0){if(this.#v(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#v(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let p=d(),v=R(p);if(v.kind==="thenable")O(v);else if(v.kind==="inspection-error")f=!0,b=v.error}catch(p){f=!0,b=p;let v=R(p);if(v.kind==="thenable")O(v)}})}catch(p){f=!0,b=p}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Ae(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#a;if(n===void 0)return!1;if((this.#W(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#a===void 0)return;this.#N(e,t)}#N(e,t){if((this.#W(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#N(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#W(e,t){if(Object.is(this.#i,e)&&Object.is(this.#c,t))return this.#f;return this.#u?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#i===void 0){this.#i=e,this.#c=t,this.#f=n&~o;return}if(Object.is(this.#i,e)&&Object.is(this.#c,t)){this.#f=(this.#f|n)&~o;return}let r=this.#u;if(r===void 0)r=new Map,this.#u=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#l??=e}#U(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#Q(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t){this.get=(n)=>e.get(t,n),this.sub=(n,o)=>e.sub(t,n,o),this.set=(n,o)=>e.set(t,n,o),this.update=(n,o)=>e.update(t,n,o),this.reset=(n)=>e.reset(t,n),this.txn=(n)=>e.txn(t,n),this.scope=function(n){return e.scope(t,arguments.length,n)},this.dispose=()=>e.dispose(t),t.installFacade(this),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return e.equal===void 0?{}:{equal:e.equal}},ct=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=P(t,l,()=>Z(c));if(f.kind==="error")throw f.error;let b=de("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=de("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=de("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw ge(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:()=>{C(t,"createStoreTree");let c=new at(t,e);return new xe(c,c.rootScope)}})};var Kt=ct();
|
|
2
|
-
export{ye as a,Ae as b,W as c,U as d,q as e,ie as f,Q as g,X as h,J as i,be as j,ke as k,we as l,se as m,oe as n,Kt as o};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var Me=Object.freeze({kind:"not-thenable"}),lt=()=>{},ut=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ye extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ae extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ie extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class Q extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class X extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class J extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class be extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ke extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class we extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class se extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var R=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},O=(e)=>{try{ut(e.then,e.target,[void 0,lt])}catch{}},Z=(e)=>{let t=R(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return O(t),Object.freeze({kind:"error",error:new X})},ve=(e)=>{try{return Z(e())}catch(t){let n=R(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return O(n),Object.freeze({kind:"error",error:new X})}},ee=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},P=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},te=(e,t,n)=>ee(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ee(e,Object.freeze({kind:"transaction",transaction:t}),n),ae=(e,t,n)=>{try{let o=ee(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},ge=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ce=(e,t,n)=>{if(!n)throw new ie;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ye;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return P(e,r,()=>L(e,t,r))},ne=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),de=(e,t)=>Object.freeze(ne({kind:e},t));class z extends Error{seal(){Object.freeze(this)}}class le extends z{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Te extends z{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class oe extends z{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class F extends z{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Re extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ue extends z{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class Oe extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}class S{#t=[];#n;#o=0;#r;#s=ft;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#r??(this.#r=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#r?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#a(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#a(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#i(e,t);o.cycleError??=n}getCycle(e,t){return this.#a(e,t).cycleError}#a(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#i(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var ft=Object.freeze({kind:"none"});var Ue=Object.freeze({kind:"not-thenable"}),ht=()=>{},St=Reflect.apply,qe=Symbol("selector dependency path root"),$e=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},Qe=(e)=>{try{St(e.then,e.target,[void 0,ht])}catch{}},mt=(e)=>Object.freeze(e),pt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=pt(o);return Object.freeze({selector:e,token:t,outcome:mt(n),dependencies:r,attemptedPrefix:n.kind==="value"?yt:Object.freeze(r.map((i)=>i.node))})},yt=Object.freeze([]),Ge=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ke=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},Ye=(e,t)=>{let n=$e(e);if(n.kind==="thenable")return Qe(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},fe=(e,t,n)=>{let{node:o}=e,r=[],i=t.getSelectorRecord(o),s=i?.dependencies,a=s===void 0?new Set:void 0,c,d=0,l=t.getComparisonBaseline(o),f=!0,b=()=>{let u=a;if(u!==void 0)return u;u=new Set;for(let m of r)u.add(m.node);return a=u,u};n.enter(t,o,r);let p=t.getSelectorGraphVersion(),v=n.getSelectorGraphPublicationCount(t),D=p,G=v,Pe=p,ze=v,me=(u,m,k,y)=>k-u===y-m,Fe=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),k=me(D,G,u,m))=>{if(k){D=u,G=m;return}for(let y=0;y<r.length;y++){let I=r[y],V=Ge(I.node,o,t,n);if(!V)continue;if(a!==void 0)for(let A=r.length-1;A>=y;A--)a.delete(r[A].node);if(r.length=y,d++,n.getControlFault().kind==="fault")return;let M=new oe(o,[o,...V]);n.latchCycle(t,o,M);return}D=u,G=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,ze=m;let k=me(D,G,u,m);if(!k)n.revalidateAncestorPrefixes(t,o);Fe(u,m,k)};n.setPrefixRevalidator(t,o,Fe);let dt=(u)=>{if(!f)throw new Oe;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let k=n.getCycle(t,o);if(k!==void 0)throw k;let y=n.activeCyclePath(t,u);if(y){let h=new oe(o,y);throw n.latchCycle(t,o,h),h}let I=r.length,V,j=!1;if(a===void 0){let h=s?.[I];if(h!==void 0&&Object.is(h.node,u))V=!1,j=!0;else V=b().has(u)}else V=a.has(u);if(!V&&!j&&s!==void 0&&s.length>0){let h=s[r.length];if(h!==void 0&&Object.is(h.node,u))j=!0;else{if(c===void 0){c=new Set;for(let B of s)c.add(B.node)}j=c.has(u)}}let M=d,A=t.serve(u,n);pe();let _=n.getCycle(t,o);if(_!==void 0)throw _;let K=a!==void 0?a.has(u):d===M&&r.length===I?!1:b().has(u),x=Pe,H=ze,N=K||j&&x===p,re=s===void 0&&me(p,v,x,H);if(!N&&!re){let h=Ge(u,o,t,n);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Ie=new oe(o,[o,...h]);throw n.latchCycle(t,o,Ie),Ie}}if(!K){let h=i?.dependencies[r.length];a?.add(u),r.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(D=x,G=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Y=n.getControlFault();if(Y.kind==="fault")throw Y.error;if(A.outcome.kind==="error")throw new Te(u,A.outcome.error);return A.outcome.value};try{let u,m,k=!1;try{u=e.get(dt)}catch(_){k=!0,m=_}finally{f=!1}if(k)m=Ke(m,"getter");let y=k?void 0:Ye(u,"getter");pe();let I=n.getControlFault();if(I.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:I.error},r);let V=n.getCycle(t,o);if(V!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:V},r);if(k)return g(o,t.createOutcomeToken(),{kind:"error",error:m instanceof F?m:new le(o,m)},r);if(y===void 0)throw Error("Selector result classification was not completed");let j=n.getControlFault();if(j.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:j.error},r);if(y.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:y.error instanceof F?y.error:new le(o,y.error)},r);let M=y.value,A;if(l){let _=e.equal??Object.is,K,x,H=!1;try{K=_(l.value,M)}catch(B){H=!0,x=Ke(B,"comparator")}let N=H?void 0:Ye(K,"comparator");pe();let re=n.getControlFault();if(re.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:re.error},r);let Y=n.getCycle(t,o);if(Y!==void 0)return g(o,t.createOutcomeToken(),{kind:"error",error:Y},r);if(H)return g(o,t.createOutcomeToken(),{kind:"error",error:x instanceof F?x:new ue(o,x)},r);if(N===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(o,t.createOutcomeToken(),{kind:"control-error",error:h.error},r);if(N.kind==="error")return g(o,t.createOutcomeToken(),{kind:"error",error:N.error instanceof F?N.error:new ue(o,N.error)},r);if(N.value!==!0&&N.value!==!1)return g(o,t.createOutcomeToken(),{kind:"error",error:new Re},r);if(N.value===!0)M=l.value,A=l.current?l.token:void 0}return g(o,A??t.createOutcomeToken(),{kind:"value",value:M},r)}finally{n.leave(t,o)}};var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#r=new Map;#s;#a=1;#i=0;constructor(e,t){this.#t=e,this.#s=t}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#r.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>fe(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#i++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#i}getComparisonBaseline(e){let t=this.#r.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??Xe,this.#r.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#a++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#r=new WeakMap;#s=new WeakSet;#a=0;#i;#c="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#c}get facade(){if(this.#i===void 0)throw Error("Store scope facade is not installed");return this.#i}installFacade(e){if(this.#i!==void 0)throw Error("Store scope facade is already installed");this.#i=e}markDisposing(){if(this.#c==="live")this.#c="disposing"}markDisposed(){this.#c="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#s.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#s.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#r.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#s.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#r=new WeakMap,this.#s=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#s.has(r))return i.served;let s=te(n,t,()=>fe(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#u(e,o?.dependencies??At,t.dependencies),this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#s.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#u(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return}for(let o of t){let r=this.#r.get(o.node);if(r?.delete(e),r?.isEmpty())this.#r.delete(o.node)}for(let o of n){let r=this.#r.get(o.node);if(r===void 0)r=this.#l(),this.#r.set(o.node,r);r.add(e)}}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#r;#s;#a;#i;#c;#f;#u;#l;#h;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#r!==void 0||this.#s!==void 0||this.#a!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#r===void 0?this.#o:void 0}stage(e,t){let n=this.#a;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#d(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#d();i.set(this.#n,o);let s=this.#d();s.set(t.atom,t),i.set(e,s),this.#a=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#r;if(i===void 0){this.#r=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#r=t,this.#y();return}let s=this.#d();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#d(),s=this.#d();if(s.set(r.atom,r),this.#r!==void 0)s.set(this.#r.atom,this.#r);i.set(this.#n,s);let a=this.#d();a.set(t.atom,t),i.set(e,a),this.#a=i,this.#n=void 0}this.#o=void 0,this.#r=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#r!==void 0)e(this.#n,this.#r);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#a;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#r;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#a?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#f!==void 0&&Object.is(this.#i,e)&&Object.is(this.#c,t))return this.#f;if(this.#l!==void 0&&Object.is(this.#i,e)&&Object.is(this.#u,t))return this.#l;if(Object.is(this.#i,e))return this.#h?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#d(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#h;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#d();s.set(this.#i,r);let a=this.#d();a.set(t,n),s.set(e,a),this.#b=s,this.#h=void 0,this.#i=void 0}return}let i=this.#f;if(i===void 0){this.#i=e,this.#c=t,this.#f=n;return}if(Object.is(this.#i,e)&&Object.is(this.#c,t))return;if(Object.is(this.#i,e)){let s=this.#l;if(s===void 0){this.#u=t,this.#l=n;return}if(Object.is(this.#u,t))return;let a=this.#d();a.set(this.#c,i),a.set(this.#u,s),a.set(t,n),this.#h=a}else{let s=this.#d(),a=this.#d();if(a.set(this.#c,i),this.#u!==void 0&&this.#l!==void 0)a.set(this.#u,this.#l);s.set(this.#i,a);let c=this.#d();c.set(t,n),s.set(e,c),this.#b=s,this.#i=void 0}this.#c=void 0,this.#f=void 0,this.#u=void 0,this.#l=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#d();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#a!==void 0){for(let e of this.#a.values())e.clear();this.#a.clear()}if(this.#h?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#r=void 0,this.#s=void 0,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#f=void 0,this.#u=void 0,this.#l=void 0,this.#h=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#d(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ve=(e,t,n)=>new Ze(e,t,n),Ne=(e)=>{let t=R(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q},et=(e)=>{let t=R(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw O(t),new Q};var bt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},kt=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31});var wt=new WeakMap;var T=(e)=>Object.freeze({kind:"value",value:e}),vt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):vt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,gt=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Tt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Rt=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Tt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Ot=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class at{#t=new WeakMap;#n;#o=1;#r=0;#s=!1;#a;#i;#c;#f=0;#u;#l;#h;#b=1;#p=0;#S;#m;#e;#y;constructor(e,t){this.#e=e,this.#y=t===void 0?void 0:wt.get(t),this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[kt[e]]+=t}#d(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=ge(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#h;if(a===void 0){if(a=new Map,this.#h=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return bt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#h,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#h=void 0}set(e,t,n){this.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#D(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#D(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#$(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function")throw TypeError("StoreTree.txn requires a callback function");let n=this.#d(),o=Ve(this,n,e),r;try{r=Be(this.#e,n.transaction,()=>t(o))}catch(i){throw n.close(),n.release(),i}n.close();try{let i=new S;ae(this.#e,i,()=>Ne(r)),this.#I(n)}finally{n.release()}return r}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#d(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#G(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ce(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#x(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#P(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ce(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ve(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return ae(this.#e,f,()=>et(l))}let d=new S;return ae(this.#e,d,()=>Ne(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#E(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#E(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>te(this.#e,n,o)}),e.generation)}#E(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#D(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ke;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new we;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ie;throw new se}throw new se}#A(e){if(e.status!=="live")throw new be}#Y(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#j(t,r,o)}#T(e,t,n,o,r){let i=t,s=new S;this.#Y(e,i,s,n);let a=this.#d();try{if(o==="set")this.#x(a,e,i,r,s);else if(o==="update")this.#P(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#I(a)}finally{a.release()}}#$(e){let t=this.#h,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#h=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ce(this.#e,e.transaction,e.active),this.#A(t),this.#j(n,i,r)}#j(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#x(e,t,n,o,r){let i=P(this.#e,r,()=>Z(o));if(i.kind==="error")throw i.error;let s=this.#O(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#P(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#O(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#O(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#O(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(P(this.#e,n,()=>ve(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#w(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#X(r,t,n,o)?t:n}#X(e,t,n,o){return P(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=R(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw O(a),new J}let i=R(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw O(i),new J;if(r!==!0&&r!==!1)throw new J;return r})}#J(e,t,n){return P(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=R(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw O(s),new X}let r=Z(o);if(r.kind==="error")throw r.error;return r.value})}#I(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=gt(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#M(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#M(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#_(e,r),i!==void 0)for(let a of i)this.#_(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let c=this.#H(a);s||=c}if(this.#B(r),i!==void 0)for(let a of i)this.#B(a);this.#ie();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let p=this.#V(o,f,b);if(p!==void 0)if(a===void 0)a=p;else c=[p]}if(o.affected!==void 0)for(let[p,v]of o.affected){let D=this.#V(o,p,v);if(D===void 0)continue;if(a===void 0)a=D;else{if(c===void 0)c=[];c.push(D)}}if(s)this.#r+=1,this.recordCounter("sourceEpoch");this.#re(a,c)}catch(a){throw this.#v(),a}}#M(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#Z(e,s,o);return i}#_(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#B({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#ne(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#Z(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Rt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(nt(i,s))continue;Ot(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#L(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#ee(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#ee(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#te(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#w(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#ne(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#te(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#oe(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#oe(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#w(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(P(this.#e,t,()=>ve(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#w(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#re(e,t){if(e===void 0){this.#v();return}this.recordCounter("propagationSettlements"),this.#a=[],this.#i=void 0,this.#c=void 0,this.#f=0,this.#u=void 0,this.#l=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#a.length){let r=this.#a[o++],i=this.#a[o++];this.#N(r,i)}}finally{n=this.#l,this.#l=void 0,this.#s=!1,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#f=0,this.#u=void 0}this.#se(n)}#ie(){this.#S=void 0,this.#m=void 0,this.#p=this.#h===void 0?0:this.#b++}#v(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#h?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#se(e){let t=this.#S;if(t===void 0){if(this.#v(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#v(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let p=d(),v=R(p);if(v.kind==="thenable")O(v);else if(v.kind==="inspection-error")f=!0,b=v.error}catch(p){f=!0,b=p;let v=R(p);if(v.kind==="thenable")O(v)}})}catch(p){f=!0,b=p}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Ae(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#a;if(n===void 0)return!1;if((this.#W(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#a===void 0)return;this.#N(e,t)}#N(e,t){if((this.#W(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#N(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#W(e,t){if(Object.is(this.#i,e)&&Object.is(this.#c,t))return this.#f;return this.#u?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#i===void 0){this.#i=e,this.#c=t,this.#f=n&~o;return}if(Object.is(this.#i,e)&&Object.is(this.#c,t)){this.#f=(this.#f|n)&~o;return}let r=this.#u;if(r===void 0)r=new Map,this.#u=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#l??=e}#U(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#Q(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t){this.get=(n)=>e.get(t,n),this.sub=(n,o)=>e.sub(t,n,o),this.set=(n,o)=>e.set(t,n,o),this.update=(n,o)=>e.update(t,n,o),this.reset=(n)=>e.reset(t,n),this.txn=(n)=>e.txn(t,n),this.scope=function(n){return e.scope(t,arguments.length,n)},this.dispose=()=>e.dispose(t),t.installFacade(this),ne(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return e.equal===void 0?{}:{equal:e.equal}},ct=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=P(t,l,()=>Z(c));if(f.kind==="error")throw f.error;let b=de("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=de("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=de("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw ge(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:()=>{C(t,"createStoreTree");let c=new at(t,e);return new xe(c,c.rootScope)}})};var Kt=ct();
|
|
2
|
-
export{ye as a,Ae as b,W as c,U as d,q as e,ie as f,Q as g,X as h,J as i,be as j,ke as k,we as l,se as m,oe as n,Kt as o};
|