valdres 1.0.0-beta.44 → 1.0.0-beta.45
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 +3 -4
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-2shwp485.js +2 -0
- package/dist/chunk-3k27f6h5.js +2 -0
- package/dist/chunk-95d3w4ys.js +2 -0
- package/dist/chunk-dqh103kc.js +2 -0
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-2shwp485.js +2 -0
- package/dist/development/chunk-3k27f6h5.js +2 -0
- package/dist/development/chunk-95d3w4ys.js +2 -0
- package/dist/development/chunk-dqh103kc.js +2 -0
- package/dist/development/equality.js +1 -1
- package/dist/development/index.js +1 -1
- package/dist/development/inspect.js +1 -1
- package/dist/development/query.js +1 -1
- package/dist/equality.js +1 -1
- package/dist/index.js +1 -1
- package/dist/inspect.js +1 -1
- package/dist/query.js +1 -1
- package/dist/types/index.d.ts +5 -8
- package/dist/types/v1-internal/committed-store-tree/types.d.ts +1 -1
- package/package.json +1 -10
- package/dist/chunk-4wpe8fhf.js +0 -2
- package/dist/chunk-tywyt3b6.js +0 -2
- package/dist/chunk-yycx0cb8.js +0 -2
- package/dist/development/chunk-4wpe8fhf.js +0 -2
- package/dist/development/chunk-tywyt3b6.js +0 -2
- package/dist/development/chunk-yycx0cb8.js +0 -2
package/README.md
CHANGED
|
@@ -76,18 +76,17 @@ A family is only a callable identity cache. It has no membership or enumeration
|
|
|
76
76
|
|
|
77
77
|
## Opt-in structural equality
|
|
78
78
|
|
|
79
|
-
`Object.is` remains the default comparator.
|
|
79
|
+
`Object.is` remains the default comparator. Pass `deepEqual` only where structurally equal replacements should retain the previous reference and stop notifications or downstream propagation:
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
import { atom } from "valdres"
|
|
83
|
-
import { deepEqual } from "valdres/equality"
|
|
82
|
+
import { atom, deepEqual } from "valdres"
|
|
84
83
|
|
|
85
84
|
const documentAtom = atom({ blocks: [] }, { equal: deepEqual })
|
|
86
85
|
```
|
|
87
86
|
|
|
88
87
|
`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.
|
|
89
88
|
|
|
90
|
-
Structural comparison walks the compared values, so use it deliberately on allocation-heavy results where pruning redundant updates outweighs that work.
|
|
89
|
+
Structural comparison walks the compared values, so use it deliberately on allocation-heavy results where pruning redundant updates outweighs that work. Bundles that never import `deepEqual` drop it.
|
|
91
90
|
|
|
92
91
|
## Inspect a Store
|
|
93
92
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ze,o}from"../chunk-2shwp485.js";var t=ze(o),{assertStore:a,read:s,subscribe:i,readHydrationSnapshot:n}=t;export{a as assertStore,s as read,n as readHydrationSnapshot,i as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Y,Ie=0,dt,et=!1,Kt=1024,ct=Kt,lt,Wt=(r)=>{setTimeout(()=>{throw r},0)},Gt=(r)=>{let l=(u)=>Wt(AggregateError([r,u],"Commit callback and error reporter failed"));try{let u=globalThis.reportError;if(typeof u!=="function")return Wt(r);let f=u.call(globalThis,r);if(f!==null&&(typeof f==="object"||typeof f==="function"))Promise.prototype.then.call(Promise.resolve(f),void 0,l)}catch(u){l(u)}},Nn=()=>{if(et||Y===void 0)return;let r=()=>{if(dt!==r)return;dt=void 0,Ut()};dt=r,queueMicrotask(r)},qt=()=>{let r=lt??={};setTimeout(()=>{if(lt!==r||et)return;lt=void 0,ct=Kt,Ut()},0)},Ut=()=>{if(et||Y===void 0)return;if(dt=void 0,lt===void 0)qt();et=!0;try{while(Y!==void 0&&Ie<Y.length&&ct>0){let r=Y[Ie];if(Y[Ie++]=void 0,ct--,r===void 0||r.scope.status!=="live")continue;try{let l=r.callback,u=l();if(u!==null&&(typeof u==="object"||typeof u==="function"))Promise.prototype.then.call(Promise.resolve(u),void 0,Gt)}catch(l){Gt(l)}}}finally{if(et=!1,Y!==void 0&&Ie===Y.length)Y=void 0;else if(Y!==void 0)Y.splice(0,Ie);if(Ie=0,Y!==void 0&&ct===0)qt()}},ut=(r)=>{let l=r.commitEntries;if(l===void 0)return;if(r.commitEntries=void 0,Y===void 0)Y=l;else for(let u of l)Y.push(u);Nn()},Yt=()=>{if(Y===void 0)return;for(let r=Ie;r<Y.length;r++)if(Y[r]?.scope.status!=="live")Y[r]=void 0};class Oe extends Error{#t=!0;static is(r){return typeof r==="object"&&r!==null&&#t in r}seal(){Object.freeze(this)}}var We,Qt=()=>{if(We!==void 0)return We;We="";try{let r=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");if(r?.writable===!0){let u;Error.stackTraceLimit=0;try{u=Error()}finally{Error.stackTraceLimit=r.value}let f=Object.getOwnPropertyDescriptor(u,"stack");if(f!==void 0&&"get"in f)return We="accessor",We}let l=Object.getOwnPropertyDescriptor(globalThis,"Bun");if(l!==void 0&&"value"in l&&l.writable===!1&&l.configurable===!1&&typeof l.value==="object"&&l.value!==null)We="lazy"}catch{}return We},Dn={writable:!1,configurable:!1},Xt=(r,l)=>{if(Qt()!=="lazy"){Object.freeze(r);return}for(let u of["message","code","name",l,"cause"])Object.defineProperty(r,u,Dn);Object.preventExtensions(r)},ft=(r,l,u)=>{let f=Qt()==="accessor"&&Oe.is(u)?Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"):void 0;if(f?.writable!==!0)return;Error.stackTraceLimit=0;try{return new r(l,u)}finally{Error.stackTraceLimit=f.value}};class Ye extends Oe{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;name="SelectorGetterError";constructor(r,l){super("Selector getter failed");this.selector=r,this.cause=l,Xt(this,"selector")}}class ht extends Oe{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;name="SelectorDependencyError";constructor(r,l){super("Selector dependency failed");this.dependency=r,this.cause=l,Xt(this,"dependency")}}class p extends Oe{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(r,l){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=r,this.path=Object.freeze([...l]),this.seal()}}class xe extends Oe{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(r){super(`Selector ${r} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=r,this.seal()}}class Ct extends Oe{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class pt extends Oe{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(r,l){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=r,this.cause=l,this.seal()}}class Ot extends Oe{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var $t=Object.freeze({kind:"not-thenable"}),xn=()=>{},Pn=Reflect.apply,Zt=Symbol("selector dependency path root"),tn=(r)=>{if((typeof r!=="object"||r===null)&&typeof r!=="function")return $t;try{let l=r.then;return typeof l==="function"?Object.freeze({kind:"thenable",target:r,then:l}):$t}catch(l){return Object.freeze({kind:"inspection-error",error:l})}},nn=(r)=>{try{Pn(r.then,r.target,[void 0,xn])}catch{}},jn=(r)=>Object.freeze(r),Vn=(r)=>Object.freeze(r),ie=(r,l,u,f)=>{let A=Vn(f);return Object.freeze({selector:r,token:l,outcome:jn(u),dependencies:A,attemptedPrefix:u.kind==="value"?In:Object.freeze(A.map((g)=>g.node))})},In=Object.freeze([]),St=32,Qe=8192,Mn=2*St,on=128,Fn=4096;class rn{passiveSearches;searches=0;constructor(r,l){if(this.passiveSearches=r,l!==void 0)this.diagnostics=l}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let r=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(r)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(r&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Qe,2*this.first.size);return r}hasProvenNoPath(r){if(!this.enabled)return!1;let l=this.first;if(l!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(l.has(r))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}let u=this.second;if(u!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(u.has(r))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(r){if(!this.enabled)return!1;let l=this.first;if(l!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,l.has(r))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}let u=this.second;if(u!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,u.has(r))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(r){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let u=r.size>=St&&r.size<=Qe,f;if(this.searches===1&&u)this.first=r,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,f="initial";else if(this.searches===this.passiveSearches&&u)f=this.first===void 0?"initial":"activation-replacement",this.first=r,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(f);return}if((this.hits??0)!==0){if(r.size>Qe){this.disable("over-cap-hit");return}let u=this.first,f=this.second,A=this.firstIndependentlyClosed===!0,g=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(u,A),this.retain(f,g);let T=this.retain(r,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(T?"hit-derived":void 0);return}if(r.size===1){this.completeDiagnostics();return}let l=r.size>=St&&r.size<=Qe;if(this.first===void 0){if(l)this.first=r,this.firstIndependentlyClosed=!0;this.completeDiagnostics(l?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(r.size,St),this.locked!==!0&&this.second===void 0&&l){this.second=r,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Mn){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(r){if(!this.enabled||r===void 0)return this.reset(),!1;let l=this.firstIndependentlyClosed===!0?this.first:void 0,u=this.secondIndependentlyClosed===!0?this.second:void 0,f=l===void 0||u!==void 0&&u.size>l.size?u:l;if(f===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Qe,2*f.size);let A=0;for(let g of r){let T=this.hasWithinCrossVersionBudget(f,g.tail);if(T===void 0)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1;if(A++,!T)continue;let O=this.hasWithinCrossVersionBudget(f,g.head);if(O===void 0)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1;if(A++,!O)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(A),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=f,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(r,l=!1){if(r===void 0||r.size>Qe||r===this.first)return!1;if(this.first===void 0||r.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=r,this.firstIndependentlyClosed=l,!0;if(this.second===void 0||r.size>this.second.size)return this.second=r,this.secondIndependentlyClosed=l,!0;return!1}disable(r){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,r)}hasWithinCrossVersionBudget(r,l){let u=this.passiveProbeBudget;if(u===void 0||u===0)return;let f=r.has(l);return this.passiveProbeBudget=u-1,f}completeDiagnostics(r,l){let u=this.diagnostics;if(u===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let f=this.mapProbes??0;u.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",r,l,f,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var zn=(r,l)=>new rn(r,l),Ge=(r,l,u,f,A,g)=>{if(g!==void 0)g.nodeVisits=u,g.dependentProbes=on-l.remaining-u,g.liveDependents=f,g.maxFrontier=A;return r},Ce=(r,l,u,f,A,g=!0,T)=>{if(A!==void 0)A.nodeVisits=0,A.dependentProbes=0,A.liveDependents=0,A.maxFrontier=0;let O=u.visitSelectorDependents;if(O===void 0)return"unsupported";if(T===void 0&&!f.isSoleActiveSelector(u,l))return"ineligible-active-frames";if(!Object.is(r,l)){let I=T===void 0?void 0:f.getTransientDependencies(u,r);if(I!==void 0){if(I.length===0)return"proven-terminal"}else{let G=u.getSelectorDependencyNodes;if(G!==void 0){let K=G.call(u,r);if(K===void 0||K.length===0)return"proven-terminal"}}}if(!g)return"disabled";let N={remaining:on},D=[l],x=new Set(D),V=0,P=0,H=1;while(D.length>0){if(N.remaining===0)return Ge("budget-exhausted",N,V,P,H,A);N.remaining--,V++;let I=D.pop();if(Object.is(I,r))return Ge("path-possible",N,V,P,H,A);let G=!1,K=(ee)=>{if(P++,Object.is(ee,r))return G=!0,!1;if(!x.has(ee)){if(x.add(ee),D.push(ee),D.length>H)H=D.length}return!0},re=O.call(u,I,N,K);if(G)return Ge("path-possible",N,V,P,H,A);if(!re)return Ge("budget-exhausted",N,V,P,H,A);let ae=T?.get(I);if(ae!==void 0)for(let ee of ae){if(N.remaining===0)return Ge("budget-exhausted",N,V,P,H,A);if(N.remaining--,!K(ee))return Ge("path-possible",N,V,P,H,A)}}return Ge("proven-reverse",N,V,P,H,A)},_n=(r,l,u,f,A,g,T,O)=>{if(A===1||A===2){let P=Ce(r,l,u,f,void 0,A===1?T?.reverseProofEnabled??!0:O?.reverseProofEnabled??!0,O?.transientDependents);if(P==="proven-terminal"||P==="proven-reverse")return;if(P==="budget-exhausted"){if(A===1&&T!==void 0)T.reverseProofEnabled=!1;else if(O!==void 0)O.reverseProofEnabled=!1}}let N=T?.(),D=N?.beginSearch()??!1,x=[r],V=new Map([[r,Zt]]);while(x.length>0){let P=x.pop();if(Object.is(P,l)){let G=[],K=P;while(K!==Zt)G.push(K),K=V.get(K);return G.reverse(),N?.completePositive(),Object.freeze(G)}let H=f.getTransientDependencies(u,P);if(H){if(H.length===0)continue;if(D){let G=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(G)continue}for(let G of H){if(V.has(G.node))continue;V.set(G.node,P),x.push(G.node)}continue}if(u.getSelectorDependencyNodes!==void 0){let G=u.getSelectorDependencyNodes(P);if(G===void 0||G.length===0)continue;if(D){let K=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(K)continue}for(let K of G){if(V.has(K))continue;V.set(K,P),x.push(K)}continue}let I=u.getSelectorRecord(P);if(!I||I.dependencies.length===0)continue;if(D){let G=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(G)continue}for(let G of I.dependencies){if(V.has(G.node))continue;V.set(G.node,P),x.push(G.node)}}N?.completeNegative(V);return},Jt=(r,l)=>{let u=tn(r);if(u.kind==="thenable")return nn(u),new xe(l);if(u.kind==="inspection-error")return u.error;return r},en=(r,l)=>{let u=tn(r);if(u.kind==="thenable")return nn(u),Object.freeze({kind:"error",error:new xe(l)});if(u.kind==="inspection-error")return Object.freeze({kind:"error",error:u.error});return Object.freeze({kind:"value",value:r})},ye=(r,l,u,f=_n,A,g)=>{let{node:T}=r,O=[],N=l.getSelectorRecord(T),D=N?.dependencies,x=D===void 0?new Set:void 0,V,P=0,H=l.getComparisonBaseline(T),I=!0,G=()=>{let W=x;if(W!==void 0)return W;W=new Set;for(let q of O)W.add(q.node);return x=W,W};u.enter(l,T,O);let K=l.getSelectorGraphVersion(),re=u.getSelectorGraphPublicationCount(l),ae=K,ee=re,zt=K,_t=re,vt,gt=!1,kt=K,it=0,qe,Bt=K,st,wt=(W,q)=>{if(W===kt)return;if(kt=W,qe===void 0){it=0;return}if(qe.advanceGraphVersion(q))return;it=0,A?.graphVersionReset()},Cn=(W)=>{if(W!==kt)wt(W,void 0);if(it++,(D?.length??0)===0&&it<3){A?.admissionSkipped();return}if(qe===void 0){let q=D!==void 0&&D.length>0&&D.length<3;qe=zn(q?3:0,A)}if(!qe.enabled){A?.disabled();return}return qe},On=(W)=>{if(gt)return;let q=l.beginSelectorGraphObservation?.(W);if(q===void 0)return;gt=!0,vt=q},Rt=(W,q,te,Q)=>te-W===Q-q,Lt=(W=l.getSelectorGraphVersion(),q=u.getSelectorGraphPublicationCount(l),te=Rt(ae,ee,W,q))=>{if(W===ae)return;if(!gt&&l.beginSelectorGraphObservation!==void 0){wt(W,void 0),ae=W,ee=q;return}let Q=vt?.takeAddedEdges();if(wt(W,Q),te){ae=W,ee=q;return}if(Q!==void 0){let oe=Q.length===0||l.visitSelectorDependents===void 0?void 0:u.captureTransientReverseDependents(l,T,O.length,Fn,g),de=Q.length===0?void 0:{transientDependents:oe,reverseProofEnabled:!0},ne=!1;for(let ke of Q)if(f(ke.head,ke.tail,l,u,2,O.length,void 0,de)!==void 0){ne=!0;break}if(!ne){ae=W,ee=q;return}}for(let oe=0;oe<O.length;oe++){let de=O[oe],ne=f(de.node,T,l,u,0,O.length);if(!ne)continue;if(x!==void 0)for(let ue=O.length-1;ue>=oe;ue--)x.delete(O[ue].node);if(O.length=oe,P++,u.getControlFault().kind==="fault")return;let Z=new p(T,[T,...ne]);u.latchCycle(l,T,Z);return}ae=W,ee=q},Tt=()=>{let W=l.getSelectorGraphVersion(),q=u.getSelectorGraphPublicationCount(l);zt=W,_t=q;let te=Rt(ae,ee,W,q);if(!te)u.revalidateAncestorPrefixes(l,T);Lt(W,q,te)};u.setPrefixRevalidator(l,T,Lt);let En=(W)=>{if(!I)throw new Ot;let q=u.getControlFaultForSuppliedRead();if(q.kind==="fault")throw q.error;let te=u.getCycle(l,T);if(te!==void 0)throw te;let Q=u.activeCyclePath(l,W);if(Q){let U=new p(T,Q);throw u.latchCycle(l,T,U),U}let oe=O.length,de,ne=!1;if(x===void 0){let U=D?.[oe];if(U!==void 0&&Object.is(U.node,W))de=!1,ne=!0;else de=G().has(W)}else de=x.has(W);if(!de&&!ne&&D!==void 0&&D.length>0){let U=D[O.length];if(U!==void 0&&Object.is(U.node,W))ne=!0;else{if(V===void 0){V=new Set;for(let Ue of D)V.add(Ue.node)}ne=V.has(W)}}let ke=P,Z=l.serve(W,u);Tt();let ue=u.getCycle(l,T);if(ue!==void 0)throw ue;let Ze=x!==void 0?x.has(W):P===ke&&O.length===oe?!1:G().has(W),Te=zt,Ke=_t,fe=Ze||ne&&Te===K,at=D===void 0&&Rt(K,re,Te,Ke);if(!fe&&!at){if(Bt=Te,st===void 0)st=()=>Cn(Bt),st.reverseProofEnabled=!0;let U=f(W,T,l,u,1,O.length,st);if(U){let Ue=u.getControlFault();if(Ue.kind==="fault")throw Ue.error;let Ht=new p(T,[T,...U]);throw u.latchCycle(l,T,Ht),Ht}}if(!Ze){let U=N?.dependencies[O.length];x?.add(W),O.push(U!==void 0&&Object.is(U.node,W)&&Object.is(U.token,Z.token)?U:Object.freeze({node:W,token:Z.token})),On(W)}if(ae=Te,ee=Ke,Z.outcome.kind==="control-error"){u.latchControlFault(Z.outcome.error,Z.outcome.origin);let U=u.getControlFault();if(U.kind==="fault")throw U.error;throw Z.outcome.error}let Je=u.getControlFault();if(Je.kind==="fault")throw Je.error;if(Z.outcome.kind==="error")throw ft(ht,W,Z.outcome.error)??new ht(W,Z.outcome.error);return Z.outcome.value};try{let W,q,te=!1;try{W=r.get(En)}catch(ue){te=!0,q=ue}finally{I=!1}if(te)q=Jt(q,"getter");let Q=te?void 0:en(W,"getter");Tt();let oe=u.getControlFault();if(oe.kind==="fault")return ie(T,l.createOutcomeToken(),{...oe,kind:"control-error"},O);let de=u.getCycle(l,T);if(de!==void 0)return ie(T,l.createOutcomeToken(),{kind:"error",error:de},O);if(te)return ie(T,l.createOutcomeToken(),{kind:"error",error:q instanceof xe?q:ft(Ye,T,q)??new Ye(T,q)},O);if(Q===void 0)throw Error("Selector result classification was not completed");let ne=u.getControlFault();if(ne.kind==="fault")return ie(T,l.createOutcomeToken(),{...ne,kind:"control-error"},O);if(Q.kind==="error")return ie(T,l.createOutcomeToken(),{kind:"error",error:Q.error instanceof xe?Q.error:ft(Ye,T,Q.error)??new Ye(T,Q.error)},O);let ke=Q.value,Z;if(H){let ue=r.equal??Object.is,Ze,Te,Ke=!1;try{Ze=ue(H.value,ke)}catch(Ue){Ke=!0,Te=Jt(Ue,"comparator")}let fe=Ke?void 0:en(Ze,"comparator");Tt();let at=u.getControlFault();if(at.kind==="fault")return ie(T,l.createOutcomeToken(),{...at,kind:"control-error"},O);let Je=u.getCycle(l,T);if(Je!==void 0)return ie(T,l.createOutcomeToken(),{kind:"error",error:Je},O);if(Ke)return ie(T,l.createOutcomeToken(),{kind:"error",error:Te instanceof xe?Te:new pt(T,Te)},O);if(fe===void 0)throw Error("Selector comparator classification was not completed");let U=u.getControlFault();if(U.kind==="fault")return ie(T,l.createOutcomeToken(),{...U,kind:"control-error"},O);if(fe.kind==="error")return ie(T,l.createOutcomeToken(),{kind:"error",error:fe.error instanceof xe?fe.error:new pt(T,fe.error)},O);if(fe.value!==!0&&fe.value!==!1)return ie(T,l.createOutcomeToken(),{kind:"error",error:new Ct},O);if(fe.value===!0)ke=H.value,Z=H.current?H.token:void 0}return ie(T,Z??l.createOutcomeToken(),{kind:"value",value:ke},O)}finally{try{vt?.close()}finally{u.leave(l,T)}}};class e{#t=[];#e;#o;#c=0;#r;#s=Bn;#u;latchControlFault(r,l={}){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:r,origin:l})}getControlFault(){return this.#s}setSuppliedReadGuard(r){let l=this.#u;return this.#u=r,l}getControlFaultForSuppliedRead(){return this.#u?.(),this.#s}noteSelectorGraphPublication(r){let l=this.#o;if(l===void 0){this.#o=r,this.#c=1;return}if(Object.is(l,r)){this.#c++;return}let u=this.#r??(this.#r=new WeakMap);u.set(r,(u.get(r)??0)+1)}getSelectorGraphPublicationCount(r){return Object.is(this.#o,r)?this.#c:this.#r?.get(r)??0}enter(r,l,u){this.#t.push({host:r,selector:l,dependencyPrefix:u,revalidatePrefix:void 0,cycleError:void 0})}leave(r,l){let u=this.#t.pop();if(!u||!Object.is(u.host,r)||!Object.is(u.selector,l))throw Error("Selector evaluation frame corruption");this.#e=u}get evaluating(){return this.#t.length!==0}getProposedDependencies(r,l){let u=this.#e;return u!==void 0&&Object.is(u.host,r)&&Object.is(u.selector,l)&&Object.isFrozen(u.dependencyPrefix)?u.dependencyPrefix:void 0}isActive(r,l){return this.#t.some((u)=>Object.is(u.host,r)&&Object.is(u.selector,l))}isSoleActiveSelector(r,l){let u=!1;for(let f of this.#t){if(!Object.is(f.host,r))continue;if(u||!Object.is(f.selector,l))return!1;u=!0}return u}activeCyclePath(r,l){let u=this.#t.findIndex((f)=>Object.is(f.host,r)&&Object.is(f.selector,l));if(u===-1)return;return Object.freeze([...this.#t.slice(u).filter((f)=>Object.is(f.host,r)).map((f)=>f.selector),l])}setPrefixRevalidator(r,l,u){let f=this.#a(r,l);if(f.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");f.revalidatePrefix=u}revalidateAncestorPrefixes(r,l){this.#a(r,l);for(let u=0;u<this.#t.length-1;u++){let f=this.#t[u];if(!Object.is(f.host,r))continue;let A=f.revalidatePrefix;if(A===void 0)throw Error("Selector prefix revalidator is not installed");A()}}getTransientDependencies(r,l){for(let u=this.#t.length-1;u>=0;u--){let f=this.#t[u];if(Object.is(f.host,r)&&Object.is(f.selector,l))return f.dependencyPrefix}return}captureTransientReverseDependents(r,l,u,f,A){let g=new Set,T=new Map,O=!1,N=0,D=0,x=0;for(let P of this.#t){if(N++,N>f){A?.recordSnapshot("overflow",N,D,x);return}if(!Object.is(P.host,r))continue;if(D++,P.revalidatePrefix===void 0||g.has(P.selector)){A?.recordSnapshot("unavailable",N,D,x);return}if(g.add(P.selector),Object.is(P.selector,l)){if(O||P.dependencyPrefix.length!==u){A?.recordSnapshot("unavailable",N,D,x);return}O=!0}for(let H of P.dependencyPrefix){if(x++,x>f){A?.recordSnapshot("overflow",N,D,x);return}let I=T.get(H.node);if(I===void 0)T.set(H.node,[P.selector]);else I.push(P.selector)}}if(!O){A?.recordSnapshot("unavailable",N,D,x);return}let V=new Map;for(let[P,H]of T)V.set(P,Object.freeze(H));return A?.recordSnapshot("completed",N,D,x),V}latchCycle(r,l,u){let f=this.#i(r,l);f.cycleError??=u}getCycle(r,l){return this.#a(r,l).cycleError}#a(r,l){let u=this.#t[this.#t.length-1];if(!u||!Object.is(u.host,r)||!Object.is(u.selector,l))throw Error("Selector evaluation frame is not active");return u}#i(r,l){for(let u=this.#t.length-1;u>=0;u--){let f=this.#t[u];if(Object.is(f.host,r)&&Object.is(f.selector,l))return f}throw Error("Selector evaluation frame is not active")}}var Bn=Object.freeze({kind:"none"});var ce=Symbol(),Ee=Symbol(),mt=Symbol(),i=Symbol(),pe=(r,l)=>r.kind===l.kind&&(r.kind==="value"?Object.is(r.value,l.value):Object.is(r.error,l.error)),sn=Object.freeze({kind:"not-thenable"}),Ln=()=>{},Hn=Reflect.apply,an=Symbol.for("valdres.runtime-owner/v1");class J extends Error{seal(){Object.freeze(this)}}var dn=new WeakSet,De=(r)=>dn.has(r);class M extends J{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class a extends J{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source;constructor(r,l="owned-mutation"){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...r]),this.cause=this.causes[0],this.source=l,this.seal()}}class d extends J{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class v extends J{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(r){super(`A selector callback cannot call ${r} directly`);this.name="SelectorCapabilityError",this.seal()}}class j extends J{code="VALDRES_SETTLE_LIMIT";constructor(){super("Store updates did not settle");this.name="SettleLimitError",this.seal()}}class w extends J{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class C extends J{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class h extends J{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class m extends J{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class y extends J{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class S extends J{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class L extends J{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class _ extends J{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class R extends J{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var t=(r)=>{if((typeof r!=="object"||r===null)&&typeof r!=="function")return sn;try{let l=r.then;return typeof l==="function"?Object.freeze({kind:"thenable",target:r,then:l}):sn}catch(l){return Object.freeze({kind:"inspection-error",error:l})}},n=(r)=>{try{Hn(r.then,r.target,[void 0,Ln])}catch{}},tt=(r)=>{let l=t(r);if(l.kind==="not-thenable")return Object.freeze({kind:"value",value:r});if(l.kind==="inspection-error")return Object.freeze({kind:"error",error:l.error});return n(l),Object.freeze({kind:"error",error:new m})},Et=(r)=>{try{return tt(r())}catch(l){let u=t(l);if(u.kind==="not-thenable")return Object.freeze({kind:"error",error:l});if(u.kind==="inspection-error")return Object.freeze({kind:"error",error:u.error});return n(u),Object.freeze({kind:"error",error:new m})}},E=(r,l,u)=>{let f=r.activity;r.activity=l;try{return u()}finally{r.activity=f}},c=(r,l,u)=>{let f=r.activity,A=f?.kind==="selector"?f:f!==void 0&&("selectorActivity"in f)?f.selectorActivity:void 0,g=A===void 0?Object.freeze({kind:"guarded-callback",session:l}):Object.freeze({kind:"guarded-callback",session:l,selectorActivity:A});try{return E(r,g,u)}finally{let T=l.getControlFault();if(T.kind==="fault")throw r.externalRuntime?.guard(T.error),T.error}},cn=(r,l,u)=>{try{return E(r,Object.freeze({kind:"subscriber",session:l}),u)}finally{let f=l.getControlFault();if(f.kind==="fault")throw f.error}},yt=(r,l,u)=>{let f=r.activity,A=f?.kind==="selector"?f:f!==void 0&&("selectorActivity"in f)?f.selectorActivity:void 0,g=Object.is(A?.session,l)?A?.parentSelectorActivity:A,T=g===void 0?Object.freeze({kind:"selector",session:l}):Object.freeze({kind:"selector",session:l,parentSelectorActivity:g});return E(r,T,u)},ln=(r,l,u)=>E(r,Object.freeze({kind:"transaction",transaction:l}),u),nt=(r,l,u)=>{try{return E(r,Object.freeze({kind:"transaction-result",session:l}),u)}finally{let f=l.getControlFault();if(f.kind==="fault")throw f.error}},Se=(r)=>{let l=new d;throw r.externalRuntime?.guard(l),l},Ae=(r,l)=>{let u=r.activity;if(u===void 0)return;if(u.kind==="selector")throw new v(l);if(u.kind==="transaction"||u.kind==="transaction-result")throw new w;Se(r)},bt=(r,l)=>{if(r.activity?.kind==="subscriber")return r.activity.session;Ae(r,l)},be=(r,l)=>{let u=l.getControlFault(),f=r.getControlFault(),A=u.kind==="fault"?u.error:f.kind==="fault"?f.error:new d;throw r.latchControlFault(A),l.latchControlFault(A),A},un=(r)=>{bt(r,"Store unsubscribe")},$e=(r,l,u)=>{if(!u)throw new C;let f=r.activity;if(f?.kind==="transaction"&&Object.is(f.transaction,l))return;if(f?.kind==="selector")throw new v("Transaction cursor operation");if(f?.kind==="guarded-callback"||f?.kind.startsWith("external-"))Se(r);throw new w},fn=(r,l)=>{let u=r.activity;return u!==void 0&&"session"in u?u.session:l},Xe=(r,l,u)=>{if(r.states.has(l)||r.stores.has(l)||r.transactionCursors.has(l))return"local";if(l!==null&&l!==void 0){let f=Object.getOwnPropertyDescriptor(l,an);if(f!==void 0&&"value"in f&&!Object.is(f.value,r.ownerToken)){let A=new M;throw dn.add(A),fn(r,u).latchControlFault(A),A}}return"invalid"},le=(r,l,u)=>{if(r.states.has(l)||r.stores.has(l)||r.transactionCursors.has(l))return"local";let f=r.activity,A=fn(r,u);if(f!==void 0&&"session"in f)try{return Xe(r,l,A)}finally{let g=A.getControlFault();if(g.kind==="fault")throw g.error}return c(r,A,()=>Xe(r,l,A))},ot=(r,l)=>(Object.defineProperty(r,an,{value:l,enumerable:!1,writable:!1,configurable:!1}),r),b=(r)=>{let l=r[Ee];if(l===void 0||l.allowDefinitions)return;let u=l.session.getControlFault();if(u.kind==="fault")throw u.error;let f=new d;throw l.session.latchControlFault(f),f},F=(r)=>({kind:r}),k=(r,l)=>{b(r);let u=r[Ee],f=Object.freeze(ot(l,r.ownerToken));return r.states.add(f),u?.definitions?.add(f),f};var hn=Symbol("no-committed-selector-baseline");class Nt{#t;#e=new Map;#o=new Map;#c=new Map;#r;#s=1;#u=0;#a;#i;constructor(r,l,u){this.#t=r,this.#r=l,this.#a=u,this.#i=r.trackPath?[]:void 0}readSelector(r){let l=new e,u=this.serve(r,l);if(u.outcome.kind!=="value")throw u.outcome.error;return u.outcome.value}advanceGeneration(r){if(r!==this.#r+1)throw Error("Scratch selector generation is not contiguous");this.#r=r,this.#e.clear(),this.#o.clear()}revoke(){this.#e.clear(),this.#o.clear(),this.#c.clear(),this.#t=void 0}serve(r,l){if(this.#i===void 0)return this.#l(r,l);this.#i.push(r);try{return this.#l(r,l)}finally{this.#i.pop()}}#l(r,l){let u=this.#f(),f=u.resolve(r,l);if(f.kind!=="selector"){let O=this.#o.get(r);if(O!==void 0)return O;let N=Object.freeze({token:this.createOutcomeToken(),outcome:u.read(r,f.kind,l,this.#i)});return this.#o.set(r,N),N}let A=this.#e.get(r);if(A!==void 0)return A.served;let g=u.run(l,()=>this.#a(f.definition,this,l));if(g.outcome.kind==="control-error")throw g.outcome.error;let T=Object.freeze({token:g.token,outcome:g.outcome});return this.#u++,l.noteSelectorGraphPublication(this),this.#e.set(r,Object.freeze({served:T,dependencies:g.dependencies})),T}getSelectorRecord(r){let l=this.#e.get(r);return l===void 0?void 0:Object.freeze({dependencies:l.dependencies})}getSelectorGraphVersion(){return this.#u}getComparisonBaseline(r){let l=this.#c.get(r);if(l===void 0)l=this.#f().baseline(r)??hn,this.#c.set(r,l);return l===hn?void 0:Object.freeze({current:!1,value:l.value})}createOutcomeToken(){return Object.freeze({id:this.#s++})}#f(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var pn=4096,Wn=Object.freeze([]);class s{onDeadReference;onEmptinessProbe;#t=new WeakMap;#e=new Set;constructor(r,l){this.onDeadReference=r;this.onEmptinessProbe=l}add(r){if(this.#t.has(r))return;let l=new WeakRef(r);this.#t.set(r,l),this.#e.add(l)}delete(r){let l=this.#t.get(r);if(l===void 0)return;this.#t.delete(r),this.#e.delete(l)}forEach(r){for(let l of this.#e){let u=l.deref();if(u===void 0){this.#e.delete(l),this.onDeadReference?.();continue}r(u)}}visitWithin(r,l){for(let u of this.#e){if(r.remaining===0)return!1;r.remaining--;let f=u.deref();if(f===void 0){this.#e.delete(u),this.onDeadReference?.();continue}if(!l(f))return!1}return!0}isEmpty(){for(let r of this.#e){if(this.onEmptinessProbe?.(),r.deref()!==void 0)return!1;this.#e.delete(r),this.onDeadReference?.()}return!0}clear(){this.#e.clear(),this.#t=new WeakMap}}class xt{scope;onSwept;#t=new WeakMap;#e=new Set;#o=64;constructor(r,l){this.scope=r;this.onSwept=l}add(r){if(this.#t.has(r))return!1;let l=new WeakRef(r);if(this.#t.set(r,l),this.#e.add(l),this.#e.size>=this.#o)this.sweep();return!0}sweep(){let r=0;for(let l of this.#e){let u=l.deref();if(u!==void 0&&this.scope.atomOverrides.has(u))continue;if(u!==void 0)this.#t.delete(u);this.#e.delete(l),r++}if(this.#o=Math.max(64,this.#e.size*2),r!==0)this.onSwept?.(r);return r}collect(r){let l=0;for(let u of this.#e){let f=u.deref();if(f!==void 0){r.push(f);continue}this.#e.delete(u),l++}if(l!==0)this.onSwept?.(l)}}class At{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;ownedAtoms;#t=new WeakMap;#e;#o=new WeakMap;#c;#r=new WeakMap;#s=new WeakSet;#u;#a=0;#i=0;#l;#f=!1;#m;#S="live";constructor(r,l,u){this.coordinator=r,this.parent=l,this.name=u,this.children=this.#d(),this.#e=this.#d()}get status(){return this.#S}get facade(){if(this.#m===void 0)throw Error("Store scope facade is not installed");return this.#m}installFacade(r){if(this.#m!==void 0)throw Error("Store scope facade is already installed");this.#m=r}markDisposing(){if(this.#S==="live")this.#S="disposing"}markDisposed(){this.#S="disposed"}getAtomView(r){return this.#t.get(r)}getMaterializedServedOutcome(r){if(r.kind!=="selector")return this.#t.get(r)?.served;let l=r,u=this.#o.get(l);return u!==void 0&&!this.#s.has(l)?u.served:void 0}createAtomView(r,l,u){let f=this.#t.get(r);if(f!==void 0)return f;let A={scope:this,atom:r,served:Object.freeze({token:this.createOutcomeToken(),outcome:l}),inheritedFrom:u,inheritingChildren:this.#d()};if(this.#t.set(r,A),this.#e.add(A),u!==void 0)u.inheritingChildren.add(A),this.coordinator.recordCounter(11);return A}attachAtomView(r,l){if(Object.is(r.inheritedFrom,l))return;this.detachAtomView(r),r.inheritedFrom=l,l.inheritingChildren.add(r),this.coordinator.recordCounter(11)}detachAtomView(r){if(r.inheritedFrom===void 0)return;r.inheritedFrom.inheritingChildren.delete(r),r.inheritedFrom=void 0,this.coordinator.recordCounter(12)}updateAtomView(r,l){r.served=Object.freeze({token:this.createOutcomeToken(),outcome:l}),this.coordinator.reachSubscriptionTarget(this,r.atom)}captureCommittedSelectorSuccess(r){let l=this.#o.get(r)?.lastSuccess;return l===void 0?void 0:Object.freeze({value:l.value})}isSelectorDirty(r){return this.#s.has(r)}getCommittedSelectorDependencies(r){return this.#o.get(r)?.dependencies}externalRecord(r){return this.#o.get(r)}replaceExternalRecord(r,l){this.#o.set(r,l)}externalDependents(r){return this.#r.get(r)}markDependents(r){this.#r.get(r)?.forEach((l)=>{if(this.coordinator.enqueueSelector(this,l))this.#s.add(l)})}dropRecords(){this.coordinator.runtimeDomain[i]?.scope(this),this.#e.forEach((r)=>{this.detachAtomView(r),r.inheritingChildren.clear()}),this.#e.clear(),this.atomOverrides=new WeakMap,this.ownedAtoms=void 0,this[ce]?.release(this.coordinator),this[ce]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#c=void 0,this.#r=new WeakMap,this.#s=new WeakSet,this.#u=void 0,this.#a++,this.#p()}serve(r,l){let u=this.coordinator.runtimeDomain;if(Xe(u,r,l)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(r,l)}serveKnownLocal(r,l){let u=this.coordinator.runtimeDomain;if(u.atoms.has(r)){let O=this.#t.get(r);if(O!==void 0)return O.served;return this.coordinator.serveScopeAtom(this,r,l)}let f=u.selectors.get(r);if(f===void 0){if(u.externalAtoms?.has(r))return this.coordinator.reachExternal().serve(this,r,l);let O=u[i]?.scope(this,r,l);if(O!==void 0)return O;throw TypeError("Unknown committed StoreTree state")}let A=r,g=this.#o.get(A);if(g?.lifecycleInClosure&&!this.#s.has(A))this.coordinator.external?.refresh(this,A,l),g=this.#o.get(A);if(g!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,A,l),g=this.#o.get(A);if(g!==void 0&&!this.#s.has(A)&&!(this.coordinator.postSourceApply&&this.#h(A)))return g.served;let T;try{T=yt(u,l,()=>this.coordinator.evaluate(f,this,l))}catch(O){return this.publishEscapedFailure(A,O,l)}if(T.outcome.kind==="control-error"&&(!this.coordinator.postSourceApply||this.coordinator.external?.dormantPull===!0))throw T.outcome.error;return this.#b(A,T,l)}getSelectorRecord(r){let l=this.#o.get(r);return l===void 0?void 0:Object.freeze({dependencies:l.dependencies})}getSelectorDependencyNodes(r){let l=this.#o.get(r);if(l===void 0)return;let u=r,f=this.#c?.get(u);if(f===void 0){let A=[];for(let T of l.dependencies)if(this.coordinator.runtimeDomain.selectors.has(T.node))A.push(T.node);f=Object.freeze(A);let g=this.#c;if(g===void 0)g=new WeakMap,this.#c=g;g.set(u,f)}return f}visitSelectorDependents(r,l,u){return this.#r.get(r)?.visitWithin(l,u)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(r){if(!this.coordinator.runtimeDomain.selectors.has(r))return;if(this.#i===0)this.#l=[],this.#f=!1;this.#i++;let l=this.#l?.length??0,u=!1;return Object.freeze({takeAddedEdges:()=>{if(u||this.#f)return;let f=this.#l;if(f===void 0)return;if(l===f.length)return Wn;let A=Object.freeze(f.slice(l));return l=f.length,A},close:()=>{if(u)return;if(u=!0,this.#i--,this.#i!==0)return;this.#l=void 0,this.#f=!1}})}getComparisonBaseline(r){let l=this.#o.get(r);if(l?.lastSuccess===void 0)return;return l.served.outcome.kind==="value"?Object.freeze({current:!0,value:l.lastSuccess.value,token:l.served.token}):Object.freeze({current:!1,value:l.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}publishEscapedFailure(r,l,u){let f=this.#o.get(r),A=u.getProposedDependencies(this,r)??f?.dependencies,g=u.getControlFault(),T=g.kind!=="fault"&&(A===void 0||A.length===0);if(g.kind==="fault"?!this.coordinator.postSourceApply||this.coordinator.external?.dormantPull===!0:T&&f===void 0&&!u.evaluating)throw l;this.coordinator.reportSelectorFailure(l);let O=this.#b(r,{token:this.createOutcomeToken(),outcome:Object.freeze(g.kind==="fault"?{...g,kind:"control-error"}:{kind:"error",error:l}),dependencies:A??Dt},u);if(T)(this.#u??=new WeakMap).set(r,this.coordinator.settlementEpoch);return O}#h(r){let l=this.#u?.get(r);if(l===void 0||l===this.coordinator.settlementEpoch)return!1;return this.#u.delete(r),!0}#b(r,l,u){let f=this.#o.get(r),g={served:Object.freeze({token:l.token,outcome:l.outcome}),dependencies:l.dependencies,lastSuccess:l.outcome.kind==="value"?Object.freeze({value:l.outcome.value,token:l.token}):f?.lastSuccess};g=this.coordinator.external?.selectorRecord(this,g,u)??Object.freeze(g);let T=this.#y(r,f?.dependencies??Dt,l.dependencies),O=T?this.#A(r,f?.dependencies??Dt,l.dependencies):void 0;if(T)this.#c?.delete(r);if(this.#a++,u.noteSelectorGraphPublication(this),this.#o.set(r,g),this.coordinator.external?.publishedSelector(this,r,f,g),this.#s.delete(r),this.#u?.delete(r),O!==void 0)this.#v(O);if(f!==void 0&&!Object.is(f.served.token,l.token))this.coordinator.reachSubscriptionTarget(this,r),this.markDependents(r);if(l.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(g.served.outcome);return g.served}#y(r,l,u){if(l.length===u.length){let f=0;while(f<l.length&&Object.is(l[f].node,u[f].node))f++;if(f===l.length)return!1}for(let f of l){let A=this.#r.get(f.node);if(A?.delete(r),A?.isEmpty())this.#r.delete(f.node)}for(let f of u){let A=this.#r.get(f.node);if(A===void 0)A=this.#d(),this.#r.set(f.node,A);A.add(r)}return!0}#A(r,l,u){if(this.#i===0||this.#f)return;let f=this.#l;if(f===void 0){this.#p();return}let A=pn-f.length,g=this.coordinator.runtimeDomain.selectors,T=new Set;for(let N of l)if(g.has(N.node))T.add(N.node);let O=[];for(let N of u)if(g.has(N.node)&&!T.has(N.node)){if(O.push(Object.freeze({tail:r,head:N.node})),O.length>A){this.#p();return}}return O}#v(r){if(r.length===0)return;let l=this.#l;if(l===void 0||l.length+r.length>pn){this.#p();return}l.push(...r)}#p(){if(this.#i===0)return;this.#l=[],this.#f=!0}#d(){return new s(this.coordinator.instrumented?()=>this.coordinator.recordCounter(2):void 0)}}var Dt=Object.freeze([]);class Pt{commitEntries;transaction=Object.freeze({});onAllocation;#t;#e;#o;#c;#r;#s;#u;#a;#i;#l;#f;#m;#S;#h;#b;#y;externalCaptures;#A;#v=!1;generation=0;active=!0;constructor(r){this.onAllocation=r}get hasIntents(){return this.#e!==void 0||this.#o!==void 0||this.#c!==void 0||this.#r!==void 0}get hasRows(){return this.#v}installRows(r){let l=this.#A;if(l!==void 0&&l!==r)throw Error();this.#A=r}markRow(r){if(this.#A===void 0)throw Error();if(r!==this.generation)throw Error();this.#v=!0,this.#p()}get singleIntentScope(){return this.#t}get singleIntent(){return this.#o===void 0?this.#e:void 0}stage(r,l){let u=this.#r;if(u!==void 0){let g=u.get(r);if(g===void 0)g=this.#d(),u.set(r,g);g.set(l.atom,l),this.#p();return}let f=this.#c;if(f!==void 0){if(Object.is(this.#t,r))f.set(l.atom,l);else{let g=this.#d();g.set(this.#t,f);let T=this.#d();T.set(l.atom,l),g.set(r,T),this.#r=g,this.#c=void 0,this.#t=void 0}this.#p();return}let A=this.#e;if(A===void 0){this.#t=r,this.#e=l,this.#p();return}if(Object.is(this.#t,r)&&Object.is(A.atom,l.atom)){this.#e=l,this.#p();return}if(Object.is(this.#t,r)){let g=this.#o;if(g===void 0){this.#o=l,this.#p();return}if(Object.is(g.atom,l.atom)){this.#o=l,this.#p();return}let T=this.#d();T.set(A.atom,A),T.set(g.atom,g),T.set(l.atom,l),this.#c=T}else{let g=this.#d(),T=this.#d();if(T.set(A.atom,A),this.#o!==void 0)T.set(this.#o.atom,this.#o);g.set(this.#t,T);let O=this.#d();O.set(l.atom,l),g.set(r,O),this.#r=g,this.#t=void 0}this.#e=void 0,this.#o=void 0,this.#p()}forEachIntent(r){let l=this.#e;if(l!==void 0){if(r(this.#t,l),this.#o!==void 0)r(this.#t,this.#o);return}let u=this.#c;if(u!==void 0){let A=this.#t;for(let g of u.values())r(A,g);return}let f=this.#r;if(f===void 0)return;for(let[A,g]of f)for(let T of g.values())r(A,T)}getIntent(r,l){let u=this.#e;if(u!==void 0&&Object.is(this.#t,r)&&Object.is(u.atom,l))return u;let f=this.#o;if(f!==void 0&&Object.is(this.#t,r)&&Object.is(f.atom,l))return f;if(Object.is(this.#t,r))return this.#c?.get(l);return this.#r?.get(r)?.get(l)}getAtomBaseline(r,l){if(this.#a!==void 0&&Object.is(this.#s,r)&&Object.is(this.#u,l))return this.#a;if(this.#l!==void 0&&Object.is(this.#s,r)&&Object.is(this.#i,l))return this.#l;if(Object.is(this.#s,r))return this.#f?.get(l);return this.#m?.get(r)?.get(l)}setAtomBaseline(r,l,u){let f=this.#m;if(f!==void 0){let T=f.get(r);if(T===void 0)T=this.#d(),f.set(r,T);if(!T.has(l))T.set(l,u);return}let A=this.#f;if(A!==void 0){if(Object.is(this.#s,r)){if(!A.has(l))A.set(l,u)}else{let T=this.#d();T.set(this.#s,A);let O=this.#d();O.set(l,u),T.set(r,O),this.#m=T,this.#f=void 0,this.#s=void 0}return}let g=this.#a;if(g===void 0){this.#s=r,this.#u=l,this.#a=u;return}if(Object.is(this.#s,r)&&Object.is(this.#u,l))return;if(Object.is(this.#s,r)){let T=this.#l;if(T===void 0){this.#i=l,this.#l=u;return}if(Object.is(this.#i,l))return;let O=this.#d();O.set(this.#u,g),O.set(this.#i,T),O.set(l,u),this.#f=O}else{let T=this.#d(),O=this.#d();if(O.set(this.#u,g),this.#i!==void 0&&this.#l!==void 0)O.set(this.#i,this.#l);T.set(this.#s,O);let N=this.#d();N.set(l,u),T.set(r,N),this.#m=T,this.#s=void 0}this.#u=void 0,this.#a=void 0,this.#i=void 0,this.#l=void 0}getFallback(r){if(Object.is(this.#S,r))return this.#h;return this.#b?.get(r)}hasFallback(r){return Object.is(this.#S,r)||(this.#b?.has(r)??!1)}setFallback(r,l){let u=this.#b;if(u!==void 0){u.set(r,l);return}if(this.#h===void 0){this.#S=r,this.#h=l;return}if(Object.is(this.#S,r)){this.#h=l;return}let f=this.#d();f.set(this.#S,this.#h),f.set(r,l),this.#b=f,this.#S=void 0,this.#h=void 0}forEachFallback(r){if(this.#S!==void 0&&this.#h!==void 0)r(this.#S,this.#h);if(this.#b!==void 0)for(let[l,u]of this.#b)r(l,u)}#p(){this.generation+=1;let r=this.#y;if(r!==void 0)for(let l of r.values())l.advanceGeneration(this.generation)}getScratchHost(r){return this.#y?.get(r)}installScratchHost(r,l){let u=this.#y,f=u===void 0;if(u===void 0)u=new Map,this.#y=u;return u.set(r,l),f}close(){if(!this.active)return;this.active=!1;let r=this.#y;if(r!==void 0){for(let l of r.values())l.revoke();r.clear()}this.#y=void 0}release(){this.commitEntries=void 0;let r=this.#A;this.#A=void 0,this.#v=!1;try{if(this.#c?.clear(),this.#r!==void 0){for(let l of this.#r.values())l.clear();this.#r.clear()}if(this.#f?.clear(),this.#m!==void 0){for(let l of this.#m.values())l.clear();this.#m.clear()}this.#b?.clear(),this.#t=void 0,this.#e=void 0,this.#o=void 0,this.#c=void 0,this.#r=void 0,this.#s=void 0,this.#u=void 0,this.#a=void 0,this.#i=void 0,this.#l=void 0,this.#f=void 0,this.#m=void 0,this.#S=void 0,this.#h=void 0,this.#b=void 0,this.#y?.clear(),this.#y=void 0,this.externalCaptures?.clear(),this.externalCaptures=void 0}finally{r?.(this)}}#d(){return this.onAllocation?.(),new Map}}class Sn{constructor(r,l,u){this.onCommit=(f)=>r.registerCommit(l,u,f),this.get=(f)=>r.transactionGet(l,u,f),this.set=(f,A)=>r.mutate(l,u,"set",f,A),this.update=(f,A)=>r.mutate(l,u,"update",f,A),this.reset=(f)=>r.mutate(l,u,"reset",f),this.delete=(f)=>r.mutate(l,u,"delete",f),this.resetAll=function(){r.resetAll(l,u,arguments.length)},this.scope=(...f)=>r.transactionScope(l,u,f[0],f.length,f[1]),ot(this,r.runtimeDomain.ownerToken),r.runtimeDomain.transactionCursors.set(this,l),Object.freeze(this)}}var jt=(r,l,u)=>new Sn(r,l,u),Vt=(r)=>{let l=t(r);if(l.kind==="not-thenable")return;if(l.kind==="inspection-error")throw l.error;throw n(l),new h},mn=(r)=>{let l=t(r);if(l.kind==="not-thenable")throw r;if(l.kind==="inspection-error")throw l.error;throw n(l),new h};var Gn=64,qn=(r)=>function(){let u=r.target;if(u===void 0)return;u.host.removeSubscription(r)},X=Symbol("definition domain records"),ge=(r)=>r[X].ownerToken,Ne=(r)=>r[X],Pe=(r,l)=>{let u=r[X],f=u[i];if(f!==void 0)return f;let A=l(u);return u[i]=A,A},Ve=(r)=>r[X][i],Kn=Object.freeze([]),B=(r,l,u,f,A,g)=>{let T=r[X],O=new e,N=T.activity,D=N?.kind==="selector"?N:N?.kind==="guarded-callback"?N.selectorActivity:void 0,x=[];while(D!==void 0){let I=D.session;if(!x.includes(I))x.push(I);D=D.parentSelectorActivity}let V=l==="factory",P=T[Ee];T[Ee]={session:O,definitions:V?new WeakSet:void 0,allowDefinitions:V,...g===void 0?{}:{createAccessorFault:g}};let H=x.length===0?Kn:x.map((I)=>Object.freeze({selectorSession:I,previous:I.setSuppliedReadGuard(()=>{let G=T.activity;return be(G?.kind==="guarded-callback"?G.session:O,I)})}));try{return c(T,O,()=>{let I=Reflect.apply(u,void 0,f);return A===void 0?I:A(I)})}finally{for(let I=H.length-1;I>=0;I--){let G=H[I];G.selectorSession.setSuppliedReadGuard(G.previous)}if(P===void 0)delete T[Ee];else T[Ee]=P}},ve=(r)=>{let l=r[X][Ee];if(l===void 0||l.allowDefinitions)return;let u=l.session.getControlFault();if(u.kind==="fault")throw u.error;let f=l.createAccessorFault===void 0?new d:l.accessorFault??=l.createAccessorFault();throw l.session.latchControlFault(f),f},he=(r)=>b(r[X]),Me=ve,z=(r,l)=>k(r[X],l),Re=(r,l)=>le(r[X],l,new e),je=(r,l)=>{let u=r[X];if((typeof l==="object"||typeof l==="function")&&l!==null&&u.states.has(l)&&(u.atoms.has(l)||u.selectors.has(l)||u.externalAtoms?.has(l))){if(u[Ee]?.definitions?.has(l)||u[mt]?.has(l))return l;return}le(u,l,new e);return};class An extends Set{release(r){r.recordCounter(34,this.size)}}class vn extends WeakSet{apply(r,{atom:l,kind:u}){let f=r[ce];if(u==="set"){if(!this.has(l))return!1;if(f===void 0)f=r[ce]=new An,r.coordinator.recordCounter(32);let A=f.size;if(f.add(l),f.size!==A)r.coordinator.recordCounter(33);return!0}else{if(f?.delete(l))r.coordinator.recordCounter(34);if(f?.size===0)r[ce]=void 0;return!1}}}var Le=(r,l)=>{let u=r[X];if((u[mt]??(u[mt]=new WeakSet)).add(l),!u.atoms.has(l))return;(u[ce]??(u[ce]=new vn)).add(l)},gn=new WeakMap,_e=()=>{let r=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,familyOwnerRetentionSetsCreated:32,familyOwnerRetains:33,familyOwnerReleases:34,liveSamples:35,serverSamples:36,transactionCaptures:37,externalClosureVisits:38,projectionPublications:39,lifecycleEdgeVisits:40,adapterSubscriptions:41,adapterCleanups:42,dirtyRounds:43,dirtySamples:44,thenableContainments:45,deliveryEntries:46,deliveryLimitHits:47,nonConvergenceTerminations:48,lifecycleRetains:49,lifecycleReleases:50,ownedAtomRetains:51,ownedAtomSweptReferences:52}),l=53,u=new Uint32Array(53),f=Object.freeze({read(A){return u[r[A]]??0}});return gn.set(f,(A,g)=>{u[A]+=g}),f},se=(r)=>Object.freeze({kind:"value",value:r}),Un=(r)=>Object.freeze({kind:"error",error:r}),yn=(r)=>r.kind==="value"?se(r.value):Un(r.error),rt=(r,l)=>r[i]?.has(l)?r[i]:void 0,kn=(r,l,u,f)=>{let A=r.read(l,u,f);if(A.kind!=="value")throw A.error;return A.value};var Yn=(r)=>({onAllocation:r,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}),Mt=(r)=>(r.onAllocation?.(),new Map),Qn=(r)=>(r.onAllocation?.(),new Set),It=(r,l,u)=>{if(r.preflightOutcome!==void 0&&Object.is(r.preflightAtom,l)&&Object.is(r.preflightScope,u))return r.preflightOutcome;if(r.secondPreflightOutcome!==void 0&&Object.is(r.secondPreflightAtom,l)&&Object.is(r.secondPreflightScope,u))return r.secondPreflightOutcome;return r.preflight?.get(l)?.get(u)},bn=(r,l,u,f)=>{if(r.preflightOutcome===void 0){r.preflightAtom=l,r.preflightScope=u,r.preflightOutcome=f;return}if(Object.is(r.preflightAtom,l)&&Object.is(r.preflightScope,u))return;if(r.secondPreflightOutcome===void 0){r.secondPreflightAtom=l,r.secondPreflightScope=u,r.secondPreflightOutcome=f;return}if(Object.is(r.secondPreflightAtom,l)&&Object.is(r.secondPreflightScope,u))return;let A=r.preflight;if(A===void 0)A=Mt(r),r.preflight=A;let g=A.get(l);if(g===void 0)g=Mt(r),A.set(l,g);g.set(u,f)},Xn=(r,l)=>{if(Object.is(r.consideredRecord,l)||Object.is(r.secondConsideredRecord,l))return!1;if(r.consideredRecord===void 0)return r.consideredRecord=l,!0;if(r.secondConsideredRecord===void 0)return r.secondConsideredRecord=l,!0;let u=r.considered;if(u===void 0)u=Qn(r),r.considered=u;if(u.has(l))return!1;return u.add(l),!0},$n=(r,l,u)=>{if(r.affectedRecord===void 0){r.affectedRecord=l,r.affectedBefore=u;return}if(r.secondAffectedRecord===void 0){r.secondAffectedRecord=l,r.secondAffectedBefore=u;return}let f=r.affected;if(f===void 0)f=Mt(r),r.affected=f;f.set(l,u)};class wn{#t=new WeakMap;#e;#o;#c;subscriberReading=!1;#r;#s=1;sourceEpoch=0;#u=!1;#a;#i;#l;#f=0;#m;#S;#h;#b=1;#y=0;#A;#v;#p;#d=0;#T;#N;#D=!1;settlementEpoch=0;#n;#C;#w;evaluate;constructor(r,l,u){this.#n=r,this.#C=l===void 0?void 0:gn.get(l),this.#w=u,this.evaluate=u?.evaluate??ye,this.#r=new At(this),this.recordCounter(7)}get runtimeDomain(){return this.#n}get postSourceApply(){return this.#u}get instrumented(){return this.#C!==void 0}get rootScope(){return this.#r}recordCounter(r,l=1){let u=this.#C;if(u===void 0)return;u(r,l)}createDraft(){return this.recordCounter(14),new Pt(this.instrumented?()=>this.recordCounter(18):void 0)}get(r,l){let u=new e,f=l,A=le(this.#n,f,u),g=bt(this.#n,"StoreTree.get");if(this.#g(r),A==="invalid")throw TypeError("StoreTree.get requires a valid State");let T=(g===void 0&&!this.#e?r.getMaterializedServedOutcome(f):void 0)??this.#U(r,f,u,g);if(T.outcome.kind!=="value"){if(T.outcome.kind==="control-error")g?.latchControlFault(T.outcome.error);throw T.outcome.error}return T.outcome.value}#U(r,l,u,f){let A=f===void 0&&!this.#e?.current(r,l)&&this.#E(1),g;this.subscriberReading=f!==void 0;try{g=this.subscriberReading||!this.#e?r.serveKnownLocal(l,u):this.#e.observe(r,l,u)}catch(T){let O=u.getControlFault();if(O.kind==="fault")f?.latchControlFault(O.error);if(A)this.#e?.failure(T);throw T}finally{if(this.subscriberReading=!1,A)this.#o=void 0,this.#e?.finish()}return(A?this.#e?.installed(r,l):void 0)??g}#E(r){if(this.#o||this.#e?.idle===!1)return!1;return this.#o=r,this.#c=this.sourceEpoch,this.external,!0}#R(r){if(this.#o)this.#o=r+1<<2|this.#o&3;this.#e?.phase(r)}get external(){let r=this.#e;if(r?.idle&&this.#o)r.beginHost(this.#o,this.#c,this.#S),this.#S=void 0;return r}reachExternal(){return this.#e??=this.#n.externalRuntime.createTree(this),this.external}hasSubscription(r,l){return this.#h?.get(r)?.has(l)===!0}sub(r,l,u){let f=l,A,g=this.#n.states.has(f)?"local":le(this.#n,f,A=new e);if(this.#g(r,"StoreTree.sub"),g==="invalid"||!this.#n.atoms.has(f)&&!this.#n.selectors.has(f)&&!this.#n.externalAtoms?.has(f)&&!rt(this.#n,f))throw TypeError("StoreTree.sub requires a valid State");let T=u,O;if(typeof u!=="function"){let x;if({settle:O,notify:T,...x}=u??{},this.#g(r),Reflect.ownKeys(x).length>0||(O??T)===void 0||O!==void 0&&typeof O!=="function"||T!==void 0&&typeof T!=="function")throw TypeError("StoreTree.sub requires a callback or settle/notify handlers")}let N=r.getMaterializedServedOutcome(f),D=(N===void 0||this.#e)&&this.#E(2);try{let x=!this.#e?N??r.serveKnownLocal(f,A??new e):this.#e.observe(r,f,A??new e);if(x.outcome.kind==="control-error")throw x.outcome.error;let V=this.#h;if(V===void 0){if(V=new Map,this.#h=V,this.instrumented)this.recordCounter(20)}let P=V.get(r);if(P===void 0){if(P=new Map,V.set(r,P),this.instrumented)this.recordCounter(20),this.recordCounter(25)}let H=P.get(f);if(H===void 0){if(H={host:this,scope:r,state:f,head:void 0,tail:void 0,reachedEpoch:0,reactions:0},P.set(f,H),this.instrumented)this.recordCounter(21),this.recordCounter(26)}let I={callback:T,reaction:O,target:H,previous:H.tail,next:void 0};if(O)H.reactions++;if(H.tail===void 0)H.head=I;else H.tail.next=I;if(H.tail=I,this.instrumented)this.recordCounter(22),this.recordCounter(27),this.recordCounter(24);return this.#e?.admit(I,x.token),qn(I)}catch(x){if(D)this.#e?.failure(x);throw x}finally{if(D)this.#o=void 0,this.#e?.finish()}}removeSubscription(r){let l=r.target;if(l===void 0)return;if(un(this.#n),this.#e?.idle)return this.#e.cleanup(()=>this.removeSubscription(r));let{previous:u,next:f}=r;if(u===void 0)l.head=f;else u.next=f;if(f===void 0)l.tail=u;else f.previous=u;if(r.reaction!==void 0)r.reaction=void 0,l.reactions--;r.callback=void 0,r.target=void 0,r.previous=void 0,r.next=void 0;let A=this.instrumented;if(A)this.recordCounter(23),this.recordCounter(27,-1);if(l.head!==void 0)return;let g=this.#h,T=g?.get(l.scope);if(T?.get(l.state)===l){if(T.delete(l.state),A)this.recordCounter(26,-1)}if(T!==void 0&&T.size===0){if(g?.delete(l.scope),A)this.recordCounter(25,-1)}if(g?.size===0)this.#h=void 0;this.#e?.releaseRoot(l.scope,l.state)}scope(r,l,u){if(l!==0&&(typeof u==="object"||typeof u==="function")&&u!==null)le(this.#n,u,new e);if(this.#g(r,"StoreTree.scope"),l===0)return this.#M(r);if(l!==1||typeof u!=="string")throw TypeError("StoreTree.scope requires a string name");let f=r.namedChildren.get(u);if(f!==void 0)return this.recordCounter(9),f.facade;return this.recordCounter(10),this.#M(r,u)}dispose(r){if(Ae(this.#n,"StoreTree.dispose"),r.status!=="live")return;if(this.#e?.idle)return this.#e.cleanup(()=>this.dispose(r));let l=[],u=[Object.freeze({node:r,expanded:!1})];while(u.length>0){let{node:f,expanded:A}=u.pop();if(A){l.push(f);continue}f.markDisposing(),u.push(Object.freeze({node:f,expanded:!0}));let g=[];f.children.forEach((T)=>g.push(T));for(let T=g.length-1;T>=0;T--)u.push(Object.freeze({node:g[T],expanded:!1}))}for(let f of l){this.recordCounter(5);let A=f.parent;if(A!==void 0){if(f.name!==void 0&&Object.is(A.namedChildren.get(f.name),f))A.namedChildren.delete(f.name);A.children.delete(f)}this.#X(f),f.dropRecords(),f.namedChildren.clear(),f.children.clear(),f.markDisposed()}if(Yt(),Object.is(r,this.#r))this.#t=new WeakMap,this.#e=void 0}txn(r,l,u){if(this.#g(r,"StoreTree.txn"),typeof l!=="function"||u!==void 0&&typeof u!=="string")throw TypeError("StoreTree.txn requires a callback");let f=this.#E(3);try{return this.#I(r,l)}catch(A){if(f)this.#e?.failure(A);throw A}finally{if(f)this.#o=void 0,this.#e?.finish()}}#I(r,l){let u=this.createDraft();try{let f=jt(this,u,r),A=ln(this.#n,u.transaction,()=>l(f));u.close();let g=new e;return nt(this.#n,g,()=>Vt(A)),this.#_(u),A}finally{u.close(),u.release()}}registerCommit(r,l,u){if($e(this.#n,r.transaction,r.active),this.#g(l),typeof u!=="function")throw TypeError("Transaction.onCommit requires a function");(r.commitEntries??=[]).push({scope:l,callback:u})}get fallbackRecords(){return this.#t}transactionGet(r,l,u){let f=u,A=new e,g=le(this.#n,f,A);if($e(this.#n,r.transaction,r.active),this.#g(l),g==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#n.atoms.has(f)){let O=this.readDraftAtomOutcome(r,l,f,A);if(O.kind!=="value")throw O.error;return O.value}if(!this.#n.selectors.has(f)&&!this.#n.externalAtoms?.has(f)){let O=rt(this.#n,f);if(!O)throw TypeError("Transaction.get requires a readable State");return kn(O,r,l,f)}let T=r.getScratchHost(l);if(T===void 0){if(T=this.createScratchSelectorHost(r,l),r.installScratchHost(l,T))this.recordCounter(15)}return T.readSelector(f)}mutate(r,l,u,f,A){let g=f,T=new e,O=`${r===void 0?"StoreTree":"Transaction"}.${u}`,N=le(this.#n,g,T);if(r===void 0)Ae(this.#n,O);else $e(this.#n,r.transaction,r.active);this.#g(l);let D=N==="local"&&this.#n.atoms.has(g),x;if(D?u==="delete":N!=="local"||typeof g==="function"||(x=rt(this.#n,g))===void 0)throw TypeError(`${O} requires a valid State`);let P=r===void 0&&this.#E(3);try{let H=r===void 0,I=r??this.createDraft();try{if(x!==void 0)x.stage(I,l,u,g,A,T);else if(u==="set")this.#$(I,l,g,A,T);else if(u==="update")this.#Z(I,l,g,A,T,O);else this.#J(I,l,g,T);if(!H)return;I.close(),this.#_(I)}finally{if(H)I.close(),I.release()}}catch(H){if(P)this.#e?.failure(H);throw H}finally{if(P)this.#o=void 0,this.#e?.finish()}}transactionScope(r,l,u,f,A){let g=new e;if(typeof u!=="string")le(this.#n,u,g);$e(this.#n,r.transaction,r.active),this.#g(l);let T=this.#Q(l,u);if(f!==1&&f!==2)throw TypeError("Transaction.scope requires a target and optional callback");let O=jt(this,r,T);if(f===1)return O;if(typeof A!=="function")throw TypeError("Transaction.scope requires a callback function");let N;try{N=A(O)}catch(x){let V=new e;return nt(this.#n,V,()=>mn(x))}let D=new e;return nt(this.#n,D,()=>Vt(N)),N}createOutcomeToken(){return Object.freeze({id:this.#s++})}createScratchSelectorHost(r,l,u=!1){return this.recordCounter(3),new Nt(Object.freeze({trackPath:u,resolve:(f,A)=>this.#Y(f,A),read:(f,A,g,T)=>this.#ee(r,l,f,A,g,T),baseline:u?()=>{return}:(f)=>l.captureCommittedSelectorSuccess(f),run:(f,A)=>yt(this.#n,f,A)}),r.generation,this.evaluate)}#Y(r,l){if(Xe(this.#n,r,l)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#n.atoms.has(r))return Object.freeze({kind:"atom"});let u=this.#n.selectors.get(r);if(u!==void 0)return Object.freeze({kind:"selector",definition:u});if(rt(this.#n,r))return Object.freeze({kind:"collection"});if(this.#n.externalAtoms?.has(r))return Object.freeze({kind:"external"});throw TypeError("Unknown scratch StoreTree State")}#M(r,l){let u=new At(this,r,l);this.recordCounter(7);let f=new Ft(this,u,this.#w);if(r.children.add(u),l!==void 0)r.namedChildren.set(l,u);return f}#Q(r,l){if(typeof l==="string"){let g=r.namedChildren.get(l);if(g===void 0)throw new L;return this.#g(g),g}let u=l,f=this.#n.stores.get(u);if(f!==void 0){let g=f;if(this.#g(g),!Object.is(g.coordinator,this))throw new _;return g}let A=this.#n.transactionCursors.get(u);if(A!==void 0){if(!A.active)throw new C;throw new R}throw new R}#g(r,l){if(l!==void 0)Ae(this.#n,l);if(r.status!=="live")throw new S}#X(r){let l=this.#h,u=l?.get(r);if(u===void 0)return;let f=0;for(let A of u.values()){let g=A.head;while(g!==void 0){let T=g.next;g.callback=void 0,g.reaction=void 0,g.target=void 0,g.previous=void 0,g.next=void 0,f++,g=T}A.head=void 0,A.tail=void 0,A.reactions=0,this.#e?.releaseRoot(r,A.state)}if(l.delete(r),l.size===0)this.#h=void 0;if(this.instrumented)this.recordCounter(23,f),this.recordCounter(27,-f),this.recordCounter(26,-u.size),this.recordCounter(25,-1)}#$(r,l,u,f,A){let g=c(this.#n,A,()=>tt(f));if(g.kind==="error")throw g.error;let T=this.#x(r,l,u,A);this.#K(r,l,u,g.value,T,A)}#Z(r,l,u,f,A,g){if(typeof f!=="function")throw TypeError(`${g} requires an updater function`);let T=this.#x(r,l,u,A),O=r.hasIntents?this.readDraftAtomOutcome(r,l,u,A):T.outcome;if(O.kind!=="value")throw O.error;let N=this.#oe(f,O.value,A);this.#K(r,l,u,N,T,A)}#J(r,l,u,f){r.stage(l,this.#F(r,l,u,f))}#F(r,l,u,f){this.#x(r,l,u,f);let A=l.parent===void 0?Object.freeze({outcome:this.#P(r,u,f),reachesFallback:!0}):this.#z(r,l.parent,u,f);if(A.outcome.kind!=="value")throw A.outcome.error;let g=A.reachesFallback&&r.hasFallback(u);return Object.freeze({kind:"reset",atom:u,publishDraftFallback:g})}resetAll(r,l,u){if($e(this.#n,r.transaction,r.active),this.#g(l),u!==0)throw TypeError("Transaction.resetAll accepts no arguments");if(l.parent===void 0)throw TypeError("Transaction.resetAll requires a child scope cursor");let f=[];l.ownedAtoms?.collect(f),l[ce]?.forEach((O)=>f.push(O)),r.forEachIntent((O,N)=>{if(Object.is(O,l))f.push(N.atom)});let A=new e,g=[],T=new Set;for(let O of f){if(T.has(O))continue;T.add(O);let N=r.getIntent(l,O);if(N===void 0){if(!l.atomOverrides.has(O))continue}else if(N.kind==="reset")continue;g.push(this.#F(r,l,O,A))}for(let O of g)r.stage(l,O);this.#n[i]?.resetAll?.(r,l)}#x(r,l,u,f){let A=r.getAtomBaseline(l,u);if(A!==void 0)return A;let g=l.atomOverrides.has(u),T=l,O;while(T!==void 0){if(T.atomOverrides.has(u)){O=se(T.atomOverrides.get(u));break}T=T.parent}let N=O===void 0,D=Object.freeze({owned:g,outcome:O??this.#P(r,u,f),reachesFallback:N});return r.setAtomBaseline(l,u,D),D}readDraftAtomOutcome(r,l,u,f){return this.#z(r,l,u,f).outcome}#ee(r,l,u,f,A,g){if(f==="atom")return this.readDraftAtomOutcome(r,l,u,A);if(f==="external")return this.#n.externalRuntime.read(r,u,A,g,this.#C);return this.#n[i].read(r,l,u)}#z(r,l,u,f){let A=l;while(A!==void 0){let g=r.getIntent(A,u);if(g?.kind==="set")return Object.freeze({outcome:se(g.value),reachesFallback:!1});if(g===void 0&&A.atomOverrides.has(u))return Object.freeze({outcome:se(A.atomOverrides.get(u)),reachesFallback:!1});A=A.parent}return Object.freeze({outcome:this.#P(r,u,f),reachesFallback:!0})}#P(r,l,u){let f=this.#t.get(l);if(f!==void 0)return f;let A=this.#O(l);if(A.fallback.kind==="eager")return se(A.fallback.value);let g=A.fallback.initialize,T=r.getFallback(l);if(T!==void 0)return T;let O=yn(c(this.#n,u,()=>Et(g)));return r.setFallback(l,O),O}#te(r,l,u,f){let A=this.#O(r).equal;if(A===void 0)return Object.is(l,u)?l:u;return this.#ne(A,l,u,f)?l:u}#ne(r,l,u,f){return c(this.#n,f,()=>{let A;try{A=r(l,u)}catch(T){let O=t(T);if(O.kind==="not-thenable")throw T;if(O.kind==="inspection-error")throw O.error;throw n(O),new y}let g=t(A);if(g.kind==="inspection-error")throw g.error;if(g.kind==="thenable")throw n(g),new y;if(A!==!0&&A!==!1)throw new y;return A})}#oe(r,l,u){return c(this.#n,u,()=>{let f;try{f=r(l)}catch(g){let T=t(g);if(T.kind==="not-thenable")throw g;if(T.kind==="inspection-error")throw T.error;throw n(T),new m}let A=tt(f);if(A.kind==="error")throw A.error;return A.value})}#_(r){this.#R(2);let l;if(r.hasRows){if(l=this.#n[i]?.plan(r),l===void 0)throw Error()}if(!r.hasIntents&&l===void 0){ut(r);return}let{singleIntent:u,singleIntentScope:f}=r;if(l===void 0&&u?.kind==="reset"&&f!==void 0&&!u.publishDraftFallback&&r.getAtomBaseline(f,u.atom)?.owned===!1){ut(r);return}let A=Yn(this.instrumented?()=>this.recordCounter(19):void 0),g,T;if(u!==void 0&&f!==void 0)g=this.#B(r,f,u,A);else r.forEachIntent((D,x)=>{let V=this.#B(r,D,x,A);if(g===void 0){g=V;return}if(T===void 0)T=[];T.push(V)});if(this.#R(6),this.#w?.(1,r,this.#n.atoms),this.#R(3),g!==void 0)this.#L(r,g);if(T!==void 0)for(let D of T)this.#L(r,D);let O=g===void 0?!1:this.#H(g);if(T!==void 0)for(let D of T){let x=this.#H(D);O||=x}if(l!==void 0){let D=l.commit(0);O||=D}if(ut(r),g!==void 0)this.#W(g);if(T!==void 0)for(let D of T)this.#W(D);if(l!==void 0)l.commit(1);let N=this.#d!==0;if(!N)this.beginNotificationSettlement();try{let D,x,{affectedRecord:V,affectedBefore:P}=A;if(V!==void 0&&P!==void 0)D=this.#j(A,V,P);let{secondAffectedRecord:H,secondAffectedBefore:I}=A;if(H!==void 0&&I!==void 0){let G=this.#j(A,H,I);if(G!==void 0)if(D===void 0)D=G;else x=[G]}if(A.affected!==void 0)for(let[G,K]of A.affected){let re=this.#j(A,G,K);if(re===void 0)continue;if(D===void 0)D=re;else{if(x===void 0)x=[];x.push(re)}}if(l!==void 0){let G=l.commit(2);if(G!==void 0)for(let K of G){let re=K;if(D===void 0)D=re;else{if(x===void 0)x=[];x.push(re)}}}if(O)this.sourceEpoch+=1,this.recordCounter(0);this.#R(6);try{this.#w?.(2,D===void 0?0:1+(x?.length??0))}catch(G){if(N)this.#T??={error:G};else if(!this.#e)throw G;else this.#e.failure(G,"instrumenting")}this.propagateFromSources(D,x)}catch(D){if(!N)this.clearNotificationSettlement();throw D}}#B(r,l,u,f){let A=r.getAtomBaseline(l,u.atom);if(A===void 0)throw Error("TreeDraft atom baseline is missing");this.#G(r,l,u.atom,f);let g=Object.freeze({scope:l,intent:u,ownershipChanged:u.kind==="set"?!A.owned||!Object.is(l.atomOverrides.get(u.atom),u.value):A.owned}),T=l.getAtomView(u.atom);if(T!==void 0)this.#ie(r,T,f);return g}#L(r,l){if(!l.intent.publishDraftFallback)return;let u=r.getFallback(l.intent.atom);if(u!==void 0&&!this.#t.has(l.intent.atom))this.#t.set(l.intent.atom,u),this.recordCounter(13)}#H(r){let{intent:l,scope:u}=r;if(l.kind==="set")u.atomOverrides.set(l.atom,l.value);else u.atomOverrides.delete(l.atom);let f=this.#n[ce]?.apply(u,l);if(u.parent!==void 0&&f!==!0){if(l.kind==="set"&&(u.ownedAtoms??this.#re(u)).add(l.atom))this.recordCounter(51)}return r.ownershipChanged}#re(r){return r.ownedAtoms=new xt(r,this.#C===void 0?void 0:(l)=>this.recordCounter(52,l))}#W({scope:r,intent:l}){let u=r.getAtomView(l.atom);if(u===void 0)return;if(l.kind==="set"||r.parent===void 0)r.detachAtomView(u);else r.attachAtomView(u,this.#de(r.parent,l.atom))}#j(r,l,u){let f=It(r,l.atom,l.scope);if(f===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter(16),pe(u,f))return;return l.scope.updateAtomView(l,f),l}#ie(r,l,u){let f=[l];while(f.length!==0){let A=f.pop();if(!Xn(u,A))continue;let g=A.served.outcome,T=this.#G(r,A.scope,A.atom,u);if(pe(g,T))continue;$n(u,A,g);let O=f.length;A.inheritingChildren.forEach((N)=>{this.recordCounter(1),f.push(N)});for(let N=O,D=f.length-1;N<D;N++,D--){let x=f[N];f[N]=f[D],f[D]=x}}}#G(r,l,u,f){let A=It(f,u,l);if(A!==void 0)return A;let g=l,T,O,N;while(g!==void 0){let D=It(f,u,g);if(D!==void 0){N=D;break}if(T===void 0)T=g;else{if(O===void 0)O=[];O.push(g)}let x=r.getIntent(g,u);if(x?.kind==="set"){N=se(x.value);break}if(x===void 0&&g.atomOverrides.has(u)){N=se(g.atomOverrides.get(u));break}g=g.parent}if(N??=this.#se(r,u),T!==void 0)bn(f,u,T,N),this.recordCounter(17);if(O!==void 0)for(let D of O)bn(f,u,D,N),this.recordCounter(17);return N}#se(r,l){let u=this.#t.get(l);if(u!==void 0)return u;let f=r.getFallback(l);if(f!==void 0)return f;let A=this.#O(l);if(A.fallback.kind==="eager")return se(A.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ae(r){let l=this.#t.get(r);if(l!==void 0)return l;let u=this.#O(r);if(u.fallback.kind==="eager")return se(u.fallback.value);throw Error("Committed Atom fallback is not materialized")}#de(r,l){let u=r,f=[],A;while(!0){let g=u.getAtomView(l);if(g!==void 0){A=g;break}if(u.atomOverrides.has(l)){A=u.createAtomView(l,se(u.atomOverrides.get(l)));break}if(u.parent===void 0){A=u.createAtomView(l,this.#ae(l));break}f.push(u),u=u.parent}for(let g=f.length-1;g>=0;g--)A=f[g].createAtomView(l,A.served.outcome,A);return A}serveScopeAtom(r,l,u){let f=r,A=[],g;while(!0){let T=f.getAtomView(l);if(T!==void 0){g=T;break}if(f.atomOverrides.has(l)){g=f.createAtomView(l,se(f.atomOverrides.get(l)));break}if(f.parent===void 0){g=f.createAtomView(l,this.#ce(l,u));break}this.recordCounter(6),A.push(f),f=f.parent}for(let T=A.length-1;T>=0;T--)g=A[T].createAtomView(l,g.served.outcome,g);return g.served}#ce(r,l){let u=this.#t.get(r);if(u!==void 0)return u;let f=this.#O(r);if(f.fallback.kind==="eager")return se(f.fallback.value);let A=f.fallback.initialize,g=yn(c(this.#n,l,()=>Et(A)));return this.#t.set(r,g),this.recordCounter(13),g}#O(r){let l=this.#n.atoms.get(r);if(l===void 0)throw TypeError("Unknown committed StoreTree Atom");return l}propagateFromSources(r,l,u){let f=this.#d!==0;if(r===void 0&&u===void 0){if(!f)this.clearNotificationSettlement();return}if(r!==void 0)this.recordCounter(4);let A=this.#e?.beginPropagation();if(this.#R(4),this.#a=[],this.#u=!0,this.#D=u!==void 0,!f)this.settlementEpoch++;let g;try{try{if(u?.(),r?.scope.markDependents(r.atom),l!==void 0)for(let P of l)P.scope.markDependents(P.atom);let V=0;while(V<this.#a.length||this.#e?.pendingLifecycle){if(V>=this.#a.length){this.#i=void 0,this.#l=void 0,this.#f=0,this.#m=void 0,this.#e.settleLifecycle();continue}let P=this.#a[V++],H=this.#a[V++];try{this.#V(P,H)}catch(I){if(f)this.#T??={error:I};else if(u===void 0)throw I;else this.#e.failure(I,"settling")}}}finally{g=this.#N,this.#N=void 0,this.#u=!1,this.#D=!1,this.#a=void 0,this.#i=void 0,this.#l=void 0,this.#f=0,this.#m=void 0,this.#e?.endPropagation(A)}if(f)return;let T=this.#p===void 0?g:this.#le(g),O=this.#he(),N=this.#S?.[0]?.error,D=T===void 0?O:O===void 0?T:[...T,...O];if(D===void 0){if(N!==void 0)throw N;return}if(D===g&&D.length===1&&N===void 0)throw D[0];let x=new a(N===void 0?D:[N,...D]);throw this.#e?.notificationFailure(x)??x}finally{if(!f)this.#S=void 0}}#le(r){let l,u=0;try{for(let f=0;this.#p!==void 0;f++){if(l=this.#p,this.#p=void 0,u=0,f===Gn){(r??=[]).push(new j);break}for(;u<l.length;u++){let A=l[u];A.pending=!1;let{reaction:g,target:T}=A;if(g===void 0||T===void 0)continue;let O=this.#ue(T.scope,g);if(O!==void 0)(r??=[]).push(O.error)}}}finally{if(l!==void 0)for(;u<l.length;u++)l[u].pending=!1}return r}#ue(r,l){let u;this.#d++;try{this.#w?.(3,r),this.#I(r,l),u=this.#T}catch(f){let A=f;try{nt(this.#n,new e,()=>{let g=t(f);if(g.kind==="thenable")n(g)})}catch(g){A=g}u={error:A}}finally{this.#d--,this.#T=void 0}try{this.#w?.(4,u!==void 0)}catch(f){u??={error:f}}return u}beginNotificationSettlement(){this.#A=void 0,this.#v=void 0,this.#y=this.#h===void 0?0:this.#b++}clearNotificationSettlement(){this.#y=0,this.#A=void 0,this.#v=void 0;let r=this.#p;if(r===void 0)return;this.#p=void 0;for(let l of r)l.pending=!1}reachSubscriptionTarget(r,l){let u=this.#y,f=this.#h?.get(r)?.get(l);if(u===0||f===void 0)return;if(f.reactions!==0)this.#fe(f);if(f.reachedEpoch===u)return;if(f.reachedEpoch=u,this.instrumented)this.recordCounter(28);if(this.#A===void 0){this.#A=f;return}if(this.#v===void 0)this.#v=[f];else this.#v.push(f)}#fe(r){let l=r.head;while(l!==void 0){if(l.reaction!==void 0&&!l.pending&&l.status!=="provisional")l.pending=!0,(this.#p??=[]).push(l);l=l.next}}#he(){let r=this.#A;if(r===void 0){this.clearNotificationSettlement();return}let l,u,f=(N)=>{let D=N.head;while(D!==void 0){let x=!this.#e?D.callback:this.#e.notificationCallback(D);if(x!==void 0)if(l===void 0)l=x;else if(u===void 0)u=[l,x];else u.push(x);D=D.next}};f(r);let A=this.#v;if(A!==void 0)for(let N of A)f(N);if(this.clearNotificationSettlement(),l===void 0)return;this.#R(7);let g=Object.freeze(u??[l]),T=this.instrumented;if(T)this.recordCounter(29);let O;for(let N of g){if(T)this.recordCounter(30);let D=new e;try{cn(this.#n,D,()=>{let x;try{if(x=t(N()),x.kind==="thenable")n(x)}catch(V){let P=t(V);if(P.kind==="thenable")n(P);throw V}if(x.kind==="inspection-error")throw x.error})}catch(x){if((O??=[]).push(x),T)this.recordCounter(31)}}return O}reportSelectorFailure(r){if(this.#a===void 0)return;if(this.#d!==0)this.#T??={error:r};else if(this.#D)this.#e.failure(r,"settling");else(this.#N??=[]).push(r)}enqueueSelector(r,l){let u=this.#a;if(u===void 0)return!1;let f=this.#q(r,l);if((f&4)!==0)this.#k(r,l,0,5),f&=-6;if((f&1)!==0)return!0;return this.#k(r,l,1),u.push(r,l),!0}prepareSelectorRead(r,l,u){if(this.#a===void 0)return;if(this.#e?.skipSelectorRead(r,l,u))return;this.#V(r,l,u)}#V(r,l,u){let f=this.#q(r,l);if((f&6)!==0)return;this.#k(r,l,8);try{let A=r.getSelectorGraphVersion(),g=(f&8)!==0?void 0:r.getCommittedSelectorDependencies(l);if(g!==void 0){for(let T of g)if(this.#n.selectors.has(T.node))this.#V(r,T.node)}if(r.isSelectorDirty(l)){this.#k(r,l,2);let T=A===r.getSelectorGraphVersion(),O=u!==void 0&&T?u:new e;try{r.serve(l,O)}catch(N){if(this.#e?.dormantPull===!0)throw N;r.publishEscapedFailure(l,N,O)}}this.#k(r,l,4)}catch(A){if(this.#e?.recordSelectorFault(r,l,A))this.#k(r,l,4);throw A}finally{this.#k(r,l,0,10&~f)}}#q(r,l){if(Object.is(this.#i,r)&&Object.is(this.#l,l))return this.#f;return this.#m?.get(r)?.get(l)??0}#k(r,l,u,f=0){if(this.#i===void 0){this.#i=r,this.#l=l,this.#f=u&~f;return}if(Object.is(this.#i,r)&&Object.is(this.#l,l)){this.#f=(this.#f|u)&~f;return}let A=this.#m;if(A===void 0)A=new Map,this.#m=A;let g=A.get(r);if(g===void 0)g=new Map,A.set(r,g);g.set(l,((g.get(l)??0)|u)&~f)}latchPropagationControlFault(r){if(this.#e?.idle===!1)this.#e.failure(r.error,"settling",r.origin);else(this.#S??=[]).push(r)}#K(r,l,u,f,A,g){let T=A.outcome.kind==="value"?this.#te(u,A.outcome.value,f,g):f;r.stage(l,Object.freeze({kind:"set",atom:u,value:T,publishDraftFallback:A.reachesFallback&&r.hasFallback(u)}))}}var Zn=(r,l)=>{let u=r.coordinator,f=new e,A=l,g=le(u.runtimeDomain,A,f);if(Ae(u.runtimeDomain,"adapter readHydrationSnapshot"),r.status!=="live")throw new S;let T,O;if(g!=="invalid")if(u.runtimeDomain.atoms.has(A))T=0;else if(u.runtimeDomain.selectors.has(A)||u.runtimeDomain.externalAtoms?.has(A))T=1;else O=rt(u.runtimeDomain,A);if(T===void 0&&!O)throw TypeError("readHydrationSnapshot requires a valid State");let N=u.createDraft(),D;try{if(T===0){let x=u.readDraftAtomOutcome(N,r,A,f);if(x.kind!=="value")throw x.error;return x.value}if(T===void 0)return kn(O,N,r,A);return D=u.createScratchSelectorHost(N,r,!0),D.readSelector(A)}finally{D?.revoke(),N.close(),N.forEachFallback((x,V)=>{if(u.fallbackRecords.has(x))return;u.fallbackRecords.set(x,V),u.recordCounter(13)}),N.release()}};class Ft{constructor(r,l,u){this.get=(f)=>r.get(l,f),this.sub=(f,A)=>r.sub(l,f,A),this.set=(f,A)=>r.mutate(void 0,l,"set",f,A),this.update=(f,A)=>r.mutate(void 0,l,"update",f,A),this.reset=(f)=>r.mutate(void 0,l,"reset",f),this.delete=(f)=>r.mutate(void 0,l,"delete",f),this.txn=(f,A)=>r.txn(l,f,A),this.scope=function(f){return r.scope(l,arguments.length,f)},this.dispose=()=>r.dispose(l),l.installFacade(this),ot(this,r.runtimeDomain.ownerToken),r.runtimeDomain.stores.set(this,l),r.recordCounter(8),u?.(0,this,l),Object.freeze(this)}}var Rn=(r)=>{if(r.equal!==void 0&&typeof r.equal!=="function")throw TypeError("Atom equal must be a function");return{...r.name===void 0?{}:{name:r.name},...r.equal===void 0?{}:{equal:r.equal}}},Tn=()=>{let r={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0};return Object.freeze({[X]:r})},Fe=(r,l,u={})=>{let f=r[X];b(f);let A=new e,g=c(f,A,()=>tt(l));if(g.kind==="error")throw g.error;let T=k(f,F("atom"));return f.atoms.set(T,Object.freeze({fallback:Object.freeze({kind:"eager",value:g.value}),...Rn(u)})),T},Be=(r,l,u={})=>{let f=r[X];if(b(f),typeof l!=="function")throw TypeError("atomLazy requires an initializer function");let A=k(f,F("atom"));return f.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:l}),...Rn(u)})),A},me=(r,l,u={})=>{let f=r[X];if(b(f),typeof l!=="function")throw TypeError("selector requires a getter function");if(u.equal!==void 0&&typeof u.equal!=="function")throw TypeError("selector equal must be a function");let A=k(f,F("selector")),g=Object.freeze({node:A,get:l,...u.name===void 0?{}:{name:u.name},...u.equal===void 0?{}:{equal:u.equal}});return f.selectors.set(A,g),A},ze=(r)=>{let l=r[X],u=(g)=>{let T=new e;if(le(l,g,T)==="invalid")return;return l.stores.get(g)};return Object.freeze({assertStore:(g)=>{let T=u(g);if(Ae(l,"adapter assertStore"),T===void 0)throw TypeError("assertStore requires a valid Store");if(T.status!=="live")throw new S},read:(g,T)=>{if(u(g)===void 0)throw bt(l,"adapter read"),TypeError("read requires a valid Store");return g.get(T)},subscribe:(g,T,O)=>{if(u(g)===void 0)throw Ae(l,"adapter subscribe"),TypeError("subscribe requires a valid Store");return g.sub(T,O)},readHydrationSnapshot:(g,T)=>{let O=u(g);if(O===void 0)throw Ae(l,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return Zn(O,T)}})},we=(r,l,u)=>{let f=r[X];Ae(f,"createStoreTree");let A=new wn(f,l,u);return new Ft(A,A.rootScope,u)};var o=Tn(),He=(r,l)=>we(o,r,l);
|
|
2
|
+
export{p,Ce,ye,e,i,pe,De,M,a,d,v,j,w,C,h,m,y,S,L,_,R,t,n,E,c,Se,be,b,F,k,s,ge,Ne,Pe,Ve,B,ve,he,Me,z,Re,je,Le,_e,Fe,Be,me,ze,we,o,He};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var G=35,U=36,X=37,x=38,Y=39,l=40,r=41,f=42,J=43,Q=44,Z=45,ee=46,te=47,A=48,I=64,Ie=65,Te=66,ne=67,T=68,Oe=69,oe=70,O=71,re=72,D=73,N=74,ie=75,se=76,ae=49,ce=50,g=51,le=52,P=53,de=54,ue=55,fe=56,V=57;
|
|
2
|
+
export{G,U,X,x,Y,l,r,f,J,Q,Z,ee,te,A,I,Ie,Te,ne,T,Oe,oe,O,re,D,N,ie,se,ae,ce,g,le,P,de,ue,fe,V};
|
|
@@ -0,0 +1,2 @@
|
|
|
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},Ee=(e,n)=>w(e,n);
|
|
2
|
+
export{Ee};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{G,U,X,x,Y,l,r,f,J,Q,Z,ee,te,A,I,Ie,Te,ne,T,Oe,oe,O,re,D,N,ie,se,ue}from"./chunk-3k27f6h5.js";import{t,n,c,s,ge,Pe,B,ve,he,z,Re,me}from"./chunk-2shwp485.js";var Ro={ref:(h)=>new WeakRef(h),registry:(h)=>{let m=new FinalizationRegistry(h);return Object.freeze({register:(C,R,L)=>m.register(C,R,L),unregister:(C)=>m.unregister(C)})}};class u{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(h,m,C=Ro,R){this.#o=h,this.#t=R,this.#r=m,this.#n=C.registry((L)=>{let we=L.route;if(we.entry!==L)return;we.entry=void 0,this.#d(we)}),this.#i=(L)=>C.ref(L)}#i;getOrCreateOne(h,m){return this.#s(this.#l(this.#e,h),m)}getOrCreateTuple(h,m){let C=this.#e;for(let R=0;R<h.length;R++)C=this.#l(C,h[R]);return this.#s(C,m)}get routeCount(){let h=0,m=(C)=>{if(C.children===void 0)return;for(let R of C.children.values())h++,m(R)};return m(this.#e),h}hasRoute(h){let m=this.#e;for(let C=0;C<h.length;C++){let R=m.children?.get(h[C]);if(R===void 0)return!1;m=R}return!0}#l(h,m){let C=h.children??(h.children=new Map),R=C.get(m);if(R!==void 0)return R;return R={parent:h,parentKey:m,children:void 0,entry:void 0},C.set(m,R),R}#s(h,m){let C=h.entry;if(C?.kind==="ready"){let L=C.reference.deref();if(L!==void 0)return L;if(this.#n.unregister(C),h.entry===C)h.entry=void 0}else if(C?.kind==="building"){let L=C.fault??this.#r();throw C.fault=L,L}let R={kind:"building",route:h,fault:void 0};h.entry=R;try{let L=this.#o(m);if(R.fault!==void 0)throw R.fault;this.#t?.(L);let we={kind:"ready",route:h,reference:this.#i(L)};return h.entry=we,this.#n.register(L,we,we),L}catch(L){if(h.entry===R)h.entry=void 0;throw this.#d(h),R.fault??L}}#d(h){let m=h;while(m.parent!==void 0&&m.entry===void 0&&(m.children===void 0||m.children.size===0)){let C=m.parent,R=C.children;if(R?.get(m.parentKey)!==m)return;if(R.delete(m.parentKey),R.size===0)C.children=void 0;m=C}}}class Tn{entries=new Map;tail;nextRank=0;constructor(h){for(let m of h)this.append(m)}append(h){let m=this.tail;if(this.entries.set(h,{rank:this.nextRank++,previous:m}),m!==void 0)this.entries.get(m).next=h;this.tail=h}remove(h){let m=this.entries.get(h);if(m===void 0)return;if(m.previous!==void 0)this.entries.get(m.previous).next=m.next;if(m.next!==void 0)this.entries.get(m.next).previous=m.previous;else this.tail=m.previous;this.entries.delete(h)}changes(h,m){if(h.length!==m.length)return!0;let C=new Set(h),R=this.tail;for(let L=m.length-1;L>=0;L--){if(m[L]!==R||!C.has(m[L]))return!0;R=this.entries.get(R)?.previous}return!1}}var qe=Symbol("collection baseline birth"),So=(h,m)=>{let C=new Map,R=new Set(m);for(let we of h)if(!R.has(we))C.set(we,{baselinePresent:!0,transitions:[],birth:void 0});let L=new Set(h);for(let we of m)if(!L.has(we))C.set(we,{baselinePresent:!1,transitions:[],birth:0});return C},go=(h,m)=>{for(let C=h.parent;C!==void 0;C=C.parent)if(C===m)return!0;return!1};class yn extends Error{seal(){Object.freeze(this)}}class H extends yn{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class W extends yn{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class K extends yn{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var an=Object.freeze({kind:"none"}),wn=Object.freeze({kind:"absent"}),Fe=Object.freeze({kind:"absent"}),Ke=Object.freeze([]),fn=(h)=>Object.freeze({kind:"present",value:h}),Ze=(h)=>Object.freeze({kind:"present",value:h}),mn=(h,m)=>h.kind===m.kind&&(h.kind==="absent"||m.kind==="present"&&Object.is(h.value,m.value)),Zn=(h,m)=>h.kind===m.kind&&(h.kind!=="present"||m.kind==="present"&&Object.is(h.value,m.value)),tn=(h)=>{let m=h.local.kind==="present"?fn(h.local.value):h.local.kind==="absent"?wn:an,C=h.effective.kind==="present"?Ze(h.effective.value):Fe,R=h.inherited.kind==="present"?Ze(h.inherited.value):Fe;if(m.kind==="none"&&!mn(C,R))throw Error("Collection baseline without local ownership must equal inherited outcome");if(m.kind==="present"&&(C.kind!=="present"||!Object.is(m.value,C.value)))throw Error("Collection present local baseline must equal its effective outcome");if(m.kind==="absent"&&C.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:m,effective:C,inherited:R})},bn=(h)=>{let m=h.final;if(m===void 0)return h.baseline.local;if(m.kind==="present")return fn(m.value);return m.kind==="absent"?wn:an},Xn=(h,m)=>h.kind==="present"?Ze(h.value):h.kind==="absent"?Fe:m,Jn=(h)=>Object.freeze({kind:"value",value:h.kind==="present"?h.value:void 0}),Qn=(h,m)=>{let C,R=new WeakMap,L=new WeakMap,we,Le,De=(i)=>i.coordinator?.evaluate?.recordExtension,ae=(i,e,o=1)=>{De(i)?.(e,o)},je=(i,e,o,a)=>{De(i)?.(e,i,o,a)},Ne=(i,e,o)=>{if(e.length!==o.length)return!1;let a=De(i);if(a===void 0){for(let d=0;d<e.length;d++)if(!Object.is(e[d],o[d]))return!1;return!0}for(let d=0;d<e.length;d++)if(!Object.is(e[d],o[d]))return a(r,d+1),!1;if(e.length)a(r,e.length);return!0},ln=(i)=>{let e=L.get(i);if(e!==void 0)return e;return e={rowLocals:void 0,ownedRows:void 0,rowViews:void 0,liveRowViews:void 0,memberships:void 0,liveMemberships:void 0},L.set(i,e),e},Me=(i,e)=>L.get(i)?.rowLocals?.get(e)??an,Ee=(i,e)=>{let o=i;while(o!==void 0){let a=Me(o,e);if(a.kind==="present")return Ze(a.value);if(a.kind==="absent")return Fe;o=o.parent}return Fe},Xe=m??((i,e)=>{let o=Me(i,e),a=Ee(i.parent,e);return Object.freeze({local:o,effective:Xn(o,a),inherited:a})}),eo=(i,e,o,a)=>{let d=i.byScope.get(e)?.get(o);if(d!==void 0)return bn(d);return tn(Xe(e,o,a)).local},_e=(i,e,o,a)=>{let d=e;while(d!==void 0){let b=eo(i,d,o,a);if(b.kind==="present")return Ze(b.value);if(b.kind==="absent")return Fe;if(m!==void 0){let w=i.byScope.get(d)?.get(o);if(w!==void 0)return w.baseline.inherited;return tn(Xe(d,o,a)).inherited}d=d.parent}return Fe},no=(i,e,o,a)=>{if(m!==void 0){let d=tn(Xe(e,o,a)),b=d.effective.kind==="present",w=b?qe:void 0;for(let y of i.byRow.get(o)?.historyByScope.get(e)??[]){if(!Object.is(y.row,o)||!Object.is(y.scope,e))continue;let S=y.kind==="present"||y.kind==="reset"&&d.inherited.kind==="present";if(!b&&S)w=y.sequence;else if(!S)w=void 0;b=S}return w}return Kn(i,e,o,a,void 0)},Rn=(i,e,o,a)=>{let d=ln(i),b=d.rowViews?.get(e);if(b!==void 0)return b;let w={scope:i,atom:e,served:Object.freeze({token:i.createOutcomeToken(),outcome:Jn(o)}),inheritedFrom:a,inheritingChildren:new s(()=>i.coordinator.recordCounter(2))},y=d.rowViews;if(y===void 0)y=new WeakMap,d.rowViews=y;let S=d.liveRowViews;if(S===void 0)S=new s(()=>i.coordinator.recordCounter(2)),d.liveRowViews=S;if(y.set(e,w),S.add(w),je(i,ie,e,h.lookupRow(e)),a!==void 0)a.inheritingChildren.add(w),i.coordinator.recordCounter(11);return w},xn=(i,e)=>{let o=i,a=[],d;while(!0){ae(o,x);let b=L.get(o),w=b?.rowViews?.get(e);if(w!==void 0){d=w;break}let y=b?.rowLocals?.get(e);if(y!==void 0){d=Rn(o,e,y.kind==="present"?Ze(y.value):Fe);break}if(o.parent===void 0){d=Rn(o,e,Fe);break}a.push(o),o=o.parent}for(let b=a.length-1;b>=0;b--)d=Rn(a[b],e,d.served.outcome.kind==="value"&&d.served.outcome.value!==void 0?Ze(d.served.outcome.value):Fe,d);return d},Sn=(i)=>{let e=i.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(i),i.inheritedFrom=void 0,i.scope.coordinator.recordCounter(12)},oo=(i,e)=>{if(Object.is(i.inheritedFrom,e))return;Sn(i),i.inheritedFrom=e,e.inheritingChildren.add(i),i.scope.coordinator.recordCounter(11)},We=(i)=>{if(i.snapshotDirty){let e=Object.freeze([...i.ordered.entries.keys()]);ae(i.scope,r,e.length),ae(i.scope,f),i.served=en(i.scope,e,i.served.token),i.snapshotDirty=!1}return i.served.outcome.kind==="value"?i.served.outcome.value:Ke},to=(i,e)=>{let o=nn(i,e),a=o;while(a!==void 0&&a.ordered===void 0){a.ordered=new Tn(We(a));let d=a.inheritedFrom;if(d!==void 0)(d.indexedChildren??=new s).add(a);a=d}return o.ordered},gn=(i,e)=>{if(e.length)ae(i,r,e.length);let o=Object.freeze([...e]);return ae(i,f),o},en=(i,e,o=i.createOutcomeToken())=>Object.freeze({token:o,outcome:Object.freeze({kind:"value",value:e})}),kn=(i,e,o,a=!1)=>{let d=ln(i),b=d.memberships?.get(e);if(b!==void 0)return b;let w={scope:i,atom:e,served:en(i,o,a?Ke:void 0),inheritedFrom:void 0,inheritingChildren:new s(()=>i.coordinator.recordCounter(2))},y=d.memberships;if(y===void 0)y=new WeakMap,d.memberships=y;let S=d.liveMemberships;if(S===void 0)S=new s(()=>i.coordinator.recordCounter(2)),d.liveMemberships=S;return y.set(e,w),S.add(w),ae(i,Y),je(i,se,e),w},Hn=(i)=>{let e=i.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(i),e.indexedChildren?.delete(i),i.inheritedFrom=void 0,i.scope.coordinator.recordCounter(12)},In=(i,e)=>{if(Object.is(i.inheritedFrom,e))return;Hn(i),i.inheritedFrom=e,e.inheritingChildren.add(i),i.scope.coordinator.recordCounter(11)},nn=(i,e)=>{let o=i,a=[],d;while(!0){ae(o,l);let b=L.get(o)?.memberships?.get(e);if(b!==void 0){if(d=b,d.served.token===Ke){let w=gn(o,We(d));d.served=en(o,w)}break}if(o.parent===void 0){d=kn(o,e,gn(o,Ke));break}a.push(o),o=o.parent}for(let b=a.length-1;b>=0;b--){let w=a[b],y=gn(w,We(d)),S=kn(w,e,y);In(S,d),d=S}return d},ro=(i)=>{let e=i;C?.release(e);let o=R.get(e);if(o===void 0)return;R.delete(e);for(let a of o.byScope.values()){for(let d of a.values())d.final=void 0,d.finalOperation=void 0;a.clear()}o.byScope.clear(),o.planOrder.length=0,o.history.length=0;for(let a of o.historyByCollectionScope.values()){for(let d of a.values())d.length=0;a.clear()}o.historyByCollectionScope.clear();for(let a of o.byRow.values()){for(let d of a.coordinatesByAncestor.values())d.length=0;a.coordinatesByAncestor.clear();for(let d of a.historyByScope.values())d.length=0;a.historyByScope.clear()}o.byRow.clear(),o.revisionByCollection.clear(),o.queryRevisionByCollection?.clear();for(let a of o.membershipMemo.values())a.clear();o.membershipMemo.clear()},Je=(i)=>{let e=R.get(i);if(e!==void 0)return e;return e={byScope:new Map,planOrder:[],history:[],historyByCollectionScope:new Map,byRow:new Map,revisionByCollection:new Map,membershipMemo:new Map,nextDiscoveryIndex:0,hasAcceptedIntent:!1},i.installRows(ro),R.set(i,e),e},sn=(i)=>{let e=h.lookupRow(i);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},Ln=(i,e)=>{i.revisionByCollection.set(e,(i.revisionByCollection.get(e)??0)+1)},io=(i,e)=>{Ln(i,e);let o=i.queryRevisionByCollection?.get(e);if(o!==void 0)i.queryRevisionByCollection.set(e,o+1)},Pn=(i,e)=>{for(let o of i.rebased?.values()??[])if(o.collections.has(e))return!0;return!1},on=(i,e,o,a=sn(o))=>{let d=Je(i),b=d.byScope.get(e);if(b===void 0)b=new Map,d.byScope.set(e,b);let w=b.get(o);if(w!==void 0)return w;if(Le!==void 0)Le.coordinates++;let y=tn(Xe(e,o,a)),S=m===void 0?_e(d,e.parent,o,a):y.inherited,ye=tn({local:y.local,effective:Xn(y.local,S),inherited:S});w={scope:e,row:o,collection:a,baseline:ye,discoveryIndex:d.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},b.set(o,w);let F=d.byRow.get(o);if(F===void 0)F={coordinatesByAncestor:new Map,historyByScope:new Map},d.byRow.set(o,F);let be=e;while(be!==void 0){let V=F.coordinatesByAncestor.get(be);if(V===void 0)V=[],F.coordinatesByAncestor.set(be,V);V.push(w),be=be.parent}return w.enablingBirth=no(d,e,o,a),w},un=(i,e,o,a,d,b)=>{let w=bn(e),y=Je(i),S=_e(y,e.scope,e.row,e.collection);if(Zn(w,d)&&mn(S,b))return;if(!y.hasAcceptedIntent)y.hasAcceptedIntent=!0,ae(e.scope,U);ae(e.scope,G);let ye=[];for(let ze of y.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let Be=_e(y,ze.scope,ze.row,ze.collection);ye.push({coordinate:ze,effective:Be,placement:Be.kind==="present"?ze.enablingBirth:void 0})}let F=i.generation;if(e.planIndex===void 0)e.planIndex=y.planOrder.length,y.planOrder.push(e);e.final=a,e.finalOperation=o;let be=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:a.kind,sequence:F});y.history.push(be);let V=y.byRow.get(e.row),fe=V.historyByScope.get(e.scope);if(fe===void 0)fe=[],V.historyByScope.set(e.scope,fe);fe.push(be);let ce=y.historyByCollectionScope.get(e.collection);if(ce===void 0)ce=new Map,y.historyByCollectionScope.set(e.collection,ce);let pe=ce.get(e.scope);if(pe===void 0)pe=[],ce.set(e.scope,pe);let Ce=pe.length===0;pe.push(be);let He=!1;for(let ze of ye){let Be=ze.coordinate,$e=_e(y,Be.scope,Be.row,Be.collection);if(ze.effective.kind==="absent"&&$e.kind==="present")Be.enablingBirth=F;else if($e.kind==="absent")Be.enablingBirth=void 0;let cn=$e.kind==="present"?Be.enablingBirth:void 0;if(!Object.is(ze.placement,cn))He=!0}if(He||Ce&&y.rebased!==void 0&&Pn(y,e.collection)&&Ge(y,e.scope,e.collection)===void 0)Ln(y,e.collection);let dn=y.queryRevisionByCollection?.get(e.collection);if(dn!==void 0)y.queryRevisionByCollection.set(e.collection,dn+1);i.markRow(F)},jn=()=>new H,Vn=(i)=>{let e=h.inspectThenable(i);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw h.containThenable(e),jn();if(i===void 0)throw new W;return i},lo=(i,e,o)=>h.runGuarded(o,()=>{let a;try{a=Reflect.apply(i,void 0,[e])}catch(d){let b=h.inspectThenable(d);if(b.kind==="not-thenable")throw d;if(b.kind==="inspection-error")throw b.error;throw h.containThenable(b),jn()}return Vn(a)}),Bn=(i,e,o,a,d)=>{let b=sn(o),w=h.runGuarded(d,()=>Vn(a)),y=on(i,e,o,b);un(i,y,"set",Object.freeze({kind:"present",value:w}),fn(w),Ze(w))},An=(i,e,o,a,d)=>{let b=sn(o);if(typeof a!=="function")throw TypeError("Collection row update requires an updater");let w=on(i,e,o,b),y=_e(Je(i),e,o,b);if(y.kind==="absent")throw new K;let S=lo(a,y.value,d);un(i,w,"update",Object.freeze({kind:"present",value:S}),fn(S),Ze(S))},_n=(i,e,o)=>{let a=on(i,e,o);un(i,a,"delete",Object.freeze({kind:"absent"}),wn,Fe)},vn=(i,e,o)=>{let a=on(i,e,o),d=m===void 0?_e(Je(i),e.parent,o,a.collection):a.baseline.inherited;un(i,a,"reset",Object.freeze({kind:"reset"}),an,d)},so=(i,e)=>{let o=i.generation,a=[],d=L.get(e)?.ownedRows;if(d!==void 0)for(let V of d)a.push(V);let b=R.get(i)?.byScope.get(e);if(b!==void 0){let V=[];for(let fe of b.values())if(fe.planIndex!==void 0)V.push(fe);V.sort((fe,ce)=>fe.planIndex-ce.planIndex);for(let fe of V)a.push(fe.row)}let w=new Set,y=[];for(let V of a){if(w.has(V))continue;w.add(V);let fe=b?.get(V);if(fe!==void 0){if(bn(fe).kind==="none")continue}else if(d?.has(V)!==!0)continue;y.push(V)}if(y.length>1&&!e.children.isEmpty()){let V=new Set(y),fe=[];for(let ce of new Set(y.map(sn)))for(let pe of rn(i,e.parent,ce))if(V.delete(pe))fe.push(pe);for(let ce of y)if(V.has(ce))fe.push(ce);y.length=0,y.push(...fe)}for(let V of y)vn(i,e,V);let S=new Set;for(let V of w)S.add(sn(V));L.get(e)?.liveMemberships?.forEach((V)=>{if(V.localHistory)S.add(V.atom)});let ye=Je(i);for(let V=e.parent;V!==void 0;V=V.parent)for(let fe of ye.rebased?.get(V)?.collections??[])S.add(fe);let F=ye.cleared?.get(e);if(F!==void 0)for(let V of F.collections)S.add(V);let be={start:o,end:i.generation,collections:S};if((ye.cleared??=new Map).set(e,be),S.size===0)return;(ye.rebased??=new Map).set(e,be);for(let[V,fe]of ye.cleared){if(V===e||!go(V,e))continue;for(let ce of S)fe.collections.add(ce);ye.rebased.set(V,fe)}for(let V of S)io(ye,V);i.markRow(i.generation)},zn=(i,e,o,a,d,b)=>{if(i.historyByCollectionScope.get(o)?.get(e)?.length)return!1;if(a.length!==d.length)return!1;for(let y=0;y<a.length;y++)if(a[y]!==d[y])return!1;let w;for(let y of L.get(e)?.ownedRows??[]){if(h.lookupRow(y)!==o)continue;if(w??=new Set(b()),Me(e,y).kind==="present"!==w.has(y))return!1}return!0},Ge=(i,e,o)=>{let a=i.rebased?.get(e);return a?.collections.has(o)?a:void 0},co=(i,e,o)=>{for(let a=e.parent;a!==void 0;a=a.parent)if(Ge(i,a,o)!==void 0)return!0;return!1},Mn=(i,e,o,a)=>{if(Ge(e,o,a)!==void 0)return!1;let d=o.parent;if(d===void 0)return!1;if(Ge(e,d,a)===void 0&&!Mn(i,e,d,a))return!1;return zn(e,o,a,We(nn(o,a)),We(nn(d,a)),()=>rn(i,d,a))},Kn=(i,e,o,a,d)=>{let b=[],w=new Set,y=new Map,S=e,ye=d!==void 0;while(S!==void 0){if(S===d)ye=!1;if(b.push(S),ye&&Ge(i,S,a)!==void 0)w.add(S);y.set(S,w.has(S)?"none":tn(Xe(S,o,a)).local.kind),S=S.parent}let F=[],be=i.byRow.get(o);if(be!==void 0){for(let pe of b){let Ce=w.has(pe)?Ge(i,pe,a):void 0;for(let He of be.historyByScope.get(pe)??[])if(Ce===void 0||He.sequence>=Ce.start)F.push(He)}F.sort((pe,Ce)=>pe.sequence-Ce.sequence)}let V=()=>{for(let pe of b){let Ce=y.get(pe);if(Ce==="present")return!0;if(Ce==="absent")return!1}return!1},fe=V(),ce=fe?qe:void 0;for(let pe of F){y.set(pe.scope,pe.kind==="present"?"present":pe.kind==="absent"?"absent":"none");let Ce=V();if(!fe&&Ce)ce=pe.sequence;else if(!Ce)ce=void 0;fe=Ce}return ce},Fn=(i,e,o,a,d)=>{let b=i.historyByCollectionScope.get(o),w=new Map,y=e;while(y!==void 0){for(let F of b?.get(y)??[])if(!w.has(F.row))w.set(F.row,Kn(i,e,F.row,o,d));y=y.parent}let S=[];for(let F of a)if(!w.has(F)||w.get(F)===qe)S.push(F);let ye=[];for(let[F,be]of w)if(typeof be==="number")ye.push({row:F,birth:be});ye.sort((F,be)=>F.birth-be.birth);for(let{row:F}of ye)S.push(F);return S},ao=(i,e,o,a)=>{let d=o.parent;while(Ge(e,d,a)!==void 0||Mn(i,e,d,a))d=d.parent;return d},Wn=(i,e,o)=>{let a=on(i,e,o),d=_e(Je(i),e,o,a.collection);return d.kind==="present"?d.value:void 0},rn=(i,e,o)=>{if(!h.lookupCollection(o))throw TypeError("Collection draft read requires a valid collection");let a=Je(i),d=a.revisionByCollection.get(o)??0,b=a.membershipMemo.get(e),w=b?.get(o);if(w?.revision===d)return w.rows;if(a.rebased!==void 0&&(Ge(a,e,o)!==void 0||Mn(i,a,e,o))){let ce;if(Ge(a,e,o)!==void 0){let He=ao(i,a,e,o);ce=Fn(a,e,o,We(nn(He,o)),He)}else ce=rn(i,e.parent,o);let pe=We(nn(e,o)),Ce=Ne(e,pe,ce)?pe:w!==void 0&&Ne(e,w.rows,ce)?w.rows:Object.freeze([...ce]);if(b===void 0)b=new Map,a.membershipMemo.set(e,b);return b.set(o,{revision:d,rows:Ce}),Ce}let y=m===void 0&&typeof e.createOutcomeToken==="function"?We(nn(e,o)):Ke,S=new Map,ye=a.historyByCollectionScope.get(o),F=e;while(F!==void 0){for(let ce of ye?.get(F)??[])if(!S.has(ce.row))S.set(ce.row,on(i,e,ce.row,o));F=F.parent}let be=[];if(y.length)ae(e,r,y.length);for(let ce of y){let pe=S.get(ce);if(pe===void 0||pe.enablingBirth===qe)be.push(ce)}let V=[];if(S.size!==0)ae(e,r,S.size);for(let ce of S.values())if(typeof ce.enablingBirth==="number"&&_e(a,ce.scope,ce.row,ce.collection).kind==="present")V.push(ce);V.sort((ce,pe)=>{let Ce=ce.enablingBirth,He=pe.enablingBirth;if(Ce===He)return ce.discoveryIndex-pe.discoveryIndex;return Ce-He});for(let ce of V)be.push(ce.row);let fe;if(Ne(e,y,be))fe=y;else if(w!==void 0&&Ne(e,w.rows,be))fe=w.rows;else fe=Object.freeze(be),ae(e,f);if(b===void 0)b=new Map,a.membershipMemo.set(e,b);return b.set(o,Object.freeze({revision:d,rows:fe})),fe},fo=(i)=>{let e=R.get(i);if(e===void 0)return;let o=0;for(let b of e.membershipMemo.values())o+=b.size;let a=new WeakMap;for(let[b,w]of e.revisionByCollection)a.set(b,Object.freeze({value:w}));let d=(b)=>Object.freeze({id:b.discoveryIndex,baselineLocal:b.baseline.local.kind,baselineEffective:b.baseline.effective.kind,baselineInherited:b.baseline.inherited.kind,final:b.final?.kind,enablingBirth:b.enablingBirth===qe?"baseline":b.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((b)=>[...b.values()]).sort((b,w)=>b.discoveryIndex-w.discoveryIndex).map(d)),planOrder:Object.freeze(e.planOrder.map(d)),history:Object.freeze(e.history.map((b)=>Object.freeze({coordinateId:b.coordinateId,kind:b.kind,sequence:b.sequence}))),membershipMemoCount:o,revision:(b)=>a.get(b)?.value??0})},uo=(i)=>{let e=i;if(!e.hasRows)return;let o=R.get(e);if(o===void 0)throw Error("Collection row draft lane is missing");let a,d=[],b=[],w=[],y=[],S,ye=new WeakSet,F=new WeakMap,be=new Map,V=[],fe=new Map,ce=Object.freeze([]),pe={baselinePresent:!1,transitions:ce,birth:void 0},Ce={baselinePresent:!0,transitions:ce,birth:qe},He=new Map,dn=new Map,ze=(p)=>{let P=be.get(p.scope);if(P===void 0)P=new Map,be.set(p.scope,P);if(P.set(p.atom,p),p.existing!==void 0)F.set(p.existing,p)},Be=(p)=>{let P=F.get(p);if(P!==void 0)return P;let g=[],v=p,k;while(v!==void 0){ae(v.scope,l);let E=F.get(v);if(E!==void 0){k=E;break}g.push(v),v=v.inheritedFrom}for(let E=g.length-1;E>=0;E--){let j=g[E],M={scope:j.scope,atom:j.atom,existing:j,parent:k,beforeRows:j.ordered===void 0?We(j):Ke,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};if(j.ordered!==void 0){let le;Object.defineProperty(M,"beforeRows",{get:()=>le??=We(j)})}ze(M),k=M}return k},$e=(p,P)=>{let g=be.get(p)?.get(P);if(g!==void 0)return g;let v=[],k=p,E;while(k!==void 0){let j=be.get(k)?.get(P);if(j!==void 0){ae(k,l),E=j;break}let M=L.get(k)?.memberships?.get(P);if(M!==void 0){E=Be(M);break}ae(k,l),v.push(k),k=k.parent}for(let j=v.length-1;j>=0;j--){let M={scope:v[j],atom:P,existing:void 0,parent:E,beforeRows:E?.beforeRows??Ke,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};E?.plannedChildren.push(M),w.push(M),ze(M),E=M}return E},cn=(p)=>{let P=fe.get(p);if(P!==void 0)return P;return P={collection:p,top:void 0},fe.set(p,P),V.push(P),P},On=(p,P)=>{P.affected=!0;let g=p.top;if(g===void 0)p.top=P;let v,k=P;while(k!==void 0){if(k.containsAffected){if(v??=k,Object.is(k,g))return}else k.containsAffected=!0;k=k.parent}if(g!==void 0)p.top=v},yo=(p,P)=>{if(p.existing?.ordered!==void 0)return p.existing.ordered.entries.has(P);let g=dn.get(p);if(g===void 0){if(p.beforeRows.length)ae(p.scope,r,p.beforeRows.length);g=new Set(p.beforeRows),dn.set(p,g)}return g.has(P)},qn=(p,P,g,v)=>{if(Le!==void 0)Le.states++;let k=Me(p.scope,P).kind;if(v===void 0)return k==="none"?g:k==="present"?Ce:pe;let E=g.baselinePresent,j=k==="present"||k==="none"&&E,M=j,le=j?qe:void 0,_=[],de=0,Se=0;while(de<g.transitions.length||Se<v.length){let Ve=g.transitions[de],Qe=v[Se],Ye;if(Ve!==void 0&&(Qe===void 0||Ve.sequence<Qe.sequence))E=Ve.present,Ye=Ve.sequence,de++;else k=Qe.kind==="present"?"present":Qe.kind==="absent"?"absent":"none",Ye=Qe.sequence,Se++;let Yn=k==="present"||k==="none"&&E;if(Yn===j)continue;j=Yn,le=j?Ye:void 0,_.push({sequence:Ye,present:j})}if(!_.length)return j?Ce:pe;return{baselinePresent:M,transitions:_,birth:le}},En=(p)=>{let P=He.get(p);if(P!==void 0)return P;let g=[],v=p;while(v!==void 0&&!He.has(v))g.push(v),v=v.parent;let k=v===void 0?new Map:He.get(v);for(let E=g.length-1;E>=0;E--){let j=g[E],M=new Map;for(let _ of o.historyByCollectionScope.get(j.atom)?.get(j.scope)??[]){let de=M.get(_.row);if(de===void 0)de=[],M.set(_.row,de);de.push(_)}let le=new Map;if(k.size!==0)ae(j.scope,r,k.size);for(let[_,de]of k)le.set(_,qn(j,_,de,M.get(_))),M.delete(_);for(let[_,de]of M){let Se=j.parent!==void 0&&yo(j.parent,_)?Ce:pe;le.set(_,qn(j,_,Se,de))}He.set(j,le),k=le}return He.get(p)},pn=(p)=>p.follower??=p.rebase===void 0&&p.parent!==void 0&&(p.parent.rebase!==void 0||pn(p.parent))&&zn(o,p.scope,p.atom,p.beforeRows,p.parent.beforeRows,()=>hn(p.parent)),Co=(p)=>{if(o.rebased===void 0)return;let P;if(p.rebase!==void 0){let k=p.parent;while(k.rebase!==void 0||pn(k))k=k.parent;P=Fn(o,p.scope,p.atom,k.beforeRows,k.scope)}else if(pn(p))P=hn(p.parent);else return;let g=p.beforeRows,v=!Ne(p.scope,g,P);if(p.membershipChangedFromBefore=v,p.finalRows=p.existing!==void 0&&!v?g:Object.freeze([...P]),v&&p.existing!==void 0&&De(p.scope)!==void 0)p.membershipChanges=So(g,p.finalRows);if(p.existing?.ordered!==void 0&&v)p.orderedRebuild=p.finalRows,(a??=[]).push(p);return p.finalRows},hn=(p)=>{if(p.finalRows!==void 0)return p.finalRows;let P=Co(p);if(P!==void 0)return P;if(p.existing?.ordered!==void 0){let M=En(p),le=[],_=[];for(let[Se,Ve]of M){if(Ve.baselinePresent&&Ve.birth!==qe)le.push(Se);if(typeof Ve.birth==="number")_.push({row:Se,birth:Ve.birth})}_.sort((Se,Ve)=>Se.birth-Ve.birth);let de=_.map((Se)=>Se.row);return p.membershipChangedFromBefore=p.existing.ordered.changes(le,de),p.orderedPatch={removals:le,births:de},(a??=[]).push(p),p.membershipChanges=M,Ke}if(p.existing!==void 0)we?.push(p.existing);let g=[],v=[],k=p.existing!==void 0&&De(p.scope)!==void 0,E;if(m===void 0){let M=En(p);if(k)E=M;if(p.beforeRows.length)ae(p.scope,r,p.beforeRows.length);for(let le of p.beforeRows){let _=M.get(le);if(_===void 0||_.birth===qe)g.push(le)}if(M.size!==0)ae(p.scope,r,M.size);for(let[le,_]of M){if(E!==void 0&&(_.baselinePresent&&_.birth===void 0||!_.baselinePresent&&typeof _.birth==="number"))p.membershipChanges=E;if(typeof _.birth==="number")v.push({row:le,birth:_.birth})}}else{let M=new Map,le=o.historyByCollectionScope.get(p.atom),_=p.scope;while(_!==void 0){for(let de of le?.get(_)??[])if(!M.has(de.row))M.set(de.row,on(e,p.scope,de.row,p.atom));_=_.parent}if(p.beforeRows.length)ae(p.scope,r,p.beforeRows.length);for(let de of p.beforeRows){let Se=M.get(de);if(Se===void 0||Se.enablingBirth===qe)g.push(de)}if(M.size!==0)ae(p.scope,r,M.size);for(let de of M.values())if(typeof de.enablingBirth==="number"&&_e(o,de.scope,de.row,de.collection).kind==="present")v.push({row:de.row,birth:de.enablingBirth})}v.sort((M,le)=>M.birth-le.birth);for(let M of v)g.push(M.row);let j=!Ne(p.scope,p.beforeRows,g);if(p.membershipChangedFromBefore=j,p.existing!==void 0&&!j)p.finalRows=p.beforeRows;else p.finalRows=Object.freeze(g),ae(p.scope,f);return p.finalRows};for(let p of o.planOrder){let P=p.final;if(P===void 0)continue;ae(p.scope,X);let g=P.kind==="present"?fn(P.value):P.kind==="absent"&&p.scope.parent!==void 0?wn:an,v=!Zn(Me(p.scope,p.row),g);d.push(Object.freeze({coordinate:p,local:g,ownershipChanged:v}));let k=cn(p.collection),E=tn(Xe(p.scope,p.row,p.collection)),j=E.local.kind!==g.kind;if(j){if($e(p.scope,p.collection),p.scope.parent!==void 0)(S??=[]).push({scope:p.scope,collection:p.collection,history:!0})}let M=E.effective.kind==="present"?qe:void 0;if(!Object.is(M,p.enablingBirth)){if(On(k,$e(p.scope,p.collection)),!j&&p.scope.parent!==void 0)(S??=[]).push({scope:p.scope,collection:p.collection,history:!0})}let le=L.get(p.scope)?.rowViews?.get(p.row);if(le===void 0)continue;let _=[le];while(_.length){let de=_.pop();if(ye.has(de))continue;ye.add(de),ae(de.scope,x);let Se=de.served.outcome.kind==="value"&&de.served.outcome.value!==void 0?Ze(de.served.outcome.value):Fe,Ve=_e(o,de.scope,de.atom,p.collection);if(mn(Se,Ve))continue;b.push(Object.freeze({scope:de.scope,atom:de.atom,record:de,before:Se,outcome:Ve}));let Qe=[];de.inheritingChildren.forEach((Ye)=>{de.scope.coordinator.recordCounter(1),Qe.push(Ye)});for(let Ye=Qe.length-1;Ye>=0;Ye--)_.push(Qe[Ye])}}if(o.rebased!==void 0)for(let[p,P]of o.rebased){let g=o.historyByCollectionScope;for(let v of P.collections){let k=$e(p,v);k.rebase=P,On(cn(v),k),(S??=[]).push({scope:p,collection:v,history:(g.get(v)?.get(p)??[]).some((E)=>E.sequence>=P.end)})}}if(o.rebased!==void 0)for(let[p,P]of o.historyByCollectionScope){if(!Pn(o,p))continue;for(let[g,v]of P){if(v.length===0||Ge(o,g,p)!==void 0||!co(o,g,p))continue;On(cn(p),$e(g,p)),(S??=[]).push({scope:g,collection:p,history:!0})}}for(let p of V){let P=p.top;if(P===void 0)continue;let g=new Set,v=[{node:P,affected:!1}];while(v.length){let k=v.pop(),E=k.node;if(g.has(E))continue;g.add(E),ae(E.scope,l);let j=k.affected||E.affected;if(j){let le=hn(E);if(E.existing!==void 0&&(E.orderedPatch!==void 0?E.membershipChangedFromBefore:!Object.is(le,E.beforeRows)))y.push(Object.freeze({scope:E.scope,atom:E.atom,node:E,record:E.existing,rows:le}))}let M=[];E.existing?.inheritingChildren.forEach((le)=>{E.scope.coordinator.recordCounter(1);let _=j?Be(le):F.get(le);if(_!==void 0&&(j||_.containsAffected))M.push(_)});for(let le of E.plannedChildren)if(j||le.containsAffected)M.push(le);for(let le=M.length-1;le>=0;le--)v.push({node:M[le],affected:j})}}for(let p of w){if(p.finalRows!==void 0)continue;if(p.parent===void 0){hn(p);continue}p.finalRows=p.beforeRows,p.membershipChangedFromBefore=!1}let Un,Gn=o.rebased===void 0?void 0:a?.filter((p)=>p.orderedRebuild!==void 0);if(C!==void 0&&(o.planOrder.some((p)=>C.active(p.collection))||Gn?.some((p)=>C.active(p.atom)))){let p=new Map;for(let g of o.planOrder){if(!C.active(g.collection))continue;let v=L.get(g.scope)?.memberships?.get(g.collection);if(v===void 0)continue;let k=[v];while(k.length){let E=k.pop();if(E.ordered===void 0)continue;ae(E.scope,ue);let j=p.get(E);if(j===void 0)p.set(E,j=new Set);j.add(g.row),E.indexedChildren?.forEach((M)=>k.push(M))}}let P=[];for(let g of Gn??[]){let v=g.existing,k=v.ordered,E=new Map;g.orderedRebuild.forEach((M,le)=>E.set(M,k.nextRank+le));let j=[];for(let M of new Set([...k.entries.keys(),...g.orderedRebuild])){let le=Ee(v.scope,M),_=_e(o,v.scope,M,v.atom);j.push({row:M,before:le.kind==="present"?le.value:void 0,after:_.kind==="present"?_.value:void 0,rank:E.get(M)})}if(j.length)P.push({scope:v.scope,collection:v.atom,changes:j})}for(let[g,v]of p){if(g.ordered===void 0)continue;if(F.get(g)?.orderedRebuild!==void 0)continue;let k=Be(g),j=o.rebased!==void 0&&(k.rebase!==void 0||pn(k))?void 0:En(k),M=[];for(let le of v){let _=Ee(g.scope,le),de=_e(o,g.scope,le,g.atom),Se=j?.get(le)?.birth;if(mn(_,de)&&typeof Se!=="number")continue;M.push({row:le,before:_.kind==="present"?_.value:void 0,after:de.kind==="present"?de.value:void 0,rank:de.kind==="absent"?void 0:typeof Se==="number"?g.ordered.nextRank+Se:g.ordered.entries.get(le)?.rank})}if(M.length)P.push({scope:g.scope,collection:g.atom,changes:M})}Un=C.prepare(P)}return{commit:mo,indexPlan:Un,orderedNodes:a,historyMarks:S,rows:Object.freeze(d),rowSettlements:Object.freeze(b),membershipInstalls:Object.freeze(w),membershipSettlements:Object.freeze(y),sources:Object.freeze([...b,...y])}},po=(i)=>{let e=i,o=!1;for(let a of e.rowSettlements){let{record:d,before:b,outcome:w}=a;ae(d.scope,Z),je(d.scope,b.kind==="absent"?T:w.kind==="absent"?oe:Oe,d.atom,h.lookupRow(d.atom))}for(let a of e.membershipSettlements)for(let[d,b]of a.node.membershipChanges??[]){let w=b.baselinePresent&&b.birth===void 0?re:!b.baselinePresent&&typeof b.birth==="number"?O:void 0;if(w!==void 0)je(a.node.scope,w,d,a.node.atom)}for(let a of e.rows){let d=a.coordinate.finalOperation;if(d!==void 0)je(a.coordinate.scope,d==="set"?I:d==="update"?Ie:d==="reset"?Te:ne,a.coordinate.row,a.coordinate.collection);if(!a.ownershipChanged)continue;o=!0;let{row:b,scope:w}=a.coordinate;if(a.local.kind==="none"){let F=L.get(w);if(F?.rowLocals?.delete(b),F?.ownedRows?.delete(b))ae(w,A);if(F?.ownedRows?.size===0){if(F.ownedRows=void 0,F.rowLocals=void 0,F.liveRowViews===void 0&&F.liveMemberships===void 0)L.delete(w)}continue}let y=ln(w),S=y.rowLocals;if(S===void 0)S=new WeakMap,y.rowLocals=S;let ye=y.ownedRows;if(ye===void 0)ye=new Set,y.ownedRows=ye,ae(w,ee);if(S.set(b,a.local),!ye.has(b))ye.add(b),ae(w,te)}for(let a of e.membershipInstalls)a.installed=kn(a.scope,a.atom,a.finalRows,a.parent!==void 0&&a.finalRows===a.beforeRows);for(let a of e.orderedNodes??[]){let d=a.existing;if(a.orderedRebuild!==void 0){let w=d.ordered,y=w.nextRank;w.entries.clear(),w.tail=void 0,w.nextRank=y;for(let S of a.orderedRebuild)w.append(S);d.snapshotDirty=!0,d.served=en(d.scope,Ke,d.served.token);continue}let b=a.orderedPatch;if(!a.membershipChangedFromBefore)continue;for(let w of b.removals)d.ordered.remove(w);for(let w of b.births)d.ordered.append(w);d.snapshotDirty=!0,d.served=en(d.scope,Ke,d.served.token)}if(e.membershipSettlements.length)return!0;for(let a of e.membershipInstalls)if(a.membershipChangedFromBefore)return!0;return o},ho=(i)=>{let e=i;for(let o of e.rows){if(!o.ownershipChanged)continue;let{row:a,scope:d}=o.coordinate,b=L.get(d)?.rowViews?.get(a);if(b===void 0)continue;if(o.local.kind!=="none"||d.parent===void 0)Sn(b);else oo(b,xn(d.parent,a))}for(let o of e.membershipInstalls){let a=o.installed,d=o.parent?.existing??o.parent?.installed;if(a!==void 0&&d!==void 0)In(a,d)}if(e.historyMarks!==void 0)for(let{scope:o,collection:a,history:d}of e.historyMarks){let b=L.get(o)?.memberships?.get(a);if(b!==void 0)b.localHistory=d}},bo=(i)=>{let e=i;for(let a of e.rowSettlements){let{record:d,outcome:b}=a;d.served=Object.freeze({token:d.scope.createOutcomeToken(),outcome:Jn(b)}),ae(d.scope,J),je(d.scope,D,d.atom,h.lookupRow(d.atom)),d.scope.coordinator.reachSubscriptionTarget(d.scope,d.atom)}for(let a of e.membershipSettlements){let{record:d,rows:b}=a;d.served=en(d.scope,d.ordered===void 0?b:d.served.outcome.kind==="value"?d.served.outcome.value:Ke),ae(d.scope,Q),je(d.scope,N,d.atom),d.scope.coordinator.reachSubscriptionTarget(d.scope,d.atom)}let o=e.indexPlan?.publish();if(o?.length)return[...e.sources,...o];return e.sources.length?e.sources:void 0},mo=function(i){if(i===0)return po(this);if(i===1)return ho(this);return bo(this)},wo=(i)=>{let e=i;C?.dispose(e);let o=L.get(e);if(o===void 0)return;o.liveRowViews?.forEach((d)=>{Sn(d),d.inheritingChildren.clear()}),o.liveMemberships?.forEach((d)=>{Hn(d),d.inheritingChildren.clear(),d.indexedChildren?.clear(),d.ordered?.entries.clear(),d.ordered=void 0,d.snapshotDirty=!1,d.served=en(d.scope,Ke,d.served.token)}),o.liveRowViews?.clear(),o.liveMemberships?.clear();let a=o.ownedRows?.size??0;if(a!==0)ae(e,A,a);o.ownedRows?.clear(),o.rowLocals=void 0,o.ownedRows=void 0,o.rowViews=void 0,o.liveRowViews=void 0,o.memberships=void 0,o.liveMemberships=void 0,L.delete(e)};return Object.freeze({installIndexes:(i)=>C??(C=i({revision:(e,o)=>{let a=Je(e),d=a.queryRevisionByCollection??=new Map,b=d.get(o)??0;return d.set(o,b),b},membership:to,value:(e,o)=>{let a=Ee(e,o);return a.kind==="present"?a.value:void 0},draftRows:rn,draftValue:(e,o,a)=>{let d=Je(e),b=o;while(b!==void 0){let w=d.byScope.get(b)?.get(a),y=w===void 0?Me(b,a):bn(w);if(y.kind==="present")return y.value;if(y.kind==="absent")return;b=b.parent}return}})),has:(i)=>C?.has(i)===!0||h.lookupRow(i)!==void 0||h.lookupCollection(i),diagnosticName:h.lookupDiagnosticName,read:(i,e,o)=>{let a=i,d=e;if(C?.has(o))return{kind:"value",value:C.read(a,d,o)};if(h.lookupRow(o)!==void 0)return Object.freeze({kind:"value",value:Wn(a,d,o)});if(h.lookupCollection(o))return Object.freeze({kind:"value",value:rn(a,d,o)});throw TypeError("Unknown collection scratch source")},stage:(i,e,o,a,d,b)=>{let w=i,y=e;if(o==="set")Bn(w,y,a,d,b);else if(o==="update")An(w,y,a,d,b);else if(o==="delete")_n(w,y,a);else vn(w,y,a)},scope:(i,e,o)=>{if(e===void 0){wo(i);return}if(C?.has(e))return C.scope(i,e,o);if(h.lookupRow(e)!==void 0)return xn(i,e).served;if(!h.lookupCollection(e))return;let a=nn(i,e);return We(a),a.served},plan:uo,resetAll:(i,e)=>so(i,e),stageSet:Bn,stageUpdate:An,stageDelete:_n,stageReset:vn,readDraftRow:Wn,readDraftCollection:rn,beginMembershipRebuildTraceForTest:()=>{if(we!==void 0)throw Error("A membership rebuild trace is already active");let i=[];return we=i,()=>{if(i===void 0)throw Error("The membership rebuild trace is already finished");we=void 0;let e=Object.freeze([...i]);return i.length=0,i=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(Le!==void 0)throw Error("A membership placement trace is already active");let i={coordinates:0,states:0};return Le=i,()=>{if(i===void 0)throw Error("The membership placement trace is already finished");Le=void 0;let e=Object.freeze({...i});return i=void 0,e}},inspectDraft:fo})};var ko=(h)=>new WeakRef(h),Cn,vo=(h)=>{let m=ge(h),C=Cn??(Cn=new WeakMap),R=C.get(m);if(R!==void 0)return R;return R={collections:new WeakMap,rows:new WeakMap},C.set(m,R),R};class q extends Error{code="VALDRES_INVALID_COLLECTION_KEY";constructor(){super("Collection keys must be strings, finite numbers, bigints, booleans, or null");this.name="InvalidCollectionKeyError",Object.freeze(this)}}var Nn=()=>new q,Dn=(h)=>{if(h===null)return null;switch(typeof h){case"string":case"bigint":case"boolean":return h;case"number":if(!Number.isFinite(h))throw Nn();return Object.is(h,-0)?0:h;default:throw Nn()}},$n=(h)=>{throw n(h),Nn()},Mo=(h,m,C)=>B(h,"collection-encoder",(R)=>{let L;try{L=Reflect.apply(m,void 0,[R])}catch(Le){let De=t(Le);if(De.kind==="not-thenable")throw Le;if(De.kind==="inspection-error")throw De.error;return $n(De)}let we=t(L);if(we.kind==="not-thenable")return L;if(we.kind==="inspection-error")throw we.error;return $n(we)},[C],Dn,()=>TypeError("collection encodeKey cannot call family or collection accessors")),Oo=(h)=>{if(h===void 0)return{};if(typeof h!=="object"||h===null)throw TypeError("collection options must be an object");for(let R of Reflect.ownKeys(h))if(R!=="encodeKey"&&R!=="indexes"&&R!=="name")throw TypeError("collection options contain an unknown option");let m;if(Object.prototype.hasOwnProperty.call(h,"encodeKey")){let R=Reflect.get(h,"encodeKey");if(typeof R!=="function")throw TypeError("collection encodeKey must be a function");m=R}let C=Reflect.get(h,"name");return{...m===void 0?{}:{encodeKey:m},...C===void 0?{}:{name:C}}},Eo=()=>TypeError("collection cannot recursively construct the same row"),To=()=>TypeError("presence requires a same-domain CollectionRow"),No=(h,m)=>{let C=Cn?.get(ge(h));if(typeof m==="object"&&m!==null||typeof m==="function"){let R=C?.rows.get(m);if(R!==void 0)return R}throw Re(h,m),To()};function ke(h,m,C){he(h);let{encodeKey:R,name:L}=Oo(m),we;if(m!==void 0&&Object.prototype.hasOwnProperty.call(m,"indexes")){let Me=Reflect.get(m,"indexes");if(typeof Me!=="object"||Me===null||Array.isArray(Me))throw TypeError("collection indexes must be an extractor map");let Ee=Reflect.ownKeys(Me).map((Ue)=>{let Xe=Reflect.get(Me,Ue);if(typeof Ue!=="string"||typeof Xe!=="function")throw TypeError("collection indexes must be named scalar extractors");return[Ue,Xe]});if(Ee.length)we=Object.freeze(Object.fromEntries(Ee))}let Le=[],De,ae=Object.assign(function(Ee){ve(h);let Ue=R===void 0?Dn(Ee):Mo(h,R,Ee);Le[0]=Ue;try{return De.rows.getOrCreateOne(Ue,Le)}finally{Le.pop()}},{kind:"collection"}),je=z(h,ae),Ne,ln=new u((Me)=>{let Ee=Me[0];return z(h,{kind:"collection-row",key:Ee})},Eo,C,(Me)=>{if(Ne===void 0)throw Error("Collection definition registry is not ready");Ne.rows.set(Me,{definition:De,presence:void 0})});return De=Object.freeze({collection:je,indexes:we,...L===void 0?{}:{name:L},rows:ln,referencePresence:C===void 0?ko:(Me)=>C.ref(Me)}),Ne=vo(h),Ne.collections.set(je,De),Pe(h,(Me)=>Qn({lookupRow:(Ee)=>Ne.rows.get(Ee)?.definition.collection,lookupCollection:(Ee)=>Ne.collections.has(Ee),lookupDiagnosticName:(Ee)=>Ne.rows.get(Ee)?.definition?.name??Ne.collections.get(Ee)?.name,runGuarded:(Ee,Ue)=>c(Me,Ee,Ue),inspectThenable:t,containThenable:n})),je}var xe=(h,m)=>{ve(h);let C=No(h,m),R=C.presence?.deref();if(R!==void 0)return R;let L=me(h,(we)=>we(m)!==void 0);return C.presence=C.definition.referencePresence(L),L},Ae=(h,m,C)=>{let R=Cn?.get(ge(h))?.collections.get(m);if(R===void 0)throw Re(h,m),TypeError("query requires a same-domain Collection");let L=R.indexes!==void 0&&Object.prototype.hasOwnProperty.call(R.indexes,C)?R.indexes[C]:void 0;if(L===void 0)throw TypeError("query requires a declared equality index");return(we)=>B(h,"collection-encoder",(Le)=>{let De;try{De=L(Le)}catch(je){let Ne=t(je);if(Ne.kind==="thenable")throw n(Ne),TypeError("Index extractors must return a synchronous scalar");if(Ne.kind==="inspection-error")throw Ne.error;throw je}let ae=t(De);if(ae.kind==="thenable")throw n(ae),TypeError("Index extractors must return a synchronous scalar");if(ae.kind==="inspection-error")throw ae.error;return Dn(De)},[we])};
|
|
2
|
+
export{u,H,W,K,q,ke,xe,Ae};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ze,o}from"../chunk-2shwp485.js";var t=ze(o),{assertStore:a,read:s,subscribe:i,readHydrationSnapshot:n}=t;export{a as assertStore,s as read,n as readHydrationSnapshot,i as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Y,Ie=0,dt,et=!1,Kt=1024,ct=Kt,lt,Wt=(r)=>{setTimeout(()=>{throw r},0)},Gt=(r)=>{let l=(u)=>Wt(AggregateError([r,u],"Commit callback and error reporter failed"));try{let u=globalThis.reportError;if(typeof u!=="function")return Wt(r);let f=u.call(globalThis,r);if(f!==null&&(typeof f==="object"||typeof f==="function"))Promise.prototype.then.call(Promise.resolve(f),void 0,l)}catch(u){l(u)}},Nn=()=>{if(et||Y===void 0)return;let r=()=>{if(dt!==r)return;dt=void 0,Ut()};dt=r,queueMicrotask(r)},qt=()=>{let r=lt??={};setTimeout(()=>{if(lt!==r||et)return;lt=void 0,ct=Kt,Ut()},0)},Ut=()=>{if(et||Y===void 0)return;if(dt=void 0,lt===void 0)qt();et=!0;try{while(Y!==void 0&&Ie<Y.length&&ct>0){let r=Y[Ie];if(Y[Ie++]=void 0,ct--,r===void 0||r.scope.status!=="live")continue;try{let l=r.callback,u=l();if(u!==null&&(typeof u==="object"||typeof u==="function"))Promise.prototype.then.call(Promise.resolve(u),void 0,Gt)}catch(l){Gt(l)}}}finally{if(et=!1,Y!==void 0&&Ie===Y.length)Y=void 0;else if(Y!==void 0)Y.splice(0,Ie);if(Ie=0,Y!==void 0&&ct===0)qt()}},ut=(r)=>{let l=r.commitEntries;if(l===void 0)return;if(r.commitEntries=void 0,Y===void 0)Y=l;else for(let u of l)Y.push(u);Nn()},Yt=()=>{if(Y===void 0)return;for(let r=Ie;r<Y.length;r++)if(Y[r]?.scope.status!=="live")Y[r]=void 0};class Oe extends Error{#t=!0;static is(r){return typeof r==="object"&&r!==null&&#t in r}seal(){Object.freeze(this)}}var We,Qt=()=>{if(We!==void 0)return We;We="";try{let r=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");if(r?.writable===!0){let u;Error.stackTraceLimit=0;try{u=Error()}finally{Error.stackTraceLimit=r.value}let f=Object.getOwnPropertyDescriptor(u,"stack");if(f!==void 0&&"get"in f)return We="accessor",We}let l=Object.getOwnPropertyDescriptor(globalThis,"Bun");if(l!==void 0&&"value"in l&&l.writable===!1&&l.configurable===!1&&typeof l.value==="object"&&l.value!==null)We="lazy"}catch{}return We},Dn={writable:!1,configurable:!1},Xt=(r,l)=>{if(Qt()!=="lazy"){Object.freeze(r);return}for(let u of["message","code","name",l,"cause"])Object.defineProperty(r,u,Dn);Object.preventExtensions(r)},ft=(r,l,u)=>{let f=Qt()==="accessor"&&Oe.is(u)?Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"):void 0;if(f?.writable!==!0)return;Error.stackTraceLimit=0;try{return new r(l,u)}finally{Error.stackTraceLimit=f.value}};class Ye extends Oe{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;name="SelectorGetterError";constructor(r,l){super("Selector getter failed");this.selector=r,this.cause=l,Xt(this,"selector")}}class ht extends Oe{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;name="SelectorDependencyError";constructor(r,l){super("Selector dependency failed");this.dependency=r,this.cause=l,Xt(this,"dependency")}}class p extends Oe{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(r,l){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=r,this.path=Object.freeze([...l]),this.seal()}}class xe extends Oe{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(r){super(`Selector ${r} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=r,this.seal()}}class Ct extends Oe{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class pt extends Oe{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(r,l){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=r,this.cause=l,this.seal()}}class Ot extends Oe{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var $t=Object.freeze({kind:"not-thenable"}),xn=()=>{},Pn=Reflect.apply,Zt=Symbol("selector dependency path root"),tn=(r)=>{if((typeof r!=="object"||r===null)&&typeof r!=="function")return $t;try{let l=r.then;return typeof l==="function"?Object.freeze({kind:"thenable",target:r,then:l}):$t}catch(l){return Object.freeze({kind:"inspection-error",error:l})}},nn=(r)=>{try{Pn(r.then,r.target,[void 0,xn])}catch{}},jn=(r)=>Object.freeze(r),Vn=(r)=>Object.freeze(r),ie=(r,l,u,f)=>{let A=Vn(f);return Object.freeze({selector:r,token:l,outcome:jn(u),dependencies:A,attemptedPrefix:u.kind==="value"?In:Object.freeze(A.map((g)=>g.node))})},In=Object.freeze([]),St=32,Qe=8192,Mn=2*St,on=128,Fn=4096;class rn{passiveSearches;searches=0;constructor(r,l){if(this.passiveSearches=r,l!==void 0)this.diagnostics=l}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let r=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(r)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(r&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Qe,2*this.first.size);return r}hasProvenNoPath(r){if(!this.enabled)return!1;let l=this.first;if(l!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(l.has(r))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}let u=this.second;if(u!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(u.has(r))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(r){if(!this.enabled)return!1;let l=this.first;if(l!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,l.has(r))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}let u=this.second;if(u!==void 0){let f=this.passiveProbeBudget;if(f===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,u.has(r))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(f!==void 0){if(this.passiveProbeBudget=f-1,f===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(r){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let u=r.size>=St&&r.size<=Qe,f;if(this.searches===1&&u)this.first=r,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,f="initial";else if(this.searches===this.passiveSearches&&u)f=this.first===void 0?"initial":"activation-replacement",this.first=r,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(f);return}if((this.hits??0)!==0){if(r.size>Qe){this.disable("over-cap-hit");return}let u=this.first,f=this.second,A=this.firstIndependentlyClosed===!0,g=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(u,A),this.retain(f,g);let T=this.retain(r,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(T?"hit-derived":void 0);return}if(r.size===1){this.completeDiagnostics();return}let l=r.size>=St&&r.size<=Qe;if(this.first===void 0){if(l)this.first=r,this.firstIndependentlyClosed=!0;this.completeDiagnostics(l?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(r.size,St),this.locked!==!0&&this.second===void 0&&l){this.second=r,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Mn){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(r){if(!this.enabled||r===void 0)return this.reset(),!1;let l=this.firstIndependentlyClosed===!0?this.first:void 0,u=this.secondIndependentlyClosed===!0?this.second:void 0,f=l===void 0||u!==void 0&&u.size>l.size?u:l;if(f===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Qe,2*f.size);let A=0;for(let g of r){let T=this.hasWithinCrossVersionBudget(f,g.tail);if(T===void 0)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1;if(A++,!T)continue;let O=this.hasWithinCrossVersionBudget(f,g.head);if(O===void 0)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1;if(A++,!O)return this.diagnostics?.recordMapProbes?.(A),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(A),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=f,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(r,l=!1){if(r===void 0||r.size>Qe||r===this.first)return!1;if(this.first===void 0||r.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=r,this.firstIndependentlyClosed=l,!0;if(this.second===void 0||r.size>this.second.size)return this.second=r,this.secondIndependentlyClosed=l,!0;return!1}disable(r){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,r)}hasWithinCrossVersionBudget(r,l){let u=this.passiveProbeBudget;if(u===void 0||u===0)return;let f=r.has(l);return this.passiveProbeBudget=u-1,f}completeDiagnostics(r,l){let u=this.diagnostics;if(u===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let f=this.mapProbes??0;u.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",r,l,f,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var zn=(r,l)=>new rn(r,l),Ge=(r,l,u,f,A,g)=>{if(g!==void 0)g.nodeVisits=u,g.dependentProbes=on-l.remaining-u,g.liveDependents=f,g.maxFrontier=A;return r},Ce=(r,l,u,f,A,g=!0,T)=>{if(A!==void 0)A.nodeVisits=0,A.dependentProbes=0,A.liveDependents=0,A.maxFrontier=0;let O=u.visitSelectorDependents;if(O===void 0)return"unsupported";if(T===void 0&&!f.isSoleActiveSelector(u,l))return"ineligible-active-frames";if(!Object.is(r,l)){let I=T===void 0?void 0:f.getTransientDependencies(u,r);if(I!==void 0){if(I.length===0)return"proven-terminal"}else{let G=u.getSelectorDependencyNodes;if(G!==void 0){let K=G.call(u,r);if(K===void 0||K.length===0)return"proven-terminal"}}}if(!g)return"disabled";let N={remaining:on},D=[l],x=new Set(D),V=0,P=0,H=1;while(D.length>0){if(N.remaining===0)return Ge("budget-exhausted",N,V,P,H,A);N.remaining--,V++;let I=D.pop();if(Object.is(I,r))return Ge("path-possible",N,V,P,H,A);let G=!1,K=(ee)=>{if(P++,Object.is(ee,r))return G=!0,!1;if(!x.has(ee)){if(x.add(ee),D.push(ee),D.length>H)H=D.length}return!0},re=O.call(u,I,N,K);if(G)return Ge("path-possible",N,V,P,H,A);if(!re)return Ge("budget-exhausted",N,V,P,H,A);let ae=T?.get(I);if(ae!==void 0)for(let ee of ae){if(N.remaining===0)return Ge("budget-exhausted",N,V,P,H,A);if(N.remaining--,!K(ee))return Ge("path-possible",N,V,P,H,A)}}return Ge("proven-reverse",N,V,P,H,A)},_n=(r,l,u,f,A,g,T,O)=>{if(A===1||A===2){let P=Ce(r,l,u,f,void 0,A===1?T?.reverseProofEnabled??!0:O?.reverseProofEnabled??!0,O?.transientDependents);if(P==="proven-terminal"||P==="proven-reverse")return;if(P==="budget-exhausted"){if(A===1&&T!==void 0)T.reverseProofEnabled=!1;else if(O!==void 0)O.reverseProofEnabled=!1}}let N=T?.(),D=N?.beginSearch()??!1,x=[r],V=new Map([[r,Zt]]);while(x.length>0){let P=x.pop();if(Object.is(P,l)){let G=[],K=P;while(K!==Zt)G.push(K),K=V.get(K);return G.reverse(),N?.completePositive(),Object.freeze(G)}let H=f.getTransientDependencies(u,P);if(H){if(H.length===0)continue;if(D){let G=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(G)continue}for(let G of H){if(V.has(G.node))continue;V.set(G.node,P),x.push(G.node)}continue}if(u.getSelectorDependencyNodes!==void 0){let G=u.getSelectorDependencyNodes(P);if(G===void 0||G.length===0)continue;if(D){let K=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(K)continue}for(let K of G){if(V.has(K))continue;V.set(K,P),x.push(K)}continue}let I=u.getSelectorRecord(P);if(!I||I.dependencies.length===0)continue;if(D){let G=N.hasProvenNoPath(P);if(!N.enabled)D=!1;if(G)continue}for(let G of I.dependencies){if(V.has(G.node))continue;V.set(G.node,P),x.push(G.node)}}N?.completeNegative(V);return},Jt=(r,l)=>{let u=tn(r);if(u.kind==="thenable")return nn(u),new xe(l);if(u.kind==="inspection-error")return u.error;return r},en=(r,l)=>{let u=tn(r);if(u.kind==="thenable")return nn(u),Object.freeze({kind:"error",error:new xe(l)});if(u.kind==="inspection-error")return Object.freeze({kind:"error",error:u.error});return Object.freeze({kind:"value",value:r})},ye=(r,l,u,f=_n,A,g)=>{let{node:T}=r,O=[],N=l.getSelectorRecord(T),D=N?.dependencies,x=D===void 0?new Set:void 0,V,P=0,H=l.getComparisonBaseline(T),I=!0,G=()=>{let W=x;if(W!==void 0)return W;W=new Set;for(let q of O)W.add(q.node);return x=W,W};u.enter(l,T,O);let K=l.getSelectorGraphVersion(),re=u.getSelectorGraphPublicationCount(l),ae=K,ee=re,zt=K,_t=re,vt,gt=!1,kt=K,it=0,qe,Bt=K,st,wt=(W,q)=>{if(W===kt)return;if(kt=W,qe===void 0){it=0;return}if(qe.advanceGraphVersion(q))return;it=0,A?.graphVersionReset()},Cn=(W)=>{if(W!==kt)wt(W,void 0);if(it++,(D?.length??0)===0&&it<3){A?.admissionSkipped();return}if(qe===void 0){let q=D!==void 0&&D.length>0&&D.length<3;qe=zn(q?3:0,A)}if(!qe.enabled){A?.disabled();return}return qe},On=(W)=>{if(gt)return;let q=l.beginSelectorGraphObservation?.(W);if(q===void 0)return;gt=!0,vt=q},Rt=(W,q,te,Q)=>te-W===Q-q,Lt=(W=l.getSelectorGraphVersion(),q=u.getSelectorGraphPublicationCount(l),te=Rt(ae,ee,W,q))=>{if(W===ae)return;if(!gt&&l.beginSelectorGraphObservation!==void 0){wt(W,void 0),ae=W,ee=q;return}let Q=vt?.takeAddedEdges();if(wt(W,Q),te){ae=W,ee=q;return}if(Q!==void 0){let oe=Q.length===0||l.visitSelectorDependents===void 0?void 0:u.captureTransientReverseDependents(l,T,O.length,Fn,g),de=Q.length===0?void 0:{transientDependents:oe,reverseProofEnabled:!0},ne=!1;for(let ke of Q)if(f(ke.head,ke.tail,l,u,2,O.length,void 0,de)!==void 0){ne=!0;break}if(!ne){ae=W,ee=q;return}}for(let oe=0;oe<O.length;oe++){let de=O[oe],ne=f(de.node,T,l,u,0,O.length);if(!ne)continue;if(x!==void 0)for(let ue=O.length-1;ue>=oe;ue--)x.delete(O[ue].node);if(O.length=oe,P++,u.getControlFault().kind==="fault")return;let Z=new p(T,[T,...ne]);u.latchCycle(l,T,Z);return}ae=W,ee=q},Tt=()=>{let W=l.getSelectorGraphVersion(),q=u.getSelectorGraphPublicationCount(l);zt=W,_t=q;let te=Rt(ae,ee,W,q);if(!te)u.revalidateAncestorPrefixes(l,T);Lt(W,q,te)};u.setPrefixRevalidator(l,T,Lt);let En=(W)=>{if(!I)throw new Ot;let q=u.getControlFaultForSuppliedRead();if(q.kind==="fault")throw q.error;let te=u.getCycle(l,T);if(te!==void 0)throw te;let Q=u.activeCyclePath(l,W);if(Q){let U=new p(T,Q);throw u.latchCycle(l,T,U),U}let oe=O.length,de,ne=!1;if(x===void 0){let U=D?.[oe];if(U!==void 0&&Object.is(U.node,W))de=!1,ne=!0;else de=G().has(W)}else de=x.has(W);if(!de&&!ne&&D!==void 0&&D.length>0){let U=D[O.length];if(U!==void 0&&Object.is(U.node,W))ne=!0;else{if(V===void 0){V=new Set;for(let Ue of D)V.add(Ue.node)}ne=V.has(W)}}let ke=P,Z=l.serve(W,u);Tt();let ue=u.getCycle(l,T);if(ue!==void 0)throw ue;let Ze=x!==void 0?x.has(W):P===ke&&O.length===oe?!1:G().has(W),Te=zt,Ke=_t,fe=Ze||ne&&Te===K,at=D===void 0&&Rt(K,re,Te,Ke);if(!fe&&!at){if(Bt=Te,st===void 0)st=()=>Cn(Bt),st.reverseProofEnabled=!0;let U=f(W,T,l,u,1,O.length,st);if(U){let Ue=u.getControlFault();if(Ue.kind==="fault")throw Ue.error;let Ht=new p(T,[T,...U]);throw u.latchCycle(l,T,Ht),Ht}}if(!Ze){let U=N?.dependencies[O.length];x?.add(W),O.push(U!==void 0&&Object.is(U.node,W)&&Object.is(U.token,Z.token)?U:Object.freeze({node:W,token:Z.token})),On(W)}if(ae=Te,ee=Ke,Z.outcome.kind==="control-error"){u.latchControlFault(Z.outcome.error,Z.outcome.origin);let U=u.getControlFault();if(U.kind==="fault")throw U.error;throw Z.outcome.error}let Je=u.getControlFault();if(Je.kind==="fault")throw Je.error;if(Z.outcome.kind==="error")throw ft(ht,W,Z.outcome.error)??new ht(W,Z.outcome.error);return Z.outcome.value};try{let W,q,te=!1;try{W=r.get(En)}catch(ue){te=!0,q=ue}finally{I=!1}if(te)q=Jt(q,"getter");let Q=te?void 0:en(W,"getter");Tt();let oe=u.getControlFault();if(oe.kind==="fault")return ie(T,l.createOutcomeToken(),{...oe,kind:"control-error"},O);let de=u.getCycle(l,T);if(de!==void 0)return ie(T,l.createOutcomeToken(),{kind:"error",error:de},O);if(te)return ie(T,l.createOutcomeToken(),{kind:"error",error:q instanceof xe?q:ft(Ye,T,q)??new Ye(T,q)},O);if(Q===void 0)throw Error("Selector result classification was not completed");let ne=u.getControlFault();if(ne.kind==="fault")return ie(T,l.createOutcomeToken(),{...ne,kind:"control-error"},O);if(Q.kind==="error")return ie(T,l.createOutcomeToken(),{kind:"error",error:Q.error instanceof xe?Q.error:ft(Ye,T,Q.error)??new Ye(T,Q.error)},O);let ke=Q.value,Z;if(H){let ue=r.equal??Object.is,Ze,Te,Ke=!1;try{Ze=ue(H.value,ke)}catch(Ue){Ke=!0,Te=Jt(Ue,"comparator")}let fe=Ke?void 0:en(Ze,"comparator");Tt();let at=u.getControlFault();if(at.kind==="fault")return ie(T,l.createOutcomeToken(),{...at,kind:"control-error"},O);let Je=u.getCycle(l,T);if(Je!==void 0)return ie(T,l.createOutcomeToken(),{kind:"error",error:Je},O);if(Ke)return ie(T,l.createOutcomeToken(),{kind:"error",error:Te instanceof xe?Te:new pt(T,Te)},O);if(fe===void 0)throw Error("Selector comparator classification was not completed");let U=u.getControlFault();if(U.kind==="fault")return ie(T,l.createOutcomeToken(),{...U,kind:"control-error"},O);if(fe.kind==="error")return ie(T,l.createOutcomeToken(),{kind:"error",error:fe.error instanceof xe?fe.error:new pt(T,fe.error)},O);if(fe.value!==!0&&fe.value!==!1)return ie(T,l.createOutcomeToken(),{kind:"error",error:new Ct},O);if(fe.value===!0)ke=H.value,Z=H.current?H.token:void 0}return ie(T,Z??l.createOutcomeToken(),{kind:"value",value:ke},O)}finally{try{vt?.close()}finally{u.leave(l,T)}}};class e{#t=[];#e;#o;#c=0;#r;#s=Bn;#u;latchControlFault(r,l={}){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:r,origin:l})}getControlFault(){return this.#s}setSuppliedReadGuard(r){let l=this.#u;return this.#u=r,l}getControlFaultForSuppliedRead(){return this.#u?.(),this.#s}noteSelectorGraphPublication(r){let l=this.#o;if(l===void 0){this.#o=r,this.#c=1;return}if(Object.is(l,r)){this.#c++;return}let u=this.#r??(this.#r=new WeakMap);u.set(r,(u.get(r)??0)+1)}getSelectorGraphPublicationCount(r){return Object.is(this.#o,r)?this.#c:this.#r?.get(r)??0}enter(r,l,u){this.#t.push({host:r,selector:l,dependencyPrefix:u,revalidatePrefix:void 0,cycleError:void 0})}leave(r,l){let u=this.#t.pop();if(!u||!Object.is(u.host,r)||!Object.is(u.selector,l))throw Error("Selector evaluation frame corruption");this.#e=u}get evaluating(){return this.#t.length!==0}getProposedDependencies(r,l){let u=this.#e;return u!==void 0&&Object.is(u.host,r)&&Object.is(u.selector,l)&&Object.isFrozen(u.dependencyPrefix)?u.dependencyPrefix:void 0}isActive(r,l){return this.#t.some((u)=>Object.is(u.host,r)&&Object.is(u.selector,l))}isSoleActiveSelector(r,l){let u=!1;for(let f of this.#t){if(!Object.is(f.host,r))continue;if(u||!Object.is(f.selector,l))return!1;u=!0}return u}activeCyclePath(r,l){let u=this.#t.findIndex((f)=>Object.is(f.host,r)&&Object.is(f.selector,l));if(u===-1)return;return Object.freeze([...this.#t.slice(u).filter((f)=>Object.is(f.host,r)).map((f)=>f.selector),l])}setPrefixRevalidator(r,l,u){let f=this.#a(r,l);if(f.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");f.revalidatePrefix=u}revalidateAncestorPrefixes(r,l){this.#a(r,l);for(let u=0;u<this.#t.length-1;u++){let f=this.#t[u];if(!Object.is(f.host,r))continue;let A=f.revalidatePrefix;if(A===void 0)throw Error("Selector prefix revalidator is not installed");A()}}getTransientDependencies(r,l){for(let u=this.#t.length-1;u>=0;u--){let f=this.#t[u];if(Object.is(f.host,r)&&Object.is(f.selector,l))return f.dependencyPrefix}return}captureTransientReverseDependents(r,l,u,f,A){let g=new Set,T=new Map,O=!1,N=0,D=0,x=0;for(let P of this.#t){if(N++,N>f){A?.recordSnapshot("overflow",N,D,x);return}if(!Object.is(P.host,r))continue;if(D++,P.revalidatePrefix===void 0||g.has(P.selector)){A?.recordSnapshot("unavailable",N,D,x);return}if(g.add(P.selector),Object.is(P.selector,l)){if(O||P.dependencyPrefix.length!==u){A?.recordSnapshot("unavailable",N,D,x);return}O=!0}for(let H of P.dependencyPrefix){if(x++,x>f){A?.recordSnapshot("overflow",N,D,x);return}let I=T.get(H.node);if(I===void 0)T.set(H.node,[P.selector]);else I.push(P.selector)}}if(!O){A?.recordSnapshot("unavailable",N,D,x);return}let V=new Map;for(let[P,H]of T)V.set(P,Object.freeze(H));return A?.recordSnapshot("completed",N,D,x),V}latchCycle(r,l,u){let f=this.#i(r,l);f.cycleError??=u}getCycle(r,l){return this.#a(r,l).cycleError}#a(r,l){let u=this.#t[this.#t.length-1];if(!u||!Object.is(u.host,r)||!Object.is(u.selector,l))throw Error("Selector evaluation frame is not active");return u}#i(r,l){for(let u=this.#t.length-1;u>=0;u--){let f=this.#t[u];if(Object.is(f.host,r)&&Object.is(f.selector,l))return f}throw Error("Selector evaluation frame is not active")}}var Bn=Object.freeze({kind:"none"});var ce=Symbol(),Ee=Symbol(),mt=Symbol(),i=Symbol(),pe=(r,l)=>r.kind===l.kind&&(r.kind==="value"?Object.is(r.value,l.value):Object.is(r.error,l.error)),sn=Object.freeze({kind:"not-thenable"}),Ln=()=>{},Hn=Reflect.apply,an=Symbol.for("valdres.runtime-owner/v1");class J extends Error{seal(){Object.freeze(this)}}var dn=new WeakSet,De=(r)=>dn.has(r);class M extends J{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class a extends J{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source;constructor(r,l="owned-mutation"){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...r]),this.cause=this.causes[0],this.source=l,this.seal()}}class d extends J{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class v extends J{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(r){super(`A selector callback cannot call ${r} directly`);this.name="SelectorCapabilityError",this.seal()}}class j extends J{code="VALDRES_SETTLE_LIMIT";constructor(){super("Store updates did not settle");this.name="SettleLimitError",this.seal()}}class w extends J{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class C extends J{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class h extends J{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class m extends J{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class y extends J{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class S extends J{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class L extends J{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class _ extends J{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class R extends J{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var t=(r)=>{if((typeof r!=="object"||r===null)&&typeof r!=="function")return sn;try{let l=r.then;return typeof l==="function"?Object.freeze({kind:"thenable",target:r,then:l}):sn}catch(l){return Object.freeze({kind:"inspection-error",error:l})}},n=(r)=>{try{Hn(r.then,r.target,[void 0,Ln])}catch{}},tt=(r)=>{let l=t(r);if(l.kind==="not-thenable")return Object.freeze({kind:"value",value:r});if(l.kind==="inspection-error")return Object.freeze({kind:"error",error:l.error});return n(l),Object.freeze({kind:"error",error:new m})},Et=(r)=>{try{return tt(r())}catch(l){let u=t(l);if(u.kind==="not-thenable")return Object.freeze({kind:"error",error:l});if(u.kind==="inspection-error")return Object.freeze({kind:"error",error:u.error});return n(u),Object.freeze({kind:"error",error:new m})}},E=(r,l,u)=>{let f=r.activity;r.activity=l;try{return u()}finally{r.activity=f}},c=(r,l,u)=>{let f=r.activity,A=f?.kind==="selector"?f:f!==void 0&&("selectorActivity"in f)?f.selectorActivity:void 0,g=A===void 0?Object.freeze({kind:"guarded-callback",session:l}):Object.freeze({kind:"guarded-callback",session:l,selectorActivity:A});try{return E(r,g,u)}finally{let T=l.getControlFault();if(T.kind==="fault")throw r.externalRuntime?.guard(T.error),T.error}},cn=(r,l,u)=>{try{return E(r,Object.freeze({kind:"subscriber",session:l}),u)}finally{let f=l.getControlFault();if(f.kind==="fault")throw f.error}},yt=(r,l,u)=>{let f=r.activity,A=f?.kind==="selector"?f:f!==void 0&&("selectorActivity"in f)?f.selectorActivity:void 0,g=Object.is(A?.session,l)?A?.parentSelectorActivity:A,T=g===void 0?Object.freeze({kind:"selector",session:l}):Object.freeze({kind:"selector",session:l,parentSelectorActivity:g});return E(r,T,u)},ln=(r,l,u)=>E(r,Object.freeze({kind:"transaction",transaction:l}),u),nt=(r,l,u)=>{try{return E(r,Object.freeze({kind:"transaction-result",session:l}),u)}finally{let f=l.getControlFault();if(f.kind==="fault")throw f.error}},Se=(r)=>{let l=new d;throw r.externalRuntime?.guard(l),l},Ae=(r,l)=>{let u=r.activity;if(u===void 0)return;if(u.kind==="selector")throw new v(l);if(u.kind==="transaction"||u.kind==="transaction-result")throw new w;Se(r)},bt=(r,l)=>{if(r.activity?.kind==="subscriber")return r.activity.session;Ae(r,l)},be=(r,l)=>{let u=l.getControlFault(),f=r.getControlFault(),A=u.kind==="fault"?u.error:f.kind==="fault"?f.error:new d;throw r.latchControlFault(A),l.latchControlFault(A),A},un=(r)=>{bt(r,"Store unsubscribe")},$e=(r,l,u)=>{if(!u)throw new C;let f=r.activity;if(f?.kind==="transaction"&&Object.is(f.transaction,l))return;if(f?.kind==="selector")throw new v("Transaction cursor operation");if(f?.kind==="guarded-callback"||f?.kind.startsWith("external-"))Se(r);throw new w},fn=(r,l)=>{let u=r.activity;return u!==void 0&&"session"in u?u.session:l},Xe=(r,l,u)=>{if(r.states.has(l)||r.stores.has(l)||r.transactionCursors.has(l))return"local";if(l!==null&&l!==void 0){let f=Object.getOwnPropertyDescriptor(l,an);if(f!==void 0&&"value"in f&&!Object.is(f.value,r.ownerToken)){let A=new M;throw dn.add(A),fn(r,u).latchControlFault(A),A}}return"invalid"},le=(r,l,u)=>{if(r.states.has(l)||r.stores.has(l)||r.transactionCursors.has(l))return"local";let f=r.activity,A=fn(r,u);if(f!==void 0&&"session"in f)try{return Xe(r,l,A)}finally{let g=A.getControlFault();if(g.kind==="fault")throw g.error}return c(r,A,()=>Xe(r,l,A))},ot=(r,l)=>(Object.defineProperty(r,an,{value:l,enumerable:!1,writable:!1,configurable:!1}),r),b=(r)=>{let l=r[Ee];if(l===void 0||l.allowDefinitions)return;let u=l.session.getControlFault();if(u.kind==="fault")throw u.error;let f=new d;throw l.session.latchControlFault(f),f},F=(r)=>({kind:r}),k=(r,l)=>{b(r);let u=r[Ee],f=Object.freeze(ot(l,r.ownerToken));return r.states.add(f),u?.definitions?.add(f),f};var hn=Symbol("no-committed-selector-baseline");class Nt{#t;#e=new Map;#o=new Map;#c=new Map;#r;#s=1;#u=0;#a;#i;constructor(r,l,u){this.#t=r,this.#r=l,this.#a=u,this.#i=r.trackPath?[]:void 0}readSelector(r){let l=new e,u=this.serve(r,l);if(u.outcome.kind!=="value")throw u.outcome.error;return u.outcome.value}advanceGeneration(r){if(r!==this.#r+1)throw Error("Scratch selector generation is not contiguous");this.#r=r,this.#e.clear(),this.#o.clear()}revoke(){this.#e.clear(),this.#o.clear(),this.#c.clear(),this.#t=void 0}serve(r,l){if(this.#i===void 0)return this.#l(r,l);this.#i.push(r);try{return this.#l(r,l)}finally{this.#i.pop()}}#l(r,l){let u=this.#f(),f=u.resolve(r,l);if(f.kind!=="selector"){let O=this.#o.get(r);if(O!==void 0)return O;let N=Object.freeze({token:this.createOutcomeToken(),outcome:u.read(r,f.kind,l,this.#i)});return this.#o.set(r,N),N}let A=this.#e.get(r);if(A!==void 0)return A.served;let g=u.run(l,()=>this.#a(f.definition,this,l));if(g.outcome.kind==="control-error")throw g.outcome.error;let T=Object.freeze({token:g.token,outcome:g.outcome});return this.#u++,l.noteSelectorGraphPublication(this),this.#e.set(r,Object.freeze({served:T,dependencies:g.dependencies})),T}getSelectorRecord(r){let l=this.#e.get(r);return l===void 0?void 0:Object.freeze({dependencies:l.dependencies})}getSelectorGraphVersion(){return this.#u}getComparisonBaseline(r){let l=this.#c.get(r);if(l===void 0)l=this.#f().baseline(r)??hn,this.#c.set(r,l);return l===hn?void 0:Object.freeze({current:!1,value:l.value})}createOutcomeToken(){return Object.freeze({id:this.#s++})}#f(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var pn=4096,Wn=Object.freeze([]);class s{onDeadReference;onEmptinessProbe;#t=new WeakMap;#e=new Set;constructor(r,l){this.onDeadReference=r;this.onEmptinessProbe=l}add(r){if(this.#t.has(r))return;let l=new WeakRef(r);this.#t.set(r,l),this.#e.add(l)}delete(r){let l=this.#t.get(r);if(l===void 0)return;this.#t.delete(r),this.#e.delete(l)}forEach(r){for(let l of this.#e){let u=l.deref();if(u===void 0){this.#e.delete(l),this.onDeadReference?.();continue}r(u)}}visitWithin(r,l){for(let u of this.#e){if(r.remaining===0)return!1;r.remaining--;let f=u.deref();if(f===void 0){this.#e.delete(u),this.onDeadReference?.();continue}if(!l(f))return!1}return!0}isEmpty(){for(let r of this.#e){if(this.onEmptinessProbe?.(),r.deref()!==void 0)return!1;this.#e.delete(r),this.onDeadReference?.()}return!0}clear(){this.#e.clear(),this.#t=new WeakMap}}class xt{scope;onSwept;#t=new WeakMap;#e=new Set;#o=64;constructor(r,l){this.scope=r;this.onSwept=l}add(r){if(this.#t.has(r))return!1;let l=new WeakRef(r);if(this.#t.set(r,l),this.#e.add(l),this.#e.size>=this.#o)this.sweep();return!0}sweep(){let r=0;for(let l of this.#e){let u=l.deref();if(u!==void 0&&this.scope.atomOverrides.has(u))continue;if(u!==void 0)this.#t.delete(u);this.#e.delete(l),r++}if(this.#o=Math.max(64,this.#e.size*2),r!==0)this.onSwept?.(r);return r}collect(r){let l=0;for(let u of this.#e){let f=u.deref();if(f!==void 0){r.push(f);continue}this.#e.delete(u),l++}if(l!==0)this.onSwept?.(l)}}class At{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;ownedAtoms;#t=new WeakMap;#e;#o=new WeakMap;#c;#r=new WeakMap;#s=new WeakSet;#u;#a=0;#i=0;#l;#f=!1;#m;#S="live";constructor(r,l,u){this.coordinator=r,this.parent=l,this.name=u,this.children=this.#d(),this.#e=this.#d()}get status(){return this.#S}get facade(){if(this.#m===void 0)throw Error("Store scope facade is not installed");return this.#m}installFacade(r){if(this.#m!==void 0)throw Error("Store scope facade is already installed");this.#m=r}markDisposing(){if(this.#S==="live")this.#S="disposing"}markDisposed(){this.#S="disposed"}getAtomView(r){return this.#t.get(r)}getMaterializedServedOutcome(r){if(r.kind!=="selector")return this.#t.get(r)?.served;let l=r,u=this.#o.get(l);return u!==void 0&&!this.#s.has(l)?u.served:void 0}createAtomView(r,l,u){let f=this.#t.get(r);if(f!==void 0)return f;let A={scope:this,atom:r,served:Object.freeze({token:this.createOutcomeToken(),outcome:l}),inheritedFrom:u,inheritingChildren:this.#d()};if(this.#t.set(r,A),this.#e.add(A),u!==void 0)u.inheritingChildren.add(A),this.coordinator.recordCounter(11);return A}attachAtomView(r,l){if(Object.is(r.inheritedFrom,l))return;this.detachAtomView(r),r.inheritedFrom=l,l.inheritingChildren.add(r),this.coordinator.recordCounter(11)}detachAtomView(r){if(r.inheritedFrom===void 0)return;r.inheritedFrom.inheritingChildren.delete(r),r.inheritedFrom=void 0,this.coordinator.recordCounter(12)}updateAtomView(r,l){r.served=Object.freeze({token:this.createOutcomeToken(),outcome:l}),this.coordinator.reachSubscriptionTarget(this,r.atom)}captureCommittedSelectorSuccess(r){let l=this.#o.get(r)?.lastSuccess;return l===void 0?void 0:Object.freeze({value:l.value})}isSelectorDirty(r){return this.#s.has(r)}getCommittedSelectorDependencies(r){return this.#o.get(r)?.dependencies}externalRecord(r){return this.#o.get(r)}replaceExternalRecord(r,l){this.#o.set(r,l)}externalDependents(r){return this.#r.get(r)}markDependents(r){this.#r.get(r)?.forEach((l)=>{if(this.coordinator.enqueueSelector(this,l))this.#s.add(l)})}dropRecords(){this.coordinator.runtimeDomain[i]?.scope(this),this.#e.forEach((r)=>{this.detachAtomView(r),r.inheritingChildren.clear()}),this.#e.clear(),this.atomOverrides=new WeakMap,this.ownedAtoms=void 0,this[ce]?.release(this.coordinator),this[ce]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#c=void 0,this.#r=new WeakMap,this.#s=new WeakSet,this.#u=void 0,this.#a++,this.#p()}serve(r,l){let u=this.coordinator.runtimeDomain;if(Xe(u,r,l)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(r,l)}serveKnownLocal(r,l){let u=this.coordinator.runtimeDomain;if(u.atoms.has(r)){let O=this.#t.get(r);if(O!==void 0)return O.served;return this.coordinator.serveScopeAtom(this,r,l)}let f=u.selectors.get(r);if(f===void 0){if(u.externalAtoms?.has(r))return this.coordinator.reachExternal().serve(this,r,l);let O=u[i]?.scope(this,r,l);if(O!==void 0)return O;throw TypeError("Unknown committed StoreTree state")}let A=r,g=this.#o.get(A);if(g?.lifecycleInClosure&&!this.#s.has(A))this.coordinator.external?.refresh(this,A,l),g=this.#o.get(A);if(g!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,A,l),g=this.#o.get(A);if(g!==void 0&&!this.#s.has(A)&&!(this.coordinator.postSourceApply&&this.#h(A)))return g.served;let T;try{T=yt(u,l,()=>this.coordinator.evaluate(f,this,l))}catch(O){return this.publishEscapedFailure(A,O,l)}if(T.outcome.kind==="control-error"&&(!this.coordinator.postSourceApply||this.coordinator.external?.dormantPull===!0))throw T.outcome.error;return this.#b(A,T,l)}getSelectorRecord(r){let l=this.#o.get(r);return l===void 0?void 0:Object.freeze({dependencies:l.dependencies})}getSelectorDependencyNodes(r){let l=this.#o.get(r);if(l===void 0)return;let u=r,f=this.#c?.get(u);if(f===void 0){let A=[];for(let T of l.dependencies)if(this.coordinator.runtimeDomain.selectors.has(T.node))A.push(T.node);f=Object.freeze(A);let g=this.#c;if(g===void 0)g=new WeakMap,this.#c=g;g.set(u,f)}return f}visitSelectorDependents(r,l,u){return this.#r.get(r)?.visitWithin(l,u)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(r){if(!this.coordinator.runtimeDomain.selectors.has(r))return;if(this.#i===0)this.#l=[],this.#f=!1;this.#i++;let l=this.#l?.length??0,u=!1;return Object.freeze({takeAddedEdges:()=>{if(u||this.#f)return;let f=this.#l;if(f===void 0)return;if(l===f.length)return Wn;let A=Object.freeze(f.slice(l));return l=f.length,A},close:()=>{if(u)return;if(u=!0,this.#i--,this.#i!==0)return;this.#l=void 0,this.#f=!1}})}getComparisonBaseline(r){let l=this.#o.get(r);if(l?.lastSuccess===void 0)return;return l.served.outcome.kind==="value"?Object.freeze({current:!0,value:l.lastSuccess.value,token:l.served.token}):Object.freeze({current:!1,value:l.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}publishEscapedFailure(r,l,u){let f=this.#o.get(r),A=u.getProposedDependencies(this,r)??f?.dependencies,g=u.getControlFault(),T=g.kind!=="fault"&&(A===void 0||A.length===0);if(g.kind==="fault"?!this.coordinator.postSourceApply||this.coordinator.external?.dormantPull===!0:T&&f===void 0&&!u.evaluating)throw l;this.coordinator.reportSelectorFailure(l);let O=this.#b(r,{token:this.createOutcomeToken(),outcome:Object.freeze(g.kind==="fault"?{...g,kind:"control-error"}:{kind:"error",error:l}),dependencies:A??Dt},u);if(T)(this.#u??=new WeakMap).set(r,this.coordinator.settlementEpoch);return O}#h(r){let l=this.#u?.get(r);if(l===void 0||l===this.coordinator.settlementEpoch)return!1;return this.#u.delete(r),!0}#b(r,l,u){let f=this.#o.get(r),g={served:Object.freeze({token:l.token,outcome:l.outcome}),dependencies:l.dependencies,lastSuccess:l.outcome.kind==="value"?Object.freeze({value:l.outcome.value,token:l.token}):f?.lastSuccess};g=this.coordinator.external?.selectorRecord(this,g,u)??Object.freeze(g);let T=this.#y(r,f?.dependencies??Dt,l.dependencies),O=T?this.#A(r,f?.dependencies??Dt,l.dependencies):void 0;if(T)this.#c?.delete(r);if(this.#a++,u.noteSelectorGraphPublication(this),this.#o.set(r,g),this.coordinator.external?.publishedSelector(this,r,f,g),this.#s.delete(r),this.#u?.delete(r),O!==void 0)this.#v(O);if(f!==void 0&&!Object.is(f.served.token,l.token))this.coordinator.reachSubscriptionTarget(this,r),this.markDependents(r);if(l.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(g.served.outcome);return g.served}#y(r,l,u){if(l.length===u.length){let f=0;while(f<l.length&&Object.is(l[f].node,u[f].node))f++;if(f===l.length)return!1}for(let f of l){let A=this.#r.get(f.node);if(A?.delete(r),A?.isEmpty())this.#r.delete(f.node)}for(let f of u){let A=this.#r.get(f.node);if(A===void 0)A=this.#d(),this.#r.set(f.node,A);A.add(r)}return!0}#A(r,l,u){if(this.#i===0||this.#f)return;let f=this.#l;if(f===void 0){this.#p();return}let A=pn-f.length,g=this.coordinator.runtimeDomain.selectors,T=new Set;for(let N of l)if(g.has(N.node))T.add(N.node);let O=[];for(let N of u)if(g.has(N.node)&&!T.has(N.node)){if(O.push(Object.freeze({tail:r,head:N.node})),O.length>A){this.#p();return}}return O}#v(r){if(r.length===0)return;let l=this.#l;if(l===void 0||l.length+r.length>pn){this.#p();return}l.push(...r)}#p(){if(this.#i===0)return;this.#l=[],this.#f=!0}#d(){return new s(this.coordinator.instrumented?()=>this.coordinator.recordCounter(2):void 0)}}var Dt=Object.freeze([]);class Pt{commitEntries;transaction=Object.freeze({});onAllocation;#t;#e;#o;#c;#r;#s;#u;#a;#i;#l;#f;#m;#S;#h;#b;#y;externalCaptures;#A;#v=!1;generation=0;active=!0;constructor(r){this.onAllocation=r}get hasIntents(){return this.#e!==void 0||this.#o!==void 0||this.#c!==void 0||this.#r!==void 0}get hasRows(){return this.#v}installRows(r){let l=this.#A;if(l!==void 0&&l!==r)throw Error();this.#A=r}markRow(r){if(this.#A===void 0)throw Error();if(r!==this.generation)throw Error();this.#v=!0,this.#p()}get singleIntentScope(){return this.#t}get singleIntent(){return this.#o===void 0?this.#e:void 0}stage(r,l){let u=this.#r;if(u!==void 0){let g=u.get(r);if(g===void 0)g=this.#d(),u.set(r,g);g.set(l.atom,l),this.#p();return}let f=this.#c;if(f!==void 0){if(Object.is(this.#t,r))f.set(l.atom,l);else{let g=this.#d();g.set(this.#t,f);let T=this.#d();T.set(l.atom,l),g.set(r,T),this.#r=g,this.#c=void 0,this.#t=void 0}this.#p();return}let A=this.#e;if(A===void 0){this.#t=r,this.#e=l,this.#p();return}if(Object.is(this.#t,r)&&Object.is(A.atom,l.atom)){this.#e=l,this.#p();return}if(Object.is(this.#t,r)){let g=this.#o;if(g===void 0){this.#o=l,this.#p();return}if(Object.is(g.atom,l.atom)){this.#o=l,this.#p();return}let T=this.#d();T.set(A.atom,A),T.set(g.atom,g),T.set(l.atom,l),this.#c=T}else{let g=this.#d(),T=this.#d();if(T.set(A.atom,A),this.#o!==void 0)T.set(this.#o.atom,this.#o);g.set(this.#t,T);let O=this.#d();O.set(l.atom,l),g.set(r,O),this.#r=g,this.#t=void 0}this.#e=void 0,this.#o=void 0,this.#p()}forEachIntent(r){let l=this.#e;if(l!==void 0){if(r(this.#t,l),this.#o!==void 0)r(this.#t,this.#o);return}let u=this.#c;if(u!==void 0){let A=this.#t;for(let g of u.values())r(A,g);return}let f=this.#r;if(f===void 0)return;for(let[A,g]of f)for(let T of g.values())r(A,T)}getIntent(r,l){let u=this.#e;if(u!==void 0&&Object.is(this.#t,r)&&Object.is(u.atom,l))return u;let f=this.#o;if(f!==void 0&&Object.is(this.#t,r)&&Object.is(f.atom,l))return f;if(Object.is(this.#t,r))return this.#c?.get(l);return this.#r?.get(r)?.get(l)}getAtomBaseline(r,l){if(this.#a!==void 0&&Object.is(this.#s,r)&&Object.is(this.#u,l))return this.#a;if(this.#l!==void 0&&Object.is(this.#s,r)&&Object.is(this.#i,l))return this.#l;if(Object.is(this.#s,r))return this.#f?.get(l);return this.#m?.get(r)?.get(l)}setAtomBaseline(r,l,u){let f=this.#m;if(f!==void 0){let T=f.get(r);if(T===void 0)T=this.#d(),f.set(r,T);if(!T.has(l))T.set(l,u);return}let A=this.#f;if(A!==void 0){if(Object.is(this.#s,r)){if(!A.has(l))A.set(l,u)}else{let T=this.#d();T.set(this.#s,A);let O=this.#d();O.set(l,u),T.set(r,O),this.#m=T,this.#f=void 0,this.#s=void 0}return}let g=this.#a;if(g===void 0){this.#s=r,this.#u=l,this.#a=u;return}if(Object.is(this.#s,r)&&Object.is(this.#u,l))return;if(Object.is(this.#s,r)){let T=this.#l;if(T===void 0){this.#i=l,this.#l=u;return}if(Object.is(this.#i,l))return;let O=this.#d();O.set(this.#u,g),O.set(this.#i,T),O.set(l,u),this.#f=O}else{let T=this.#d(),O=this.#d();if(O.set(this.#u,g),this.#i!==void 0&&this.#l!==void 0)O.set(this.#i,this.#l);T.set(this.#s,O);let N=this.#d();N.set(l,u),T.set(r,N),this.#m=T,this.#s=void 0}this.#u=void 0,this.#a=void 0,this.#i=void 0,this.#l=void 0}getFallback(r){if(Object.is(this.#S,r))return this.#h;return this.#b?.get(r)}hasFallback(r){return Object.is(this.#S,r)||(this.#b?.has(r)??!1)}setFallback(r,l){let u=this.#b;if(u!==void 0){u.set(r,l);return}if(this.#h===void 0){this.#S=r,this.#h=l;return}if(Object.is(this.#S,r)){this.#h=l;return}let f=this.#d();f.set(this.#S,this.#h),f.set(r,l),this.#b=f,this.#S=void 0,this.#h=void 0}forEachFallback(r){if(this.#S!==void 0&&this.#h!==void 0)r(this.#S,this.#h);if(this.#b!==void 0)for(let[l,u]of this.#b)r(l,u)}#p(){this.generation+=1;let r=this.#y;if(r!==void 0)for(let l of r.values())l.advanceGeneration(this.generation)}getScratchHost(r){return this.#y?.get(r)}installScratchHost(r,l){let u=this.#y,f=u===void 0;if(u===void 0)u=new Map,this.#y=u;return u.set(r,l),f}close(){if(!this.active)return;this.active=!1;let r=this.#y;if(r!==void 0){for(let l of r.values())l.revoke();r.clear()}this.#y=void 0}release(){this.commitEntries=void 0;let r=this.#A;this.#A=void 0,this.#v=!1;try{if(this.#c?.clear(),this.#r!==void 0){for(let l of this.#r.values())l.clear();this.#r.clear()}if(this.#f?.clear(),this.#m!==void 0){for(let l of this.#m.values())l.clear();this.#m.clear()}this.#b?.clear(),this.#t=void 0,this.#e=void 0,this.#o=void 0,this.#c=void 0,this.#r=void 0,this.#s=void 0,this.#u=void 0,this.#a=void 0,this.#i=void 0,this.#l=void 0,this.#f=void 0,this.#m=void 0,this.#S=void 0,this.#h=void 0,this.#b=void 0,this.#y?.clear(),this.#y=void 0,this.externalCaptures?.clear(),this.externalCaptures=void 0}finally{r?.(this)}}#d(){return this.onAllocation?.(),new Map}}class Sn{constructor(r,l,u){this.onCommit=(f)=>r.registerCommit(l,u,f),this.get=(f)=>r.transactionGet(l,u,f),this.set=(f,A)=>r.mutate(l,u,"set",f,A),this.update=(f,A)=>r.mutate(l,u,"update",f,A),this.reset=(f)=>r.mutate(l,u,"reset",f),this.delete=(f)=>r.mutate(l,u,"delete",f),this.resetAll=function(){r.resetAll(l,u,arguments.length)},this.scope=(...f)=>r.transactionScope(l,u,f[0],f.length,f[1]),ot(this,r.runtimeDomain.ownerToken),r.runtimeDomain.transactionCursors.set(this,l),Object.freeze(this)}}var jt=(r,l,u)=>new Sn(r,l,u),Vt=(r)=>{let l=t(r);if(l.kind==="not-thenable")return;if(l.kind==="inspection-error")throw l.error;throw n(l),new h},mn=(r)=>{let l=t(r);if(l.kind==="not-thenable")throw r;if(l.kind==="inspection-error")throw l.error;throw n(l),new h};var Gn=64,qn=(r)=>function(){let u=r.target;if(u===void 0)return;u.host.removeSubscription(r)},X=Symbol("definition domain records"),ge=(r)=>r[X].ownerToken,Ne=(r)=>r[X],Pe=(r,l)=>{let u=r[X],f=u[i];if(f!==void 0)return f;let A=l(u);return u[i]=A,A},Ve=(r)=>r[X][i],Kn=Object.freeze([]),B=(r,l,u,f,A,g)=>{let T=r[X],O=new e,N=T.activity,D=N?.kind==="selector"?N:N?.kind==="guarded-callback"?N.selectorActivity:void 0,x=[];while(D!==void 0){let I=D.session;if(!x.includes(I))x.push(I);D=D.parentSelectorActivity}let V=l==="factory",P=T[Ee];T[Ee]={session:O,definitions:V?new WeakSet:void 0,allowDefinitions:V,...g===void 0?{}:{createAccessorFault:g}};let H=x.length===0?Kn:x.map((I)=>Object.freeze({selectorSession:I,previous:I.setSuppliedReadGuard(()=>{let G=T.activity;return be(G?.kind==="guarded-callback"?G.session:O,I)})}));try{return c(T,O,()=>{let I=Reflect.apply(u,void 0,f);return A===void 0?I:A(I)})}finally{for(let I=H.length-1;I>=0;I--){let G=H[I];G.selectorSession.setSuppliedReadGuard(G.previous)}if(P===void 0)delete T[Ee];else T[Ee]=P}},ve=(r)=>{let l=r[X][Ee];if(l===void 0||l.allowDefinitions)return;let u=l.session.getControlFault();if(u.kind==="fault")throw u.error;let f=l.createAccessorFault===void 0?new d:l.accessorFault??=l.createAccessorFault();throw l.session.latchControlFault(f),f},he=(r)=>b(r[X]),Me=ve,z=(r,l)=>k(r[X],l),Re=(r,l)=>le(r[X],l,new e),je=(r,l)=>{let u=r[X];if((typeof l==="object"||typeof l==="function")&&l!==null&&u.states.has(l)&&(u.atoms.has(l)||u.selectors.has(l)||u.externalAtoms?.has(l))){if(u[Ee]?.definitions?.has(l)||u[mt]?.has(l))return l;return}le(u,l,new e);return};class An extends Set{release(r){r.recordCounter(34,this.size)}}class vn extends WeakSet{apply(r,{atom:l,kind:u}){let f=r[ce];if(u==="set"){if(!this.has(l))return!1;if(f===void 0)f=r[ce]=new An,r.coordinator.recordCounter(32);let A=f.size;if(f.add(l),f.size!==A)r.coordinator.recordCounter(33);return!0}else{if(f?.delete(l))r.coordinator.recordCounter(34);if(f?.size===0)r[ce]=void 0;return!1}}}var Le=(r,l)=>{let u=r[X];if((u[mt]??(u[mt]=new WeakSet)).add(l),!u.atoms.has(l))return;(u[ce]??(u[ce]=new vn)).add(l)},gn=new WeakMap,_e=()=>{let r=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,familyOwnerRetentionSetsCreated:32,familyOwnerRetains:33,familyOwnerReleases:34,liveSamples:35,serverSamples:36,transactionCaptures:37,externalClosureVisits:38,projectionPublications:39,lifecycleEdgeVisits:40,adapterSubscriptions:41,adapterCleanups:42,dirtyRounds:43,dirtySamples:44,thenableContainments:45,deliveryEntries:46,deliveryLimitHits:47,nonConvergenceTerminations:48,lifecycleRetains:49,lifecycleReleases:50,ownedAtomRetains:51,ownedAtomSweptReferences:52}),l=53,u=new Uint32Array(53),f=Object.freeze({read(A){return u[r[A]]??0}});return gn.set(f,(A,g)=>{u[A]+=g}),f},se=(r)=>Object.freeze({kind:"value",value:r}),Un=(r)=>Object.freeze({kind:"error",error:r}),yn=(r)=>r.kind==="value"?se(r.value):Un(r.error),rt=(r,l)=>r[i]?.has(l)?r[i]:void 0,kn=(r,l,u,f)=>{let A=r.read(l,u,f);if(A.kind!=="value")throw A.error;return A.value};var Yn=(r)=>({onAllocation:r,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}),Mt=(r)=>(r.onAllocation?.(),new Map),Qn=(r)=>(r.onAllocation?.(),new Set),It=(r,l,u)=>{if(r.preflightOutcome!==void 0&&Object.is(r.preflightAtom,l)&&Object.is(r.preflightScope,u))return r.preflightOutcome;if(r.secondPreflightOutcome!==void 0&&Object.is(r.secondPreflightAtom,l)&&Object.is(r.secondPreflightScope,u))return r.secondPreflightOutcome;return r.preflight?.get(l)?.get(u)},bn=(r,l,u,f)=>{if(r.preflightOutcome===void 0){r.preflightAtom=l,r.preflightScope=u,r.preflightOutcome=f;return}if(Object.is(r.preflightAtom,l)&&Object.is(r.preflightScope,u))return;if(r.secondPreflightOutcome===void 0){r.secondPreflightAtom=l,r.secondPreflightScope=u,r.secondPreflightOutcome=f;return}if(Object.is(r.secondPreflightAtom,l)&&Object.is(r.secondPreflightScope,u))return;let A=r.preflight;if(A===void 0)A=Mt(r),r.preflight=A;let g=A.get(l);if(g===void 0)g=Mt(r),A.set(l,g);g.set(u,f)},Xn=(r,l)=>{if(Object.is(r.consideredRecord,l)||Object.is(r.secondConsideredRecord,l))return!1;if(r.consideredRecord===void 0)return r.consideredRecord=l,!0;if(r.secondConsideredRecord===void 0)return r.secondConsideredRecord=l,!0;let u=r.considered;if(u===void 0)u=Qn(r),r.considered=u;if(u.has(l))return!1;return u.add(l),!0},$n=(r,l,u)=>{if(r.affectedRecord===void 0){r.affectedRecord=l,r.affectedBefore=u;return}if(r.secondAffectedRecord===void 0){r.secondAffectedRecord=l,r.secondAffectedBefore=u;return}let f=r.affected;if(f===void 0)f=Mt(r),r.affected=f;f.set(l,u)};class wn{#t=new WeakMap;#e;#o;#c;subscriberReading=!1;#r;#s=1;sourceEpoch=0;#u=!1;#a;#i;#l;#f=0;#m;#S;#h;#b=1;#y=0;#A;#v;#p;#d=0;#T;#N;#D=!1;settlementEpoch=0;#n;#C;#w;evaluate;constructor(r,l,u){this.#n=r,this.#C=l===void 0?void 0:gn.get(l),this.#w=u,this.evaluate=u?.evaluate??ye,this.#r=new At(this),this.recordCounter(7)}get runtimeDomain(){return this.#n}get postSourceApply(){return this.#u}get instrumented(){return this.#C!==void 0}get rootScope(){return this.#r}recordCounter(r,l=1){let u=this.#C;if(u===void 0)return;u(r,l)}createDraft(){return this.recordCounter(14),new Pt(this.instrumented?()=>this.recordCounter(18):void 0)}get(r,l){let u=new e,f=l,A=le(this.#n,f,u),g=bt(this.#n,"StoreTree.get");if(this.#g(r),A==="invalid")throw TypeError("StoreTree.get requires a valid State");let T=(g===void 0&&!this.#e?r.getMaterializedServedOutcome(f):void 0)??this.#U(r,f,u,g);if(T.outcome.kind!=="value"){if(T.outcome.kind==="control-error")g?.latchControlFault(T.outcome.error);throw T.outcome.error}return T.outcome.value}#U(r,l,u,f){let A=f===void 0&&!this.#e?.current(r,l)&&this.#E(1),g;this.subscriberReading=f!==void 0;try{g=this.subscriberReading||!this.#e?r.serveKnownLocal(l,u):this.#e.observe(r,l,u)}catch(T){let O=u.getControlFault();if(O.kind==="fault")f?.latchControlFault(O.error);if(A)this.#e?.failure(T);throw T}finally{if(this.subscriberReading=!1,A)this.#o=void 0,this.#e?.finish()}return(A?this.#e?.installed(r,l):void 0)??g}#E(r){if(this.#o||this.#e?.idle===!1)return!1;return this.#o=r,this.#c=this.sourceEpoch,this.external,!0}#R(r){if(this.#o)this.#o=r+1<<2|this.#o&3;this.#e?.phase(r)}get external(){let r=this.#e;if(r?.idle&&this.#o)r.beginHost(this.#o,this.#c,this.#S),this.#S=void 0;return r}reachExternal(){return this.#e??=this.#n.externalRuntime.createTree(this),this.external}hasSubscription(r,l){return this.#h?.get(r)?.has(l)===!0}sub(r,l,u){let f=l,A,g=this.#n.states.has(f)?"local":le(this.#n,f,A=new e);if(this.#g(r,"StoreTree.sub"),g==="invalid"||!this.#n.atoms.has(f)&&!this.#n.selectors.has(f)&&!this.#n.externalAtoms?.has(f)&&!rt(this.#n,f))throw TypeError("StoreTree.sub requires a valid State");let T=u,O;if(typeof u!=="function"){let x;if({settle:O,notify:T,...x}=u??{},this.#g(r),Reflect.ownKeys(x).length>0||(O??T)===void 0||O!==void 0&&typeof O!=="function"||T!==void 0&&typeof T!=="function")throw TypeError("StoreTree.sub requires a callback or settle/notify handlers")}let N=r.getMaterializedServedOutcome(f),D=(N===void 0||this.#e)&&this.#E(2);try{let x=!this.#e?N??r.serveKnownLocal(f,A??new e):this.#e.observe(r,f,A??new e);if(x.outcome.kind==="control-error")throw x.outcome.error;let V=this.#h;if(V===void 0){if(V=new Map,this.#h=V,this.instrumented)this.recordCounter(20)}let P=V.get(r);if(P===void 0){if(P=new Map,V.set(r,P),this.instrumented)this.recordCounter(20),this.recordCounter(25)}let H=P.get(f);if(H===void 0){if(H={host:this,scope:r,state:f,head:void 0,tail:void 0,reachedEpoch:0,reactions:0},P.set(f,H),this.instrumented)this.recordCounter(21),this.recordCounter(26)}let I={callback:T,reaction:O,target:H,previous:H.tail,next:void 0};if(O)H.reactions++;if(H.tail===void 0)H.head=I;else H.tail.next=I;if(H.tail=I,this.instrumented)this.recordCounter(22),this.recordCounter(27),this.recordCounter(24);return this.#e?.admit(I,x.token),qn(I)}catch(x){if(D)this.#e?.failure(x);throw x}finally{if(D)this.#o=void 0,this.#e?.finish()}}removeSubscription(r){let l=r.target;if(l===void 0)return;if(un(this.#n),this.#e?.idle)return this.#e.cleanup(()=>this.removeSubscription(r));let{previous:u,next:f}=r;if(u===void 0)l.head=f;else u.next=f;if(f===void 0)l.tail=u;else f.previous=u;if(r.reaction!==void 0)r.reaction=void 0,l.reactions--;r.callback=void 0,r.target=void 0,r.previous=void 0,r.next=void 0;let A=this.instrumented;if(A)this.recordCounter(23),this.recordCounter(27,-1);if(l.head!==void 0)return;let g=this.#h,T=g?.get(l.scope);if(T?.get(l.state)===l){if(T.delete(l.state),A)this.recordCounter(26,-1)}if(T!==void 0&&T.size===0){if(g?.delete(l.scope),A)this.recordCounter(25,-1)}if(g?.size===0)this.#h=void 0;this.#e?.releaseRoot(l.scope,l.state)}scope(r,l,u){if(l!==0&&(typeof u==="object"||typeof u==="function")&&u!==null)le(this.#n,u,new e);if(this.#g(r,"StoreTree.scope"),l===0)return this.#M(r);if(l!==1||typeof u!=="string")throw TypeError("StoreTree.scope requires a string name");let f=r.namedChildren.get(u);if(f!==void 0)return this.recordCounter(9),f.facade;return this.recordCounter(10),this.#M(r,u)}dispose(r){if(Ae(this.#n,"StoreTree.dispose"),r.status!=="live")return;if(this.#e?.idle)return this.#e.cleanup(()=>this.dispose(r));let l=[],u=[Object.freeze({node:r,expanded:!1})];while(u.length>0){let{node:f,expanded:A}=u.pop();if(A){l.push(f);continue}f.markDisposing(),u.push(Object.freeze({node:f,expanded:!0}));let g=[];f.children.forEach((T)=>g.push(T));for(let T=g.length-1;T>=0;T--)u.push(Object.freeze({node:g[T],expanded:!1}))}for(let f of l){this.recordCounter(5);let A=f.parent;if(A!==void 0){if(f.name!==void 0&&Object.is(A.namedChildren.get(f.name),f))A.namedChildren.delete(f.name);A.children.delete(f)}this.#X(f),f.dropRecords(),f.namedChildren.clear(),f.children.clear(),f.markDisposed()}if(Yt(),Object.is(r,this.#r))this.#t=new WeakMap,this.#e=void 0}txn(r,l,u){if(this.#g(r,"StoreTree.txn"),typeof l!=="function"||u!==void 0&&typeof u!=="string")throw TypeError("StoreTree.txn requires a callback");let f=this.#E(3);try{return this.#I(r,l)}catch(A){if(f)this.#e?.failure(A);throw A}finally{if(f)this.#o=void 0,this.#e?.finish()}}#I(r,l){let u=this.createDraft();try{let f=jt(this,u,r),A=ln(this.#n,u.transaction,()=>l(f));u.close();let g=new e;return nt(this.#n,g,()=>Vt(A)),this.#_(u),A}finally{u.close(),u.release()}}registerCommit(r,l,u){if($e(this.#n,r.transaction,r.active),this.#g(l),typeof u!=="function")throw TypeError("Transaction.onCommit requires a function");(r.commitEntries??=[]).push({scope:l,callback:u})}get fallbackRecords(){return this.#t}transactionGet(r,l,u){let f=u,A=new e,g=le(this.#n,f,A);if($e(this.#n,r.transaction,r.active),this.#g(l),g==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#n.atoms.has(f)){let O=this.readDraftAtomOutcome(r,l,f,A);if(O.kind!=="value")throw O.error;return O.value}if(!this.#n.selectors.has(f)&&!this.#n.externalAtoms?.has(f)){let O=rt(this.#n,f);if(!O)throw TypeError("Transaction.get requires a readable State");return kn(O,r,l,f)}let T=r.getScratchHost(l);if(T===void 0){if(T=this.createScratchSelectorHost(r,l),r.installScratchHost(l,T))this.recordCounter(15)}return T.readSelector(f)}mutate(r,l,u,f,A){let g=f,T=new e,O=`${r===void 0?"StoreTree":"Transaction"}.${u}`,N=le(this.#n,g,T);if(r===void 0)Ae(this.#n,O);else $e(this.#n,r.transaction,r.active);this.#g(l);let D=N==="local"&&this.#n.atoms.has(g),x;if(D?u==="delete":N!=="local"||typeof g==="function"||(x=rt(this.#n,g))===void 0)throw TypeError(`${O} requires a valid State`);let P=r===void 0&&this.#E(3);try{let H=r===void 0,I=r??this.createDraft();try{if(x!==void 0)x.stage(I,l,u,g,A,T);else if(u==="set")this.#$(I,l,g,A,T);else if(u==="update")this.#Z(I,l,g,A,T,O);else this.#J(I,l,g,T);if(!H)return;I.close(),this.#_(I)}finally{if(H)I.close(),I.release()}}catch(H){if(P)this.#e?.failure(H);throw H}finally{if(P)this.#o=void 0,this.#e?.finish()}}transactionScope(r,l,u,f,A){let g=new e;if(typeof u!=="string")le(this.#n,u,g);$e(this.#n,r.transaction,r.active),this.#g(l);let T=this.#Q(l,u);if(f!==1&&f!==2)throw TypeError("Transaction.scope requires a target and optional callback");let O=jt(this,r,T);if(f===1)return O;if(typeof A!=="function")throw TypeError("Transaction.scope requires a callback function");let N;try{N=A(O)}catch(x){let V=new e;return nt(this.#n,V,()=>mn(x))}let D=new e;return nt(this.#n,D,()=>Vt(N)),N}createOutcomeToken(){return Object.freeze({id:this.#s++})}createScratchSelectorHost(r,l,u=!1){return this.recordCounter(3),new Nt(Object.freeze({trackPath:u,resolve:(f,A)=>this.#Y(f,A),read:(f,A,g,T)=>this.#ee(r,l,f,A,g,T),baseline:u?()=>{return}:(f)=>l.captureCommittedSelectorSuccess(f),run:(f,A)=>yt(this.#n,f,A)}),r.generation,this.evaluate)}#Y(r,l){if(Xe(this.#n,r,l)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#n.atoms.has(r))return Object.freeze({kind:"atom"});let u=this.#n.selectors.get(r);if(u!==void 0)return Object.freeze({kind:"selector",definition:u});if(rt(this.#n,r))return Object.freeze({kind:"collection"});if(this.#n.externalAtoms?.has(r))return Object.freeze({kind:"external"});throw TypeError("Unknown scratch StoreTree State")}#M(r,l){let u=new At(this,r,l);this.recordCounter(7);let f=new Ft(this,u,this.#w);if(r.children.add(u),l!==void 0)r.namedChildren.set(l,u);return f}#Q(r,l){if(typeof l==="string"){let g=r.namedChildren.get(l);if(g===void 0)throw new L;return this.#g(g),g}let u=l,f=this.#n.stores.get(u);if(f!==void 0){let g=f;if(this.#g(g),!Object.is(g.coordinator,this))throw new _;return g}let A=this.#n.transactionCursors.get(u);if(A!==void 0){if(!A.active)throw new C;throw new R}throw new R}#g(r,l){if(l!==void 0)Ae(this.#n,l);if(r.status!=="live")throw new S}#X(r){let l=this.#h,u=l?.get(r);if(u===void 0)return;let f=0;for(let A of u.values()){let g=A.head;while(g!==void 0){let T=g.next;g.callback=void 0,g.reaction=void 0,g.target=void 0,g.previous=void 0,g.next=void 0,f++,g=T}A.head=void 0,A.tail=void 0,A.reactions=0,this.#e?.releaseRoot(r,A.state)}if(l.delete(r),l.size===0)this.#h=void 0;if(this.instrumented)this.recordCounter(23,f),this.recordCounter(27,-f),this.recordCounter(26,-u.size),this.recordCounter(25,-1)}#$(r,l,u,f,A){let g=c(this.#n,A,()=>tt(f));if(g.kind==="error")throw g.error;let T=this.#x(r,l,u,A);this.#K(r,l,u,g.value,T,A)}#Z(r,l,u,f,A,g){if(typeof f!=="function")throw TypeError(`${g} requires an updater function`);let T=this.#x(r,l,u,A),O=r.hasIntents?this.readDraftAtomOutcome(r,l,u,A):T.outcome;if(O.kind!=="value")throw O.error;let N=this.#oe(f,O.value,A);this.#K(r,l,u,N,T,A)}#J(r,l,u,f){r.stage(l,this.#F(r,l,u,f))}#F(r,l,u,f){this.#x(r,l,u,f);let A=l.parent===void 0?Object.freeze({outcome:this.#P(r,u,f),reachesFallback:!0}):this.#z(r,l.parent,u,f);if(A.outcome.kind!=="value")throw A.outcome.error;let g=A.reachesFallback&&r.hasFallback(u);return Object.freeze({kind:"reset",atom:u,publishDraftFallback:g})}resetAll(r,l,u){if($e(this.#n,r.transaction,r.active),this.#g(l),u!==0)throw TypeError("Transaction.resetAll accepts no arguments");if(l.parent===void 0)throw TypeError("Transaction.resetAll requires a child scope cursor");let f=[];l.ownedAtoms?.collect(f),l[ce]?.forEach((O)=>f.push(O)),r.forEachIntent((O,N)=>{if(Object.is(O,l))f.push(N.atom)});let A=new e,g=[],T=new Set;for(let O of f){if(T.has(O))continue;T.add(O);let N=r.getIntent(l,O);if(N===void 0){if(!l.atomOverrides.has(O))continue}else if(N.kind==="reset")continue;g.push(this.#F(r,l,O,A))}for(let O of g)r.stage(l,O);this.#n[i]?.resetAll?.(r,l)}#x(r,l,u,f){let A=r.getAtomBaseline(l,u);if(A!==void 0)return A;let g=l.atomOverrides.has(u),T=l,O;while(T!==void 0){if(T.atomOverrides.has(u)){O=se(T.atomOverrides.get(u));break}T=T.parent}let N=O===void 0,D=Object.freeze({owned:g,outcome:O??this.#P(r,u,f),reachesFallback:N});return r.setAtomBaseline(l,u,D),D}readDraftAtomOutcome(r,l,u,f){return this.#z(r,l,u,f).outcome}#ee(r,l,u,f,A,g){if(f==="atom")return this.readDraftAtomOutcome(r,l,u,A);if(f==="external")return this.#n.externalRuntime.read(r,u,A,g,this.#C);return this.#n[i].read(r,l,u)}#z(r,l,u,f){let A=l;while(A!==void 0){let g=r.getIntent(A,u);if(g?.kind==="set")return Object.freeze({outcome:se(g.value),reachesFallback:!1});if(g===void 0&&A.atomOverrides.has(u))return Object.freeze({outcome:se(A.atomOverrides.get(u)),reachesFallback:!1});A=A.parent}return Object.freeze({outcome:this.#P(r,u,f),reachesFallback:!0})}#P(r,l,u){let f=this.#t.get(l);if(f!==void 0)return f;let A=this.#O(l);if(A.fallback.kind==="eager")return se(A.fallback.value);let g=A.fallback.initialize,T=r.getFallback(l);if(T!==void 0)return T;let O=yn(c(this.#n,u,()=>Et(g)));return r.setFallback(l,O),O}#te(r,l,u,f){let A=this.#O(r).equal;if(A===void 0)return Object.is(l,u)?l:u;return this.#ne(A,l,u,f)?l:u}#ne(r,l,u,f){return c(this.#n,f,()=>{let A;try{A=r(l,u)}catch(T){let O=t(T);if(O.kind==="not-thenable")throw T;if(O.kind==="inspection-error")throw O.error;throw n(O),new y}let g=t(A);if(g.kind==="inspection-error")throw g.error;if(g.kind==="thenable")throw n(g),new y;if(A!==!0&&A!==!1)throw new y;return A})}#oe(r,l,u){return c(this.#n,u,()=>{let f;try{f=r(l)}catch(g){let T=t(g);if(T.kind==="not-thenable")throw g;if(T.kind==="inspection-error")throw T.error;throw n(T),new m}let A=tt(f);if(A.kind==="error")throw A.error;return A.value})}#_(r){this.#R(2);let l;if(r.hasRows){if(l=this.#n[i]?.plan(r),l===void 0)throw Error()}if(!r.hasIntents&&l===void 0){ut(r);return}let{singleIntent:u,singleIntentScope:f}=r;if(l===void 0&&u?.kind==="reset"&&f!==void 0&&!u.publishDraftFallback&&r.getAtomBaseline(f,u.atom)?.owned===!1){ut(r);return}let A=Yn(this.instrumented?()=>this.recordCounter(19):void 0),g,T;if(u!==void 0&&f!==void 0)g=this.#B(r,f,u,A);else r.forEachIntent((D,x)=>{let V=this.#B(r,D,x,A);if(g===void 0){g=V;return}if(T===void 0)T=[];T.push(V)});if(this.#R(6),this.#w?.(1,r,this.#n.atoms),this.#R(3),g!==void 0)this.#L(r,g);if(T!==void 0)for(let D of T)this.#L(r,D);let O=g===void 0?!1:this.#H(g);if(T!==void 0)for(let D of T){let x=this.#H(D);O||=x}if(l!==void 0){let D=l.commit(0);O||=D}if(ut(r),g!==void 0)this.#W(g);if(T!==void 0)for(let D of T)this.#W(D);if(l!==void 0)l.commit(1);let N=this.#d!==0;if(!N)this.beginNotificationSettlement();try{let D,x,{affectedRecord:V,affectedBefore:P}=A;if(V!==void 0&&P!==void 0)D=this.#j(A,V,P);let{secondAffectedRecord:H,secondAffectedBefore:I}=A;if(H!==void 0&&I!==void 0){let G=this.#j(A,H,I);if(G!==void 0)if(D===void 0)D=G;else x=[G]}if(A.affected!==void 0)for(let[G,K]of A.affected){let re=this.#j(A,G,K);if(re===void 0)continue;if(D===void 0)D=re;else{if(x===void 0)x=[];x.push(re)}}if(l!==void 0){let G=l.commit(2);if(G!==void 0)for(let K of G){let re=K;if(D===void 0)D=re;else{if(x===void 0)x=[];x.push(re)}}}if(O)this.sourceEpoch+=1,this.recordCounter(0);this.#R(6);try{this.#w?.(2,D===void 0?0:1+(x?.length??0))}catch(G){if(N)this.#T??={error:G};else if(!this.#e)throw G;else this.#e.failure(G,"instrumenting")}this.propagateFromSources(D,x)}catch(D){if(!N)this.clearNotificationSettlement();throw D}}#B(r,l,u,f){let A=r.getAtomBaseline(l,u.atom);if(A===void 0)throw Error("TreeDraft atom baseline is missing");this.#G(r,l,u.atom,f);let g=Object.freeze({scope:l,intent:u,ownershipChanged:u.kind==="set"?!A.owned||!Object.is(l.atomOverrides.get(u.atom),u.value):A.owned}),T=l.getAtomView(u.atom);if(T!==void 0)this.#ie(r,T,f);return g}#L(r,l){if(!l.intent.publishDraftFallback)return;let u=r.getFallback(l.intent.atom);if(u!==void 0&&!this.#t.has(l.intent.atom))this.#t.set(l.intent.atom,u),this.recordCounter(13)}#H(r){let{intent:l,scope:u}=r;if(l.kind==="set")u.atomOverrides.set(l.atom,l.value);else u.atomOverrides.delete(l.atom);let f=this.#n[ce]?.apply(u,l);if(u.parent!==void 0&&f!==!0){if(l.kind==="set"&&(u.ownedAtoms??this.#re(u)).add(l.atom))this.recordCounter(51)}return r.ownershipChanged}#re(r){return r.ownedAtoms=new xt(r,this.#C===void 0?void 0:(l)=>this.recordCounter(52,l))}#W({scope:r,intent:l}){let u=r.getAtomView(l.atom);if(u===void 0)return;if(l.kind==="set"||r.parent===void 0)r.detachAtomView(u);else r.attachAtomView(u,this.#de(r.parent,l.atom))}#j(r,l,u){let f=It(r,l.atom,l.scope);if(f===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter(16),pe(u,f))return;return l.scope.updateAtomView(l,f),l}#ie(r,l,u){let f=[l];while(f.length!==0){let A=f.pop();if(!Xn(u,A))continue;let g=A.served.outcome,T=this.#G(r,A.scope,A.atom,u);if(pe(g,T))continue;$n(u,A,g);let O=f.length;A.inheritingChildren.forEach((N)=>{this.recordCounter(1),f.push(N)});for(let N=O,D=f.length-1;N<D;N++,D--){let x=f[N];f[N]=f[D],f[D]=x}}}#G(r,l,u,f){let A=It(f,u,l);if(A!==void 0)return A;let g=l,T,O,N;while(g!==void 0){let D=It(f,u,g);if(D!==void 0){N=D;break}if(T===void 0)T=g;else{if(O===void 0)O=[];O.push(g)}let x=r.getIntent(g,u);if(x?.kind==="set"){N=se(x.value);break}if(x===void 0&&g.atomOverrides.has(u)){N=se(g.atomOverrides.get(u));break}g=g.parent}if(N??=this.#se(r,u),T!==void 0)bn(f,u,T,N),this.recordCounter(17);if(O!==void 0)for(let D of O)bn(f,u,D,N),this.recordCounter(17);return N}#se(r,l){let u=this.#t.get(l);if(u!==void 0)return u;let f=r.getFallback(l);if(f!==void 0)return f;let A=this.#O(l);if(A.fallback.kind==="eager")return se(A.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ae(r){let l=this.#t.get(r);if(l!==void 0)return l;let u=this.#O(r);if(u.fallback.kind==="eager")return se(u.fallback.value);throw Error("Committed Atom fallback is not materialized")}#de(r,l){let u=r,f=[],A;while(!0){let g=u.getAtomView(l);if(g!==void 0){A=g;break}if(u.atomOverrides.has(l)){A=u.createAtomView(l,se(u.atomOverrides.get(l)));break}if(u.parent===void 0){A=u.createAtomView(l,this.#ae(l));break}f.push(u),u=u.parent}for(let g=f.length-1;g>=0;g--)A=f[g].createAtomView(l,A.served.outcome,A);return A}serveScopeAtom(r,l,u){let f=r,A=[],g;while(!0){let T=f.getAtomView(l);if(T!==void 0){g=T;break}if(f.atomOverrides.has(l)){g=f.createAtomView(l,se(f.atomOverrides.get(l)));break}if(f.parent===void 0){g=f.createAtomView(l,this.#ce(l,u));break}this.recordCounter(6),A.push(f),f=f.parent}for(let T=A.length-1;T>=0;T--)g=A[T].createAtomView(l,g.served.outcome,g);return g.served}#ce(r,l){let u=this.#t.get(r);if(u!==void 0)return u;let f=this.#O(r);if(f.fallback.kind==="eager")return se(f.fallback.value);let A=f.fallback.initialize,g=yn(c(this.#n,l,()=>Et(A)));return this.#t.set(r,g),this.recordCounter(13),g}#O(r){let l=this.#n.atoms.get(r);if(l===void 0)throw TypeError("Unknown committed StoreTree Atom");return l}propagateFromSources(r,l,u){let f=this.#d!==0;if(r===void 0&&u===void 0){if(!f)this.clearNotificationSettlement();return}if(r!==void 0)this.recordCounter(4);let A=this.#e?.beginPropagation();if(this.#R(4),this.#a=[],this.#u=!0,this.#D=u!==void 0,!f)this.settlementEpoch++;let g;try{try{if(u?.(),r?.scope.markDependents(r.atom),l!==void 0)for(let P of l)P.scope.markDependents(P.atom);let V=0;while(V<this.#a.length||this.#e?.pendingLifecycle){if(V>=this.#a.length){this.#i=void 0,this.#l=void 0,this.#f=0,this.#m=void 0,this.#e.settleLifecycle();continue}let P=this.#a[V++],H=this.#a[V++];try{this.#V(P,H)}catch(I){if(f)this.#T??={error:I};else if(u===void 0)throw I;else this.#e.failure(I,"settling")}}}finally{g=this.#N,this.#N=void 0,this.#u=!1,this.#D=!1,this.#a=void 0,this.#i=void 0,this.#l=void 0,this.#f=0,this.#m=void 0,this.#e?.endPropagation(A)}if(f)return;let T=this.#p===void 0?g:this.#le(g),O=this.#he(),N=this.#S?.[0]?.error,D=T===void 0?O:O===void 0?T:[...T,...O];if(D===void 0){if(N!==void 0)throw N;return}if(D===g&&D.length===1&&N===void 0)throw D[0];let x=new a(N===void 0?D:[N,...D]);throw this.#e?.notificationFailure(x)??x}finally{if(!f)this.#S=void 0}}#le(r){let l,u=0;try{for(let f=0;this.#p!==void 0;f++){if(l=this.#p,this.#p=void 0,u=0,f===Gn){(r??=[]).push(new j);break}for(;u<l.length;u++){let A=l[u];A.pending=!1;let{reaction:g,target:T}=A;if(g===void 0||T===void 0)continue;let O=this.#ue(T.scope,g);if(O!==void 0)(r??=[]).push(O.error)}}}finally{if(l!==void 0)for(;u<l.length;u++)l[u].pending=!1}return r}#ue(r,l){let u;this.#d++;try{this.#w?.(3,r),this.#I(r,l),u=this.#T}catch(f){let A=f;try{nt(this.#n,new e,()=>{let g=t(f);if(g.kind==="thenable")n(g)})}catch(g){A=g}u={error:A}}finally{this.#d--,this.#T=void 0}try{this.#w?.(4,u!==void 0)}catch(f){u??={error:f}}return u}beginNotificationSettlement(){this.#A=void 0,this.#v=void 0,this.#y=this.#h===void 0?0:this.#b++}clearNotificationSettlement(){this.#y=0,this.#A=void 0,this.#v=void 0;let r=this.#p;if(r===void 0)return;this.#p=void 0;for(let l of r)l.pending=!1}reachSubscriptionTarget(r,l){let u=this.#y,f=this.#h?.get(r)?.get(l);if(u===0||f===void 0)return;if(f.reactions!==0)this.#fe(f);if(f.reachedEpoch===u)return;if(f.reachedEpoch=u,this.instrumented)this.recordCounter(28);if(this.#A===void 0){this.#A=f;return}if(this.#v===void 0)this.#v=[f];else this.#v.push(f)}#fe(r){let l=r.head;while(l!==void 0){if(l.reaction!==void 0&&!l.pending&&l.status!=="provisional")l.pending=!0,(this.#p??=[]).push(l);l=l.next}}#he(){let r=this.#A;if(r===void 0){this.clearNotificationSettlement();return}let l,u,f=(N)=>{let D=N.head;while(D!==void 0){let x=!this.#e?D.callback:this.#e.notificationCallback(D);if(x!==void 0)if(l===void 0)l=x;else if(u===void 0)u=[l,x];else u.push(x);D=D.next}};f(r);let A=this.#v;if(A!==void 0)for(let N of A)f(N);if(this.clearNotificationSettlement(),l===void 0)return;this.#R(7);let g=Object.freeze(u??[l]),T=this.instrumented;if(T)this.recordCounter(29);let O;for(let N of g){if(T)this.recordCounter(30);let D=new e;try{cn(this.#n,D,()=>{let x;try{if(x=t(N()),x.kind==="thenable")n(x)}catch(V){let P=t(V);if(P.kind==="thenable")n(P);throw V}if(x.kind==="inspection-error")throw x.error})}catch(x){if((O??=[]).push(x),T)this.recordCounter(31)}}return O}reportSelectorFailure(r){if(this.#a===void 0)return;if(this.#d!==0)this.#T??={error:r};else if(this.#D)this.#e.failure(r,"settling");else(this.#N??=[]).push(r)}enqueueSelector(r,l){let u=this.#a;if(u===void 0)return!1;let f=this.#q(r,l);if((f&4)!==0)this.#k(r,l,0,5),f&=-6;if((f&1)!==0)return!0;return this.#k(r,l,1),u.push(r,l),!0}prepareSelectorRead(r,l,u){if(this.#a===void 0)return;if(this.#e?.skipSelectorRead(r,l,u))return;this.#V(r,l,u)}#V(r,l,u){let f=this.#q(r,l);if((f&6)!==0)return;this.#k(r,l,8);try{let A=r.getSelectorGraphVersion(),g=(f&8)!==0?void 0:r.getCommittedSelectorDependencies(l);if(g!==void 0){for(let T of g)if(this.#n.selectors.has(T.node))this.#V(r,T.node)}if(r.isSelectorDirty(l)){this.#k(r,l,2);let T=A===r.getSelectorGraphVersion(),O=u!==void 0&&T?u:new e;try{r.serve(l,O)}catch(N){if(this.#e?.dormantPull===!0)throw N;r.publishEscapedFailure(l,N,O)}}this.#k(r,l,4)}catch(A){if(this.#e?.recordSelectorFault(r,l,A))this.#k(r,l,4);throw A}finally{this.#k(r,l,0,10&~f)}}#q(r,l){if(Object.is(this.#i,r)&&Object.is(this.#l,l))return this.#f;return this.#m?.get(r)?.get(l)??0}#k(r,l,u,f=0){if(this.#i===void 0){this.#i=r,this.#l=l,this.#f=u&~f;return}if(Object.is(this.#i,r)&&Object.is(this.#l,l)){this.#f=(this.#f|u)&~f;return}let A=this.#m;if(A===void 0)A=new Map,this.#m=A;let g=A.get(r);if(g===void 0)g=new Map,A.set(r,g);g.set(l,((g.get(l)??0)|u)&~f)}latchPropagationControlFault(r){if(this.#e?.idle===!1)this.#e.failure(r.error,"settling",r.origin);else(this.#S??=[]).push(r)}#K(r,l,u,f,A,g){let T=A.outcome.kind==="value"?this.#te(u,A.outcome.value,f,g):f;r.stage(l,Object.freeze({kind:"set",atom:u,value:T,publishDraftFallback:A.reachesFallback&&r.hasFallback(u)}))}}var Zn=(r,l)=>{let u=r.coordinator,f=new e,A=l,g=le(u.runtimeDomain,A,f);if(Ae(u.runtimeDomain,"adapter readHydrationSnapshot"),r.status!=="live")throw new S;let T,O;if(g!=="invalid")if(u.runtimeDomain.atoms.has(A))T=0;else if(u.runtimeDomain.selectors.has(A)||u.runtimeDomain.externalAtoms?.has(A))T=1;else O=rt(u.runtimeDomain,A);if(T===void 0&&!O)throw TypeError("readHydrationSnapshot requires a valid State");let N=u.createDraft(),D;try{if(T===0){let x=u.readDraftAtomOutcome(N,r,A,f);if(x.kind!=="value")throw x.error;return x.value}if(T===void 0)return kn(O,N,r,A);return D=u.createScratchSelectorHost(N,r,!0),D.readSelector(A)}finally{D?.revoke(),N.close(),N.forEachFallback((x,V)=>{if(u.fallbackRecords.has(x))return;u.fallbackRecords.set(x,V),u.recordCounter(13)}),N.release()}};class Ft{constructor(r,l,u){this.get=(f)=>r.get(l,f),this.sub=(f,A)=>r.sub(l,f,A),this.set=(f,A)=>r.mutate(void 0,l,"set",f,A),this.update=(f,A)=>r.mutate(void 0,l,"update",f,A),this.reset=(f)=>r.mutate(void 0,l,"reset",f),this.delete=(f)=>r.mutate(void 0,l,"delete",f),this.txn=(f,A)=>r.txn(l,f,A),this.scope=function(f){return r.scope(l,arguments.length,f)},this.dispose=()=>r.dispose(l),l.installFacade(this),ot(this,r.runtimeDomain.ownerToken),r.runtimeDomain.stores.set(this,l),r.recordCounter(8),u?.(0,this,l),Object.freeze(this)}}var Rn=(r)=>{if(r.equal!==void 0&&typeof r.equal!=="function")throw TypeError("Atom equal must be a function");return{...r.name===void 0?{}:{name:r.name},...r.equal===void 0?{}:{equal:r.equal}}},Tn=()=>{let r={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0};return Object.freeze({[X]:r})},Fe=(r,l,u={})=>{let f=r[X];b(f);let A=new e,g=c(f,A,()=>tt(l));if(g.kind==="error")throw g.error;let T=k(f,F("atom"));return f.atoms.set(T,Object.freeze({fallback:Object.freeze({kind:"eager",value:g.value}),...Rn(u)})),T},Be=(r,l,u={})=>{let f=r[X];if(b(f),typeof l!=="function")throw TypeError("atomLazy requires an initializer function");let A=k(f,F("atom"));return f.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:l}),...Rn(u)})),A},me=(r,l,u={})=>{let f=r[X];if(b(f),typeof l!=="function")throw TypeError("selector requires a getter function");if(u.equal!==void 0&&typeof u.equal!=="function")throw TypeError("selector equal must be a function");let A=k(f,F("selector")),g=Object.freeze({node:A,get:l,...u.name===void 0?{}:{name:u.name},...u.equal===void 0?{}:{equal:u.equal}});return f.selectors.set(A,g),A},ze=(r)=>{let l=r[X],u=(g)=>{let T=new e;if(le(l,g,T)==="invalid")return;return l.stores.get(g)};return Object.freeze({assertStore:(g)=>{let T=u(g);if(Ae(l,"adapter assertStore"),T===void 0)throw TypeError("assertStore requires a valid Store");if(T.status!=="live")throw new S},read:(g,T)=>{if(u(g)===void 0)throw bt(l,"adapter read"),TypeError("read requires a valid Store");return g.get(T)},subscribe:(g,T,O)=>{if(u(g)===void 0)throw Ae(l,"adapter subscribe"),TypeError("subscribe requires a valid Store");return g.sub(T,O)},readHydrationSnapshot:(g,T)=>{let O=u(g);if(O===void 0)throw Ae(l,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return Zn(O,T)}})},we=(r,l,u)=>{let f=r[X];Ae(f,"createStoreTree");let A=new wn(f,l,u);return new Ft(A,A.rootScope,u)};var o=Tn(),He=(r,l)=>we(o,r,l);
|
|
2
|
+
export{p,Ce,ye,e,i,pe,De,M,a,d,v,j,w,C,h,m,y,S,L,_,R,t,n,E,c,Se,be,b,F,k,s,ge,Ne,Pe,Ve,B,ve,he,Me,z,Re,je,Le,_e,Fe,Be,me,ze,we,o,He};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var G=35,U=36,X=37,x=38,Y=39,l=40,r=41,f=42,J=43,Q=44,Z=45,ee=46,te=47,A=48,I=64,Ie=65,Te=66,ne=67,T=68,Oe=69,oe=70,O=71,re=72,D=73,N=74,ie=75,se=76,ae=49,ce=50,g=51,le=52,P=53,de=54,ue=55,fe=56,V=57;
|
|
2
|
+
export{G,U,X,x,Y,l,r,f,J,Q,Z,ee,te,A,I,Ie,Te,ne,T,Oe,oe,O,re,D,N,ie,se,ae,ce,g,le,P,de,ue,fe,V};
|
|
@@ -0,0 +1,2 @@
|
|
|
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},Ee=(e,n)=>w(e,n);
|
|
2
|
+
export{Ee};
|