valdres 1.0.0-beta.4 → 1.0.0-beta.40

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.
Files changed (136) hide show
  1. package/README.md +121 -1
  2. package/dist/adapter-internals/v1.js +1 -0
  3. package/dist/chunk-ptej8q17.js +2 -0
  4. package/dist/chunk-rr3063rn.js +2 -0
  5. package/dist/chunk-tywyt3b6.js +2 -0
  6. package/dist/development/adapter-internals/v1.js +1 -0
  7. package/dist/development/chunk-ptej8q17.js +2 -0
  8. package/dist/development/chunk-rr3063rn.js +2 -0
  9. package/dist/development/chunk-tywyt3b6.js +2 -0
  10. package/dist/development/equality.js +1 -0
  11. package/dist/development/index.js +1 -0
  12. package/dist/development/inspect.js +1 -0
  13. package/dist/development/query.js +1 -0
  14. package/dist/equality.js +1 -0
  15. package/dist/index.js +1 -2620
  16. package/dist/inspect.js +1 -0
  17. package/dist/query.js +1 -0
  18. package/dist/types/adapter-internals/v1.d.ts +5 -0
  19. package/dist/types/equality.d.ts +9 -0
  20. package/dist/types/index.d.ts +90 -43
  21. package/dist/types/inspect.d.ts +12 -0
  22. package/dist/types/query.d.ts +3 -0
  23. package/dist/types/types/QueryDefinition.d.ts +4 -0
  24. package/dist/types/types/QueryWhere.d.ts +10 -0
  25. package/dist/types/utils/query.d.ts +4 -0
  26. package/dist/types/v1-internal/collection-index-protocol.d.ts +35 -0
  27. package/dist/types/v1-internal/collection-inspection-protocol.d.ts +38 -0
  28. package/dist/types/v1-internal/collection-kernel.d.ts +117 -0
  29. package/dist/types/v1-internal/collection-query.d.ts +9 -0
  30. package/dist/types/v1-internal/collection.d.ts +16 -0
  31. package/dist/types/v1-internal/committed-store-tree/committed-store-tree.d.ts +130 -0
  32. package/dist/types/v1-internal/committed-store-tree/counter-ids.d.ts +54 -0
  33. package/dist/types/v1-internal/committed-store-tree/external-atom.d.ts +65 -0
  34. package/dist/types/v1-internal/committed-store-tree/external-inspection-protocol.d.ts +11 -0
  35. package/dist/types/v1-internal/committed-store-tree/external-projection.d.ts +72 -0
  36. package/dist/types/v1-internal/committed-store-tree/external-types.d.ts +115 -0
  37. package/dist/types/v1-internal/committed-store-tree/runtime-domain.d.ts +268 -0
  38. package/dist/types/v1-internal/committed-store-tree/scope-node.d.ts +135 -0
  39. package/dist/types/v1-internal/committed-store-tree/scratch-selector-host.d.ts +42 -0
  40. package/dist/types/v1-internal/committed-store-tree/tree-transaction.d.ts +83 -0
  41. package/dist/types/v1-internal/committed-store-tree/types.d.ts +150 -0
  42. package/dist/types/v1-internal/family-factory-types.d.ts +14 -0
  43. package/dist/types/v1-internal/family.d.ts +4 -0
  44. package/dist/types/v1-internal/inspection.d.ts +498 -0
  45. package/dist/types/v1-internal/ordered-membership.d.ts +16 -0
  46. package/dist/types/v1-internal/public-domain.d.ts +5 -0
  47. package/dist/types/v1-internal/query-definition.d.ts +15 -0
  48. package/dist/types/v1-internal/selector-evaluator/errors.d.ts +42 -0
  49. package/dist/types/v1-internal/selector-evaluator/evaluate.d.ts +23 -0
  50. package/dist/types/v1-internal/selector-evaluator/types.d.ts +267 -0
  51. package/dist/types/v1-internal/weak-member-cache.d.ts +38 -0
  52. package/dist/types/v1.d.ts +59 -0
  53. package/package.json +51 -3
  54. package/dist/types/atom.d.ts +0 -16
  55. package/dist/types/atomFamily.d.ts +0 -13
  56. package/dist/types/cacheMeta.d.ts +0 -4
  57. package/dist/types/errors/SelectorCircularDependencyError.d.ts +0 -5
  58. package/dist/types/errors/SelectorEvaluationError.d.ts +0 -7
  59. package/dist/types/errors/lib/generateSelectorTrace.d.ts +0 -2
  60. package/dist/types/globalStore.d.ts +0 -4
  61. package/dist/types/indexConstructor.d.ts +0 -5
  62. package/dist/types/lib/asyncDependencyTracking.d.ts +0 -22
  63. package/dist/types/lib/atomFamilyIndex.d.ts +0 -17
  64. package/dist/types/lib/createAtomFamily.d.ts +0 -4
  65. package/dist/types/lib/createGlobalAtomFamily.d.ts +0 -4
  66. package/dist/types/lib/createStoreData.d.ts +0 -5
  67. package/dist/types/lib/deleteFamilyAtom.d.ts +0 -3
  68. package/dist/types/lib/equal.d.ts +0 -1
  69. package/dist/types/lib/familyKey.d.ts +0 -2
  70. package/dist/types/lib/getState.d.ts +0 -8
  71. package/dist/types/lib/globalAtom.d.ts +0 -4
  72. package/dist/types/lib/initAtom.d.ts +0 -5
  73. package/dist/types/lib/initSelector.d.ts +0 -19
  74. package/dist/types/lib/isFunction.d.ts +0 -1
  75. package/dist/types/lib/isProd.d.ts +0 -1
  76. package/dist/types/lib/maxAgeCleanups.d.ts +0 -4
  77. package/dist/types/lib/mountAtom.d.ts +0 -58
  78. package/dist/types/lib/propagateUpdatedAtoms.d.ts +0 -13
  79. package/dist/types/lib/resetAtom.d.ts +0 -3
  80. package/dist/types/lib/setAtom.d.ts +0 -4
  81. package/dist/types/lib/setAtoms.d.ts +0 -3
  82. package/dist/types/lib/setValueInData.d.ts +0 -8
  83. package/dist/types/lib/stableStringify.d.ts +0 -1
  84. package/dist/types/lib/storeFromStoreData.d.ts +0 -4
  85. package/dist/types/lib/stringifyFamilyArgs.d.ts +0 -1
  86. package/dist/types/lib/subscribe.d.ts +0 -6
  87. package/dist/types/lib/transaction.d.ts +0 -37
  88. package/dist/types/lib/unsubscribe.d.ts +0 -5
  89. package/dist/types/selector.d.ts +0 -4
  90. package/dist/types/selectorFamily.d.ts +0 -4
  91. package/dist/types/store.d.ts +0 -6
  92. package/dist/types/types/Atom.d.ts +0 -32
  93. package/dist/types/types/AtomDefaultValue.d.ts +0 -2
  94. package/dist/types/types/AtomFamily.d.ts +0 -15
  95. package/dist/types/types/AtomFamilyAtom.d.ts +0 -7
  96. package/dist/types/types/AtomFamilyDefaultValue.d.ts +0 -5
  97. package/dist/types/types/AtomFamilySelector.d.ts +0 -6
  98. package/dist/types/types/AtomOnInit.d.ts +0 -9
  99. package/dist/types/types/AtomOnMount.d.ts +0 -14
  100. package/dist/types/types/AtomOnSet.d.ts +0 -2
  101. package/dist/types/types/AtomOptions.d.ts +0 -15
  102. package/dist/types/types/EqualFunc.d.ts +0 -3
  103. package/dist/types/types/Family.d.ts +0 -3
  104. package/dist/types/types/FamilyKey.d.ts +0 -3
  105. package/dist/types/types/GetValue.d.ts +0 -9
  106. package/dist/types/types/GlobalAtom.d.ts +0 -17
  107. package/dist/types/types/GlobalAtomGetSelfFunc.d.ts +0 -1
  108. package/dist/types/types/GlobalAtomResetSelfFunc.d.ts +0 -1
  109. package/dist/types/types/GlobalAtomSetSelfFunc.d.ts +0 -2
  110. package/dist/types/types/Reactive.d.ts +0 -3
  111. package/dist/types/types/ResetAtom.d.ts +0 -2
  112. package/dist/types/types/Selector.d.ts +0 -18
  113. package/dist/types/types/SelectorFamily.d.ts +0 -7
  114. package/dist/types/types/SelectorOptions.d.ts +0 -5
  115. package/dist/types/types/SetAtom.d.ts +0 -5
  116. package/dist/types/types/SetAtomValue.d.ts +0 -1
  117. package/dist/types/types/State.d.ts +0 -4
  118. package/dist/types/types/Store.d.ts +0 -31
  119. package/dist/types/types/StoreData.d.ts +0 -58
  120. package/dist/types/types/SubscribeFn.d.ts +0 -9
  121. package/dist/types/types/Subscription.d.ts +0 -11
  122. package/dist/types/types/SyncSetAtom.d.ts +0 -4
  123. package/dist/types/types/TransactionFn.d.ts +0 -2
  124. package/dist/types/types/TransactionInterface.d.ts +0 -15
  125. package/dist/types/utils/deepFreeze.d.ts +0 -1
  126. package/dist/types/utils/isAtom.d.ts +0 -2
  127. package/dist/types/utils/isAtomFamily.d.ts +0 -2
  128. package/dist/types/utils/isFamily.d.ts +0 -1
  129. package/dist/types/utils/isFamilyAtom.d.ts +0 -2
  130. package/dist/types/utils/isFamilySelector.d.ts +0 -2
  131. package/dist/types/utils/isFamilyState.d.ts +0 -3
  132. package/dist/types/utils/isGlobalAtom.d.ts +0 -2
  133. package/dist/types/utils/isPromiseLike.d.ts +0 -1
  134. package/dist/types/utils/isSelector.d.ts +0 -2
  135. package/dist/types/utils/isSelectorFamily.d.ts +0 -2
  136. package/dist/types/utils/resolveReactive.d.ts +0 -4
package/README.md CHANGED
@@ -1 +1,121 @@
1
- Se [valdres.dev](https://valdres.dev) for docs
1
+ <!-- DOCS:START -->
2
+
3
+ # valdres
4
+
5
+ The first public beta of Valdres's new synchronous state engine.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install valdres@beta
11
+ ```
12
+
13
+ ```ts
14
+ import { store, atom, selector } from "valdres"
15
+
16
+ const countAtom = atom(0)
17
+ const doubledSelector = selector(get => get(countAtom) * 2)
18
+
19
+ const s = store()
20
+ s.set(countAtom, 21)
21
+ s.get(doubledSelector) // 42
22
+ ```
23
+
24
+ `set` always stores the exact value you pass, including functions. Use `update` when the next value depends on the current value:
25
+
26
+ ```ts
27
+ s.set(countAtom, 1)
28
+ s.update(countAtom, current => current + 1)
29
+ ```
30
+
31
+ A store also exposes `sub`, `reset`, `txn`, `scope`, and `dispose`. Store operations are stable bound functions, so they can be passed as callbacks without rebinding. `store.txn(callback, name?)` accepts an optional human-readable diagnostic label; labels are metadata, not identity.
32
+
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
+
35
+ ## External sources
36
+
37
+ `externalAtom(source, { name? })` creates read-only State from a synchronous external source. The source provides `getSnapshot`, optional `getServerSnapshot`, and `subscribe(invalidate)` returning synchronous cleanup. Every call creates a fresh definition; preserve snapshot identity until the source changes. Equality is always `Object.is`.
38
+
39
+ Stores share one projection across scopes and attach once while consumers retain it. Transactions capture each source once. React SSR/hydration uses isolated server snapshots, and thenables are rejected rather than suspended. Family factories may construct ExternalAtoms.
40
+
41
+ See the [ExternalAtom reference](https://github.com/eigilsagafos/valdres/blob/main/docs/external-atom.md) and [integration guide](https://github.com/eigilsagafos/valdres/blob/main/docs/howto-external-atom.md) for lifecycle, errors, and hydration examples.
42
+
43
+ ## Parameterized State identity
44
+
45
+ `family(factory)` memoizes one Atom, Selector, or ExternalAtom 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.
46
+
47
+ ```ts
48
+ import { atom, family } from "valdres"
49
+
50
+ const cellValue = family((sheetId: string, row: number) => atom(""))
51
+ cellValue("budget", 4) === cellValue("budget", 4) // true
52
+
53
+ type Step = { readonly id: string; readonly title: string }
54
+
55
+ const stepProgress = family((step: Step) => atom(0), {
56
+ encodeKey: step => step.id,
57
+ })
58
+
59
+ stepProgress({ id: "step-1", title: "Draft" }) ===
60
+ stepProgress({ id: "step-1", title: "Review" }) // true
61
+ ```
62
+
63
+ Structured arguments require a synchronous `encodeKey` that returns one canonical primitive key. The factory must construct and return its Atom, Selector, or ExternalAtom during that member's construction, or return any member already published by a family. Returning an arbitrary pre-existing State is rejected.
64
+
65
+ The exported `FamilyKey` type names the primitive-key union for reusable APIs.
66
+
67
+ 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.
68
+
69
+ 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.
70
+
71
+ A family is only a callable identity cache. It has no membership or enumeration API and no `delete`, `release`, `index`, Store, or collection surface.
72
+
73
+ ## Keyed collections
74
+
75
+ `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.
76
+
77
+ ## Opt-in structural equality
78
+
79
+ `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:
80
+
81
+ ```ts
82
+ import { atom } from "valdres"
83
+ import { deepEqual } from "valdres/equality"
84
+
85
+ const documentAtom = atom({ blocks: [] }, { equal: deepEqual })
86
+ ```
87
+
88
+ `deepEqual` recursively compares supported values using SameValueZero primitive leaves, own enumerable string and symbol properties, and native identity for Map keys and Set members. Non-binary objects require the same prototype. Matching binary brands compare visible bytes across realms and ignore attached properties. Functions, Promises, Errors, URLs, weak collections, other opaque platform objects, and DOM nodes compare only by identity. Cyclic structures are unsupported. Reached getters, Proxy traps, `valueOf`, and `toString` hooks can run and throw.
89
+
90
+ Structural comparison walks the compared values, so use it deliberately on allocation-heavy results where pruning redundant updates outweighs that work. The separate `valdres/equality` entry keeps it out of ordinary root bundles.
91
+
92
+ ## Inspect a Store
93
+
94
+ `valdres/inspect` creates an opt-in Store with a bounded structural flight recorder. It belongs to the same runtime domain as ordinary Stores, so existing atoms, selectors, scopes, and framework adapters work unchanged:
95
+
96
+ ```ts
97
+ import { createInspectableStore } from "valdres/inspect"
98
+
99
+ const { store: appStore, inspect } = createInspectableStore()
100
+
101
+ inspect.span("drop interaction", () =>
102
+ appStore.txn(transaction => {
103
+ transaction.update(processAtom, updateProcess)
104
+ }, "collapse process"),
105
+ )
106
+
107
+ const report = inspect.export()
108
+ inspect.reset()
109
+ ```
110
+
111
+ The report links labels to opaque operation, commit, evaluation, session, and search IDs. It records selector topology/search work, collection row and membership work, external projection/lifecycle 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 7.
112
+
113
+ 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.
114
+
115
+ The versioned `valdres/adapter-internals/v1` entry is for framework bindings. It exports only `assertStore`, `read`, `subscribe`, and `readHydrationSnapshot`; application code should use Store methods directly.
116
+
117
+ ## Beta compatibility
118
+
119
+ `valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.6` is certified with `valdres@1.0.0-beta.27` and later v1 betas accepted by its `^1.0.0-beta.27` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
120
+
121
+ <!-- DOCS:END -->
@@ -0,0 +1 @@
1
+ import{Ka as e,Ma as r}from"../chunk-rr3063rn.js";var t=e(r),s=t.assertStore,i=t.read,n=t.subscribe,m=t.readHydrationSnapshot;export{s as assertStore,i as read,m as readHydrationSnapshot,n as subscribe};
@@ -0,0 +1,2 @@
1
+ import{A as Rn,B as kn,C as gn,D as Sn,E as vn,F as Mn,G as On,H as En,I as Tn,P as Dn,i as sn,j as cn,k as dn,l as Pe,m as an,n as ae,o as W,p as pe,q as fn,r as un,s as pn,t as hn,u as mn,v as je,w as bn,x as wn,y as yn,z as Cn}from"./chunk-tywyt3b6.js";import{Aa as Vn,Ca as Ve,Da as ze,Ja as Bn,ka as fe,la as be,na as jn,ta as de,ua as ge,wa as Hn,ya as _e,za as Ae}from"./chunk-rr3063rn.js";class Ie{entries=new Map;tail;nextRank=0;constructor(i){for(let c of i)this.append(c)}append(i){let c=this.tail;if(this.entries.set(i,{rank:this.nextRank++,previous:c}),c!==void 0)this.entries.get(c).next=i;this.tail=i}remove(i){let c=this.entries.get(i);if(c===void 0)return;if(c.previous!==void 0)this.entries.get(c.previous).next=c.next;if(c.next!==void 0)this.entries.get(c.next).previous=c.previous;else this.tail=c.previous;this.entries.delete(i)}changes(i,c){if(i.length!==c.length)return!0;let a=new Set(i),f=this.tail;for(let m=c.length-1;m>=0;m--){if(c[m]!==f||!a.has(c[m]))return!0;f=this.entries.get(f)?.previous}return!1}}var X=Symbol("collection baseline birth");class Re extends Error{seal(){Object.freeze(this)}}class Nn extends Re{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class xn extends Re{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class In extends Re{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var he=Object.freeze({kind:"none"}),Ce=Object.freeze({kind:"absent"}),q=Object.freeze({kind:"absent"}),G=Object.freeze([]),me=(i)=>Object.freeze({kind:"present",value:i}),J=(i)=>Object.freeze({kind:"present",value:i}),ye=(i,c)=>i.kind===c.kind&&(i.kind==="absent"||c.kind==="present"&&Object.is(i.value,c.value)),tn=(i,c)=>i.kind===c.kind&&(i.kind!=="present"||c.kind==="present"&&Object.is(i.value,c.value)),le=(i)=>{let c=i.local.kind==="present"?me(i.local.value):i.local.kind==="absent"?Ce:he,a=i.effective.kind==="present"?J(i.effective.value):q,f=i.inherited.kind==="present"?J(i.inherited.value):q;if(c.kind==="none"&&!ye(a,f))throw Error("Collection baseline without local ownership must equal inherited outcome");if(c.kind==="present"&&(a.kind!=="present"||!Object.is(c.value,a.value)))throw Error("Collection present local baseline must equal its effective outcome");if(c.kind==="absent"&&a.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:c,effective:a,inherited:f})},Le=(i)=>{let c=i.final;if(c===void 0)return i.baseline.local;if(c.kind==="present")return me(c.value);return c.kind==="absent"?Ce:he},rn=(i,c)=>i.kind==="present"?J(i.value):i.kind==="absent"?q:c,ln=(i)=>Object.freeze({kind:"value",value:i.kind==="present"?i.value:void 0}),Ln=(i,c)=>{let a,f=new WeakMap,m=new WeakMap,N,B,H=(t)=>t.coordinator?.evaluate?.recordExtension,g=(t,e,o=1)=>{H(t)?.(e,o)},z=(t,e,o,r)=>{H(t)?.(e,t,o,r)},V=(t,e,o)=>{if(e.length!==o.length)return!1;let r=H(t);if(r===void 0){for(let n=0;n<e.length;n++)if(!Object.is(e[n],o[n]))return!1;return!0}for(let n=0;n<e.length;n++)if(!Object.is(e[n],o[n]))return r(W,n+1),!1;if(e.length)r(W,e.length);return!0},ue=(t)=>{let e=m.get(t);if(e!==void 0)return e;return e={rowLocals:void 0,ownedRows:void 0,rowViews:void 0,liveRowViews:void 0,memberships:void 0,liveMemberships:void 0},m.set(t,e),e},I=(t,e)=>m.get(t)?.rowLocals?.get(e)??he,L=(t,e)=>{let o=t;while(o!==void 0){let r=I(o,e);if(r.kind==="present")return J(r.value);if(r.kind==="absent")return q;o=o.parent}return q},Q=c??((t,e)=>{let o=I(t,e),r=L(t.parent,e);return Object.freeze({local:o,effective:rn(o,r),inherited:r})}),An=(t,e,o,r)=>{let n=t.byScope.get(e)?.get(o);if(n!==void 0)return Le(n);return le(Q(e,o,r)).local},U=(t,e,o,r)=>{let n=e;while(n!==void 0){let l=An(t,n,o,r);if(l.kind==="present")return J(l.value);if(l.kind==="absent")return q;if(c!==void 0){let d=t.byScope.get(n)?.get(o);if(d!==void 0)return d.baseline.inherited;return le(Q(n,o,r)).inherited}n=n.parent}return q},zn=(t,e,o,r)=>{if(c!==void 0){let D=le(Q(e,o,r)),T=D.effective.kind==="present",E=T?X:void 0;for(let j of t.byRow.get(o)?.historyByScope.get(e)??[]){if(!Object.is(j.row,o)||!Object.is(j.scope,e))continue;let _=j.kind==="present"||j.kind==="reset"&&D.inherited.kind==="present";if(!T&&_)E=j.sequence;else if(!_)E=void 0;T=_}return E}let n=[],l=new Map,d=e;while(d!==void 0)n.push(d),l.set(d,le(Q(d,o,r)).local.kind),d=d.parent;let u=[],v=t.byRow.get(o);if(v!==void 0){for(let D of n){let T=v.historyByScope.get(D);if(T!==void 0)u.push(...T)}u.sort((D,T)=>D.sequence-T.sequence)}let P=()=>{for(let D of n){let T=l.get(D);if(T==="present")return!0;if(T==="absent")return!1}return!1},O=P(),x=O?X:void 0;for(let D of u){l.set(D.scope,D.kind==="present"?"present":D.kind==="absent"?"absent":"none");let T=P();if(!O&&T)x=D.sequence;else if(!T)x=void 0;O=T}return x},Se=(t,e,o,r)=>{let n=ue(t),l=n.rowViews?.get(e);if(l!==void 0)return l;let d={scope:t,atom:e,served:Object.freeze({token:t.createOutcomeToken(),outcome:ln(o)}),inheritedFrom:r,inheritingChildren:new de(()=>t.coordinator.recordCounter(2))},u=n.rowViews;if(u===void 0)u=new WeakMap,n.rowViews=u;let v=n.liveRowViews;if(v===void 0)v=new de(()=>t.coordinator.recordCounter(2)),n.liveRowViews=v;if(u.set(e,d),v.add(d),z(t,En,e,i.lookupRow(e)),r!==void 0)r.inheritingChildren.add(d),t.coordinator.recordCounter(11);return d},We=(t,e)=>{let o=t,r=[],n;while(!0){g(o,Pe);let l=m.get(o),d=l?.rowViews?.get(e);if(d!==void 0){n=d;break}let u=l?.rowLocals?.get(e);if(u!==void 0){n=Se(o,e,u.kind==="present"?J(u.value):q);break}if(o.parent===void 0){n=Se(o,e,q);break}r.push(o),o=o.parent}for(let l=r.length-1;l>=0;l--)n=Se(r[l],e,n.served.outcome.kind==="value"&&n.served.outcome.value!==void 0?J(n.served.outcome.value):q,n);return n},ve=(t)=>{let e=t.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(t),t.inheritedFrom=void 0,t.scope.coordinator.recordCounter(12)},Kn=(t,e)=>{if(Object.is(t.inheritedFrom,e))return;ve(t),t.inheritedFrom=e,e.inheritingChildren.add(t),t.scope.coordinator.recordCounter(11)},te=(t)=>{if(t.snapshotDirty){let e=Object.freeze([...t.ordered.entries.keys()]);g(t.scope,W,e.length),g(t.scope,pe),t.served=se(t.scope,e,t.served.token),t.snapshotDirty=!1}return t.served.outcome.kind==="value"?t.served.outcome.value:G},Wn=(t,e)=>{let o=Ee(t,e),r=o;while(r!==void 0&&r.ordered===void 0){r.ordered=new Ie(te(r));let n=r.inheritedFrom;if(n!==void 0)(n.indexedChildren??=new de).add(r);r=n}return o.ordered},Me=(t,e)=>{if(e.length)g(t,W,e.length);let o=Object.freeze([...e]);return g(t,pe),o},se=(t,e,o=t.createOutcomeToken())=>Object.freeze({token:o,outcome:Object.freeze({kind:"value",value:e})}),Oe=(t,e,o,r=!1)=>{let n=ue(t),l=n.memberships?.get(e);if(l!==void 0)return l;let d={scope:t,atom:e,served:se(t,o,r?G:void 0),inheritedFrom:void 0,inheritingChildren:new de(()=>t.coordinator.recordCounter(2))},u=n.memberships;if(u===void 0)u=new WeakMap,n.memberships=u;let v=n.liveMemberships;if(v===void 0)v=new de(()=>t.coordinator.recordCounter(2)),n.liveMemberships=v;return u.set(e,d),v.add(d),g(t,an),z(t,Tn,e),d},Fe=(t)=>{let e=t.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(t),e.indexedChildren?.delete(t),t.inheritedFrom=void 0,t.scope.coordinator.recordCounter(12)},qe=(t,e)=>{if(Object.is(t.inheritedFrom,e))return;Fe(t),t.inheritedFrom=e,e.inheritingChildren.add(t),t.scope.coordinator.recordCounter(11)},Ee=(t,e)=>{let o=t,r=[],n;while(!0){g(o,ae);let l=m.get(o)?.memberships?.get(e);if(l!==void 0){if(n=l,n.served.token===G){let d=Me(o,te(n));n.served=se(o,d)}break}if(o.parent===void 0){n=Oe(o,e,Me(o,G));break}r.push(o),o=o.parent}for(let l=r.length-1;l>=0;l--){let d=r[l],u=Me(d,te(n)),v=Oe(d,e,u);qe(v,n),n=v}return n},Fn=(t)=>{let e=t;a?.release(e);let o=f.get(e);if(o===void 0)return;f.delete(e);for(let r of o.byScope.values()){for(let n of r.values())n.final=void 0,n.finalOperation=void 0;r.clear()}o.byScope.clear(),o.planOrder.length=0,o.history.length=0;for(let r of o.historyByCollectionScope.values()){for(let n of r.values())n.length=0;r.clear()}o.historyByCollectionScope.clear();for(let r of o.byRow.values()){for(let n of r.coordinatesByAncestor.values())n.length=0;r.coordinatesByAncestor.clear();for(let n of r.historyByScope.values())n.length=0;r.historyByScope.clear()}o.byRow.clear(),o.revisionByCollection.clear(),o.queryRevisionByCollection?.clear();for(let r of o.membershipMemo.values())r.clear();o.membershipMemo.clear()},ne=(t)=>{let e=f.get(t);if(e!==void 0)return e;return e={byScope:new Map,planOrder:[],history:[],historyByCollectionScope:new Map,byRow:new Map,revisionByCollection:new Map,membershipMemo:new Map,nextDiscoveryIndex:0,hasAcceptedIntent:!1},t.installRows(Fn),f.set(t,e),e},Te=(t)=>{let e=i.lookupRow(t);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},qn=(t,e)=>{t.revisionByCollection.set(e,(t.revisionByCollection.get(e)??0)+1)},re=(t,e,o,r=Te(o))=>{let n=ne(t),l=n.byScope.get(e);if(l===void 0)l=new Map,n.byScope.set(e,l);let d=l.get(o);if(d!==void 0)return d;if(B!==void 0)B.coordinates++;let u=le(Q(e,o,r)),v=c===void 0?U(n,e.parent,o,r):u.inherited,P=le({local:u.local,effective:rn(u.local,v),inherited:v});d={scope:e,row:o,collection:r,baseline:P,discoveryIndex:n.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},l.set(o,d);let O=n.byRow.get(o);if(O===void 0)O={coordinatesByAncestor:new Map,historyByScope:new Map},n.byRow.set(o,O);let x=e;while(x!==void 0){let D=O.coordinatesByAncestor.get(x);if(D===void 0)D=[],O.coordinatesByAncestor.set(x,D);D.push(d),x=x.parent}return d.enablingBirth=zn(n,e,o,r),d},we=(t,e,o,r,n,l)=>{let d=Le(e),u=ne(t),v=U(u,e.scope,e.row,e.collection);if(tn(d,n)&&ye(v,l))return;if(!u.hasAcceptedIntent)u.hasAcceptedIntent=!0,g(e.scope,cn);g(e.scope,sn);let P=[];for(let F of u.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let K=U(u,F.scope,F.row,F.collection);P.push({coordinate:F,effective:K,placement:K.kind==="present"?F.enablingBirth:void 0})}let O=t.generation;if(e.planIndex===void 0)e.planIndex=u.planOrder.length,u.planOrder.push(e);e.final=r,e.finalOperation=o;let x=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:r.kind,sequence:O});u.history.push(x);let D=u.byRow.get(e.row),T=D.historyByScope.get(e.scope);if(T===void 0)T=[],D.historyByScope.set(e.scope,T);T.push(x);let E=u.historyByCollectionScope.get(e.collection);if(E===void 0)E=new Map,u.historyByCollectionScope.set(e.collection,E);let j=E.get(e.scope);if(j===void 0)j=[],E.set(e.scope,j);j.push(x);let _=!1;for(let F of P){let K=F.coordinate,ce=U(u,K.scope,K.row,K.collection);if(F.effective.kind==="absent"&&ce.kind==="present")K.enablingBirth=O;else if(ce.kind==="absent")K.enablingBirth=void 0;let Ne=ce.kind==="present"?K.enablingBirth:void 0;if(!Object.is(F.placement,Ne))_=!0}if(_)qn(u,e.collection);let oe=u.queryRevisionByCollection?.get(e.collection);if(oe!==void 0)u.queryRevisionByCollection.set(e.collection,oe+1);t.markRow(O)},Ue=()=>new Nn,Ge=(t)=>{let e=i.inspectThenable(t);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw i.containThenable(e),Ue();if(t===void 0)throw new xn;return t},Un=(t,e,o)=>i.runGuarded(o,()=>{let r;try{r=Reflect.apply(t,void 0,[e])}catch(n){let l=i.inspectThenable(n);if(l.kind==="not-thenable")throw n;if(l.kind==="inspection-error")throw l.error;throw i.containThenable(l),Ue()}return Ge(r)}),Ye=(t,e,o,r,n)=>{let l=Te(o),d=i.runGuarded(n,()=>Ge(r)),u=re(t,e,o,l);we(t,u,"set",Object.freeze({kind:"present",value:d}),me(d),J(d))},Ze=(t,e,o,r,n)=>{let l=Te(o);if(typeof r!=="function")throw TypeError("Collection row update requires an updater");let d=re(t,e,o,l),u=U(ne(t),e,o,l);if(u.kind==="absent")throw new In;let v=Un(r,u.value,n);we(t,d,"update",Object.freeze({kind:"present",value:v}),me(v),J(v))},Xe=(t,e,o)=>{let r=re(t,e,o);we(t,r,"delete",Object.freeze({kind:"absent"}),Ce,q)},Je=(t,e,o)=>{let r=re(t,e,o),n=c===void 0?U(ne(t),e.parent,o,r.collection):r.baseline.inherited;we(t,r,"reset",Object.freeze({kind:"reset"}),he,n)},Qe=(t,e,o)=>{let r=re(t,e,o),n=U(ne(t),e,o,r.collection);return n.kind==="present"?n.value:void 0},De=(t,e,o)=>{if(!i.lookupCollection(o))throw TypeError("Collection draft read requires a valid collection");let r=ne(t),n=r.revisionByCollection.get(o)??0,l=r.membershipMemo.get(e),d=l?.get(o);if(d?.revision===n)return d.rows;let u=c===void 0&&typeof e.createOutcomeToken==="function"?te(Ee(e,o)):G,v=new Map,P=r.historyByCollectionScope.get(o),O=e;while(O!==void 0){for(let E of P?.get(O)??[])if(!v.has(E.row))v.set(E.row,re(t,e,E.row,o));O=O.parent}let x=[];if(u.length)g(e,W,u.length);for(let E of u){let j=v.get(E);if(j===void 0||j.enablingBirth===X)x.push(E)}let D=[];if(v.size!==0)g(e,W,v.size);for(let E of v.values())if(typeof E.enablingBirth==="number"&&U(r,E.scope,E.row,E.collection).kind==="present")D.push(E);D.sort((E,j)=>{let _=E.enablingBirth,oe=j.enablingBirth;if(_===oe)return E.discoveryIndex-j.discoveryIndex;return _-oe});for(let E of D)x.push(E.row);let T;if(V(e,u,x))T=u;else if(d!==void 0&&V(e,d.rows,x))T=d.rows;else T=Object.freeze(x),g(e,pe);if(l===void 0)l=new Map,r.membershipMemo.set(e,l);return l.set(o,Object.freeze({revision:n,rows:T})),T},Gn=(t)=>{let e=f.get(t);if(e===void 0)return;let o=0;for(let l of e.membershipMemo.values())o+=l.size;let r=new WeakMap;for(let[l,d]of e.revisionByCollection)r.set(l,Object.freeze({value:d}));let n=(l)=>Object.freeze({id:l.discoveryIndex,baselineLocal:l.baseline.local.kind,baselineEffective:l.baseline.effective.kind,baselineInherited:l.baseline.inherited.kind,final:l.final?.kind,enablingBirth:l.enablingBirth===X?"baseline":l.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((l)=>[...l.values()]).sort((l,d)=>l.discoveryIndex-d.discoveryIndex).map(n)),planOrder:Object.freeze(e.planOrder.map(n)),history:Object.freeze(e.history.map((l)=>Object.freeze({coordinateId:l.coordinateId,kind:l.kind,sequence:l.sequence}))),membershipMemoCount:o,revision:(l)=>r.get(l)?.value??0})},Yn=(t)=>{let e=t;if(!e.hasRows)return;let o=f.get(e);if(o===void 0)throw Error("Collection row draft lane is missing");let r,n=[],l=[],d=[],u=[],v=new WeakSet,P=new WeakMap,O=new Map,x=[],D=new Map,T=Object.freeze([]),E={baselinePresent:!1,transitions:T,birth:void 0},j={baselinePresent:!0,transitions:T,birth:X},_=new Map,oe=new Map,F=(s)=>{let y=O.get(s.scope);if(y===void 0)y=new Map,O.set(s.scope,y);if(y.set(s.atom,s),s.existing!==void 0)P.set(s.existing,s)},K=(s)=>{let y=P.get(s);if(y!==void 0)return y;let b=[],M=s,w;while(M!==void 0){g(M.scope,ae);let h=P.get(M);if(h!==void 0){w=h;break}b.push(M),M=M.inheritedFrom}for(let h=b.length-1;h>=0;h--){let p=b[h],R={scope:p.scope,atom:p.atom,existing:p,parent:w,beforeRows:p.ordered===void 0?te(p):G,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};if(p.ordered!==void 0){let C;Object.defineProperty(R,"beforeRows",{get:()=>C??=te(p)})}F(R),w=R}return w},ce=(s,y)=>{let b=O.get(s)?.get(y);if(b!==void 0)return b;let M=[],w=s,h;while(w!==void 0){let p=O.get(w)?.get(y);if(p!==void 0){g(w,ae),h=p;break}let R=m.get(w)?.memberships?.get(y);if(R!==void 0){h=K(R);break}g(w,ae),M.push(w),w=w.parent}for(let p=M.length-1;p>=0;p--){let R={scope:M[p],atom:y,existing:void 0,parent:h,beforeRows:h?.beforeRows??G,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};h?.plannedChildren.push(R),d.push(R),F(R),h=R}return h},Ne=(s)=>{let y=D.get(s);if(y!==void 0)return y;return y={collection:s,top:void 0},D.set(s,y),x.push(y),y},eo=(s,y)=>{y.affected=!0;let b=s.top;if(b===void 0)s.top=y;let M,w=y;while(w!==void 0){if(w.containsAffected){if(M??=w,Object.is(w,b))return}else w.containsAffected=!0;w=w.parent}if(b!==void 0)s.top=M},no=(s,y)=>{if(s.existing?.ordered!==void 0)return s.existing.ordered.entries.has(y);let b=oe.get(s);if(b===void 0){if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);b=new Set(s.beforeRows),oe.set(s,b)}return b.has(y)},$e=(s,y,b,M)=>{if(B!==void 0)B.states++;let w=I(s.scope,y).kind;if(M===void 0)return w==="none"?b:w==="present"?j:E;let h=b.baselinePresent,p=w==="present"||w==="none"&&h,R=p,C=p?X:void 0,k=[],S=0,A=0;while(S<b.transitions.length||A<M.length){let ie=b.transitions[S],ee=M[A],Z;if(ie!==void 0&&(ee===void 0||ie.sequence<ee.sequence))h=ie.present,Z=ie.sequence,S++;else w=ee.kind==="present"?"present":ee.kind==="absent"?"absent":"none",Z=ee.sequence,A++;let on=w==="present"||w==="none"&&h;if(on===p)continue;p=on,C=p?Z:void 0,k.push({sequence:Z,present:p})}if(!k.length)return p?j:E;return{baselinePresent:R,transitions:k,birth:C}},xe=(s)=>{let y=_.get(s);if(y!==void 0)return y;let b=[],M=s;while(M!==void 0&&!_.has(M))b.push(M),M=M.parent;let w=M===void 0?new Map:_.get(M);for(let h=b.length-1;h>=0;h--){let p=b[h],R=new Map;for(let k of o.historyByCollectionScope.get(p.atom)?.get(p.scope)??[]){let S=R.get(k.row);if(S===void 0)S=[],R.set(k.row,S);S.push(k)}let C=new Map;if(w.size!==0)g(p.scope,W,w.size);for(let[k,S]of w)C.set(k,$e(p,k,S,R.get(k))),R.delete(k);for(let[k,S]of R){let A=p.parent!==void 0&&no(p.parent,k)?j:E;C.set(k,$e(p,k,A,S))}_.set(p,C),w=C}return _.get(s)},en=(s)=>{if(s.finalRows!==void 0)return s.finalRows;if(s.existing?.ordered!==void 0){let p=xe(s),R=[],C=[];for(let[S,A]of p){if(A.baselinePresent&&A.birth!==X)R.push(S);if(typeof A.birth==="number")C.push({row:S,birth:A.birth})}C.sort((S,A)=>S.birth-A.birth);let k=C.map((S)=>S.row);return s.membershipChangedFromBefore=s.existing.ordered.changes(R,k),s.orderedPatch={removals:R,births:k},(r??=[]).push(s),s.membershipChanges=p,G}if(s.existing!==void 0)N?.push(s.existing);let y=[],b=[],M=s.existing!==void 0&&H(s.scope)!==void 0,w;if(c===void 0){let p=xe(s);if(M)w=p;if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);for(let R of s.beforeRows){let C=p.get(R);if(C===void 0||C.birth===X)y.push(R)}if(p.size!==0)g(s.scope,W,p.size);for(let[R,C]of p){if(w!==void 0&&(C.baselinePresent&&C.birth===void 0||!C.baselinePresent&&typeof C.birth==="number"))s.membershipChanges=w;if(typeof C.birth==="number")b.push({row:R,birth:C.birth})}}else{let p=new Map,R=o.historyByCollectionScope.get(s.atom),C=s.scope;while(C!==void 0){for(let k of R?.get(C)??[])if(!p.has(k.row))p.set(k.row,re(e,s.scope,k.row,s.atom));C=C.parent}if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);for(let k of s.beforeRows){let S=p.get(k);if(S===void 0||S.enablingBirth===X)y.push(k)}if(p.size!==0)g(s.scope,W,p.size);for(let k of p.values())if(typeof k.enablingBirth==="number"&&U(o,k.scope,k.row,k.collection).kind==="present")b.push({row:k.row,birth:k.enablingBirth})}b.sort((p,R)=>p.birth-R.birth);for(let p of b)y.push(p.row);let h=!V(s.scope,s.beforeRows,y);if(s.membershipChangedFromBefore=h,s.existing!==void 0&&!h)s.finalRows=s.beforeRows;else s.finalRows=Object.freeze(y),g(s.scope,pe);return s.finalRows};for(let s of o.planOrder){let y=s.final;if(y===void 0)continue;g(s.scope,dn);let b=y.kind==="present"?me(y.value):y.kind==="absent"&&s.scope.parent!==void 0?Ce:he,M=!tn(I(s.scope,s.row),b);n.push(Object.freeze({coordinate:s,local:b,ownershipChanged:M}));let w=Ne(s.collection),h=le(Q(s.scope,s.row,s.collection));if(h.local.kind!==b.kind)ce(s.scope,s.collection);let R=h.effective.kind==="present"?X:void 0;if(!Object.is(R,s.enablingBirth))eo(w,ce(s.scope,s.collection));let C=m.get(s.scope)?.rowViews?.get(s.row);if(C===void 0)continue;let k=[C];while(k.length){let S=k.pop();if(v.has(S))continue;v.add(S),g(S.scope,Pe);let A=S.served.outcome.kind==="value"&&S.served.outcome.value!==void 0?J(S.served.outcome.value):q,ie=U(o,S.scope,S.atom,s.collection);if(ye(A,ie))continue;l.push(Object.freeze({scope:S.scope,atom:S.atom,record:S,before:A,outcome:ie}));let ee=[];S.inheritingChildren.forEach((Z)=>{S.scope.coordinator.recordCounter(1),ee.push(Z)});for(let Z=ee.length-1;Z>=0;Z--)k.push(ee[Z])}}for(let s of x){let y=s.top;if(y===void 0)continue;let b=new Set,M=[{node:y,affected:!1}];while(M.length){let w=M.pop(),h=w.node;if(b.has(h))continue;b.add(h),g(h.scope,ae);let p=w.affected||h.affected;if(p){let C=en(h);if(h.existing!==void 0&&(h.orderedPatch!==void 0?h.membershipChangedFromBefore:!Object.is(C,h.beforeRows)))u.push(Object.freeze({scope:h.scope,atom:h.atom,node:h,record:h.existing,rows:C}))}let R=[];h.existing?.inheritingChildren.forEach((C)=>{h.scope.coordinator.recordCounter(1);let k=p?K(C):P.get(C);if(k!==void 0&&(p||k.containsAffected))R.push(k)});for(let C of h.plannedChildren)if(p||C.containsAffected)R.push(C);for(let C=R.length-1;C>=0;C--)M.push({node:R[C],affected:p})}}for(let s of d){if(s.finalRows!==void 0)continue;if(s.parent===void 0){en(s);continue}s.finalRows=s.beforeRows,s.membershipChangedFromBefore=!1}let nn;if(a!==void 0&&o.planOrder.some((s)=>a.active(s.collection))){let s=new Map;for(let b of o.planOrder){if(!a.active(b.collection))continue;let M=m.get(b.scope)?.memberships?.get(b.collection);if(M===void 0)continue;let w=[M];while(w.length){let h=w.pop();if(h.ordered===void 0)continue;g(h.scope,Dn);let p=s.get(h);if(p===void 0)s.set(h,p=new Set);p.add(b.row),h.indexedChildren?.forEach((R)=>w.push(R))}}let y=[];for(let[b,M]of s){if(b.ordered===void 0)continue;let w=K(b),h=xe(w),p=[];for(let R of M){let C=L(b.scope,R),k=U(o,b.scope,R,b.atom),S=h.get(R)?.birth;if(ye(C,k)&&typeof S!=="number")continue;p.push({row:R,before:C.kind==="present"?C.value:void 0,after:k.kind==="present"?k.value:void 0,rank:k.kind==="absent"?void 0:typeof S==="number"?b.ordered.nextRank+S:b.ordered.entries.get(R)?.rank})}if(p.length)y.push({scope:b.scope,collection:b.atom,changes:p})}nn=a.prepare(y)}return{commit:Qn,indexPlan:nn,orderedNodes:r,rows:Object.freeze(n),rowSettlements:Object.freeze(l),membershipInstalls:Object.freeze(d),membershipSettlements:Object.freeze(u),sources:Object.freeze([...l,...u])}},Zn=(t)=>{let e=t,o=!1;for(let r of e.rowSettlements){let{record:n,before:l,outcome:d}=r;g(n.scope,pn),z(n.scope,l.kind==="absent"?Rn:d.kind==="absent"?gn:kn,n.atom,i.lookupRow(n.atom))}for(let r of e.membershipSettlements)for(let[n,l]of r.node.membershipChanges??[]){let d=l.baselinePresent&&l.birth===void 0?vn:!l.baselinePresent&&typeof l.birth==="number"?Sn:void 0;if(d!==void 0)z(r.node.scope,d,n,r.node.atom)}for(let r of e.rows){let n=r.coordinate.finalOperation;if(n!==void 0)z(r.coordinate.scope,n==="set"?bn:n==="update"?wn:n==="reset"?yn:Cn,r.coordinate.row,r.coordinate.collection);if(!r.ownershipChanged)continue;o=!0;let{row:l,scope:d}=r.coordinate;if(r.local.kind==="none"){let O=m.get(d);if(O?.rowLocals?.delete(l),O?.ownedRows?.delete(l))g(d,je);if(O?.ownedRows?.size===0){if(O.ownedRows=void 0,O.rowLocals=void 0,O.liveRowViews===void 0&&O.liveMemberships===void 0)m.delete(d)}continue}let u=ue(d),v=u.rowLocals;if(v===void 0)v=new WeakMap,u.rowLocals=v;let P=u.ownedRows;if(P===void 0)P=new Set,u.ownedRows=P,g(d,hn);if(v.set(l,r.local),!P.has(l))P.add(l),g(d,mn)}for(let r of e.membershipInstalls)r.installed=Oe(r.scope,r.atom,r.finalRows,r.parent!==void 0&&r.finalRows===r.beforeRows);for(let r of e.orderedNodes??[]){let{existing:n,orderedPatch:l}=r;if(!r.membershipChangedFromBefore)continue;for(let d of l.removals)n.ordered.remove(d);for(let d of l.births)n.ordered.append(d);n.snapshotDirty=!0,n.served=se(n.scope,G,n.served.token)}if(e.membershipSettlements.length)return!0;for(let r of e.membershipInstalls)if(r.membershipChangedFromBefore)return!0;return o},Xn=(t)=>{let e=t;for(let o of e.rows){if(!o.ownershipChanged)continue;let{row:r,scope:n}=o.coordinate,l=m.get(n)?.rowViews?.get(r);if(l===void 0)continue;if(o.local.kind!=="none"||n.parent===void 0)ve(l);else Kn(l,We(n.parent,r))}for(let o of e.membershipInstalls){let r=o.installed,n=o.parent?.existing??o.parent?.installed;if(r!==void 0&&n!==void 0)qe(r,n)}},Jn=(t)=>{let e=t;for(let r of e.rowSettlements){let{record:n,outcome:l}=r;n.served=Object.freeze({token:n.scope.createOutcomeToken(),outcome:ln(l)}),g(n.scope,fn),z(n.scope,Mn,n.atom,i.lookupRow(n.atom)),n.scope.coordinator.reachSubscriptionTarget(n.scope,n.atom)}for(let r of e.membershipSettlements){let{record:n,rows:l}=r;n.served=se(n.scope,n.ordered===void 0?l:n.served.outcome.kind==="value"?n.served.outcome.value:G),g(n.scope,un),z(n.scope,On,n.atom),n.scope.coordinator.reachSubscriptionTarget(n.scope,n.atom)}let o=e.indexPlan?.publish();if(o?.length)return[...e.sources,...o];return e.sources.length?e.sources:void 0},Qn=function(t){if(t===0)return Zn(this);if(t===1)return Xn(this);return Jn(this)},$n=(t)=>{let e=t;a?.dispose(e);let o=m.get(e);if(o===void 0)return;o.liveRowViews?.forEach((n)=>{ve(n),n.inheritingChildren.clear()}),o.liveMemberships?.forEach((n)=>{Fe(n),n.inheritingChildren.clear(),n.indexedChildren?.clear(),n.ordered?.entries.clear(),n.ordered=void 0,n.snapshotDirty=!1,n.served=se(n.scope,G,n.served.token)}),o.liveRowViews?.clear(),o.liveMemberships?.clear();let r=o.ownedRows?.size??0;if(r!==0)g(e,je,r);o.ownedRows?.clear(),o.rowLocals=void 0,o.ownedRows=void 0,o.rowViews=void 0,o.liveRowViews=void 0,o.memberships=void 0,o.liveMemberships=void 0,m.delete(e)};return Object.freeze({installIndexes:(t)=>a??(a=t({revision:(e,o)=>{let r=ne(e),n=r.queryRevisionByCollection??=new Map,l=n.get(o)??0;return n.set(o,l),l},membership:Wn,value:(e,o)=>{let r=L(e,o);return r.kind==="present"?r.value:void 0},draftRows:De,draftValue:(e,o,r)=>{let n=ne(e),l=o;while(l!==void 0){let d=n.byScope.get(l)?.get(r),u=d===void 0?I(l,r):Le(d);if(u.kind==="present")return u.value;if(u.kind==="absent")return;l=l.parent}return}})),has:(t)=>a?.has(t)===!0||i.lookupRow(t)!==void 0||i.lookupCollection(t),diagnosticName:i.lookupDiagnosticName,read:(t,e,o)=>{let r=t,n=e;if(a?.has(o))return{kind:"value",value:a.read(r,n,o)};if(i.lookupRow(o)!==void 0)return Object.freeze({kind:"value",value:Qe(r,n,o)});if(i.lookupCollection(o))return Object.freeze({kind:"value",value:De(r,n,o)});throw TypeError("Unknown collection scratch source")},stage:(t,e,o,r,n,l)=>{let d=t,u=e;if(o==="set")Ye(d,u,r,n,l);else if(o==="update")Ze(d,u,r,n,l);else if(o==="delete")Xe(d,u,r);else Je(d,u,r)},scope:(t,e)=>{if(e===void 0){$n(t);return}if(a?.has(e))return a.scope(t,e);if(i.lookupRow(e)!==void 0)return We(t,e).served;if(!i.lookupCollection(e))return;let o=Ee(t,e);return te(o),o.served},plan:Yn,stageSet:Ye,stageUpdate:Ze,stageDelete:Xe,stageReset:Je,readDraftRow:Qe,readDraftCollection:De,beginMembershipRebuildTraceForTest:()=>{if(N!==void 0)throw Error("A membership rebuild trace is already active");let t=[];return N=t,()=>{if(t===void 0)throw Error("The membership rebuild trace is already finished");N=void 0;let e=Object.freeze([...t]);return t.length=0,t=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(B!==void 0)throw Error("A membership placement trace is already active");let t={coordinates:0,states:0};return B=t,()=>{if(t===void 0)throw Error("The membership placement trace is already finished");B=void 0;let e=Object.freeze({...t});return t=void 0,e}},inspectDraft:Gn})};var oo={ref:(i)=>new WeakRef(i),registry:(i)=>{let c=new FinalizationRegistry(i);return Object.freeze({register:(a,f,m)=>c.register(a,f,m),unregister:(a)=>c.unregister(a)})}};class He{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(i,c,a=oo,f){this.#o=i,this.#t=f,this.#r=c,this.#n=a.registry((m)=>{let N=m.route;if(N.entry!==m)return;N.entry=void 0,this.#c(N)}),this.#i=(m)=>a.ref(m)}#i;getOrCreateOne(i,c){return this.#s(this.#l(this.#e,i),c)}getOrCreateTuple(i,c){let a=this.#e;for(let f=0;f<i.length;f++)a=this.#l(a,i[f]);return this.#s(a,c)}get routeCount(){let i=0,c=(a)=>{if(a.children===void 0)return;for(let f of a.children.values())i++,c(f)};return c(this.#e),i}hasRoute(i){let c=this.#e;for(let a=0;a<i.length;a++){let f=c.children?.get(i[a]);if(f===void 0)return!1;c=f}return!0}#l(i,c){let a=i.children??(i.children=new Map),f=a.get(c);if(f!==void 0)return f;return f={parent:i,parentKey:c,children:void 0,entry:void 0},a.set(c,f),f}#s(i,c){let a=i.entry;if(a?.kind==="ready"){let m=a.reference.deref();if(m!==void 0)return m;if(this.#n.unregister(a),i.entry===a)i.entry=void 0}else if(a?.kind==="building"){let m=a.fault??this.#r();throw a.fault=m,m}let f={kind:"building",route:i,fault:void 0};i.entry=f;try{let m=this.#o(c);if(f.fault!==void 0)throw f.fault;this.#t?.(m);let N={kind:"ready",route:i,reference:this.#i(m)};return i.entry=N,this.#n.register(m,N,N),m}catch(m){if(i.entry===f)i.entry=void 0;throw this.#c(i),f.fault??m}}#c(i){let c=i;while(c.parent!==void 0&&c.entry===void 0&&(c.children===void 0||c.children.size===0)){let a=c.parent,f=a.children;if(f?.get(c.parentKey)!==c)return;if(f.delete(c.parentKey),f.size===0)a.children=void 0;c=a}}}var to=(i)=>new WeakRef(i),ke,ro=(i)=>{let c=ge(i),a=ke??(ke=new WeakMap),f=a.get(c);if(f!==void 0)return f;return f={collections:new WeakMap,rows:new WeakMap},a.set(c,f),f};class _n extends Error{code="VALDRES_INVALID_COLLECTION_KEY";constructor(){super("Collection keys must be strings, finite numbers, bigints, booleans, or null");this.name="InvalidCollectionKeyError",Object.freeze(this)}}var Be=()=>new _n,Ke=(i)=>{if(i===null)return null;switch(typeof i){case"string":case"bigint":case"boolean":return i;case"number":if(!Number.isFinite(i))throw Be();return Object.is(i,-0)?0:i;default:throw Be()}},Pn=(i)=>{throw be(i),Be()},io=(i,c,a)=>_e(i,"collection-encoder",(f)=>{let m;try{m=Reflect.apply(c,void 0,[f])}catch(B){let H=fe(B);if(H.kind==="not-thenable")throw B;if(H.kind==="inspection-error")throw H.error;return Pn(H)}let N=fe(m);if(N.kind==="not-thenable")return m;if(N.kind==="inspection-error")throw N.error;return Pn(N)},[a],Ke,()=>TypeError("collection encodeKey cannot call family or collection accessors")),lo=(i)=>{if(i===void 0)return{};if(typeof i!=="object"||i===null)throw TypeError("collection options must be an object");for(let f of Reflect.ownKeys(i))if(f!=="encodeKey"&&f!=="indexes"&&f!=="name")throw TypeError("collection options contain an unknown option");let c;if(Object.prototype.hasOwnProperty.call(i,"encodeKey")){let f=Reflect.get(i,"encodeKey");if(typeof f!=="function")throw TypeError("collection encodeKey must be a function");c=f}let a=Reflect.get(i,"name");return{...c===void 0?{}:{encodeKey:c},...a===void 0?{}:{name:a}}},so=()=>TypeError("collection cannot recursively construct the same row"),co=()=>TypeError("presence requires a same-domain CollectionRow"),ao=(i,c)=>{let a=ke?.get(ge(i));if(typeof c==="object"&&c!==null||typeof c==="function"){let f=a?.rows.get(c);if(f!==void 0)return f}throw ze(i,c),co()};function So(i,c,a){Vn(i);let{encodeKey:f,name:m}=lo(c),N;if(c!==void 0&&Object.prototype.hasOwnProperty.call(c,"indexes")){let I=Reflect.get(c,"indexes");if(typeof I!=="object"||I===null||Array.isArray(I))throw TypeError("collection indexes must be an extractor map");let L=Reflect.ownKeys(I).map((Y)=>{let Q=Reflect.get(I,Y);if(typeof Y!=="string"||typeof Q!=="function")throw TypeError("collection indexes must be named scalar extractors");return[Y,Q]});if(L.length)N=Object.freeze(Object.fromEntries(L))}let B=[],H,g=Object.assign(function(L){Ae(i);let Y=f===void 0?Ke(L):io(i,f,L);B[0]=Y;try{return H.rows.getOrCreateOne(Y,B)}finally{B.pop()}},{kind:"collection"}),z=Ve(i,g),V,ue=new He((I)=>{let L=I[0];return Ve(i,{kind:"collection-row",key:L})},so,a,(I)=>{if(V===void 0)throw Error("Collection definition registry is not ready");V.rows.set(I,{definition:H,presence:void 0})});return H=Object.freeze({collection:z,indexes:N,...m===void 0?{}:{name:m},rows:ue,referencePresence:a===void 0?to:(I)=>a.ref(I)}),V=ro(i),V.collections.set(z,H),Hn(i,(I)=>Ln({lookupRow:(L)=>V.rows.get(L)?.definition.collection,lookupCollection:(L)=>V.collections.has(L),lookupDiagnosticName:(L)=>V.rows.get(L)?.definition?.name??V.collections.get(L)?.name,runGuarded:(L,Y)=>jn(I,L,Y),inspectThenable:fe,containThenable:be})),z}var vo=(i,c)=>{Ae(i);let a=ao(i,c),f=a.presence?.deref();if(f!==void 0)return f;let m=Bn(i,(N)=>N(c)!==void 0);return a.presence=a.definition.referencePresence(m),m},Mo=(i,c,a)=>{let f=ke?.get(ge(i))?.collections.get(c);if(f===void 0)throw ze(i,c),TypeError("query requires a same-domain Collection");let m=f.indexes!==void 0&&Object.prototype.hasOwnProperty.call(f.indexes,a)?f.indexes[a]:void 0;if(m===void 0)throw TypeError("query requires a declared equality index");return(N)=>_e(i,"collection-encoder",(B)=>{let H;try{H=m(B)}catch(z){let V=fe(z);if(V.kind==="thenable")throw be(V),TypeError("Index extractors must return a synchronous scalar");if(V.kind==="inspection-error")throw V.error;throw z}let g=fe(H);if(g.kind==="thenable")throw be(g),TypeError("Index extractors must return a synchronous scalar");if(g.kind==="inspection-error")throw g.error;return Ke(H)},[N])};
2
+ export{He as a,Nn as b,xn as c,In as d,_n as e,So as f,vo as g,Mo as h};
@@ -0,0 +1,2 @@
1
+ class q extends Error{seal(){Object.freeze(this)}}class be extends q{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 ze extends q{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 ie extends q{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class K extends q{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class _e extends q{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class Ae extends q{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class Be extends q{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var _=Symbol(),G=Symbol(),ve=Symbol(),V=Symbol(),Le=(e,t)=>e.kind===t.kind&&(e.kind==="value"?Object.is(e.value,t.value):Object.is(e.error,t.error)),it=Object.freeze({kind:"not-thenable"}),Ht=()=>{},Gt=Reflect.apply,st=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}var at=new WeakSet,pn=(e)=>at.has(e);class He extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ge extends T{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source;constructor(e,t="owned-mutation"){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.source=t,this.seal()}}class J extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class ge extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class ke extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class we extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class se extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ae extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class de 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 ce extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class We extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class qe extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class Re extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var j=(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})}},I=(e)=>{try{Gt(e.then,e.target,[void 0,Ht])}catch{}},le=(e)=>{let t=j(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 I(t),Object.freeze({kind:"error",error:new ae})},Ke=(e)=>{try{return le(e())}catch(t){let n=j(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 I(n),Object.freeze({kind:"error",error:new ae})}},ue=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},W=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o!==void 0&&("selectorActivity"in o)?o.selectorActivity:void 0,i=r===void 0?Object.freeze({kind:"guarded-callback",session:t}):Object.freeze({kind:"guarded-callback",session:t,selectorActivity:r});try{return ue(e,i,n)}finally{let s=t.getControlFault();if(s.kind==="fault")throw e.externalRuntime?.guard(s.error),s.error}},dt=(e,t,n)=>{try{return ue(e,Object.freeze({kind:"subscriber",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},Ce=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o!==void 0&&("selectorActivity"in o)?o.selectorActivity:void 0,i=Object.is(r?.session,t)?r?.parentSelectorActivity:r,s=i===void 0?Object.freeze({kind:"selector",session:t}):Object.freeze({kind:"selector",session:t,parentSelectorActivity:i});return ue(e,s,n)},ct=(e,t,n)=>ue(e,Object.freeze({kind:"transaction",transaction:t}),n),Oe=(e,t,n)=>{try{return ue(e,Object.freeze({kind:"transaction-result",session:t}),n)}finally{let o=t.getControlFault();if(o.kind==="fault")throw o.error}},lt=(e)=>{let t=new J;throw e.externalRuntime?.guard(t),t},B=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new ge(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new ke;lt(e)},Te=(e,t)=>{if(e.activity?.kind==="subscriber")return e.activity.session;B(e,t)},ut=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new J;throw e.latchControlFault(r),t.latchControlFault(r),r},ft=(e)=>{Te(e,"Store unsubscribe")},Ee=(e,t,n)=>{if(!n)throw new we;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new ge("Transaction cursor operation");if(o?.kind==="guarded-callback"||o?.kind.startsWith("external-"))lt(e);throw new ke},ht=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},Z=(e,t,n)=>{if(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t))return"local";if(t!==null&&t!==void 0){let o=Object.getOwnPropertyDescriptor(t,st);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new He;throw at.add(r),ht(e,n).latchControlFault(r),r}}return"invalid"},M=(e,t,n)=>{if(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t))return"local";let o=e.activity,r=ht(e,n);if(o!==void 0&&"session"in o)try{return Z(e,t,r)}finally{let i=r.getControlFault();if(i.kind==="fault")throw i.error}return W(e,r,()=>Z(e,t,r))},fe=(e,t)=>(Object.defineProperty(e,st,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),ee=(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 J;throw t.session.latchControlFault(o),o},Ne=(e)=>({kind:e}),he=(e,t)=>{ee(e);let n=e[G],o=Object.freeze(fe(t,e.ownerToken));return e.states.add(o),n?.definitions?.add(o),o};var pt=Object.freeze({kind:"not-thenable"}),Wt=()=>{},qt=Reflect.apply,St=Symbol("selector dependency path root"),bt=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return pt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):pt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},At=(e)=>{try{qt(e.then,e.target,[void 0,Wt])}catch{}},Kt=(e)=>Object.freeze(e),Ut=(e)=>Object.freeze(e),N=(e,t,n,o)=>{let r=Ut(o);return Object.freeze({selector:e,token:t,outcome:Kt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Yt:Object.freeze(r.map((i)=>i.node))})},Yt=Object.freeze([]),De=32,te=8192,Xt=2*De,vt=128,Qt=4096;class gt{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(te,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>=De&&e.size<=te,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>te){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=De&&e.size<=te;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,De),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Xt){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(te,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>te||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 $t=(e,t)=>new gt(e,t),U=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=vt-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},Zt=(e,t,n,o,r,i=!0,s)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let a=n.visitSelectorDependents;if(a===void 0)return"unsupported";if(s===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let f=s===void 0?void 0:o.getTransientDependencies(n,e);if(f!==void 0){if(f.length===0)return"proven-terminal"}else{let S=n.getSelectorDependencyNodes;if(S!==void 0){let y=S.call(n,e);if(y===void 0||y.length===0)return"proven-terminal"}}}if(!i)return"disabled";let d={remaining:vt},c=[t],l=new Set(c),h=0,u=0,m=1;while(c.length>0){if(d.remaining===0)return U("budget-exhausted",d,h,u,m,r);d.remaining--,h++;let f=c.pop();if(Object.is(f,e))return U("path-possible",d,h,u,m,r);let S=!1,y=(w)=>{if(u++,Object.is(w,e))return S=!0,!1;if(!l.has(w)){if(l.add(w),c.push(w),c.length>m)m=c.length}return!0},ne=a.call(n,f,d,y);if(S)return U("path-possible",d,h,u,m,r);if(!ne)return U("budget-exhausted",d,h,u,m,r);let x=s?.get(f);if(x!==void 0)for(let w of x){if(d.remaining===0)return U("budget-exhausted",d,h,u,m,r);if(d.remaining--,!y(w))return U("path-possible",d,h,u,m,r)}}return U("proven-reverse",d,h,u,m,r)},Jt=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let u=Zt(e,t,n,o,void 0,r===1?s?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(u==="proven-terminal"||u==="proven-reverse")return;if(u==="budget-exhausted"){if(r===1&&s!==void 0)s.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=s?.(),c=d?.beginSearch()??!1,l=[e],h=new Map([[e,St]]);while(l.length>0){let u=l.pop();if(Object.is(u,t)){let S=[],y=u;while(y!==St)S.push(y),y=h.get(y);return S.reverse(),d?.completePositive(),Object.freeze(S)}let m=o.getTransientDependencies(n,u);if(m){if(m.length===0)continue;if(c){let S=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(S)continue}for(let S of m){if(h.has(S.node))continue;h.set(S.node,u),l.push(S.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let S=n.getSelectorDependencyNodes(u);if(S===void 0||S.length===0)continue;if(c){let y=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(y)continue}for(let y of S){if(h.has(y))continue;h.set(y,u),l.push(y)}continue}let f=n.getSelectorRecord(u);if(!f||f.dependencies.length===0)continue;if(c){let S=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(S)continue}for(let S of f.dependencies){if(h.has(S.node))continue;h.set(S.node,u),l.push(S.node)}}d?.completeNegative(h);return},mt=(e,t)=>{let n=bt(e);if(n.kind==="thenable")return At(n),new K(t);if(n.kind==="inspection-error")return n.error;return e},yt=(e,t)=>{let n=bt(e);if(n.kind==="thenable")return At(n),Object.freeze({kind:"error",error:new K(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},kt=(e,t,n,o=Jt,r,i)=>{let{node:s}=e,a=[],d=t.getSelectorRecord(s),c=d?.dependencies,l=c===void 0?new Set:void 0,h,u=0,m=t.getComparisonBaseline(s),f=!0,S=()=>{let p=l;if(p!==void 0)return p;p=new Set;for(let b of a)p.add(b.node);return l=p,p};n.enter(t,s,a);let y=t.getSelectorGraphVersion(),ne=n.getSelectorGraphPublicationCount(t),x=y,w=ne,et=y,tt=ne,Pe,Ve=!1,je=y,Se=0,Y,nt=y,me,Ie=(p,b)=>{if(p===je)return;if(je=p,Y===void 0){Se=0;return}if(Y.advanceGraphVersion(b))return;Se=0,r?.graphVersionReset()},_t=(p)=>{if(p!==je)Ie(p,void 0);if(Se++,(c?.length??0)===0&&Se<3){r?.admissionSkipped();return}if(Y===void 0){let b=c!==void 0&&c.length>0&&c.length<3;Y=$t(b?3:0,r)}if(!Y.enabled){r?.disabled();return}return Y},Bt=(p)=>{if(Ve)return;let b=t.beginSelectorGraphObservation?.(p);if(b===void 0)return;Ve=!0,Pe=b},Me=(p,b,R,g)=>R-p===g-b,ot=(p=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t),R=Me(x,w,p,b))=>{if(p===x)return;if(!Ve&&t.beginSelectorGraphObservation!==void 0){Ie(p,void 0),x=p,w=b;return}let g=Pe?.takeAddedEdges();if(Ie(p,g),R){x=p,w=b;return}if(g!==void 0){let E=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,Qt,i),P=g.length===0?void 0:{transientDependents:E,reverseProofEnabled:!0},C=!1;for(let L of g)if(o(L.head,L.tail,t,n,2,a.length,void 0,P)!==void 0){C=!0;break}if(!C){x=p,w=b;return}}for(let E=0;E<a.length;E++){let P=a[E],C=o(P.node,s,t,n,0,a.length);if(!C)continue;if(l!==void 0)for(let F=a.length-1;F>=E;F--)l.delete(a[F].node);if(a.length=E,u++,n.getControlFault().kind==="fault")return;let O=new ie(s,[s,...C]);n.latchCycle(t,s,O);return}x=p,w=b},Fe=()=>{let p=t.getSelectorGraphVersion(),b=n.getSelectorGraphPublicationCount(t);et=p,tt=b;let R=Me(x,w,p,b);if(!R)n.revalidateAncestorPrefixes(t,s);ot(p,b,R)};n.setPrefixRevalidator(t,s,ot);let Lt=(p)=>{if(!f)throw new Be;let b=n.getControlFaultForSuppliedRead();if(b.kind==="fault")throw b.error;let R=n.getCycle(t,s);if(R!==void 0)throw R;let g=n.activeCyclePath(t,p);if(g){let v=new ie(s,g);throw n.latchCycle(t,s,v),v}let E=a.length,P,C=!1;if(l===void 0){let v=c?.[E];if(v!==void 0&&Object.is(v.node,p))P=!1,C=!0;else P=S().has(p)}else P=l.has(p);if(!P&&!C&&c!==void 0&&c.length>0){let v=c[a.length];if(v!==void 0&&Object.is(v.node,p))C=!0;else{if(h===void 0){h=new Set;for(let Q of c)h.add(Q.node)}C=h.has(p)}}let L=u,O=t.serve(p,n);Fe();let F=n.getCycle(t,s);if(F!==void 0)throw F;let oe=l!==void 0?l.has(p):u===L&&a.length===E?!1:S().has(p),H=et,X=tt,z=oe||C&&H===y,ye=c===void 0&&Me(y,ne,H,X);if(!z&&!ye){if(nt=H,me===void 0)me=()=>_t(nt),me.reverseProofEnabled=!0;let v=o(p,s,t,n,1,a.length,me);if(v){let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;let rt=new ie(s,[s,...v]);throw n.latchCycle(t,s,rt),rt}}if(!oe){let v=d?.dependencies[a.length];l?.add(p),a.push(v!==void 0&&Object.is(v.node,p)&&Object.is(v.token,O.token)?v:Object.freeze({node:p,token:O.token})),Bt(p)}if(x=H,w=X,O.outcome.kind==="control-error"){n.latchControlFault(O.outcome.error,O.outcome.origin);let v=n.getControlFault();if(v.kind==="fault")throw v.error;throw O.outcome.error}let re=n.getControlFault();if(re.kind==="fault")throw re.error;if(O.outcome.kind==="error")throw new ze(p,O.outcome.error);return O.outcome.value};try{let p,b,R=!1;try{p=e.get(Lt)}catch(F){R=!0,b=F}finally{f=!1}if(R)b=mt(b,"getter");let g=R?void 0:yt(p,"getter");Fe();let E=n.getControlFault();if(E.kind==="fault")return N(s,t.createOutcomeToken(),{...E,kind:"control-error"},a);let P=n.getCycle(t,s);if(P!==void 0)return N(s,t.createOutcomeToken(),{kind:"error",error:P},a);if(R)return N(s,t.createOutcomeToken(),{kind:"error",error:b instanceof K?b:new be(s,b)},a);if(g===void 0)throw Error("Selector result classification was not completed");let C=n.getControlFault();if(C.kind==="fault")return N(s,t.createOutcomeToken(),{...C,kind:"control-error"},a);if(g.kind==="error")return N(s,t.createOutcomeToken(),{kind:"error",error:g.error instanceof K?g.error:new be(s,g.error)},a);let L=g.value,O;if(m){let F=e.equal??Object.is,oe,H,X=!1;try{oe=F(m.value,L)}catch(Q){X=!0,H=mt(Q,"comparator")}let z=X?void 0:yt(oe,"comparator");Fe();let ye=n.getControlFault();if(ye.kind==="fault")return N(s,t.createOutcomeToken(),{...ye,kind:"control-error"},a);let re=n.getCycle(t,s);if(re!==void 0)return N(s,t.createOutcomeToken(),{kind:"error",error:re},a);if(X)return N(s,t.createOutcomeToken(),{kind:"error",error:H instanceof K?H:new Ae(s,H)},a);if(z===void 0)throw Error("Selector comparator classification was not completed");let v=n.getControlFault();if(v.kind==="fault")return N(s,t.createOutcomeToken(),{...v,kind:"control-error"},a);if(z.kind==="error")return N(s,t.createOutcomeToken(),{kind:"error",error:z.error instanceof K?z.error:new Ae(s,z.error)},a);if(z.value!==!0&&z.value!==!1)return N(s,t.createOutcomeToken(),{kind:"error",error:new _e},a);if(z.value===!0)L=m.value,O=m.current?m.token:void 0}return N(s,O??t.createOutcomeToken(),{kind:"value",value:L},a)}finally{try{Pe?.close()}finally{n.leave(t,s)}}};class A{#n=[];#e;#o=0;#d;#r=en;#s;latchControlFault(e,t={}){if(this.#r.kind==="fault")return;this.#r=Object.freeze({kind:"fault",error:e,origin:t})}getControlFault(){return this.#r}setSuppliedReadGuard(e){let t=this.#s;return this.#s=e,t}getControlFaultForSuppliedRead(){return this.#s?.(),this.#r}noteSelectorGraphPublication(e){let t=this.#e;if(t===void 0){this.#e=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#d??(this.#d=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#e,e)?this.#o:this.#d?.get(e)??0}enter(e,t,n){this.#n.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#n.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#n.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#n){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.#n.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#n.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#l(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#l(e,t);for(let n=0;n<this.#n.length-1;n++){let o=this.#n[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.#n.length-1;n>=0;n--){let o=this.#n[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}captureTransientReverseDependents(e,t,n,o,r){let i=new Set,s=new Map,a=!1,d=0,c=0,l=0;for(let u of this.#n){if(d++,d>o){r?.recordSnapshot("overflow",d,c,l);return}if(!Object.is(u.host,e))continue;if(c++,u.revalidatePrefix===void 0||i.has(u.selector)){r?.recordSnapshot("unavailable",d,c,l);return}if(i.add(u.selector),Object.is(u.selector,t)){if(a||u.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,c,l);return}a=!0}for(let m of u.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,c,l);return}let f=s.get(m.node);if(f===void 0)s.set(m.node,[u.selector]);else f.push(u.selector)}}if(!a){r?.recordSnapshot("unavailable",d,c,l);return}let h=new Map;for(let[u,m]of s)h.set(u,Object.freeze(m));return r?.recordSnapshot("completed",d,c,l),h}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#l(e,t).cycleError}#l(e,t){let n=this.#n[this.#n.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#n.length-1;n>=0;n--){let o=this.#n[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var en=Object.freeze({kind:"none"});var wt=Symbol("no-committed-selector-baseline");class Ue{#n;#e=new Map;#o=new Map;#d=new Map;#r;#s=1;#l=0;#a;#i;constructor(e,t,n){this.#n=e,this.#r=t,this.#a=n,this.#i=e.trackPath?[]:void 0}readSelector(e){let t=new A,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#r+1)throw Error("Scratch selector generation is not contiguous");this.#r=e,this.#e.clear(),this.#o.clear()}revoke(){this.#e.clear(),this.#o.clear(),this.#d.clear(),this.#n=void 0}serve(e,t){if(this.#i===void 0)return this.#c(e,t);this.#i.push(e);try{return this.#c(e,t)}finally{this.#i.pop()}}#c(e,t){let n=this.#u(),o=n.resolve(e,t);if(o.kind!=="selector"){let a=this.#o.get(e);if(a!==void 0)return a;let d=Object.freeze({token:this.createOutcomeToken(),outcome:n.read(e,o.kind,t,this.#i)});return this.#o.set(e,d),d}let r=this.#e.get(e);if(r!==void 0)return r.served;let i=n.run(t,()=>this.#a(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#l++,t.noteSelectorGraphPublication(this),this.#e.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#e.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#l}getComparisonBaseline(e){let t=this.#d.get(e);if(t===void 0)t=this.#u().baseline(e)??wt,this.#d.set(e,t);return t===wt?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#s++})}#u(){if(this.#n===void 0)throw Error("Scratch selector host is revoked");return this.#n}}var Rt=4096,tn=Object.freeze([]);class Ot{onDeadReference;onEmptinessProbe;#n=new WeakMap;#e=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#n.has(e))return;let t=new WeakRef(e);this.#n.set(e,t),this.#e.add(t)}delete(e){let t=this.#n.get(e);if(t===void 0)return;this.#n.delete(e),this.#e.delete(t)}forEach(e){for(let t of this.#e){let n=t.deref();if(n===void 0){this.#e.delete(t),this.onDeadReference?.();continue}e(n)}}visitWithin(e,t){for(let n of this.#e){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#e.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}isEmpty(){for(let e of this.#e){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#e.delete(e),this.onDeadReference?.()}return!0}clear(){this.#e.clear(),this.#n=new WeakMap}}class xe{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#n=new WeakMap;#e;#o=new WeakMap;#d;#r=new WeakMap;#s=new WeakSet;#l=0;#a=0;#i;#c=!1;#u;#p="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#y(),this.#e=this.#y()}get status(){return this.#p}get facade(){if(this.#u===void 0)throw Error("Store scope facade is not installed");return this.#u}installFacade(e){if(this.#u!==void 0)throw Error("Store scope facade is already installed");this.#u=e}markDisposing(){if(this.#p==="live")this.#p="disposing"}markDisposed(){this.#p="disposed"}getAtomView(e){return this.#n.get(e)}getMaterializedServedOutcome(e){if(e.kind!=="selector")return this.#n.get(e)?.served;let t=e,n=this.#o.get(t);return n!==void 0&&!this.#s.has(t)?n.served:void 0}createAtomView(e,t,n){let o=this.#n.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.#n.set(e,r),this.#e.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter(11);return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter(11)}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter(12)}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#s.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}externalRecord(e){return this.#o.get(e)}replaceExternalRecord(e,t){this.#o.set(e,t)}externalDependents(e){return this.#r.get(e)}markDependents(e){this.#r.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#s.add(t)})}dropRecords(){this.coordinator.runtimeDomain[V]?.scope(this),this.#e.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#e.clear(),this.atomOverrides=new WeakMap,this[_]?.release(this.coordinator),this[_]=void 0,this.#n=new WeakMap,this.#o=new WeakMap,this.#d=void 0,this.#r=new WeakMap,this.#s=new WeakSet,this.#l++,this.#m()}serve(e,t){let n=this.coordinator.runtimeDomain;if(Z(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.#n.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0){if(n.externalAtoms?.has(e))return this.coordinator.reachExternal().serve(this,e,t);let a=n[V]?.scope(this,e);if(a!==void 0)return a;throw TypeError("Unknown committed StoreTree state")}let r=e,i=this.#o.get(r);if(i?.lifecycleInClosure&&!this.#s.has(r))this.coordinator.external?.refresh(this,r,t),i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r,t),i=this.#o.get(r);if(i!==void 0&&!this.#s.has(r))return i.served;let s=Ce(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&(!this.coordinator.postSourceApply||this.coordinator.external?.dormantPull===!0))throw s.outcome.error;return this.#S(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#d?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#d;if(i===void 0)i=new WeakMap,this.#d=i;i.set(n,o)}return o}visitSelectorDependents(e,t,n){return this.#r.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#l}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#a===0)this.#i=[],this.#c=!1;this.#a++;let t=this.#i?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#c)return;let o=this.#i;if(o===void 0)return;if(t===o.length)return tn;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#a--,this.#a!==0)return;this.#i=void 0,this.#c=!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()}#S(e,t,n){let o=this.#o.get(e),i={served:Object.freeze({token:t.token,outcome:t.outcome}),dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess};i=this.coordinator.external?.selectorRecord(this,i,n)??Object.freeze(i);let s=this.#f(e,o?.dependencies??Ct,t.dependencies),a=s?this.#A(e,o?.dependencies??Ct,t.dependencies):void 0;if(s)this.#d?.delete(e);if(this.#l++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.coordinator.external?.publishedSelector(this,e,o,i),this.#s.delete(e),a!==void 0)this.#b(a);if(o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(i.served.outcome);return i.served}#f(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#r.get(o.node);if(r?.delete(e),r?.isEmpty())this.#r.delete(o.node)}for(let o of n){let r=this.#r.get(o.node);if(r===void 0)r=this.#y(),this.#r.set(o.node,r);r.add(e)}return!0}#A(e,t,n){if(this.#a===0||this.#c)return;let o=this.#i;if(o===void 0){this.#m();return}let r=Rt-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let d of t)if(i.has(d.node))s.add(d.node);let a=[];for(let d of n)if(i.has(d.node)&&!s.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#m();return}}return a}#b(e){if(e.length===0)return;let t=this.#i;if(t===void 0||t.length+e.length>Rt){this.#m();return}t.push(...e)}#m(){if(this.#a===0)return;this.#i=[],this.#c=!0}#y(){return new Ot(this.coordinator.instrumented?()=>this.coordinator.recordCounter(2):void 0)}}var Ct=Object.freeze([]);class Ye{transaction=Object.freeze({});onAllocation;#n;#e;#o;#d;#r;#s;#l;#a;#i;#c;#u;#p;#S;#f;#A;#b;externalCaptures;#m;#y=!1;generation=0;active=!0;constructor(e){this.onAllocation=e}get hasIntents(){return this.#e!==void 0||this.#o!==void 0||this.#d!==void 0||this.#r!==void 0}get hasRows(){return this.#y}installRows(e){let t=this.#m;if(t!==void 0&&t!==e)throw Error();this.#m=e}markRow(e){if(this.#m===void 0)throw Error();if(e!==this.generation)throw Error();this.#y=!0,this.#t()}get singleIntentScope(){return this.#n}get singleIntent(){return this.#o===void 0?this.#e:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#h(),n.set(e,i);i.set(t.atom,t),this.#t();return}let o=this.#d;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#h();i.set(this.#n,o);let s=this.#h();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#d=void 0,this.#n=void 0}this.#t();return}let r=this.#e;if(r===void 0){this.#n=e,this.#e=t,this.#t();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#e=t,this.#t();return}if(Object.is(this.#n,e)){let i=this.#o;if(i===void 0){this.#o=t,this.#t();return}if(Object.is(i.atom,t.atom)){this.#o=t,this.#t();return}let s=this.#h();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#d=s}else{let i=this.#h(),s=this.#h();if(s.set(r.atom,r),this.#o!==void 0)s.set(this.#o.atom,this.#o);i.set(this.#n,s);let a=this.#h();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#e=void 0,this.#o=void 0,this.#t()}forEachIntent(e){let t=this.#e;if(t!==void 0){if(e(this.#n,t),this.#o!==void 0)e(this.#n,this.#o);return}let n=this.#d;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#e;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#o;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#d?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#a!==void 0&&Object.is(this.#s,e)&&Object.is(this.#l,t))return this.#a;if(this.#c!==void 0&&Object.is(this.#s,e)&&Object.is(this.#i,t))return this.#c;if(Object.is(this.#s,e))return this.#u?.get(t);return this.#p?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#p;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#h(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#s,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#h();s.set(this.#s,r);let a=this.#h();a.set(t,n),s.set(e,a),this.#p=s,this.#u=void 0,this.#s=void 0}return}let i=this.#a;if(i===void 0){this.#s=e,this.#l=t,this.#a=n;return}if(Object.is(this.#s,e)&&Object.is(this.#l,t))return;if(Object.is(this.#s,e)){let s=this.#c;if(s===void 0){this.#i=t,this.#c=n;return}if(Object.is(this.#i,t))return;let a=this.#h();a.set(this.#l,i),a.set(this.#i,s),a.set(t,n),this.#u=a}else{let s=this.#h(),a=this.#h();if(a.set(this.#l,i),this.#i!==void 0&&this.#c!==void 0)a.set(this.#i,this.#c);s.set(this.#s,a);let d=this.#h();d.set(t,n),s.set(e,d),this.#p=s,this.#s=void 0}this.#l=void 0,this.#a=void 0,this.#i=void 0,this.#c=void 0}getFallback(e){if(Object.is(this.#S,e))return this.#f;return this.#A?.get(e)}hasFallback(e){return Object.is(this.#S,e)||(this.#A?.has(e)??!1)}setFallback(e,t){let n=this.#A;if(n!==void 0){n.set(e,t);return}if(this.#f===void 0){this.#S=e,this.#f=t;return}if(Object.is(this.#S,e)){this.#f=t;return}let o=this.#h();o.set(this.#S,this.#f),o.set(e,t),this.#A=o,this.#S=void 0,this.#f=void 0}forEachFallback(e){if(this.#S!==void 0&&this.#f!==void 0)e(this.#S,this.#f);if(this.#A!==void 0)for(let[t,n]of this.#A)e(t,n)}#t(){this.generation+=1;let e=this.#b;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#b?.get(e)}installScratchHost(e,t){let n=this.#b,o=n===void 0;if(n===void 0)n=new Map,this.#b=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#b;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#b=void 0}release(){let e=this.#m;this.#m=void 0,this.#y=!1;try{if(this.#d?.clear(),this.#r!==void 0){for(let t of this.#r.values())t.clear();this.#r.clear()}if(this.#u?.clear(),this.#p!==void 0){for(let t of this.#p.values())t.clear();this.#p.clear()}this.#A?.clear(),this.#n=void 0,this.#e=void 0,this.#o=void 0,this.#d=void 0,this.#r=void 0,this.#s=void 0,this.#l=void 0,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#u=void 0,this.#p=void 0,this.#S=void 0,this.#f=void 0,this.#A=void 0,this.#b?.clear(),this.#b=void 0,this.externalCaptures?.clear(),this.externalCaptures=void 0}finally{e?.(this)}}#h(){return this.onAllocation?.(),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]),fe(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Xe=(e,t,n)=>new Tt(e,t,n),Qe=(e)=>{let t=j(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw I(t),new se},Et=(e)=>{let t=j(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw I(t),new se};var nn=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},k=Symbol("definition domain records"),xn=(e)=>e[k].ownerToken,Pn=(e)=>e[k],Vn=(e,t)=>{let n=e[k],o=n[V];if(o!==void 0)return o;let r=t(n);return n[V]=r,r},jn=(e)=>e[k][V],on=Object.freeze([]),In=(e,t,n,o,r,i)=>{let s=e[k],a=new A,d=s.activity,c=d?.kind==="selector"?d:d?.kind==="guarded-callback"?d.selectorActivity:void 0,l=[];while(c!==void 0){let f=c.session;if(!l.includes(f))l.push(f);c=c.parentSelectorActivity}let h=t==="factory",u=s[G];s[G]={session:a,definitions:h?new WeakSet:void 0,allowDefinitions:h,...i===void 0?{}:{createAccessorFault:i}};let m=l.length===0?on:l.map((f)=>Object.freeze({selectorSession:f,previous:f.setSuppliedReadGuard(()=>{let S=s.activity;return ut(S?.kind==="guarded-callback"?S.session:a,f)})}));try{return W(s,a,()=>{let f=Reflect.apply(n,void 0,o);return r===void 0?f:r(f)})}finally{for(let f=m.length-1;f>=0;f--){let S=m[f];S.selectorSession.setSuppliedReadGuard(S.previous)}if(u===void 0)delete s[G];else s[G]=u}},rn=(e)=>{let t=e[k][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 J:t.accessorFault??=t.createAccessorFault();throw t.session.latchControlFault(o),o},Mn=(e)=>ee(e[k]),Fn=rn,zn=(e,t)=>he(e[k],t),_n=(e,t)=>M(e[k],t,new A),Bn=(e,t)=>{let n=e[k];if((typeof t==="object"||typeof t==="function")&&t!==null&&n.states.has(t)&&(n.atoms.has(t)||n.selectors.has(t)||n.externalAtoms?.has(t))){if(n[G]?.definitions?.has(t)||n[ve]?.has(t))return t;return}M(n,t,new A);return};class xt extends Set{release(e){e.recordCounter(34,this.size)}}class Pt extends WeakSet{apply(e,{atom:t,kind:n}){let o=e[_];if(n==="set"){if(!this.has(t))return;if(o===void 0)o=e[_]=new xt,e.coordinator.recordCounter(32);let r=o.size;if(o.add(t),o.size!==r)e.coordinator.recordCounter(33)}else{if(o?.delete(t))e.coordinator.recordCounter(34);if(o?.size===0)e[_]=void 0}}}var Ln=(e,t)=>{let n=e[k];if((n[ve]??(n[ve]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[_]??(n[_]=new Pt)).add(t)},Vt=new WeakMap,Hn=()=>{let e=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31,familyOwnerRetentionSetsCreated:32,familyOwnerRetains:33,familyOwnerReleases:34,liveSamples:35,serverSamples:36,transactionCaptures:37,externalClosureVisits:38,projectionPublications:39,lifecycleEdgeVisits:40,adapterSubscriptions:41,adapterCleanups:42,dirtyRounds:43,dirtySamples:44,thenableContainments:45,deliveryEntries:46,deliveryLimitHits:47,nonConvergenceTerminations:48,lifecycleRetains:49,lifecycleReleases:50}),t=51,n=new Uint32Array(51),o=Object.freeze({read(r){return n[e[r]]??0}});return Vt.set(o,(r,i)=>{n[r]+=i}),o},D=(e)=>Object.freeze({kind:"value",value:e}),sn=(e)=>Object.freeze({kind:"error",error:e}),Nt=(e)=>e.kind==="value"?D(e.value):sn(e.error),pe=(e,t)=>e[V]?.has(t)?e[V]:void 0,jt=(e,t,n,o)=>{let r=e.read(t,n,o);if(r.kind!=="value")throw r.error;return r.value};var an=(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),dn=(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)},Dt=(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 i=r.get(t);if(i===void 0)i=Ze(e),r.set(t,i);i.set(n,o)},cn=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=dn(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},ln=(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 It{#n=new WeakMap;#e;#o;#d;subscriberReading=!1;#r;#s=1;sourceEpoch=0;#l=!1;#a;#i;#c;#u=0;#p;#S;#f;#A=1;#b=0;#m;#y;#t;#h;#R;evaluate;constructor(e,t,n){this.#t=e,this.#h=t===void 0?void 0:Vt.get(t),this.#R=n,this.evaluate=n?.evaluate??kt,this.#r=new xe(this),this.recordCounter(7)}get runtimeDomain(){return this.#t}get postSourceApply(){return this.#l}get instrumented(){return this.#h!==void 0}get rootScope(){return this.#r}recordCounter(e,t=1){let n=this.#h;if(n===void 0)return;n(e,t)}createDraft(){return this.recordCounter(14),new Ye(this.instrumented?()=>this.recordCounter(18):void 0)}get(e,t){let n=new A,o=t,r=M(this.#t,o,n),i=Te(this.#t,"StoreTree.get");if(this.#v(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");let s=(i===void 0&&!this.#e?e.getMaterializedServedOutcome(o):void 0)??this.#B(e,o,n,i);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i?.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}#B(e,t,n,o){let r=o===void 0&&!this.#e?.current(e,t)&&this.#C(1),i;this.subscriberReading=o!==void 0;try{i=this.subscriberReading||!this.#e?e.serveKnownLocal(t,n):this.#e.observe(e,t,n)}catch(s){let a=n.getControlFault();if(a.kind==="fault")o?.latchControlFault(a.error);if(r)this.#e?.failure(s);throw s}finally{if(this.subscriberReading=!1,r)this.#o=void 0,this.#e?.finish()}return(r?this.#e?.installed(e,t):void 0)??i}#C(e){if(this.#o||this.#e?.idle===!1)return!1;return this.#o=e,this.#d=this.sourceEpoch,this.external,!0}#k(e){if(this.#o)this.#o=e+1<<2|this.#o&3;this.#e?.phase(e)}get external(){let e=this.#e;if(e?.idle&&this.#o)e.beginHost(this.#o,this.#d,this.#S),this.#S=void 0;return e}reachExternal(){return this.#e??=this.#t.externalRuntime.createTree(this),this.external}hasSubscription(e,t){return this.#f?.get(e)?.has(t)===!0}sub(e,t,n){let o=t,r,i=this.#t.states.has(o)?"local":M(this.#t,o,r=new A);if(this.#v(e,"StoreTree.sub"),i==="invalid"||!this.#t.atoms.has(o)&&!this.#t.selectors.has(o)&&!this.#t.externalAtoms?.has(o)&&!pe(this.#t,o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o),a=(s===void 0||this.#e)&&this.#C(2);try{let d=!this.#e?s??e.serveKnownLocal(o,r??new A):this.#e.observe(e,o,r??new A);if(d.outcome.kind==="control-error")throw d.outcome.error;let c=this.#f;if(c===void 0){if(c=new Map,this.#f=c,this.instrumented)this.recordCounter(20)}let l=c.get(e);if(l===void 0){if(l=new Map,c.set(e,l),this.instrumented)this.recordCounter(20),this.recordCounter(25)}let h=l.get(o);if(h===void 0){if(h={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},l.set(o,h),this.instrumented)this.recordCounter(21),this.recordCounter(26)}let u={callback:n,target:h,previous:h.tail,next:void 0};if(h.tail===void 0)h.head=u;else h.tail.next=u;if(h.tail=u,this.instrumented)this.recordCounter(22),this.recordCounter(27),this.recordCounter(24);return this.#e?.admit(u,d.token),nn(u)}catch(d){if(a)this.#e?.failure(d);throw d}finally{if(a)this.#o=void 0,this.#e?.finish()}}removeSubscription(e){let t=e.target;if(t===void 0)return;if(ft(this.#t),this.#e?.idle)return this.#e.cleanup(()=>this.removeSubscription(e));let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter(23),this.recordCounter(27,-1);if(t.head!==void 0)return;let i=this.#f,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter(26,-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter(25,-1)}if(i?.size===0)this.#f=void 0;this.#e?.releaseRoot(t.scope,t.state)}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)M(this.#t,n,new A);if(this.#v(e,"StoreTree.scope"),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(9),o.facade;return this.recordCounter(10),this.#D(e,n)}dispose(e){if(B(this.#t,"StoreTree.dispose"),e.status!=="live")return;if(this.#e?.idle)return this.#e.cleanup(()=>this.dispose(e));let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter(5);let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#G(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#r))this.#n=new WeakMap,this.#e=void 0}txn(e,t,n){if(this.#v(e,"StoreTree.txn"),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#C(3);try{let r=this.createDraft();try{let i=Xe(this,r,e),s=ct(this.#t,r.transaction,()=>t(i));r.close();let a=new A;return Oe(this.#t,a,()=>Qe(s)),this.#P(r),s}finally{r.close(),r.release()}}catch(r){if(o)this.#e?.failure(r);throw r}finally{if(o)this.#o=void 0,this.#e?.finish()}}get fallbackRecords(){return this.#n}transactionGet(e,t,n){let o=n,r=new A,i=M(this.#t,o,r);if(Ee(this.#t,e.transaction,e.active),this.#v(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#t.atoms.has(o)){let a=this.readDraftAtomOutcome(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#t.selectors.has(o)&&!this.#t.externalAtoms?.has(o)){let a=pe(this.#t,o);if(!a)throw TypeError("Transaction.get requires a readable State");return jt(a,e,t,o)}let s=e.getScratchHost(t);if(s===void 0){if(s=this.createScratchSelectorHost(e,t),e.installScratchHost(t,s))this.recordCounter(15)}return s.readSelector(o)}mutate(e,t,n,o,r){let i=o,s=new A,a=`${e===void 0?"StoreTree":"Transaction"}.${n}`,d=M(this.#t,i,s);if(e===void 0)B(this.#t,a);else Ee(this.#t,e.transaction,e.active);this.#v(t);let c=d==="local"&&this.#t.atoms.has(i),l;if(c?n==="delete":d!=="local"||typeof i==="function"||(l=pe(this.#t,i))===void 0)throw TypeError(`${a} requires a valid State`);let u=e===void 0&&this.#C(3);try{let m=e===void 0,f=e??this.createDraft();try{if(l!==void 0)l.stage(f,t,n,i,r,s);else if(n==="set")this.#W(f,t,i,r,s);else if(n==="update")this.#q(f,t,i,r,s,a);else this.#K(f,t,i,s);if(!m)return;f.close(),this.#P(f)}finally{if(m)f.close(),f.release()}}catch(m){if(u)this.#e?.failure(m);throw m}finally{if(u)this.#o=void 0,this.#e?.finish()}}transactionScope(e,t,n,o,r){let i=new A;if(typeof n!=="string")M(this.#t,n,i);Ee(this.#t,e.transaction,e.active),this.#v(t);let s=this.#H(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Xe(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let d;try{d=r(a)}catch(l){let h=new A;return Oe(this.#t,h,()=>Et(l))}let c=new A;return Oe(this.#t,c,()=>Qe(d)),d}createOutcomeToken(){return Object.freeze({id:this.#s++})}createScratchSelectorHost(e,t,n=!1){return this.recordCounter(3),new Ue(Object.freeze({trackPath:n,resolve:(o,r)=>this.#L(o,r),read:(o,r,i,s)=>this.#U(e,t,o,r,i,s),baseline:n?()=>{return}:(o)=>t.captureCommittedSelectorSuccess(o),run:(o,r)=>Ce(this.#t,o,r)}),e.generation,this.evaluate)}#L(e,t){if(Z(this.#t,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#t.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#t.selectors.get(e);if(n!==void 0)return Object.freeze({kind:"selector",definition:n});if(pe(this.#t,e))return Object.freeze({kind:"collection"});if(this.#t.externalAtoms?.has(e))return Object.freeze({kind:"external"});throw TypeError("Unknown scratch StoreTree State")}#D(e,t){let n=new xe(this,e,t);this.recordCounter(7);let o=new Je(this,n,this.#R);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#H(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new We;return this.#v(i),i}let n=t,o=this.#t.stores.get(n);if(o!==void 0){let i=o;if(this.#v(i),!Object.is(i.coordinator,this))throw new qe;return i}let r=this.#t.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new we;throw new Re}throw new Re}#v(e,t){if(t!==void 0)B(this.#t,t);if(e.status!=="live")throw new ce}#G(e){let t=this.#f,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0,this.#e?.releaseRoot(e,r.state)}if(t.delete(e),t.size===0)this.#f=void 0;if(this.instrumented)this.recordCounter(23,o),this.recordCounter(27,-o),this.recordCounter(26,-n.size),this.recordCounter(25,-1)}#W(e,t,n,o,r){let i=W(this.#t,r,()=>le(o));if(i.kind==="error")throw i.error;let s=this.#O(e,t,n,r);this.#_(e,t,n,i.value,s,r)}#q(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#O(e,t,n,r),a=e.hasIntents?this.readDraftAtomOutcome(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let d=this.#Q(o,a.value,r);this.#_(e,t,n,d,s,r)}#K(e,t,n,o){this.#O(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#T(e,n,o),reachesFallback:!0}):this.#x(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#O(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=D(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,c=Object.freeze({owned:i,outcome:a??this.#T(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}readDraftAtomOutcome(e,t,n,o){return this.#x(e,t,n,o).outcome}#U(e,t,n,o,r,i){if(o==="atom")return this.readDraftAtomOutcome(e,t,n,r);if(o==="external")return this.#t.externalRuntime.read(e,n,r,i,this.#h);return this.#t[V].read(e,t,n)}#x(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:D(i.value),reachesFallback:!1});if(i===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.#T(e,n,o),reachesFallback:!0})}#T(e,t,n){let o=this.#n.get(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return D(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=Nt(W(this.#t,n,()=>Ke(i)));return e.setFallback(t,a),a}#Y(e,t,n,o){let r=this.#w(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#X(r,t,n,o)?t:n}#X(e,t,n,o){return W(this.#t,o,()=>{let r;try{r=e(t,n)}catch(s){let a=j(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw I(a),new de}let i=j(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw I(i),new de;if(r!==!0&&r!==!1)throw new de;return r})}#Q(e,t,n){return W(this.#t,n,()=>{let o;try{o=e(t)}catch(i){let s=j(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw I(s),new ae}let r=le(o);if(r.kind==="error")throw r.error;return r.value})}#P(e){this.#k(2);let t;if(e.hasRows){if(t=this.#t[V]?.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=an(this.instrumented?()=>this.recordCounter(19):void 0),i,s;if(n!==void 0&&o!==void 0)i=this.#V(e,o,n,r);else e.forEachIntent((d,c)=>{let l=this.#V(e,d,c,r);if(i===void 0){i=l;return}if(s===void 0)s=[];s.push(l)});if(this.#k(6),this.#R?.(1,e,this.#t.atoms),this.#k(3),i!==void 0)this.#j(e,i);if(s!==void 0)for(let d of s)this.#j(e,d);let a=i===void 0?!1:this.#I(i);if(s!==void 0)for(let d of s){let c=this.#I(d);a||=c}if(t!==void 0){let d=t.commit(0);a||=d}if(i!==void 0)this.#M(i);if(s!==void 0)for(let d of s)this.#M(d);if(t!==void 0)t.commit(1);this.beginNotificationSettlement();try{let d,c,l=r.affectedRecord,h=r.affectedBefore;if(l!==void 0&&h!==void 0)d=this.#E(r,l,h);let{secondAffectedRecord:u,secondAffectedBefore:m}=r;if(u!==void 0&&m!==void 0){let f=this.#E(r,u,m);if(f!==void 0)if(d===void 0)d=f;else c=[f]}if(r.affected!==void 0)for(let[f,S]of r.affected){let y=this.#E(r,f,S);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 f=t.commit(2);if(f!==void 0)for(let S of f){let y=S;if(d===void 0)d=y;else{if(c===void 0)c=[];c.push(y)}}}if(a)this.sourceEpoch+=1,this.recordCounter(0);this.#k(6);try{this.#R?.(2,d===void 0?0:1+(c?.length??0))}catch(f){if(!this.#e)throw f;this.#e.failure(f,"instrumenting")}this.propagateFromSources(d,c)}catch(d){throw this.clearNotificationSettlement(),d}}#V(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 i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#$(e,s,o);return i}#j(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#n.has(t.intent.atom))this.#n.set(t.intent.atom,n),this.recordCounter(13)}#I(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return this.#t[_]?.apply(n,t),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.#ee(e.parent,t.atom))}#E(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(16),Le(n,o))return;return t.scope.updateAtomView(t,o),t}#$(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!cn(n,r))continue;let i=r.served.outcome,s=this.#F(e,r.scope,r.atom,n);if(Le(i,s))continue;ln(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter(1),o.push(d)});for(let d=a,c=o.length-1;d<c;d++,c--){let l=o[d];o[d]=o[c],o[c]=l}}}#F(e,t,n,o){let r=$e(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=$e(o,n,i);if(c!==void 0){d=c;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){d=D(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=D(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#Z(e,n),s!==void 0)Dt(o,n,s,d),this.recordCounter(17);if(a!==void 0)for(let c of a)Dt(o,n,c,d),this.recordCounter(17);return d}#Z(e,t){let n=this.#n.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#w(t);if(r.fallback.kind==="eager")return D(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#J(e){let t=this.#n.get(e);if(t!==void 0)return t;let n=this.#w(e);if(n.fallback.kind==="eager")return D(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#ee(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,D(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#J(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,D(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#te(t,n));break}this.recordCounter(6),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#te(e,t){let n=this.#n.get(e);if(n!==void 0)return n;let o=this.#w(e);if(o.fallback.kind==="eager")return D(o.fallback.value);let r=o.fallback.initialize,i=Nt(W(this.#t,t,()=>Ke(r)));return this.#n.set(e,i),this.recordCounter(13),i}#w(e){let t=this.#t.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}propagateFromSources(e,t,n){if(e===void 0&&n===void 0){this.clearNotificationSettlement();return}if(e!==void 0)this.recordCounter(4);let o=this.#e?.beginPropagation();this.#k(4),this.#a=[],this.#l=!0;try{try{if(n?.(),e?.scope.markDependents(e.atom),t!==void 0)for(let d of t)d.scope.markDependents(d.atom);let a=0;while(a<this.#a.length||this.#e?.pendingLifecycle){if(a>=this.#a.length){this.#i=void 0,this.#c=void 0,this.#u=0,this.#p=void 0,this.#e.settleLifecycle();continue}let d=this.#a[a++],c=this.#a[a++];try{this.#N(d,c)}catch(l){if(n===void 0)throw l;this.#e.failure(l,"settling")}}}finally{this.#l=!1,this.#a=void 0,this.#i=void 0,this.#c=void 0,this.#u=0,this.#p=void 0,this.#e?.endPropagation(o)}let r=this.#ne(),i=this.#S?.[0]?.error;if(r===void 0){if(i!==void 0)throw i;return}let s=new Ge(i===void 0?r:[i,...r]);throw this.#e?.notificationFailure(s)??s}finally{this.#S=void 0}}beginNotificationSettlement(){this.#m=void 0,this.#y=void 0,this.#b=this.#f===void 0?0:this.#A++}clearNotificationSettlement(){this.#b=0,this.#m=void 0,this.#y=void 0}reachSubscriptionTarget(e,t){let n=this.#b,o=this.#f?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter(28);if(this.#m===void 0){this.#m=o;return}if(this.#y===void 0)this.#y=[o];else this.#y.push(o)}#ne(){let e=this.#m;if(e===void 0){this.clearNotificationSettlement();return}let t,n,o=(d)=>{let c=d.head;while(c!==void 0){let l=!this.#e?c.callback:this.#e.notificationCallback(c);if(l!==void 0)if(t===void 0)t=l;else if(n===void 0)n=[t,l];else n.push(l);c=c.next}};o(e);let r=this.#y;if(r!==void 0)for(let d of r)o(d);if(this.clearNotificationSettlement(),t===void 0)return;this.#k(7);let i=Object.freeze(n??[t]),s=this.instrumented;if(s)this.recordCounter(29);let a;for(let d of i){if(s)this.recordCounter(30);let c=new A;try{dt(this.#t,c,()=>{let l;try{if(l=j(d()),l.kind==="thenable")I(l)}catch(h){let u=j(h);if(u.kind==="thenable")I(u);throw h}if(l.kind==="inspection-error")throw l.error})}catch(l){if((a??=[]).push(l),s)this.recordCounter(31)}}return a}enqueueSelector(e,t){let n=this.#a;if(n===void 0)return!1;let o=this.#z(e,t);if((o&4)!==0)this.#g(e,t,0,5),o&=-6;if((o&1)!==0)return!0;return this.#g(e,t,1),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#a===void 0)return;if(this.#e?.skipSelectorRead(e,t,n))return;this.#N(e,t,n)}#N(e,t,n){let o=this.#z(e,t);if((o&6)!==0)return;this.#g(e,t,8);try{let r=e.getSelectorGraphVersion(),i=(o&8)!==0?void 0:e.getCommittedSelectorDependencies(t);if(i!==void 0){for(let s of i)if(this.#t.selectors.has(s.node))this.#N(e,s.node)}if(e.isSelectorDirty(t)){this.#g(e,t,2);let s=r===e.getSelectorGraphVersion();if(n!==void 0&&s)e.serve(t,n);else e.serve(t,new A)}this.#g(e,t,4)}catch(r){if(this.#e?.recordSelectorFault(e,t,r))this.#g(e,t,4);throw r}finally{this.#g(e,t,0,10&~o)}}#z(e,t){if(Object.is(this.#i,e)&&Object.is(this.#c,t))return this.#u;return this.#p?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#i===void 0){this.#i=e,this.#c=t,this.#u=n&~o;return}if(Object.is(this.#i,e)&&Object.is(this.#c,t)){this.#u=(this.#u|n)&~o;return}let r=this.#p;if(r===void 0)r=new Map,this.#p=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){if(this.#e?.idle===!1)this.#e.failure(e.error,"settling",e.origin);else(this.#S??=[]).push(e)}#_(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#Y(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}var un=(e,t)=>{let n=e.coordinator,o=new A,r=t,i=M(n.runtimeDomain,r,o);if(B(n.runtimeDomain,"adapter readHydrationSnapshot"),e.status!=="live")throw new ce;let s,a;if(i!=="invalid")if(n.runtimeDomain.atoms.has(r))s=0;else if(n.runtimeDomain.selectors.has(r)||n.runtimeDomain.externalAtoms?.has(r))s=1;else a=pe(n.runtimeDomain,r);if(s===void 0&&!a)throw TypeError("readHydrationSnapshot requires a valid State");let d=n.createDraft(),c;try{if(s===0){let l=n.readDraftAtomOutcome(d,e,r,o);if(l.kind!=="value")throw l.error;return l.value}if(s===void 0)return jt(a,d,e,r);return c=n.createScratchSelectorHost(d,e,!0),c.readSelector(r)}finally{c?.revoke(),d.close(),d.forEachFallback((l,h)=>{if(n.fallbackRecords.has(l))return;n.fallbackRecords.set(l,h),n.recordCounter(13)}),d.release()}};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),fe(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter(8),n?.(0,this,t),Object.freeze(this)}}var Mt=(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=()=>{let e={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0};return Object.freeze({[k]:e})},Gn=(e,t,n={})=>{let o=e[k];ee(o);let r=new A,i=W(o,r,()=>le(t));if(i.kind==="error")throw i.error;let s=he(o,Ne("atom"));return o.atoms.set(s,Object.freeze({fallback:Object.freeze({kind:"eager",value:i.value}),...Mt(n)})),s},Wn=(e,t,n={})=>{let o=e[k];if(ee(o),typeof t!=="function")throw TypeError("atomLazy requires an initializer function");let r=he(o,Ne("atom"));return o.atoms.set(r,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:t}),...Mt(n)})),r},qn=(e,t,n={})=>{let o=e[k];if(ee(o),typeof t!=="function")throw TypeError("selector requires a getter function");if(n.equal!==void 0&&typeof n.equal!=="function")throw TypeError("selector equal must be a function");let r=he(o,Ne("selector")),i=Object.freeze({node:r,get:t,...n.name===void 0?{}:{name:n.name},...n.equal===void 0?{}:{equal:n.equal}});return o.selectors.set(r,i),r},Kn=(e)=>{let t=e[k],n=(i)=>{let s=new A;if(M(t,i,s)==="invalid")return;return t.stores.get(i)};return Object.freeze({assertStore:(i)=>{let s=n(i);if(B(t,"adapter assertStore"),s===void 0)throw TypeError("assertStore requires a valid Store");if(s.status!=="live")throw new ce},read:(i,s)=>{if(n(i)===void 0)throw Te(t,"adapter read"),TypeError("read requires a valid Store");return i.get(s)},subscribe:(i,s,a)=>{if(n(i)===void 0)throw B(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return i.sub(s,a)},readHydrationSnapshot:(i,s)=>{let a=n(i);if(a===void 0)throw B(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return un(a,s)}})},zt=(e,t,n)=>{let o=e[k];B(o,"createStoreTree");let r=new It(o,t,n);return new Je(r,r.rootScope,n)};var fn=Ft(),Xn=(e,t)=>zt(fn,e,t);
2
+ export{ie as S,Zt as T,kt as U,A as V,V as W,Le as X,pn as Y,He as Z,Ge as _,J as $,ge as aa,ke as ba,we as ca,se as da,ae as ea,de as fa,ce as ga,We as ha,qe as ia,Re as ja,j as ka,I as la,ue as ma,W as na,lt as oa,ut as pa,ee as qa,Ne as ra,he as sa,Ot as ta,xn as ua,Pn as va,Vn as wa,jn as xa,In as ya,rn as za,Mn as Aa,Fn as Ba,zn as Ca,_n as Da,Bn as Ea,Ln as Fa,Hn as Ga,Gn as Ha,Wn as Ia,qn as Ja,Kn as Ka,zt as La,fn as Ma,Xn as Na};
@@ -0,0 +1,2 @@
1
+ var E=35,O=36,I=37,_=38,C=39,T=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,D=70,M=71,P=72,B=73,U=74,W=75,H=76,V=49,X=50,F=51,G=52,K=53,Z=54,Y=55,a=56,b=57;
2
+ export{E as i,O as j,I as k,_ as l,C as m,T as n,L as o,N as p,o as q,t as r,R as s,S as t,c as u,e as v,n as w,p as x,r as y,s as z,x as A,A as B,D as C,M as D,P as E,B as F,U as G,W as H,H as I,V as J,X as K,F as L,G as M,K as N,Z as O,Y as P,a as Q,b as R};
@@ -0,0 +1 @@
1
+ import{Ka as e,Ma as r}from"../chunk-rr3063rn.js";var t=e(r),s=t.assertStore,i=t.read,n=t.subscribe,m=t.readHydrationSnapshot;export{s as assertStore,i as read,m as readHydrationSnapshot,n as subscribe};
@@ -0,0 +1,2 @@
1
+ import{A as Rn,B as kn,C as gn,D as Sn,E as vn,F as Mn,G as On,H as En,I as Tn,P as Dn,i as sn,j as cn,k as dn,l as Pe,m as an,n as ae,o as W,p as pe,q as fn,r as un,s as pn,t as hn,u as mn,v as je,w as bn,x as wn,y as yn,z as Cn}from"./chunk-tywyt3b6.js";import{Aa as Vn,Ca as Ve,Da as ze,Ja as Bn,ka as fe,la as be,na as jn,ta as de,ua as ge,wa as Hn,ya as _e,za as Ae}from"./chunk-rr3063rn.js";class Ie{entries=new Map;tail;nextRank=0;constructor(i){for(let c of i)this.append(c)}append(i){let c=this.tail;if(this.entries.set(i,{rank:this.nextRank++,previous:c}),c!==void 0)this.entries.get(c).next=i;this.tail=i}remove(i){let c=this.entries.get(i);if(c===void 0)return;if(c.previous!==void 0)this.entries.get(c.previous).next=c.next;if(c.next!==void 0)this.entries.get(c.next).previous=c.previous;else this.tail=c.previous;this.entries.delete(i)}changes(i,c){if(i.length!==c.length)return!0;let a=new Set(i),f=this.tail;for(let m=c.length-1;m>=0;m--){if(c[m]!==f||!a.has(c[m]))return!0;f=this.entries.get(f)?.previous}return!1}}var X=Symbol("collection baseline birth");class Re extends Error{seal(){Object.freeze(this)}}class Nn extends Re{code="VALDRES_INVALID_SYNCHRONOUS_COLLECTION_VALUE";constructor(){super("Collection row values must be synchronous");this.name="InvalidSynchronousCollectionValueError",this.seal()}}class xn extends Re{code="VALDRES_UNDEFINED_COLLECTION_VALUE";constructor(){super("Collection row values cannot be undefined");this.name="UndefinedCollectionValueError",this.seal()}}class In extends Re{code="VALDRES_MISSING_COLLECTION_ROW";constructor(){super("Cannot update an absent collection row");this.name="MissingCollectionRowError",this.seal()}}var he=Object.freeze({kind:"none"}),Ce=Object.freeze({kind:"absent"}),q=Object.freeze({kind:"absent"}),G=Object.freeze([]),me=(i)=>Object.freeze({kind:"present",value:i}),J=(i)=>Object.freeze({kind:"present",value:i}),ye=(i,c)=>i.kind===c.kind&&(i.kind==="absent"||c.kind==="present"&&Object.is(i.value,c.value)),tn=(i,c)=>i.kind===c.kind&&(i.kind!=="present"||c.kind==="present"&&Object.is(i.value,c.value)),le=(i)=>{let c=i.local.kind==="present"?me(i.local.value):i.local.kind==="absent"?Ce:he,a=i.effective.kind==="present"?J(i.effective.value):q,f=i.inherited.kind==="present"?J(i.inherited.value):q;if(c.kind==="none"&&!ye(a,f))throw Error("Collection baseline without local ownership must equal inherited outcome");if(c.kind==="present"&&(a.kind!=="present"||!Object.is(c.value,a.value)))throw Error("Collection present local baseline must equal its effective outcome");if(c.kind==="absent"&&a.kind!=="absent")throw Error("Collection absent local baseline must be effectively absent");return Object.freeze({local:c,effective:a,inherited:f})},Le=(i)=>{let c=i.final;if(c===void 0)return i.baseline.local;if(c.kind==="present")return me(c.value);return c.kind==="absent"?Ce:he},rn=(i,c)=>i.kind==="present"?J(i.value):i.kind==="absent"?q:c,ln=(i)=>Object.freeze({kind:"value",value:i.kind==="present"?i.value:void 0}),Ln=(i,c)=>{let a,f=new WeakMap,m=new WeakMap,N,B,H=(t)=>t.coordinator?.evaluate?.recordExtension,g=(t,e,o=1)=>{H(t)?.(e,o)},z=(t,e,o,r)=>{H(t)?.(e,t,o,r)},V=(t,e,o)=>{if(e.length!==o.length)return!1;let r=H(t);if(r===void 0){for(let n=0;n<e.length;n++)if(!Object.is(e[n],o[n]))return!1;return!0}for(let n=0;n<e.length;n++)if(!Object.is(e[n],o[n]))return r(W,n+1),!1;if(e.length)r(W,e.length);return!0},ue=(t)=>{let e=m.get(t);if(e!==void 0)return e;return e={rowLocals:void 0,ownedRows:void 0,rowViews:void 0,liveRowViews:void 0,memberships:void 0,liveMemberships:void 0},m.set(t,e),e},I=(t,e)=>m.get(t)?.rowLocals?.get(e)??he,L=(t,e)=>{let o=t;while(o!==void 0){let r=I(o,e);if(r.kind==="present")return J(r.value);if(r.kind==="absent")return q;o=o.parent}return q},Q=c??((t,e)=>{let o=I(t,e),r=L(t.parent,e);return Object.freeze({local:o,effective:rn(o,r),inherited:r})}),An=(t,e,o,r)=>{let n=t.byScope.get(e)?.get(o);if(n!==void 0)return Le(n);return le(Q(e,o,r)).local},U=(t,e,o,r)=>{let n=e;while(n!==void 0){let l=An(t,n,o,r);if(l.kind==="present")return J(l.value);if(l.kind==="absent")return q;if(c!==void 0){let d=t.byScope.get(n)?.get(o);if(d!==void 0)return d.baseline.inherited;return le(Q(n,o,r)).inherited}n=n.parent}return q},zn=(t,e,o,r)=>{if(c!==void 0){let D=le(Q(e,o,r)),T=D.effective.kind==="present",E=T?X:void 0;for(let j of t.byRow.get(o)?.historyByScope.get(e)??[]){if(!Object.is(j.row,o)||!Object.is(j.scope,e))continue;let _=j.kind==="present"||j.kind==="reset"&&D.inherited.kind==="present";if(!T&&_)E=j.sequence;else if(!_)E=void 0;T=_}return E}let n=[],l=new Map,d=e;while(d!==void 0)n.push(d),l.set(d,le(Q(d,o,r)).local.kind),d=d.parent;let u=[],v=t.byRow.get(o);if(v!==void 0){for(let D of n){let T=v.historyByScope.get(D);if(T!==void 0)u.push(...T)}u.sort((D,T)=>D.sequence-T.sequence)}let P=()=>{for(let D of n){let T=l.get(D);if(T==="present")return!0;if(T==="absent")return!1}return!1},O=P(),x=O?X:void 0;for(let D of u){l.set(D.scope,D.kind==="present"?"present":D.kind==="absent"?"absent":"none");let T=P();if(!O&&T)x=D.sequence;else if(!T)x=void 0;O=T}return x},Se=(t,e,o,r)=>{let n=ue(t),l=n.rowViews?.get(e);if(l!==void 0)return l;let d={scope:t,atom:e,served:Object.freeze({token:t.createOutcomeToken(),outcome:ln(o)}),inheritedFrom:r,inheritingChildren:new de(()=>t.coordinator.recordCounter(2))},u=n.rowViews;if(u===void 0)u=new WeakMap,n.rowViews=u;let v=n.liveRowViews;if(v===void 0)v=new de(()=>t.coordinator.recordCounter(2)),n.liveRowViews=v;if(u.set(e,d),v.add(d),z(t,En,e,i.lookupRow(e)),r!==void 0)r.inheritingChildren.add(d),t.coordinator.recordCounter(11);return d},We=(t,e)=>{let o=t,r=[],n;while(!0){g(o,Pe);let l=m.get(o),d=l?.rowViews?.get(e);if(d!==void 0){n=d;break}let u=l?.rowLocals?.get(e);if(u!==void 0){n=Se(o,e,u.kind==="present"?J(u.value):q);break}if(o.parent===void 0){n=Se(o,e,q);break}r.push(o),o=o.parent}for(let l=r.length-1;l>=0;l--)n=Se(r[l],e,n.served.outcome.kind==="value"&&n.served.outcome.value!==void 0?J(n.served.outcome.value):q,n);return n},ve=(t)=>{let e=t.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(t),t.inheritedFrom=void 0,t.scope.coordinator.recordCounter(12)},Kn=(t,e)=>{if(Object.is(t.inheritedFrom,e))return;ve(t),t.inheritedFrom=e,e.inheritingChildren.add(t),t.scope.coordinator.recordCounter(11)},te=(t)=>{if(t.snapshotDirty){let e=Object.freeze([...t.ordered.entries.keys()]);g(t.scope,W,e.length),g(t.scope,pe),t.served=se(t.scope,e,t.served.token),t.snapshotDirty=!1}return t.served.outcome.kind==="value"?t.served.outcome.value:G},Wn=(t,e)=>{let o=Ee(t,e),r=o;while(r!==void 0&&r.ordered===void 0){r.ordered=new Ie(te(r));let n=r.inheritedFrom;if(n!==void 0)(n.indexedChildren??=new de).add(r);r=n}return o.ordered},Me=(t,e)=>{if(e.length)g(t,W,e.length);let o=Object.freeze([...e]);return g(t,pe),o},se=(t,e,o=t.createOutcomeToken())=>Object.freeze({token:o,outcome:Object.freeze({kind:"value",value:e})}),Oe=(t,e,o,r=!1)=>{let n=ue(t),l=n.memberships?.get(e);if(l!==void 0)return l;let d={scope:t,atom:e,served:se(t,o,r?G:void 0),inheritedFrom:void 0,inheritingChildren:new de(()=>t.coordinator.recordCounter(2))},u=n.memberships;if(u===void 0)u=new WeakMap,n.memberships=u;let v=n.liveMemberships;if(v===void 0)v=new de(()=>t.coordinator.recordCounter(2)),n.liveMemberships=v;return u.set(e,d),v.add(d),g(t,an),z(t,Tn,e),d},Fe=(t)=>{let e=t.inheritedFrom;if(e===void 0)return;e.inheritingChildren.delete(t),e.indexedChildren?.delete(t),t.inheritedFrom=void 0,t.scope.coordinator.recordCounter(12)},qe=(t,e)=>{if(Object.is(t.inheritedFrom,e))return;Fe(t),t.inheritedFrom=e,e.inheritingChildren.add(t),t.scope.coordinator.recordCounter(11)},Ee=(t,e)=>{let o=t,r=[],n;while(!0){g(o,ae);let l=m.get(o)?.memberships?.get(e);if(l!==void 0){if(n=l,n.served.token===G){let d=Me(o,te(n));n.served=se(o,d)}break}if(o.parent===void 0){n=Oe(o,e,Me(o,G));break}r.push(o),o=o.parent}for(let l=r.length-1;l>=0;l--){let d=r[l],u=Me(d,te(n)),v=Oe(d,e,u);qe(v,n),n=v}return n},Fn=(t)=>{let e=t;a?.release(e);let o=f.get(e);if(o===void 0)return;f.delete(e);for(let r of o.byScope.values()){for(let n of r.values())n.final=void 0,n.finalOperation=void 0;r.clear()}o.byScope.clear(),o.planOrder.length=0,o.history.length=0;for(let r of o.historyByCollectionScope.values()){for(let n of r.values())n.length=0;r.clear()}o.historyByCollectionScope.clear();for(let r of o.byRow.values()){for(let n of r.coordinatesByAncestor.values())n.length=0;r.coordinatesByAncestor.clear();for(let n of r.historyByScope.values())n.length=0;r.historyByScope.clear()}o.byRow.clear(),o.revisionByCollection.clear(),o.queryRevisionByCollection?.clear();for(let r of o.membershipMemo.values())r.clear();o.membershipMemo.clear()},ne=(t)=>{let e=f.get(t);if(e!==void 0)return e;return e={byScope:new Map,planOrder:[],history:[],historyByCollectionScope:new Map,byRow:new Map,revisionByCollection:new Map,membershipMemo:new Map,nextDiscoveryIndex:0,hasAcceptedIntent:!1},t.installRows(Fn),f.set(t,e),e},Te=(t)=>{let e=i.lookupRow(t);if(e===void 0)throw TypeError("Collection draft operation requires a valid row");return e},qn=(t,e)=>{t.revisionByCollection.set(e,(t.revisionByCollection.get(e)??0)+1)},re=(t,e,o,r=Te(o))=>{let n=ne(t),l=n.byScope.get(e);if(l===void 0)l=new Map,n.byScope.set(e,l);let d=l.get(o);if(d!==void 0)return d;if(B!==void 0)B.coordinates++;let u=le(Q(e,o,r)),v=c===void 0?U(n,e.parent,o,r):u.inherited,P=le({local:u.local,effective:rn(u.local,v),inherited:v});d={scope:e,row:o,collection:r,baseline:P,discoveryIndex:n.nextDiscoveryIndex++,planIndex:void 0,final:void 0,finalOperation:void 0,enablingBirth:void 0},l.set(o,d);let O=n.byRow.get(o);if(O===void 0)O={coordinatesByAncestor:new Map,historyByScope:new Map},n.byRow.set(o,O);let x=e;while(x!==void 0){let D=O.coordinatesByAncestor.get(x);if(D===void 0)D=[],O.coordinatesByAncestor.set(x,D);D.push(d),x=x.parent}return d.enablingBirth=zn(n,e,o,r),d},we=(t,e,o,r,n,l)=>{let d=Le(e),u=ne(t),v=U(u,e.scope,e.row,e.collection);if(tn(d,n)&&ye(v,l))return;if(!u.hasAcceptedIntent)u.hasAcceptedIntent=!0,g(e.scope,cn);g(e.scope,sn);let P=[];for(let F of u.byRow.get(e.row).coordinatesByAncestor.get(e.scope)??[]){let K=U(u,F.scope,F.row,F.collection);P.push({coordinate:F,effective:K,placement:K.kind==="present"?F.enablingBirth:void 0})}let O=t.generation;if(e.planIndex===void 0)e.planIndex=u.planOrder.length,u.planOrder.push(e);e.final=r,e.finalOperation=o;let x=Object.freeze({coordinateId:e.discoveryIndex,scope:e.scope,row:e.row,collection:e.collection,kind:r.kind,sequence:O});u.history.push(x);let D=u.byRow.get(e.row),T=D.historyByScope.get(e.scope);if(T===void 0)T=[],D.historyByScope.set(e.scope,T);T.push(x);let E=u.historyByCollectionScope.get(e.collection);if(E===void 0)E=new Map,u.historyByCollectionScope.set(e.collection,E);let j=E.get(e.scope);if(j===void 0)j=[],E.set(e.scope,j);j.push(x);let _=!1;for(let F of P){let K=F.coordinate,ce=U(u,K.scope,K.row,K.collection);if(F.effective.kind==="absent"&&ce.kind==="present")K.enablingBirth=O;else if(ce.kind==="absent")K.enablingBirth=void 0;let Ne=ce.kind==="present"?K.enablingBirth:void 0;if(!Object.is(F.placement,Ne))_=!0}if(_)qn(u,e.collection);let oe=u.queryRevisionByCollection?.get(e.collection);if(oe!==void 0)u.queryRevisionByCollection.set(e.collection,oe+1);t.markRow(O)},Ue=()=>new Nn,Ge=(t)=>{let e=i.inspectThenable(t);if(e.kind==="inspection-error")throw e.error;if(e.kind==="thenable")throw i.containThenable(e),Ue();if(t===void 0)throw new xn;return t},Un=(t,e,o)=>i.runGuarded(o,()=>{let r;try{r=Reflect.apply(t,void 0,[e])}catch(n){let l=i.inspectThenable(n);if(l.kind==="not-thenable")throw n;if(l.kind==="inspection-error")throw l.error;throw i.containThenable(l),Ue()}return Ge(r)}),Ye=(t,e,o,r,n)=>{let l=Te(o),d=i.runGuarded(n,()=>Ge(r)),u=re(t,e,o,l);we(t,u,"set",Object.freeze({kind:"present",value:d}),me(d),J(d))},Ze=(t,e,o,r,n)=>{let l=Te(o);if(typeof r!=="function")throw TypeError("Collection row update requires an updater");let d=re(t,e,o,l),u=U(ne(t),e,o,l);if(u.kind==="absent")throw new In;let v=Un(r,u.value,n);we(t,d,"update",Object.freeze({kind:"present",value:v}),me(v),J(v))},Xe=(t,e,o)=>{let r=re(t,e,o);we(t,r,"delete",Object.freeze({kind:"absent"}),Ce,q)},Je=(t,e,o)=>{let r=re(t,e,o),n=c===void 0?U(ne(t),e.parent,o,r.collection):r.baseline.inherited;we(t,r,"reset",Object.freeze({kind:"reset"}),he,n)},Qe=(t,e,o)=>{let r=re(t,e,o),n=U(ne(t),e,o,r.collection);return n.kind==="present"?n.value:void 0},De=(t,e,o)=>{if(!i.lookupCollection(o))throw TypeError("Collection draft read requires a valid collection");let r=ne(t),n=r.revisionByCollection.get(o)??0,l=r.membershipMemo.get(e),d=l?.get(o);if(d?.revision===n)return d.rows;let u=c===void 0&&typeof e.createOutcomeToken==="function"?te(Ee(e,o)):G,v=new Map,P=r.historyByCollectionScope.get(o),O=e;while(O!==void 0){for(let E of P?.get(O)??[])if(!v.has(E.row))v.set(E.row,re(t,e,E.row,o));O=O.parent}let x=[];if(u.length)g(e,W,u.length);for(let E of u){let j=v.get(E);if(j===void 0||j.enablingBirth===X)x.push(E)}let D=[];if(v.size!==0)g(e,W,v.size);for(let E of v.values())if(typeof E.enablingBirth==="number"&&U(r,E.scope,E.row,E.collection).kind==="present")D.push(E);D.sort((E,j)=>{let _=E.enablingBirth,oe=j.enablingBirth;if(_===oe)return E.discoveryIndex-j.discoveryIndex;return _-oe});for(let E of D)x.push(E.row);let T;if(V(e,u,x))T=u;else if(d!==void 0&&V(e,d.rows,x))T=d.rows;else T=Object.freeze(x),g(e,pe);if(l===void 0)l=new Map,r.membershipMemo.set(e,l);return l.set(o,Object.freeze({revision:n,rows:T})),T},Gn=(t)=>{let e=f.get(t);if(e===void 0)return;let o=0;for(let l of e.membershipMemo.values())o+=l.size;let r=new WeakMap;for(let[l,d]of e.revisionByCollection)r.set(l,Object.freeze({value:d}));let n=(l)=>Object.freeze({id:l.discoveryIndex,baselineLocal:l.baseline.local.kind,baselineEffective:l.baseline.effective.kind,baselineInherited:l.baseline.inherited.kind,final:l.final?.kind,enablingBirth:l.enablingBirth===X?"baseline":l.enablingBirth});return Object.freeze({discoveryOrder:Object.freeze([...e.byScope.values()].flatMap((l)=>[...l.values()]).sort((l,d)=>l.discoveryIndex-d.discoveryIndex).map(n)),planOrder:Object.freeze(e.planOrder.map(n)),history:Object.freeze(e.history.map((l)=>Object.freeze({coordinateId:l.coordinateId,kind:l.kind,sequence:l.sequence}))),membershipMemoCount:o,revision:(l)=>r.get(l)?.value??0})},Yn=(t)=>{let e=t;if(!e.hasRows)return;let o=f.get(e);if(o===void 0)throw Error("Collection row draft lane is missing");let r,n=[],l=[],d=[],u=[],v=new WeakSet,P=new WeakMap,O=new Map,x=[],D=new Map,T=Object.freeze([]),E={baselinePresent:!1,transitions:T,birth:void 0},j={baselinePresent:!0,transitions:T,birth:X},_=new Map,oe=new Map,F=(s)=>{let y=O.get(s.scope);if(y===void 0)y=new Map,O.set(s.scope,y);if(y.set(s.atom,s),s.existing!==void 0)P.set(s.existing,s)},K=(s)=>{let y=P.get(s);if(y!==void 0)return y;let b=[],M=s,w;while(M!==void 0){g(M.scope,ae);let h=P.get(M);if(h!==void 0){w=h;break}b.push(M),M=M.inheritedFrom}for(let h=b.length-1;h>=0;h--){let p=b[h],R={scope:p.scope,atom:p.atom,existing:p,parent:w,beforeRows:p.ordered===void 0?te(p):G,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};if(p.ordered!==void 0){let C;Object.defineProperty(R,"beforeRows",{get:()=>C??=te(p)})}F(R),w=R}return w},ce=(s,y)=>{let b=O.get(s)?.get(y);if(b!==void 0)return b;let M=[],w=s,h;while(w!==void 0){let p=O.get(w)?.get(y);if(p!==void 0){g(w,ae),h=p;break}let R=m.get(w)?.memberships?.get(y);if(R!==void 0){h=K(R);break}g(w,ae),M.push(w),w=w.parent}for(let p=M.length-1;p>=0;p--){let R={scope:M[p],atom:y,existing:void 0,parent:h,beforeRows:h?.beforeRows??G,plannedChildren:[],finalRows:void 0,membershipChangedFromBefore:void 0,installed:void 0,affected:!1,containsAffected:!1};h?.plannedChildren.push(R),d.push(R),F(R),h=R}return h},Ne=(s)=>{let y=D.get(s);if(y!==void 0)return y;return y={collection:s,top:void 0},D.set(s,y),x.push(y),y},eo=(s,y)=>{y.affected=!0;let b=s.top;if(b===void 0)s.top=y;let M,w=y;while(w!==void 0){if(w.containsAffected){if(M??=w,Object.is(w,b))return}else w.containsAffected=!0;w=w.parent}if(b!==void 0)s.top=M},no=(s,y)=>{if(s.existing?.ordered!==void 0)return s.existing.ordered.entries.has(y);let b=oe.get(s);if(b===void 0){if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);b=new Set(s.beforeRows),oe.set(s,b)}return b.has(y)},$e=(s,y,b,M)=>{if(B!==void 0)B.states++;let w=I(s.scope,y).kind;if(M===void 0)return w==="none"?b:w==="present"?j:E;let h=b.baselinePresent,p=w==="present"||w==="none"&&h,R=p,C=p?X:void 0,k=[],S=0,A=0;while(S<b.transitions.length||A<M.length){let ie=b.transitions[S],ee=M[A],Z;if(ie!==void 0&&(ee===void 0||ie.sequence<ee.sequence))h=ie.present,Z=ie.sequence,S++;else w=ee.kind==="present"?"present":ee.kind==="absent"?"absent":"none",Z=ee.sequence,A++;let on=w==="present"||w==="none"&&h;if(on===p)continue;p=on,C=p?Z:void 0,k.push({sequence:Z,present:p})}if(!k.length)return p?j:E;return{baselinePresent:R,transitions:k,birth:C}},xe=(s)=>{let y=_.get(s);if(y!==void 0)return y;let b=[],M=s;while(M!==void 0&&!_.has(M))b.push(M),M=M.parent;let w=M===void 0?new Map:_.get(M);for(let h=b.length-1;h>=0;h--){let p=b[h],R=new Map;for(let k of o.historyByCollectionScope.get(p.atom)?.get(p.scope)??[]){let S=R.get(k.row);if(S===void 0)S=[],R.set(k.row,S);S.push(k)}let C=new Map;if(w.size!==0)g(p.scope,W,w.size);for(let[k,S]of w)C.set(k,$e(p,k,S,R.get(k))),R.delete(k);for(let[k,S]of R){let A=p.parent!==void 0&&no(p.parent,k)?j:E;C.set(k,$e(p,k,A,S))}_.set(p,C),w=C}return _.get(s)},en=(s)=>{if(s.finalRows!==void 0)return s.finalRows;if(s.existing?.ordered!==void 0){let p=xe(s),R=[],C=[];for(let[S,A]of p){if(A.baselinePresent&&A.birth!==X)R.push(S);if(typeof A.birth==="number")C.push({row:S,birth:A.birth})}C.sort((S,A)=>S.birth-A.birth);let k=C.map((S)=>S.row);return s.membershipChangedFromBefore=s.existing.ordered.changes(R,k),s.orderedPatch={removals:R,births:k},(r??=[]).push(s),s.membershipChanges=p,G}if(s.existing!==void 0)N?.push(s.existing);let y=[],b=[],M=s.existing!==void 0&&H(s.scope)!==void 0,w;if(c===void 0){let p=xe(s);if(M)w=p;if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);for(let R of s.beforeRows){let C=p.get(R);if(C===void 0||C.birth===X)y.push(R)}if(p.size!==0)g(s.scope,W,p.size);for(let[R,C]of p){if(w!==void 0&&(C.baselinePresent&&C.birth===void 0||!C.baselinePresent&&typeof C.birth==="number"))s.membershipChanges=w;if(typeof C.birth==="number")b.push({row:R,birth:C.birth})}}else{let p=new Map,R=o.historyByCollectionScope.get(s.atom),C=s.scope;while(C!==void 0){for(let k of R?.get(C)??[])if(!p.has(k.row))p.set(k.row,re(e,s.scope,k.row,s.atom));C=C.parent}if(s.beforeRows.length)g(s.scope,W,s.beforeRows.length);for(let k of s.beforeRows){let S=p.get(k);if(S===void 0||S.enablingBirth===X)y.push(k)}if(p.size!==0)g(s.scope,W,p.size);for(let k of p.values())if(typeof k.enablingBirth==="number"&&U(o,k.scope,k.row,k.collection).kind==="present")b.push({row:k.row,birth:k.enablingBirth})}b.sort((p,R)=>p.birth-R.birth);for(let p of b)y.push(p.row);let h=!V(s.scope,s.beforeRows,y);if(s.membershipChangedFromBefore=h,s.existing!==void 0&&!h)s.finalRows=s.beforeRows;else s.finalRows=Object.freeze(y),g(s.scope,pe);return s.finalRows};for(let s of o.planOrder){let y=s.final;if(y===void 0)continue;g(s.scope,dn);let b=y.kind==="present"?me(y.value):y.kind==="absent"&&s.scope.parent!==void 0?Ce:he,M=!tn(I(s.scope,s.row),b);n.push(Object.freeze({coordinate:s,local:b,ownershipChanged:M}));let w=Ne(s.collection),h=le(Q(s.scope,s.row,s.collection));if(h.local.kind!==b.kind)ce(s.scope,s.collection);let R=h.effective.kind==="present"?X:void 0;if(!Object.is(R,s.enablingBirth))eo(w,ce(s.scope,s.collection));let C=m.get(s.scope)?.rowViews?.get(s.row);if(C===void 0)continue;let k=[C];while(k.length){let S=k.pop();if(v.has(S))continue;v.add(S),g(S.scope,Pe);let A=S.served.outcome.kind==="value"&&S.served.outcome.value!==void 0?J(S.served.outcome.value):q,ie=U(o,S.scope,S.atom,s.collection);if(ye(A,ie))continue;l.push(Object.freeze({scope:S.scope,atom:S.atom,record:S,before:A,outcome:ie}));let ee=[];S.inheritingChildren.forEach((Z)=>{S.scope.coordinator.recordCounter(1),ee.push(Z)});for(let Z=ee.length-1;Z>=0;Z--)k.push(ee[Z])}}for(let s of x){let y=s.top;if(y===void 0)continue;let b=new Set,M=[{node:y,affected:!1}];while(M.length){let w=M.pop(),h=w.node;if(b.has(h))continue;b.add(h),g(h.scope,ae);let p=w.affected||h.affected;if(p){let C=en(h);if(h.existing!==void 0&&(h.orderedPatch!==void 0?h.membershipChangedFromBefore:!Object.is(C,h.beforeRows)))u.push(Object.freeze({scope:h.scope,atom:h.atom,node:h,record:h.existing,rows:C}))}let R=[];h.existing?.inheritingChildren.forEach((C)=>{h.scope.coordinator.recordCounter(1);let k=p?K(C):P.get(C);if(k!==void 0&&(p||k.containsAffected))R.push(k)});for(let C of h.plannedChildren)if(p||C.containsAffected)R.push(C);for(let C=R.length-1;C>=0;C--)M.push({node:R[C],affected:p})}}for(let s of d){if(s.finalRows!==void 0)continue;if(s.parent===void 0){en(s);continue}s.finalRows=s.beforeRows,s.membershipChangedFromBefore=!1}let nn;if(a!==void 0&&o.planOrder.some((s)=>a.active(s.collection))){let s=new Map;for(let b of o.planOrder){if(!a.active(b.collection))continue;let M=m.get(b.scope)?.memberships?.get(b.collection);if(M===void 0)continue;let w=[M];while(w.length){let h=w.pop();if(h.ordered===void 0)continue;g(h.scope,Dn);let p=s.get(h);if(p===void 0)s.set(h,p=new Set);p.add(b.row),h.indexedChildren?.forEach((R)=>w.push(R))}}let y=[];for(let[b,M]of s){if(b.ordered===void 0)continue;let w=K(b),h=xe(w),p=[];for(let R of M){let C=L(b.scope,R),k=U(o,b.scope,R,b.atom),S=h.get(R)?.birth;if(ye(C,k)&&typeof S!=="number")continue;p.push({row:R,before:C.kind==="present"?C.value:void 0,after:k.kind==="present"?k.value:void 0,rank:k.kind==="absent"?void 0:typeof S==="number"?b.ordered.nextRank+S:b.ordered.entries.get(R)?.rank})}if(p.length)y.push({scope:b.scope,collection:b.atom,changes:p})}nn=a.prepare(y)}return{commit:Qn,indexPlan:nn,orderedNodes:r,rows:Object.freeze(n),rowSettlements:Object.freeze(l),membershipInstalls:Object.freeze(d),membershipSettlements:Object.freeze(u),sources:Object.freeze([...l,...u])}},Zn=(t)=>{let e=t,o=!1;for(let r of e.rowSettlements){let{record:n,before:l,outcome:d}=r;g(n.scope,pn),z(n.scope,l.kind==="absent"?Rn:d.kind==="absent"?gn:kn,n.atom,i.lookupRow(n.atom))}for(let r of e.membershipSettlements)for(let[n,l]of r.node.membershipChanges??[]){let d=l.baselinePresent&&l.birth===void 0?vn:!l.baselinePresent&&typeof l.birth==="number"?Sn:void 0;if(d!==void 0)z(r.node.scope,d,n,r.node.atom)}for(let r of e.rows){let n=r.coordinate.finalOperation;if(n!==void 0)z(r.coordinate.scope,n==="set"?bn:n==="update"?wn:n==="reset"?yn:Cn,r.coordinate.row,r.coordinate.collection);if(!r.ownershipChanged)continue;o=!0;let{row:l,scope:d}=r.coordinate;if(r.local.kind==="none"){let O=m.get(d);if(O?.rowLocals?.delete(l),O?.ownedRows?.delete(l))g(d,je);if(O?.ownedRows?.size===0){if(O.ownedRows=void 0,O.rowLocals=void 0,O.liveRowViews===void 0&&O.liveMemberships===void 0)m.delete(d)}continue}let u=ue(d),v=u.rowLocals;if(v===void 0)v=new WeakMap,u.rowLocals=v;let P=u.ownedRows;if(P===void 0)P=new Set,u.ownedRows=P,g(d,hn);if(v.set(l,r.local),!P.has(l))P.add(l),g(d,mn)}for(let r of e.membershipInstalls)r.installed=Oe(r.scope,r.atom,r.finalRows,r.parent!==void 0&&r.finalRows===r.beforeRows);for(let r of e.orderedNodes??[]){let{existing:n,orderedPatch:l}=r;if(!r.membershipChangedFromBefore)continue;for(let d of l.removals)n.ordered.remove(d);for(let d of l.births)n.ordered.append(d);n.snapshotDirty=!0,n.served=se(n.scope,G,n.served.token)}if(e.membershipSettlements.length)return!0;for(let r of e.membershipInstalls)if(r.membershipChangedFromBefore)return!0;return o},Xn=(t)=>{let e=t;for(let o of e.rows){if(!o.ownershipChanged)continue;let{row:r,scope:n}=o.coordinate,l=m.get(n)?.rowViews?.get(r);if(l===void 0)continue;if(o.local.kind!=="none"||n.parent===void 0)ve(l);else Kn(l,We(n.parent,r))}for(let o of e.membershipInstalls){let r=o.installed,n=o.parent?.existing??o.parent?.installed;if(r!==void 0&&n!==void 0)qe(r,n)}},Jn=(t)=>{let e=t;for(let r of e.rowSettlements){let{record:n,outcome:l}=r;n.served=Object.freeze({token:n.scope.createOutcomeToken(),outcome:ln(l)}),g(n.scope,fn),z(n.scope,Mn,n.atom,i.lookupRow(n.atom)),n.scope.coordinator.reachSubscriptionTarget(n.scope,n.atom)}for(let r of e.membershipSettlements){let{record:n,rows:l}=r;n.served=se(n.scope,n.ordered===void 0?l:n.served.outcome.kind==="value"?n.served.outcome.value:G),g(n.scope,un),z(n.scope,On,n.atom),n.scope.coordinator.reachSubscriptionTarget(n.scope,n.atom)}let o=e.indexPlan?.publish();if(o?.length)return[...e.sources,...o];return e.sources.length?e.sources:void 0},Qn=function(t){if(t===0)return Zn(this);if(t===1)return Xn(this);return Jn(this)},$n=(t)=>{let e=t;a?.dispose(e);let o=m.get(e);if(o===void 0)return;o.liveRowViews?.forEach((n)=>{ve(n),n.inheritingChildren.clear()}),o.liveMemberships?.forEach((n)=>{Fe(n),n.inheritingChildren.clear(),n.indexedChildren?.clear(),n.ordered?.entries.clear(),n.ordered=void 0,n.snapshotDirty=!1,n.served=se(n.scope,G,n.served.token)}),o.liveRowViews?.clear(),o.liveMemberships?.clear();let r=o.ownedRows?.size??0;if(r!==0)g(e,je,r);o.ownedRows?.clear(),o.rowLocals=void 0,o.ownedRows=void 0,o.rowViews=void 0,o.liveRowViews=void 0,o.memberships=void 0,o.liveMemberships=void 0,m.delete(e)};return Object.freeze({installIndexes:(t)=>a??(a=t({revision:(e,o)=>{let r=ne(e),n=r.queryRevisionByCollection??=new Map,l=n.get(o)??0;return n.set(o,l),l},membership:Wn,value:(e,o)=>{let r=L(e,o);return r.kind==="present"?r.value:void 0},draftRows:De,draftValue:(e,o,r)=>{let n=ne(e),l=o;while(l!==void 0){let d=n.byScope.get(l)?.get(r),u=d===void 0?I(l,r):Le(d);if(u.kind==="present")return u.value;if(u.kind==="absent")return;l=l.parent}return}})),has:(t)=>a?.has(t)===!0||i.lookupRow(t)!==void 0||i.lookupCollection(t),diagnosticName:i.lookupDiagnosticName,read:(t,e,o)=>{let r=t,n=e;if(a?.has(o))return{kind:"value",value:a.read(r,n,o)};if(i.lookupRow(o)!==void 0)return Object.freeze({kind:"value",value:Qe(r,n,o)});if(i.lookupCollection(o))return Object.freeze({kind:"value",value:De(r,n,o)});throw TypeError("Unknown collection scratch source")},stage:(t,e,o,r,n,l)=>{let d=t,u=e;if(o==="set")Ye(d,u,r,n,l);else if(o==="update")Ze(d,u,r,n,l);else if(o==="delete")Xe(d,u,r);else Je(d,u,r)},scope:(t,e)=>{if(e===void 0){$n(t);return}if(a?.has(e))return a.scope(t,e);if(i.lookupRow(e)!==void 0)return We(t,e).served;if(!i.lookupCollection(e))return;let o=Ee(t,e);return te(o),o.served},plan:Yn,stageSet:Ye,stageUpdate:Ze,stageDelete:Xe,stageReset:Je,readDraftRow:Qe,readDraftCollection:De,beginMembershipRebuildTraceForTest:()=>{if(N!==void 0)throw Error("A membership rebuild trace is already active");let t=[];return N=t,()=>{if(t===void 0)throw Error("The membership rebuild trace is already finished");N=void 0;let e=Object.freeze([...t]);return t.length=0,t=void 0,e}},beginMembershipPlacementTraceForTest:()=>{if(B!==void 0)throw Error("A membership placement trace is already active");let t={coordinates:0,states:0};return B=t,()=>{if(t===void 0)throw Error("The membership placement trace is already finished");B=void 0;let e=Object.freeze({...t});return t=void 0,e}},inspectDraft:Gn})};var oo={ref:(i)=>new WeakRef(i),registry:(i)=>{let c=new FinalizationRegistry(i);return Object.freeze({register:(a,f,m)=>c.register(a,f,m),unregister:(a)=>c.unregister(a)})}};class He{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#n;#o;#t;#r;constructor(i,c,a=oo,f){this.#o=i,this.#t=f,this.#r=c,this.#n=a.registry((m)=>{let N=m.route;if(N.entry!==m)return;N.entry=void 0,this.#c(N)}),this.#i=(m)=>a.ref(m)}#i;getOrCreateOne(i,c){return this.#s(this.#l(this.#e,i),c)}getOrCreateTuple(i,c){let a=this.#e;for(let f=0;f<i.length;f++)a=this.#l(a,i[f]);return this.#s(a,c)}get routeCount(){let i=0,c=(a)=>{if(a.children===void 0)return;for(let f of a.children.values())i++,c(f)};return c(this.#e),i}hasRoute(i){let c=this.#e;for(let a=0;a<i.length;a++){let f=c.children?.get(i[a]);if(f===void 0)return!1;c=f}return!0}#l(i,c){let a=i.children??(i.children=new Map),f=a.get(c);if(f!==void 0)return f;return f={parent:i,parentKey:c,children:void 0,entry:void 0},a.set(c,f),f}#s(i,c){let a=i.entry;if(a?.kind==="ready"){let m=a.reference.deref();if(m!==void 0)return m;if(this.#n.unregister(a),i.entry===a)i.entry=void 0}else if(a?.kind==="building"){let m=a.fault??this.#r();throw a.fault=m,m}let f={kind:"building",route:i,fault:void 0};i.entry=f;try{let m=this.#o(c);if(f.fault!==void 0)throw f.fault;this.#t?.(m);let N={kind:"ready",route:i,reference:this.#i(m)};return i.entry=N,this.#n.register(m,N,N),m}catch(m){if(i.entry===f)i.entry=void 0;throw this.#c(i),f.fault??m}}#c(i){let c=i;while(c.parent!==void 0&&c.entry===void 0&&(c.children===void 0||c.children.size===0)){let a=c.parent,f=a.children;if(f?.get(c.parentKey)!==c)return;if(f.delete(c.parentKey),f.size===0)a.children=void 0;c=a}}}var to=(i)=>new WeakRef(i),ke,ro=(i)=>{let c=ge(i),a=ke??(ke=new WeakMap),f=a.get(c);if(f!==void 0)return f;return f={collections:new WeakMap,rows:new WeakMap},a.set(c,f),f};class _n extends Error{code="VALDRES_INVALID_COLLECTION_KEY";constructor(){super("Collection keys must be strings, finite numbers, bigints, booleans, or null");this.name="InvalidCollectionKeyError",Object.freeze(this)}}var Be=()=>new _n,Ke=(i)=>{if(i===null)return null;switch(typeof i){case"string":case"bigint":case"boolean":return i;case"number":if(!Number.isFinite(i))throw Be();return Object.is(i,-0)?0:i;default:throw Be()}},Pn=(i)=>{throw be(i),Be()},io=(i,c,a)=>_e(i,"collection-encoder",(f)=>{let m;try{m=Reflect.apply(c,void 0,[f])}catch(B){let H=fe(B);if(H.kind==="not-thenable")throw B;if(H.kind==="inspection-error")throw H.error;return Pn(H)}let N=fe(m);if(N.kind==="not-thenable")return m;if(N.kind==="inspection-error")throw N.error;return Pn(N)},[a],Ke,()=>TypeError("collection encodeKey cannot call family or collection accessors")),lo=(i)=>{if(i===void 0)return{};if(typeof i!=="object"||i===null)throw TypeError("collection options must be an object");for(let f of Reflect.ownKeys(i))if(f!=="encodeKey"&&f!=="indexes"&&f!=="name")throw TypeError("collection options contain an unknown option");let c;if(Object.prototype.hasOwnProperty.call(i,"encodeKey")){let f=Reflect.get(i,"encodeKey");if(typeof f!=="function")throw TypeError("collection encodeKey must be a function");c=f}let a=Reflect.get(i,"name");return{...c===void 0?{}:{encodeKey:c},...a===void 0?{}:{name:a}}},so=()=>TypeError("collection cannot recursively construct the same row"),co=()=>TypeError("presence requires a same-domain CollectionRow"),ao=(i,c)=>{let a=ke?.get(ge(i));if(typeof c==="object"&&c!==null||typeof c==="function"){let f=a?.rows.get(c);if(f!==void 0)return f}throw ze(i,c),co()};function So(i,c,a){Vn(i);let{encodeKey:f,name:m}=lo(c),N;if(c!==void 0&&Object.prototype.hasOwnProperty.call(c,"indexes")){let I=Reflect.get(c,"indexes");if(typeof I!=="object"||I===null||Array.isArray(I))throw TypeError("collection indexes must be an extractor map");let L=Reflect.ownKeys(I).map((Y)=>{let Q=Reflect.get(I,Y);if(typeof Y!=="string"||typeof Q!=="function")throw TypeError("collection indexes must be named scalar extractors");return[Y,Q]});if(L.length)N=Object.freeze(Object.fromEntries(L))}let B=[],H,g=Object.assign(function(L){Ae(i);let Y=f===void 0?Ke(L):io(i,f,L);B[0]=Y;try{return H.rows.getOrCreateOne(Y,B)}finally{B.pop()}},{kind:"collection"}),z=Ve(i,g),V,ue=new He((I)=>{let L=I[0];return Ve(i,{kind:"collection-row",key:L})},so,a,(I)=>{if(V===void 0)throw Error("Collection definition registry is not ready");V.rows.set(I,{definition:H,presence:void 0})});return H=Object.freeze({collection:z,indexes:N,...m===void 0?{}:{name:m},rows:ue,referencePresence:a===void 0?to:(I)=>a.ref(I)}),V=ro(i),V.collections.set(z,H),Hn(i,(I)=>Ln({lookupRow:(L)=>V.rows.get(L)?.definition.collection,lookupCollection:(L)=>V.collections.has(L),lookupDiagnosticName:(L)=>V.rows.get(L)?.definition?.name??V.collections.get(L)?.name,runGuarded:(L,Y)=>jn(I,L,Y),inspectThenable:fe,containThenable:be})),z}var vo=(i,c)=>{Ae(i);let a=ao(i,c),f=a.presence?.deref();if(f!==void 0)return f;let m=Bn(i,(N)=>N(c)!==void 0);return a.presence=a.definition.referencePresence(m),m},Mo=(i,c,a)=>{let f=ke?.get(ge(i))?.collections.get(c);if(f===void 0)throw ze(i,c),TypeError("query requires a same-domain Collection");let m=f.indexes!==void 0&&Object.prototype.hasOwnProperty.call(f.indexes,a)?f.indexes[a]:void 0;if(m===void 0)throw TypeError("query requires a declared equality index");return(N)=>_e(i,"collection-encoder",(B)=>{let H;try{H=m(B)}catch(z){let V=fe(z);if(V.kind==="thenable")throw be(V),TypeError("Index extractors must return a synchronous scalar");if(V.kind==="inspection-error")throw V.error;throw z}let g=fe(H);if(g.kind==="thenable")throw be(g),TypeError("Index extractors must return a synchronous scalar");if(g.kind==="inspection-error")throw g.error;return Ke(H)},[N])};
2
+ export{He as a,Nn as b,xn as c,In as d,_n as e,So as f,vo as g,Mo as h};