valdres 1.0.0-beta.35 → 1.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-dab744dc.js +2 -0
- package/dist/chunk-kr7hrpvx.js +2 -0
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-dab744dc.js +2 -0
- package/dist/development/chunk-kr7hrpvx.js +2 -0
- package/dist/development/index.js +1 -1
- package/dist/development/inspect.js +1 -1
- package/dist/index.js +1 -1
- package/dist/inspect.js +1 -1
- package/dist/types/index.d.ts +25 -0
- package/dist/types/inspect.d.ts +2 -2
- package/dist/types/v1-internal/collection-inspection-protocol.d.ts +29 -0
- package/dist/types/v1-internal/collection-kernel.d.ts +114 -0
- package/dist/types/v1-internal/collection.d.ts +14 -0
- package/dist/types/v1-internal/committed-store-tree/committed-store-tree.d.ts +33 -2
- package/dist/types/v1-internal/committed-store-tree/runtime-domain.d.ts +75 -10
- package/dist/types/v1-internal/committed-store-tree/scope-node.d.ts +20 -4
- package/dist/types/v1-internal/committed-store-tree/scratch-selector-host.d.ts +7 -4
- package/dist/types/v1-internal/committed-store-tree/tree-transaction.d.ts +9 -4
- package/dist/types/v1-internal/committed-store-tree/types.d.ts +67 -11
- package/dist/types/v1-internal/family.d.ts +4 -0
- package/dist/types/v1-internal/inspection.d.ts +54 -6
- package/dist/types/v1-internal/selector-evaluator/types.d.ts +6 -0
- package/dist/types/v1-internal/weak-member-cache.d.ts +38 -0
- package/dist/types/v1.d.ts +28 -1
- package/package.json +1 -1
- package/dist/chunk-y5ja7h9m.js +0 -2
- package/dist/development/chunk-y5ja7h9m.js +0 -2
package/README.md
CHANGED
|
@@ -32,6 +32,40 @@ A store also exposes `sub`, `reset`, `txn`, `scope`, and `dispose`. Store operat
|
|
|
32
32
|
|
|
33
33
|
`atom(initial, options)` and `atom.lazy(initialize, options)` create writable state. `selector(read, options)` creates synchronous derived state. Atom and selector options accept an inert diagnostic `name` and an `equal(previous, next)` comparator.
|
|
34
34
|
|
|
35
|
+
## Parameterized State identity
|
|
36
|
+
|
|
37
|
+
`family(factory)` memoizes one Atom or Selector per non-empty ordered tuple of primitive keys (`string`, `number`, `bigint`, `boolean`, `symbol`, `null`, or `undefined`). Keys use SameValueZero, so `NaN` matches `NaN` and `0` matches `-0`; tuple arity and order still matter.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { atom, family } from "valdres"
|
|
41
|
+
|
|
42
|
+
const cellValue = family((sheetId: string, row: number) => atom(""))
|
|
43
|
+
cellValue("budget", 4) === cellValue("budget", 4) // true
|
|
44
|
+
|
|
45
|
+
type Step = { readonly id: string; readonly title: string }
|
|
46
|
+
|
|
47
|
+
const stepProgress = family((step: Step) => atom(0), {
|
|
48
|
+
encodeKey: step => step.id,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
stepProgress({ id: "step-1", title: "Draft" }) ===
|
|
52
|
+
stepProgress({ id: "step-1", title: "Review" }) // true
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Structured arguments require a synchronous `encodeKey` that returns one canonical primitive key. The factory must construct and return its Atom or Selector during that member's construction, or return any member already published by a family. Returning an arbitrary pre-existing State is rejected.
|
|
56
|
+
|
|
57
|
+
The exported `FamilyKey` type names the primitive-key union for reusable APIs.
|
|
58
|
+
|
|
59
|
+
Factories and encoders are synchronous definition callbacks, not Store work. Neither may perform Store, scope, transaction, or subscription operations or borrow an active selector's `get`. Encoders also cannot construct State definitions or call a family; factories may do both. A violation throws without caching a member.
|
|
60
|
+
|
|
61
|
+
The family cache is weak. A live reference, a committed Store override for a family Atom, an active subscription, or a retained selector dependency keeps that member alive. Reset or disposal releases Store ownership, and unsubscription releases subscription ownership. After the last owner disappears, a later lookup may run the factory again.
|
|
62
|
+
|
|
63
|
+
A family is only a callable identity cache. It has no membership or enumeration API and no `delete`, `release`, `index`, Store, or collection surface.
|
|
64
|
+
|
|
65
|
+
## Keyed collections
|
|
66
|
+
|
|
67
|
+
`collection()` defines canonical keyed rows and a readonly ordered membership State. Store and Transaction `set`, `update`, `reset`, and `delete` mutate rows; `presence(row)` is a readonly Selector. Reads never insert.
|
|
68
|
+
|
|
35
69
|
## Opt-in structural equality
|
|
36
70
|
|
|
37
71
|
`Object.is` remains the default comparator. Import `deepEqual` from the separate equality entry only where structurally equal replacements should retain the previous reference and stop notifications or downstream propagation:
|
|
@@ -66,7 +100,7 @@ const report = inspect.export()
|
|
|
66
100
|
inspect.reset()
|
|
67
101
|
```
|
|
68
102
|
|
|
69
|
-
The report
|
|
103
|
+
The report links labels to opaque operation, commit, evaluation, session, and search IDs. It records selector topology/search work, collection row and membership work, related counters, and propagation/notification totals. Summary/detail rings are bounded with explicit overflow. Exports are immutable and JSON-safe; collection keys, values, callbacks, errors, and live State handles are never recorded. Labels are metadata, not identity. The core inspection schema is version 6.
|
|
70
104
|
|
|
71
105
|
Inspection adds recording and timing work only to the Store created by `createInspectableStore`. The recorder stays outside the ordinary root entry and ordinary consumer bundles remain within their existing size budget.
|
|
72
106
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{fa as e}from"../chunk-dab744dc.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class K extends Error{seal(){Object.freeze(this)}}class Ae extends K{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Me extends K{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class ae extends K{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class U extends K{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 Fe extends K{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ve extends K{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 ze extends K{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var N=Symbol(),G=Symbol(),ge=Symbol(),_=Symbol(),it=Object.freeze({kind:"not-thenable"}),Lt=()=>{},Ht=Reflect.apply,st=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}class _e extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Be extends T{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class ee extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class te extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ke extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class de extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ce extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class le 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 Le extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class He extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ge extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class we extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var x=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return it;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):it}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{Ht(e.then,e.target,[void 0,Lt])}catch{}},ue=(e)=>{let t=x(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 ce})},We=(e)=>{try{return ue(e())}catch(t){let n=x(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 ce})}},fe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},q=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,s=r===void 0?Object.freeze({kind:"guarded-callback",session:t}):Object.freeze({kind:"guarded-callback",session:t,selectorActivity:r});try{let i=fe(e,s,n),a=t.getControlFault();if(a.kind==="fault")throw a.error;return i}catch(i){let a=t.getControlFault();if(a.kind==="fault")throw a.error;throw i}},at=(e,t,n)=>{try{let o=fe(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},Re=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,s=Object.is(r?.session,t)?r?.parentSelectorActivity:r,i=s===void 0?Object.freeze({kind:"selector",session:t}):Object.freeze({kind:"selector",session:t,parentSelectorActivity:s});return fe(e,i,n)},dt=(e,t,n)=>fe(e,Object.freeze({kind:"transaction",transaction:t}),n),Te=(e,t,n)=>{try{let o=fe(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},I=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new ee(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new te;throw new W},qe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new ee(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new te;throw new W},ct=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new W;throw e.latchControlFault(r),t.latchControlFault(r),r},lt=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new ee("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new te;throw new W},Ce=(e,t,n)=>{if(!n)throw new ke;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new ee("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new te},ut=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},J=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,st);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new _e;throw ut(e,n).latchControlFault(r),r}}return"invalid"},M=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=ut(e,n);if(o!==void 0&&"session"in o)try{let s=J(e,t,r),i=r.getControlFault();if(i.kind==="fault")throw i.error;return s}catch(s){let i=r.getControlFault();if(i.kind==="fault")throw i.error;throw s}return q(e,r,()=>J(e,t,r))},he=(e,t)=>(Object.defineProperty(e,st,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),ne=(e)=>{let t=e[G];if(t===void 0||t.allowDefinitions)return;let n=t.session.getControlFault();if(n.kind==="fault")throw n.error;let o=new W;throw t.session.latchControlFault(o),o},Oe=(e)=>({kind:e}),Se=(e,t)=>{ne(e);let n=e[G],o=Object.freeze(he(t,e.ownerToken));return e.states.add(o),n?.definitions.add(o),o};var ft=Object.freeze({kind:"not-thenable"}),Gt=()=>{},Wt=Reflect.apply,ht=Symbol("selector dependency path root"),mt=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return ft;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):ft}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},yt=(e)=>{try{Wt(e.then,e.target,[void 0,Gt])}catch{}},qt=(e)=>Object.freeze(e),Kt=(e)=>Object.freeze(e),E=(e,t,n,o)=>{let r=Kt(o);return Object.freeze({selector:e,token:t,outcome:qt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Ut:Object.freeze(r.map((s)=>s.node))})},Ut=Object.freeze([]),Ne=32,oe=8192,Yt=2*Ne,bt=128,Xt=4096;class At{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(oe,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>=Ne&&e.size<=oe,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>oe){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,s=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,s);let i=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(i?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Ne&&e.size<=oe;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,Ne),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Yt){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(oe,2*o.size);let r=0;for(let s of e){let i=this.hasWithinCrossVersionBudget(o,s.tail);if(i===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!i)continue;let a=this.hasWithinCrossVersionBudget(o,s.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>oe||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 Qt=(e,t)=>new At(e,t),Y=(e,t,n,o,r,s)=>{if(s!==void 0)s.nodeVisits=n,s.dependentProbes=bt-t.remaining-n,s.liveDependents=o,s.maxFrontier=r;return e},$t=(e,t,n,o,r,s=!0,i)=>{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(i===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let p=i===void 0?void 0:o.getTransientDependencies(n,e);if(p!==void 0){if(p.length===0)return"proven-terminal"}else{let m=n.getSelectorDependencyNodes;if(m!==void 0){let y=m.call(n,e);if(y===void 0||y.length===0)return"proven-terminal"}}}if(!s)return"disabled";let d={remaining:bt},c=[t],l=new Set(c),u=0,f=0,h=1;while(c.length>0){if(d.remaining===0)return Y("budget-exhausted",d,u,f,h,r);d.remaining--,u++;let p=c.pop();if(Object.is(p,e))return Y("path-possible",d,u,f,h,r);let m=!1,y=(k)=>{if(f++,Object.is(k,e))return m=!0,!1;if(!l.has(k)){if(l.add(k),c.push(k),c.length>h)h=c.length}return!0},re=a.call(n,p,d,y);if(m)return Y("path-possible",d,u,f,h,r);if(!re)return Y("budget-exhausted",d,u,f,h,r);let P=i?.get(p);if(P!==void 0)for(let k of P){if(d.remaining===0)return Y("budget-exhausted",d,u,f,h,r);if(d.remaining--,!y(k))return Y("path-possible",d,u,f,h,r)}}return Y("proven-reverse",d,u,f,h,r)},Zt=(e,t,n,o,r,s,i,a)=>{if(r===1||r===2){let f=$t(e,t,n,o,void 0,r===1?i?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(f==="proven-terminal"||f==="proven-reverse")return;if(f==="budget-exhausted"){if(r===1&&i!==void 0)i.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=i?.(),c=d?.beginSearch()??!1,l=[e],u=new Map([[e,ht]]);while(l.length>0){let f=l.pop();if(Object.is(f,t)){let m=[],y=f;while(y!==ht)m.push(y),y=u.get(y);return m.reverse(),d?.completePositive(),Object.freeze(m)}let h=o.getTransientDependencies(n,f);if(h){if(h.length===0)continue;if(c){let m=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(m)continue}for(let m of h){if(u.has(m.node))continue;u.set(m.node,f),l.push(m.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let m=n.getSelectorDependencyNodes(f);if(m===void 0||m.length===0)continue;if(c){let y=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(y)continue}for(let y of m){if(u.has(y))continue;u.set(y,f),l.push(y)}continue}let p=n.getSelectorRecord(f);if(!p||p.dependencies.length===0)continue;if(c){let m=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(m)continue}for(let m of p.dependencies){if(u.has(m.node))continue;u.set(m.node,f),l.push(m.node)}}d?.completeNegative(u);return},St=(e,t)=>{let n=mt(e);if(n.kind==="thenable")return yt(n),new U(t);if(n.kind==="inspection-error")return n.error;return e},pt=(e,t)=>{let n=mt(e);if(n.kind==="thenable")return yt(n),Object.freeze({kind:"error",error:new U(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},vt=(e,t,n,o=Zt,r,s)=>{let{node:i}=e,a=[],d=t.getSelectorRecord(i),c=d?.dependencies,l=c===void 0?new Set:void 0,u,f=0,h=t.getComparisonBaseline(i),p=!0,m=()=>{let S=l;if(S!==void 0)return S;S=new Set;for(let b of a)S.add(b.node);return l=S,S};n.enter(t,i,a);let y=t.getSelectorGraphVersion(),re=n.getSelectorGraphPublicationCount(t),P=y,k=re,et=y,tt=re,De,Pe=!1,Ve=y,me=0,X,nt=y,ye,xe=(S,b)=>{if(S===Ve)return;if(Ve=S,X===void 0){me=0;return}if(X.advanceGraphVersion(b))return;me=0,r?.graphVersionReset()},zt=(S)=>{if(S!==Ve)xe(S,void 0);if(me++,(c?.length??0)===0&&me<3){r?.admissionSkipped();return}if(X===void 0){let b=c!==void 0&&c.length>0&&c.length<3;X=Qt(b?3:0,r)}if(!X.enabled){r?.disabled();return}return X},_t=(S)=>{if(Pe)return;let b=t.beginSelectorGraphObservation?.(S);if(b===void 0)return;Pe=!0,De=b},je=(S,b,w,g)=>w-S===g-b,ot=(S=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t),w=je(P,k,S,b))=>{if(S===P)return;if(!Pe&&t.beginSelectorGraphObservation!==void 0){xe(S,void 0),P=S,k=b;return}let g=De?.takeAddedEdges();if(xe(S,g),w){P=S,k=b;return}if(g!==void 0){let C=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,i,a.length,Xt,s),V=g.length===0?void 0:{transientDependents:C,reverseProofEnabled:!0},R=!1;for(let L of g)if(o(L.head,L.tail,t,n,2,a.length,void 0,V)!==void 0){R=!0;break}if(!R){P=S,k=b;return}}for(let C=0;C<a.length;C++){let V=a[C],R=o(V.node,i,t,n,0,a.length);if(!R)continue;if(l!==void 0)for(let F=a.length-1;F>=C;F--)l.delete(a[F].node);if(a.length=C,f++,n.getControlFault().kind==="fault")return;let O=new ae(i,[i,...R]);n.latchCycle(t,i,O);return}P=S,k=b},Ie=()=>{let S=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t);et=S,tt=b;let w=je(P,k,S,b);if(!w)n.revalidateAncestorPrefixes(t,i);ot(S,b,w)};n.setPrefixRevalidator(t,i,ot);let Bt=(S)=>{if(!p)throw new ze;let b=n.getControlFaultForSuppliedRead();if(b.kind==="fault")throw b.error;let w=n.getCycle(t,i);if(w!==void 0)throw w;let g=n.activeCyclePath(t,S);if(g){let A=new ae(i,g);throw n.latchCycle(t,i,A),A}let C=a.length,V,R=!1;if(l===void 0){let A=c?.[C];if(A!==void 0&&Object.is(A.node,S))V=!1,R=!0;else V=m().has(S)}else V=l.has(S);if(!V&&!R&&c!==void 0&&c.length>0){let A=c[a.length];if(A!==void 0&&Object.is(A.node,S))R=!0;else{if(u===void 0){u=new Set;for(let Z of c)u.add(Z.node)}R=u.has(S)}}let L=f,O=t.serve(S,n);Ie();let F=n.getCycle(t,i);if(F!==void 0)throw F;let ie=l!==void 0?l.has(S):f===L&&a.length===C?!1:m().has(S),H=et,Q=tt,z=ie||R&&H===y,be=c===void 0&&je(y,re,H,Q);if(!z&&!be){if(nt=H,ye===void 0)ye=()=>zt(nt),ye.reverseProofEnabled=!0;let A=o(S,i,t,n,1,a.length,ye);if(A){let Z=n.getControlFault();if(Z.kind==="fault")throw Z.error;let rt=new ae(i,[i,...A]);throw n.latchCycle(t,i,rt),rt}}if(!ie){let A=d?.dependencies[a.length];l?.add(S),a.push(A!==void 0&&Object.is(A.node,S)&&Object.is(A.token,O.token)?A:Object.freeze({node:S,token:O.token})),_t(S)}if(P=H,k=Q,O.outcome.kind==="control-error"){n.latchControlFault(O.outcome.error);let A=n.getControlFault();if(A.kind==="fault")throw A.error;throw O.outcome.error}let se=n.getControlFault();if(se.kind==="fault")throw se.error;if(O.outcome.kind==="error")throw new Me(S,O.outcome.error);return O.outcome.value};try{let S,b,w=!1;try{S=e.get(Bt)}catch(F){w=!0,b=F}finally{p=!1}if(w)b=St(b,"getter");let g=w?void 0:pt(S,"getter");Ie();let C=n.getControlFault();if(C.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:C.error},a);let V=n.getCycle(t,i);if(V!==void 0)return E(i,t.createOutcomeToken(),{kind:"error",error:V},a);if(w)return E(i,t.createOutcomeToken(),{kind:"error",error:b instanceof U?b:new Ae(i,b)},a);if(g===void 0)throw Error("Selector result classification was not completed");let R=n.getControlFault();if(R.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);if(g.kind==="error")return E(i,t.createOutcomeToken(),{kind:"error",error:g.error instanceof U?g.error:new Ae(i,g.error)},a);let L=g.value,O;if(h){let F=e.equal??Object.is,ie,H,Q=!1;try{ie=F(h.value,L)}catch(Z){Q=!0,H=St(Z,"comparator")}let z=Q?void 0:pt(ie,"comparator");Ie();let be=n.getControlFault();if(be.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:be.error},a);let se=n.getCycle(t,i);if(se!==void 0)return E(i,t.createOutcomeToken(),{kind:"error",error:se},a);if(Q)return E(i,t.createOutcomeToken(),{kind:"error",error:H instanceof U?H:new ve(i,H)},a);if(z===void 0)throw Error("Selector comparator classification was not completed");let A=n.getControlFault();if(A.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:A.error},a);if(z.kind==="error")return E(i,t.createOutcomeToken(),{kind:"error",error:z.error instanceof U?z.error:new ve(i,z.error)},a);if(z.value!==!0&&z.value!==!1)return E(i,t.createOutcomeToken(),{kind:"error",error:new Fe},a);if(z.value===!0)L=h.value,O=h.current?h.token:void 0}return E(i,O??t.createOutcomeToken(),{kind:"value",value:L},a)}finally{try{De?.close()}finally{n.leave(t,i)}}};class v{#t=[];#n;#o=0;#s;#a=Jt;#r;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}setSuppliedReadGuard(e){let t=this.#r;return this.#r=e,t}getControlFaultForSuppliedRead(){return this.#r?.(),this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#s??(this.#s=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#s?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}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.#i(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#i(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 s=new Set,i=new Map,a=!1,d=0,c=0,l=0;for(let f of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,c,l);return}if(!Object.is(f.host,e))continue;if(c++,f.revalidatePrefix===void 0||s.has(f.selector)){r?.recordSnapshot("unavailable",d,c,l);return}if(s.add(f.selector),Object.is(f.selector,t)){if(a||f.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,c,l);return}a=!0}for(let h of f.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,c,l);return}let p=i.get(h.node);if(p===void 0)i.set(h.node,[f.selector]);else p.push(f.selector)}}if(!a){r?.recordSnapshot("unavailable",d,c,l);return}let u=new Map;for(let[f,h]of i)u.set(f,Object.freeze(h));return r?.recordSnapshot("completed",d,c,l),u}latchCycle(e,t,n){let o=this.#d(e,t);o.cycleError??=n}getCycle(e,t){return this.#i(e,t).cycleError}#i(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}#d(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 Jt=Object.freeze({kind:"none"});var gt=Symbol("no-committed-selector-baseline");class Ke{#t;#n=new Map;#o=new Map;#s=new Map;#a;#r=1;#i=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new v,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#s.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),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)});return this.#o.set(e,d),d}let r=this.#n.get(e);if(r!==void 0)return r.served;let s=n.run(t,()=>this.#d(o.definition,this,t));if(s.outcome.kind==="control-error")throw s.outcome.error;let i=Object.freeze({token:s.token,outcome:s.outcome});return this.#i++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:i,dependencies:s.dependencies})),i}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#i}getComparisonBaseline(e){let t=this.#s.get(e);if(t===void 0)t=this.#c().baseline(e)??gt,this.#s.set(e,t);return t===gt?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var kt=4096,en=Object.freeze([]);class Rt{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Ee{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;[N]=void 0;#t=new WeakMap;#n;#o=new WeakMap;#s;#a=new WeakMap;#r=new WeakSet;#i=0;#d=0;#c;#l=!1;#f;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#y(),this.#n=this.#y()}get status(){return this.#u}get facade(){if(this.#f===void 0)throw Error("Store scope facade is not installed");return this.#f}installFacade(e){if(this.#f!==void 0)throw Error("Store scope facade is already installed");this.#f=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#y()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#a.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.coordinator.runtimeDomain[_]?.scope(this),this.#n.forEach((t)=>{this.detachAtomView(t),t.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap;let e=this[N]?.size??0;if(e>0)this.coordinator.recordCounter("familyOwnerReleases",e);this[N]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#s=void 0,this.#a=new WeakMap,this.#r=new WeakSet,this.#i++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(J(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){let a=n[_]?.scope(this,e);if(a!==void 0)return a;throw TypeError("Unknown committed StoreTree state")}let r=e,s=this.#o.get(r);if(s!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r,t),s=this.#o.get(r);if(s!==void 0&&!this.#r.has(r))return s.served;let i=Re(n,t,()=>this.coordinator.evaluate(o,this,t));if(i.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw i.outcome.error;return this.#b(r,i,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.#s?.get(n);if(o===void 0){let r=[];for(let i of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(i.node))r.push(i.node);o=Object.freeze(r);let s=this.#s;if(s===void 0)s=new WeakMap,this.#s=s;s.set(n,o)}return o}visitSelectorDependents(e,t,n){return this.#a.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#i}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#d===0)this.#c=[],this.#l=!1;this.#d++;let t=this.#c?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#c;if(o===void 0)return;if(t===o.length)return en;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#d--,this.#d!==0)return;this.#c=void 0,this.#l=!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()}#b(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),s=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess}),i=this.#m(e,o?.dependencies??wt,t.dependencies),a=i?this.#S(e,o?.dependencies??wt,t.dependencies):void 0;if(i)this.#s?.delete(e);if(this.#i++,n.noteSelectorGraphPublication(this),this.#o.set(e,s),this.#r.delete(e),a!==void 0)this.#p(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(t.outcome.error);return r}#m(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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#y(),this.#a.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=kt-o.length,s=this.coordinator.runtimeDomain.selectors,i=new Set;for(let d of t)if(s.has(d.node))i.add(d.node);let a=[];for(let d of n)if(s.has(d.node)&&!i.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#c;if(t===void 0||t.length+e.length>kt){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#y(){return new Rt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var wt=Object.freeze([]);class Ue{transaction=Object.freeze({});#t;#n;#o;#s;#a;#r;#i;#d;#c;#l;#f;#u;#b;#m;#S;#p;#e;#y;#g=!1;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#s!==void 0||this.#a!==void 0||this.#r!==void 0}get hasRows(){return this.#g}installRows(e){let t=this.#y;if(t!==void 0&&t!==e)throw Error();this.#y=e}markRow(e){if(this.#y===void 0)throw Error();if(e!==this.generation)throw Error();this.#g=!0,this.#A()}get singleIntentScope(){return this.#n}get singleIntent(){return this.#s===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let s=n.get(e);if(s===void 0)s=this.#h(),n.set(e,s);s.set(t.atom,t),this.#A();return}let o=this.#a;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let s=this.#h();s.set(this.#n,o);let i=this.#h();i.set(t.atom,t),s.set(e,i),this.#r=s,this.#a=void 0,this.#n=void 0}this.#A();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#A();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#A();return}if(Object.is(this.#n,e)){let s=this.#s;if(s===void 0){this.#s=t,this.#A();return}if(Object.is(s.atom,t.atom)){this.#s=t,this.#A();return}let i=this.#h();i.set(r.atom,r),i.set(s.atom,s),i.set(t.atom,t),this.#a=i}else{let s=this.#h(),i=this.#h();if(i.set(r.atom,r),this.#s!==void 0)i.set(this.#s.atom,this.#s);s.set(this.#n,i);let a=this.#h();a.set(t.atom,t),s.set(e,a),this.#r=s,this.#n=void 0}this.#o=void 0,this.#s=void 0,this.#A()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#s!==void 0)e(this.#n,this.#s);return}let n=this.#a;if(n!==void 0){let r=this.#n;for(let s of n.values())e(r,s);return}let o=this.#r;if(o===void 0)return;for(let[r,s]of o)for(let i of s.values())e(r,i)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#s;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#c!==void 0&&Object.is(this.#i,e)&&Object.is(this.#d,t))return this.#c;if(this.#f!==void 0&&Object.is(this.#i,e)&&Object.is(this.#l,t))return this.#f;if(Object.is(this.#i,e))return this.#u?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let i=o.get(e);if(i===void 0)i=this.#h(),o.set(e,i);if(!i.has(t))i.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let i=this.#h();i.set(this.#i,r);let a=this.#h();a.set(t,n),i.set(e,a),this.#b=i,this.#u=void 0,this.#i=void 0}return}let s=this.#c;if(s===void 0){this.#i=e,this.#d=t,this.#c=n;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t))return;if(Object.is(this.#i,e)){let i=this.#f;if(i===void 0){this.#l=t,this.#f=n;return}if(Object.is(this.#l,t))return;let a=this.#h();a.set(this.#d,s),a.set(this.#l,i),a.set(t,n),this.#u=a}else{let i=this.#h(),a=this.#h();if(a.set(this.#d,s),this.#l!==void 0&&this.#f!==void 0)a.set(this.#l,this.#f);i.set(this.#i,a);let d=this.#h();d.set(t,n),i.set(e,d),this.#b=i,this.#i=void 0}this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#f=void 0}getFallback(e){if(Object.is(this.#m,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#m,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#m=e,this.#S=t;return}if(Object.is(this.#m,e)){this.#S=t;return}let o=this.#h();o.set(this.#m,this.#S),o.set(e,t),this.#p=o,this.#m=void 0,this.#S=void 0}forEachFallback(e){if(this.#m!==void 0&&this.#S!==void 0)e(this.#m,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#A(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){let e=this.#y;this.#y=void 0,this.#g=!1;try{if(this.#a?.clear(),this.#r!==void 0){for(let t of this.#r.values())t.clear();this.#r.clear()}if(this.#u?.clear(),this.#b!==void 0){for(let t of this.#b.values())t.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#s=void 0,this.#a=void 0,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#f=void 0,this.#u=void 0,this.#b=void 0,this.#m=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}finally{e?.(this)}}#h(){return this.#t?.(),new Map}}class Tt{constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.mutate(t,n,"set",o,r),this.update=(o,r)=>e.mutate(t,n,"update",o,r),this.reset=(o)=>e.mutate(t,n,"reset",o),this.delete=(o)=>e.mutate(t,n,"delete",o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),he(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ye=(e,t,n)=>new Tt(e,t,n),Xe=(e)=>{let t=x(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new de},Ct=(e)=>{let t=x(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new de};var tn=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},B=Symbol("definition domain records"),Nn=(e)=>e[B].ownerToken,En=(e,t)=>{let n=e[B],o=n[_];if(o!==void 0)return o;let r=t(n);return n[_]=r,r};var Dn=(e,t,n,o,r,s)=>{let i=e[B],a=new v,d=i.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 u=i[G];i[G]={session:a,definitions:new WeakSet,allowDefinitions:t==="factory",...s===void 0?{}:{createAccessorFault:s}};let f=l.map((h)=>Object.freeze({selectorSession:h,previous:h.setSuppliedReadGuard(()=>{let p=i.activity;return ct(p?.kind==="guarded-callback"?p.session:a,h)})}));try{return q(i,a,()=>{let h=Reflect.apply(n,void 0,o);return r===void 0?h:r(h)})}finally{for(let h=f.length-1;h>=0;h--){let p=f[h];p.selectorSession.setSuppliedReadGuard(p.previous)}if(u===void 0)delete i[G];else i[G]=u}},nn=(e)=>{let t=e[B][G];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 W:t.accessorFault??=t.createAccessorFault();throw t.session.latchControlFault(o),o},Pn=(e)=>ne(e[B]),Vn=nn,xn=(e,t)=>Se(e[B],t),jn=(e,t)=>M(e[B],t,new v),In=(e,t)=>{let n=e[B];if((typeof t==="object"||typeof t==="function")&&t!==null&&n.states.has(t)&&(n.atoms.has(t)||n.selectors.has(t))){if(n[G]?.definitions.has(t)||n[ge]?.has(t))return t;return}M(n,t,new v);return},Mn=(e,t)=>{let n=e[B];if((n[ge]??(n[ge]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[N]??(n[N]=new WeakSet)).add(t)},jt=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}),on=35,It=new WeakMap,Fn=()=>{let e=new Uint32Array(on),t=Object.freeze({read(n){return e[jt[n]]??0}});return It.set(t,e),t},D=(e)=>Object.freeze({kind:"value",value:e}),rn=(e)=>Object.freeze({kind:"error",error:e}),Ot=(e)=>e.kind==="value"?D(e.value):rn(e.error),pe=(e,t)=>e[_]?.has(t)?e[_]:void 0,Nt=(e,t,n,o)=>{let r=e.read(t,n,o);if(r.kind!=="value")throw r.error;return r.value},Et=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},Dt=1,Qe=2,Pt=4,sn=(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}),Ze=(e)=>(e.onAllocation?.(),new Map),an=(e)=>(e.onAllocation?.(),new Set),$e=(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)},Vt=(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=Ze(e),e.preflight=r;let s=r.get(t);if(s===void 0)s=Ze(e),r.set(t,s);s.set(n,o)},dn=(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=an(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},cn=(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=Ze(e),e.affected=o;o.set(t,n)};class Mt{#t=new WeakMap;#n;#o=1;#s=0;#a=!1;#r;#i;#d;#c=0;#l;#f;#u;#b=1;#m=0;#S;#p;#e;#y;#g;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:It.get(t),this.#g=n,this.evaluate=n?.evaluate??vt,this.#n=new Ee(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[jt[e]]+=t}#A(){return this.recordCounter("draftCreations"),new Ue(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new v,o=t,r=M(this.#e,o,n),s=qe(this.#e,"StoreTree.get");if(this.#v(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(s===void 0){let i=e.serveKnownLocal(o,n);if(i.outcome.kind!=="value")throw i.outcome.error;return i.outcome.value}try{let i=e.serveKnownLocal(o,n);if(i.outcome.kind!=="value"){if(i.outcome.kind==="control-error")s.latchControlFault(i.outcome.error);throw i.outcome.error}return i.outcome.value}catch(i){let a=n.getControlFault();if(a.kind==="fault")s.latchControlFault(a.error);throw i}}sub(e,t,n){let o=t,r,s=this.#e.states.has(o)?"local":M(this.#e,o,r=new v);if(I(this.#e,"StoreTree.sub"),this.#v(e),s==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o)&&!pe(this.#e,o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let i=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new v);if(i.outcome.kind==="control-error")throw i.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return tn(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;lt(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let s=this.#u,i=s?.get(t.scope);if(i?.get(t.state)===t){if(i.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(i!==void 0&&i.size===0){if(s?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(s?.size===0)this.#u=void 0}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)M(this.#e,n,new v);if(I(this.#e,"StoreTree.scope"),this.#v(e),t===0)return this.#D(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#D(e,n)}dispose(e){if(I(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let s=[];o.children.forEach((i)=>s.push(i));for(let i=s.length-1;i>=0;i--)n.push(Object.freeze({node:s[i],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#H(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(I(this.#e,"StoreTree.txn"),this.#v(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#A(),r=Ye(this,o,e),s;try{s=dt(this.#e,o.transaction,()=>t(r))}catch(i){throw o.close(),o.release(),i}o.close();try{let i=new v;Te(this.#e,i,()=>Xe(s)),this.#V(o)}finally{o.release()}return s}readHydrationSnapshot(e,t){let n=new v,o=t,r=M(this.#e,o,n);I(this.#e,"adapter readHydrationSnapshot"),this.#v(e);let s,i;if(r!=="invalid")if(this.#e.atoms.has(o))s=0;else if(this.#e.selectors.has(o))s=1;else i=pe(this.#e,o);if(s===void 0&&!i)throw TypeError("readHydrationSnapshot requires a valid State");let a=this.#A(),d;try{if(s===0){let c=this.#w(a,e,o,n);if(c.kind!=="value")throw c.error;return c.value}if(s===void 0)return Nt(i,a,e,o);return d=this.#h(a,e,!0),d.readSelector(o)}finally{d?.revoke(),a.close(),a.forEachFallback((c,l)=>{if(this.#t.has(c))return;this.#t.set(c,l),this.recordCounter("fallbackPublications")}),a.release()}}transactionGet(e,t,n){let o=n,r=new v,s=M(this.#e,o,r);if(Ce(this.#e,e.transaction,e.active),this.#v(t),s==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#w(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o)){let a=pe(this.#e,o);if(!a)throw TypeError("Transaction.get requires a readable State");return Nt(a,e,t,o)}let i=e.getScratchHost(t);if(i===void 0){if(i=this.#h(e,t),e.installScratchHost(t,i))this.recordCounter("scratchMapAllocations")}return i.readSelector(o)}mutate(e,t,n,o,r){let s=o,i=new v,a=`${e===void 0?"StoreTree":"Transaction"}.${n}`,d=M(this.#e,s,i);if(e===void 0)I(this.#e,a);else Ce(this.#e,e.transaction,e.active);this.#v(t);let c=d==="local"&&this.#e.atoms.has(s),l;if(c?n==="delete":d!=="local"||typeof s==="function"||(l=pe(this.#e,s))===void 0)throw TypeError(`${a} requires a valid State`);let f=e===void 0,h=e??this.#A();try{if(l!==void 0)l.stage(h,t,n,s,r,i);else if(n==="set")this.#G(h,t,s,r,i);else if(n==="update")this.#W(h,t,s,r,i,a);else this.#q(h,t,s,i)}catch(p){if(f)h.close(),h.release();throw p}if(!f)return;h.close();try{this.#V(h)}finally{h.release()}}transactionScope(e,t,n,o,r){let s=new v;if(typeof n!=="string")M(this.#e,n,s);Ce(this.#e,e.transaction,e.active),this.#v(t);let i=this.#L(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ye(this,e,i);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 u=new v;return Te(this.#e,u,()=>Ct(l))}let c=new v;return Te(this.#e,c,()=>Xe(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#h(e,t,n=!1){return this.recordCounter("scratchHostAllocations"),new Ke(Object.freeze({resolve:(o,r)=>this.#B(o,r),read:(o,r,s)=>this.#K(e,t,o,r,s),baseline:n?()=>{return}:(o)=>t.captureCommittedSelectorSuccess(o),run:(o,r)=>Re(this.#e,o,r)}),e.generation,this.evaluate)}#B(e,t){if(J(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n!==void 0)return Object.freeze({kind:"selector",definition:n});if(pe(this.#e,e))return Object.freeze({kind:"ext"});throw TypeError("Unknown scratch StoreTree State")}#D(e,t){let n=new Ee(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Je(this,n,this.#g);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#L(e,t){if(typeof t==="string"){let s=e.namedChildren.get(t);if(s===void 0)throw new He;return this.#v(s),s}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let s=o;if(this.#v(s),!Object.is(s.coordinator,this))throw new Ge;return s}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ke;throw new we}throw new we}#v(e){if(e.status!=="live")throw new Le}#H(e){let t=this.#u,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let s=r.head;while(s!==void 0){let i=s.next;s.callback=void 0,s.target=void 0,s.previous=void 0,s.next=void 0,o++,s=i}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#u=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#G(e,t,n,o,r){let s=q(this.#e,r,()=>ue(o));if(s.kind==="error")throw s.error;let i=this.#C(e,t,n,r);this.#_(e,t,n,s.value,i,r)}#W(e,t,n,o,r,s){if(typeof o!=="function")throw TypeError(`${s} requires an updater function`);let i=this.#C(e,t,n,r),a=e.hasIntents?this.#w(e,t,n,r):i.outcome;if(a.kind!=="value")throw a.error;let d=this.#X(o,a.value,r);this.#_(e,t,n,d,i,r)}#q(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#O(e,n,o),reachesFallback:!0}):this.#P(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let s=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:s}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let s=t.atomOverrides.has(n),i=t,a;while(i!==void 0){if(i.atomOverrides.has(n)){a=D(i.atomOverrides.get(n));break}i=i.parent}let d=a===void 0,c=Object.freeze({owned:s,outcome:a??this.#O(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#w(e,t,n,o){return this.#P(e,t,n,o).outcome}#K(e,t,n,o,r){if(o==="atom")return this.#w(e,t,n,r);return this.#e[_].read(e,t,n)}#P(e,t,n,o){let r=t;while(r!==void 0){let s=e.getIntent(r,n);if(s?.kind==="set")return Object.freeze({outcome:D(s.value),reachesFallback:!1});if(s===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:D(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#O(e,n,o),reachesFallback:!0})}#O(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#k(t);if(r.fallback.kind==="eager")return D(r.fallback.value);let s=r.fallback.initialize,i=e.getFallback(t);if(i!==void 0)return i;let a=Ot(q(this.#e,n,()=>We(s)));return e.setFallback(t,a),a}#U(e,t,n,o){let r=this.#k(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Y(r,t,n,o)?t:n}#Y(e,t,n,o){return q(this.#e,o,()=>{let r;try{r=e(t,n)}catch(i){let a=x(i);if(a.kind==="not-thenable")throw i;if(a.kind==="inspection-error")throw a.error;throw j(a),new le}let s=x(r);if(s.kind==="inspection-error")throw s.error;if(s.kind==="thenable")throw j(s),new le;if(r!==!0&&r!==!1)throw new le;return r})}#X(e,t,n){return q(this.#e,n,()=>{let o;try{o=e(t)}catch(s){let i=x(s);if(i.kind==="not-thenable")throw s;if(i.kind==="inspection-error")throw i.error;throw j(i),new ce}let r=ue(o);if(r.kind==="error")throw r.error;return r.value})}#V(e){let t;if(e.hasRows){if(t=this.#e[_]?.plan(e),t===void 0)throw Error()}if(!e.hasIntents&&t===void 0)return;let{singleIntent:n,singleIntentScope:o}=e;if(t===void 0&&n?.kind==="reset"&&o!==void 0&&!n.publishDraftFallback&&e.getAtomBaseline(o,n.atom)?.owned===!1)return;let r=sn(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),s,i;if(n!==void 0&&o!==void 0)s=this.#x(e,o,n,r);else e.forEachIntent((d,c)=>{let l=this.#x(e,d,c,r);if(s===void 0){s=l;return}if(i===void 0)i=[];i.push(l)});if(this.#g?.(1,e,this.#e.atoms),s!==void 0)this.#j(e,s);if(i!==void 0)for(let d of i)this.#j(e,d);let a=s===void 0?!1:this.#I(s);if(i!==void 0)for(let d of i){let c=this.#I(d);a||=c}if(t!==void 0){let d=t.commit(0);a||=d}if(s!==void 0)this.#M(s);if(i!==void 0)for(let d of i)this.#M(d);if(t!==void 0)t.commit(1);this.#ne();try{let d,c,l=r.affectedRecord,u=r.affectedBefore;if(l!==void 0&&u!==void 0)d=this.#N(r,l,u);let{secondAffectedRecord:f,secondAffectedBefore:h}=r;if(f!==void 0&&h!==void 0){let p=this.#N(r,f,h);if(p!==void 0)if(d===void 0)d=p;else c=[p]}if(r.affected!==void 0)for(let[p,m]of r.affected){let y=this.#N(r,p,m);if(y===void 0)continue;if(d===void 0)d=y;else{if(c===void 0)c=[];c.push(y)}}if(t!==void 0){let p=t.commit(2);if(p!==void 0)for(let m of p){let y=m;if(d===void 0)d=y;else{if(c===void 0)c=[];c.push(y)}}}if(a)this.#s+=1,this.recordCounter("sourceEpoch");this.#g?.(2,d===void 0?0:1+(c?.length??0)),this.#te(d,c)}catch(d){throw this.#R(),d}}#x(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#F(e,t,n.atom,o);let s=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),i=t.getAtomView(n.atom);if(i!==void 0)this.#Q(e,i,o);return s}#j(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#I(e){let{intent:t,scope:n}=e;if(t.kind==="set"){if(n.atomOverrides.set(t.atom,t.value),this.#e[N]?.has(t.atom)){let o=n[N];if(o===void 0)o=new Set,n[N]=o,this.recordCounter("familyOwnerRetentionSetsCreated");let r=o.size;if(o.add(t.atom),o.size!==r)this.recordCounter("familyOwnerRetains")}}else{n.atomOverrides.delete(t.atom);let o=n[N];if(o?.delete(t.atom))this.recordCounter("familyOwnerReleases");if(o?.size===0)n[N]=void 0}return e.ownershipChanged}#M({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.#J(e.parent,t.atom))}#N(e,t,n){let o=$e(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),Et(n,o))return;return t.scope.updateAtomView(t,o),t}#Q(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!dn(n,r))continue;let s=r.served.outcome,i=this.#F(e,r.scope,r.atom,n);if(Et(s,i))continue;cn(n,r,s);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),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}}}#F(e,t,n,o){let r=$e(o,n,t);if(r!==void 0)return r;let s=t,i,a,d;while(s!==void 0){let c=$e(o,n,s);if(c!==void 0){d=c;break}if(i===void 0)i=s;else{if(a===void 0)a=[];a.push(s)}let l=e.getIntent(s,n);if(l?.kind==="set"){d=D(l.value);break}if(l===void 0&&s.atomOverrides.has(n)){d=D(s.atomOverrides.get(n));break}s=s.parent}if(d??=this.#$(e,n),i!==void 0)Vt(o,n,i,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)Vt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#$(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.#k(t);if(r.fallback.kind==="eager")return D(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#Z(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#k(e);if(n.fallback.kind==="eager")return D(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#J(e,t){let n=e,o=[],r;while(!0){let s=n.getAtomView(t);if(s!==void 0){r=s;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,D(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#Z(t));break}o.push(n),n=n.parent}for(let s=o.length-1;s>=0;s--)r=o[s].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],s;while(!0){let i=o.getAtomView(t);if(i!==void 0){s=i;break}if(o.atomOverrides.has(t)){s=o.createAtomView(t,D(o.atomOverrides.get(t)));break}if(o.parent===void 0){s=o.createAtomView(t,this.#ee(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let i=r.length-1;i>=0;i--)s=r[i].createAtomView(t,s.served.outcome,s);return s.served}#ee(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#k(e);if(o.fallback.kind==="eager")return D(o.fallback.value);let r=o.fallback.initialize,s=Ot(q(this.#e,t,()=>We(r)));return this.#t.set(e,s),this.recordCounter("fallbackPublications"),s}#k(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#te(e,t){if(e===void 0){this.#R();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0,this.#f=void 0,this.#a=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],s=this.#r[o++];this.#E(r,s)}}finally{n=this.#f,this.#f=void 0,this.#a=!1,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#oe(n)}#ne(){this.#S=void 0,this.#p=void 0,this.#m=this.#u===void 0?0:this.#b++}#R(){this.#m=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#m,o=this.#u?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#oe(e){let t=this.#S;if(t===void 0){if(this.#R(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let u=l.callback;if(u!==void 0)if(n===void 0)n=u;else if(o===void 0)o=[n,u];else o.push(u);l=l.next}};r(t);let s=this.#p;if(s!==void 0)for(let c of s)r(c);if(this.#R(),n===void 0){if(e!==void 0)throw e;return}let i=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let d;for(let c of i){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new v,u=!1,f;try{at(this.#e,l,()=>{try{let h=c(),p=x(h);if(p.kind==="thenable")j(p);else if(p.kind==="inspection-error")u=!0,f=p.error}catch(h){u=!0,f=h;let p=x(h);if(p.kind==="thenable")j(p)}})}catch(h){u=!0,f=h}if(u){if(d===void 0)d=[];if(d.push(f),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Be(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#z(e,t)&Dt)!==0)return!0;return this.#T(e,t,Dt),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#E(e,t,n)}#E(e,t,n){if((this.#z(e,t)&(Pt|Qe))!==0)return;this.#T(e,t,Qe);try{let r=e.getSelectorGraphVersion(),s=e.getCommittedSelectorDependencies(t);if(s!==void 0){for(let i of s)if(this.#e.selectors.has(i.node))this.#E(e,i.node)}if(e.isSelectorDirty(t)){let i=r===e.getSelectorGraphVersion();if(n!==void 0&&i)e.serve(t,n);else e.serve(t,new v)}this.#T(e,t,Pt)}finally{this.#T(e,t,0,Qe)}}#z(e,t){if(Object.is(this.#i,e)&&Object.is(this.#d,t))return this.#c;return this.#l?.get(e)?.get(t)??0}#T(e,t,n,o=0){if(this.#i===void 0){this.#i=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t)){this.#c=(this.#c|n)&~o;return}let r=this.#l;if(r===void 0)r=new Map,this.#l=r;let s=r.get(e);if(s===void 0)s=new Map,r.set(e,s);s.set(t,((s.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#f??=e}#_(e,t,n,o,r,s){let i=r.outcome.kind==="value"?this.#U(n,r.outcome.value,o,s):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:i,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class Je{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),he(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var xt=(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}}},Ft=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,l={})=>{ne(t);let u=new v,f=q(t,u,()=>ue(c));if(f.kind==="error")throw f.error;let h=Se(t,Oe("atom"));return t.atoms.set(h,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...xt(l)})),h},o=(c,l={})=>{if(ne(t),typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let u=Se(t,Oe("atom"));return t.atoms.set(u,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...xt(l)})),u},r=(c,l={})=>{if(ne(t),typeof c!=="function")throw TypeError("selector requires a getter function");if(l.equal!==void 0&&typeof l.equal!=="function")throw TypeError("selector equal must be a function");let u=Se(t,Oe("selector")),f=Object.freeze({node:u,get:c,...l.name===void 0?{}:{name:l.name},...l.equal===void 0?{}:{equal:l.equal}});return t.selectors.set(u,f),u},s=(c)=>{let l=new v;if(M(t,c,l)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let l=s(c);if(I(t,"adapter assertStore"),l===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,l)=>{if(s(c)===void 0)throw qe(t,"adapter read"),TypeError("read requires a valid Store");return c.get(l)},subscribe:(c,l,u)=>{if(s(c)===void 0)throw I(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(l,u)},readHydrationSnapshot:(c,l)=>{let u=s(c);if(u===void 0)throw I(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return u.coordinator.readHydrationSnapshot(u,l)}});return Object.freeze({[B]:t,atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,l)=>{I(t,"createStoreTree");let u=new Mt(t,c,l);return new Je(u,u.rootScope,l)}})};var ln=Ft(),Bn=(e,t)=>ln.createStoreTree(e,t);
|
|
2
|
+
export{ae as B,$t as C,vt as D,_ as E,_e as F,Be as G,W as H,ee as I,te as J,ke as K,de as L,ce as M,le as N,Le as O,He as P,Ge as Q,we as R,x as S,j as T,q as U,Rt as V,Nn as W,En as X,Dn as Y,nn as Z,Pn as _,Vn as $,xn as aa,jn as ba,In as ca,Mn as da,Fn as ea,ln as fa,Bn as ga};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=35,O=36,T=37,_=38,C=39,I=40,L=41,N=42,o=43,t=44,R=45,S=46,c=47,e=48,n=64,p=65,r=66,s=67,x=68,A=69,M=70,D=71,P=72,H=73,B=74,W=75,F=76;
|
|
2
|
+
export{E as a,O as b,T as c,_ as d,C as e,I as f,L as g,N as h,o as i,t as j,R as k,S as l,c as m,e as n,n as o,p,r as q,s as r,x as s,A as t,M as u,D as v,P as w,H as x,B as y,W as z,F as A};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{fa as e}from"../chunk-dab744dc.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class K extends Error{seal(){Object.freeze(this)}}class Ae extends K{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class Me extends K{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class ae extends K{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class U extends K{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 Fe extends K{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ve extends K{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 ze extends K{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var N=Symbol(),G=Symbol(),ge=Symbol(),_=Symbol(),it=Object.freeze({kind:"not-thenable"}),Lt=()=>{},Ht=Reflect.apply,st=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}class _e extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Be extends T{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class ee extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class te extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ke extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class de extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ce extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class le 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 Le extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class He extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ge extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class we extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var x=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return it;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):it}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{Ht(e.then,e.target,[void 0,Lt])}catch{}},ue=(e)=>{let t=x(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 ce})},We=(e)=>{try{return ue(e())}catch(t){let n=x(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 ce})}},fe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},q=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,s=r===void 0?Object.freeze({kind:"guarded-callback",session:t}):Object.freeze({kind:"guarded-callback",session:t,selectorActivity:r});try{let i=fe(e,s,n),a=t.getControlFault();if(a.kind==="fault")throw a.error;return i}catch(i){let a=t.getControlFault();if(a.kind==="fault")throw a.error;throw i}},at=(e,t,n)=>{try{let o=fe(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},Re=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,s=Object.is(r?.session,t)?r?.parentSelectorActivity:r,i=s===void 0?Object.freeze({kind:"selector",session:t}):Object.freeze({kind:"selector",session:t,parentSelectorActivity:s});return fe(e,i,n)},dt=(e,t,n)=>fe(e,Object.freeze({kind:"transaction",transaction:t}),n),Te=(e,t,n)=>{try{let o=fe(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},I=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new ee(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new te;throw new W},qe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new ee(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new te;throw new W},ct=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new W;throw e.latchControlFault(r),t.latchControlFault(r),r},lt=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new ee("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new te;throw new W},Ce=(e,t,n)=>{if(!n)throw new ke;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new ee("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new te},ut=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},J=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,st);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new _e;throw ut(e,n).latchControlFault(r),r}}return"invalid"},M=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=ut(e,n);if(o!==void 0&&"session"in o)try{let s=J(e,t,r),i=r.getControlFault();if(i.kind==="fault")throw i.error;return s}catch(s){let i=r.getControlFault();if(i.kind==="fault")throw i.error;throw s}return q(e,r,()=>J(e,t,r))},he=(e,t)=>(Object.defineProperty(e,st,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),ne=(e)=>{let t=e[G];if(t===void 0||t.allowDefinitions)return;let n=t.session.getControlFault();if(n.kind==="fault")throw n.error;let o=new W;throw t.session.latchControlFault(o),o},Oe=(e)=>({kind:e}),Se=(e,t)=>{ne(e);let n=e[G],o=Object.freeze(he(t,e.ownerToken));return e.states.add(o),n?.definitions.add(o),o};var ft=Object.freeze({kind:"not-thenable"}),Gt=()=>{},Wt=Reflect.apply,ht=Symbol("selector dependency path root"),mt=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return ft;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):ft}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},yt=(e)=>{try{Wt(e.then,e.target,[void 0,Gt])}catch{}},qt=(e)=>Object.freeze(e),Kt=(e)=>Object.freeze(e),E=(e,t,n,o)=>{let r=Kt(o);return Object.freeze({selector:e,token:t,outcome:qt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Ut:Object.freeze(r.map((s)=>s.node))})},Ut=Object.freeze([]),Ne=32,oe=8192,Yt=2*Ne,bt=128,Xt=4096;class At{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(oe,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>=Ne&&e.size<=oe,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>oe){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,s=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,s);let i=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(i?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Ne&&e.size<=oe;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,Ne),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Yt){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(oe,2*o.size);let r=0;for(let s of e){let i=this.hasWithinCrossVersionBudget(o,s.tail);if(i===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!i)continue;let a=this.hasWithinCrossVersionBudget(o,s.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>oe||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 Qt=(e,t)=>new At(e,t),Y=(e,t,n,o,r,s)=>{if(s!==void 0)s.nodeVisits=n,s.dependentProbes=bt-t.remaining-n,s.liveDependents=o,s.maxFrontier=r;return e},$t=(e,t,n,o,r,s=!0,i)=>{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(i===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let p=i===void 0?void 0:o.getTransientDependencies(n,e);if(p!==void 0){if(p.length===0)return"proven-terminal"}else{let m=n.getSelectorDependencyNodes;if(m!==void 0){let y=m.call(n,e);if(y===void 0||y.length===0)return"proven-terminal"}}}if(!s)return"disabled";let d={remaining:bt},c=[t],l=new Set(c),u=0,f=0,h=1;while(c.length>0){if(d.remaining===0)return Y("budget-exhausted",d,u,f,h,r);d.remaining--,u++;let p=c.pop();if(Object.is(p,e))return Y("path-possible",d,u,f,h,r);let m=!1,y=(k)=>{if(f++,Object.is(k,e))return m=!0,!1;if(!l.has(k)){if(l.add(k),c.push(k),c.length>h)h=c.length}return!0},re=a.call(n,p,d,y);if(m)return Y("path-possible",d,u,f,h,r);if(!re)return Y("budget-exhausted",d,u,f,h,r);let P=i?.get(p);if(P!==void 0)for(let k of P){if(d.remaining===0)return Y("budget-exhausted",d,u,f,h,r);if(d.remaining--,!y(k))return Y("path-possible",d,u,f,h,r)}}return Y("proven-reverse",d,u,f,h,r)},Zt=(e,t,n,o,r,s,i,a)=>{if(r===1||r===2){let f=$t(e,t,n,o,void 0,r===1?i?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(f==="proven-terminal"||f==="proven-reverse")return;if(f==="budget-exhausted"){if(r===1&&i!==void 0)i.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=i?.(),c=d?.beginSearch()??!1,l=[e],u=new Map([[e,ht]]);while(l.length>0){let f=l.pop();if(Object.is(f,t)){let m=[],y=f;while(y!==ht)m.push(y),y=u.get(y);return m.reverse(),d?.completePositive(),Object.freeze(m)}let h=o.getTransientDependencies(n,f);if(h){if(h.length===0)continue;if(c){let m=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(m)continue}for(let m of h){if(u.has(m.node))continue;u.set(m.node,f),l.push(m.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let m=n.getSelectorDependencyNodes(f);if(m===void 0||m.length===0)continue;if(c){let y=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(y)continue}for(let y of m){if(u.has(y))continue;u.set(y,f),l.push(y)}continue}let p=n.getSelectorRecord(f);if(!p||p.dependencies.length===0)continue;if(c){let m=d.hasProvenNoPath(f);if(!d.enabled)c=!1;if(m)continue}for(let m of p.dependencies){if(u.has(m.node))continue;u.set(m.node,f),l.push(m.node)}}d?.completeNegative(u);return},St=(e,t)=>{let n=mt(e);if(n.kind==="thenable")return yt(n),new U(t);if(n.kind==="inspection-error")return n.error;return e},pt=(e,t)=>{let n=mt(e);if(n.kind==="thenable")return yt(n),Object.freeze({kind:"error",error:new U(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},vt=(e,t,n,o=Zt,r,s)=>{let{node:i}=e,a=[],d=t.getSelectorRecord(i),c=d?.dependencies,l=c===void 0?new Set:void 0,u,f=0,h=t.getComparisonBaseline(i),p=!0,m=()=>{let S=l;if(S!==void 0)return S;S=new Set;for(let b of a)S.add(b.node);return l=S,S};n.enter(t,i,a);let y=t.getSelectorGraphVersion(),re=n.getSelectorGraphPublicationCount(t),P=y,k=re,et=y,tt=re,De,Pe=!1,Ve=y,me=0,X,nt=y,ye,xe=(S,b)=>{if(S===Ve)return;if(Ve=S,X===void 0){me=0;return}if(X.advanceGraphVersion(b))return;me=0,r?.graphVersionReset()},zt=(S)=>{if(S!==Ve)xe(S,void 0);if(me++,(c?.length??0)===0&&me<3){r?.admissionSkipped();return}if(X===void 0){let b=c!==void 0&&c.length>0&&c.length<3;X=Qt(b?3:0,r)}if(!X.enabled){r?.disabled();return}return X},_t=(S)=>{if(Pe)return;let b=t.beginSelectorGraphObservation?.(S);if(b===void 0)return;Pe=!0,De=b},je=(S,b,w,g)=>w-S===g-b,ot=(S=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t),w=je(P,k,S,b))=>{if(S===P)return;if(!Pe&&t.beginSelectorGraphObservation!==void 0){xe(S,void 0),P=S,k=b;return}let g=De?.takeAddedEdges();if(xe(S,g),w){P=S,k=b;return}if(g!==void 0){let C=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,i,a.length,Xt,s),V=g.length===0?void 0:{transientDependents:C,reverseProofEnabled:!0},R=!1;for(let L of g)if(o(L.head,L.tail,t,n,2,a.length,void 0,V)!==void 0){R=!0;break}if(!R){P=S,k=b;return}}for(let C=0;C<a.length;C++){let V=a[C],R=o(V.node,i,t,n,0,a.length);if(!R)continue;if(l!==void 0)for(let F=a.length-1;F>=C;F--)l.delete(a[F].node);if(a.length=C,f++,n.getControlFault().kind==="fault")return;let O=new ae(i,[i,...R]);n.latchCycle(t,i,O);return}P=S,k=b},Ie=()=>{let S=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t);et=S,tt=b;let w=je(P,k,S,b);if(!w)n.revalidateAncestorPrefixes(t,i);ot(S,b,w)};n.setPrefixRevalidator(t,i,ot);let Bt=(S)=>{if(!p)throw new ze;let b=n.getControlFaultForSuppliedRead();if(b.kind==="fault")throw b.error;let w=n.getCycle(t,i);if(w!==void 0)throw w;let g=n.activeCyclePath(t,S);if(g){let A=new ae(i,g);throw n.latchCycle(t,i,A),A}let C=a.length,V,R=!1;if(l===void 0){let A=c?.[C];if(A!==void 0&&Object.is(A.node,S))V=!1,R=!0;else V=m().has(S)}else V=l.has(S);if(!V&&!R&&c!==void 0&&c.length>0){let A=c[a.length];if(A!==void 0&&Object.is(A.node,S))R=!0;else{if(u===void 0){u=new Set;for(let Z of c)u.add(Z.node)}R=u.has(S)}}let L=f,O=t.serve(S,n);Ie();let F=n.getCycle(t,i);if(F!==void 0)throw F;let ie=l!==void 0?l.has(S):f===L&&a.length===C?!1:m().has(S),H=et,Q=tt,z=ie||R&&H===y,be=c===void 0&&je(y,re,H,Q);if(!z&&!be){if(nt=H,ye===void 0)ye=()=>zt(nt),ye.reverseProofEnabled=!0;let A=o(S,i,t,n,1,a.length,ye);if(A){let Z=n.getControlFault();if(Z.kind==="fault")throw Z.error;let rt=new ae(i,[i,...A]);throw n.latchCycle(t,i,rt),rt}}if(!ie){let A=d?.dependencies[a.length];l?.add(S),a.push(A!==void 0&&Object.is(A.node,S)&&Object.is(A.token,O.token)?A:Object.freeze({node:S,token:O.token})),_t(S)}if(P=H,k=Q,O.outcome.kind==="control-error"){n.latchControlFault(O.outcome.error);let A=n.getControlFault();if(A.kind==="fault")throw A.error;throw O.outcome.error}let se=n.getControlFault();if(se.kind==="fault")throw se.error;if(O.outcome.kind==="error")throw new Me(S,O.outcome.error);return O.outcome.value};try{let S,b,w=!1;try{S=e.get(Bt)}catch(F){w=!0,b=F}finally{p=!1}if(w)b=St(b,"getter");let g=w?void 0:pt(S,"getter");Ie();let C=n.getControlFault();if(C.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:C.error},a);let V=n.getCycle(t,i);if(V!==void 0)return E(i,t.createOutcomeToken(),{kind:"error",error:V},a);if(w)return E(i,t.createOutcomeToken(),{kind:"error",error:b instanceof U?b:new Ae(i,b)},a);if(g===void 0)throw Error("Selector result classification was not completed");let R=n.getControlFault();if(R.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);if(g.kind==="error")return E(i,t.createOutcomeToken(),{kind:"error",error:g.error instanceof U?g.error:new Ae(i,g.error)},a);let L=g.value,O;if(h){let F=e.equal??Object.is,ie,H,Q=!1;try{ie=F(h.value,L)}catch(Z){Q=!0,H=St(Z,"comparator")}let z=Q?void 0:pt(ie,"comparator");Ie();let be=n.getControlFault();if(be.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:be.error},a);let se=n.getCycle(t,i);if(se!==void 0)return E(i,t.createOutcomeToken(),{kind:"error",error:se},a);if(Q)return E(i,t.createOutcomeToken(),{kind:"error",error:H instanceof U?H:new ve(i,H)},a);if(z===void 0)throw Error("Selector comparator classification was not completed");let A=n.getControlFault();if(A.kind==="fault")return E(i,t.createOutcomeToken(),{kind:"control-error",error:A.error},a);if(z.kind==="error")return E(i,t.createOutcomeToken(),{kind:"error",error:z.error instanceof U?z.error:new ve(i,z.error)},a);if(z.value!==!0&&z.value!==!1)return E(i,t.createOutcomeToken(),{kind:"error",error:new Fe},a);if(z.value===!0)L=h.value,O=h.current?h.token:void 0}return E(i,O??t.createOutcomeToken(),{kind:"value",value:L},a)}finally{try{De?.close()}finally{n.leave(t,i)}}};class v{#t=[];#n;#o=0;#s;#a=Jt;#r;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}setSuppliedReadGuard(e){let t=this.#r;return this.#r=e,t}getControlFaultForSuppliedRead(){return this.#r?.(),this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#s??(this.#s=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#s?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}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.#i(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#i(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 s=new Set,i=new Map,a=!1,d=0,c=0,l=0;for(let f of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,c,l);return}if(!Object.is(f.host,e))continue;if(c++,f.revalidatePrefix===void 0||s.has(f.selector)){r?.recordSnapshot("unavailable",d,c,l);return}if(s.add(f.selector),Object.is(f.selector,t)){if(a||f.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,c,l);return}a=!0}for(let h of f.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,c,l);return}let p=i.get(h.node);if(p===void 0)i.set(h.node,[f.selector]);else p.push(f.selector)}}if(!a){r?.recordSnapshot("unavailable",d,c,l);return}let u=new Map;for(let[f,h]of i)u.set(f,Object.freeze(h));return r?.recordSnapshot("completed",d,c,l),u}latchCycle(e,t,n){let o=this.#d(e,t);o.cycleError??=n}getCycle(e,t){return this.#i(e,t).cycleError}#i(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}#d(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 Jt=Object.freeze({kind:"none"});var gt=Symbol("no-committed-selector-baseline");class Ke{#t;#n=new Map;#o=new Map;#s=new Map;#a;#r=1;#i=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new v,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#s.clear(),this.#t=void 0}serve(e,t){let n=this.#c(),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)});return this.#o.set(e,d),d}let r=this.#n.get(e);if(r!==void 0)return r.served;let s=n.run(t,()=>this.#d(o.definition,this,t));if(s.outcome.kind==="control-error")throw s.outcome.error;let i=Object.freeze({token:s.token,outcome:s.outcome});return this.#i++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:i,dependencies:s.dependencies})),i}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#i}getComparisonBaseline(e){let t=this.#s.get(e);if(t===void 0)t=this.#c().baseline(e)??gt,this.#s.set(e,t);return t===gt?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var kt=4096,en=Object.freeze([]);class Rt{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Ee{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;[N]=void 0;#t=new WeakMap;#n;#o=new WeakMap;#s;#a=new WeakMap;#r=new WeakSet;#i=0;#d=0;#c;#l=!1;#f;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#y(),this.#n=this.#y()}get status(){return this.#u}get facade(){if(this.#f===void 0)throw Error("Store scope facade is not installed");return this.#f}installFacade(e){if(this.#f!==void 0)throw Error("Store scope facade is already installed");this.#f=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#y()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#a.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.coordinator.runtimeDomain[_]?.scope(this),this.#n.forEach((t)=>{this.detachAtomView(t),t.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap;let e=this[N]?.size??0;if(e>0)this.coordinator.recordCounter("familyOwnerReleases",e);this[N]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#s=void 0,this.#a=new WeakMap,this.#r=new WeakSet,this.#i++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(J(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){let a=n[_]?.scope(this,e);if(a!==void 0)return a;throw TypeError("Unknown committed StoreTree state")}let r=e,s=this.#o.get(r);if(s!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r,t),s=this.#o.get(r);if(s!==void 0&&!this.#r.has(r))return s.served;let i=Re(n,t,()=>this.coordinator.evaluate(o,this,t));if(i.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw i.outcome.error;return this.#b(r,i,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.#s?.get(n);if(o===void 0){let r=[];for(let i of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(i.node))r.push(i.node);o=Object.freeze(r);let s=this.#s;if(s===void 0)s=new WeakMap,this.#s=s;s.set(n,o)}return o}visitSelectorDependents(e,t,n){return this.#a.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#i}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#d===0)this.#c=[],this.#l=!1;this.#d++;let t=this.#c?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#c;if(o===void 0)return;if(t===o.length)return en;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#d--,this.#d!==0)return;this.#c=void 0,this.#l=!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()}#b(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),s=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess}),i=this.#m(e,o?.dependencies??wt,t.dependencies),a=i?this.#S(e,o?.dependencies??wt,t.dependencies):void 0;if(i)this.#s?.delete(e);if(this.#i++,n.noteSelectorGraphPublication(this),this.#o.set(e,s),this.#r.delete(e),a!==void 0)this.#p(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(t.outcome.error);return r}#m(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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#y(),this.#a.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=kt-o.length,s=this.coordinator.runtimeDomain.selectors,i=new Set;for(let d of t)if(s.has(d.node))i.add(d.node);let a=[];for(let d of n)if(s.has(d.node)&&!i.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#c;if(t===void 0||t.length+e.length>kt){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#y(){return new Rt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var wt=Object.freeze([]);class Ue{transaction=Object.freeze({});#t;#n;#o;#s;#a;#r;#i;#d;#c;#l;#f;#u;#b;#m;#S;#p;#e;#y;#g=!1;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#s!==void 0||this.#a!==void 0||this.#r!==void 0}get hasRows(){return this.#g}installRows(e){let t=this.#y;if(t!==void 0&&t!==e)throw Error();this.#y=e}markRow(e){if(this.#y===void 0)throw Error();if(e!==this.generation)throw Error();this.#g=!0,this.#A()}get singleIntentScope(){return this.#n}get singleIntent(){return this.#s===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let s=n.get(e);if(s===void 0)s=this.#h(),n.set(e,s);s.set(t.atom,t),this.#A();return}let o=this.#a;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let s=this.#h();s.set(this.#n,o);let i=this.#h();i.set(t.atom,t),s.set(e,i),this.#r=s,this.#a=void 0,this.#n=void 0}this.#A();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#A();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#A();return}if(Object.is(this.#n,e)){let s=this.#s;if(s===void 0){this.#s=t,this.#A();return}if(Object.is(s.atom,t.atom)){this.#s=t,this.#A();return}let i=this.#h();i.set(r.atom,r),i.set(s.atom,s),i.set(t.atom,t),this.#a=i}else{let s=this.#h(),i=this.#h();if(i.set(r.atom,r),this.#s!==void 0)i.set(this.#s.atom,this.#s);s.set(this.#n,i);let a=this.#h();a.set(t.atom,t),s.set(e,a),this.#r=s,this.#n=void 0}this.#o=void 0,this.#s=void 0,this.#A()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#s!==void 0)e(this.#n,this.#s);return}let n=this.#a;if(n!==void 0){let r=this.#n;for(let s of n.values())e(r,s);return}let o=this.#r;if(o===void 0)return;for(let[r,s]of o)for(let i of s.values())e(r,i)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#s;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#c!==void 0&&Object.is(this.#i,e)&&Object.is(this.#d,t))return this.#c;if(this.#f!==void 0&&Object.is(this.#i,e)&&Object.is(this.#l,t))return this.#f;if(Object.is(this.#i,e))return this.#u?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let i=o.get(e);if(i===void 0)i=this.#h(),o.set(e,i);if(!i.has(t))i.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let i=this.#h();i.set(this.#i,r);let a=this.#h();a.set(t,n),i.set(e,a),this.#b=i,this.#u=void 0,this.#i=void 0}return}let s=this.#c;if(s===void 0){this.#i=e,this.#d=t,this.#c=n;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t))return;if(Object.is(this.#i,e)){let i=this.#f;if(i===void 0){this.#l=t,this.#f=n;return}if(Object.is(this.#l,t))return;let a=this.#h();a.set(this.#d,s),a.set(this.#l,i),a.set(t,n),this.#u=a}else{let i=this.#h(),a=this.#h();if(a.set(this.#d,s),this.#l!==void 0&&this.#f!==void 0)a.set(this.#l,this.#f);i.set(this.#i,a);let d=this.#h();d.set(t,n),i.set(e,d),this.#b=i,this.#i=void 0}this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#f=void 0}getFallback(e){if(Object.is(this.#m,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#m,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#m=e,this.#S=t;return}if(Object.is(this.#m,e)){this.#S=t;return}let o=this.#h();o.set(this.#m,this.#S),o.set(e,t),this.#p=o,this.#m=void 0,this.#S=void 0}forEachFallback(e){if(this.#m!==void 0&&this.#S!==void 0)e(this.#m,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#A(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){let e=this.#y;this.#y=void 0,this.#g=!1;try{if(this.#a?.clear(),this.#r!==void 0){for(let t of this.#r.values())t.clear();this.#r.clear()}if(this.#u?.clear(),this.#b!==void 0){for(let t of this.#b.values())t.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#s=void 0,this.#a=void 0,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#f=void 0,this.#u=void 0,this.#b=void 0,this.#m=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}finally{e?.(this)}}#h(){return this.#t?.(),new Map}}class Tt{constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.mutate(t,n,"set",o,r),this.update=(o,r)=>e.mutate(t,n,"update",o,r),this.reset=(o)=>e.mutate(t,n,"reset",o),this.delete=(o)=>e.mutate(t,n,"delete",o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),he(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ye=(e,t,n)=>new Tt(e,t,n),Xe=(e)=>{let t=x(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new de},Ct=(e)=>{let t=x(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new de};var tn=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},B=Symbol("definition domain records"),Nn=(e)=>e[B].ownerToken,En=(e,t)=>{let n=e[B],o=n[_];if(o!==void 0)return o;let r=t(n);return n[_]=r,r};var Dn=(e,t,n,o,r,s)=>{let i=e[B],a=new v,d=i.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 u=i[G];i[G]={session:a,definitions:new WeakSet,allowDefinitions:t==="factory",...s===void 0?{}:{createAccessorFault:s}};let f=l.map((h)=>Object.freeze({selectorSession:h,previous:h.setSuppliedReadGuard(()=>{let p=i.activity;return ct(p?.kind==="guarded-callback"?p.session:a,h)})}));try{return q(i,a,()=>{let h=Reflect.apply(n,void 0,o);return r===void 0?h:r(h)})}finally{for(let h=f.length-1;h>=0;h--){let p=f[h];p.selectorSession.setSuppliedReadGuard(p.previous)}if(u===void 0)delete i[G];else i[G]=u}},nn=(e)=>{let t=e[B][G];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 W:t.accessorFault??=t.createAccessorFault();throw t.session.latchControlFault(o),o},Pn=(e)=>ne(e[B]),Vn=nn,xn=(e,t)=>Se(e[B],t),jn=(e,t)=>M(e[B],t,new v),In=(e,t)=>{let n=e[B];if((typeof t==="object"||typeof t==="function")&&t!==null&&n.states.has(t)&&(n.atoms.has(t)||n.selectors.has(t))){if(n[G]?.definitions.has(t)||n[ge]?.has(t))return t;return}M(n,t,new v);return},Mn=(e,t)=>{let n=e[B];if((n[ge]??(n[ge]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[N]??(n[N]=new WeakSet)).add(t)},jt=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}),on=35,It=new WeakMap,Fn=()=>{let e=new Uint32Array(on),t=Object.freeze({read(n){return e[jt[n]]??0}});return It.set(t,e),t},D=(e)=>Object.freeze({kind:"value",value:e}),rn=(e)=>Object.freeze({kind:"error",error:e}),Ot=(e)=>e.kind==="value"?D(e.value):rn(e.error),pe=(e,t)=>e[_]?.has(t)?e[_]:void 0,Nt=(e,t,n,o)=>{let r=e.read(t,n,o);if(r.kind!=="value")throw r.error;return r.value},Et=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},Dt=1,Qe=2,Pt=4,sn=(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}),Ze=(e)=>(e.onAllocation?.(),new Map),an=(e)=>(e.onAllocation?.(),new Set),$e=(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)},Vt=(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=Ze(e),e.preflight=r;let s=r.get(t);if(s===void 0)s=Ze(e),r.set(t,s);s.set(n,o)},dn=(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=an(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},cn=(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=Ze(e),e.affected=o;o.set(t,n)};class Mt{#t=new WeakMap;#n;#o=1;#s=0;#a=!1;#r;#i;#d;#c=0;#l;#f;#u;#b=1;#m=0;#S;#p;#e;#y;#g;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:It.get(t),this.#g=n,this.evaluate=n?.evaluate??vt,this.#n=new Ee(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[jt[e]]+=t}#A(){return this.recordCounter("draftCreations"),new Ue(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new v,o=t,r=M(this.#e,o,n),s=qe(this.#e,"StoreTree.get");if(this.#v(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(s===void 0){let i=e.serveKnownLocal(o,n);if(i.outcome.kind!=="value")throw i.outcome.error;return i.outcome.value}try{let i=e.serveKnownLocal(o,n);if(i.outcome.kind!=="value"){if(i.outcome.kind==="control-error")s.latchControlFault(i.outcome.error);throw i.outcome.error}return i.outcome.value}catch(i){let a=n.getControlFault();if(a.kind==="fault")s.latchControlFault(a.error);throw i}}sub(e,t,n){let o=t,r,s=this.#e.states.has(o)?"local":M(this.#e,o,r=new v);if(I(this.#e,"StoreTree.sub"),this.#v(e),s==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o)&&!pe(this.#e,o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let i=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new v);if(i.outcome.kind==="control-error")throw i.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return tn(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;lt(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let s=this.#u,i=s?.get(t.scope);if(i?.get(t.state)===t){if(i.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(i!==void 0&&i.size===0){if(s?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(s?.size===0)this.#u=void 0}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)M(this.#e,n,new v);if(I(this.#e,"StoreTree.scope"),this.#v(e),t===0)return this.#D(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#D(e,n)}dispose(e){if(I(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let s=[];o.children.forEach((i)=>s.push(i));for(let i=s.length-1;i>=0;i--)n.push(Object.freeze({node:s[i],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#H(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(I(this.#e,"StoreTree.txn"),this.#v(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#A(),r=Ye(this,o,e),s;try{s=dt(this.#e,o.transaction,()=>t(r))}catch(i){throw o.close(),o.release(),i}o.close();try{let i=new v;Te(this.#e,i,()=>Xe(s)),this.#V(o)}finally{o.release()}return s}readHydrationSnapshot(e,t){let n=new v,o=t,r=M(this.#e,o,n);I(this.#e,"adapter readHydrationSnapshot"),this.#v(e);let s,i;if(r!=="invalid")if(this.#e.atoms.has(o))s=0;else if(this.#e.selectors.has(o))s=1;else i=pe(this.#e,o);if(s===void 0&&!i)throw TypeError("readHydrationSnapshot requires a valid State");let a=this.#A(),d;try{if(s===0){let c=this.#w(a,e,o,n);if(c.kind!=="value")throw c.error;return c.value}if(s===void 0)return Nt(i,a,e,o);return d=this.#h(a,e,!0),d.readSelector(o)}finally{d?.revoke(),a.close(),a.forEachFallback((c,l)=>{if(this.#t.has(c))return;this.#t.set(c,l),this.recordCounter("fallbackPublications")}),a.release()}}transactionGet(e,t,n){let o=n,r=new v,s=M(this.#e,o,r);if(Ce(this.#e,e.transaction,e.active),this.#v(t),s==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#w(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o)){let a=pe(this.#e,o);if(!a)throw TypeError("Transaction.get requires a readable State");return Nt(a,e,t,o)}let i=e.getScratchHost(t);if(i===void 0){if(i=this.#h(e,t),e.installScratchHost(t,i))this.recordCounter("scratchMapAllocations")}return i.readSelector(o)}mutate(e,t,n,o,r){let s=o,i=new v,a=`${e===void 0?"StoreTree":"Transaction"}.${n}`,d=M(this.#e,s,i);if(e===void 0)I(this.#e,a);else Ce(this.#e,e.transaction,e.active);this.#v(t);let c=d==="local"&&this.#e.atoms.has(s),l;if(c?n==="delete":d!=="local"||typeof s==="function"||(l=pe(this.#e,s))===void 0)throw TypeError(`${a} requires a valid State`);let f=e===void 0,h=e??this.#A();try{if(l!==void 0)l.stage(h,t,n,s,r,i);else if(n==="set")this.#G(h,t,s,r,i);else if(n==="update")this.#W(h,t,s,r,i,a);else this.#q(h,t,s,i)}catch(p){if(f)h.close(),h.release();throw p}if(!f)return;h.close();try{this.#V(h)}finally{h.release()}}transactionScope(e,t,n,o,r){let s=new v;if(typeof n!=="string")M(this.#e,n,s);Ce(this.#e,e.transaction,e.active),this.#v(t);let i=this.#L(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ye(this,e,i);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 u=new v;return Te(this.#e,u,()=>Ct(l))}let c=new v;return Te(this.#e,c,()=>Xe(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#h(e,t,n=!1){return this.recordCounter("scratchHostAllocations"),new Ke(Object.freeze({resolve:(o,r)=>this.#B(o,r),read:(o,r,s)=>this.#K(e,t,o,r,s),baseline:n?()=>{return}:(o)=>t.captureCommittedSelectorSuccess(o),run:(o,r)=>Re(this.#e,o,r)}),e.generation,this.evaluate)}#B(e,t){if(J(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n!==void 0)return Object.freeze({kind:"selector",definition:n});if(pe(this.#e,e))return Object.freeze({kind:"ext"});throw TypeError("Unknown scratch StoreTree State")}#D(e,t){let n=new Ee(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Je(this,n,this.#g);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#L(e,t){if(typeof t==="string"){let s=e.namedChildren.get(t);if(s===void 0)throw new He;return this.#v(s),s}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let s=o;if(this.#v(s),!Object.is(s.coordinator,this))throw new Ge;return s}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ke;throw new we}throw new we}#v(e){if(e.status!=="live")throw new Le}#H(e){let t=this.#u,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let s=r.head;while(s!==void 0){let i=s.next;s.callback=void 0,s.target=void 0,s.previous=void 0,s.next=void 0,o++,s=i}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#u=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#G(e,t,n,o,r){let s=q(this.#e,r,()=>ue(o));if(s.kind==="error")throw s.error;let i=this.#C(e,t,n,r);this.#_(e,t,n,s.value,i,r)}#W(e,t,n,o,r,s){if(typeof o!=="function")throw TypeError(`${s} requires an updater function`);let i=this.#C(e,t,n,r),a=e.hasIntents?this.#w(e,t,n,r):i.outcome;if(a.kind!=="value")throw a.error;let d=this.#X(o,a.value,r);this.#_(e,t,n,d,i,r)}#q(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#O(e,n,o),reachesFallback:!0}):this.#P(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let s=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:s}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let s=t.atomOverrides.has(n),i=t,a;while(i!==void 0){if(i.atomOverrides.has(n)){a=D(i.atomOverrides.get(n));break}i=i.parent}let d=a===void 0,c=Object.freeze({owned:s,outcome:a??this.#O(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#w(e,t,n,o){return this.#P(e,t,n,o).outcome}#K(e,t,n,o,r){if(o==="atom")return this.#w(e,t,n,r);return this.#e[_].read(e,t,n)}#P(e,t,n,o){let r=t;while(r!==void 0){let s=e.getIntent(r,n);if(s?.kind==="set")return Object.freeze({outcome:D(s.value),reachesFallback:!1});if(s===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:D(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#O(e,n,o),reachesFallback:!0})}#O(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#k(t);if(r.fallback.kind==="eager")return D(r.fallback.value);let s=r.fallback.initialize,i=e.getFallback(t);if(i!==void 0)return i;let a=Ot(q(this.#e,n,()=>We(s)));return e.setFallback(t,a),a}#U(e,t,n,o){let r=this.#k(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Y(r,t,n,o)?t:n}#Y(e,t,n,o){return q(this.#e,o,()=>{let r;try{r=e(t,n)}catch(i){let a=x(i);if(a.kind==="not-thenable")throw i;if(a.kind==="inspection-error")throw a.error;throw j(a),new le}let s=x(r);if(s.kind==="inspection-error")throw s.error;if(s.kind==="thenable")throw j(s),new le;if(r!==!0&&r!==!1)throw new le;return r})}#X(e,t,n){return q(this.#e,n,()=>{let o;try{o=e(t)}catch(s){let i=x(s);if(i.kind==="not-thenable")throw s;if(i.kind==="inspection-error")throw i.error;throw j(i),new ce}let r=ue(o);if(r.kind==="error")throw r.error;return r.value})}#V(e){let t;if(e.hasRows){if(t=this.#e[_]?.plan(e),t===void 0)throw Error()}if(!e.hasIntents&&t===void 0)return;let{singleIntent:n,singleIntentScope:o}=e;if(t===void 0&&n?.kind==="reset"&&o!==void 0&&!n.publishDraftFallback&&e.getAtomBaseline(o,n.atom)?.owned===!1)return;let r=sn(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),s,i;if(n!==void 0&&o!==void 0)s=this.#x(e,o,n,r);else e.forEachIntent((d,c)=>{let l=this.#x(e,d,c,r);if(s===void 0){s=l;return}if(i===void 0)i=[];i.push(l)});if(this.#g?.(1,e,this.#e.atoms),s!==void 0)this.#j(e,s);if(i!==void 0)for(let d of i)this.#j(e,d);let a=s===void 0?!1:this.#I(s);if(i!==void 0)for(let d of i){let c=this.#I(d);a||=c}if(t!==void 0){let d=t.commit(0);a||=d}if(s!==void 0)this.#M(s);if(i!==void 0)for(let d of i)this.#M(d);if(t!==void 0)t.commit(1);this.#ne();try{let d,c,l=r.affectedRecord,u=r.affectedBefore;if(l!==void 0&&u!==void 0)d=this.#N(r,l,u);let{secondAffectedRecord:f,secondAffectedBefore:h}=r;if(f!==void 0&&h!==void 0){let p=this.#N(r,f,h);if(p!==void 0)if(d===void 0)d=p;else c=[p]}if(r.affected!==void 0)for(let[p,m]of r.affected){let y=this.#N(r,p,m);if(y===void 0)continue;if(d===void 0)d=y;else{if(c===void 0)c=[];c.push(y)}}if(t!==void 0){let p=t.commit(2);if(p!==void 0)for(let m of p){let y=m;if(d===void 0)d=y;else{if(c===void 0)c=[];c.push(y)}}}if(a)this.#s+=1,this.recordCounter("sourceEpoch");this.#g?.(2,d===void 0?0:1+(c?.length??0)),this.#te(d,c)}catch(d){throw this.#R(),d}}#x(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#F(e,t,n.atom,o);let s=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),i=t.getAtomView(n.atom);if(i!==void 0)this.#Q(e,i,o);return s}#j(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#I(e){let{intent:t,scope:n}=e;if(t.kind==="set"){if(n.atomOverrides.set(t.atom,t.value),this.#e[N]?.has(t.atom)){let o=n[N];if(o===void 0)o=new Set,n[N]=o,this.recordCounter("familyOwnerRetentionSetsCreated");let r=o.size;if(o.add(t.atom),o.size!==r)this.recordCounter("familyOwnerRetains")}}else{n.atomOverrides.delete(t.atom);let o=n[N];if(o?.delete(t.atom))this.recordCounter("familyOwnerReleases");if(o?.size===0)n[N]=void 0}return e.ownershipChanged}#M({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.#J(e.parent,t.atom))}#N(e,t,n){let o=$e(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),Et(n,o))return;return t.scope.updateAtomView(t,o),t}#Q(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!dn(n,r))continue;let s=r.served.outcome,i=this.#F(e,r.scope,r.atom,n);if(Et(s,i))continue;cn(n,r,s);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),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}}}#F(e,t,n,o){let r=$e(o,n,t);if(r!==void 0)return r;let s=t,i,a,d;while(s!==void 0){let c=$e(o,n,s);if(c!==void 0){d=c;break}if(i===void 0)i=s;else{if(a===void 0)a=[];a.push(s)}let l=e.getIntent(s,n);if(l?.kind==="set"){d=D(l.value);break}if(l===void 0&&s.atomOverrides.has(n)){d=D(s.atomOverrides.get(n));break}s=s.parent}if(d??=this.#$(e,n),i!==void 0)Vt(o,n,i,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)Vt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#$(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.#k(t);if(r.fallback.kind==="eager")return D(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#Z(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#k(e);if(n.fallback.kind==="eager")return D(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#J(e,t){let n=e,o=[],r;while(!0){let s=n.getAtomView(t);if(s!==void 0){r=s;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,D(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#Z(t));break}o.push(n),n=n.parent}for(let s=o.length-1;s>=0;s--)r=o[s].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],s;while(!0){let i=o.getAtomView(t);if(i!==void 0){s=i;break}if(o.atomOverrides.has(t)){s=o.createAtomView(t,D(o.atomOverrides.get(t)));break}if(o.parent===void 0){s=o.createAtomView(t,this.#ee(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let i=r.length-1;i>=0;i--)s=r[i].createAtomView(t,s.served.outcome,s);return s.served}#ee(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#k(e);if(o.fallback.kind==="eager")return D(o.fallback.value);let r=o.fallback.initialize,s=Ot(q(this.#e,t,()=>We(r)));return this.#t.set(e,s),this.recordCounter("fallbackPublications"),s}#k(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#te(e,t){if(e===void 0){this.#R();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0,this.#f=void 0,this.#a=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],s=this.#r[o++];this.#E(r,s)}}finally{n=this.#f,this.#f=void 0,this.#a=!1,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#oe(n)}#ne(){this.#S=void 0,this.#p=void 0,this.#m=this.#u===void 0?0:this.#b++}#R(){this.#m=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#m,o=this.#u?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#oe(e){let t=this.#S;if(t===void 0){if(this.#R(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let u=l.callback;if(u!==void 0)if(n===void 0)n=u;else if(o===void 0)o=[n,u];else o.push(u);l=l.next}};r(t);let s=this.#p;if(s!==void 0)for(let c of s)r(c);if(this.#R(),n===void 0){if(e!==void 0)throw e;return}let i=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let d;for(let c of i){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new v,u=!1,f;try{at(this.#e,l,()=>{try{let h=c(),p=x(h);if(p.kind==="thenable")j(p);else if(p.kind==="inspection-error")u=!0,f=p.error}catch(h){u=!0,f=h;let p=x(h);if(p.kind==="thenable")j(p)}})}catch(h){u=!0,f=h}if(u){if(d===void 0)d=[];if(d.push(f),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Be(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#z(e,t)&Dt)!==0)return!0;return this.#T(e,t,Dt),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#E(e,t,n)}#E(e,t,n){if((this.#z(e,t)&(Pt|Qe))!==0)return;this.#T(e,t,Qe);try{let r=e.getSelectorGraphVersion(),s=e.getCommittedSelectorDependencies(t);if(s!==void 0){for(let i of s)if(this.#e.selectors.has(i.node))this.#E(e,i.node)}if(e.isSelectorDirty(t)){let i=r===e.getSelectorGraphVersion();if(n!==void 0&&i)e.serve(t,n);else e.serve(t,new v)}this.#T(e,t,Pt)}finally{this.#T(e,t,0,Qe)}}#z(e,t){if(Object.is(this.#i,e)&&Object.is(this.#d,t))return this.#c;return this.#l?.get(e)?.get(t)??0}#T(e,t,n,o=0){if(this.#i===void 0){this.#i=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t)){this.#c=(this.#c|n)&~o;return}let r=this.#l;if(r===void 0)r=new Map,this.#l=r;let s=r.get(e);if(s===void 0)s=new Map,r.set(e,s);s.set(t,((s.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#f??=e}#_(e,t,n,o,r,s){let i=r.outcome.kind==="value"?this.#U(n,r.outcome.value,o,s):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:i,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class Je{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),he(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var xt=(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}}},Ft=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,l={})=>{ne(t);let u=new v,f=q(t,u,()=>ue(c));if(f.kind==="error")throw f.error;let h=Se(t,Oe("atom"));return t.atoms.set(h,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...xt(l)})),h},o=(c,l={})=>{if(ne(t),typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let u=Se(t,Oe("atom"));return t.atoms.set(u,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...xt(l)})),u},r=(c,l={})=>{if(ne(t),typeof c!=="function")throw TypeError("selector requires a getter function");if(l.equal!==void 0&&typeof l.equal!=="function")throw TypeError("selector equal must be a function");let u=Se(t,Oe("selector")),f=Object.freeze({node:u,get:c,...l.name===void 0?{}:{name:l.name},...l.equal===void 0?{}:{equal:l.equal}});return t.selectors.set(u,f),u},s=(c)=>{let l=new v;if(M(t,c,l)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let l=s(c);if(I(t,"adapter assertStore"),l===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,l)=>{if(s(c)===void 0)throw qe(t,"adapter read"),TypeError("read requires a valid Store");return c.get(l)},subscribe:(c,l,u)=>{if(s(c)===void 0)throw I(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(l,u)},readHydrationSnapshot:(c,l)=>{let u=s(c);if(u===void 0)throw I(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return u.coordinator.readHydrationSnapshot(u,l)}});return Object.freeze({[B]:t,atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,l)=>{I(t,"createStoreTree");let u=new Mt(t,c,l);return new Je(u,u.rootScope,l)}})};var ln=Ft(),Bn=(e,t)=>ln.createStoreTree(e,t);
|
|
2
|
+
export{ae as B,$t as C,vt as D,_ as E,_e as F,Be as G,W as H,ee as I,te as J,ke as K,de as L,ce as M,le as N,Le as O,He as P,Ge as Q,we as R,x as S,j as T,q as U,Rt as V,Nn as W,En as X,Dn as Y,nn as Z,Pn as _,Vn as $,xn as aa,jn as ba,In as ca,Mn as da,Fn as ea,ln as fa,Bn as ga};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=35,O=36,T=37,_=38,C=39,I=40,L=41,N=42,o=43,t=44,R=45,S=46,c=47,e=48,n=64,p=65,r=66,s=67,x=68,A=69,M=70,D=71,P=72,H=73,B=74,W=75,F=76;
|
|
2
|
+
export{E as a,O as b,T as c,_ as d,C as e,I as f,L as g,N as h,o as i,t as j,R as k,S as l,c as m,e as n,n as o,p,r as q,s as r,x as s,A as t,M as u,D as v,P as w,H as x,B as y,W as z,F as A};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,d as a,e as n,f as l,g as p,h as c,i,j as s,k as u,l as y,m as v,n as E,o as m,p as S,r as t}from"./chunk-y5ja7h9m.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=l,g=y,D=u,O=s,M=S,N=a,q=E,P=p,z=o,w=v,U=m,G=n,j=i,L=c;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
|
|
1
|
+
import{A as Gn,a as Tn,b as On,c as Mn,d as xe,e as Vn,f as le,g as z,h as we,i as In,j as xn,k as Nn,l as Dn,m as Kn,n as Ne,o as Ln,p as Pn,q as Fn,r as An,s as jn,t as Hn,u as Bn,v as _n,w as zn,x as Wn,y as qn,z as Un}from"./chunk-kr7hrpvx.js";import{$ as to,B as He,F as Be,G as _e,H as ze,I as We,J as qe,K as Ue,L as Ge,M as Ye,N as Ze,O as Je,P as Qe,Q as Xe,R as $e,S as ke,T as Fe,U as Jn,V as ce,W as Ae,X as Qn,Y as Ee,Z as je,_ as Xn,aa as Ke,ba as $n,ca as ro,da as io,fa as q}from"./chunk-dab744dc.js";var Io={ref:(t)=>new WeakRef(t),registry:(t)=>{let l=new FinalizationRegistry(t);return Object.freeze({register:(s,u,m)=>l.register(s,u,m),unregister:(s)=>l.unregister(s)})}};class ae{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(t,l,s=Io,u){this.#o=t,this.#t=u,this.#r=l,this.#n=s.registry((m)=>{let k=m.route;if(k.entry!==m)return;k.entry=void 0,this.#c(k)}),this.#i=(m)=>s.ref(m)}#i;getOrCreateOne(t,l){return this.#a(this.#l(this.#e,t),l)}getOrCreateTuple(t,l){let s=this.#e;for(let u=0;u<t.length;u++)s=this.#l(s,t[u]);return this.#a(s,l)}get routeCount(){let t=0,l=(s)=>{if(s.children===void 0)return;for(let u of s.children.values())t++,l(u)};return l(this.#e),t}hasRoute(t){let l=this.#e;for(let s=0;s<t.length;s++){let u=l.children?.get(t[s]);if(u===void 0)return!1;l=u}return!0}#l(t,l){let s=t.children??(t.children=new Map),u=s.get(l);if(u!==void 0)return u;return u={parent:t,parentKey:l,children:void 0,entry:void 0},s.set(l,u),u}#a(t,l){let s=t.entry;if(s?.kind==="ready"){let m=s.reference.deref();if(m!==void 0)return m;if(this.#n.unregister(s),t.entry===s)t.entry=void 0}else if(s?.kind==="building"){let m=s.fault??this.#r();throw s.fault=m,m}let u={kind:"building",route:t,fault:void 0};t.entry=u;try{let m=this.#o(l);if(u.fault!==void 0)throw u.fault;this.#t?.(m);let k={kind:"ready",route:t,reference:this.#i(m)};return t.entry=k,this.#n.register(m,k,k),m}catch(m){if(t.entry===u)t.entry=void 0;throw this.#c(t),u.fault??m}}#c(t){let l=t;while(l.parent!==void 0&&l.entry===void 0&&(l.children===void 0||l.children.size===0)){let s=l.parent,u=s.children;if(u?.get(l.parentKey)!==l)return;if(u.delete(l.parentKey),u.size===0)s.children=void 0;l=s}}}var bn={kind:"not-thenable"},xo=()=>{},hn=(t)=>{if((typeof t!=="object"||t===null)&&typeof t!=="function")return bn;try{let l=t.then;return typeof l==="function"?Object.freeze({kind:"thenable",target:t,then:l}):bn}catch(l){return Object.freeze({kind:"inspection-error",error:l})}},Cn=(t)=>{try{Reflect.apply(t.then,t.target,[void 0,xo])}catch{}throw TypeError("Definition callbacks must complete synchronously")},wn=(t,l,s,u,m)=>t(l,(...k)=>{let L;try{L=Reflect.apply(s,void 0,k)}catch(P){let j=hn(P);if(j.kind==="not-thenable")throw P;if(j.kind==="inspection-error")throw j.error;return Cn(j)}let y=hn(L);if(y.kind==="not-thenable")return L;if(y.kind==="inspection-error")throw y.error;return Cn(y)},u,m),No=()=>TypeError("family cannot recursively construct the same member"),Ie=(t)=>t===null||t===void 0||typeof t!=="object"&&typeof t!=="function",Rn=()=>TypeError("family keys must be primitive; use encodeKey for structured arguments"),Do=()=>TypeError("family encodeKey must return one primitive FamilyKey"),Ko=()=>TypeError("family members require at least one key"),Sn=(t,l,s,u,m,k)=>{let L,y=new ae((j)=>wn(s,"factory",t,j,u),No,void 0,m),P={family(j){let x=arguments,F=L;if(F!==void 0){let A=F.fault??TypeError("family encodeKey cannot call its own family");throw F.fault=A,A}if(k(),x.length===0)throw Ko();if(l!==void 0){let A={fault:void 0};L=A;let me;try{me=wn(s,"encoder",l,x)}catch(Q){throw A.fault??Q}finally{L=void 0}if(A.fault!==void 0)throw A.fault;if(!Ie(me))throw Do();return y.getOrCreateOne(me,x)}if(x.length===1){if(!Ie(j))throw Rn();return y.getOrCreateOne(j,x)}for(let A=0;A<x.length;A++)if(!Ie(x[A]))throw Rn();return y.getOrCreateTuple(x,x)}}.family;return Object.freeze(P)};var J=Symbol("collection baseline birth");class Se extends Error{seal(){Object.freeze(this)}}class ue extends Se{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class fe extends Se{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class pe extends Se{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var se=Object.freeze({kind:"none"}),Re=Object.freeze({kind:"absent"}),W=Object.freeze({kind:"absent"}),oe=Object.freeze([]),de=(t)=>Object.freeze({kind:"present",value:t}),Y=(t)=>Object.freeze({kind:"present",value:t}),De=(t,l)=>t.kind===l.kind&&(t.kind==="absent"||l.kind==="present"&&Object.is(t.value,l.value)),kn=(t,l)=>t.kind===l.kind&&(t.kind!=="present"||l.kind==="present"&&Object.is(t.value,l.value)),te=(t)=>{let l=t.local.kind==="present"?de(t.local.value):t.local.kind==="absent"?Re:se,s=t.effective.kind==="present"?Y(t.effective.value):W,u=t.inherited.kind==="present"?Y(t.inherited.value):W;if(l.kind==="none"&&!De(s,u))throw Error("Collection baseline without local ownership must equal inherited outcome");if(l.kind==="present"&&(s.kind!=="present"||!Object.is(l.value,s.value)))throw Error("Collection present local baseline must equal its effective outcome");if(l.kind==="absent"&&s.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:l,effective:s,inherited:u})},En=(t)=>{let l=t.final;if(l===void 0)return t.baseline.local;if(l.kind==="present")return de(l.value);return l.kind==="absent"?Re:se},vn=(t,l)=>t.kind==="present"?Y(t.value):t.kind==="absent"?W:l,gn=(t)=>Object.freeze({kind:"value",value:t.kind==="present"?t.value:void 0}),Yn=(t,l)=>{let s=new WeakMap,u=new WeakMap,m,k,L=(n)=>n.coordinator?.evaluate?.recordExtension,y=(n,e,o=1)=>{L(n)?.(e,o)},P=(n,e,o,r)=>{L(n)?.(e,n,o,r)},j=(n,e,o)=>{if(e.length!==o.length)return!1;let r=L(n);if(r===void 0){for(let i=0;i<e.length;i++)if(!Object.is(e[i],o[i]))return!1;return!0}for(let i=0;i<e.length;i++)if(!Object.is(e[i],o[i]))return r(z,i+1),!1;if(e.length)r(z,e.length);return!0},x=(n)=>{let e=u.get(n);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},u.set(n,e),e},F=(n,e)=>u.get(n)?.rowLocals?.get(e)??se,A=(n,e)=>{let o=n;while(o!==void 0){let r=F(o,e);if(r.kind==="present")return Y(r.value);if(r.kind==="absent")return W;o=o.parent}return W},Q=l??((n,e)=>{let o=F(n,e),r=A(n.parent,e);return Object.freeze({local:o,effective:vn(o,r),inherited:r})}),yo=(n,e,o,r)=>{let i=n.byScope.get(e)?.get(o);if(i!==void 0)return En(i);return te(Q(e,o,r)).local},U=(n,e,o,r)=>{let i=e;while(i!==void 0){let a=yo(n,i,o,r);if(a.kind==="present")return Y(a.value);if(a.kind==="absent")return W;if(l!==void 0){let d=n.byScope.get(i)?.get(o);if(d!==void 0)return d.baseline.inherited;return te(Q(i,o,r)).inherited}i=i.parent}return W},mo=(n,e,o,r)=>{if(l!==void 0){let I=te(Q(e,o,r)),O=I.effective.kind==="present",T=O?J:void 0;for(let D of n.byRow.get(o)?.historyByScope.get(e)??[]){if(!Object.is(D.row,o)||!Object.is(D.scope,e))continue;let B=D.kind==="present"||D.kind==="reset"&&I.inherited.kind==="present";if(!O&&B)T=D.sequence;else if(!B)T=void 0;O=B}return T}let i=[],a=new Map,d=e;while(d!==void 0)i.push(d),a.set(d,te(Q(d,o,r)).local.kind),d=d.parent;let f=[],w=n.byRow.get(o);if(w!==void 0){for(let I of i){let O=w.historyByScope.get(I);if(O!==void 0)f.push(...O)}f.sort((I,O)=>I.sequence-O.sequence)}let K=()=>{for(let I of i){let O=a.get(I);if(O==="present")return!0;if(O==="absent")return!1}return!1},M=K(),N=M?J:void 0;for(let I of f){a.set(I.scope,I.kind==="present"?"present":I.kind==="absent"?"absent":"none");let O=K();if(!M&&O)N=I.sequence;else if(!O)N=void 0;M=O}return N},ve=(n,e,o,r)=>{let i=x(n),a=i.rowViews?.get(e);if(a!==void 0)return a;let d={scope:n,atom:e,served:Object.freeze({token:n.createOutcomeToken(),outcome:gn(o)}),inheritedFrom:r,inheritingChildren:new ce(()=>n.coordinator.recordCounter("deadRouteCompactions"))},f=i.rowViews;if(f===void 0)f=new WeakMap,i.rowViews=f;let w=i.liveRowViews;if(w===void 0)w=new ce(()=>n.coordinator.recordCounter("deadRouteCompactions")),i.liveRowViews=w;if(f.set(e,d),w.add(d),P(n,Un,e,t.lookupRow(e)),r!==void 0)r.inheritingChildren.add(d),n.coordinator.recordCounter("routeAdds");return d},en=(n,e)=>{let o=n,r=[],i;while(!0){y(o,xe);let a=u.get(o),d=a?.rowViews?.get(e);if(d!==void 0){i=d;break}let f=a?.rowLocals?.get(e);if(f!==void 0){i=ve(o,e,f.kind==="present"?Y(f.value):W);break}if(o.parent===void 0){i=ve(o,e,W);break}r.push(o),o=o.parent}for(let a=r.length-1;a>=0;a--)i=ve(r[a],e,i.served.outcome.kind==="value"&&i.served.outcome.value!==void 0?Y(i.served.outcome.value):W,i);return i},ge=(n)=>{let e=n.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(n),n.inheritedFrom=void 0,n.scope.coordinator.recordCounter("routeRemoves")},bo=(n,e)=>{if(Object.is(n.inheritedFrom,e))return;ge(n),n.inheritedFrom=e,e.inheritingChildren.add(n),n.scope.coordinator.recordCounter("routeAdds")},be=(n)=>n.served.outcome.kind==="value"?n.served.outcome.value:oe,Te=(n,e)=>{if(e.length)y(n,z,e.length);let o=Object.freeze([...e]);return y(n,we),o},he=(n,e,o=n.createOutcomeToken())=>Object.freeze({token:o,outcome:Object.freeze({kind:"value",value:e})}),Oe=(n,e,o,r=!1)=>{let i=x(n),a=i.memberships?.get(e);if(a!==void 0)return a;let d={scope:n,atom:e,served:he(n,o,r?oe:void 0),inheritedFrom:void 0,inheritingChildren:new ce(()=>n.coordinator.recordCounter("deadRouteCompactions"))},f=i.memberships;if(f===void 0)f=new WeakMap,i.memberships=f;let w=i.liveMemberships;if(w===void 0)w=new ce(()=>n.coordinator.recordCounter("deadRouteCompactions")),i.liveMemberships=w;return f.set(e,d),w.add(d),y(n,Vn),P(n,Gn,e),d},nn=(n)=>{let e=n.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(n),n.inheritedFrom=void 0,n.scope.coordinator.recordCounter("routeRemoves")},on=(n,e)=>{if(Object.is(n.inheritedFrom,e))return;nn(n),n.inheritedFrom=e,e.inheritingChildren.add(n),n.scope.coordinator.recordCounter("routeAdds")},tn=(n,e)=>{let o=n,r=[],i;while(!0){y(o,le);let a=u.get(o)?.memberships?.get(e);if(a!==void 0){if(i=a,i.served.token===oe){let d=Te(o,be(i));i.served=he(o,d)}break}if(o.parent===void 0){i=Oe(o,e,Te(o,oe));break}r.push(o),o=o.parent}for(let a=r.length-1;a>=0;a--){let d=r[a],f=Te(d,be(i)),w=Oe(d,e,f);on(w,i),i=w}return i},ho=(n)=>{let e=n,o=s.get(e);if(o===void 0)return;s.delete(e);for(let r of o.byScope.values()){for(let i of r.values())i.final=void 0,i.finalOperation=void 0;r.clear()}o.byScope.clear(),o.planOrder.length=0,o.history.length=0;for(let r of o.historyByCollectionScope.values()){for(let i of r.values())i.length=0;r.clear()}o.historyByCollectionScope.clear();for(let r of o.byRow.values()){for(let i of r.coordinatesByAncestor.values())i.length=0;r.coordinatesByAncestor.clear();for(let i of r.historyByScope.values())i.length=0;r.historyByScope.clear()}o.byRow.clear(),o.revisionByCollection.clear();for(let r of o.membershipMemo.values())r.clear();o.membershipMemo.clear()},re=(n)=>{let e=s.get(n);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},n.installRows(ho),s.set(n,e),e},Me=(n)=>{let e=t.lookupRow(n);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},Co=(n,e)=>{n.revisionByCollection.set(e,(n.revisionByCollection.get(e)??0)+1)},ee=(n,e,o,r=Me(o))=>{let i=re(n),a=i.byScope.get(e);if(a===void 0)a=new Map,i.byScope.set(e,a);let d=a.get(o);if(d!==void 0)return d;if(k!==void 0)k.coordinates++;let f=te(Q(e,o,r)),w=l===void 0?U(i,e.parent,o,r):f.inherited,K=te({local:f.local,effective:vn(f.local,w),inherited:w});d={scope:e,row:o,collection:r,baseline:K,discoveryIndex:i.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},a.set(o,d);let M=i.byRow.get(o);if(M===void 0)M={coordinatesByAncestor:new Map,historyByScope:new Map},i.byRow.set(o,M);let N=e;while(N!==void 0){let I=M.coordinatesByAncestor.get(N);if(I===void 0)I=[],M.coordinatesByAncestor.set(N,I);I.push(d),N=N.parent}return d.enablingBirth=mo(i,e,o,r),d},Ce=(n,e,o,r,i,a)=>{let d=En(e),f=re(n),w=U(f,e.scope,e.row,e.collection);if(kn(d,i)&&De(w,a))return;if(!f.hasAcceptedIntent)f.hasAcceptedIntent=!0,y(e.scope,On);y(e.scope,Tn);let K=[];for(let H of f.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let _=U(f,H.scope,H.row,H.collection);K.push({coordinate:H,effective:_,placement:_.kind==="present"?H.enablingBirth:void 0})}let M=n.generation;if(e.planIndex===void 0)e.planIndex=f.planOrder.length,f.planOrder.push(e);e.final=r,e.finalOperation=o;let N=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:r.kind,sequence:M});f.history.push(N);let I=f.byRow.get(e.row),O=I.historyByScope.get(e.scope);if(O===void 0)O=[],I.historyByScope.set(e.scope,O);O.push(N);let T=f.historyByCollectionScope.get(e.collection);if(T===void 0)T=new Map,f.historyByCollectionScope.set(e.collection,T);let D=T.get(e.scope);if(D===void 0)D=[],T.set(e.scope,D);D.push(N);let B=!1;for(let H of K){let _=H.coordinate,ie=U(f,_.scope,_.row,_.collection);if(H.effective.kind==="absent"&&ie.kind==="present")_.enablingBirth=M;else if(ie.kind==="absent")_.enablingBirth=void 0;let Ve=ie.kind==="present"?_.enablingBirth:void 0;if(!Object.is(H.placement,Ve))B=!0}if(B)Co(f,e.collection);n.markRow(M)},rn=()=>new ue,ln=(n)=>{let e=t.inspectThenable(n);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw t.containThenable(e),rn();if(n===void 0)throw new fe;return n},wo=(n,e,o)=>t.runGuarded(o,()=>{let r;try{r=Reflect.apply(n,void 0,[e])}catch(i){let a=t.inspectThenable(i);if(a.kind==="not-thenable")throw i;if(a.kind==="inspection-error")throw a.error;throw t.containThenable(a),rn()}return ln(r)}),an=(n,e,o,r,i)=>{let a=Me(o),d=t.runGuarded(i,()=>ln(r)),f=ee(n,e,o,a);Ce(n,f,"set",Object.freeze({kind:"present",value:d}),de(d),Y(d))},cn=(n,e,o,r,i)=>{let a=Me(o);if(typeof r!=="function")throw TypeError("Collection row update requires an updater");let d=ee(n,e,o,a),f=U(re(n),e,o,a);if(f.kind==="absent")throw new pe;let w=wo(r,f.value,i);Ce(n,d,"update",Object.freeze({kind:"present",value:w}),de(w),Y(w))},sn=(n,e,o)=>{let r=ee(n,e,o);Ce(n,r,"delete",Object.freeze({kind:"absent"}),Re,W)},dn=(n,e,o)=>{let r=ee(n,e,o),i=l===void 0?U(re(n),e.parent,o,r.collection):r.baseline.inherited;Ce(n,r,"reset",Object.freeze({kind:"reset"}),se,i)},un=(n,e,o)=>{let r=ee(n,e,o),i=U(re(n),e,o,r.collection);return i.kind==="present"?i.value:void 0},fn=(n,e,o)=>{if(!t.lookupCollection(o))throw TypeError("Collection draft read requires a valid collection");let r=re(n),i=r.revisionByCollection.get(o)??0,a=r.membershipMemo.get(e),d=a?.get(o);if(d?.revision===i)return d.rows;let f=l===void 0&&typeof e.createOutcomeToken==="function"?be(tn(e,o)):oe,w=new Map,K=r.historyByCollectionScope.get(o),M=e;while(M!==void 0){for(let T of K?.get(M)??[])if(!w.has(T.row))w.set(T.row,ee(n,e,T.row,o));M=M.parent}let N=[];if(f.length)y(e,z,f.length);for(let T of f){let D=w.get(T);if(D===void 0||D.enablingBirth===J)N.push(T)}let I=[];if(w.size!==0)y(e,z,w.size);for(let T of w.values())if(typeof T.enablingBirth==="number"&&U(r,T.scope,T.row,T.collection).kind==="present")I.push(T);I.sort((T,D)=>{let B=T.enablingBirth,H=D.enablingBirth;if(B===H)return T.discoveryIndex-D.discoveryIndex;return B-H});for(let T of I)N.push(T.row);let O;if(j(e,f,N))O=f;else if(d!==void 0&&j(e,d.rows,N))O=d.rows;else O=Object.freeze(N),y(e,we);if(a===void 0)a=new Map,r.membershipMemo.set(e,a);return a.set(o,Object.freeze({revision:i,rows:O})),O},Ro=(n)=>{let e=s.get(n);if(e===void 0)return;let o=0;for(let a of e.membershipMemo.values())o+=a.size;let r=new WeakMap;for(let[a,d]of e.revisionByCollection)r.set(a,Object.freeze({value:d}));let i=(a)=>Object.freeze({id:a.discoveryIndex,baselineLocal:a.baseline.local.kind,baselineEffective:a.baseline.effective.kind,baselineInherited:a.baseline.inherited.kind,final:a.final?.kind,enablingBirth:a.enablingBirth===J?"baseline":a.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((a)=>[...a.values()]).sort((a,d)=>a.discoveryIndex-d.discoveryIndex).map(i)),planOrder:Object.freeze(e.planOrder.map(i)),history:Object.freeze(e.history.map((a)=>Object.freeze({coordinateId:a.coordinateId,kind:a.kind,sequence:a.sequence}))),membershipMemoCount:o,revision:(a)=>r.get(a)?.value??0})},So=(n)=>{let e=n;if(!e.hasRows)return;let o=s.get(e);if(o===void 0)throw Error("Collection row draft lane is missing");let r=[],i=[],a=[],d=[],f=new WeakSet,w=new WeakMap,K=new Map,M=[],N=new Map,I=Object.freeze([]),O={baselinePresent:!1,transitions:I,birth:void 0},T={baselinePresent:!0,transitions:I,birth:J},D=new Map,B=new Map,H=(c)=>{let b=K.get(c.scope);if(b===void 0)b=new Map,K.set(c.scope,b);if(b.set(c.atom,c),c.existing!==void 0)w.set(c.existing,c)},_=(c)=>{let b=w.get(c);if(b!==void 0)return b;let E=[],g=c,h;while(g!==void 0){y(g.scope,le);let C=w.get(g);if(C!==void 0){h=C;break}E.push(g),g=g.inheritedFrom}for(let C=E.length-1;C>=0;C--){let p=E[C],v={scope:p.scope,atom:p.atom,existing:p,parent:h,beforeRows:be(p),plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};H(v),h=v}return h},ie=(c,b)=>{let E=K.get(c)?.get(b);if(E!==void 0)return E;let g=[],h=c,C;while(h!==void 0){let p=K.get(h)?.get(b);if(p!==void 0){y(h,le),C=p;break}let v=u.get(h)?.memberships?.get(b);if(v!==void 0){C=_(v);break}y(h,le),g.push(h),h=h.parent}for(let p=g.length-1;p>=0;p--){let v={scope:g[p],atom:b,existing:void 0,parent:C,beforeRows:C?.beforeRows??oe,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};C?.plannedChildren.push(v),a.push(v),H(v),C=v}return C},Ve=(c)=>{let b=N.get(c);if(b!==void 0)return b;return b={collection:c,top:void 0},N.set(c,b),M.push(b),b},Oo=(c,b)=>{b.affected=!0;let E=c.top;if(E===void 0)c.top=b;let g,h=b;while(h!==void 0){if(h.containsAffected){if(g??=h,Object.is(h,E))return}else h.containsAffected=!0;h=h.parent}if(E!==void 0)c.top=g},Mo=(c,b)=>{let E=B.get(c);if(E===void 0){if(c.beforeRows.length)y(c.scope,z,c.beforeRows.length);E=new Set(c.beforeRows),B.set(c,E)}return E.has(b)},pn=(c,b,E,g)=>{if(k!==void 0)k.states++;let h=F(c.scope,b).kind;if(g===void 0)return h==="none"?E:h==="present"?T:O;let C=E.baselinePresent,p=h==="present"||h==="none"&&C,v=p,R=p?J:void 0,S=[],V=0,X=0;while(V<E.transitions.length||X<g.length){let ne=E.transitions[V],Z=g[X],G;if(ne!==void 0&&(Z===void 0||ne.sequence<Z.sequence))C=ne.present,G=ne.sequence,V++;else h=Z.kind==="present"?"present":Z.kind==="absent"?"absent":"none",G=Z.sequence,X++;let mn=h==="present"||h==="none"&&C;if(mn===p)continue;p=mn,R=p?G:void 0,S.push({sequence:G,present:p})}if(!S.length)return p?T:O;return{baselinePresent:v,transitions:S,birth:R}},Vo=(c)=>{let b=D.get(c);if(b!==void 0)return b;let E=[],g=c;while(g!==void 0&&!D.has(g))E.push(g),g=g.parent;let h=g===void 0?new Map:D.get(g);for(let C=E.length-1;C>=0;C--){let p=E[C],v=new Map;for(let S of o.historyByCollectionScope.get(p.atom)?.get(p.scope)??[]){let V=v.get(S.row);if(V===void 0)V=[],v.set(S.row,V);V.push(S)}let R=new Map;if(h.size!==0)y(p.scope,z,h.size);for(let[S,V]of h)R.set(S,pn(p,S,V,v.get(S))),v.delete(S);for(let[S,V]of v){let X=p.parent!==void 0&&Mo(p.parent,S)?T:O;R.set(S,pn(p,S,X,V))}D.set(p,R),h=R}return D.get(c)},yn=(c)=>{if(c.finalRows!==void 0)return c.finalRows;if(c.existing!==void 0)m?.push(c.existing);let b=[],E=[],g=c.existing!==void 0&&L(c.scope)!==void 0,h;if(l===void 0){let p=Vo(c);if(g)h=p;if(c.beforeRows.length)y(c.scope,z,c.beforeRows.length);for(let v of c.beforeRows){let R=p.get(v);if(R===void 0||R.birth===J)b.push(v)}if(p.size!==0)y(c.scope,z,p.size);for(let[v,R]of p){if(h!==void 0&&(R.baselinePresent&&R.birth===void 0||!R.baselinePresent&&typeof R.birth==="number"))c.membershipChanges=h;if(typeof R.birth==="number")E.push({row:v,birth:R.birth})}}else{let p=new Map,v=o.historyByCollectionScope.get(c.atom),R=c.scope;while(R!==void 0){for(let S of v?.get(R)??[])if(!p.has(S.row))p.set(S.row,ee(e,c.scope,S.row,c.atom));R=R.parent}if(c.beforeRows.length)y(c.scope,z,c.beforeRows.length);for(let S of c.beforeRows){let V=p.get(S);if(V===void 0||V.enablingBirth===J)b.push(S)}if(p.size!==0)y(c.scope,z,p.size);for(let S of p.values())if(typeof S.enablingBirth==="number"&&U(o,S.scope,S.row,S.collection).kind==="present")E.push({row:S.row,birth:S.enablingBirth})}E.sort((p,v)=>p.birth-v.birth);for(let p of E)b.push(p.row);let C=!j(c.scope,c.beforeRows,b);if(c.membershipChangedFromBefore=C,c.existing!==void 0&&!C)c.finalRows=c.beforeRows;else c.finalRows=Object.freeze(b),y(c.scope,we);return c.finalRows};for(let c of o.planOrder){let b=c.final;if(b===void 0)continue;y(c.scope,Mn);let E=b.kind==="present"?de(b.value):b.kind==="absent"&&c.scope.parent!==void 0?Re:se,g=!kn(F(c.scope,c.row),E);r.push(Object.freeze({coordinate:c,local:E,ownershipChanged:g}));let h=Ve(c.collection),C=te(Q(c.scope,c.row,c.collection));if(C.local.kind!==E.kind)ie(c.scope,c.collection);let v=C.effective.kind==="present"?J:void 0;if(!Object.is(v,c.enablingBirth))Oo(h,ie(c.scope,c.collection));let R=u.get(c.scope)?.rowViews?.get(c.row);if(R===void 0)continue;let S=[R];while(S.length){let V=S.pop();if(f.has(V))continue;f.add(V),y(V.scope,xe);let X=V.served.outcome.kind==="value"&&V.served.outcome.value!==void 0?Y(V.served.outcome.value):W,ne=U(o,V.scope,V.atom,c.collection);if(De(X,ne))continue;i.push(Object.freeze({scope:V.scope,atom:V.atom,record:V,before:X,outcome:ne}));let Z=[];V.inheritingChildren.forEach((G)=>{V.scope.coordinator.recordCounter("routeVisits"),Z.push(G)});for(let G=Z.length-1;G>=0;G--)S.push(Z[G])}}for(let c of M){let b=c.top;if(b===void 0)continue;let E=new Set,g=[{node:b,affected:!1}];while(g.length){let h=g.pop(),C=h.node;if(E.has(C))continue;E.add(C),y(C.scope,le);let p=h.affected||C.affected;if(p){let R=yn(C);if(C.existing!==void 0&&!Object.is(R,C.beforeRows))d.push(Object.freeze({scope:C.scope,atom:C.atom,node:C,record:C.existing,rows:R}))}let v=[];C.existing?.inheritingChildren.forEach((R)=>{C.scope.coordinator.recordCounter("routeVisits");let S=p?_(R):w.get(R);if(S!==void 0&&(p||S.containsAffected))v.push(S)});for(let R of C.plannedChildren)if(p||R.containsAffected)v.push(R);for(let R=v.length-1;R>=0;R--)g.push({node:v[R],affected:p})}}for(let c of a){if(c.finalRows!==void 0)continue;if(c.parent===void 0){yn(c);continue}c.finalRows=c.beforeRows,c.membershipChangedFromBefore=!1}return{commit:go,rows:Object.freeze(r),rowSettlements:Object.freeze(i),membershipInstalls:Object.freeze(a),membershipSettlements:Object.freeze(d),sources:Object.freeze([...i,...d])}},ko=(n)=>{let e=n,o=!1;for(let r of e.rowSettlements){let{record:i,before:a,outcome:d}=r;y(i.scope,Nn),P(i.scope,a.kind==="absent"?jn:d.kind==="absent"?Bn:Hn,i.atom,t.lookupRow(i.atom))}for(let r of e.membershipSettlements)for(let[i,a]of r.node.membershipChanges??[]){let d=a.baselinePresent&&a.birth===void 0?zn:!a.baselinePresent&&typeof a.birth==="number"?_n:void 0;if(d!==void 0)P(r.node.scope,d,i,r.node.atom)}for(let r of e.rows){let i=r.coordinate.finalOperation;if(i!==void 0)P(r.coordinate.scope,i==="set"?Ln:i==="update"?Pn:i==="reset"?Fn:An,r.coordinate.row,r.coordinate.collection);if(!r.ownershipChanged)continue;o=!0;let{row:a,scope:d}=r.coordinate;if(r.local.kind==="none"){let M=u.get(d);if(M?.rowLocals?.delete(a),M?.ownedRows?.delete(a))y(d,Ne);if(M?.ownedRows?.size===0){if(M.ownedRows=void 0,M.rowLocals=void 0,M.liveRowViews===void 0&&M.liveMemberships===void 0)u.delete(d)}continue}let f=x(d),w=f.rowLocals;if(w===void 0)w=new WeakMap,f.rowLocals=w;let K=f.ownedRows;if(K===void 0)K=new Set,f.ownedRows=K,y(d,Dn);if(w.set(a,r.local),!K.has(a))K.add(a),y(d,Kn)}for(let r of e.membershipInstalls)r.installed=Oe(r.scope,r.atom,r.finalRows,r.parent!==void 0&&r.finalRows===r.beforeRows);if(e.membershipSettlements.length)return!0;for(let r of e.membershipInstalls)if(r.membershipChangedFromBefore)return!0;return o},Eo=(n)=>{let e=n;for(let o of e.rows){if(!o.ownershipChanged)continue;let{row:r,scope:i}=o.coordinate,a=u.get(i)?.rowViews?.get(r);if(a===void 0)continue;if(o.local.kind!=="none"||i.parent===void 0)ge(a);else bo(a,en(i.parent,r))}for(let o of e.membershipInstalls){let r=o.installed,i=o.parent?.existing??o.parent?.installed;if(r!==void 0&&i!==void 0)on(r,i)}},vo=(n)=>{let e=n;for(let o of e.rowSettlements){let{record:r,outcome:i}=o;r.served=Object.freeze({token:r.scope.createOutcomeToken(),outcome:gn(i)}),y(r.scope,In),P(r.scope,Wn,r.atom,t.lookupRow(r.atom)),r.scope.coordinator.reachSubscriptionTarget(r.scope,r.atom)}for(let o of e.membershipSettlements){let{record:r,rows:i}=o;r.served=he(r.scope,i),y(r.scope,xn),P(r.scope,qn,r.atom),r.scope.coordinator.reachSubscriptionTarget(r.scope,r.atom)}return e.sources.length?e.sources:void 0},go=function(n){if(n===0)return ko(this);if(n===1)return Eo(this);return vo(this)},To=(n)=>{let e=n,o=u.get(e);if(o===void 0)return;o.liveRowViews?.forEach((i)=>{ge(i),i.inheritingChildren.clear()}),o.liveMemberships?.forEach((i)=>{nn(i),i.inheritingChildren.clear(),i.served=he(i.scope,oe,i.served.token)}),o.liveRowViews?.clear(),o.liveMemberships?.clear();let r=o.ownedRows?.size??0;if(r!==0)y(e,Ne,r);o.ownedRows?.clear(),o.rowLocals=void 0,o.ownedRows=void 0,o.rowViews=void 0,o.liveRowViews=void 0,o.memberships=void 0,o.liveMemberships=void 0,u.delete(e)};return Object.freeze({has:(n)=>t.lookupRow(n)!==void 0||t.lookupCollection(n),read:(n,e,o)=>{let r=n,i=e;if(t.lookupRow(o)!==void 0)return Object.freeze({kind:"value",value:un(r,i,o)});if(t.lookupCollection(o))return Object.freeze({kind:"value",value:fn(r,i,o)});throw TypeError("Unknown collection scratch source")},stage:(n,e,o,r,i,a)=>{let d=n,f=e;if(o==="set")an(d,f,r,i,a);else if(o==="update")cn(d,f,r,i,a);else if(o==="delete")sn(d,f,r);else dn(d,f,r)},scope:(n,e)=>{if(e===void 0){To(n);return}if(t.lookupRow(e)!==void 0)return en(n,e).served;if(!t.lookupCollection(e))return;return tn(n,e).served},plan:So,stageSet:an,stageUpdate:cn,stageDelete:sn,stageReset:dn,readDraftRow:un,readDraftCollection:fn,beginMembershipRebuildTraceForTest:()=>{if(m!==void 0)throw Error("A membership rebuild trace is already active");let n=[];return m=n,()=>{if(n===void 0)throw Error("The membership rebuild trace is already finished");m=void 0;let e=Object.freeze([...n]);return n.length=0,n=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(k!==void 0)throw Error("A membership placement trace is already active");let n={coordinates:0,states:0};return k=n,()=>{if(n===void 0)throw Error("The membership placement trace is already finished");k=void 0;let e=Object.freeze({...n});return n=void 0,e}},inspectDraft:Ro})};var Lo=(t)=>new WeakRef(t),Le,Po=(t)=>{let l=Ae(t),s=Le??(Le=new WeakMap),u=s.get(l);if(u!==void 0)return u;return u={collections:new WeakMap,rows:new WeakMap},s.set(l,u),u};class ye 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 Pe=()=>new ye,eo=(t)=>{if(t===null)return null;switch(typeof t){case"string":case"bigint":case"boolean":return t;case"number":if(!Number.isFinite(t))throw Pe();return Object.is(t,-0)?0:t;default:throw Pe()}},Zn=(t)=>{throw Fe(t),Pe()},Fo=(t,l,s)=>Ee(t,"collection-encoder",(u)=>{let m;try{m=Reflect.apply(l,void 0,[u])}catch(L){let y=ke(L);if(y.kind==="not-thenable")throw L;if(y.kind==="inspection-error")throw y.error;return Zn(y)}let k=ke(m);if(k.kind==="not-thenable")return m;if(k.kind==="inspection-error")throw k.error;return Zn(k)},[s],eo,()=>TypeError("collection encodeKey cannot call family or collection accessors")),Ao=(t)=>{if(t===void 0)return;if(typeof t!=="object"||t===null)throw TypeError("collection options must be an object");for(let s of Reflect.ownKeys(t)){if(s==="indexes")throw TypeError("collection indexes are not available in this beta");if(s!=="encodeKey")throw TypeError("collection options contain an unknown option")}if(!Object.prototype.hasOwnProperty.call(t,"encodeKey"))return;let l=Reflect.get(t,"encodeKey");if(typeof l!=="function")throw TypeError("collection encodeKey must be a function");return l},jo=()=>TypeError("collection cannot recursively construct the same row"),Ho=()=>TypeError("presence requires a same-domain CollectionRow"),Bo=(t,l)=>{let s=Le?.get(Ae(t));if(typeof l==="object"&&l!==null||typeof l==="function"){let u=s?.rows.get(l);if(u!==void 0)return u}throw $n(t,l),Ho()};function no(t,l,s){Xn(t);let u=Ao(l),m=[],k,L=Object.assign(function(F){je(t);let A=u===void 0?eo(F):Fo(t,u,F);m[0]=A;try{return k.rows.getOrCreateOne(A,m)}finally{m.pop()}},{kind:"collection"}),y=Ke(t,L),P,j=new ae((x)=>{let F=x[0];return Ke(t,{kind:"collection-row",key:F})},jo,s,(x)=>{if(P===void 0)throw Error("Collection definition registry is not ready");P.rows.set(x,{definition:k,presence:void 0})});return k=Object.freeze({collection:y,rows:j,referencePresence:s===void 0?Lo:(x)=>s.ref(x)}),P=Po(t),P.collections.set(y,k),Qn(t,(x)=>Yn({lookupRow:(F)=>P.rows.get(F)?.definition.collection,lookupCollection:(F)=>P.collections.has(F),runGuarded:(F,A)=>Jn(x,F,A),inspectThenable:ke,containThenable:Fe})),y}var oo=(t,l)=>{je(t);let s=Bo(t,l),u=s.presence?.deref();if(u!==void 0)return u;let m=t.selector((k)=>k(l)!==void 0);return s.presence=s.definition.referencePresence(m),m};var _o=(t,l={})=>q.atomLazy(t,l),lo=(t,l={})=>q.atom(t,l);Object.defineProperty(lo,"lazy",{configurable:!1,enumerable:!0,value:_o,writable:!1});var ao=Object.freeze(lo),co=(t,l={})=>q.selector(t,l);function so(t){return no(q,t)}var uo=(t)=>oo(q,t),zo=(...t)=>{if(t.length===0||t.length>2)throw TypeError("family requires a State factory and options");let[l,s]=t;if(typeof l!=="function")throw TypeError("family requires a State factory function");if(s!==void 0&&(typeof s!=="object"||s===null))throw TypeError("family options must be an object");let u=s?.encodeKey;if(u!==void 0&&typeof u!=="function")throw TypeError("family encodeKey must be a function");return Sn(l,u,(m,k,L,y)=>Ee(q,m,k,L,y),(m)=>{let k=ro(q,m);if(k===void 0)throw TypeError("family factories must construct or return a family State");return k},(m)=>io(q,m),()=>to(q))},fo=zo;function po(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return q.createStoreTree()}var ut=ao,ft=so,pt=fo,yt=uo,mt=co,bt=po,ht=ze,Ct=Ze,wt=ye,Rt=ue,St=Ye,kt=Ge,Et=$e,vt=pe,gt=Be,Tt=Qe,Ot=We,Mt=He,Vt=Je,It=Xe,xt=_e,Nt=Ue,Dt=qe,Kt=fe;export{ht as CallbackCapabilityError,Ct as InvalidAtomComparatorResultError,wt as InvalidCollectionKeyError,St as InvalidSynchronousAtomValueError,Rt as InvalidSynchronousCollectionValueError,kt as InvalidTransactionCallbackResultError,Et as InvalidTransactionTargetError,vt as MissingCollectionRowError,gt as RuntimeMismatchError,Tt as ScopeNotFoundError,Ot as SelectorCapabilityError,Mt as SelectorCircularDependencyError,Vt as StoreDisposedError,It as StoreTreeMismatchError,xt as SubscriberNotificationError,Nt as TransactionClosedError,Dt as TransactionPhaseError,Kt as UndefinedCollectionValueError,ut as atom,ft as collection,pt as family,yt as presence,mt as selector,bt as store};
|