valdres 1.0.0-beta.40 → 1.0.0-beta.41

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