valdres 1.0.0-beta.43 → 1.0.0-beta.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-4wpe8fhf.js +2 -0
- package/dist/{chunk-gm0x0qe5.js → chunk-yycx0cb8.js} +1 -1
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-4wpe8fhf.js +2 -0
- package/dist/development/{chunk-gm0x0qe5.js → chunk-yycx0cb8.js} +1 -1
- package/dist/development/index.js +1 -1
- package/dist/development/inspect.js +1 -1
- package/dist/development/query.js +1 -1
- package/dist/index.js +1 -1
- package/dist/inspect.js +1 -1
- package/dist/query.js +1 -1
- package/dist/types/v1-internal/committed-store-tree/commit-hooks.d.ts +8 -0
- package/dist/types/v1-internal/committed-store-tree/committed-store-tree.d.ts +1 -0
- package/dist/types/v1-internal/committed-store-tree/tree-transaction.d.ts +3 -0
- package/dist/types/v1-internal/committed-store-tree/types.d.ts +19 -0
- package/package.json +1 -1
- package/dist/chunk-pf9vsntr.js +0 -2
- package/dist/development/chunk-pf9vsntr.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{La as e,Na as r}from"../chunk-
|
|
1
|
+
import{La as e,Na as r}from"../chunk-4wpe8fhf.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 q extends Error{#t=!0;static is(e){return typeof e==="object"&&e!==null&&#t in e}seal(){Object.freeze(this)}}var Q,yt=()=>{if(Q!==void 0)return Q;Q="";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 Q="accessor",Q}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)Q="lazy"}catch{}return Q},dn={writable:!1,configurable:!1},bt=(e,t)=>{if(yt()!=="lazy"){Object.freeze(e);return}for(let n of["message","code","name",t,"cause"])Object.defineProperty(e,n,dn);Object.preventExtensions(e)},Te=(e,t,n)=>{let o=yt()==="accessor"&&q.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 ne extends q{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;name="SelectorGetterError";constructor(e,t){super("Selector getter failed");this.selector=e,this.cause=t,bt(this,"selector")}}class Ce extends q{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;name="SelectorDependencyError";constructor(e,t){super("Selector dependency failed");this.dependency=e,this.cause=t,bt(this,"dependency")}}class le extends q{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 Y extends q{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 Ye extends q{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class Oe extends q{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 Qe extends q{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var z=Symbol(),K=Symbol(),Ee=Symbol(),x=Symbol(),Xe=(e,t)=>e.kind===t.kind&&(e.kind==="value"?Object.is(e.value,t.value):Object.is(e.error,t.error)),At=Object.freeze({kind:"not-thenable"}),cn=()=>{},ln=Reflect.apply,vt=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}var gt=new WeakSet,Mn=(e)=>gt.has(e);class $e extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ze extends T{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 re extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Ne extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Je extends T{code="VALDRES_SETTLE_LIMIT";constructor(){super("Store updates did not settle");this.name="SettleLimitError",this.seal()}}class De extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class xe extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class ue extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class fe extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class he extends T{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class pe extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class et extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class tt extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class Pe extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var P=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return At;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):At}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{ln(e.then,e.target,[void 0,cn])}catch{}},Se=(e)=>{let t=P(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 j(t),Object.freeze({kind:"error",error:new fe})},nt=(e)=>{try{return Se(e())}catch(t){let n=P(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 j(n),Object.freeze({kind:"error",error:new fe})}},me=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},U=(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 me(e,i,n)}finally{let s=t.getControlFault();if(s.kind==="fault")throw e.externalRuntime?.guard(s.error),s.error}},kt=(e,t,n)=>{try{return me(e,Object.freeze({kind:"subscriber",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},je=(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 me(e,s,n)},wt=(e,t,n)=>me(e,Object.freeze({kind:"transaction",transaction:t}),n),ye=(e,t,n)=>{try{return me(e,Object.freeze({kind:"transaction-result",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},Rt=(e)=>{let t=new re;throw e.externalRuntime?.guard(t),t},H=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Ne(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new De;Rt(e)},Ve=(e,t)=>{if(e.activity?.kind==="subscriber")return e.activity.session;H(e,t)},Tt=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new re;throw e.latchControlFault(r),t.latchControlFault(r),r},Ct=(e)=>{Ve(e,"Store unsubscribe")},ie=(e,t,n)=>{if(!n)throw new xe;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Ne("Transaction cursor operation");if(o?.kind==="guarded-callback"||o?.kind.startsWith("external-"))Rt(e);throw new De},Ot=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},oe=(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,vt);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new $e;throw gt.add(r),Ot(e,n).latchControlFault(r),r}}return"invalid"},_=(e,t,n)=>{if(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t))return"local";let o=e.activity,r=Ot(e,n);if(o!==void 0&&"session"in o)try{return oe(e,t,r)}finally{let i=r.getControlFault();if(i.kind==="fault")throw i.error}return U(e,r,()=>oe(e,t,r))},be=(e,t)=>(Object.defineProperty(e,vt,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),se=(e)=>{let t=e[K];if(t===void 0||t.allowDefinitions)return;let n=t.session.getControlFault();if(n.kind==="fault")throw n.error;let o=new re;throw t.session.latchControlFault(o),o},Ie=(e)=>({kind:e}),Ae=(e,t)=>{se(e);let n=e[K],o=Object.freeze(be(t,e.ownerToken));return e.states.add(o),n?.definitions?.add(o),o};var g,X=0,Me,ve=!1,xt=1024,Fe=xt,ze,Et=(e)=>{setTimeout(()=>{throw e},0)},Nt=(e)=>{let t=(n)=>Et(AggregateError([e,n],"Commit callback and error reporter failed"));try{let n=globalThis.reportError;if(typeof n!=="function")return Et(e);let o=n.call(globalThis,e);if(o!==null&&(typeof o==="object"||typeof o==="function"))Promise.prototype.then.call(Promise.resolve(o),void 0,t)}catch(n){t(n)}},un=()=>{if(ve||g===void 0)return;let e=()=>{if(Me!==e)return;Me=void 0,Pt()};Me=e,queueMicrotask(e)},Dt=()=>{let e=ze??={};setTimeout(()=>{if(ze!==e||ve)return;ze=void 0,Fe=xt,Pt()},0)},Pt=()=>{if(ve||g===void 0)return;if(Me=void 0,ze===void 0)Dt();ve=!0;try{while(g!==void 0&&X<g.length&&Fe>0){let e=g[X];if(g[X++]=void 0,Fe--,e===void 0||e.scope.status!=="live")continue;try{let t=e.callback,n=t();if(n!==null&&(typeof n==="object"||typeof n==="function"))Promise.prototype.then.call(Promise.resolve(n),void 0,Nt)}catch(t){Nt(t)}}}finally{if(ve=!1,g!==void 0&&X===g.length)g=void 0;else if(g!==void 0)g.splice(0,X);if(X=0,g!==void 0&&Fe===0)Dt()}},_e=(e)=>{let t=e.commitEntries;if(t===void 0)return;if(e.commitEntries=void 0,g===void 0)g=t;else for(let n of t)g.push(n);un()},jt=()=>{if(g===void 0)return;for(let e=X;e<g.length;e++)if(g[e]?.scope.status!=="live")g[e]=void 0};var Vt=Object.freeze({kind:"not-thenable"}),fn=()=>{},hn=Reflect.apply,It=Symbol("selector dependency path root"),zt=(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})}},_t=(e)=>{try{hn(e.then,e.target,[void 0,fn])}catch{}},pn=(e)=>Object.freeze(e),Sn=(e)=>Object.freeze(e),V=(e,t,n,o)=>{let r=Sn(o);return Object.freeze({selector:e,token:t,outcome:pn(n),dependencies:r,attemptedPrefix:n.kind==="value"?mn:Object.freeze(r.map((i)=>i.node))})},mn=Object.freeze([]),Be=32,ae=8192,yn=2*Be,Bt=128,bn=4096;class Lt{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(ae,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>=Be&&e.size<=ae,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>ae){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>=Be&&e.size<=ae;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,Be),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=yn){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(ae,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>ae||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 An=(e,t)=>new Lt(e,t),Z=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=Bt-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},vn=(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:Bt},c=[t],l=new Set(c),f=0,u=0,p=1;while(c.length>0){if(d.remaining===0)return Z("budget-exhausted",d,f,u,p,r);d.remaining--,f++;let h=c.pop();if(Object.is(h,e))return Z("path-possible",d,f,u,p,r);let m=!1,b=(C)=>{if(u++,Object.is(C,e))return m=!0,!1;if(!l.has(C)){if(l.add(C),c.push(C),c.length>p)p=c.length}return!0},D=a.call(n,h,d,b);if(m)return Z("path-possible",d,f,u,p,r);if(!D)return Z("budget-exhausted",d,f,u,p,r);let M=s?.get(h);if(M!==void 0)for(let C of M){if(d.remaining===0)return Z("budget-exhausted",d,f,u,p,r);if(d.remaining--,!b(C))return Z("path-possible",d,f,u,p,r)}}return Z("proven-reverse",d,f,u,p,r)},gn=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let u=vn(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,It]]);while(l.length>0){let u=l.pop();if(Object.is(u,t)){let m=[],b=u;while(b!==It)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},Mt=(e,t)=>{let n=zt(e);if(n.kind==="thenable")return _t(n),new Y(t);if(n.kind==="inspection-error")return n.error;return e},Ft=(e,t)=>{let n=zt(e);if(n.kind==="thenable")return _t(n),Object.freeze({kind:"error",error:new Y(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Ht=(e,t,n,o=gn,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(),D=n.getSelectorGraphPublicationCount(t),M=b,C=D,ft=b,ht=D,He,We=!1,Ge=b,ke=0,J,pt=b,we,qe=(S,y)=>{if(S===Ge)return;if(Ge=S,J===void 0){ke=0;return}if(J.advanceGraphVersion(y))return;ke=0,r?.graphVersionReset()},rn=(S)=>{if(S!==Ge)qe(S,void 0);if(ke++,(c?.length??0)===0&&ke<3){r?.admissionSkipped();return}if(J===void 0){let y=c!==void 0&&c.length>0&&c.length<3;J=An(y?3:0,r)}if(!J.enabled){r?.disabled();return}return J},sn=(S)=>{if(We)return;let y=t.beginSelectorGraphObservation?.(S);if(y===void 0)return;We=!0,He=y},Ke=(S,y,O,k)=>O-S===k-y,St=(S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t),O=Ke(M,C,S,y))=>{if(S===M)return;if(!We&&t.beginSelectorGraphObservation!==void 0){qe(S,void 0),M=S,C=y;return}let k=He?.takeAddedEdges();if(qe(S,k),O){M=S,C=y;return}if(k!==void 0){let N=k.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,bn,i),F=k.length===0?void 0:{transientDependents:N,reverseProofEnabled:!0},E=!1;for(let W of k)if(o(W.head,W.tail,t,n,2,a.length,void 0,F)!==void 0){E=!0;break}if(!E){M=S,C=y;return}}for(let N=0;N<a.length;N++){let F=a[N],E=o(F.node,s,t,n,0,a.length);if(!E)continue;if(l!==void 0)for(let B=a.length-1;B>=N;B--)l.delete(a[B].node);if(a.length=N,u++,n.getControlFault().kind==="fault")return;let R=new le(s,[s,...E]);n.latchCycle(t,s,R);return}M=S,C=y},Ue=()=>{let S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t);ft=S,ht=y;let O=Ke(M,C,S,y);if(!O)n.revalidateAncestorPrefixes(t,s);St(S,y,O)};n.setPrefixRevalidator(t,s,St);let an=(S)=>{if(!h)throw new Qe;let y=n.getControlFaultForSuppliedRead();if(y.kind==="fault")throw y.error;let O=n.getCycle(t,s);if(O!==void 0)throw O;let k=n.activeCyclePath(t,S);if(k){let v=new le(s,k);throw n.latchCycle(t,s,v),v}let N=a.length,F,E=!1;if(l===void 0){let v=c?.[N];if(v!==void 0&&Object.is(v.node,S))F=!1,E=!0;else F=m().has(S)}else F=l.has(S);if(!F&&!E&&c!==void 0&&c.length>0){let v=c[a.length];if(v!==void 0&&Object.is(v.node,S))E=!0;else{if(f===void 0){f=new Set;for(let te of c)f.add(te.node)}E=f.has(S)}}let W=u,R=t.serve(S,n);Ue();let B=n.getCycle(t,s);if(B!==void 0)throw B;let de=l!==void 0?l.has(S):u===W&&a.length===N?!1:m().has(S),G=ft,ee=ht,L=de||E&&G===b,Re=c===void 0&&Ke(b,D,G,ee);if(!L&&!Re){if(pt=G,we===void 0)we=()=>rn(pt),we.reverseProofEnabled=!0;let v=o(S,s,t,n,1,a.length,we);if(v){let te=n.getControlFault();if(te.kind==="fault")throw te.error;let mt=new le(s,[s,...v]);throw n.latchCycle(t,s,mt),mt}}if(!de){let v=d?.dependencies[a.length];l?.add(S),a.push(v!==void 0&&Object.is(v.node,S)&&Object.is(v.token,R.token)?v:Object.freeze({node:S,token:R.token})),sn(S)}if(M=G,C=ee,R.outcome.kind==="control-error"){n.latchControlFault(R.outcome.error,R.outcome.origin);let v=n.getControlFault();if(v.kind==="fault")throw v.error;throw R.outcome.error}let ce=n.getControlFault();if(ce.kind==="fault")throw ce.error;if(R.outcome.kind==="error")throw Te(Ce,S,R.outcome.error)??new Ce(S,R.outcome.error);return R.outcome.value};try{let S,y,O=!1;try{S=e.get(an)}catch(B){O=!0,y=B}finally{h=!1}if(O)y=Mt(y,"getter");let k=O?void 0:Ft(S,"getter");Ue();let N=n.getControlFault();if(N.kind==="fault")return V(s,t.createOutcomeToken(),{...N,kind:"control-error"},a);let F=n.getCycle(t,s);if(F!==void 0)return V(s,t.createOutcomeToken(),{kind:"error",error:F},a);if(O)return V(s,t.createOutcomeToken(),{kind:"error",error:y instanceof Y?y:Te(ne,s,y)??new ne(s,y)},a);if(k===void 0)throw Error("Selector result classification was not completed");let E=n.getControlFault();if(E.kind==="fault")return V(s,t.createOutcomeToken(),{...E,kind:"control-error"},a);if(k.kind==="error")return V(s,t.createOutcomeToken(),{kind:"error",error:k.error instanceof Y?k.error:Te(ne,s,k.error)??new ne(s,k.error)},a);let W=k.value,R;if(p){let B=e.equal??Object.is,de,G,ee=!1;try{de=B(p.value,W)}catch(te){ee=!0,G=Mt(te,"comparator")}let L=ee?void 0:Ft(de,"comparator");Ue();let Re=n.getControlFault();if(Re.kind==="fault")return V(s,t.createOutcomeToken(),{...Re,kind:"control-error"},a);let ce=n.getCycle(t,s);if(ce!==void 0)return V(s,t.createOutcomeToken(),{kind:"error",error:ce},a);if(ee)return V(s,t.createOutcomeToken(),{kind:"error",error:G instanceof Y?G:new Oe(s,G)},a);if(L===void 0)throw Error("Selector comparator classification was not completed");let v=n.getControlFault();if(v.kind==="fault")return V(s,t.createOutcomeToken(),{...v,kind:"control-error"},a);if(L.kind==="error")return V(s,t.createOutcomeToken(),{kind:"error",error:L.error instanceof Y?L.error:new Oe(s,L.error)},a);if(L.value!==!0&&L.value!==!1)return V(s,t.createOutcomeToken(),{kind:"error",error:new Ye},a);if(L.value===!0)W=p.value,R=p.current?p.token:void 0}return V(s,R??t.createOutcomeToken(),{kind:"value",value:W},a)}finally{try{He?.close()}finally{n.leave(t,s)}}};class A{#t=[];#e;#o;#c=0;#r;#s=kn;#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 kn=Object.freeze({kind:"none"});var Wt=Symbol("no-committed-selector-baseline");class ot{#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)??Wt,this.#c.set(e,t);return t===Wt?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 Gt=4096,wn=Object.freeze([]);class qt{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 it{scope;onSwept;#t=new WeakMap;#e=new Set;#o=64;constructor(e,t){this.scope=e;this.onSwept=t}add(e){if(this.#t.has(e))return!1;let t=new WeakRef(e);if(this.#t.set(e,t),this.#e.add(t),this.#e.size>=this.#o)this.sweep();return!0}sweep(){let e=0;for(let t of this.#e){let n=t.deref();if(n!==void 0&&this.scope.atomOverrides.has(n))continue;if(n!==void 0)this.#t.delete(n);this.#e.delete(t),e++}if(this.#o=Math.max(64,this.#e.size*2),e!==0)this.onSwept?.(e);return e}collect(e){let t=0;for(let n of this.#e){let o=n.deref();if(o!==void 0){e.push(o);continue}this.#e.delete(n),t++}if(t!==0)this.onSwept?.(t)}}class Le{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;ownedAtoms;#t=new WeakMap;#e;#o=new WeakMap;#c;#r=new WeakMap;#s=new WeakSet;#u;#a=0;#i=0;#l;#f=!1;#m;#S="live";constructor(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[x]?.scope(this),this.#e.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#e.clear(),this.atomOverrides=new WeakMap,this.ownedAtoms=void 0,this[z]?.release(this.coordinator),this[z]=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(oe(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[x]?.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=je(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 wn;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??rt},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??rt,t.dependencies),a=s?this.#A(e,o?.dependencies??rt,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=Gt-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>Gt){this.#p();return}t.push(...e)}#p(){if(this.#i===0)return;this.#l=[],this.#f=!0}#d(){return new qt(this.coordinator.instrumented?()=>this.coordinator.recordCounter(2):void 0)}}var rt=Object.freeze([]);class st{commitEntries;transaction=Object.freeze({});onAllocation;#t;#e;#o;#c;#r;#s;#u;#a;#i;#l;#f;#m;#S;#h;#b;#y;externalCaptures;#A;#v=!1;generation=0;active=!0;constructor(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(){this.commitEntries=void 0;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 Kt{constructor(e,t,n){this.onCommit=(o)=>e.registerCommit(t,n,o),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.resetAll=function(){e.resetAll(t,n,arguments.length)},this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),be(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var at=(e,t,n)=>new Kt(e,t,n),dt=(e)=>{let t=P(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new ue},Ut=(e)=>{let t=P(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new ue};var Rn=64,Tn=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},w=Symbol("definition domain records"),to=(e)=>e[w].ownerToken,no=(e)=>e[w],oo=(e,t)=>{let n=e[w],o=n[x];if(o!==void 0)return o;let r=t(n);return n[x]=r,r},ro=(e)=>e[w][x],Cn=Object.freeze([]),io=(e,t,n,o,r,i)=>{let s=e[w],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[K];s[K]={session:a,definitions:f?new WeakSet:void 0,allowDefinitions:f,...i===void 0?{}:{createAccessorFault:i}};let p=l.length===0?Cn:l.map((h)=>Object.freeze({selectorSession:h,previous:h.setSuppliedReadGuard(()=>{let m=s.activity;return Tt(m?.kind==="guarded-callback"?m.session:a,h)})}));try{return U(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[K];else s[K]=u}},On=(e)=>{let t=e[w][K];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 re:t.accessorFault??=t.createAccessorFault();throw t.session.latchControlFault(o),o},so=(e)=>se(e[w]),ao=On,co=(e,t)=>Ae(e[w],t),lo=(e,t)=>_(e[w],t,new A),uo=(e,t)=>{let n=e[w];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[K]?.definitions?.has(t)||n[Ee]?.has(t))return t;return}_(n,t,new A);return};class Xt extends Set{release(e){e.recordCounter(34,this.size)}}class $t extends WeakSet{apply(e,{atom:t,kind:n}){let o=e[z];if(n==="set"){if(!this.has(t))return!1;if(o===void 0)o=e[z]=new Xt,e.coordinator.recordCounter(32);let r=o.size;if(o.add(t),o.size!==r)e.coordinator.recordCounter(33);return!0}else{if(o?.delete(t))e.coordinator.recordCounter(34);if(o?.size===0)e[z]=void 0;return!1}}}var fo=(e,t)=>{let n=e[w];if((n[Ee]??(n[Ee]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[z]??(n[z]=new $t)).add(t)},Zt=new WeakMap,ho=()=>{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,ownedAtomRetains:51,ownedAtomSweptReferences:52}),t=53,n=new Uint32Array(53),o=Object.freeze({read(r){return n[e[r]]??0}});return Zt.set(o,(r,i)=>{n[r]+=i}),o},I=(e)=>Object.freeze({kind:"value",value:e}),En=(e)=>Object.freeze({kind:"error",error:e}),Yt=(e)=>e.kind==="value"?I(e.value):En(e.error),ge=(e,t)=>e[x]?.has(t)?e[x]:void 0,Jt=(e,t,n,o)=>{let r=e.read(t,n,o);if(r.kind!=="value")throw r.error;return r.value};var Nn=(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}),lt=(e)=>(e.onAllocation?.(),new Map),Dn=(e)=>(e.onAllocation?.(),new Set),ct=(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)},Qt=(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=lt(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=lt(e),r.set(t,i);i.set(n,o)},xn=(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=Dn(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Pn=(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=lt(e),e.affected=o;o.set(t,n)};class en{#t=new WeakMap;#e;#o;#c;subscriberReading=!1;#r;#s=1;sourceEpoch=0;#u=!1;#a;#i;#l;#f=0;#m;#S;#h;#b=1;#y=0;#A;#v;#p;#d=0;#T;#N;#D=!1;settlementEpoch=0;#n;#C;#w;evaluate;constructor(e,t,n){this.#n=e,this.#C=t===void 0?void 0:Zt.get(t),this.#w=n,this.evaluate=n?.evaluate??Ht,this.#r=new Le(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 st(this.instrumented?()=>this.recordCounter(18):void 0)}get(e,t){let n=new A,o=t,r=_(this.#n,o,n),i=Ve(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.#U(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}#U(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":_(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)&&!ge(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),Tn(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(Ct(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)_(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(H(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.#X(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(jt(),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=at(this,n,e),r=wt(this.#n,n.transaction,()=>t(o));n.close();let i=new A;return ye(this.#n,i,()=>dt(r)),this.#_(n),r}finally{n.close(),n.release()}}registerCommit(e,t,n){if(ie(this.#n,e.transaction,e.active),this.#g(t),typeof n!=="function")throw TypeError("Transaction.onCommit requires a function");(e.commitEntries??=[]).push({scope:t,callback:n})}get fallbackRecords(){return this.#t}transactionGet(e,t,n){let o=n,r=new A,i=_(this.#n,o,r);if(ie(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=ge(this.#n,o);if(!a)throw TypeError("Transaction.get requires a readable State");return Jt(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=_(this.#n,i,s);if(e===void 0)H(this.#n,a);else ie(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=ge(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.#$(h,t,i,r,s);else if(n==="update")this.#Z(h,t,i,r,s,a);else this.#J(h,t,i,s);if(!p)return;h.close(),this.#_(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")_(this.#n,n,i);ie(this.#n,e.transaction,e.active),this.#g(t);let s=this.#Q(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=at(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 ye(this.#n,f,()=>Ut(l))}let c=new A;return ye(this.#n,c,()=>dt(d)),d}createOutcomeToken(){return Object.freeze({id:this.#s++})}createScratchSelectorHost(e,t,n=!1){return this.recordCounter(3),new ot(Object.freeze({trackPath:n,resolve:(o,r)=>this.#Y(o,r),read:(o,r,i,s)=>this.#ee(e,t,o,r,i,s),baseline:n?()=>{return}:(o)=>t.captureCommittedSelectorSuccess(o),run:(o,r)=>je(this.#n,o,r)}),e.generation,this.evaluate)}#Y(e,t){if(oe(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(ge(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 Le(this,e,t);this.recordCounter(7);let o=new ut(this,n,this.#w);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Q(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new et;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 tt;return i}let r=this.#n.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new xe;throw new Pe}throw new Pe}#g(e,t){if(t!==void 0)H(this.#n,t);if(e.status!=="live")throw new pe}#X(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)}#$(e,t,n,o,r){let i=U(this.#n,r,()=>Se(o));if(i.kind==="error")throw i.error;let s=this.#x(e,t,n,r);this.#K(e,t,n,i.value,s,r)}#Z(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.#oe(o,a.value,r);this.#K(e,t,n,d,s,r)}#J(e,t,n,o){e.stage(t,this.#F(e,t,n,o))}#F(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.#z(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);return Object.freeze({kind:"reset",atom:n,publishDraftFallback:i})}resetAll(e,t,n){if(ie(this.#n,e.transaction,e.active),this.#g(t),n!==0)throw TypeError("Transaction.resetAll accepts no arguments");if(t.parent===void 0)throw TypeError("Transaction.resetAll requires a child scope cursor");let o=[];t.ownedAtoms?.collect(o),t[z]?.forEach((a)=>o.push(a)),e.forEachIntent((a,d)=>{if(Object.is(a,t))o.push(d.atom)});let r=new A,i=[],s=new Set;for(let a of o){if(s.has(a))continue;s.add(a);let d=e.getIntent(t,a);if(d===void 0){if(!t.atomOverrides.has(a))continue}else if(d.kind==="reset")continue;i.push(this.#F(e,t,a,r))}for(let a of i)e.stage(t,a);this.#n[x]?.resetAll?.(e,t)}#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=I(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.#z(e,t,n,o).outcome}#ee(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[x].read(e,t,n)}#z(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:I(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:I(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.#O(t);if(r.fallback.kind==="eager")return I(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=Yt(U(this.#n,n,()=>nt(i)));return e.setFallback(t,a),a}#te(e,t,n,o){let r=this.#O(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#ne(r,t,n,o)?t:n}#ne(e,t,n,o){return U(this.#n,o,()=>{let r;try{r=e(t,n)}catch(s){let a=P(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw j(a),new he}let i=P(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw j(i),new he;if(r!==!0&&r!==!1)throw new he;return r})}#oe(e,t,n){return U(this.#n,n,()=>{let o;try{o=e(t)}catch(i){let s=P(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw j(s),new fe}let r=Se(o);if(r.kind==="error")throw r.error;return r.value})}#_(e){this.#R(2);let t;if(e.hasRows){if(t=this.#n[x]?.plan(e),t===void 0)throw Error()}if(!e.hasIntents&&t===void 0){_e(e);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){_e(e);return}let r=Nn(this.instrumented?()=>this.recordCounter(19):void 0),i,s;if(n!==void 0&&o!==void 0)i=this.#B(e,o,n,r);else e.forEachIntent((c,l)=>{let f=this.#B(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.#L(e,i);if(s!==void 0)for(let c of s)this.#L(e,c);let a=i===void 0?!1:this.#H(i);if(s!==void 0)for(let c of s){let l=this.#H(c);a||=l}if(t!==void 0){let c=t.commit(0);a||=c}if(_e(e),i!==void 0)this.#W(i);if(s!==void 0)for(let c of s)this.#W(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.#j(r,f,u);let{secondAffectedRecord:p,secondAffectedBefore:h}=r;if(p!==void 0&&h!==void 0){let m=this.#j(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 D=this.#j(r,m,b);if(D===void 0)continue;if(c===void 0)c=D;else{if(l===void 0)l=[];l.push(D)}}if(t!==void 0){let m=t.commit(2);if(m!==void 0)for(let b of m){let D=b;if(c===void 0)c=D;else{if(l===void 0)l=[];l.push(D)}}}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.#T??={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}}#B(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.#ie(e,s,o);return i}#L(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)}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);let o=this.#n[z]?.apply(n,t);if(n.parent!==void 0&&o!==!0){if(t.kind==="set"&&(n.ownedAtoms??this.#re(n)).add(t.atom))this.recordCounter(51)}return e.ownershipChanged}#re(e){return e.ownedAtoms=new it(e,this.#C===void 0?void 0:(t)=>this.recordCounter(52,t))}#W({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.#de(e.parent,t.atom))}#j(e,t,n){let o=ct(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter(16),Xe(n,o))return;return t.scope.updateAtomView(t,o),t}#ie(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!xn(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(Xe(i,s))continue;Pn(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=ct(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=ct(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=I(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=I(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#se(e,n),s!==void 0)Qt(o,n,s,d),this.recordCounter(17);if(a!==void 0)for(let c of a)Qt(o,n,c,d),this.recordCounter(17);return d}#se(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.#O(t);if(r.fallback.kind==="eager")return I(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ae(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#O(e);if(n.fallback.kind==="eager")return I(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#de(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,I(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ae(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,I(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#ce(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}#ce(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#O(e);if(o.fallback.kind==="eager")return I(o.fallback.value);let r=o.fallback.initialize,i=Yt(U(this.#n,t,()=>nt(r)));return this.#t.set(e,i),this.recordCounter(13),i}#O(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.#V(u,p)}catch(h){if(o)this.#T??={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.#le(i),a=this.#he(),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 Ze(d===void 0?c:[d,...c]);throw this.#e?.notificationFailure(l)??l}finally{if(!o)this.#S=void 0}}#le(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===Rn){(e??=[]).push(new Je);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.#ue(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}#ue(e,t){let n;this.#d++;try{this.#w?.(3,e),this.#I(e,t),n=this.#T}catch(o){let r=o;try{ye(this.#n,new A,()=>{let i=P(o);if(i.kind==="thenable")j(i)})}catch(i){r=i}n={error:r}}finally{this.#d--,this.#T=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.#fe(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)}#fe(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}}#he(){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{kt(this.#n,c,()=>{let l;try{if(l=P(d()),l.kind==="thenable")j(l)}catch(f){let u=P(f);if(u.kind==="thenable")j(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.#T??={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.#q(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.#V(e,t,n)}#V(e,t,n){let o=this.#q(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.#V(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)}}#q(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)}#K(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#te(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 jn=(e,t)=>{let n=e.coordinator,o=new A,r=t,i=_(n.runtimeDomain,r,o);if(H(n.runtimeDomain,"adapter readHydrationSnapshot"),e.status!=="live")throw new pe;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=ge(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 Jt(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 ut{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),be(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter(8),n?.(0,this,t),Object.freeze(this)}}var tn=(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}}},nn=()=>{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({[w]:e})},po=(e,t,n={})=>{let o=e[w];se(o);let r=new A,i=U(o,r,()=>Se(t));if(i.kind==="error")throw i.error;let s=Ae(o,Ie("atom"));return o.atoms.set(s,Object.freeze({fallback:Object.freeze({kind:"eager",value:i.value}),...tn(n)})),s},So=(e,t,n={})=>{let o=e[w];if(se(o),typeof t!=="function")throw TypeError("atomLazy requires an initializer function");let r=Ae(o,Ie("atom"));return o.atoms.set(r,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:t}),...tn(n)})),r},mo=(e,t,n={})=>{let o=e[w];if(se(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=Ae(o,Ie("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},yo=(e)=>{let t=e[w],n=(i)=>{let s=new A;if(_(t,i,s)==="invalid")return;return t.stores.get(i)};return Object.freeze({assertStore:(i)=>{let s=n(i);if(H(t,"adapter assertStore"),s===void 0)throw TypeError("assertStore requires a valid Store");if(s.status!=="live")throw new pe},read:(i,s)=>{if(n(i)===void 0)throw Ve(t,"adapter read"),TypeError("read requires a valid Store");return i.get(s)},subscribe:(i,s,a)=>{if(n(i)===void 0)throw H(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 H(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return jn(a,s)}})},on=(e,t,n)=>{let o=e[w];H(o,"createStoreTree");let r=new en(o,t,n);return new ut(r,r.rootScope,n)};var Vn=nn(),vo=(e,t)=>on(Vn,e,t);
|
|
2
|
+
export{le as S,vn as T,Ht as U,A as V,x as W,Xe as X,Mn as Y,$e as Z,Ze as _,re as $,Ne as aa,Je as ba,De as ca,xe as da,ue as ea,fe as fa,he as ga,pe as ha,et as ia,tt as ja,Pe as ka,P as la,j as ma,me as na,U as oa,Rt as pa,Tt as qa,se as ra,Ie as sa,Ae as ta,qt as ua,to as va,no as wa,oo as xa,ro as ya,io as za,On as Aa,so as Ba,ao as Ca,co as Da,lo as Ea,uo as Fa,fo as Ga,ho as Ha,po as Ia,So as Ja,mo as Ka,yo as La,on as Ma,Vn as Na,vo as Oa};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as xn,B as Hn,C as In,D as Ln,E as Pn,F as jn,G as Vn,H as Bn,I as An,P as _n,i as yn,j as Cn,k as Rn,l as ze,m as Sn,n as pe,o as q,p as Ce,q as gn,r as kn,s as vn,t as Mn,u as On,v as Ke,w as En,x as Tn,y as Nn,z as Dn}from"./chunk-tywyt3b6.js";import{Aa as Ge,Ba as Yn,Da as We,Ea as Ye,Ka as Zn,la as he,ma as ge,oa as Un,ua as ue,va as xe,xa as Gn,za as Ue}from"./chunk-pf9vsntr.js";class _e{entries=new Map;tail;nextRank=0;constructor(l){for(let d of l)this.append(d)}append(l){let d=this.tail;if(this.entries.set(l,{rank:this.nextRank++,previous:d}),d!==void 0)this.entries.get(d).next=l;this.tail=l}remove(l){let d=this.entries.get(l);if(d===void 0)return;if(d.previous!==void 0)this.entries.get(d.previous).next=d.next;if(d.next!==void 0)this.entries.get(d.next).previous=d.previous;else this.tail=d.previous;this.entries.delete(l)}changes(l,d){if(l.length!==d.length)return!0;let f=new Set(l),u=this.tail;for(let C=d.length-1;C>=0;C--){if(d[C]!==u||!f.has(d[C]))return!0;u=this.entries.get(u)?.previous}return!1}}var J=Symbol("collection baseline birth"),wo=(l,d)=>{let f=new Map,u=new Set(d);for(let H of l)if(!u.has(H))f.set(H,{baselinePresent:!0,transitions:[],birth:void 0});let C=new Set(l);for(let H of d)if(!C.has(H))f.set(H,{baselinePresent:!1,transitions:[],birth:0});return f},yo=(l,d)=>{for(let f=l.parent;f!==void 0;f=f.parent)if(f===d)return!0;return!1};class Ne extends Error{seal(){Object.freeze(this)}}class zn extends Ne{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class Kn extends Ne{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class Fn extends Ne{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var Re=Object.freeze({kind:"none"}),Te=Object.freeze({kind:"absent"}),Z=Object.freeze({kind:"absent"}),Y=Object.freeze([]),Se=(l)=>Object.freeze({kind:"present",value:l}),oe=(l)=>Object.freeze({kind:"present",value:l}),Ee=(l,d)=>l.kind===d.kind&&(l.kind==="absent"||d.kind==="present"&&Object.is(l.value,d.value)),bn=(l,d)=>l.kind===d.kind&&(l.kind!=="present"||d.kind==="present"&&Object.is(l.value,d.value)),ae=(l)=>{let d=l.local.kind==="present"?Se(l.local.value):l.local.kind==="absent"?Te:Re,f=l.effective.kind==="present"?oe(l.effective.value):Z,u=l.inherited.kind==="present"?oe(l.inherited.value):Z;if(d.kind==="none"&&!Ee(f,u))throw Error("Collection baseline without local ownership must equal inherited outcome");if(d.kind==="present"&&(f.kind!=="present"||!Object.is(d.value,f.value)))throw Error("Collection present local baseline must equal its effective outcome");if(d.kind==="absent"&&f.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:d,effective:f,inherited:u})},Oe=(l)=>{let d=l.final;if(d===void 0)return l.baseline.local;if(d.kind==="present")return Se(d.value);return d.kind==="absent"?Te:Re},mn=(l,d)=>l.kind==="present"?oe(l.value):l.kind==="absent"?Z:d,wn=(l)=>Object.freeze({kind:"value",value:l.kind==="present"?l.value:void 0}),Wn=(l,d)=>{let f,u=new WeakMap,C=new WeakMap,H,z,A=(o)=>o.coordinator?.evaluate?.recordExtension,T=(o,e,n=1)=>{A(o)?.(e,n)},K=(o,e,n,r)=>{A(o)?.(e,o,n,r)},B=(o,e,n)=>{if(e.length!==n.length)return!1;let r=A(o);if(r===void 0){for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return!1;return!0}for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return r(q,t+1),!1;if(e.length)r(q,e.length);return!0},be=(o)=>{let e=C.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},C.set(o,e),e},j=(o,e)=>C.get(o)?.rowLocals?.get(e)??Re,V=(o,e)=>{let n=o;while(n!==void 0){let r=j(n,e);if(r.kind==="present")return oe(r.value);if(r.kind==="absent")return Z;n=n.parent}return Z},te=d??((o,e)=>{let n=j(o,e),r=V(o.parent,e);return Object.freeze({local:n,effective:mn(n,r),inherited:r})}),Jn=(o,e,n,r)=>{let t=o.byScope.get(e)?.get(n);if(t!==void 0)return Oe(t);return ae(te(e,n,r)).local},U=(o,e,n,r)=>{let t=e;while(t!==void 0){let s=Jn(o,t,n,r);if(s.kind==="present")return oe(s.value);if(s.kind==="absent")return Z;if(d!==void 0){let c=o.byScope.get(t)?.get(n);if(c!==void 0)return c.baseline.inherited;return ae(te(t,n,r)).inherited}t=t.parent}return Z},Qn=(o,e,n,r)=>{if(d!==void 0){let t=ae(te(e,n,r)),s=t.effective.kind==="present",c=s?J:void 0;for(let a of o.byRow.get(n)?.historyByScope.get(e)??[]){if(!Object.is(a.row,n)||!Object.is(a.scope,e))continue;let p=a.kind==="present"||a.kind==="reset"&&t.inherited.kind==="present";if(!s&&p)c=a.sequence;else if(!p)c=void 0;s=p}return c}return dn(o,e,n,r,void 0)},He=(o,e,n,r)=>{let t=be(o),s=t.rowViews?.get(e);if(s!==void 0)return s;let c={scope:o,atom:e,served:Object.freeze({token:o.createOutcomeToken(),outcome:wn(n)}),inheritedFrom:r,inheritingChildren:new ue(()=>o.coordinator.recordCounter(2))},a=t.rowViews;if(a===void 0)a=new WeakMap,t.rowViews=a;let p=t.liveRowViews;if(p===void 0)p=new ue(()=>o.coordinator.recordCounter(2)),t.liveRowViews=p;if(a.set(e,c),p.add(c),K(o,Bn,e,l.lookupRow(e)),r!==void 0)r.inheritingChildren.add(c),o.coordinator.recordCounter(11);return c},Xe=(o,e)=>{let n=o,r=[],t;while(!0){T(n,ze);let s=C.get(n),c=s?.rowViews?.get(e);if(c!==void 0){t=c;break}let a=s?.rowLocals?.get(e);if(a!==void 0){t=He(n,e,a.kind==="present"?oe(a.value):Z);break}if(n.parent===void 0){t=He(n,e,Z);break}r.push(n),n=n.parent}for(let s=r.length-1;s>=0;s--)t=He(r[s],e,t.served.outcome.kind==="value"&&t.served.outcome.value!==void 0?oe(t.served.outcome.value):Z,t);return t},Ie=(o)=>{let e=o.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(o),o.inheritedFrom=void 0,o.scope.coordinator.recordCounter(12)},$n=(o,e)=>{if(Object.is(o.inheritedFrom,e))return;Ie(o),o.inheritedFrom=e,e.inheritingChildren.add(o),o.scope.coordinator.recordCounter(11)},X=(o)=>{if(o.snapshotDirty){let e=Object.freeze([...o.ordered.entries.keys()]);T(o.scope,q,e.length),T(o.scope,Ce),o.served=se(o.scope,e,o.served.token),o.snapshotDirty=!1}return o.served.outcome.kind==="value"?o.served.outcome.value:Y},eo=(o,e)=>{let n=de(o,e),r=n;while(r!==void 0&&r.ordered===void 0){r.ordered=new _e(X(r));let t=r.inheritedFrom;if(t!==void 0)(t.indexedChildren??=new ue).add(r);r=t}return n.ordered},Le=(o,e)=>{if(e.length)T(o,q,e.length);let n=Object.freeze([...e]);return T(o,Ce),n},se=(o,e,n=o.createOutcomeToken())=>Object.freeze({token:n,outcome:Object.freeze({kind:"value",value:e})}),Pe=(o,e,n,r=!1)=>{let t=be(o),s=t.memberships?.get(e);if(s!==void 0)return s;let c={scope:o,atom:e,served:se(o,n,r?Y:void 0),inheritedFrom:void 0,inheritingChildren:new ue(()=>o.coordinator.recordCounter(2))},a=t.memberships;if(a===void 0)a=new WeakMap,t.memberships=a;let p=t.liveMemberships;if(p===void 0)p=new ue(()=>o.coordinator.recordCounter(2)),t.liveMemberships=p;return a.set(e,c),p.add(c),T(o,Sn),K(o,An,e),c},Je=(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;Je(o),o.inheritedFrom=e,e.inheritingChildren.add(o),o.scope.coordinator.recordCounter(11)},de=(o,e)=>{let n=o,r=[],t;while(!0){T(n,pe);let s=C.get(n)?.memberships?.get(e);if(s!==void 0){if(t=s,t.served.token===Y){let c=Le(n,X(t));t.served=se(n,c)}break}if(n.parent===void 0){t=Pe(n,e,Le(n,Y));break}r.push(n),n=n.parent}for(let s=r.length-1;s>=0;s--){let c=r[s],a=Le(c,X(t)),p=Pe(c,e,a);Qe(p,t),t=p}return t},no=(o)=>{let e=o;f?.release(e);let n=u.get(e);if(n===void 0)return;u.delete(e);for(let r of n.byScope.values()){for(let t of r.values())t.final=void 0,t.finalOperation=void 0;r.clear()}n.byScope.clear(),n.planOrder.length=0,n.history.length=0;for(let r of n.historyByCollectionScope.values()){for(let t of r.values())t.length=0;r.clear()}n.historyByCollectionScope.clear();for(let r of n.byRow.values()){for(let t of r.coordinatesByAncestor.values())t.length=0;r.coordinatesByAncestor.clear();for(let t of r.historyByScope.values())t.length=0;r.historyByScope.clear()}n.byRow.clear(),n.revisionByCollection.clear(),n.queryRevisionByCollection?.clear();for(let r of n.membershipMemo.values())r.clear();n.membershipMemo.clear()},re=(o)=>{let e=u.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(no),u.set(o,e),e},me=(o)=>{let e=l.lookupRow(o);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},$e=(o,e)=>{o.revisionByCollection.set(e,(o.revisionByCollection.get(e)??0)+1)},oo=(o,e)=>{$e(o,e);let n=o.queryRevisionByCollection?.get(e);if(n!==void 0)o.queryRevisionByCollection.set(e,n+1)},en=(o,e)=>{for(let n of o.rebased?.values()??[])if(n.collections.has(e))return!0;return!1},ce=(o,e,n,r=me(n))=>{let t=re(o),s=t.byScope.get(e);if(s===void 0)s=new Map,t.byScope.set(e,s);let c=s.get(n);if(c!==void 0)return c;if(z!==void 0)z.coordinates++;let a=ae(te(e,n,r)),p=d===void 0?U(t,e.parent,n,r):a.inherited,I=ae({local:a.local,effective:mn(a.local,p),inherited:p});c={scope:e,row:n,collection:r,baseline:I,discoveryIndex:t.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},s.set(n,c);let v=t.byRow.get(n);if(v===void 0)v={coordinatesByAncestor:new Map,historyByScope:new Map},t.byRow.set(n,v);let x=e;while(x!==void 0){let g=v.coordinatesByAncestor.get(x);if(g===void 0)g=[],v.coordinatesByAncestor.set(x,g);g.push(c),x=x.parent}return c.enablingBirth=Qn(t,e,n,r),c},ke=(o,e,n,r,t,s)=>{let c=Oe(e),a=re(o),p=U(a,e.scope,e.row,e.collection);if(bn(c,t)&&Ee(p,s))return;if(!a.hasAcceptedIntent)a.hasAcceptedIntent=!0,T(e.scope,Cn);T(e.scope,yn);let I=[];for(let G of a.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let W=U(a,G.scope,G.row,G.collection);I.push({coordinate:G,effective:W,placement:W.kind==="present"?G.enablingBirth:void 0})}let v=o.generation;if(e.planIndex===void 0)e.planIndex=a.planOrder.length,a.planOrder.push(e);e.final=r,e.finalOperation=n;let x=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:r.kind,sequence:v});a.history.push(x);let g=a.byRow.get(e.row),N=g.historyByScope.get(e.scope);if(N===void 0)N=[],g.historyByScope.set(e.scope,N);N.push(x);let E=a.historyByCollectionScope.get(e.collection);if(E===void 0)E=new Map,a.historyByCollectionScope.set(e.collection,E);let D=E.get(e.scope);if(D===void 0)D=[],E.set(e.scope,D);let L=D.length===0;D.push(x);let _=!1;for(let G of I){let W=G.coordinate,le=U(a,W.scope,W.row,W.collection);if(G.effective.kind==="absent"&&le.kind==="present")W.enablingBirth=v;else if(le.kind==="absent")W.enablingBirth=void 0;let ye=le.kind==="present"?W.enablingBirth:void 0;if(!Object.is(G.placement,ye))_=!0}if(_||L&&a.rebased!==void 0&&en(a,e.collection)&&ee(a,e.scope,e.collection)===void 0)$e(a,e.collection);let we=a.queryRevisionByCollection?.get(e.collection);if(we!==void 0)a.queryRevisionByCollection.set(e.collection,we+1);o.markRow(v)},nn=()=>new zn,on=(o)=>{let e=l.inspectThenable(o);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw l.containThenable(e),nn();if(o===void 0)throw new Kn;return o},to=(o,e,n)=>l.runGuarded(n,()=>{let r;try{r=Reflect.apply(o,void 0,[e])}catch(t){let s=l.inspectThenable(t);if(s.kind==="not-thenable")throw t;if(s.kind==="inspection-error")throw s.error;throw l.containThenable(s),nn()}return on(r)}),tn=(o,e,n,r,t)=>{let s=me(n),c=l.runGuarded(t,()=>on(r)),a=ce(o,e,n,s);ke(o,a,"set",Object.freeze({kind:"present",value:c}),Se(c),oe(c))},rn=(o,e,n,r,t)=>{let s=me(n);if(typeof r!=="function")throw TypeError("Collection row update requires an updater");let c=ce(o,e,n,s),a=U(re(o),e,n,s);if(a.kind==="absent")throw new Fn;let p=to(r,a.value,t);ke(o,c,"update",Object.freeze({kind:"present",value:p}),Se(p),oe(p))},ln=(o,e,n)=>{let r=ce(o,e,n);ke(o,r,"delete",Object.freeze({kind:"absent"}),Te,Z)},je=(o,e,n)=>{let r=ce(o,e,n),t=d===void 0?U(re(o),e.parent,n,r.collection):r.baseline.inherited;ke(o,r,"reset",Object.freeze({kind:"reset"}),Re,t)},ro=(o,e)=>{let n=o.generation,r=[],t=C.get(e)?.ownedRows;if(t!==void 0)for(let g of t)r.push(g);let s=u.get(o)?.byScope.get(e);if(s!==void 0){let g=[];for(let N of s.values())if(N.planIndex!==void 0)g.push(N);g.sort((N,E)=>N.planIndex-E.planIndex);for(let N of g)r.push(N.row)}let c=new Set,a=[];for(let g of r){if(c.has(g))continue;c.add(g);let N=s?.get(g);if(N!==void 0){if(Oe(N).kind==="none")continue}else if(t?.has(g)!==!0)continue;a.push(g)}if(a.length>1&&!e.children.isEmpty()){let g=new Set(a),N=[];for(let E of new Set(a.map(me)))for(let D of fe(o,e.parent,E))if(g.delete(D))N.push(D);for(let E of a)if(g.has(E))N.push(E);a.length=0,a.push(...N)}for(let g of a)je(o,e,g);let p=new Set;for(let g of c)p.add(me(g));C.get(e)?.liveMemberships?.forEach((g)=>{if(g.localHistory)p.add(g.atom)});let I=re(o);for(let g=e.parent;g!==void 0;g=g.parent)for(let N of I.rebased?.get(g)?.collections??[])p.add(N);let v=I.cleared?.get(e);if(v!==void 0)for(let g of v.collections)p.add(g);let x={start:n,end:o.generation,collections:p};if((I.cleared??=new Map).set(e,x),p.size===0)return;(I.rebased??=new Map).set(e,x);for(let[g,N]of I.cleared){if(g===e||!yo(g,e))continue;for(let E of p)N.collections.add(E);I.rebased.set(g,N)}for(let g of p)oo(I,g);o.markRow(o.generation)},sn=(o,e,n,r,t,s)=>{if(o.historyByCollectionScope.get(n)?.get(e)?.length)return!1;if(r.length!==t.length)return!1;for(let a=0;a<r.length;a++)if(r[a]!==t[a])return!1;let c;for(let a of C.get(e)?.ownedRows??[]){if(l.lookupRow(a)!==n)continue;if(c??=new Set(s()),j(e,a).kind==="present"!==c.has(a))return!1}return!0},ee=(o,e,n)=>{let r=o.rebased?.get(e);return r?.collections.has(n)?r:void 0},io=(o,e,n)=>{for(let r=e.parent;r!==void 0;r=r.parent)if(ee(o,r,n)!==void 0)return!0;return!1},Ve=(o,e,n,r)=>{if(ee(e,n,r)!==void 0)return!1;let t=n.parent;if(t===void 0)return!1;if(ee(e,t,r)===void 0&&!Ve(o,e,t,r))return!1;return sn(e,n,r,X(de(n,r)),X(de(t,r)),()=>fe(o,t,r))},dn=(o,e,n,r,t)=>{let s=[],c=new Set,a=new Map,p=e,I=t!==void 0;while(p!==void 0){if(p===t)I=!1;if(s.push(p),I&&ee(o,p,r)!==void 0)c.add(p);a.set(p,c.has(p)?"none":ae(te(p,n,r)).local.kind),p=p.parent}let v=[],x=o.byRow.get(n);if(x!==void 0){for(let D of s){let L=c.has(D)?ee(o,D,r):void 0;for(let _ of x.historyByScope.get(D)??[])if(L===void 0||_.sequence>=L.start)v.push(_)}v.sort((D,L)=>D.sequence-L.sequence)}let g=()=>{for(let D of s){let L=a.get(D);if(L==="present")return!0;if(L==="absent")return!1}return!1},N=g(),E=N?J:void 0;for(let D of v){a.set(D.scope,D.kind==="present"?"present":D.kind==="absent"?"absent":"none");let L=g();if(!N&&L)E=D.sequence;else if(!L)E=void 0;N=L}return E},cn=(o,e,n,r,t)=>{let s=o.historyByCollectionScope.get(n),c=new Map,a=e;while(a!==void 0){for(let v of s?.get(a)??[])if(!c.has(v.row))c.set(v.row,dn(o,e,v.row,n,t));a=a.parent}let p=[];for(let v of r)if(!c.has(v)||c.get(v)===J)p.push(v);let I=[];for(let[v,x]of c)if(typeof x==="number")I.push({row:v,birth:x});I.sort((v,x)=>v.birth-x.birth);for(let{row:v}of I)p.push(v);return p},lo=(o,e,n,r)=>{let t=n.parent;while(ee(e,t,r)!==void 0||Ve(o,e,t,r))t=t.parent;return t},an=(o,e,n)=>{let r=ce(o,e,n),t=U(re(o),e,n,r.collection);return t.kind==="present"?t.value:void 0},fe=(o,e,n)=>{if(!l.lookupCollection(n))throw TypeError("Collection draft read requires a valid collection");let r=re(o),t=r.revisionByCollection.get(n)??0,s=r.membershipMemo.get(e),c=s?.get(n);if(c?.revision===t)return c.rows;if(r.rebased!==void 0&&(ee(r,e,n)!==void 0||Ve(o,r,e,n))){let E;if(ee(r,e,n)!==void 0){let _=lo(o,r,e,n);E=cn(r,e,n,X(de(_,n)),_)}else E=fe(o,e.parent,n);let D=X(de(e,n)),L=B(e,D,E)?D:c!==void 0&&B(e,c.rows,E)?c.rows:Object.freeze([...E]);if(s===void 0)s=new Map,r.membershipMemo.set(e,s);return s.set(n,{revision:t,rows:L}),L}let a=d===void 0&&typeof e.createOutcomeToken==="function"?X(de(e,n)):Y,p=new Map,I=r.historyByCollectionScope.get(n),v=e;while(v!==void 0){for(let E of I?.get(v)??[])if(!p.has(E.row))p.set(E.row,ce(o,e,E.row,n));v=v.parent}let x=[];if(a.length)T(e,q,a.length);for(let E of a){let D=p.get(E);if(D===void 0||D.enablingBirth===J)x.push(E)}let g=[];if(p.size!==0)T(e,q,p.size);for(let E of p.values())if(typeof E.enablingBirth==="number"&&U(r,E.scope,E.row,E.collection).kind==="present")g.push(E);g.sort((E,D)=>{let L=E.enablingBirth,_=D.enablingBirth;if(L===_)return E.discoveryIndex-D.discoveryIndex;return L-_});for(let E of g)x.push(E.row);let N;if(B(e,a,x))N=a;else if(c!==void 0&&B(e,c.rows,x))N=c.rows;else N=Object.freeze(x),T(e,Ce);if(s===void 0)s=new Map,r.membershipMemo.set(e,s);return s.set(n,Object.freeze({revision:t,rows:N})),N},so=(o)=>{let e=u.get(o);if(e===void 0)return;let n=0;for(let s of e.membershipMemo.values())n+=s.size;let r=new WeakMap;for(let[s,c]of e.revisionByCollection)r.set(s,Object.freeze({value:c}));let t=(s)=>Object.freeze({id:s.discoveryIndex,baselineLocal:s.baseline.local.kind,baselineEffective:s.baseline.effective.kind,baselineInherited:s.baseline.inherited.kind,final:s.final?.kind,enablingBirth:s.enablingBirth===J?"baseline":s.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((s)=>[...s.values()]).sort((s,c)=>s.discoveryIndex-c.discoveryIndex).map(t)),planOrder:Object.freeze(e.planOrder.map(t)),history:Object.freeze(e.history.map((s)=>Object.freeze({coordinateId:s.coordinateId,kind:s.kind,sequence:s.sequence}))),membershipMemoCount:n,revision:(s)=>r.get(s)?.value??0})},co=(o)=>{let e=o;if(!e.hasRows)return;let n=u.get(e);if(n===void 0)throw Error("Collection row draft lane is missing");let r,t=[],s=[],c=[],a=[],p,I=new WeakSet,v=new WeakMap,x=new Map,g=[],N=new Map,E=Object.freeze([]),D={baselinePresent:!1,transitions:E,birth:void 0},L={baselinePresent:!0,transitions:E,birth:J},_=new Map,we=new Map,G=(i)=>{let R=x.get(i.scope);if(R===void 0)R=new Map,x.set(i.scope,R);if(R.set(i.atom,i),i.existing!==void 0)v.set(i.existing,i)},W=(i)=>{let R=v.get(i);if(R!==void 0)return R;let h=[],m=i,b;while(m!==void 0){T(m.scope,pe);let y=v.get(m);if(y!==void 0){b=y;break}h.push(m),m=m.inheritedFrom}for(let y=h.length-1;y>=0;y--){let S=h[y],w={scope:S.scope,atom:S.atom,existing:S,parent:b,beforeRows:S.ordered===void 0?X(S):Y,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};if(S.ordered!==void 0){let M;Object.defineProperty(w,"beforeRows",{get:()=>M??=X(S)})}G(w),b=w}return b},le=(i,R)=>{let h=x.get(i)?.get(R);if(h!==void 0)return h;let m=[],b=i,y;while(b!==void 0){let S=x.get(b)?.get(R);if(S!==void 0){T(b,pe),y=S;break}let w=C.get(b)?.memberships?.get(R);if(w!==void 0){y=W(w);break}T(b,pe),m.push(b),b=b.parent}for(let S=m.length-1;S>=0;S--){let w={scope:m[S],atom:R,existing:void 0,parent:y,beforeRows:y?.beforeRows??Y,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};y?.plannedChildren.push(w),c.push(w),G(w),y=w}return y},ye=(i)=>{let R=N.get(i);if(R!==void 0)return R;return R={collection:i,top:void 0},N.set(i,R),g.push(R),R},Be=(i,R)=>{R.affected=!0;let h=i.top;if(h===void 0)i.top=R;let m,b=R;while(b!==void 0){if(b.containsAffected){if(m??=b,Object.is(b,h))return}else b.containsAffected=!0;b=b.parent}if(h!==void 0)i.top=m},bo=(i,R)=>{if(i.existing?.ordered!==void 0)return i.existing.ordered.entries.has(R);let h=we.get(i);if(h===void 0){if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);h=new Set(i.beforeRows),we.set(i,h)}return h.has(R)},fn=(i,R,h,m)=>{if(z!==void 0)z.states++;let b=j(i.scope,R).kind;if(m===void 0)return b==="none"?h:b==="present"?L:D;let y=h.baselinePresent,S=b==="present"||b==="none"&&y,w=S,M=S?J:void 0,k=[],O=0,P=0;while(O<h.transitions.length||P<m.length){let F=h.transitions[O],ie=m[P],ne;if(F!==void 0&&(ie===void 0||F.sequence<ie.sequence))y=F.present,ne=F.sequence,O++;else b=ie.kind==="present"?"present":ie.kind==="absent"?"absent":"none",ne=ie.sequence,P++;let hn=b==="present"||b==="none"&&y;if(hn===S)continue;S=hn,M=S?ne:void 0,k.push({sequence:ne,present:S})}if(!k.length)return S?L:D;return{baselinePresent:w,transitions:k,birth:M}},Ae=(i)=>{let R=_.get(i);if(R!==void 0)return R;let h=[],m=i;while(m!==void 0&&!_.has(m))h.push(m),m=m.parent;let b=m===void 0?new Map:_.get(m);for(let y=h.length-1;y>=0;y--){let S=h[y],w=new Map;for(let k of n.historyByCollectionScope.get(S.atom)?.get(S.scope)??[]){let O=w.get(k.row);if(O===void 0)O=[],w.set(k.row,O);O.push(k)}let M=new Map;if(b.size!==0)T(S.scope,q,b.size);for(let[k,O]of b)M.set(k,fn(S,k,O,w.get(k))),w.delete(k);for(let[k,O]of w){let P=S.parent!==void 0&&bo(S.parent,k)?L:D;M.set(k,fn(S,k,P,O))}_.set(S,M),b=M}return _.get(i)},ve=(i)=>i.follower??=i.rebase===void 0&&i.parent!==void 0&&(i.parent.rebase!==void 0||ve(i.parent))&&sn(n,i.scope,i.atom,i.beforeRows,i.parent.beforeRows,()=>Me(i.parent)),mo=(i)=>{if(n.rebased===void 0)return;let R;if(i.rebase!==void 0){let b=i.parent;while(b.rebase!==void 0||ve(b))b=b.parent;R=cn(n,i.scope,i.atom,b.beforeRows,b.scope)}else if(ve(i))R=Me(i.parent);else return;let h=i.beforeRows,m=!B(i.scope,h,R);if(i.membershipChangedFromBefore=m,i.finalRows=i.existing!==void 0&&!m?h:Object.freeze([...R]),m&&i.existing!==void 0&&A(i.scope)!==void 0)i.membershipChanges=wo(h,i.finalRows);if(i.existing?.ordered!==void 0&&m)i.orderedRebuild=i.finalRows,(r??=[]).push(i);return i.finalRows},Me=(i)=>{if(i.finalRows!==void 0)return i.finalRows;let R=mo(i);if(R!==void 0)return R;if(i.existing?.ordered!==void 0){let w=Ae(i),M=[],k=[];for(let[P,F]of w){if(F.baselinePresent&&F.birth!==J)M.push(P);if(typeof F.birth==="number")k.push({row:P,birth:F.birth})}k.sort((P,F)=>P.birth-F.birth);let O=k.map((P)=>P.row);return i.membershipChangedFromBefore=i.existing.ordered.changes(M,O),i.orderedPatch={removals:M,births:O},(r??=[]).push(i),i.membershipChanges=w,Y}if(i.existing!==void 0)H?.push(i.existing);let h=[],m=[],b=i.existing!==void 0&&A(i.scope)!==void 0,y;if(d===void 0){let w=Ae(i);if(b)y=w;if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);for(let M of i.beforeRows){let k=w.get(M);if(k===void 0||k.birth===J)h.push(M)}if(w.size!==0)T(i.scope,q,w.size);for(let[M,k]of w){if(y!==void 0&&(k.baselinePresent&&k.birth===void 0||!k.baselinePresent&&typeof k.birth==="number"))i.membershipChanges=y;if(typeof k.birth==="number")m.push({row:M,birth:k.birth})}}else{let w=new Map,M=n.historyByCollectionScope.get(i.atom),k=i.scope;while(k!==void 0){for(let O of M?.get(k)??[])if(!w.has(O.row))w.set(O.row,ce(e,i.scope,O.row,i.atom));k=k.parent}if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);for(let O of i.beforeRows){let P=w.get(O);if(P===void 0||P.enablingBirth===J)h.push(O)}if(w.size!==0)T(i.scope,q,w.size);for(let O of w.values())if(typeof O.enablingBirth==="number"&&U(n,O.scope,O.row,O.collection).kind==="present")m.push({row:O.row,birth:O.enablingBirth})}m.sort((w,M)=>w.birth-M.birth);for(let w of m)h.push(w.row);let S=!B(i.scope,i.beforeRows,h);if(i.membershipChangedFromBefore=S,i.existing!==void 0&&!S)i.finalRows=i.beforeRows;else i.finalRows=Object.freeze(h),T(i.scope,Ce);return i.finalRows};for(let i of n.planOrder){let R=i.final;if(R===void 0)continue;T(i.scope,Rn);let h=R.kind==="present"?Se(R.value):R.kind==="absent"&&i.scope.parent!==void 0?Te:Re,m=!bn(j(i.scope,i.row),h);t.push(Object.freeze({coordinate:i,local:h,ownershipChanged:m}));let b=ye(i.collection),y=ae(te(i.scope,i.row,i.collection)),S=y.local.kind!==h.kind;if(S){if(le(i.scope,i.collection),i.scope.parent!==void 0)(p??=[]).push({scope:i.scope,collection:i.collection,history:!0})}let w=y.effective.kind==="present"?J:void 0;if(!Object.is(w,i.enablingBirth)){if(Be(b,le(i.scope,i.collection)),!S&&i.scope.parent!==void 0)(p??=[]).push({scope:i.scope,collection:i.collection,history:!0})}let M=C.get(i.scope)?.rowViews?.get(i.row);if(M===void 0)continue;let k=[M];while(k.length){let O=k.pop();if(I.has(O))continue;I.add(O),T(O.scope,ze);let P=O.served.outcome.kind==="value"&&O.served.outcome.value!==void 0?oe(O.served.outcome.value):Z,F=U(n,O.scope,O.atom,i.collection);if(Ee(P,F))continue;s.push(Object.freeze({scope:O.scope,atom:O.atom,record:O,before:P,outcome:F}));let ie=[];O.inheritingChildren.forEach((ne)=>{O.scope.coordinator.recordCounter(1),ie.push(ne)});for(let ne=ie.length-1;ne>=0;ne--)k.push(ie[ne])}}if(n.rebased!==void 0)for(let[i,R]of n.rebased){let h=n.historyByCollectionScope;for(let m of R.collections){let b=le(i,m);b.rebase=R,Be(ye(m),b),(p??=[]).push({scope:i,collection:m,history:(h.get(m)?.get(i)??[]).some((y)=>y.sequence>=R.end)})}}if(n.rebased!==void 0)for(let[i,R]of n.historyByCollectionScope){if(!en(n,i))continue;for(let[h,m]of R){if(m.length===0||ee(n,h,i)!==void 0||!io(n,h,i))continue;Be(ye(i),le(h,i)),(p??=[]).push({scope:h,collection:i,history:!0})}}for(let i of g){let R=i.top;if(R===void 0)continue;let h=new Set,m=[{node:R,affected:!1}];while(m.length){let b=m.pop(),y=b.node;if(h.has(y))continue;h.add(y),T(y.scope,pe);let S=b.affected||y.affected;if(S){let M=Me(y);if(y.existing!==void 0&&(y.orderedPatch!==void 0?y.membershipChangedFromBefore:!Object.is(M,y.beforeRows)))a.push(Object.freeze({scope:y.scope,atom:y.atom,node:y,record:y.existing,rows:M}))}let w=[];y.existing?.inheritingChildren.forEach((M)=>{y.scope.coordinator.recordCounter(1);let k=S?W(M):v.get(M);if(k!==void 0&&(S||k.containsAffected))w.push(k)});for(let M of y.plannedChildren)if(S||M.containsAffected)w.push(M);for(let M=w.length-1;M>=0;M--)m.push({node:w[M],affected:S})}}for(let i of c){if(i.finalRows!==void 0)continue;if(i.parent===void 0){Me(i);continue}i.finalRows=i.beforeRows,i.membershipChangedFromBefore=!1}let un,pn=n.rebased===void 0?void 0:r?.filter((i)=>i.orderedRebuild!==void 0);if(f!==void 0&&(n.planOrder.some((i)=>f.active(i.collection))||pn?.some((i)=>f.active(i.atom)))){let i=new Map;for(let h of n.planOrder){if(!f.active(h.collection))continue;let m=C.get(h.scope)?.memberships?.get(h.collection);if(m===void 0)continue;let b=[m];while(b.length){let y=b.pop();if(y.ordered===void 0)continue;T(y.scope,_n);let S=i.get(y);if(S===void 0)i.set(y,S=new Set);S.add(h.row),y.indexedChildren?.forEach((w)=>b.push(w))}}let R=[];for(let h of pn??[]){let m=h.existing,b=m.ordered,y=new Map;h.orderedRebuild.forEach((w,M)=>y.set(w,b.nextRank+M));let S=[];for(let w of new Set([...b.entries.keys(),...h.orderedRebuild])){let M=V(m.scope,w),k=U(n,m.scope,w,m.atom);S.push({row:w,before:M.kind==="present"?M.value:void 0,after:k.kind==="present"?k.value:void 0,rank:y.get(w)})}if(S.length)R.push({scope:m.scope,collection:m.atom,changes:S})}for(let[h,m]of i){if(h.ordered===void 0)continue;if(v.get(h)?.orderedRebuild!==void 0)continue;let b=W(h),S=n.rebased!==void 0&&(b.rebase!==void 0||ve(b))?void 0:Ae(b),w=[];for(let M of m){let k=V(h.scope,M),O=U(n,h.scope,M,h.atom),P=S?.get(M)?.birth;if(Ee(k,O)&&typeof P!=="number")continue;w.push({row:M,before:k.kind==="present"?k.value:void 0,after:O.kind==="present"?O.value:void 0,rank:O.kind==="absent"?void 0:typeof P==="number"?h.ordered.nextRank+P:h.ordered.entries.get(M)?.rank})}if(w.length)R.push({scope:h.scope,collection:h.atom,changes:w})}un=f.prepare(R)}return{commit:po,indexPlan:un,orderedNodes:r,historyMarks:p,rows:Object.freeze(t),rowSettlements:Object.freeze(s),membershipInstalls:Object.freeze(c),membershipSettlements:Object.freeze(a),sources:Object.freeze([...s,...a])}},ao=(o)=>{let e=o,n=!1;for(let r of e.rowSettlements){let{record:t,before:s,outcome:c}=r;T(t.scope,vn),K(t.scope,s.kind==="absent"?xn:c.kind==="absent"?In:Hn,t.atom,l.lookupRow(t.atom))}for(let r of e.membershipSettlements)for(let[t,s]of r.node.membershipChanges??[]){let c=s.baselinePresent&&s.birth===void 0?Pn:!s.baselinePresent&&typeof s.birth==="number"?Ln:void 0;if(c!==void 0)K(r.node.scope,c,t,r.node.atom)}for(let r of e.rows){let t=r.coordinate.finalOperation;if(t!==void 0)K(r.coordinate.scope,t==="set"?En:t==="update"?Tn:t==="reset"?Nn:Dn,r.coordinate.row,r.coordinate.collection);if(!r.ownershipChanged)continue;n=!0;let{row:s,scope:c}=r.coordinate;if(r.local.kind==="none"){let v=C.get(c);if(v?.rowLocals?.delete(s),v?.ownedRows?.delete(s))T(c,Ke);if(v?.ownedRows?.size===0){if(v.ownedRows=void 0,v.rowLocals=void 0,v.liveRowViews===void 0&&v.liveMemberships===void 0)C.delete(c)}continue}let a=be(c),p=a.rowLocals;if(p===void 0)p=new WeakMap,a.rowLocals=p;let I=a.ownedRows;if(I===void 0)I=new Set,a.ownedRows=I,T(c,Mn);if(p.set(s,r.local),!I.has(s))I.add(s),T(c,On)}for(let r of e.membershipInstalls)r.installed=Pe(r.scope,r.atom,r.finalRows,r.parent!==void 0&&r.finalRows===r.beforeRows);for(let r of e.orderedNodes??[]){let t=r.existing;if(r.orderedRebuild!==void 0){let c=t.ordered,a=c.nextRank;c.entries.clear(),c.tail=void 0,c.nextRank=a;for(let p of r.orderedRebuild)c.append(p);t.snapshotDirty=!0,t.served=se(t.scope,Y,t.served.token);continue}let s=r.orderedPatch;if(!r.membershipChangedFromBefore)continue;for(let c of s.removals)t.ordered.remove(c);for(let c of s.births)t.ordered.append(c);t.snapshotDirty=!0,t.served=se(t.scope,Y,t.served.token)}if(e.membershipSettlements.length)return!0;for(let r of e.membershipInstalls)if(r.membershipChangedFromBefore)return!0;return n},fo=(o)=>{let e=o;for(let n of e.rows){if(!n.ownershipChanged)continue;let{row:r,scope:t}=n.coordinate,s=C.get(t)?.rowViews?.get(r);if(s===void 0)continue;if(n.local.kind!=="none"||t.parent===void 0)Ie(s);else $n(s,Xe(t.parent,r))}for(let n of e.membershipInstalls){let r=n.installed,t=n.parent?.existing??n.parent?.installed;if(r!==void 0&&t!==void 0)Qe(r,t)}if(e.historyMarks!==void 0)for(let{scope:n,collection:r,history:t}of e.historyMarks){let s=C.get(n)?.memberships?.get(r);if(s!==void 0)s.localHistory=t}},uo=(o)=>{let e=o;for(let r of e.rowSettlements){let{record:t,outcome:s}=r;t.served=Object.freeze({token:t.scope.createOutcomeToken(),outcome:wn(s)}),T(t.scope,gn),K(t.scope,jn,t.atom,l.lookupRow(t.atom)),t.scope.coordinator.reachSubscriptionTarget(t.scope,t.atom)}for(let r of e.membershipSettlements){let{record:t,rows:s}=r;t.served=se(t.scope,t.ordered===void 0?s:t.served.outcome.kind==="value"?t.served.outcome.value:Y),T(t.scope,kn),K(t.scope,Vn,t.atom),t.scope.coordinator.reachSubscriptionTarget(t.scope,t.atom)}let n=e.indexPlan?.publish();if(n?.length)return[...e.sources,...n];return e.sources.length?e.sources:void 0},po=function(o){if(o===0)return ao(this);if(o===1)return fo(this);return uo(this)},ho=(o)=>{let e=o;f?.dispose(e);let n=C.get(e);if(n===void 0)return;n.liveRowViews?.forEach((t)=>{Ie(t),t.inheritingChildren.clear()}),n.liveMemberships?.forEach((t)=>{Je(t),t.inheritingChildren.clear(),t.indexedChildren?.clear(),t.ordered?.entries.clear(),t.ordered=void 0,t.snapshotDirty=!1,t.served=se(t.scope,Y,t.served.token)}),n.liveRowViews?.clear(),n.liveMemberships?.clear();let r=n.ownedRows?.size??0;if(r!==0)T(e,Ke,r);n.ownedRows?.clear(),n.rowLocals=void 0,n.ownedRows=void 0,n.rowViews=void 0,n.liveRowViews=void 0,n.memberships=void 0,n.liveMemberships=void 0,C.delete(e)};return Object.freeze({installIndexes:(o)=>f??(f=o({revision:(e,n)=>{let r=re(e),t=r.queryRevisionByCollection??=new Map,s=t.get(n)??0;return t.set(n,s),s},membership:eo,value:(e,n)=>{let r=V(e,n);return r.kind==="present"?r.value:void 0},draftRows:fe,draftValue:(e,n,r)=>{let t=re(e),s=n;while(s!==void 0){let c=t.byScope.get(s)?.get(r),a=c===void 0?j(s,r):Oe(c);if(a.kind==="present")return a.value;if(a.kind==="absent")return;s=s.parent}return}})),has:(o)=>f?.has(o)===!0||l.lookupRow(o)!==void 0||l.lookupCollection(o),diagnosticName:l.lookupDiagnosticName,read:(o,e,n)=>{let r=o,t=e;if(f?.has(n))return{kind:"value",value:f.read(r,t,n)};if(l.lookupRow(n)!==void 0)return Object.freeze({kind:"value",value:an(r,t,n)});if(l.lookupCollection(n))return Object.freeze({kind:"value",value:fe(r,t,n)});throw TypeError("Unknown collection scratch source")},stage:(o,e,n,r,t,s)=>{let c=o,a=e;if(n==="set")tn(c,a,r,t,s);else if(n==="update")rn(c,a,r,t,s);else if(n==="delete")ln(c,a,r);else je(c,a,r)},scope:(o,e,n)=>{if(e===void 0){ho(o);return}if(f?.has(e))return f.scope(o,e,n);if(l.lookupRow(e)!==void 0)return Xe(o,e).served;if(!l.lookupCollection(e))return;let r=de(o,e);return X(r),r.served},plan:co,resetAll:(o,e)=>ro(o,e),stageSet:tn,stageUpdate:rn,stageDelete:ln,stageReset:je,readDraftRow:an,readDraftCollection:fe,beginMembershipRebuildTraceForTest:()=>{if(H!==void 0)throw Error("A membership rebuild trace is already active");let o=[];return H=o,()=>{if(o===void 0)throw Error("The membership rebuild trace is already finished");H=void 0;let e=Object.freeze([...o]);return o.length=0,o=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(z!==void 0)throw Error("A membership placement trace is already active");let o={coordinates:0,states:0};return z=o,()=>{if(o===void 0)throw Error("The membership placement trace is already finished");z=void 0;let e=Object.freeze({...o});return o=void 0,e}},inspectDraft:so})};var Co={ref:(l)=>new WeakRef(l),registry:(l)=>{let d=new FinalizationRegistry(l);return Object.freeze({register:(f,u,C)=>d.register(f,u,C),unregister:(f)=>d.unregister(f)})}};class Fe{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(l,d,f=Co,u){this.#o=l,this.#t=u,this.#r=d,this.#n=f.registry((C)=>{let H=C.route;if(H.entry!==C)return;H.entry=void 0,this.#d(H)}),this.#i=(C)=>f.ref(C)}#i;getOrCreateOne(l,d){return this.#s(this.#l(this.#e,l),d)}getOrCreateTuple(l,d){let f=this.#e;for(let u=0;u<l.length;u++)f=this.#l(f,l[u]);return this.#s(f,d)}get routeCount(){let l=0,d=(f)=>{if(f.children===void 0)return;for(let u of f.children.values())l++,d(u)};return d(this.#e),l}hasRoute(l){let d=this.#e;for(let f=0;f<l.length;f++){let u=d.children?.get(l[f]);if(u===void 0)return!1;d=u}return!0}#l(l,d){let f=l.children??(l.children=new Map),u=f.get(d);if(u!==void 0)return u;return u={parent:l,parentKey:d,children:void 0,entry:void 0},f.set(d,u),u}#s(l,d){let f=l.entry;if(f?.kind==="ready"){let C=f.reference.deref();if(C!==void 0)return C;if(this.#n.unregister(f),l.entry===f)l.entry=void 0}else if(f?.kind==="building"){let C=f.fault??this.#r();throw f.fault=C,C}let u={kind:"building",route:l,fault:void 0};l.entry=u;try{let C=this.#o(d);if(u.fault!==void 0)throw u.fault;this.#t?.(C);let H={kind:"ready",route:l,reference:this.#i(C)};return l.entry=H,this.#n.register(C,H,H),C}catch(C){if(l.entry===u)l.entry=void 0;throw this.#d(l),u.fault??C}}#d(l){let d=l;while(d.parent!==void 0&&d.entry===void 0&&(d.children===void 0||d.children.size===0)){let f=d.parent,u=f.children;if(u?.get(d.parentKey)!==d)return;if(u.delete(d.parentKey),u.size===0)f.children=void 0;d=f}}}var Ro=(l)=>new WeakRef(l),De,So=(l)=>{let d=xe(l),f=De??(De=new WeakMap),u=f.get(d);if(u!==void 0)return u;return u={collections:new WeakMap,rows:new WeakMap},f.set(d,u),u};class Xn 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 qe=()=>new Xn,Ze=(l)=>{if(l===null)return null;switch(typeof l){case"string":case"bigint":case"boolean":return l;case"number":if(!Number.isFinite(l))throw qe();return Object.is(l,-0)?0:l;default:throw qe()}},qn=(l)=>{throw ge(l),qe()},go=(l,d,f)=>Ue(l,"collection-encoder",(u)=>{let C;try{C=Reflect.apply(d,void 0,[u])}catch(z){let A=he(z);if(A.kind==="not-thenable")throw z;if(A.kind==="inspection-error")throw A.error;return qn(A)}let H=he(C);if(H.kind==="not-thenable")return C;if(H.kind==="inspection-error")throw H.error;return qn(H)},[f],Ze,()=>TypeError("collection encodeKey cannot call family or collection accessors")),ko=(l)=>{if(l===void 0)return{};if(typeof l!=="object"||l===null)throw TypeError("collection options must be an object");for(let u of Reflect.ownKeys(l))if(u!=="encodeKey"&&u!=="indexes"&&u!=="name")throw TypeError("collection options contain an unknown option");let d;if(Object.prototype.hasOwnProperty.call(l,"encodeKey")){let u=Reflect.get(l,"encodeKey");if(typeof u!=="function")throw TypeError("collection encodeKey must be a function");d=u}let f=Reflect.get(l,"name");return{...d===void 0?{}:{encodeKey:d},...f===void 0?{}:{name:f}}},vo=()=>TypeError("collection cannot recursively construct the same row"),Mo=()=>TypeError("presence requires a same-domain CollectionRow"),Oo=(l,d)=>{let f=De?.get(xe(l));if(typeof d==="object"&&d!==null||typeof d==="function"){let u=f?.rows.get(d);if(u!==void 0)return u}throw Ye(l,d),Mo()};function Ao(l,d,f){Yn(l);let{encodeKey:u,name:C}=ko(d),H;if(d!==void 0&&Object.prototype.hasOwnProperty.call(d,"indexes")){let j=Reflect.get(d,"indexes");if(typeof j!=="object"||j===null||Array.isArray(j))throw TypeError("collection indexes must be an extractor map");let V=Reflect.ownKeys(j).map((Q)=>{let te=Reflect.get(j,Q);if(typeof Q!=="string"||typeof te!=="function")throw TypeError("collection indexes must be named scalar extractors");return[Q,te]});if(V.length)H=Object.freeze(Object.fromEntries(V))}let z=[],A,T=Object.assign(function(V){Ge(l);let Q=u===void 0?Ze(V):go(l,u,V);z[0]=Q;try{return A.rows.getOrCreateOne(Q,z)}finally{z.pop()}},{kind:"collection"}),K=We(l,T),B,be=new Fe((j)=>{let V=j[0];return We(l,{kind:"collection-row",key:V})},vo,f,(j)=>{if(B===void 0)throw Error("Collection definition registry is not ready");B.rows.set(j,{definition:A,presence:void 0})});return A=Object.freeze({collection:K,indexes:H,...C===void 0?{}:{name:C},rows:be,referencePresence:f===void 0?Ro:(j)=>f.ref(j)}),B=So(l),B.collections.set(K,A),Gn(l,(j)=>Wn({lookupRow:(V)=>B.rows.get(V)?.definition.collection,lookupCollection:(V)=>B.collections.has(V),lookupDiagnosticName:(V)=>B.rows.get(V)?.definition?.name??B.collections.get(V)?.name,runGuarded:(V,Q)=>Un(j,V,Q),inspectThenable:he,containThenable:ge})),K}var _o=(l,d)=>{Ge(l);let f=Oo(l,d),u=f.presence?.deref();if(u!==void 0)return u;let C=Zn(l,(H)=>H(d)!==void 0);return f.presence=f.definition.referencePresence(C),C},zo=(l,d,f)=>{let u=De?.get(xe(l))?.collections.get(d);if(u===void 0)throw Ye(l,d),TypeError("query requires a same-domain Collection");let C=u.indexes!==void 0&&Object.prototype.hasOwnProperty.call(u.indexes,f)?u.indexes[f]:void 0;if(C===void 0)throw TypeError("query requires a declared equality index");return(H)=>Ue(l,"collection-encoder",(z)=>{let A;try{A=C(z)}catch(K){let B=he(K);if(B.kind==="thenable")throw ge(B),TypeError("Index extractors must return a synchronous scalar");if(B.kind==="inspection-error")throw B.error;throw K}let T=he(A);if(T.kind==="thenable")throw ge(T),TypeError("Index extractors must return a synchronous scalar");if(T.kind==="inspection-error")throw T.error;return Ze(A)},[H])};
|
|
1
|
+
import{A as xn,B as Hn,C as In,D as Ln,E as Pn,F as jn,G as Vn,H as Bn,I as An,P as _n,i as yn,j as Cn,k as Rn,l as ze,m as Sn,n as pe,o as q,p as Ce,q as gn,r as kn,s as vn,t as Mn,u as On,v as Ke,w as En,x as Tn,y as Nn,z as Dn}from"./chunk-tywyt3b6.js";import{Aa as Ge,Ba as Yn,Da as We,Ea as Ye,Ka as Zn,la as he,ma as ge,oa as Un,ua as ue,va as xe,xa as Gn,za as Ue}from"./chunk-4wpe8fhf.js";class _e{entries=new Map;tail;nextRank=0;constructor(l){for(let d of l)this.append(d)}append(l){let d=this.tail;if(this.entries.set(l,{rank:this.nextRank++,previous:d}),d!==void 0)this.entries.get(d).next=l;this.tail=l}remove(l){let d=this.entries.get(l);if(d===void 0)return;if(d.previous!==void 0)this.entries.get(d.previous).next=d.next;if(d.next!==void 0)this.entries.get(d.next).previous=d.previous;else this.tail=d.previous;this.entries.delete(l)}changes(l,d){if(l.length!==d.length)return!0;let f=new Set(l),u=this.tail;for(let C=d.length-1;C>=0;C--){if(d[C]!==u||!f.has(d[C]))return!0;u=this.entries.get(u)?.previous}return!1}}var J=Symbol("collection baseline birth"),wo=(l,d)=>{let f=new Map,u=new Set(d);for(let H of l)if(!u.has(H))f.set(H,{baselinePresent:!0,transitions:[],birth:void 0});let C=new Set(l);for(let H of d)if(!C.has(H))f.set(H,{baselinePresent:!1,transitions:[],birth:0});return f},yo=(l,d)=>{for(let f=l.parent;f!==void 0;f=f.parent)if(f===d)return!0;return!1};class Ne extends Error{seal(){Object.freeze(this)}}class zn extends Ne{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class Kn extends Ne{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class Fn extends Ne{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var Re=Object.freeze({kind:"none"}),Te=Object.freeze({kind:"absent"}),Z=Object.freeze({kind:"absent"}),Y=Object.freeze([]),Se=(l)=>Object.freeze({kind:"present",value:l}),oe=(l)=>Object.freeze({kind:"present",value:l}),Ee=(l,d)=>l.kind===d.kind&&(l.kind==="absent"||d.kind==="present"&&Object.is(l.value,d.value)),bn=(l,d)=>l.kind===d.kind&&(l.kind!=="present"||d.kind==="present"&&Object.is(l.value,d.value)),ae=(l)=>{let d=l.local.kind==="present"?Se(l.local.value):l.local.kind==="absent"?Te:Re,f=l.effective.kind==="present"?oe(l.effective.value):Z,u=l.inherited.kind==="present"?oe(l.inherited.value):Z;if(d.kind==="none"&&!Ee(f,u))throw Error("Collection baseline without local ownership must equal inherited outcome");if(d.kind==="present"&&(f.kind!=="present"||!Object.is(d.value,f.value)))throw Error("Collection present local baseline must equal its effective outcome");if(d.kind==="absent"&&f.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:d,effective:f,inherited:u})},Oe=(l)=>{let d=l.final;if(d===void 0)return l.baseline.local;if(d.kind==="present")return Se(d.value);return d.kind==="absent"?Te:Re},mn=(l,d)=>l.kind==="present"?oe(l.value):l.kind==="absent"?Z:d,wn=(l)=>Object.freeze({kind:"value",value:l.kind==="present"?l.value:void 0}),Wn=(l,d)=>{let f,u=new WeakMap,C=new WeakMap,H,z,A=(o)=>o.coordinator?.evaluate?.recordExtension,T=(o,e,n=1)=>{A(o)?.(e,n)},K=(o,e,n,r)=>{A(o)?.(e,o,n,r)},B=(o,e,n)=>{if(e.length!==n.length)return!1;let r=A(o);if(r===void 0){for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return!1;return!0}for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return r(q,t+1),!1;if(e.length)r(q,e.length);return!0},be=(o)=>{let e=C.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},C.set(o,e),e},j=(o,e)=>C.get(o)?.rowLocals?.get(e)??Re,V=(o,e)=>{let n=o;while(n!==void 0){let r=j(n,e);if(r.kind==="present")return oe(r.value);if(r.kind==="absent")return Z;n=n.parent}return Z},te=d??((o,e)=>{let n=j(o,e),r=V(o.parent,e);return Object.freeze({local:n,effective:mn(n,r),inherited:r})}),Jn=(o,e,n,r)=>{let t=o.byScope.get(e)?.get(n);if(t!==void 0)return Oe(t);return ae(te(e,n,r)).local},U=(o,e,n,r)=>{let t=e;while(t!==void 0){let s=Jn(o,t,n,r);if(s.kind==="present")return oe(s.value);if(s.kind==="absent")return Z;if(d!==void 0){let c=o.byScope.get(t)?.get(n);if(c!==void 0)return c.baseline.inherited;return ae(te(t,n,r)).inherited}t=t.parent}return Z},Qn=(o,e,n,r)=>{if(d!==void 0){let t=ae(te(e,n,r)),s=t.effective.kind==="present",c=s?J:void 0;for(let a of o.byRow.get(n)?.historyByScope.get(e)??[]){if(!Object.is(a.row,n)||!Object.is(a.scope,e))continue;let p=a.kind==="present"||a.kind==="reset"&&t.inherited.kind==="present";if(!s&&p)c=a.sequence;else if(!p)c=void 0;s=p}return c}return dn(o,e,n,r,void 0)},He=(o,e,n,r)=>{let t=be(o),s=t.rowViews?.get(e);if(s!==void 0)return s;let c={scope:o,atom:e,served:Object.freeze({token:o.createOutcomeToken(),outcome:wn(n)}),inheritedFrom:r,inheritingChildren:new ue(()=>o.coordinator.recordCounter(2))},a=t.rowViews;if(a===void 0)a=new WeakMap,t.rowViews=a;let p=t.liveRowViews;if(p===void 0)p=new ue(()=>o.coordinator.recordCounter(2)),t.liveRowViews=p;if(a.set(e,c),p.add(c),K(o,Bn,e,l.lookupRow(e)),r!==void 0)r.inheritingChildren.add(c),o.coordinator.recordCounter(11);return c},Xe=(o,e)=>{let n=o,r=[],t;while(!0){T(n,ze);let s=C.get(n),c=s?.rowViews?.get(e);if(c!==void 0){t=c;break}let a=s?.rowLocals?.get(e);if(a!==void 0){t=He(n,e,a.kind==="present"?oe(a.value):Z);break}if(n.parent===void 0){t=He(n,e,Z);break}r.push(n),n=n.parent}for(let s=r.length-1;s>=0;s--)t=He(r[s],e,t.served.outcome.kind==="value"&&t.served.outcome.value!==void 0?oe(t.served.outcome.value):Z,t);return t},Ie=(o)=>{let e=o.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(o),o.inheritedFrom=void 0,o.scope.coordinator.recordCounter(12)},$n=(o,e)=>{if(Object.is(o.inheritedFrom,e))return;Ie(o),o.inheritedFrom=e,e.inheritingChildren.add(o),o.scope.coordinator.recordCounter(11)},X=(o)=>{if(o.snapshotDirty){let e=Object.freeze([...o.ordered.entries.keys()]);T(o.scope,q,e.length),T(o.scope,Ce),o.served=se(o.scope,e,o.served.token),o.snapshotDirty=!1}return o.served.outcome.kind==="value"?o.served.outcome.value:Y},eo=(o,e)=>{let n=de(o,e),r=n;while(r!==void 0&&r.ordered===void 0){r.ordered=new _e(X(r));let t=r.inheritedFrom;if(t!==void 0)(t.indexedChildren??=new ue).add(r);r=t}return n.ordered},Le=(o,e)=>{if(e.length)T(o,q,e.length);let n=Object.freeze([...e]);return T(o,Ce),n},se=(o,e,n=o.createOutcomeToken())=>Object.freeze({token:n,outcome:Object.freeze({kind:"value",value:e})}),Pe=(o,e,n,r=!1)=>{let t=be(o),s=t.memberships?.get(e);if(s!==void 0)return s;let c={scope:o,atom:e,served:se(o,n,r?Y:void 0),inheritedFrom:void 0,inheritingChildren:new ue(()=>o.coordinator.recordCounter(2))},a=t.memberships;if(a===void 0)a=new WeakMap,t.memberships=a;let p=t.liveMemberships;if(p===void 0)p=new ue(()=>o.coordinator.recordCounter(2)),t.liveMemberships=p;return a.set(e,c),p.add(c),T(o,Sn),K(o,An,e),c},Je=(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;Je(o),o.inheritedFrom=e,e.inheritingChildren.add(o),o.scope.coordinator.recordCounter(11)},de=(o,e)=>{let n=o,r=[],t;while(!0){T(n,pe);let s=C.get(n)?.memberships?.get(e);if(s!==void 0){if(t=s,t.served.token===Y){let c=Le(n,X(t));t.served=se(n,c)}break}if(n.parent===void 0){t=Pe(n,e,Le(n,Y));break}r.push(n),n=n.parent}for(let s=r.length-1;s>=0;s--){let c=r[s],a=Le(c,X(t)),p=Pe(c,e,a);Qe(p,t),t=p}return t},no=(o)=>{let e=o;f?.release(e);let n=u.get(e);if(n===void 0)return;u.delete(e);for(let r of n.byScope.values()){for(let t of r.values())t.final=void 0,t.finalOperation=void 0;r.clear()}n.byScope.clear(),n.planOrder.length=0,n.history.length=0;for(let r of n.historyByCollectionScope.values()){for(let t of r.values())t.length=0;r.clear()}n.historyByCollectionScope.clear();for(let r of n.byRow.values()){for(let t of r.coordinatesByAncestor.values())t.length=0;r.coordinatesByAncestor.clear();for(let t of r.historyByScope.values())t.length=0;r.historyByScope.clear()}n.byRow.clear(),n.revisionByCollection.clear(),n.queryRevisionByCollection?.clear();for(let r of n.membershipMemo.values())r.clear();n.membershipMemo.clear()},re=(o)=>{let e=u.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(no),u.set(o,e),e},me=(o)=>{let e=l.lookupRow(o);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},$e=(o,e)=>{o.revisionByCollection.set(e,(o.revisionByCollection.get(e)??0)+1)},oo=(o,e)=>{$e(o,e);let n=o.queryRevisionByCollection?.get(e);if(n!==void 0)o.queryRevisionByCollection.set(e,n+1)},en=(o,e)=>{for(let n of o.rebased?.values()??[])if(n.collections.has(e))return!0;return!1},ce=(o,e,n,r=me(n))=>{let t=re(o),s=t.byScope.get(e);if(s===void 0)s=new Map,t.byScope.set(e,s);let c=s.get(n);if(c!==void 0)return c;if(z!==void 0)z.coordinates++;let a=ae(te(e,n,r)),p=d===void 0?U(t,e.parent,n,r):a.inherited,I=ae({local:a.local,effective:mn(a.local,p),inherited:p});c={scope:e,row:n,collection:r,baseline:I,discoveryIndex:t.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},s.set(n,c);let v=t.byRow.get(n);if(v===void 0)v={coordinatesByAncestor:new Map,historyByScope:new Map},t.byRow.set(n,v);let x=e;while(x!==void 0){let g=v.coordinatesByAncestor.get(x);if(g===void 0)g=[],v.coordinatesByAncestor.set(x,g);g.push(c),x=x.parent}return c.enablingBirth=Qn(t,e,n,r),c},ke=(o,e,n,r,t,s)=>{let c=Oe(e),a=re(o),p=U(a,e.scope,e.row,e.collection);if(bn(c,t)&&Ee(p,s))return;if(!a.hasAcceptedIntent)a.hasAcceptedIntent=!0,T(e.scope,Cn);T(e.scope,yn);let I=[];for(let G of a.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let W=U(a,G.scope,G.row,G.collection);I.push({coordinate:G,effective:W,placement:W.kind==="present"?G.enablingBirth:void 0})}let v=o.generation;if(e.planIndex===void 0)e.planIndex=a.planOrder.length,a.planOrder.push(e);e.final=r,e.finalOperation=n;let x=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:r.kind,sequence:v});a.history.push(x);let g=a.byRow.get(e.row),N=g.historyByScope.get(e.scope);if(N===void 0)N=[],g.historyByScope.set(e.scope,N);N.push(x);let E=a.historyByCollectionScope.get(e.collection);if(E===void 0)E=new Map,a.historyByCollectionScope.set(e.collection,E);let D=E.get(e.scope);if(D===void 0)D=[],E.set(e.scope,D);let L=D.length===0;D.push(x);let _=!1;for(let G of I){let W=G.coordinate,le=U(a,W.scope,W.row,W.collection);if(G.effective.kind==="absent"&&le.kind==="present")W.enablingBirth=v;else if(le.kind==="absent")W.enablingBirth=void 0;let ye=le.kind==="present"?W.enablingBirth:void 0;if(!Object.is(G.placement,ye))_=!0}if(_||L&&a.rebased!==void 0&&en(a,e.collection)&&ee(a,e.scope,e.collection)===void 0)$e(a,e.collection);let we=a.queryRevisionByCollection?.get(e.collection);if(we!==void 0)a.queryRevisionByCollection.set(e.collection,we+1);o.markRow(v)},nn=()=>new zn,on=(o)=>{let e=l.inspectThenable(o);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw l.containThenable(e),nn();if(o===void 0)throw new Kn;return o},to=(o,e,n)=>l.runGuarded(n,()=>{let r;try{r=Reflect.apply(o,void 0,[e])}catch(t){let s=l.inspectThenable(t);if(s.kind==="not-thenable")throw t;if(s.kind==="inspection-error")throw s.error;throw l.containThenable(s),nn()}return on(r)}),tn=(o,e,n,r,t)=>{let s=me(n),c=l.runGuarded(t,()=>on(r)),a=ce(o,e,n,s);ke(o,a,"set",Object.freeze({kind:"present",value:c}),Se(c),oe(c))},rn=(o,e,n,r,t)=>{let s=me(n);if(typeof r!=="function")throw TypeError("Collection row update requires an updater");let c=ce(o,e,n,s),a=U(re(o),e,n,s);if(a.kind==="absent")throw new Fn;let p=to(r,a.value,t);ke(o,c,"update",Object.freeze({kind:"present",value:p}),Se(p),oe(p))},ln=(o,e,n)=>{let r=ce(o,e,n);ke(o,r,"delete",Object.freeze({kind:"absent"}),Te,Z)},je=(o,e,n)=>{let r=ce(o,e,n),t=d===void 0?U(re(o),e.parent,n,r.collection):r.baseline.inherited;ke(o,r,"reset",Object.freeze({kind:"reset"}),Re,t)},ro=(o,e)=>{let n=o.generation,r=[],t=C.get(e)?.ownedRows;if(t!==void 0)for(let g of t)r.push(g);let s=u.get(o)?.byScope.get(e);if(s!==void 0){let g=[];for(let N of s.values())if(N.planIndex!==void 0)g.push(N);g.sort((N,E)=>N.planIndex-E.planIndex);for(let N of g)r.push(N.row)}let c=new Set,a=[];for(let g of r){if(c.has(g))continue;c.add(g);let N=s?.get(g);if(N!==void 0){if(Oe(N).kind==="none")continue}else if(t?.has(g)!==!0)continue;a.push(g)}if(a.length>1&&!e.children.isEmpty()){let g=new Set(a),N=[];for(let E of new Set(a.map(me)))for(let D of fe(o,e.parent,E))if(g.delete(D))N.push(D);for(let E of a)if(g.has(E))N.push(E);a.length=0,a.push(...N)}for(let g of a)je(o,e,g);let p=new Set;for(let g of c)p.add(me(g));C.get(e)?.liveMemberships?.forEach((g)=>{if(g.localHistory)p.add(g.atom)});let I=re(o);for(let g=e.parent;g!==void 0;g=g.parent)for(let N of I.rebased?.get(g)?.collections??[])p.add(N);let v=I.cleared?.get(e);if(v!==void 0)for(let g of v.collections)p.add(g);let x={start:n,end:o.generation,collections:p};if((I.cleared??=new Map).set(e,x),p.size===0)return;(I.rebased??=new Map).set(e,x);for(let[g,N]of I.cleared){if(g===e||!yo(g,e))continue;for(let E of p)N.collections.add(E);I.rebased.set(g,N)}for(let g of p)oo(I,g);o.markRow(o.generation)},sn=(o,e,n,r,t,s)=>{if(o.historyByCollectionScope.get(n)?.get(e)?.length)return!1;if(r.length!==t.length)return!1;for(let a=0;a<r.length;a++)if(r[a]!==t[a])return!1;let c;for(let a of C.get(e)?.ownedRows??[]){if(l.lookupRow(a)!==n)continue;if(c??=new Set(s()),j(e,a).kind==="present"!==c.has(a))return!1}return!0},ee=(o,e,n)=>{let r=o.rebased?.get(e);return r?.collections.has(n)?r:void 0},io=(o,e,n)=>{for(let r=e.parent;r!==void 0;r=r.parent)if(ee(o,r,n)!==void 0)return!0;return!1},Ve=(o,e,n,r)=>{if(ee(e,n,r)!==void 0)return!1;let t=n.parent;if(t===void 0)return!1;if(ee(e,t,r)===void 0&&!Ve(o,e,t,r))return!1;return sn(e,n,r,X(de(n,r)),X(de(t,r)),()=>fe(o,t,r))},dn=(o,e,n,r,t)=>{let s=[],c=new Set,a=new Map,p=e,I=t!==void 0;while(p!==void 0){if(p===t)I=!1;if(s.push(p),I&&ee(o,p,r)!==void 0)c.add(p);a.set(p,c.has(p)?"none":ae(te(p,n,r)).local.kind),p=p.parent}let v=[],x=o.byRow.get(n);if(x!==void 0){for(let D of s){let L=c.has(D)?ee(o,D,r):void 0;for(let _ of x.historyByScope.get(D)??[])if(L===void 0||_.sequence>=L.start)v.push(_)}v.sort((D,L)=>D.sequence-L.sequence)}let g=()=>{for(let D of s){let L=a.get(D);if(L==="present")return!0;if(L==="absent")return!1}return!1},N=g(),E=N?J:void 0;for(let D of v){a.set(D.scope,D.kind==="present"?"present":D.kind==="absent"?"absent":"none");let L=g();if(!N&&L)E=D.sequence;else if(!L)E=void 0;N=L}return E},cn=(o,e,n,r,t)=>{let s=o.historyByCollectionScope.get(n),c=new Map,a=e;while(a!==void 0){for(let v of s?.get(a)??[])if(!c.has(v.row))c.set(v.row,dn(o,e,v.row,n,t));a=a.parent}let p=[];for(let v of r)if(!c.has(v)||c.get(v)===J)p.push(v);let I=[];for(let[v,x]of c)if(typeof x==="number")I.push({row:v,birth:x});I.sort((v,x)=>v.birth-x.birth);for(let{row:v}of I)p.push(v);return p},lo=(o,e,n,r)=>{let t=n.parent;while(ee(e,t,r)!==void 0||Ve(o,e,t,r))t=t.parent;return t},an=(o,e,n)=>{let r=ce(o,e,n),t=U(re(o),e,n,r.collection);return t.kind==="present"?t.value:void 0},fe=(o,e,n)=>{if(!l.lookupCollection(n))throw TypeError("Collection draft read requires a valid collection");let r=re(o),t=r.revisionByCollection.get(n)??0,s=r.membershipMemo.get(e),c=s?.get(n);if(c?.revision===t)return c.rows;if(r.rebased!==void 0&&(ee(r,e,n)!==void 0||Ve(o,r,e,n))){let E;if(ee(r,e,n)!==void 0){let _=lo(o,r,e,n);E=cn(r,e,n,X(de(_,n)),_)}else E=fe(o,e.parent,n);let D=X(de(e,n)),L=B(e,D,E)?D:c!==void 0&&B(e,c.rows,E)?c.rows:Object.freeze([...E]);if(s===void 0)s=new Map,r.membershipMemo.set(e,s);return s.set(n,{revision:t,rows:L}),L}let a=d===void 0&&typeof e.createOutcomeToken==="function"?X(de(e,n)):Y,p=new Map,I=r.historyByCollectionScope.get(n),v=e;while(v!==void 0){for(let E of I?.get(v)??[])if(!p.has(E.row))p.set(E.row,ce(o,e,E.row,n));v=v.parent}let x=[];if(a.length)T(e,q,a.length);for(let E of a){let D=p.get(E);if(D===void 0||D.enablingBirth===J)x.push(E)}let g=[];if(p.size!==0)T(e,q,p.size);for(let E of p.values())if(typeof E.enablingBirth==="number"&&U(r,E.scope,E.row,E.collection).kind==="present")g.push(E);g.sort((E,D)=>{let L=E.enablingBirth,_=D.enablingBirth;if(L===_)return E.discoveryIndex-D.discoveryIndex;return L-_});for(let E of g)x.push(E.row);let N;if(B(e,a,x))N=a;else if(c!==void 0&&B(e,c.rows,x))N=c.rows;else N=Object.freeze(x),T(e,Ce);if(s===void 0)s=new Map,r.membershipMemo.set(e,s);return s.set(n,Object.freeze({revision:t,rows:N})),N},so=(o)=>{let e=u.get(o);if(e===void 0)return;let n=0;for(let s of e.membershipMemo.values())n+=s.size;let r=new WeakMap;for(let[s,c]of e.revisionByCollection)r.set(s,Object.freeze({value:c}));let t=(s)=>Object.freeze({id:s.discoveryIndex,baselineLocal:s.baseline.local.kind,baselineEffective:s.baseline.effective.kind,baselineInherited:s.baseline.inherited.kind,final:s.final?.kind,enablingBirth:s.enablingBirth===J?"baseline":s.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((s)=>[...s.values()]).sort((s,c)=>s.discoveryIndex-c.discoveryIndex).map(t)),planOrder:Object.freeze(e.planOrder.map(t)),history:Object.freeze(e.history.map((s)=>Object.freeze({coordinateId:s.coordinateId,kind:s.kind,sequence:s.sequence}))),membershipMemoCount:n,revision:(s)=>r.get(s)?.value??0})},co=(o)=>{let e=o;if(!e.hasRows)return;let n=u.get(e);if(n===void 0)throw Error("Collection row draft lane is missing");let r,t=[],s=[],c=[],a=[],p,I=new WeakSet,v=new WeakMap,x=new Map,g=[],N=new Map,E=Object.freeze([]),D={baselinePresent:!1,transitions:E,birth:void 0},L={baselinePresent:!0,transitions:E,birth:J},_=new Map,we=new Map,G=(i)=>{let R=x.get(i.scope);if(R===void 0)R=new Map,x.set(i.scope,R);if(R.set(i.atom,i),i.existing!==void 0)v.set(i.existing,i)},W=(i)=>{let R=v.get(i);if(R!==void 0)return R;let h=[],m=i,b;while(m!==void 0){T(m.scope,pe);let y=v.get(m);if(y!==void 0){b=y;break}h.push(m),m=m.inheritedFrom}for(let y=h.length-1;y>=0;y--){let S=h[y],w={scope:S.scope,atom:S.atom,existing:S,parent:b,beforeRows:S.ordered===void 0?X(S):Y,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};if(S.ordered!==void 0){let M;Object.defineProperty(w,"beforeRows",{get:()=>M??=X(S)})}G(w),b=w}return b},le=(i,R)=>{let h=x.get(i)?.get(R);if(h!==void 0)return h;let m=[],b=i,y;while(b!==void 0){let S=x.get(b)?.get(R);if(S!==void 0){T(b,pe),y=S;break}let w=C.get(b)?.memberships?.get(R);if(w!==void 0){y=W(w);break}T(b,pe),m.push(b),b=b.parent}for(let S=m.length-1;S>=0;S--){let w={scope:m[S],atom:R,existing:void 0,parent:y,beforeRows:y?.beforeRows??Y,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};y?.plannedChildren.push(w),c.push(w),G(w),y=w}return y},ye=(i)=>{let R=N.get(i);if(R!==void 0)return R;return R={collection:i,top:void 0},N.set(i,R),g.push(R),R},Be=(i,R)=>{R.affected=!0;let h=i.top;if(h===void 0)i.top=R;let m,b=R;while(b!==void 0){if(b.containsAffected){if(m??=b,Object.is(b,h))return}else b.containsAffected=!0;b=b.parent}if(h!==void 0)i.top=m},bo=(i,R)=>{if(i.existing?.ordered!==void 0)return i.existing.ordered.entries.has(R);let h=we.get(i);if(h===void 0){if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);h=new Set(i.beforeRows),we.set(i,h)}return h.has(R)},fn=(i,R,h,m)=>{if(z!==void 0)z.states++;let b=j(i.scope,R).kind;if(m===void 0)return b==="none"?h:b==="present"?L:D;let y=h.baselinePresent,S=b==="present"||b==="none"&&y,w=S,M=S?J:void 0,k=[],O=0,P=0;while(O<h.transitions.length||P<m.length){let F=h.transitions[O],ie=m[P],ne;if(F!==void 0&&(ie===void 0||F.sequence<ie.sequence))y=F.present,ne=F.sequence,O++;else b=ie.kind==="present"?"present":ie.kind==="absent"?"absent":"none",ne=ie.sequence,P++;let hn=b==="present"||b==="none"&&y;if(hn===S)continue;S=hn,M=S?ne:void 0,k.push({sequence:ne,present:S})}if(!k.length)return S?L:D;return{baselinePresent:w,transitions:k,birth:M}},Ae=(i)=>{let R=_.get(i);if(R!==void 0)return R;let h=[],m=i;while(m!==void 0&&!_.has(m))h.push(m),m=m.parent;let b=m===void 0?new Map:_.get(m);for(let y=h.length-1;y>=0;y--){let S=h[y],w=new Map;for(let k of n.historyByCollectionScope.get(S.atom)?.get(S.scope)??[]){let O=w.get(k.row);if(O===void 0)O=[],w.set(k.row,O);O.push(k)}let M=new Map;if(b.size!==0)T(S.scope,q,b.size);for(let[k,O]of b)M.set(k,fn(S,k,O,w.get(k))),w.delete(k);for(let[k,O]of w){let P=S.parent!==void 0&&bo(S.parent,k)?L:D;M.set(k,fn(S,k,P,O))}_.set(S,M),b=M}return _.get(i)},ve=(i)=>i.follower??=i.rebase===void 0&&i.parent!==void 0&&(i.parent.rebase!==void 0||ve(i.parent))&&sn(n,i.scope,i.atom,i.beforeRows,i.parent.beforeRows,()=>Me(i.parent)),mo=(i)=>{if(n.rebased===void 0)return;let R;if(i.rebase!==void 0){let b=i.parent;while(b.rebase!==void 0||ve(b))b=b.parent;R=cn(n,i.scope,i.atom,b.beforeRows,b.scope)}else if(ve(i))R=Me(i.parent);else return;let h=i.beforeRows,m=!B(i.scope,h,R);if(i.membershipChangedFromBefore=m,i.finalRows=i.existing!==void 0&&!m?h:Object.freeze([...R]),m&&i.existing!==void 0&&A(i.scope)!==void 0)i.membershipChanges=wo(h,i.finalRows);if(i.existing?.ordered!==void 0&&m)i.orderedRebuild=i.finalRows,(r??=[]).push(i);return i.finalRows},Me=(i)=>{if(i.finalRows!==void 0)return i.finalRows;let R=mo(i);if(R!==void 0)return R;if(i.existing?.ordered!==void 0){let w=Ae(i),M=[],k=[];for(let[P,F]of w){if(F.baselinePresent&&F.birth!==J)M.push(P);if(typeof F.birth==="number")k.push({row:P,birth:F.birth})}k.sort((P,F)=>P.birth-F.birth);let O=k.map((P)=>P.row);return i.membershipChangedFromBefore=i.existing.ordered.changes(M,O),i.orderedPatch={removals:M,births:O},(r??=[]).push(i),i.membershipChanges=w,Y}if(i.existing!==void 0)H?.push(i.existing);let h=[],m=[],b=i.existing!==void 0&&A(i.scope)!==void 0,y;if(d===void 0){let w=Ae(i);if(b)y=w;if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);for(let M of i.beforeRows){let k=w.get(M);if(k===void 0||k.birth===J)h.push(M)}if(w.size!==0)T(i.scope,q,w.size);for(let[M,k]of w){if(y!==void 0&&(k.baselinePresent&&k.birth===void 0||!k.baselinePresent&&typeof k.birth==="number"))i.membershipChanges=y;if(typeof k.birth==="number")m.push({row:M,birth:k.birth})}}else{let w=new Map,M=n.historyByCollectionScope.get(i.atom),k=i.scope;while(k!==void 0){for(let O of M?.get(k)??[])if(!w.has(O.row))w.set(O.row,ce(e,i.scope,O.row,i.atom));k=k.parent}if(i.beforeRows.length)T(i.scope,q,i.beforeRows.length);for(let O of i.beforeRows){let P=w.get(O);if(P===void 0||P.enablingBirth===J)h.push(O)}if(w.size!==0)T(i.scope,q,w.size);for(let O of w.values())if(typeof O.enablingBirth==="number"&&U(n,O.scope,O.row,O.collection).kind==="present")m.push({row:O.row,birth:O.enablingBirth})}m.sort((w,M)=>w.birth-M.birth);for(let w of m)h.push(w.row);let S=!B(i.scope,i.beforeRows,h);if(i.membershipChangedFromBefore=S,i.existing!==void 0&&!S)i.finalRows=i.beforeRows;else i.finalRows=Object.freeze(h),T(i.scope,Ce);return i.finalRows};for(let i of n.planOrder){let R=i.final;if(R===void 0)continue;T(i.scope,Rn);let h=R.kind==="present"?Se(R.value):R.kind==="absent"&&i.scope.parent!==void 0?Te:Re,m=!bn(j(i.scope,i.row),h);t.push(Object.freeze({coordinate:i,local:h,ownershipChanged:m}));let b=ye(i.collection),y=ae(te(i.scope,i.row,i.collection)),S=y.local.kind!==h.kind;if(S){if(le(i.scope,i.collection),i.scope.parent!==void 0)(p??=[]).push({scope:i.scope,collection:i.collection,history:!0})}let w=y.effective.kind==="present"?J:void 0;if(!Object.is(w,i.enablingBirth)){if(Be(b,le(i.scope,i.collection)),!S&&i.scope.parent!==void 0)(p??=[]).push({scope:i.scope,collection:i.collection,history:!0})}let M=C.get(i.scope)?.rowViews?.get(i.row);if(M===void 0)continue;let k=[M];while(k.length){let O=k.pop();if(I.has(O))continue;I.add(O),T(O.scope,ze);let P=O.served.outcome.kind==="value"&&O.served.outcome.value!==void 0?oe(O.served.outcome.value):Z,F=U(n,O.scope,O.atom,i.collection);if(Ee(P,F))continue;s.push(Object.freeze({scope:O.scope,atom:O.atom,record:O,before:P,outcome:F}));let ie=[];O.inheritingChildren.forEach((ne)=>{O.scope.coordinator.recordCounter(1),ie.push(ne)});for(let ne=ie.length-1;ne>=0;ne--)k.push(ie[ne])}}if(n.rebased!==void 0)for(let[i,R]of n.rebased){let h=n.historyByCollectionScope;for(let m of R.collections){let b=le(i,m);b.rebase=R,Be(ye(m),b),(p??=[]).push({scope:i,collection:m,history:(h.get(m)?.get(i)??[]).some((y)=>y.sequence>=R.end)})}}if(n.rebased!==void 0)for(let[i,R]of n.historyByCollectionScope){if(!en(n,i))continue;for(let[h,m]of R){if(m.length===0||ee(n,h,i)!==void 0||!io(n,h,i))continue;Be(ye(i),le(h,i)),(p??=[]).push({scope:h,collection:i,history:!0})}}for(let i of g){let R=i.top;if(R===void 0)continue;let h=new Set,m=[{node:R,affected:!1}];while(m.length){let b=m.pop(),y=b.node;if(h.has(y))continue;h.add(y),T(y.scope,pe);let S=b.affected||y.affected;if(S){let M=Me(y);if(y.existing!==void 0&&(y.orderedPatch!==void 0?y.membershipChangedFromBefore:!Object.is(M,y.beforeRows)))a.push(Object.freeze({scope:y.scope,atom:y.atom,node:y,record:y.existing,rows:M}))}let w=[];y.existing?.inheritingChildren.forEach((M)=>{y.scope.coordinator.recordCounter(1);let k=S?W(M):v.get(M);if(k!==void 0&&(S||k.containsAffected))w.push(k)});for(let M of y.plannedChildren)if(S||M.containsAffected)w.push(M);for(let M=w.length-1;M>=0;M--)m.push({node:w[M],affected:S})}}for(let i of c){if(i.finalRows!==void 0)continue;if(i.parent===void 0){Me(i);continue}i.finalRows=i.beforeRows,i.membershipChangedFromBefore=!1}let un,pn=n.rebased===void 0?void 0:r?.filter((i)=>i.orderedRebuild!==void 0);if(f!==void 0&&(n.planOrder.some((i)=>f.active(i.collection))||pn?.some((i)=>f.active(i.atom)))){let i=new Map;for(let h of n.planOrder){if(!f.active(h.collection))continue;let m=C.get(h.scope)?.memberships?.get(h.collection);if(m===void 0)continue;let b=[m];while(b.length){let y=b.pop();if(y.ordered===void 0)continue;T(y.scope,_n);let S=i.get(y);if(S===void 0)i.set(y,S=new Set);S.add(h.row),y.indexedChildren?.forEach((w)=>b.push(w))}}let R=[];for(let h of pn??[]){let m=h.existing,b=m.ordered,y=new Map;h.orderedRebuild.forEach((w,M)=>y.set(w,b.nextRank+M));let S=[];for(let w of new Set([...b.entries.keys(),...h.orderedRebuild])){let M=V(m.scope,w),k=U(n,m.scope,w,m.atom);S.push({row:w,before:M.kind==="present"?M.value:void 0,after:k.kind==="present"?k.value:void 0,rank:y.get(w)})}if(S.length)R.push({scope:m.scope,collection:m.atom,changes:S})}for(let[h,m]of i){if(h.ordered===void 0)continue;if(v.get(h)?.orderedRebuild!==void 0)continue;let b=W(h),S=n.rebased!==void 0&&(b.rebase!==void 0||ve(b))?void 0:Ae(b),w=[];for(let M of m){let k=V(h.scope,M),O=U(n,h.scope,M,h.atom),P=S?.get(M)?.birth;if(Ee(k,O)&&typeof P!=="number")continue;w.push({row:M,before:k.kind==="present"?k.value:void 0,after:O.kind==="present"?O.value:void 0,rank:O.kind==="absent"?void 0:typeof P==="number"?h.ordered.nextRank+P:h.ordered.entries.get(M)?.rank})}if(w.length)R.push({scope:h.scope,collection:h.atom,changes:w})}un=f.prepare(R)}return{commit:po,indexPlan:un,orderedNodes:r,historyMarks:p,rows:Object.freeze(t),rowSettlements:Object.freeze(s),membershipInstalls:Object.freeze(c),membershipSettlements:Object.freeze(a),sources:Object.freeze([...s,...a])}},ao=(o)=>{let e=o,n=!1;for(let r of e.rowSettlements){let{record:t,before:s,outcome:c}=r;T(t.scope,vn),K(t.scope,s.kind==="absent"?xn:c.kind==="absent"?In:Hn,t.atom,l.lookupRow(t.atom))}for(let r of e.membershipSettlements)for(let[t,s]of r.node.membershipChanges??[]){let c=s.baselinePresent&&s.birth===void 0?Pn:!s.baselinePresent&&typeof s.birth==="number"?Ln:void 0;if(c!==void 0)K(r.node.scope,c,t,r.node.atom)}for(let r of e.rows){let t=r.coordinate.finalOperation;if(t!==void 0)K(r.coordinate.scope,t==="set"?En:t==="update"?Tn:t==="reset"?Nn:Dn,r.coordinate.row,r.coordinate.collection);if(!r.ownershipChanged)continue;n=!0;let{row:s,scope:c}=r.coordinate;if(r.local.kind==="none"){let v=C.get(c);if(v?.rowLocals?.delete(s),v?.ownedRows?.delete(s))T(c,Ke);if(v?.ownedRows?.size===0){if(v.ownedRows=void 0,v.rowLocals=void 0,v.liveRowViews===void 0&&v.liveMemberships===void 0)C.delete(c)}continue}let a=be(c),p=a.rowLocals;if(p===void 0)p=new WeakMap,a.rowLocals=p;let I=a.ownedRows;if(I===void 0)I=new Set,a.ownedRows=I,T(c,Mn);if(p.set(s,r.local),!I.has(s))I.add(s),T(c,On)}for(let r of e.membershipInstalls)r.installed=Pe(r.scope,r.atom,r.finalRows,r.parent!==void 0&&r.finalRows===r.beforeRows);for(let r of e.orderedNodes??[]){let t=r.existing;if(r.orderedRebuild!==void 0){let c=t.ordered,a=c.nextRank;c.entries.clear(),c.tail=void 0,c.nextRank=a;for(let p of r.orderedRebuild)c.append(p);t.snapshotDirty=!0,t.served=se(t.scope,Y,t.served.token);continue}let s=r.orderedPatch;if(!r.membershipChangedFromBefore)continue;for(let c of s.removals)t.ordered.remove(c);for(let c of s.births)t.ordered.append(c);t.snapshotDirty=!0,t.served=se(t.scope,Y,t.served.token)}if(e.membershipSettlements.length)return!0;for(let r of e.membershipInstalls)if(r.membershipChangedFromBefore)return!0;return n},fo=(o)=>{let e=o;for(let n of e.rows){if(!n.ownershipChanged)continue;let{row:r,scope:t}=n.coordinate,s=C.get(t)?.rowViews?.get(r);if(s===void 0)continue;if(n.local.kind!=="none"||t.parent===void 0)Ie(s);else $n(s,Xe(t.parent,r))}for(let n of e.membershipInstalls){let r=n.installed,t=n.parent?.existing??n.parent?.installed;if(r!==void 0&&t!==void 0)Qe(r,t)}if(e.historyMarks!==void 0)for(let{scope:n,collection:r,history:t}of e.historyMarks){let s=C.get(n)?.memberships?.get(r);if(s!==void 0)s.localHistory=t}},uo=(o)=>{let e=o;for(let r of e.rowSettlements){let{record:t,outcome:s}=r;t.served=Object.freeze({token:t.scope.createOutcomeToken(),outcome:wn(s)}),T(t.scope,gn),K(t.scope,jn,t.atom,l.lookupRow(t.atom)),t.scope.coordinator.reachSubscriptionTarget(t.scope,t.atom)}for(let r of e.membershipSettlements){let{record:t,rows:s}=r;t.served=se(t.scope,t.ordered===void 0?s:t.served.outcome.kind==="value"?t.served.outcome.value:Y),T(t.scope,kn),K(t.scope,Vn,t.atom),t.scope.coordinator.reachSubscriptionTarget(t.scope,t.atom)}let n=e.indexPlan?.publish();if(n?.length)return[...e.sources,...n];return e.sources.length?e.sources:void 0},po=function(o){if(o===0)return ao(this);if(o===1)return fo(this);return uo(this)},ho=(o)=>{let e=o;f?.dispose(e);let n=C.get(e);if(n===void 0)return;n.liveRowViews?.forEach((t)=>{Ie(t),t.inheritingChildren.clear()}),n.liveMemberships?.forEach((t)=>{Je(t),t.inheritingChildren.clear(),t.indexedChildren?.clear(),t.ordered?.entries.clear(),t.ordered=void 0,t.snapshotDirty=!1,t.served=se(t.scope,Y,t.served.token)}),n.liveRowViews?.clear(),n.liveMemberships?.clear();let r=n.ownedRows?.size??0;if(r!==0)T(e,Ke,r);n.ownedRows?.clear(),n.rowLocals=void 0,n.ownedRows=void 0,n.rowViews=void 0,n.liveRowViews=void 0,n.memberships=void 0,n.liveMemberships=void 0,C.delete(e)};return Object.freeze({installIndexes:(o)=>f??(f=o({revision:(e,n)=>{let r=re(e),t=r.queryRevisionByCollection??=new Map,s=t.get(n)??0;return t.set(n,s),s},membership:eo,value:(e,n)=>{let r=V(e,n);return r.kind==="present"?r.value:void 0},draftRows:fe,draftValue:(e,n,r)=>{let t=re(e),s=n;while(s!==void 0){let c=t.byScope.get(s)?.get(r),a=c===void 0?j(s,r):Oe(c);if(a.kind==="present")return a.value;if(a.kind==="absent")return;s=s.parent}return}})),has:(o)=>f?.has(o)===!0||l.lookupRow(o)!==void 0||l.lookupCollection(o),diagnosticName:l.lookupDiagnosticName,read:(o,e,n)=>{let r=o,t=e;if(f?.has(n))return{kind:"value",value:f.read(r,t,n)};if(l.lookupRow(n)!==void 0)return Object.freeze({kind:"value",value:an(r,t,n)});if(l.lookupCollection(n))return Object.freeze({kind:"value",value:fe(r,t,n)});throw TypeError("Unknown collection scratch source")},stage:(o,e,n,r,t,s)=>{let c=o,a=e;if(n==="set")tn(c,a,r,t,s);else if(n==="update")rn(c,a,r,t,s);else if(n==="delete")ln(c,a,r);else je(c,a,r)},scope:(o,e,n)=>{if(e===void 0){ho(o);return}if(f?.has(e))return f.scope(o,e,n);if(l.lookupRow(e)!==void 0)return Xe(o,e).served;if(!l.lookupCollection(e))return;let r=de(o,e);return X(r),r.served},plan:co,resetAll:(o,e)=>ro(o,e),stageSet:tn,stageUpdate:rn,stageDelete:ln,stageReset:je,readDraftRow:an,readDraftCollection:fe,beginMembershipRebuildTraceForTest:()=>{if(H!==void 0)throw Error("A membership rebuild trace is already active");let o=[];return H=o,()=>{if(o===void 0)throw Error("The membership rebuild trace is already finished");H=void 0;let e=Object.freeze([...o]);return o.length=0,o=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(z!==void 0)throw Error("A membership placement trace is already active");let o={coordinates:0,states:0};return z=o,()=>{if(o===void 0)throw Error("The membership placement trace is already finished");z=void 0;let e=Object.freeze({...o});return o=void 0,e}},inspectDraft:so})};var Co={ref:(l)=>new WeakRef(l),registry:(l)=>{let d=new FinalizationRegistry(l);return Object.freeze({register:(f,u,C)=>d.register(f,u,C),unregister:(f)=>d.unregister(f)})}};class Fe{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(l,d,f=Co,u){this.#o=l,this.#t=u,this.#r=d,this.#n=f.registry((C)=>{let H=C.route;if(H.entry!==C)return;H.entry=void 0,this.#d(H)}),this.#i=(C)=>f.ref(C)}#i;getOrCreateOne(l,d){return this.#s(this.#l(this.#e,l),d)}getOrCreateTuple(l,d){let f=this.#e;for(let u=0;u<l.length;u++)f=this.#l(f,l[u]);return this.#s(f,d)}get routeCount(){let l=0,d=(f)=>{if(f.children===void 0)return;for(let u of f.children.values())l++,d(u)};return d(this.#e),l}hasRoute(l){let d=this.#e;for(let f=0;f<l.length;f++){let u=d.children?.get(l[f]);if(u===void 0)return!1;d=u}return!0}#l(l,d){let f=l.children??(l.children=new Map),u=f.get(d);if(u!==void 0)return u;return u={parent:l,parentKey:d,children:void 0,entry:void 0},f.set(d,u),u}#s(l,d){let f=l.entry;if(f?.kind==="ready"){let C=f.reference.deref();if(C!==void 0)return C;if(this.#n.unregister(f),l.entry===f)l.entry=void 0}else if(f?.kind==="building"){let C=f.fault??this.#r();throw f.fault=C,C}let u={kind:"building",route:l,fault:void 0};l.entry=u;try{let C=this.#o(d);if(u.fault!==void 0)throw u.fault;this.#t?.(C);let H={kind:"ready",route:l,reference:this.#i(C)};return l.entry=H,this.#n.register(C,H,H),C}catch(C){if(l.entry===u)l.entry=void 0;throw this.#d(l),u.fault??C}}#d(l){let d=l;while(d.parent!==void 0&&d.entry===void 0&&(d.children===void 0||d.children.size===0)){let f=d.parent,u=f.children;if(u?.get(d.parentKey)!==d)return;if(u.delete(d.parentKey),u.size===0)f.children=void 0;d=f}}}var Ro=(l)=>new WeakRef(l),De,So=(l)=>{let d=xe(l),f=De??(De=new WeakMap),u=f.get(d);if(u!==void 0)return u;return u={collections:new WeakMap,rows:new WeakMap},f.set(d,u),u};class Xn 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 qe=()=>new Xn,Ze=(l)=>{if(l===null)return null;switch(typeof l){case"string":case"bigint":case"boolean":return l;case"number":if(!Number.isFinite(l))throw qe();return Object.is(l,-0)?0:l;default:throw qe()}},qn=(l)=>{throw ge(l),qe()},go=(l,d,f)=>Ue(l,"collection-encoder",(u)=>{let C;try{C=Reflect.apply(d,void 0,[u])}catch(z){let A=he(z);if(A.kind==="not-thenable")throw z;if(A.kind==="inspection-error")throw A.error;return qn(A)}let H=he(C);if(H.kind==="not-thenable")return C;if(H.kind==="inspection-error")throw H.error;return qn(H)},[f],Ze,()=>TypeError("collection encodeKey cannot call family or collection accessors")),ko=(l)=>{if(l===void 0)return{};if(typeof l!=="object"||l===null)throw TypeError("collection options must be an object");for(let u of Reflect.ownKeys(l))if(u!=="encodeKey"&&u!=="indexes"&&u!=="name")throw TypeError("collection options contain an unknown option");let d;if(Object.prototype.hasOwnProperty.call(l,"encodeKey")){let u=Reflect.get(l,"encodeKey");if(typeof u!=="function")throw TypeError("collection encodeKey must be a function");d=u}let f=Reflect.get(l,"name");return{...d===void 0?{}:{encodeKey:d},...f===void 0?{}:{name:f}}},vo=()=>TypeError("collection cannot recursively construct the same row"),Mo=()=>TypeError("presence requires a same-domain CollectionRow"),Oo=(l,d)=>{let f=De?.get(xe(l));if(typeof d==="object"&&d!==null||typeof d==="function"){let u=f?.rows.get(d);if(u!==void 0)return u}throw Ye(l,d),Mo()};function Ao(l,d,f){Yn(l);let{encodeKey:u,name:C}=ko(d),H;if(d!==void 0&&Object.prototype.hasOwnProperty.call(d,"indexes")){let j=Reflect.get(d,"indexes");if(typeof j!=="object"||j===null||Array.isArray(j))throw TypeError("collection indexes must be an extractor map");let V=Reflect.ownKeys(j).map((Q)=>{let te=Reflect.get(j,Q);if(typeof Q!=="string"||typeof te!=="function")throw TypeError("collection indexes must be named scalar extractors");return[Q,te]});if(V.length)H=Object.freeze(Object.fromEntries(V))}let z=[],A,T=Object.assign(function(V){Ge(l);let Q=u===void 0?Ze(V):go(l,u,V);z[0]=Q;try{return A.rows.getOrCreateOne(Q,z)}finally{z.pop()}},{kind:"collection"}),K=We(l,T),B,be=new Fe((j)=>{let V=j[0];return We(l,{kind:"collection-row",key:V})},vo,f,(j)=>{if(B===void 0)throw Error("Collection definition registry is not ready");B.rows.set(j,{definition:A,presence:void 0})});return A=Object.freeze({collection:K,indexes:H,...C===void 0?{}:{name:C},rows:be,referencePresence:f===void 0?Ro:(j)=>f.ref(j)}),B=So(l),B.collections.set(K,A),Gn(l,(j)=>Wn({lookupRow:(V)=>B.rows.get(V)?.definition.collection,lookupCollection:(V)=>B.collections.has(V),lookupDiagnosticName:(V)=>B.rows.get(V)?.definition?.name??B.collections.get(V)?.name,runGuarded:(V,Q)=>Un(j,V,Q),inspectThenable:he,containThenable:ge})),K}var _o=(l,d)=>{Ge(l);let f=Oo(l,d),u=f.presence?.deref();if(u!==void 0)return u;let C=Zn(l,(H)=>H(d)!==void 0);return f.presence=f.definition.referencePresence(C),C},zo=(l,d,f)=>{let u=De?.get(xe(l))?.collections.get(d);if(u===void 0)throw Ye(l,d),TypeError("query requires a same-domain Collection");let C=u.indexes!==void 0&&Object.prototype.hasOwnProperty.call(u.indexes,f)?u.indexes[f]:void 0;if(C===void 0)throw TypeError("query requires a declared equality index");return(H)=>Ue(l,"collection-encoder",(z)=>{let A;try{A=C(z)}catch(K){let B=he(K);if(B.kind==="thenable")throw ge(B),TypeError("Index extractors must return a synchronous scalar");if(B.kind==="inspection-error")throw B.error;throw K}let T=he(A);if(T.kind==="thenable")throw ge(T),TypeError("Index extractors must return a synchronous scalar");if(T.kind==="inspection-error")throw T.error;return Ze(A)},[H])};
|
|
2
2
|
export{Fe as a,zn as b,Kn as c,Fn as d,Xn as e,Ao as f,_o as g,zo as h};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{La as e,Na as r}from"../chunk-
|
|
1
|
+
import{La as e,Na as r}from"../chunk-4wpe8fhf.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 q extends Error{#t=!0;static is(e){return typeof e==="object"&&e!==null&&#t in e}seal(){Object.freeze(this)}}var Q,yt=()=>{if(Q!==void 0)return Q;Q="";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 Q="accessor",Q}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)Q="lazy"}catch{}return Q},dn={writable:!1,configurable:!1},bt=(e,t)=>{if(yt()!=="lazy"){Object.freeze(e);return}for(let n of["message","code","name",t,"cause"])Object.defineProperty(e,n,dn);Object.preventExtensions(e)},Te=(e,t,n)=>{let o=yt()==="accessor"&&q.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 ne extends q{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;name="SelectorGetterError";constructor(e,t){super("Selector getter failed");this.selector=e,this.cause=t,bt(this,"selector")}}class Ce extends q{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;name="SelectorDependencyError";constructor(e,t){super("Selector dependency failed");this.dependency=e,this.cause=t,bt(this,"dependency")}}class le extends q{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 Y extends q{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 Ye extends q{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class Oe extends q{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 Qe extends q{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var z=Symbol(),K=Symbol(),Ee=Symbol(),x=Symbol(),Xe=(e,t)=>e.kind===t.kind&&(e.kind==="value"?Object.is(e.value,t.value):Object.is(e.error,t.error)),At=Object.freeze({kind:"not-thenable"}),cn=()=>{},ln=Reflect.apply,vt=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}var gt=new WeakSet,Mn=(e)=>gt.has(e);class $e extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ze extends T{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 re extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Ne extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Je extends T{code="VALDRES_SETTLE_LIMIT";constructor(){super("Store updates did not settle");this.name="SettleLimitError",this.seal()}}class De extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class xe extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class ue extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class fe extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class he extends T{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class pe extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class et extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class tt extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class Pe extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var P=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return At;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):At}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{ln(e.then,e.target,[void 0,cn])}catch{}},Se=(e)=>{let t=P(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 j(t),Object.freeze({kind:"error",error:new fe})},nt=(e)=>{try{return Se(e())}catch(t){let n=P(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 j(n),Object.freeze({kind:"error",error:new fe})}},me=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},U=(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 me(e,i,n)}finally{let s=t.getControlFault();if(s.kind==="fault")throw e.externalRuntime?.guard(s.error),s.error}},kt=(e,t,n)=>{try{return me(e,Object.freeze({kind:"subscriber",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},je=(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 me(e,s,n)},wt=(e,t,n)=>me(e,Object.freeze({kind:"transaction",transaction:t}),n),ye=(e,t,n)=>{try{return me(e,Object.freeze({kind:"transaction-result",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},Rt=(e)=>{let t=new re;throw e.externalRuntime?.guard(t),t},H=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Ne(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new De;Rt(e)},Ve=(e,t)=>{if(e.activity?.kind==="subscriber")return e.activity.session;H(e,t)},Tt=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new re;throw e.latchControlFault(r),t.latchControlFault(r),r},Ct=(e)=>{Ve(e,"Store unsubscribe")},ie=(e,t,n)=>{if(!n)throw new xe;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Ne("Transaction cursor operation");if(o?.kind==="guarded-callback"||o?.kind.startsWith("external-"))Rt(e);throw new De},Ot=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},oe=(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,vt);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new $e;throw gt.add(r),Ot(e,n).latchControlFault(r),r}}return"invalid"},_=(e,t,n)=>{if(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t))return"local";let o=e.activity,r=Ot(e,n);if(o!==void 0&&"session"in o)try{return oe(e,t,r)}finally{let i=r.getControlFault();if(i.kind==="fault")throw i.error}return U(e,r,()=>oe(e,t,r))},be=(e,t)=>(Object.defineProperty(e,vt,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),se=(e)=>{let t=e[K];if(t===void 0||t.allowDefinitions)return;let n=t.session.getControlFault();if(n.kind==="fault")throw n.error;let o=new re;throw t.session.latchControlFault(o),o},Ie=(e)=>({kind:e}),Ae=(e,t)=>{se(e);let n=e[K],o=Object.freeze(be(t,e.ownerToken));return e.states.add(o),n?.definitions?.add(o),o};var g,X=0,Me,ve=!1,xt=1024,Fe=xt,ze,Et=(e)=>{setTimeout(()=>{throw e},0)},Nt=(e)=>{let t=(n)=>Et(AggregateError([e,n],"Commit callback and error reporter failed"));try{let n=globalThis.reportError;if(typeof n!=="function")return Et(e);let o=n.call(globalThis,e);if(o!==null&&(typeof o==="object"||typeof o==="function"))Promise.prototype.then.call(Promise.resolve(o),void 0,t)}catch(n){t(n)}},un=()=>{if(ve||g===void 0)return;let e=()=>{if(Me!==e)return;Me=void 0,Pt()};Me=e,queueMicrotask(e)},Dt=()=>{let e=ze??={};setTimeout(()=>{if(ze!==e||ve)return;ze=void 0,Fe=xt,Pt()},0)},Pt=()=>{if(ve||g===void 0)return;if(Me=void 0,ze===void 0)Dt();ve=!0;try{while(g!==void 0&&X<g.length&&Fe>0){let e=g[X];if(g[X++]=void 0,Fe--,e===void 0||e.scope.status!=="live")continue;try{let t=e.callback,n=t();if(n!==null&&(typeof n==="object"||typeof n==="function"))Promise.prototype.then.call(Promise.resolve(n),void 0,Nt)}catch(t){Nt(t)}}}finally{if(ve=!1,g!==void 0&&X===g.length)g=void 0;else if(g!==void 0)g.splice(0,X);if(X=0,g!==void 0&&Fe===0)Dt()}},_e=(e)=>{let t=e.commitEntries;if(t===void 0)return;if(e.commitEntries=void 0,g===void 0)g=t;else for(let n of t)g.push(n);un()},jt=()=>{if(g===void 0)return;for(let e=X;e<g.length;e++)if(g[e]?.scope.status!=="live")g[e]=void 0};var Vt=Object.freeze({kind:"not-thenable"}),fn=()=>{},hn=Reflect.apply,It=Symbol("selector dependency path root"),zt=(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})}},_t=(e)=>{try{hn(e.then,e.target,[void 0,fn])}catch{}},pn=(e)=>Object.freeze(e),Sn=(e)=>Object.freeze(e),V=(e,t,n,o)=>{let r=Sn(o);return Object.freeze({selector:e,token:t,outcome:pn(n),dependencies:r,attemptedPrefix:n.kind==="value"?mn:Object.freeze(r.map((i)=>i.node))})},mn=Object.freeze([]),Be=32,ae=8192,yn=2*Be,Bt=128,bn=4096;class Lt{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(ae,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>=Be&&e.size<=ae,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>ae){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>=Be&&e.size<=ae;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,Be),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=yn){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(ae,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>ae||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 An=(e,t)=>new Lt(e,t),Z=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=Bt-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},vn=(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:Bt},c=[t],l=new Set(c),f=0,u=0,p=1;while(c.length>0){if(d.remaining===0)return Z("budget-exhausted",d,f,u,p,r);d.remaining--,f++;let h=c.pop();if(Object.is(h,e))return Z("path-possible",d,f,u,p,r);let m=!1,b=(C)=>{if(u++,Object.is(C,e))return m=!0,!1;if(!l.has(C)){if(l.add(C),c.push(C),c.length>p)p=c.length}return!0},D=a.call(n,h,d,b);if(m)return Z("path-possible",d,f,u,p,r);if(!D)return Z("budget-exhausted",d,f,u,p,r);let M=s?.get(h);if(M!==void 0)for(let C of M){if(d.remaining===0)return Z("budget-exhausted",d,f,u,p,r);if(d.remaining--,!b(C))return Z("path-possible",d,f,u,p,r)}}return Z("proven-reverse",d,f,u,p,r)},gn=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let u=vn(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,It]]);while(l.length>0){let u=l.pop();if(Object.is(u,t)){let m=[],b=u;while(b!==It)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},Mt=(e,t)=>{let n=zt(e);if(n.kind==="thenable")return _t(n),new Y(t);if(n.kind==="inspection-error")return n.error;return e},Ft=(e,t)=>{let n=zt(e);if(n.kind==="thenable")return _t(n),Object.freeze({kind:"error",error:new Y(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Ht=(e,t,n,o=gn,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(),D=n.getSelectorGraphPublicationCount(t),M=b,C=D,ft=b,ht=D,He,We=!1,Ge=b,ke=0,J,pt=b,we,qe=(S,y)=>{if(S===Ge)return;if(Ge=S,J===void 0){ke=0;return}if(J.advanceGraphVersion(y))return;ke=0,r?.graphVersionReset()},rn=(S)=>{if(S!==Ge)qe(S,void 0);if(ke++,(c?.length??0)===0&&ke<3){r?.admissionSkipped();return}if(J===void 0){let y=c!==void 0&&c.length>0&&c.length<3;J=An(y?3:0,r)}if(!J.enabled){r?.disabled();return}return J},sn=(S)=>{if(We)return;let y=t.beginSelectorGraphObservation?.(S);if(y===void 0)return;We=!0,He=y},Ke=(S,y,O,k)=>O-S===k-y,St=(S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t),O=Ke(M,C,S,y))=>{if(S===M)return;if(!We&&t.beginSelectorGraphObservation!==void 0){qe(S,void 0),M=S,C=y;return}let k=He?.takeAddedEdges();if(qe(S,k),O){M=S,C=y;return}if(k!==void 0){let N=k.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,bn,i),F=k.length===0?void 0:{transientDependents:N,reverseProofEnabled:!0},E=!1;for(let W of k)if(o(W.head,W.tail,t,n,2,a.length,void 0,F)!==void 0){E=!0;break}if(!E){M=S,C=y;return}}for(let N=0;N<a.length;N++){let F=a[N],E=o(F.node,s,t,n,0,a.length);if(!E)continue;if(l!==void 0)for(let B=a.length-1;B>=N;B--)l.delete(a[B].node);if(a.length=N,u++,n.getControlFault().kind==="fault")return;let R=new le(s,[s,...E]);n.latchCycle(t,s,R);return}M=S,C=y},Ue=()=>{let S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t);ft=S,ht=y;let O=Ke(M,C,S,y);if(!O)n.revalidateAncestorPrefixes(t,s);St(S,y,O)};n.setPrefixRevalidator(t,s,St);let an=(S)=>{if(!h)throw new Qe;let y=n.getControlFaultForSuppliedRead();if(y.kind==="fault")throw y.error;let O=n.getCycle(t,s);if(O!==void 0)throw O;let k=n.activeCyclePath(t,S);if(k){let v=new le(s,k);throw n.latchCycle(t,s,v),v}let N=a.length,F,E=!1;if(l===void 0){let v=c?.[N];if(v!==void 0&&Object.is(v.node,S))F=!1,E=!0;else F=m().has(S)}else F=l.has(S);if(!F&&!E&&c!==void 0&&c.length>0){let v=c[a.length];if(v!==void 0&&Object.is(v.node,S))E=!0;else{if(f===void 0){f=new Set;for(let te of c)f.add(te.node)}E=f.has(S)}}let W=u,R=t.serve(S,n);Ue();let B=n.getCycle(t,s);if(B!==void 0)throw B;let de=l!==void 0?l.has(S):u===W&&a.length===N?!1:m().has(S),G=ft,ee=ht,L=de||E&&G===b,Re=c===void 0&&Ke(b,D,G,ee);if(!L&&!Re){if(pt=G,we===void 0)we=()=>rn(pt),we.reverseProofEnabled=!0;let v=o(S,s,t,n,1,a.length,we);if(v){let te=n.getControlFault();if(te.kind==="fault")throw te.error;let mt=new le(s,[s,...v]);throw n.latchCycle(t,s,mt),mt}}if(!de){let v=d?.dependencies[a.length];l?.add(S),a.push(v!==void 0&&Object.is(v.node,S)&&Object.is(v.token,R.token)?v:Object.freeze({node:S,token:R.token})),sn(S)}if(M=G,C=ee,R.outcome.kind==="control-error"){n.latchControlFault(R.outcome.error,R.outcome.origin);let v=n.getControlFault();if(v.kind==="fault")throw v.error;throw R.outcome.error}let ce=n.getControlFault();if(ce.kind==="fault")throw ce.error;if(R.outcome.kind==="error")throw Te(Ce,S,R.outcome.error)??new Ce(S,R.outcome.error);return R.outcome.value};try{let S,y,O=!1;try{S=e.get(an)}catch(B){O=!0,y=B}finally{h=!1}if(O)y=Mt(y,"getter");let k=O?void 0:Ft(S,"getter");Ue();let N=n.getControlFault();if(N.kind==="fault")return V(s,t.createOutcomeToken(),{...N,kind:"control-error"},a);let F=n.getCycle(t,s);if(F!==void 0)return V(s,t.createOutcomeToken(),{kind:"error",error:F},a);if(O)return V(s,t.createOutcomeToken(),{kind:"error",error:y instanceof Y?y:Te(ne,s,y)??new ne(s,y)},a);if(k===void 0)throw Error("Selector result classification was not completed");let E=n.getControlFault();if(E.kind==="fault")return V(s,t.createOutcomeToken(),{...E,kind:"control-error"},a);if(k.kind==="error")return V(s,t.createOutcomeToken(),{kind:"error",error:k.error instanceof Y?k.error:Te(ne,s,k.error)??new ne(s,k.error)},a);let W=k.value,R;if(p){let B=e.equal??Object.is,de,G,ee=!1;try{de=B(p.value,W)}catch(te){ee=!0,G=Mt(te,"comparator")}let L=ee?void 0:Ft(de,"comparator");Ue();let Re=n.getControlFault();if(Re.kind==="fault")return V(s,t.createOutcomeToken(),{...Re,kind:"control-error"},a);let ce=n.getCycle(t,s);if(ce!==void 0)return V(s,t.createOutcomeToken(),{kind:"error",error:ce},a);if(ee)return V(s,t.createOutcomeToken(),{kind:"error",error:G instanceof Y?G:new Oe(s,G)},a);if(L===void 0)throw Error("Selector comparator classification was not completed");let v=n.getControlFault();if(v.kind==="fault")return V(s,t.createOutcomeToken(),{...v,kind:"control-error"},a);if(L.kind==="error")return V(s,t.createOutcomeToken(),{kind:"error",error:L.error instanceof Y?L.error:new Oe(s,L.error)},a);if(L.value!==!0&&L.value!==!1)return V(s,t.createOutcomeToken(),{kind:"error",error:new Ye},a);if(L.value===!0)W=p.value,R=p.current?p.token:void 0}return V(s,R??t.createOutcomeToken(),{kind:"value",value:W},a)}finally{try{He?.close()}finally{n.leave(t,s)}}};class A{#t=[];#e;#o;#c=0;#r;#s=kn;#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 kn=Object.freeze({kind:"none"});var Wt=Symbol("no-committed-selector-baseline");class ot{#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)??Wt,this.#c.set(e,t);return t===Wt?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 Gt=4096,wn=Object.freeze([]);class qt{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 it{scope;onSwept;#t=new WeakMap;#e=new Set;#o=64;constructor(e,t){this.scope=e;this.onSwept=t}add(e){if(this.#t.has(e))return!1;let t=new WeakRef(e);if(this.#t.set(e,t),this.#e.add(t),this.#e.size>=this.#o)this.sweep();return!0}sweep(){let e=0;for(let t of this.#e){let n=t.deref();if(n!==void 0&&this.scope.atomOverrides.has(n))continue;if(n!==void 0)this.#t.delete(n);this.#e.delete(t),e++}if(this.#o=Math.max(64,this.#e.size*2),e!==0)this.onSwept?.(e);return e}collect(e){let t=0;for(let n of this.#e){let o=n.deref();if(o!==void 0){e.push(o);continue}this.#e.delete(n),t++}if(t!==0)this.onSwept?.(t)}}class Le{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;ownedAtoms;#t=new WeakMap;#e;#o=new WeakMap;#c;#r=new WeakMap;#s=new WeakSet;#u;#a=0;#i=0;#l;#f=!1;#m;#S="live";constructor(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[x]?.scope(this),this.#e.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#e.clear(),this.atomOverrides=new WeakMap,this.ownedAtoms=void 0,this[z]?.release(this.coordinator),this[z]=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(oe(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[x]?.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=je(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 wn;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??rt},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??rt,t.dependencies),a=s?this.#A(e,o?.dependencies??rt,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=Gt-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>Gt){this.#p();return}t.push(...e)}#p(){if(this.#i===0)return;this.#l=[],this.#f=!0}#d(){return new qt(this.coordinator.instrumented?()=>this.coordinator.recordCounter(2):void 0)}}var rt=Object.freeze([]);class st{commitEntries;transaction=Object.freeze({});onAllocation;#t;#e;#o;#c;#r;#s;#u;#a;#i;#l;#f;#m;#S;#h;#b;#y;externalCaptures;#A;#v=!1;generation=0;active=!0;constructor(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(){this.commitEntries=void 0;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 Kt{constructor(e,t,n){this.onCommit=(o)=>e.registerCommit(t,n,o),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.resetAll=function(){e.resetAll(t,n,arguments.length)},this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),be(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var at=(e,t,n)=>new Kt(e,t,n),dt=(e)=>{let t=P(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new ue},Ut=(e)=>{let t=P(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new ue};var Rn=64,Tn=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},w=Symbol("definition domain records"),to=(e)=>e[w].ownerToken,no=(e)=>e[w],oo=(e,t)=>{let n=e[w],o=n[x];if(o!==void 0)return o;let r=t(n);return n[x]=r,r},ro=(e)=>e[w][x],Cn=Object.freeze([]),io=(e,t,n,o,r,i)=>{let s=e[w],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[K];s[K]={session:a,definitions:f?new WeakSet:void 0,allowDefinitions:f,...i===void 0?{}:{createAccessorFault:i}};let p=l.length===0?Cn:l.map((h)=>Object.freeze({selectorSession:h,previous:h.setSuppliedReadGuard(()=>{let m=s.activity;return Tt(m?.kind==="guarded-callback"?m.session:a,h)})}));try{return U(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[K];else s[K]=u}},On=(e)=>{let t=e[w][K];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 re:t.accessorFault??=t.createAccessorFault();throw t.session.latchControlFault(o),o},so=(e)=>se(e[w]),ao=On,co=(e,t)=>Ae(e[w],t),lo=(e,t)=>_(e[w],t,new A),uo=(e,t)=>{let n=e[w];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[K]?.definitions?.has(t)||n[Ee]?.has(t))return t;return}_(n,t,new A);return};class Xt extends Set{release(e){e.recordCounter(34,this.size)}}class $t extends WeakSet{apply(e,{atom:t,kind:n}){let o=e[z];if(n==="set"){if(!this.has(t))return!1;if(o===void 0)o=e[z]=new Xt,e.coordinator.recordCounter(32);let r=o.size;if(o.add(t),o.size!==r)e.coordinator.recordCounter(33);return!0}else{if(o?.delete(t))e.coordinator.recordCounter(34);if(o?.size===0)e[z]=void 0;return!1}}}var fo=(e,t)=>{let n=e[w];if((n[Ee]??(n[Ee]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[z]??(n[z]=new $t)).add(t)},Zt=new WeakMap,ho=()=>{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,ownedAtomRetains:51,ownedAtomSweptReferences:52}),t=53,n=new Uint32Array(53),o=Object.freeze({read(r){return n[e[r]]??0}});return Zt.set(o,(r,i)=>{n[r]+=i}),o},I=(e)=>Object.freeze({kind:"value",value:e}),En=(e)=>Object.freeze({kind:"error",error:e}),Yt=(e)=>e.kind==="value"?I(e.value):En(e.error),ge=(e,t)=>e[x]?.has(t)?e[x]:void 0,Jt=(e,t,n,o)=>{let r=e.read(t,n,o);if(r.kind!=="value")throw r.error;return r.value};var Nn=(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}),lt=(e)=>(e.onAllocation?.(),new Map),Dn=(e)=>(e.onAllocation?.(),new Set),ct=(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)},Qt=(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=lt(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=lt(e),r.set(t,i);i.set(n,o)},xn=(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=Dn(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Pn=(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=lt(e),e.affected=o;o.set(t,n)};class en{#t=new WeakMap;#e;#o;#c;subscriberReading=!1;#r;#s=1;sourceEpoch=0;#u=!1;#a;#i;#l;#f=0;#m;#S;#h;#b=1;#y=0;#A;#v;#p;#d=0;#T;#N;#D=!1;settlementEpoch=0;#n;#C;#w;evaluate;constructor(e,t,n){this.#n=e,this.#C=t===void 0?void 0:Zt.get(t),this.#w=n,this.evaluate=n?.evaluate??Ht,this.#r=new Le(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 st(this.instrumented?()=>this.recordCounter(18):void 0)}get(e,t){let n=new A,o=t,r=_(this.#n,o,n),i=Ve(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.#U(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}#U(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":_(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)&&!ge(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),Tn(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(Ct(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)_(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(H(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.#X(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(jt(),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=at(this,n,e),r=wt(this.#n,n.transaction,()=>t(o));n.close();let i=new A;return ye(this.#n,i,()=>dt(r)),this.#_(n),r}finally{n.close(),n.release()}}registerCommit(e,t,n){if(ie(this.#n,e.transaction,e.active),this.#g(t),typeof n!=="function")throw TypeError("Transaction.onCommit requires a function");(e.commitEntries??=[]).push({scope:t,callback:n})}get fallbackRecords(){return this.#t}transactionGet(e,t,n){let o=n,r=new A,i=_(this.#n,o,r);if(ie(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=ge(this.#n,o);if(!a)throw TypeError("Transaction.get requires a readable State");return Jt(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=_(this.#n,i,s);if(e===void 0)H(this.#n,a);else ie(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=ge(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.#$(h,t,i,r,s);else if(n==="update")this.#Z(h,t,i,r,s,a);else this.#J(h,t,i,s);if(!p)return;h.close(),this.#_(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")_(this.#n,n,i);ie(this.#n,e.transaction,e.active),this.#g(t);let s=this.#Q(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=at(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 ye(this.#n,f,()=>Ut(l))}let c=new A;return ye(this.#n,c,()=>dt(d)),d}createOutcomeToken(){return Object.freeze({id:this.#s++})}createScratchSelectorHost(e,t,n=!1){return this.recordCounter(3),new ot(Object.freeze({trackPath:n,resolve:(o,r)=>this.#Y(o,r),read:(o,r,i,s)=>this.#ee(e,t,o,r,i,s),baseline:n?()=>{return}:(o)=>t.captureCommittedSelectorSuccess(o),run:(o,r)=>je(this.#n,o,r)}),e.generation,this.evaluate)}#Y(e,t){if(oe(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(ge(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 Le(this,e,t);this.recordCounter(7);let o=new ut(this,n,this.#w);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Q(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new et;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 tt;return i}let r=this.#n.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new xe;throw new Pe}throw new Pe}#g(e,t){if(t!==void 0)H(this.#n,t);if(e.status!=="live")throw new pe}#X(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)}#$(e,t,n,o,r){let i=U(this.#n,r,()=>Se(o));if(i.kind==="error")throw i.error;let s=this.#x(e,t,n,r);this.#K(e,t,n,i.value,s,r)}#Z(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.#oe(o,a.value,r);this.#K(e,t,n,d,s,r)}#J(e,t,n,o){e.stage(t,this.#F(e,t,n,o))}#F(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.#z(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);return Object.freeze({kind:"reset",atom:n,publishDraftFallback:i})}resetAll(e,t,n){if(ie(this.#n,e.transaction,e.active),this.#g(t),n!==0)throw TypeError("Transaction.resetAll accepts no arguments");if(t.parent===void 0)throw TypeError("Transaction.resetAll requires a child scope cursor");let o=[];t.ownedAtoms?.collect(o),t[z]?.forEach((a)=>o.push(a)),e.forEachIntent((a,d)=>{if(Object.is(a,t))o.push(d.atom)});let r=new A,i=[],s=new Set;for(let a of o){if(s.has(a))continue;s.add(a);let d=e.getIntent(t,a);if(d===void 0){if(!t.atomOverrides.has(a))continue}else if(d.kind==="reset")continue;i.push(this.#F(e,t,a,r))}for(let a of i)e.stage(t,a);this.#n[x]?.resetAll?.(e,t)}#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=I(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.#z(e,t,n,o).outcome}#ee(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[x].read(e,t,n)}#z(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:I(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:I(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.#O(t);if(r.fallback.kind==="eager")return I(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=Yt(U(this.#n,n,()=>nt(i)));return e.setFallback(t,a),a}#te(e,t,n,o){let r=this.#O(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#ne(r,t,n,o)?t:n}#ne(e,t,n,o){return U(this.#n,o,()=>{let r;try{r=e(t,n)}catch(s){let a=P(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw j(a),new he}let i=P(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw j(i),new he;if(r!==!0&&r!==!1)throw new he;return r})}#oe(e,t,n){return U(this.#n,n,()=>{let o;try{o=e(t)}catch(i){let s=P(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw j(s),new fe}let r=Se(o);if(r.kind==="error")throw r.error;return r.value})}#_(e){this.#R(2);let t;if(e.hasRows){if(t=this.#n[x]?.plan(e),t===void 0)throw Error()}if(!e.hasIntents&&t===void 0){_e(e);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){_e(e);return}let r=Nn(this.instrumented?()=>this.recordCounter(19):void 0),i,s;if(n!==void 0&&o!==void 0)i=this.#B(e,o,n,r);else e.forEachIntent((c,l)=>{let f=this.#B(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.#L(e,i);if(s!==void 0)for(let c of s)this.#L(e,c);let a=i===void 0?!1:this.#H(i);if(s!==void 0)for(let c of s){let l=this.#H(c);a||=l}if(t!==void 0){let c=t.commit(0);a||=c}if(_e(e),i!==void 0)this.#W(i);if(s!==void 0)for(let c of s)this.#W(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.#j(r,f,u);let{secondAffectedRecord:p,secondAffectedBefore:h}=r;if(p!==void 0&&h!==void 0){let m=this.#j(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 D=this.#j(r,m,b);if(D===void 0)continue;if(c===void 0)c=D;else{if(l===void 0)l=[];l.push(D)}}if(t!==void 0){let m=t.commit(2);if(m!==void 0)for(let b of m){let D=b;if(c===void 0)c=D;else{if(l===void 0)l=[];l.push(D)}}}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.#T??={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}}#B(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.#ie(e,s,o);return i}#L(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)}#H(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);let o=this.#n[z]?.apply(n,t);if(n.parent!==void 0&&o!==!0){if(t.kind==="set"&&(n.ownedAtoms??this.#re(n)).add(t.atom))this.recordCounter(51)}return e.ownershipChanged}#re(e){return e.ownedAtoms=new it(e,this.#C===void 0?void 0:(t)=>this.recordCounter(52,t))}#W({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.#de(e.parent,t.atom))}#j(e,t,n){let o=ct(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter(16),Xe(n,o))return;return t.scope.updateAtomView(t,o),t}#ie(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!xn(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(Xe(i,s))continue;Pn(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=ct(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=ct(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=I(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=I(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#se(e,n),s!==void 0)Qt(o,n,s,d),this.recordCounter(17);if(a!==void 0)for(let c of a)Qt(o,n,c,d),this.recordCounter(17);return d}#se(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.#O(t);if(r.fallback.kind==="eager")return I(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ae(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#O(e);if(n.fallback.kind==="eager")return I(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#de(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,I(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ae(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,I(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#ce(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}#ce(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#O(e);if(o.fallback.kind==="eager")return I(o.fallback.value);let r=o.fallback.initialize,i=Yt(U(this.#n,t,()=>nt(r)));return this.#t.set(e,i),this.recordCounter(13),i}#O(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.#V(u,p)}catch(h){if(o)this.#T??={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.#le(i),a=this.#he(),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 Ze(d===void 0?c:[d,...c]);throw this.#e?.notificationFailure(l)??l}finally{if(!o)this.#S=void 0}}#le(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===Rn){(e??=[]).push(new Je);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.#ue(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}#ue(e,t){let n;this.#d++;try{this.#w?.(3,e),this.#I(e,t),n=this.#T}catch(o){let r=o;try{ye(this.#n,new A,()=>{let i=P(o);if(i.kind==="thenable")j(i)})}catch(i){r=i}n={error:r}}finally{this.#d--,this.#T=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.#fe(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)}#fe(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}}#he(){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{kt(this.#n,c,()=>{let l;try{if(l=P(d()),l.kind==="thenable")j(l)}catch(f){let u=P(f);if(u.kind==="thenable")j(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.#T??={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.#q(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.#V(e,t,n)}#V(e,t,n){let o=this.#q(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.#V(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)}}#q(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)}#K(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#te(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 jn=(e,t)=>{let n=e.coordinator,o=new A,r=t,i=_(n.runtimeDomain,r,o);if(H(n.runtimeDomain,"adapter readHydrationSnapshot"),e.status!=="live")throw new pe;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=ge(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 Jt(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 ut{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),be(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter(8),n?.(0,this,t),Object.freeze(this)}}var tn=(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}}},nn=()=>{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({[w]:e})},po=(e,t,n={})=>{let o=e[w];se(o);let r=new A,i=U(o,r,()=>Se(t));if(i.kind==="error")throw i.error;let s=Ae(o,Ie("atom"));return o.atoms.set(s,Object.freeze({fallback:Object.freeze({kind:"eager",value:i.value}),...tn(n)})),s},So=(e,t,n={})=>{let o=e[w];if(se(o),typeof t!=="function")throw TypeError("atomLazy requires an initializer function");let r=Ae(o,Ie("atom"));return o.atoms.set(r,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:t}),...tn(n)})),r},mo=(e,t,n={})=>{let o=e[w];if(se(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=Ae(o,Ie("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},yo=(e)=>{let t=e[w],n=(i)=>{let s=new A;if(_(t,i,s)==="invalid")return;return t.stores.get(i)};return Object.freeze({assertStore:(i)=>{let s=n(i);if(H(t,"adapter assertStore"),s===void 0)throw TypeError("assertStore requires a valid Store");if(s.status!=="live")throw new pe},read:(i,s)=>{if(n(i)===void 0)throw Ve(t,"adapter read"),TypeError("read requires a valid Store");return i.get(s)},subscribe:(i,s,a)=>{if(n(i)===void 0)throw H(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 H(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return jn(a,s)}})},on=(e,t,n)=>{let o=e[w];H(o,"createStoreTree");let r=new en(o,t,n);return new ut(r,r.rootScope,n)};var Vn=nn(),vo=(e,t)=>on(Vn,e,t);
|
|
2
|
+
export{le as S,vn as T,Ht as U,A as V,x as W,Xe as X,Mn as Y,$e as Z,Ze as _,re as $,Ne as aa,Je as ba,De as ca,xe as da,ue as ea,fe as fa,he as ga,pe as ha,et as ia,tt as ja,Pe as ka,P as la,j as ma,me as na,U as oa,Rt as pa,Tt as qa,se as ra,Ie as sa,Ae as ta,qt as ua,to as va,no as wa,oo as xa,ro as ya,io as za,On as Aa,so as Ba,ao as Ca,co as Da,lo as Ea,uo as Fa,fo as Ga,ho as Ha,po as Ia,So as Ja,mo as Ka,yo as La,on as Ma,Vn as Na,vo as Oa};
|