@wcstack/state 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +20 -17
- package/README.md +20 -17
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.esm.js +73 -34
- package/dist/parser.esm.js +10 -4
- package/dist/split/auto.js +1 -1
- package/dist/split/chunks/chunk-2RBI6DVS.js +2 -0
- package/dist/split/chunks/chunk-2RBI6DVS.js.map +1 -0
- package/dist/split/chunks/{chunk-V3HFN3MW.js → chunk-3Q7LGONS.js} +2 -2
- package/dist/split/chunks/{chunk-V3HFN3MW.js.map → chunk-3Q7LGONS.js.map} +1 -1
- package/dist/split/chunks/{chunk-UFIDBJBP.js → chunk-4ECL4ITF.js} +2 -2
- package/dist/split/chunks/{chunk-7ZU3CLEG.js → chunk-BGUJ3HF6.js} +2 -2
- package/dist/split/chunks/{chunk-4HLDITUB.js → chunk-BI4645UG.js} +2 -2
- package/dist/split/chunks/chunk-BI4645UG.js.map +1 -0
- package/dist/split/chunks/{chunk-JAEYZSVS.js → chunk-BYQBV3ZC.js} +2 -2
- package/dist/split/chunks/{chunk-R5OJ52SF.js → chunk-CIBJLAA3.js} +2 -2
- package/dist/split/chunks/{chunk-R5OJ52SF.js.map → chunk-CIBJLAA3.js.map} +1 -1
- package/dist/split/chunks/chunk-JK3B3LLB.js +2 -0
- package/dist/split/chunks/chunk-OKBVNGFK.js +2 -0
- package/dist/split/chunks/{chunk-56ZGITUJ.js.map → chunk-OKBVNGFK.js.map} +1 -1
- package/dist/split/chunks/{chunk-GGSHXG7N.js → chunk-UBGJGMSG.js} +2 -2
- package/dist/split/chunks/chunk-UBGJGMSG.js.map +1 -0
- package/dist/split/chunks/{chunk-7QVEF5E3.js → chunk-UPSLR4FS.js} +2 -2
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/diagnostics.js.map +1 -1
- package/dist/split/features/formats.d.ts +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/formats.js.map +1 -1
- package/dist/split/features/list-keys.js +1 -1
- package/dist/split/features/native-commands.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/split/features/temporal.js.map +1 -1
- package/dist/wcs-manifest.json +25 -7
- package/package.json +1 -1
- package/dist/split/chunks/chunk-4HLDITUB.js.map +0 -1
- package/dist/split/chunks/chunk-56ZGITUJ.js +0 -2
- package/dist/split/chunks/chunk-BWGPKDHS.js +0 -2
- package/dist/split/chunks/chunk-BWGPKDHS.js.map +0 -1
- package/dist/split/chunks/chunk-GGSHXG7N.js.map +0 -1
- package/dist/split/chunks/chunk-XEGL4FW5.js +0 -2
- /package/dist/split/chunks/{chunk-UFIDBJBP.js.map → chunk-4ECL4ITF.js.map} +0 -0
- /package/dist/split/chunks/{chunk-7ZU3CLEG.js.map → chunk-BGUJ3HF6.js.map} +0 -0
- /package/dist/split/chunks/{chunk-JAEYZSVS.js.map → chunk-BYQBV3ZC.js.map} +0 -0
- /package/dist/split/chunks/{chunk-XEGL4FW5.js.map → chunk-JK3B3LLB.js.map} +0 -0
- /package/dist/split/chunks/{chunk-7QVEF5E3.js.map → chunk-UPSLR4FS.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["TRUSTED_TYPES_POLICY_SLOT","Symbol","for","getTrustedTypesPolicy","value","globalThis","setTrustedTypesPolicy","policy","isHtmlSink","prop","trustHtml","trustedTypes","isHTML","s","String","create","createHTML","call","StateRow","constructor","list","index","item","this","cache","view","bindings","eqSubs","children","alive","StateList","pattern","parentRow","arr","rows","extra","queued","stale","shared","depth","EMPTY","Token","name","subscribers","Set","size","subscribe","fn","add","delete","unsubscribe","emit","args","results","push","error","console","text","readNames","key","reserved","Array","isArray","raise","seen","has","TRANSITION_RUNNER_KEY","getTransitionRunner","source","candidate","protocol","version","run","accepts","runTransition","mutate","types","runner","DECLARATIONS","BEHAVIOR_KEYS","unbound","path","includes","recursionUnsupported","evals","MAX_DRAIN_PASSES","MAX_RENDER_CHAIN","upsert","m","k","make","v","get","set","newSet","newArray","isThenable","r","then","sameValueZero","a","b","unsubEq","sub","dig","segs","i","length","rowAt","row","ctxRow","ctx","p","lists","Engine","target","strategy","slotCount","readonlyDepth","dropped","delegated","Map","blockKey","element","errors","rendered","frames","depthNow","top","rootLists","rootBindings","queue","dirtyLists","staleLists","scheduled","draining","listsByArray","WeakMap","chain","carried","unsettled","fedBack","codeWrote","feeding","unchainFn","renderedFn","rp","rr","drainFn","drain","deliverFn","handler","proxy","rootEqSubs","loose","api","$untracked","f","untracked","$eqIndex","level","getter","underGetter","watchIndex","read","g","watchers","eqIndexWatchers","some","w","listP","eqIndexKeys","readUntracked","$eq","eq","$eqPath","keyPath","kp","$dependOn","resolve","track","$getAll","indexes","getAll","$setAll","options","setAll","$resolve","checkArity","rowOf","write","$postUpdate","last","resetRow","touched","mirror","rekeyEqUnder","landed","patterns","PatternTable","onPatternCreated","loadTarget","engine","getOwnPropertyDescriptor","_t","d","Reflect","configurable","receiver","t","charCodeAt","dollar","indexOf","peek","bound","trap","Proxy","pinned","registerAccessors","o","Object","prototype","getPrototypeOf","getOwnPropertyNames","setter","slot","all","parent","markupAccessor","INDEX_PARAM","test","split","findIndex","j","markup","childList","l","sync","trySync","failAt","anchor","unfile","old","next","hooks","n","start","oe","ne","rowRemoved","end","byItem","pop","values","indexChanged","reconcile","same","x","listSynced","schedule","keys","sel","before","after","invalidateUnder","onIndexChange","subs","e","was","splice","parsed","parsePath","idx","join","readData","tail","readGetter","addDependent","mark","epoch","reads","Math","min","crossSources","evalGetter","frame","outer","prev","prune","sources","filter","rootValue","unlink","dropDependent","sweep","c","parents","dead","dependents","drop","q","indexWatchers","slice","commands","subscribeEq","forSubtree","map","rest","rekeyEqIndex","invalidate","occurrence","beforeWrite","callAt","guard","is","syncListsUnder","sharing","direct","suffix","land","mp","down","deps","DIRTY","up","forListsUnder","enqueueBound","ls","isUnder","forAllLists","forRowsUnder","written","changed","onWrite","delegate","type","known","root","addEventListener","parentNode","cancelBubble","block","dispatch","reset","bs","enqueue","resetList","watchRendered","feature","requireFeature","$features","$behavior","mustache","directional","ns","$commandTokens","freeze","commandNamespace","events","deliver","tokens","$eventTokens","on","$on","entries","token","eventTokens","declare","forget","indexesOf","out","unshift","fireEventToken","event","command","emitCommand","invoke","apply","slots","enqueueSlots","fv","rv","walkDependents","visit","visitGetter","forAllRows","getterReached","register","unregister","queueMicrotask","dropWork","cutLoop","id","max","paths","noticed","maxDepth","setTimeout","pass","update","owner","applyBinding","report","pending","drained","fail","node","typeName","noteRendered","$renderedCallback","callHook","hook","$errorCallback","binding","failed","bindingType","forMatches","walk","lp","targets","spread","exact","et","G","I","J","Z","H","Q","lt","ut","at"],"sources":["../../../src/trustedTypes.ts","../../../src/list.ts","../../../src/token.ts","../../../src/protocol/transitionRunner.ts","../../../src/engine.ts"],"sourcesContent":["/**\n * Trusted Types for the HTML sinks (`html:`, `innerHTML:`, `outerHTML:`, `srcdoc:`).\n * The policy lives on the same global slot as @wcstack/state, so a page that installed\n * one for the current engine keeps working:\n * globalThis[Symbol.for(\"wcstack.trustedTypes.policy\")] = trustedTypes.createPolicy(…)\n * No identity policy is ever created here — that would defeat the CSP.\n */\nexport interface TrustedTypesPolicy {\n createHTML?(input: string): unknown;\n}\n\nexport const TRUSTED_TYPES_POLICY_SLOT = Symbol.for(\"wcstack.trustedTypes.policy\");\n\ntype Slot = { [key: symbol]: unknown };\n\nexport function getTrustedTypesPolicy(): TrustedTypesPolicy | null {\n const value = (globalThis as Slot)[TRUSTED_TYPES_POLICY_SLOT];\n return value !== null && typeof value === \"object\" ? (value as TrustedTypesPolicy) : null;\n}\n\nexport function setTrustedTypesPolicy(policy: TrustedTypesPolicy | null): void {\n (globalThis as Slot)[TRUSTED_TYPES_POLICY_SLOT] = policy;\n}\n\nexport function isHtmlSink(prop: string): boolean {\n return prop === \"innerHTML\" || prop === \"outerHTML\" || prop === \"srcdoc\";\n}\n\n/**\n * A value for an HTML sink: a TrustedHTML (the page made it with its own policy) as it is, anything\n * else — an array or another object too, which the sink would turn into markup — as a string\n * (null / undefined: empty) passed through the installed policy (if any).\n */\nexport function trustHtml(value: unknown): unknown {\n if ((globalThis as any).trustedTypes?.isHTML(value)) return value;\n const s = value == null ? \"\" : String(value);\n const policy = getTrustedTypesPolicy();\n const create = policy?.createHTML;\n return typeof create === \"function\" ? create.call(policy, s) : s;\n}\n","import type { Pattern } from \"./pattern\";\nimport type { Binding, ForView, RowView } from \"./dom/view\";\n\n/**\n * One element of a list, owned by its StateList. The row is the whole address of\n * everything under `list.*`: the value (`item`), the position (`index`), the getter\n * cache and the bindings that render it hang off this object — no ledger keyed by an\n * address. Dropping the row drops all of it.\n */\nexport class StateRow {\n readonly list: StateList;\n index: number;\n item: unknown;\n /** Getter cache by slot (row-level getters of this engine). */\n cache: unknown[] | null = null;\n /** The rendering of this row by its list's first for view (see StateList.extra for the others). */\n view: RowView | null = null;\n /**\n * Binding objects whose location is in this row (pattern depth = this row's depth), wherever\n * they render. Row views' slot bindings are not here: they are reached through the views.\n */\n bindings: Binding[] | null = null;\n /** `$eq` subscriptions of getters evaluated at this row (dropped with the row). */\n eqSubs: import(\"./engine\").EqEntry[] | null = null;\n /** Nested lists under this row, by list pattern. */\n children: Map<Pattern, StateList> | null = null;\n alive = true;\n\n constructor(list: StateList, index: number, item: unknown) {\n this.list = list;\n this.index = index;\n this.item = item;\n }\n}\n\nexport class StateList {\n readonly pattern: Pattern;\n readonly parentRow: StateRow | null;\n /** Depth of this list's rows (1 for a root list). */\n readonly depth: number;\n /** The array the rows were last reconciled against. */\n arr: unknown[] | null = null;\n rows: StateRow[] = [];\n /** The first for view that renders this list, if any (its row views are on row.view). */\n view: ForView | null = null;\n /** Further for views rendering the same list (each keeps its row views by row). */\n extra: ForView[] | null = null;\n /** Queued for a view update in the current drain. */\n queued = false;\n /** Its pattern reads through a getter that changed: re-synced at the next drain pass. */\n stale = false;\n /** Another list has the same array (a getter returning it, an index path): writes reach both. */\n shared = false;\n\n constructor(pattern: Pattern, parentRow: StateRow | null) {\n this.pattern = pattern;\n this.parentRow = parentRow;\n this.depth = pattern.depth + 1;\n }\n}\n\nexport interface ReconcileHooks {\n /** A kept row changed position. */\n indexChanged(row: StateRow): void;\n /** A row left the list (it marks it dead). */\n rowRemoved(row: StateRow): void;\n}\n\ntype Bucket = StateRow | StateRow[];\n\n/**\n * Brings `list.rows` in line with `next`, reusing rows by item identity.\n * Returns the previous rows (for $eqIndex re-keying) or null when nothing changed.\n * DOM is not touched here; the list's view catches up in the drain.\n */\nexport function reconcile(list: StateList, next: unknown, hooks: ReconcileHooks): StateRow[] | null {\n const arr = Array.isArray(next) ? next : EMPTY;\n if (arr === list.arr) return null;\n const old = list.rows;\n const n = arr.length;\n const o = old.length;\n const rows: StateRow[] = new Array(n);\n\n let start = 0;\n while (start < n && start < o && old[start].item === arr[start]) {\n rows[start] = old[start];\n start++;\n }\n let oe = o - 1;\n let ne = n - 1;\n while (oe >= start && ne >= start && old[oe].item === arr[ne]) {\n rows[ne] = old[oe];\n oe--;\n ne--;\n }\n\n if (start > oe) {\n for (let i = start; i <= ne; i++) rows[i] = new StateRow(list, i, arr[i]);\n } else if (start > ne) {\n for (let i = start; i <= oe; i++) hooks.rowRemoved(old[i]);\n } else {\n // a row whose item is where it was keeps its place: among equal items (a board of 0 / 1), handing\n // the rows out in order would move every one after the first change\n const end = oe < ne ? oe : ne;\n for (let i = start; i <= end; i++) if (old[i].item === arr[i]) rows[i] = old[i];\n const byItem = new Map<unknown, Bucket>();\n // filled from the end, so a bucket hands out its first row with pop(): shift() moves the whole\n // array, and over a long run of equal items the reconcile went quadratic\n for (let i = oe; i >= start; i--) {\n const row = old[i];\n if (i <= end && rows[i] === row) continue;\n const b = byItem.get(row.item);\n if (b === undefined) byItem.set(row.item, row);\n else if (Array.isArray(b)) b.push(row);\n else byItem.set(row.item, [b, row]);\n }\n for (let i = start; i <= ne; i++) {\n if (rows[i] !== undefined) continue;\n const item = arr[i];\n const b = byItem.get(item);\n let row: StateRow | undefined;\n if (b !== undefined) {\n if (Array.isArray(b)) {\n row = b.pop();\n if (b.length === 0) byItem.delete(item);\n } else {\n row = b;\n byItem.delete(item);\n }\n }\n rows[i] = row ?? new StateRow(list, i, item);\n }\n for (const b of byItem.values()) {\n if (Array.isArray(b)) for (const r of b) hooks.rowRemoved(r);\n else hooks.rowRemoved(b);\n }\n }\n\n // positions: only rows from `start` on can have moved\n for (let i = start; i < n; i++) {\n const row = rows[i];\n if (row.index !== i) {\n row.index = i;\n hooks.indexChanged(row);\n }\n }\n list.rows = rows;\n list.arr = arr;\n return old;\n}\n\n/** What a list whose value is not an array reconciles against (engine: an index there is a key). */\nexport const EMPTY: unknown[] = [];\n","/**\n * The command-token / event-token pub/sub primitive (the same shape as @wcstack/state's\n * `Token`). A subscriber that throws is reported and the others still receive the call.\n */\nimport { raise, M, text } from \"./messages\";\n\nexport type TokenSubscriber = (...args: unknown[]) => unknown;\n\nexport class Token {\n readonly name: string;\n private readonly subscribers = new Set<TokenSubscriber>();\n\n constructor(name: string) {\n this.name = name;\n }\n\n get size(): number {\n return this.subscribers.size;\n }\n\n subscribe(fn: TokenSubscriber): () => void {\n this.subscribers.add(fn);\n return () => {\n this.subscribers.delete(fn);\n };\n }\n\n unsubscribe(fn: TokenSubscriber): boolean {\n return this.subscribers.delete(fn);\n }\n\n emit(...args: unknown[]): unknown[] {\n const results: unknown[] = [];\n for (const fn of this.subscribers) {\n try {\n results.push(fn(...args));\n } catch (error) {\n results.push(undefined);\n console.error(`[@wcstack/state] ${text(M.TokenSubscriberThrew, [this.name])}`, error);\n }\n }\n return results;\n }\n}\n\nfunction readNames(value: unknown, key: string, reserved?: string): string[] {\n if (value === undefined) return [];\n if (!Array.isArray(value)) raise(M.TokenListNotArray, [key]);\n const seen = new Set<string>();\n for (const name of value) {\n if (typeof name !== \"string\" || name === \"\") raise(M.TokenEntryEmpty, [key]);\n if (name === reserved) raise(M.TokenEntryReserved, [key, name, reserved]);\n if (seen.has(name)) raise(M.TokenEntryDuplicated, [key, name]);\n seen.add(name);\n }\n return value as string[];\n}\n\n/**\n * `$commandTokens` → the frozen `$command` namespace (name → Token). On a re-set, a name\n * the previous state declared keeps its token: elements subscribed to it keep receiving.\n */\nexport function commandNamespace(target: Record<string, any>, prev?: Readonly<Record<string, Token>>): Readonly<Record<string, Token>> {\n const ns: Record<string, Token> = {};\n for (const name of readNames(target.$commandTokens, \"$commandTokens\", \"$command\")) ns[name] = prev?.[name] ?? new Token(name);\n return Object.freeze(ns);\n}\n\n/**\n * `$eventTokens` + `$on` → name → Token, with each `$on` handler subscribed as\n * `(state, event, ...listIndexes)` through `deliver`.\n */\nexport function eventTokens(\n target: Record<string, any>,\n deliver: (handler: (...args: unknown[]) => unknown, args: unknown[]) => unknown,\n): Map<string, Token> {\n const tokens = new Map<string, Token>();\n for (const name of readNames(target.$eventTokens, \"$eventTokens\")) tokens.set(name, new Token(name));\n const on = target.$on;\n if (on === undefined) return tokens;\n if (on === null || typeof on !== \"object\") raise(M.OnNotObject);\n for (const [name, handler] of Object.entries(on)) {\n const token = tokens.get(name);\n if (token === undefined) raise(M.OnEntryUndeclared, [name]);\n if (typeof handler !== \"function\") raise(M.OnEntryNotFunction, [name]);\n token.subscribe((...args) => deliver(handler as (...a: unknown[]) => unknown, args));\n }\n return tokens;\n}\n","// ===========================================================================\n// AUTO-GENERATED FILE - DO NOT EDIT.\n// Generated from /protocol/transition-runner.ts by scripts/sync-protocol-types.mjs.\n// Run `node scripts/sync-protocol-types.mjs` after editing the source.\n// ===========================================================================\n\n// transition-runner protocol — how a package that mutates the DOM hands that\n// mutation to whoever is arbitrating view transitions on the page.\n//\n// @wcstack/state and @wcstack/router must not depend on @wcstack/view-transition\n// (zero runtime dependencies, independently publishable), so the arbiter installs\n// itself on a well-known global symbol and the participants look it up lazily.\n// No arbiter installed means the mutation is invoked directly, synchronously —\n// byte-for-byte the behavior these packages had before the protocol existed.\n//\n// docs/view-transition-design.md §4 is the normative description.\n//\n// SINGLE SOURCE OF TRUTH: edit only this file (/protocol/transition-runner.ts), then run\n// `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies\n// (packages/<pkg>/src/protocol/transitionRunner.ts). Those copies are generated — do not edit them.\n\n/**\n * Global key the arbiter installs itself under. `Symbol.for` so independently\n * loaded copies of this file (two CDN bundles on one page) still agree.\n */\nexport const TRANSITION_RUNNER_KEY = Symbol.for(\"wcstack.transition-runner\");\n\n/** Who is asking. Backs the arbiter's `for=` participant gate. */\nexport type TransitionSource = \"router\" | \"state\";\n\n/** `view-transition-name` assignment policy the arbiter declares for participants. */\nexport type TransitionNaming = \"manual\" | \"auto\";\n\nexport interface IWcsTransitionRunOptions {\n /** Participant id, for the `for=` gate and for diagnostics. */\n readonly source?: string;\n /** Transition types, where the environment supports `startViewTransition({ types })`. */\n readonly types?: readonly string[];\n}\n\nexport interface IWcsTransitionRunner {\n readonly protocol: \"wcs-transition-runner\";\n /** Integer protocol version. All versions >= 1 are participant-compatible. */\n readonly version: number;\n /** `\"auto\"` licenses a participant to assign `view-transition-name` itself. */\n readonly naming: TransitionNaming;\n /** Upper bound on auto-assigned names; past it a participant stops naming. */\n readonly namingLimit: number;\n /** Whether this participant animates at all. */\n accepts(source: string): boolean;\n /**\n * Invoke `mutate` inside a view transition when one is possible.\n *\n * Contract (docs/view-transition-design.md §4):\n * - `mutate` is invoked exactly once, whatever happens to the transition.\n * - The promise resolves once `mutate` has run — never waits for the animation.\n * - When no transition is started, `mutate` runs synchronously inside `run()`.\n * - It rejects only if `mutate` threw.\n */\n run(mutate: () => void, options?: IWcsTransitionRunOptions): Promise<void>;\n}\n\n/**\n * The installed arbiter, or null when there is none, it speaks a version this\n * reader does not, or it does not accept this participant.\n *\n * Looked up on every call rather than cached: the tag can be added, removed, or\n * reconfigured at any point in a page's life, and a stale cache would either\n * animate what the author just switched off or miss what they switched on.\n */\nexport function getTransitionRunner(source: string): IWcsTransitionRunner | null {\n const candidate = (globalThis as Record<symbol, unknown>)[TRANSITION_RUNNER_KEY] as\n | IWcsTransitionRunner\n | undefined;\n if (candidate === undefined || candidate === null) return null;\n if (candidate.protocol !== \"wcs-transition-runner\") return null;\n if (typeof candidate.version !== \"number\" || candidate.version < 1) return null;\n if (typeof candidate.run !== \"function\") return null;\n if (typeof candidate.accepts !== \"function\" || !candidate.accepts(source)) return null;\n return candidate;\n}\n\n/**\n * Run `mutate` under the installed arbiter, or directly when there is none.\n *\n * Returns `undefined` in the no-arbiter case instead of a resolved promise: the\n * state drain calls this on every batch, and awaiting is a caller's choice, not\n * an allocation the common path should pay for. `await` accepts both.\n */\nexport function runTransition(\n source: string,\n mutate: () => void,\n types?: readonly string[],\n): Promise<void> | undefined {\n const runner = getTransitionRunner(source);\n if (runner === null) {\n mutate();\n return undefined;\n }\n return runner.run(mutate, { source, types });\n}\n","import { DIRTY, Pattern, PatternTable, parsePath, WILDCARD, type EqSub } from \"./pattern\";\nimport { StateList, StateRow, reconcile, EMPTY, type ReconcileHooks } from \"./list\";\nimport type { Strategy } from \"./strategy/types\";\nimport type { Binding } from \"./dom/view\";\nimport { commandNamespace, eventTokens, type Token } from \"./token\";\nimport { runTransition } from \"./protocol/transitionRunner\";\nimport { raise, M, text } from \"./messages\";\nimport { recursionUnsupported } from \"./parser/parseStatePart\";\nimport { hooks, requireFeature } from \"./hooks\";\nimport { INDEX_PARAM, MAX_INDEX_PARAM } from \"./parser/define\";\n\n/** Declarations an add-on serves: without it installed they fail instead of doing nothing. */\nconst DECLARATIONS: [string, string][] = [[\"$watch\", \"temporal\"], [\"$stream\", \"temporal\"], [\"$listKeys\", \"list-keys\"], [\"$recursion\", \"recursion\"]];\n\n/**\n * The options of `$behavior` (each true by default): what an engine reads them as is `mustache` / `guard` / `directional`.\n * The tooling manifest publishes the same list (`behaviorOptions`, public/manifest.ts — public-surface.test.ts pins\n * them equal; the manifest does not import the engine).\n */\nexport const BEHAVIOR_KEYS: readonly string[] = [\"enableMustache\", \"sameValueGuard\", \"enableDirectionalInitialSync\"];\n\n/** `**` binds a depth only where a path is read: an assignment, $resolve, $postUpdate and $dependOn refuse it. */\nfunction unbound(path: string): string {\n if (path.includes(\"**\")) recursionUnsupported(path);\n return path;\n}\n\n/** `$1` … `$128`, no leading zero (parser/define.ts — the tooling manifest reads them there too). */\nexport { INDEX_PARAM, MAX_INDEX_PARAM };\n\ninterface Frame {\n getter: Pattern;\n row: StateRow | null;\n untracked: number;\n /** The evaluation this frame runs (`$eq` tells its keys from an earlier evaluation's). */\n epoch: number;\n /** What a root getter's evaluation read (Engine.prune). */\n reads: Pattern[];\n}\n\n/** Getter evaluations so far (each frame takes the next: an evaluation's identity). */\nlet evals = 0;\n\n/** A `$eq` subscription of a getter occurrence, kept on its row (or the engine, at the root). */\nexport interface EqEntry {\n source: Pattern;\n key: unknown;\n sub: EqSub;\n epoch: number;\n}\n\n/** A drain that keeps producing work this many times in a row is an update loop. */\nexport const MAX_DRAIN_PASSES = 32;\n/**\n * Drains in a row that rendering itself started (an element's write-back, a write in\n * `$renderedCallback`) beyond this many are an update loop (as @wcstack/state 3.3.x).\n */\nexport const MAX_RENDER_CHAIN = 100;\n/** Nested getter evaluations deeper than this are a runaway chain. */\nconst MAX_GETTER_DEPTH = 128;\n\nexport type Visit = (getter: Pattern, row: StateRow | null) => boolean;\n\n/** The value of `k` in `m`, made and set first when there is none (`make`: a shared factory, not a closure per call). */\nfunction upsert<K, V>(m: { get(k: K): V | undefined; set(k: K, v: V): unknown }, k: K, make: () => V): V {\n let v = m.get(k);\n if (v === undefined) m.set(k, (v = make()));\n return v;\n}\nconst newSet = <T>(): Set<T> => new Set<T>();\nconst newArray = <T>(): T[] => [];\n\n/** A promise, or anything with a then(). */\nexport function isThenable(r: any): r is PromiseLike<unknown> {\n return r !== null && typeof r === \"object\" && typeof r.then === \"function\";\n}\n\n/** Map-key equality: Object.is, except +0 and -0 are equal (keys of a Map). */\nfunction sameValueZero(a: unknown, b: unknown): boolean {\n return a === b || (a !== a && b !== b);\n}\n\n/** Drops a `$eq` subscription; a key nobody waits for any more leaves the map (it may be a row's item). */\nfunction unsubEq(source: Pattern, key: unknown, sub: EqSub): void {\n const set = source.eqSubs?.get(key);\n if (set !== undefined && set.delete(sub) && set.size === 0) source.eqSubs!.delete(key);\n}\n\nfunction dig(v: any, segs: readonly string[]): unknown {\n for (let i = 0; i < segs.length; i++) {\n if (v == null) return undefined;\n v = v[segs[i]];\n }\n return v;\n}\n\n/** The row at `depth` on the chain of `row` (itself or an ancestor), or null. */\nexport function rowAt(row: StateRow | null, depth: number): StateRow | null {\n while (row !== null && row.list.depth > depth) row = row.list.parentRow;\n return row !== null && row.list.depth === depth ? row : null;\n}\n\n/** The context row of `p`'s list at depth `k` — null when the context is a row of another list. */\nfunction ctxRow(ctx: StateRow | null, p: Pattern, k: number): StateRow | null {\n const r = rowAt(ctx, k);\n return r !== null && r.list.pattern === p.lists[k] ? r : null;\n}\n\n/**\n * One engine per <wcs-state>. It owns everything reachable from its state: the\n * patterns, the lists and their rows, the bindings, the update queue. Nothing is keyed\n * by the state element, because nothing is shared between engines.\n */\nexport class Engine implements ReconcileHooks {\n target!: Record<string, any>;\n /** `$behavior` (fixed at construction): `{{ }}` text, the same-value guard, direction-aware initial sync. */\n mustache!: boolean;\n guard!: boolean;\n directional!: boolean;\n readonly patterns: PatternTable;\n readonly strategy: Strategy;\n readonly proxy: Record<string, any>;\n /** Number of row-level getter slots. */\n slotCount = 0;\n /** Evaluation context: the row a getter / method / setter runs for. */\n ctx: StateRow | null = null;\n /** Writes throw while > 0: a readonly createState callback, or a getter being evaluated. */\n readonlyDepth = 0;\n /**\n * Top-level keys a re-set dropped (the old state had them, the new one lacks them): they read as\n * undefined, not as keys never declared (read; the diagnostics add-on reads it too). Kept here — the\n * author's state object is not written to (it may be frozen, or a Proxy that refuses).\n */\n readonly dropped = new Set<string>();\n /** The node the bindings were mounted on (delegated listeners live here); none before the mount. */\n root?: Node;\n /** Delegated event types → the property (per engine) their element handlers are stored under. */\n private readonly delegated = new Map<string, symbol>();\n /** Property (per engine) on a block's top node(s) holding the block, for delegated events. */\n readonly blockKey = Symbol(\"wcs.block\");\n /** The <wcs-state> element (`this.$stateElement`). */\n element: unknown = null;\n /**\n * A mounted component's (scopes add-on): a function read off the proxy itself, made to run on it\n * when called detached — the proxy is `element.state`, and `const { toggle } = element.state`\n * works (3.x #331). Undefined (or no answer): as it is.\n */\n declare bound?: (fn: (...args: any[]) => unknown) => unknown;\n /** `$command`: the command tokens declared in `$commandTokens`. */\n commands!: Readonly<Record<string, Token>>;\n /** The event tokens declared in `$eventTokens`, with the `$on` handlers subscribed. */\n events!: Map<string, Token>;\n /** Binding failures of the current drain, reported after it (`$errorCallback` or console). */\n private errors: [unknown, Binding][] = [];\n /** Paths applied in the current drain, for `$renderedCallback` (collected only when declared). */\n rendered: Map<string, number[][]> | null = null;\n private frames: Frame[] = [];\n private depthNow = 0;\n private top: Frame | null = null;\n readonly rootLists = new Map<Pattern, StateList>();\n readonly rootBindings = new Map<Pattern, Set<Binding>>();\n private queue: Binding[] = [];\n private dirtyLists: StateList[] = [];\n /** Lists over a changed getter, re-synced at the start of the next drain pass. */\n private staleLists: StateList[] = [];\n private scheduled = false;\n private draining = false;\n /** The lists over each array (only while more than one list has it do writes mirror). */\n private readonly listsByArray = new WeakMap<unknown[], StateList[]>();\n /** Drains in a row that rendering started (MAX_RENDER_CHAIN); a pause between tasks ends it. */\n private chain = 0;\n /**\n * For the drain the write-backs of an apply an arbiter deferred start: its place in that apply's\n * chain (0: none). The pause before the apply ends the task's chain, not this one. Only what the\n * apply writes synchronously is carried: an async `$renderedCallback` writing after an `await`\n * starts a task chain again, so such a loop runs one lap per arbiter task and is never cut.\n */\n private carried = 0;\n /** This chain was reported as not settling within a drain (#11): reported once a chain. */\n private unsettled = false;\n /** Since the last drain started: a write rendering fed back / a write from code (which ends a chain). */\n private fedBack = false;\n private codeWrote = false;\n /**\n * Inside `$renderedCallback` (until an async one settles) or a `$watch` handler: its writes are\n * reactions, fed back like an element's (MAX_RENDER_CHAIN).\n */\n feeding = 0;\n private readonly unchainFn = () => {\n this.chain = 0;\n this.unsettled = false;\n };\n private readonly renderedFn = () => {\n this.feeding--;\n };\n // out-parameters of resolve()\n private rp: Pattern | null = null;\n private rr: StateRow | null = null;\n\n private readonly drainFn = () => this.drain();\n private readonly deliverFn = (handler: (...a: unknown[]) => unknown, args: unknown[]) => handler(this.proxy, ...args);\n /** `$eq` subscriptions of root-level getters. */\n private readonly rootEqSubs: EqEntry[] = [];\n /** Patterns made, or no longer read by a root getter, since the last sweep: what it looks at. */\n private loose: Pattern[] = [];\n /** The `$` functions of the state (`this.$eq`, …), by name. */\n private readonly api: Record<string, unknown> = {\n $untracked: (fn: () => unknown) => {\n const f = this.top;\n if (f === null) return fn();\n f.untracked++;\n try {\n return fn();\n } finally {\n f.untracked--;\n }\n },\n $eqIndex: (path: string, level = 1) => {\n const row = rowAt(this.ctx, level);\n if (row === null) raise(M.EqIndexNoRow, [path]);\n const source = this.pattern(path);\n // a getter (or a path under one) changes without a write: an ordinary tracked read, and the\n // row's index is read as `$1` reads it (a moved row compares again)\n if (source.getter !== null || source.underGetter) {\n this.watchIndex(level);\n return row.index === this.read(source, null);\n }\n const f = this.top;\n if (f !== null) {\n const g = f.getter;\n const watchers = source.eqIndexWatchers ?? (source.eqIndexWatchers = []);\n if (!watchers.some((w) => w.getter === g && w.level === level)) {\n watchers.push({ getter: g, level });\n const listP = g.lists[level]!;\n (listP.eqIndexKeys ?? (listP.eqIndexKeys = [])).push({ source, getter: g });\n }\n }\n return row.index === this.readUntracked(source, null);\n },\n $eq: (path: string, key: unknown) => this.eq(path, key),\n $eqPath: (path: string, keyPath: string) => {\n const kp = this.pattern(keyPath);\n return this.eq(path, this.readUntracked(kp, rowAt(this.ctx, kp.depth)));\n },\n $dependOn: (path: string) => {\n this.resolve(unbound(path), this.ctx);\n if (this.top !== null && this.top.untracked === 0) this.track(this.rp!, this.rr, this.top);\n },\n $getAll: (path: string, indexes?: number[]) => this.getAll(path, indexes),\n $setAll: (path: string, indexes: number[], value: unknown, options?: { spread?: boolean }) =>\n this.setAll(path, indexes, value, options),\n // $resolve(path, indexes) reads; $resolve(path, indexes, value) writes (the argument count decides)\n $resolve: (...args: unknown[]) => {\n const path = unbound(args[0] as string);\n const indexes = (args[1] ?? []) as number[];\n const p = this.pattern(path, true);\n this.checkArity(\"$resolve\", path, p, indexes, true);\n const row = this.rowOf(p, indexes, null);\n if (args.length < 3) return this.read(p, row);\n this.write(p, row, args[2]);\n },\n $postUpdate: (path: string) => {\n this.resolve(unbound(path), this.ctx);\n const p = this.rp!;\n const row = this.rr;\n // changed in place: an element is what its array holds now\n if (p.last === WILDCARD && row !== null) {\n row.item = row.list.arr![row.index];\n this.strategy.resetRow(row);\n }\n this.touched(p, row);\n if (row !== null) this.mirror(row, p, undefined, row.item, false);\n // the value before is not known: the `$eq` / `$eqIndex` occurrences under every key change\n if (p.depth === 0) this.rekeyEqUnder(p, undefined, undefined, true);\n this.landed(p, row, undefined, undefined, false);\n },\n };\n\n constructor(target: Record<string, any>, strategy: Strategy) {\n this.strategy = strategy;\n this.patterns = new PatternTable((p) => {\n this.loose.push(p);\n this.onPatternCreated(p);\n });\n this.loadTarget(target);\n const engine = this;\n // the handler reads engine.target, not the proxy's target (a stand-in): a re-set swaps the state.\n // So do `in`, `delete`, `Object.keys(this)`, `instanceof` (the forwarded traps below); a descriptor\n // is reported configurable, as the stand-in has none (a frozen state's would break the invariants)\n const handler: ProxyHandler<object> = {\n getOwnPropertyDescriptor(_t, key) {\n const d = Reflect.getOwnPropertyDescriptor(engine.target, key);\n if (d) d.configurable = true;\n return d;\n },\n get(_t, key, receiver) {\n const t = engine.target;\n if (typeof key === \"symbol\") return Reflect.get(t, key);\n if (key.charCodeAt(0) === 36 /* $ */) return engine.dollar(key);\n if (key.indexOf(\".\") < 0) {\n const p = engine.patterns.peek(key);\n if (p === undefined || p.getter === null) {\n const v = t[key];\n // (a view of the proxy — the readonly createStateAsync's — gets it as it is)\n if (typeof v === \"function\") return (receiver === engine.proxy && engine.bound?.(v)) || v;\n }\n // a known top-level key: no path to parse\n if (p !== undefined && p.depth === 0) return engine.read(p, null);\n }\n engine.resolve(key, engine.ctx);\n return engine.read(engine.rp!, engine.rr);\n },\n set(_t, key, value) {\n if (typeof key === \"symbol\") return Reflect.set(engine.target, key, value);\n engine.resolve(unbound(key), engine.ctx);\n engine.write(engine.rp!, engine.rr, value);\n return true;\n },\n };\n for (const trap of [\"has\", \"ownKeys\", \"deleteProperty\", \"defineProperty\", \"getPrototypeOf\"]) {\n (handler as any)[trap] = (_t: object, ...a: unknown[]) => (Reflect as any)[trap](engine.target, ...a);\n }\n this.proxy = new Proxy({}, handler);\n }\n\n // ---------------------------------------------------------------- patterns\n\n /**\n * The pattern of `path`, pinned: whoever asks keeps it (a binding, a list, an add-on). `loose`: a\n * path read or written (the proxy, `$resolve`, `$getAll`), swept once it holds nothing.\n */\n pattern(path: string, loose?: boolean): Pattern {\n const p = this.patterns.get(path);\n if (!loose) p.pinned = true;\n return p;\n }\n\n private registerAccessors(target: object): void {\n const seen = new Set<string>();\n for (let o: object | null = target; o !== null && o !== Object.prototype; o = Object.getPrototypeOf(o)) {\n for (const key of Object.getOwnPropertyNames(o)) {\n if (seen.has(key)) continue;\n seen.add(key);\n const d = Object.getOwnPropertyDescriptor(o, key)!;\n if (d.get === undefined && d.set === undefined) continue;\n const p = this.pattern(key);\n p.getter = d.get ?? null;\n p.setter = d.set ?? null;\n if (p.getter !== null && p.depth > 0) p.slot = this.slotCount++;\n }\n }\n // accessors registered after their descendants were created: recompute\n for (const p of this.patterns.all()) this.onPatternCreated(p);\n }\n\n private onPatternCreated(p: Pattern): void {\n // (the recursion add-on makes its `**` templates without this, while the state registers)\n if (p.path.includes(\"**\")) recursionUnsupported(p.path);\n // a path through an object's prototype would read and write every object's (once per path)\n if (p.last === \"__proto__\" || p.last === \"prototype\") raise(M.UnsafeSegment, [p.path]);\n const parent = p.parent;\n p.underGetter = parent !== null && p.last !== WILDCARD && parent.depth === p.depth &&\n (parent.getter !== null || parent.underGetter);\n if (p.getter === null) this.markupAccessor(p);\n }\n\n /**\n * Markup names two things the tree does not hold, as `this[...]` reads them: an explicit index\n * (`items.0.v`, the row at that index now) and a loop index (`items.*.$1`, `$1` in a row).\n * Their patterns (only markup makes them: the proxy parses an index into a row) read — and an\n * index path writes — as the proxy resolves them, so the reads are tracked like a getter's.\n * Where a number is a key of an object (`sales.2024.total`), the path resolves to the pattern\n * itself (rowOf): it is read and written through its parent.\n */\n private markupAccessor(p: Pattern): void {\n const path = p.path;\n const last = p.last;\n if (INDEX_PARAM.test(last)) {\n p.getter = function (this: any) {\n return this[last];\n };\n } else {\n const segs = path.split(\".\");\n // (a leading numeric segment is a root key, not an index: parsePath)\n const i = segs.findIndex((s, j) => j > 0 && s.charCodeAt(0) >= 48 && s.charCodeAt(0) <= 57);\n // none, or a `*` after it: a row of a list over the index path (`for: groups.0.items`) reads its\n // own item, and a write through the index reaches it as a list with the same array (mirror)\n if (i < 0 || segs.indexOf(WILDCARD, i) >= 0) return;\n // (the parent read from the context row: the occurrence's, the setter's — at p.depth)\n p.getter = () => {\n this.resolve(path, this.ctx);\n if (this.rp !== p) return this.read(this.rp!, this.rr);\n return (this.read(p.parent!, this.ctx) as any)?.[last];\n };\n p.setter = (v: unknown) => {\n this.resolve(path, this.ctx);\n if (this.rp !== p) return this.write(this.rp!, this.rr, v);\n const o = this.read(p.parent!, this.ctx) as any;\n if (o == null) raise(M.ParentNotObject, [path, o]);\n o[last] = v;\n };\n }\n p.markup = true;\n if (p.depth > 0) p.slot = this.slotCount++;\n }\n\n // ---------------------------------------------------------------- lists\n\n /** The list of list pattern `p` in `row` (null: a root list), made on first use, synced. */\n childList(row: StateRow | null, p: Pattern): StateList {\n const m = row === null ? this.rootLists : (row.children ??= new Map());\n let l = m.get(p);\n if (l === undefined) m.set(p, (l = new StateList(p, row)));\n // (the list holds it: a path's read made it loose, `users.3.name` through `users`)\n p.pinned = true;\n this.sync(l);\n return l;\n }\n\n /** Syncs `l`; a failure (a missing key, a getter that throws) is its for binding's, and it keeps its rows. */\n private trySync(l: StateList): void {\n try {\n this.sync(l);\n } catch (error) {\n this.failAt(error, l.pattern.path, l.view?.anchor ?? null, \"for\");\n }\n }\n\n /** Reconciles a list's rows with the current value of its pattern. */\n sync(l: StateList): void {\n const value = this.readUntracked(l.pattern, l.parentRow);\n const before = l.arr;\n if (value === before) return;\n // out of the lists over its array before (filed again under the new one below)\n this.unfile(l);\n const old = reconcile(l, value, this);\n if (old === null) return;\n // filed under its array: lists that share an array mirror writes\n // (a value that is not an array reconciles against a stand-in: nothing to share)\n if (l.arr === value) {\n const same = upsert(this.listsByArray, value as unknown[], newArray<StateList>);\n same.push(l);\n // (the rows it kept are up to date: a write into an object reached every list showing it, F26)\n if (same.length > 1) for (const x of same) x.shared = true;\n }\n hooks.listSynced?.(this, l, old);\n if ((l.view !== null || l.extra !== null) && !l.queued) {\n l.queued = true;\n this.dirtyLists.push(l);\n this.schedule();\n }\n const keys = l.pattern.eqIndexKeys;\n if (keys !== null) {\n for (const { source, getter } of keys) {\n const sel = this.readUntracked(source, null) as number;\n const before = old[sel];\n const after = l.rows[sel];\n if (before === after) continue;\n if (before !== undefined && before.alive) this.invalidateUnder(getter, before);\n if (after !== undefined) this.invalidateUnder(getter, after);\n }\n }\n }\n\n indexChanged(row: StateRow): void {\n this.strategy.onIndexChange(this, row);\n }\n\n rowRemoved(row: StateRow): void {\n row.alive = false;\n const subs = row.eqSubs;\n if (subs !== null) {\n for (const e of subs) unsubEq(e.source, e.key, e.sub);\n row.eqSubs = null;\n }\n // the rows of its nested lists go with it, and the lists leave the ledger of their arrays\n if (row.children !== null) {\n for (const l of row.children.values()) {\n this.unfile(l);\n for (const r of l.rows) this.rowRemoved(r);\n }\n }\n }\n\n /** Takes `l` out of the lists over its array; one left alone with it no longer mirrors. */\n private unfile(l: StateList): void {\n const was = this.listsByArray.get(l.arr!);\n if (was === undefined) return;\n was.splice(was.indexOf(l) >>> 0, 1);\n l.shared = false;\n if (was.length === 1) was[0].shared = false;\n }\n\n // ---------------------------------------------------------------- resolve / read\n\n /** Splits a concrete path into (pattern, row) — written to this.rp / this.rr. */\n resolve(path: string, ctx: StateRow | null): void {\n const parsed = parsePath(path);\n const p = (this.rp = this.pattern(parsed.pattern, true));\n const idx = parsed.indexes;\n this.rr = p.depth === 0 ? null : idx === null ? ctxRow(ctx, p, p.depth) : this.rowOf(p, idx, ctx, path);\n }\n\n /**\n * The row at p.depth addressed by `idx` (one index per `*`; -1 takes the one of `ctx`). The pattern\n * it is at goes to this.rp — set last: finding the row can sync a list over a getter, whose\n * evaluation resolves paths too. An index of `path` (the proxy's) into an object that is not an\n * array (`sales.2024.total`) is a key: the pattern keeps it as written (into null or a string, it\n * has no row).\n */\n private rowOf(p: Pattern, idx: readonly number[], ctx: StateRow | null, path?: string): StateRow | null {\n let row: StateRow | null = null;\n for (let k = 1, j = 0, v; k <= p.depth; k++) {\n const listP = p.lists[k]!;\n const list = this.childList(row, listP);\n let i = idx[j++];\n if (i < 0) i = ctxRow(ctx, p, k)?.index ?? -1;\n else if (path && list.arr === EMPTY && Object((v = this.readUntracked(listP, row))) === v) {\n const segs = p.path.split(\".\");\n const n = listP.path.split(\".\").length;\n segs[n] = path.split(\".\")[n];\n p = this.pattern(segs.join(\".\"), true);\n k--;\n continue;\n }\n row = list.rows[i] ?? null;\n if (row === null) break;\n }\n this.rp = p;\n return row;\n }\n\n /** Raw data read (no getter, no tracking). `row` is the row at p.depth. */\n readData(p: Pattern, row: StateRow | null): unknown {\n return p.depth === 0 ? dig(this.target, p.tail) : row === null ? undefined : dig(row.item, p.tail);\n }\n\n /** Tracked read. `row` is the row at p.depth (null at the root). */\n read(p: Pattern, row: StateRow | null): unknown {\n const f = this.top;\n if (f !== null && f.untracked === 0) this.track(p, row, f);\n if (p.getter !== null) return this.strategy.readGetter(this, p, row);\n if (p.underGetter) {\n const parent = this.read(p.parent!, row) as any;\n return parent == null ? undefined : parent[p.last];\n }\n // (`then` / `toJSON` are probes — await, JSON.stringify — not reads of the state: undefined)\n if (p.parent === null && !(p.last in this.target) && !this.dropped.has(p.last) && p.last !== \"then\" && p.last !== \"toJSON\") {\n raise(M.PathMissing, [p.path], p.last, Object.keys(this.target));\n }\n return this.readData(p, row);\n }\n\n readUntracked(p: Pattern, row: StateRow | null): unknown {\n const f = this.top;\n if (f === null) return this.read(p, row);\n f.untracked++;\n try {\n return this.read(p, row);\n } finally {\n f.untracked--;\n }\n }\n\n private track(p: Pattern, row: StateRow | null, f: Frame): void {\n const g = f.getter;\n p.addDependent(g);\n // a root getter's reads (once each, but around a nested one): what it no longer reads goes (prune)\n if (g.depth === 0) {\n if (p.mark !== f.epoch) {\n p.mark = f.epoch;\n f.reads.push(p);\n }\n } else if (p.depth > 0 && rowAt(row, Math.min(p.depth, g.depth)) !== rowAt(f.row, Math.min(p.depth, g.depth))) {\n (g.crossSources ?? (g.crossSources = new Set())).add(p);\n }\n }\n\n /** Evaluates a getter occurrence with dependency tracking. Caching is the strategy's. */\n evalGetter(g: Pattern, row: StateRow | null): unknown {\n // frames are reused by depth: an evaluation allocates nothing of its own\n for (let i = 0; i < this.depthNow; i++) {\n const f = this.frames[i];\n if (f.getter === g && f.row === row) raise(M.GetterCycle, [g.path]);\n }\n if (this.depthNow >= MAX_GETTER_DEPTH) raise(M.GetterDepth, [g.path]);\n const depth = this.depthNow++;\n this.readonlyDepth++;\n const frame = (this.frames[depth] ??= { getter: g, row, untracked: 0, epoch: 0, reads: [] });\n frame.getter = g;\n frame.row = row;\n frame.untracked = 0;\n frame.epoch = ++evals;\n frame.reads.length = 0;\n const outer = this.top;\n this.top = frame;\n const prev = this.ctx;\n this.ctx = row;\n try {\n const v = g.getter!.call(this.proxy);\n if (g.depth === 0) this.prune(g, frame);\n return v;\n } finally {\n this.readonlyDepth--;\n this.depthNow--;\n this.top = outer;\n this.ctx = prev;\n frame.row = null;\n }\n }\n\n /**\n * A root getter evaluated (without throwing): the top-level sources it did not read this time are no\n * longer its sources. Its one occurrence is the whole getter, so what it reads is what it depends on\n * (a row getter's sources stay the union over its rows). A key built from data it read before\n * (`this[\"users.\" + this.selectedId]`) then holds nothing, and is swept. One holding an array stays:\n * a write into an object that array shares with the one the getter returns reaches the rows of the\n * list over the getter through it (mirror — F26, 3.x #362).\n */\n private prune(g: Pattern, f: Frame): void {\n const e = f.epoch;\n for (const s of f.reads) s.mark = e;\n g.sources = g.sources.filter((s) => s.mark === e || s.depth > 0 ||\n (!s.underGetter && Array.isArray(s.getter !== null ? s.rootValue : this.readData(s, null))) || this.unlink(s, g));\n }\n\n /** `getter` reads `s` no more (its side is the caller's): `s` may hold nothing now. False (filtered out). */\n private unlink(s: Pattern, getter: Pattern): false {\n s.dropDependent(getter);\n this.loose.push(s);\n return false;\n }\n\n /**\n * After a drain: the patterns only a path made that hold nothing now leave the table, so it grows\n * with the state's shape, not with every key a path was ever built with. A pattern stays while it\n * is pinned (Engine.pattern: `$eqIndex`'s source among them), at the top level (the state's own\n * keys), has children, is read by a getter, is `$eq`'s source, or has an accessor that is not the\n * engine's own for an index path at the top level (one in a row has a cache slot).\n */\n private sweep(): void {\n for (let c = this.loose; c.length > 0; c = this.loose) {\n this.loose = [];\n const parents = new Set<Pattern>();\n for (const p of c) {\n if (p.pinned || p.dead || p.parent === null || p.children.length > 0 || p.dependents.length > 0 ||\n (p.getter !== null && !(p.markup && p.slot < 0)) || p.eqSubs !== null) continue;\n p.dead = true;\n this.patterns.drop(p);\n parents.add(p.parent);\n // an index path's accessor read its parent\n for (const s of p.sources) this.unlink(s, p);\n }\n for (const q of parents) if (!(q.children = q.children.filter((x) => !x.dead)).length) this.loose.push(q);\n }\n }\n\n /** The getter evaluating now reads the index of its row at level `n`: a move of that row re-evaluates it. */\n private watchIndex(n: number): void {\n const f = this.top;\n if (f !== null && f.untracked === 0) {\n const g = f.getter;\n const listP = g.lists[n];\n if (listP) {\n const w = listP.indexWatchers ?? (listP.indexWatchers = []);\n if (!w.includes(g)) w.push(g);\n }\n }\n }\n\n private dollar(key: string): unknown {\n const c = key.charCodeAt(1);\n if (c >= 48 && c <= 57) {\n const n = key.length === 2 ? c - 48 : INDEX_PARAM.test(key) ? +key.slice(1) : 0;\n if (n < 1 || n > MAX_INDEX_PARAM) {\n raise(M.IndexParamRange, [key]);\n }\n this.watchIndex(n);\n return rowAt(this.ctx, n)?.index;\n }\n const fn = this.api[key];\n if (fn !== undefined) return fn;\n // (the 3.x names 4.0 removed, $trackDependency and $untrackDependency, are the diagnostics add-on's)\n switch (key) {\n case \"$stateElement\":\n return this.element;\n case \"$command\":\n return this.commands;\n }\n return hooks.dollar?.(this, key);\n }\n\n /**\n * `$eq(path, key)`: is the value of `path` equal to `key`? Inside a getter the occurrence\n * subscribes under `key` instead of depending on `path`: a write to `path` re-evaluates\n * only the occurrences keyed under its old and its new value. A `path` that is a getter\n * (or under one) changes without a write, so it falls back to an ordinary tracked read.\n */\n private eq(path: string, key: unknown): boolean {\n this.resolve(path, this.ctx);\n const source = this.rp!;\n const row = this.rr;\n if (source.getter !== null || source.underGetter || source.depth > 0) return sameValueZero(this.read(source, row), key);\n const f = this.top;\n if (f !== null && f.untracked === 0) this.subscribeEq(source, key, f);\n return sameValueZero(this.readUntracked(source, null), key);\n }\n\n /**\n * Subscribes the occurrence evaluating in `f` under `key`. A key it subscribed in an earlier\n * evaluation and not in this one moved; one of this evaluation stays (`$eq(p, a) || $eq(p, b)`).\n */\n private subscribeEq(source: Pattern, key: unknown, f: Frame): void {\n const getter = f.getter;\n const row = f.row;\n const list = row === null ? this.rootEqSubs : (row.eqSubs ?? (row.eqSubs = []));\n for (let i = 0; i < list.length; i++) {\n const e = list[i];\n if (e.sub.getter !== getter || e.source !== source) continue;\n if (sameValueZero(e.key, key)) {\n e.epoch = f.epoch;\n return;\n }\n if (e.epoch !== f.epoch) {\n unsubEq(source, e.key, e.sub);\n list.splice(i--, 1);\n }\n }\n const sub: EqSub = { getter, row };\n upsert((source.eqSubs ??= new Map()), key, newSet<EqSub>).add(sub);\n list.push({ source, key, sub, epoch: f.epoch });\n }\n\n /**\n * A root write to `p` (or an object above a `$eq` / `$eqIndex` source): re-key every source at or\n * under it. `all` (`$postUpdate`, which knows no value before): every key.\n */\n private rekeyEqUnder(p: Pattern, before: unknown, after: unknown, all?: boolean): void {\n this.forSubtree(p, (q) => {\n const map = q.eqSubs;\n if (map === null && q.eqIndexWatchers === null) return;\n const rest = q === p ? [] : q.path.slice(p.path.length + 1).split(\".\");\n const b = dig(before, rest);\n const a = dig(after, rest);\n if (q.eqIndexWatchers !== null) this.rekeyEqIndex(q, b, a, all);\n // the occurrences keyed under the value before and the value after\n if (map !== null) for (const k of all ? map.keys() : [b, a]) {\n const set = map.get(k);\n if (set === undefined) continue;\n for (const sub of set) {\n if (sub.row !== null && !sub.row.alive) {\n unsubEq(q, k, sub);\n continue;\n }\n this.strategy.invalidate(this, sub.getter, sub.row);\n }\n }\n });\n }\n\n // ---------------------------------------------------------------- write\n\n /**\n * `occurrence`: an event-semantics write, applied even when equal to the current value.\n * `element`: an element wrote it back (a two-way input, a wc-bindable event), not code.\n */\n write(p: Pattern, row: StateRow | null, value: unknown, occurrence = false, element = false): void {\n if (this.readonlyDepth > 0) raise(M.Readonly);\n if (element || this.feeding > 0) this.fedBack = true;\n else this.codeWrote = true;\n if (hooks.beforeWrite?.(this, p, row, value, element)) return;\n // a setter's write is not a data write: the add-ons hear of it without old and new values\n if (p.setter !== null) {\n // a setter that throws after it wrote: what it wrote still lands (3.x #361), and the error\n // propagates. One that throws before writing anything lands as well, as one that returns\n // without writing does (3.x notifies in `finally` too): `$watch` hears of it, a getter recomputes\n try {\n this.callAt(p.setter, row, [value]);\n } finally {\n this.landed(p, row, undefined, undefined, false, element);\n }\n return;\n }\n if (p.getter !== null) raise(M.GetterWithoutSetter, [p.path]);\n if (p.depth > 0 && row === null) raise(M.NoRow, [p.path]);\n // under a getter, the value before is read through it (the data has no such path)\n const old = p.underGetter ? this.readUntracked(p, row) : this.readData(p, row);\n if (!occurrence && this.guard && Object.is(old, value) && Object(value) !== value) return;\n if (p.last === WILDCARD) {\n // element write: the position keeps its row, the row takes the new value\n const r = row!;\n (r.list.arr as unknown[])[r.index] = value;\n r.item = value;\n this.strategy.resetRow(r);\n } else {\n const parent = (p.tail.length === 1\n ? (p.depth === 0 ? this.target : row!.item)\n : this.readUntracked(p.parent!, row)) as any;\n if (parent == null) raise(M.ParentNotObject, [p.path, parent]);\n parent[p.last] = value;\n }\n this.syncListsUnder(p, row);\n if (row !== null) this.mirror(row, p, old, value);\n if (p.depth === 0) this.rekeyEqUnder(p, old, value);\n this.landed(p, row, old, value, true, element);\n }\n\n /** The lists over `l`'s array now (`l` among them), none of a removed row. */\n private sharing(l: StateList): StateList[] {\n return (this.listsByArray.get(l.arr!) ?? []).filter((m) => m.arr === l.arr && (m.parentRow === null || m.parentRow.alive));\n }\n\n /**\n * A write into row `row` of a list whose array another list has too (`for: shown` over a getter\n * returning `todos`, `for: groups.0.items`): the other list's row at the same position shows it.\n *\n * A write into the row's object (not the element) reaches it wherever else it is (F26, `get\n * shown()` filtering `todos`). From the array holding it (the list's own, or one its getter read\n * at a data path), the write goes to the getters that read that array and returned one holding the\n * object (a filter, a sort, a slice: evaluated again), on down their dependents, and to the rows\n * holding the object in the lists over those arrays. A getter whose array does not hold the object\n * is not reached: it read the array, not the object (the dependency boundary).\n */\n private mirror(row: StateRow, p: Pattern, old: unknown, value: unknown, direct = true): void {\n const l = row.list;\n // another list has its array, or it is over a getter or a getter reads it: its object may be in\n // another array too. A plain list pays these checks only\n if (!l.shared && l.pattern.getter === null && !l.pattern.dependents.length) return;\n const o = row.item;\n const suffix = p.path.slice(l.pattern.path.length + 2);\n const land = (m: StateList, r: StateRow | undefined): void => {\n if (r === undefined || r === row) return;\n const mp = this.pattern(`${m.pattern.path}.*${suffix}`, true);\n if (suffix === \"\") {\n r.item = value;\n this.strategy.resetRow(r);\n }\n if (direct) this.syncListsUnder(mp, r);\n else this.touched(mp, r);\n this.landed(mp, r, old, value, direct);\n };\n for (const m of this.sharing(l)) land(m, m.rows[row.index]);\n if (suffix === \"\") return;\n // (a leaf write: the row's item is an object. The lists over its own array were reached above)\n const seen = new Set<unknown>([l.arr]);\n const has = (a: unknown): a is unknown[] => Array.isArray(a) && a.includes(o);\n const down = (arr: unknown, deps: Pattern[]): void => {\n if (!seen.has(arr) && seen.add(arr)) for (const m of this.listsByArray.get(arr as unknown[]) ?? []) for (const r of m.rows) if (r.item === o) land(m, r);\n // each getter once (a cycle across evaluations ends). One passing the array on (`get shown()\n // { return this.todos }`) is not evaluated again: the lists over it were reached already. One\n // reached before (earlier in the batch, or just now through a getter it reads) is evaluated again\n // in the drain, its list synced then: the rows it keeps are those its list shows now\n for (const g of deps) {\n let v = g.rootValue;\n const stale = v === DIRTY;\n if (stale) v = this.rootLists.get(g)?.arr;\n if ((stale || has(v)) && !seen.has(g.dependents) && seen.add(g.dependents)) {\n if (!stale && v !== arr) this.strategy.invalidate(this, g, null);\n down(v, g.dependents);\n }\n }\n };\n const up = (g: Pattern): void => {\n for (const s of g.sources) {\n if (seen.has(s) || !seen.add(s)) continue;\n if (s.getter !== null) up(s);\n else if (!s.underGetter) {\n const a = this.readData(s, null);\n if (has(a)) down(a, s.dependents);\n }\n }\n };\n if (l.pattern.getter !== null) up(l.pattern);\n else down(l.arr!, l.pattern.dependents);\n }\n\n /**\n * `$postUpdate`: what is at `p` changed in place. Its lists are synced as a write syncs them, and\n * their rows (and the rows of the lists over the same arrays) show it again: a write reaches a\n * row's bindings through the row it replaced, an in-place change through none.\n */\n private touched(p: Pattern, row: StateRow | null): void {\n this.forListsUnder(p, row, (l) => {\n this.sync(l);\n for (const m of l.shared ? this.sharing(l) : [l]) {\n const e = this.pattern(`${m.pattern.path}.*`);\n for (const r of m.rows) {\n this.enqueueBound(e, r);\n this.touched(e, r);\n }\n }\n });\n }\n\n private syncListsUnder(p: Pattern, row: StateRow | null): void {\n const ls = row === null ? this.rootLists : row.children;\n if (ls !== null) for (const l of ls.values()) if (l.pattern.isUnder(p)) this.sync(l);\n }\n\n /** The lists of `row` (the root lists at null) whose pattern is `p` or under it. */\n private forListsUnder(p: Pattern, row: StateRow | null, fn: (l: StateList) => void): void {\n const ls = row === null ? this.rootLists : row.children;\n if (ls !== null) for (const l of ls.values()) if (l.pattern.isUnder(p)) fn(l);\n }\n\n /**\n * `$eqIndex(source, level)` compares the index of the row at `level`: when `source` changes, the\n * getter's occurrences under the rows at that level with the old or the new index change (`all`:\n * under every row).\n */\n private rekeyEqIndex(source: Pattern, before: unknown, after: unknown, all?: boolean): void {\n for (const { getter, level } of source.eqIndexWatchers!) {\n this.forAllLists(getter.lists[level]!, (l) => {\n for (const k of all ? l.rows.keys() : [before, after]) {\n const r = typeof k === \"number\" ? l.rows[k] : undefined;\n if (r !== undefined) this.invalidateUnder(getter, r);\n }\n });\n }\n }\n\n /** Invalidates getter `g`'s occurrences at or under `row` (row.depth <= g.depth). */\n private invalidateUnder(g: Pattern, row: StateRow): void {\n if (row.list.depth === g.depth) this.strategy.invalidate(this, g, row);\n else this.forRowsUnder(row, g, (r) => this.strategy.invalidate(this, g, r));\n }\n\n /** A write landed at (p, row): the add-ons hear of it, then its dependents. */\n private landed(p: Pattern, row: StateRow | null, old: unknown, value: unknown, direct: boolean, element?: boolean): void {\n hooks.written?.(this, p, row, old, value, direct, element);\n this.changed(p, row);\n }\n\n changed(p: Pattern, row: StateRow | null): void {\n this.strategy.onWrite(this, p, row);\n this.schedule();\n }\n\n /**\n * One listener per event type on the root, dispatching to the delegated element handlers.\n * Returns the property the element's handler is stored under (one symbol per engine and\n * type, so two engines never run each other's handlers).\n */\n delegate(type: string): symbol {\n const known = this.delegated.get(type);\n if (known !== undefined) return known;\n const key = Symbol(`wcs.on${type}`);\n this.delegated.set(type, key);\n const root = this.root!;\n const blockKey = this.blockKey;\n root.addEventListener(type, (e) => {\n for (let n = e.target as any; n !== null && n !== root; n = n.parentNode) {\n // a handler stored on the element (a root-level one, or one a block pinned)\n const fn = n[key];\n if (fn !== undefined) {\n fn(e);\n if (e.cancelBubble) return;\n }\n // a block's top node: the handlers of the block's elements the event passed\n const block = n[blockKey];\n if (block !== undefined && block.alive && block.dispatch(type, e)) return;\n }\n });\n return key;\n }\n\n // ---------------------------------------------------------------- re-set\n\n /**\n * `setInitialState` on an initialized element: the state is replaced whole and every\n * binding is re-applied to it before this returns. Not a write: no `$renderedCallback`.\n * Everything learned from the old state goes (accessors, dependencies, caches, `$eq`\n * keys); rows are kept where their list's array is the same instance.\n */\n reset(target: Record<string, any>): void {\n const old = this.target;\n // a key the old state had (or an earlier re-set dropped) and this one lacks is empty (B8), as a\n // missing path under a key is — not a key never declared, which fails on read: its bindings, lists\n // and getters read undefined, until it is written. Its accessors too: those on a class state's\n // prototype, which for…in does not list, are the top-level patterns with a getter\n const dropped = this.dropped;\n for (const p of this.patterns.all()) if (p.parent === null && p.getter !== null) dropped.add(p.last);\n this.loadTarget(target);\n for (const k in old) if (k[0] !== \"$\") dropped.add(k);\n for (const k of dropped) if (k in target) dropped.delete(k);\n for (const bs of this.rootBindings.values()) for (const b of bs) this.enqueue(b);\n for (const l of this.rootLists.values()) this.resetList(l);\n this.rendered = null;\n try {\n this.drain();\n } finally {\n this.watchRendered();\n }\n hooks.element?.(this, \"reset\");\n }\n\n /** Takes in a state object: at construction, and on a re-set (everything learned from the old one goes). */\n private loadTarget(target: Record<string, any>): void {\n for (const [key, feature] of DECLARATIONS) if (target[key] !== undefined) requireFeature(feature, key);\n // (the 3.x declarations 4.0 removed — $scan, $streams, $updatedCallback — are the diagnostics add-on's)\n const f = target.$features;\n if (f !== undefined) {\n if (!Array.isArray(f)) raise(M.FeaturesNotArray);\n for (const name of f) requireFeature(name, \"$features\");\n }\n // an options object: null and an array are not one (as for bootstrapState's options)\n const c = target.$behavior === undefined ? {} : target.$behavior;\n if (typeof c !== \"object\" || !c || Array.isArray(c)) raise(M.OptionInvalid, [\"state\", \"$behavior\"]);\n for (const key in c) if (!BEHAVIOR_KEYS.includes(key) || typeof c[key] !== \"boolean\") raise(M.OptionInvalid, [\"$behavior\", key]);\n const [mustache, guard, directional] = BEHAVIOR_KEYS.map((key) => c[key] ?? true);\n // a re-set keeps the engine, and what was built by the old options\n if (this.target !== undefined && (mustache !== this.mustache || guard !== this.guard || directional !== this.directional)) raise(M.BehaviorChanged);\n // (read before anything is taken in: a malformed declaration leaves a re-set's old state in place)\n const commands = commandNamespace(target, this.commands);\n const events = eventTokens(target, this.deliverFn);\n this.mustache = mustache;\n this.guard = guard;\n this.directional = directional;\n hooks.declare?.(this, target);\n this.target = target;\n this.slotCount = 0;\n for (const p of this.patterns.all()) p.forget();\n this.rootEqSubs.length = 0;\n this.registerAccessors(target);\n this.commands = commands;\n this.events = events;\n }\n\n private resetList(l: StateList): void {\n // a list that cannot be read (its getter throws) fails alone: the re-set goes on (and ends with its hook)\n this.trySync(l);\n const element = this.pattern(`${l.pattern.path}.*`);\n for (const row of l.rows) {\n row.cache = null;\n row.eqSubs = null;\n this.enqueueBound(element, row);\n if (row.children !== null) for (const c of row.children.values()) this.resetList(c);\n }\n }\n\n // ---------------------------------------------------------------- tokens\n\n /** The loop indexes of `row`, outermost first (`$1`, `$2`, …). */\n indexesOf(row: StateRow | null): number[] {\n const out: number[] = [];\n for (let r = row; r !== null; r = r.list.parentRow) out.unshift(r.index);\n return out;\n }\n\n /** An element event wired with `eventToken.<prop>: <name>` — the token is resolved at fire time. */\n fireEventToken(name: string, event: Event, row: StateRow | null): void {\n const token = this.events.get(name);\n if (token === undefined) raise(M.EventTokenUndeclared, [name], name, this.events.keys());\n token.emit(event, ...this.indexesOf(row));\n }\n\n /** The `$command.<name>` token (declared in `$commandTokens`). */\n command(name: string): Token {\n const token = this.commands[name];\n if (token === undefined) raise(M.CommandTokenUndeclared, [name], name, Object.keys(this.commands));\n return token;\n }\n\n /** `onclick: $command.<name>` — emits the token with (event, ...listIndexes). */\n emitCommand(name: string, event: Event, row: StateRow | null): void {\n this.command(name).emit(event, ...this.indexesOf(row));\n }\n\n // ---------------------------------------------------------------- methods\n\n invoke(name: string, event: Event, row: StateRow | null): unknown {\n // a dotted name is a path (a volume method lives under its mount path)\n const fn = name.includes(\".\") ? this.readUntracked(this.pattern(name), null) : this.target[name];\n if (typeof fn !== \"function\") raise(M.NotAMethod, [name]);\n return this.callAt(fn, row, [event, ...this.indexesOf(row)]);\n }\n\n /** Calls `fn` on the proxy with the evaluation context at `row`. */\n private callAt(fn: (...args: any[]) => unknown, row: StateRow | null, args: unknown[]): unknown {\n const prev = this.ctx;\n this.ctx = row;\n try {\n return fn.apply(this.proxy, args);\n } finally {\n this.ctx = prev;\n }\n }\n\n // ---------------------------------------------------------------- change walk\n\n /** Queues the bindings on `p` (and patterns under it) in the scope of `row`. */\n enqueueBound(p: Pattern, row: StateRow | null): void {\n // a list over a getter (or under one) is re-synced in the drain: a data write syncs its\n // lists right away, but a getter's value is only known when it is read again\n if (p.getter !== null) {\n const ls = row === null ? this.rootLists : row.children;\n if (ls !== null) {\n for (const l of ls.values()) {\n if (!l.stale && l.pattern.isUnder(p)) {\n l.stale = true;\n this.staleLists.push(l);\n }\n }\n }\n }\n if (row === null) {\n this.forSubtree(p, (q) => {\n const bs = this.rootBindings.get(q);\n if (bs !== undefined) for (const b of bs) this.enqueue(b);\n });\n return;\n }\n const bs = row.bindings;\n if (bs !== null) for (let i = 0; i < bs.length; i++) if (bs[i].pattern.isUnder(p)) this.enqueue(bs[i]);\n // slot bindings of the row's renderings\n const view = row.view;\n if (view !== null && view.slots !== null) view.enqueueSlots(this, p);\n const extra = row.list.extra;\n if (extra !== null) {\n for (const fv of extra) {\n const rv = fv.map!.get(row);\n if (rv !== undefined && rv.slots !== null) rv.enqueueSlots(this, p);\n }\n }\n }\n\n /** Reaches every getter occurrence that read `p` (or a pattern under it) at `row`. */\n walkDependents(p: Pattern, row: StateRow | null, visit: Visit): void {\n this.forSubtree(p, (q) => {\n const deps = q.dependents;\n for (let i = 0; i < deps.length; i++) {\n const g = deps[i];\n if (g.depth === 0) this.visitGetter(g, null, visit);\n else if (row === null || q.depth === 0 || g.lists[1] !== q.lists[1] || (g.crossSources !== null && g.crossSources.has(q))) {\n this.forAllRows(g.lists[g.depth]!, (r) => this.visitGetter(g, r, visit));\n } else if (g.depth <= q.depth) {\n const r = rowAt(row, g.depth);\n if (r !== null) this.visitGetter(g, r, visit);\n } else this.forRowsUnder(row, g, (r) => this.visitGetter(g, r, visit));\n }\n });\n }\n\n visitGetter(g: Pattern, row: StateRow | null, visit: Visit): void {\n if (!visit(g, row)) return;\n hooks.getterReached?.(this, g, row);\n this.enqueueBound(g, row);\n this.walkDependents(g, row, visit);\n }\n\n forSubtree(p: Pattern, fn: (q: Pattern) => void): void {\n fn(p);\n const c = p.children;\n for (let i = 0; i < c.length; i++) this.forSubtree(c[i], fn);\n }\n\n /** Every row of every list instance of list pattern `listP`. */\n forAllRows(listP: Pattern, fn: (row: StateRow) => void): void {\n this.forAllLists(listP, (l) => {\n for (const r of l.rows) fn(r);\n });\n }\n\n /** Every list instance of list pattern `listP`. */\n private forAllLists(listP: Pattern, fn: (l: StateList) => void): void {\n if (listP.depth === 0) {\n const l = this.rootLists.get(listP);\n if (l !== undefined) fn(l);\n return;\n }\n this.forAllRows(listP.lists[listP.depth]!, (parent) => {\n const l = parent.children?.get(listP);\n if (l !== undefined) fn(l);\n });\n }\n\n /** Rows at g.depth at or under `row` (row.depth <= g.depth). */\n forRowsUnder(row: StateRow, g: Pattern, fn: (row: StateRow) => void): void {\n if (row.list.depth === g.depth) return fn(row);\n const l = row.children?.get(g.lists[row.list.depth + 1]!);\n if (l !== undefined) for (const r of l.rows) this.forRowsUnder(r, g, fn);\n }\n\n // ---------------------------------------------------------------- bindings & drain\n\n /** Registers a binding where a change of its location finds it: its row, or the root table. */\n register(b: Binding): void {\n const row = b.row;\n if (row !== null) {\n (row.bindings ?? (row.bindings = [])).push(b);\n return;\n }\n upsert(this.rootBindings, b.pattern, newSet<Binding>).add(b);\n }\n\n unregister(b: Binding): void {\n const row = b.row;\n if (row === null) {\n this.rootBindings.get(b.pattern)?.delete(b);\n return;\n }\n // a row that left its list takes its registrations with it\n const bs = row.bindings;\n if (row.alive && bs !== null) bs.splice(bs.indexOf(b) >>> 0, 1);\n }\n\n enqueue(b: Binding): void {\n if (b.queued) return;\n b.queued = true;\n this.queue.push(b);\n this.schedule();\n }\n\n schedule(): void {\n if (this.scheduled) return;\n this.scheduled = true;\n queueMicrotask(this.drainFn);\n }\n\n /** Drops the queued work of a cut update loop: what it would have shown waits for the next change. */\n private dropWork(): void {\n for (const b of this.queue) b.queued = false;\n for (const l of this.dirtyLists) l.queued = false;\n for (const l of this.staleLists) l.stale = false;\n this.queue = [];\n this.dirtyLists = [];\n this.staleLists = [];\n this.strategy.dropped(this);\n }\n\n /**\n * Cuts an update loop past `max` (`id`: its message): reported with the paths its queued work\n * would have rendered (the console, and DevTools as `state:render-chain-limit`), then dropped.\n */\n private cutLoop(id: M, max: number): void {\n const paths = [...new Set([...this.queue, ...this.dirtyLists, ...this.staleLists].map((x) => x.pattern.path))];\n console.error(`[@wcstack/state] ${text(id)}`, paths);\n hooks.noticed?.(this, { \"type\": \"state:render-chain-limit\", \"maxDepth\": max, \"paths\": paths });\n this.dropWork();\n }\n\n drain(): void {\n this.scheduled = false;\n // a drain only rendering fed (no write from code since the last) continues a chain: the carried\n // one of a deferred apply, or the task's\n const carried = this.carried;\n this.carried = 0;\n let chain = 0;\n if (!this.fedBack || this.codeWrote) this.unchainFn();\n else if (carried > 0) chain = carried;\n else if ((chain = ++this.chain) === 1) setTimeout(this.unchainFn, 0);\n this.fedBack = this.codeWrote = false;\n if (chain > MAX_RENDER_CHAIN) {\n if (chain === MAX_RENDER_CHAIN + 1) this.cutLoop(M.RenderChain, MAX_RENDER_CHAIN);\n else this.dropWork();\n return;\n }\n this.draining = true;\n try {\n for (let pass = 0; this.queue.length > 0 || this.dirtyLists.length > 0 || this.staleLists.length > 0; pass++) {\n if (pass >= MAX_DRAIN_PASSES) {\n // (once a chain: a reaction that starts the same loop again in each drain is not reported again)\n if (this.unsettled) this.dropWork();\n else this.cutLoop(M.DrainNotSettled, MAX_DRAIN_PASSES);\n this.unsettled = true;\n break;\n }\n const stale = this.staleLists;\n if (stale.length > 0) {\n this.staleLists = [];\n for (const l of stale) {\n l.stale = false;\n this.trySync(l);\n }\n }\n const lists = this.dirtyLists;\n const q = this.queue;\n this.dirtyLists = [];\n this.queue = [];\n // a pass that changes structure — a list's rows, an `if` branch — goes to the page's\n // view-transition arbiter, if any (transition-runner protocol); one that only updates\n // values is applied right here, as with no arbiter (a value change is CSS transitions'\n // job, and a transition per keystroke left the page unclickable — docs/seam-apps.md,\n // router-admin). Queued entries stay marked until applied, so a write meanwhile folds\n // into them\n const apply = (): void => {\n // list views first (they build rows), then bindings\n for (const l of lists) {\n l.queued = false;\n for (const v of [l.view, ...(l.extra ?? [])]) {\n if (v === null || !v.alive) continue;\n // a row that fails to build (a binding refused as it is attached) fails this view\n // alone: the rest of the pass is still applied (nothing stays queued)\n try {\n v.update();\n } catch (error) {\n this.failAt(error, l.pattern.path, v.anchor, \"for\");\n }\n }\n }\n // `if` / `elseif` conditions first: a branch one closes takes its bindings with it, so\n // they are not applied with the value that closes it (a condition over a getter is\n // queued after the bindings on the path it reads — docs/seam-apps.md, router-auth)\n for (let k = 0; k < 2; k++) {\n for (let i = 0; i < q.length; i++) {\n const b = q[i];\n // applied since it was queued (a row slot, when its row was built)\n if (!b.queued || (b.chain === null) === (k === 0)) continue;\n b.queued = false;\n if (b.owner === null || b.owner.alive) this.applyBinding(b);\n }\n }\n // applied later by the arbiter, outside any drain: report its failures now, and the drain\n // what it fed back starts (a write-back, `$renderedCallback`) is the next of this drain's chain\n if (!this.draining) {\n this.report();\n if (this.scheduled) this.carried = chain + 1;\n }\n };\n const pending = lists.length > 0 || q.some((b) => b.chain !== null) ? runTransition(\"state\", apply) : apply();\n if (pending !== undefined) pending.then(undefined, (e) => console.error(e));\n }\n } finally {\n this.draining = false;\n }\n // (writes made while applying are this drain's own passes)\n this.fedBack = this.codeWrote = false;\n this.report();\n hooks.drained?.(this);\n this.sweep();\n // (as is the one a carried drain's reactions start)\n if (carried > 0 && this.scheduled) this.carried = chain + 1;\n }\n\n // ---------------------------------------------------------------- apply, hooks, reports\n\n /** A binding that failed to apply: reported after the drain. */\n fail(error: unknown, b: Binding): void {\n this.errors.push([error, b]);\n }\n\n /**\n * A failure of what has no Binding object, reported like a binding's: a list that failed to sync\n * or render (its `for`), a binding refused as it was attached in a row.\n */\n failAt(error: unknown, path: string, node: Node | null, type: string): void {\n this.fail(error, { pattern: { path }, node, typeName: () => type } as unknown as Binding);\n }\n\n applyBinding(b: Binding): void {\n try {\n b.apply();\n } catch (error) {\n this.errors.push([error, b]);\n return;\n }\n if (this.rendered !== null) this.noteRendered(b.pattern, b.row);\n }\n\n /** Records an applied binding for `$renderedCallback`. */\n noteRendered(p: Pattern, row: StateRow | null): void {\n const list = upsert(this.rendered!, p.path, newArray<number[]>);\n if (row !== null) list.push(this.indexesOf(row));\n }\n\n /** Starts collecting applied paths when the state declares `$renderedCallback`. */\n watchRendered(): void {\n this.rendered = typeof this.target.$renderedCallback === \"function\" ? new Map() : null;\n }\n\n /** `$renderedCallback` for the paths applied since the last report, then binding failures. */\n report(): void {\n const rendered = this.rendered;\n if (rendered !== null && rendered.size > 0) {\n this.rendered = new Map();\n const paths = [...rendered.keys()];\n const indexes: Record<string, number[][]> = {};\n for (const [p, l] of rendered) if (l.length > 0) indexes[p] = l;\n this.feeding++;\n let r: any;\n try {\n r = this.callHook(\"$renderedCallback\", [paths, indexes]);\n } catch (e) {\n console.error(e);\n }\n if (isThenable(r)) {\n r.then(this.renderedFn, (e: unknown) => {\n this.renderedFn();\n console.error(e);\n });\n } else {\n this.feeding--;\n }\n }\n if (this.errors.length === 0) return;\n const errors = this.errors;\n this.errors = [];\n const hook = this.target.$errorCallback;\n for (const [error, binding] of errors) {\n hooks.failed?.(this, error, binding);\n const path = binding.pattern.path;\n const type = binding.typeName();\n if (typeof hook === \"function\") {\n // quoted keys: the author reads them (mangle.mjs shortens the unquoted ones)\n try {\n const r = this.callHook(\"$errorCallback\", [error, { \"path\": path, \"bindingType\": type, \"node\": binding.node }]) as any;\n if (isThenable(r)) r.then(undefined, (e: unknown) => console.error(e));\n } catch (e) {\n console.error(e);\n }\n } else {\n console.error(`[@wcstack/state] ${text(M.BindingFailed, [type, path])}`, error);\n }\n }\n }\n\n /** Runs a lifecycle hook with the writable proxy; returns its result (awaited by the caller or not). */\n callHook(name: string, args: unknown[] = []): unknown {\n const fn = this.target[name];\n return typeof fn === \"function\" ? this.callAt(fn, null, args) : undefined;\n }\n\n // ---------------------------------------------------------------- $getAll / $setAll / $resolve\n\n /** Calls fn for every row at p.depth that matches `indexes` (a prefix over p's wildcards). */\n private forMatches(p: Pattern, indexes: readonly number[], fn: (row: StateRow | null, idx: number[]) => void): void {\n if (p.depth === 0) {\n fn(null, []);\n return;\n }\n const idx: number[] = [];\n const walk = (k: number, parent: StateRow | null): void => {\n const lp = p.lists[k]!;\n // the list itself is read too: a getter over $getAll sees the first row of an empty list\n this.read(lp, parent);\n const list = this.childList(parent, lp);\n const visit = (r: StateRow): void => {\n idx.push(r.index);\n if (k === p.depth) fn(r, idx);\n else walk(k + 1, r);\n idx.pop();\n };\n for (const r of k - 1 < indexes.length ? [list.rows[indexes[k - 1]]] : list.rows) if (r !== undefined) visit(r);\n };\n walk(1, null);\n }\n\n private getAll(path: string, indexes?: number[]): unknown[] {\n const p = this.pattern(path, true);\n if (indexes !== undefined) this.checkArity(\"$getAll\", path, p, indexes, false);\n // by default the loop context, on the wildcard levels the path shares with it\n let idx = indexes;\n if (idx === undefined) {\n idx = [];\n const ctx = this.ctx;\n if (ctx !== null && p.depth > 0) {\n for (let k = 1; k <= p.depth; k++) {\n const r = ctxRow(ctx, p, k);\n if (r === null) break;\n idx.push(r.index);\n }\n if (idx.length === 0) raise(M.GetAllNoCommonLevel, [path]);\n }\n }\n const out: unknown[] = [];\n this.forMatches(p, idx, (row) => out.push(this.read(p, row)));\n return out;\n }\n\n private setAll(path: string, indexes: number[], value: unknown, options?: { spread?: boolean }): number {\n if (!Array.isArray(indexes)) raise(M.SetAllNeedsIndexes, [path]);\n if (this.readonlyDepth > 0) raise(M.Readonly);\n const p = this.pattern(path, true);\n this.checkArity(\"$setAll\", path, p, indexes, false);\n const targets: [StateRow | null, number[]][] = [];\n this.forMatches(p, indexes, (row, idx) => targets.push([row, idx.slice()]));\n const spread = options?.spread === true;\n if (spread && (!Array.isArray(value) || value.length !== targets.length)) {\n raise(M.SetAllSpreadLength, [path, targets.length]);\n }\n let written = 0;\n for (let i = 0; i < targets.length; i++) {\n const [row, idx] = targets[i];\n const v = typeof value === \"function\"\n ? (value as (cur: unknown, ...i: number[]) => unknown)(this.readUntracked(p, row), ...idx)\n : spread ? (value as unknown[])[i] : value;\n if (v === undefined) continue;\n this.write(p, row, v);\n written++;\n }\n return written;\n }\n\n /** `$resolve` takes exactly one index per `*`; `$getAll` / `$setAll` at most one (fewer expands the rest). */\n private checkArity(api: string, path: string, p: Pattern, indexes: readonly number[], exact: boolean): void {\n const n = indexes.length;\n if (n > p.depth || (exact && n < p.depth)) {\n raise(exact ? M.IndexArityExact : M.IndexArityAtMost, [api, path, p.depth, n]);\n }\n }\n}\n"],"mappings":"mMAWO,IAAMA,EAA4BC,OAAOC,IAAI,+BAI7C,SAASC,IACd,IAAMC,EAASC,WAAoBL,GACnC,OAAiB,OAAVI,GAAmC,iBAAVA,EAAsBA,EAA+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C,IAAOG,EAAKmK,GAAOmJ,EAAQzT,GACrBf,EAAqB,mBAAVvF,EACZA,EAAoDmB,KAAKqJ,EAAc5D,EAAGH,MAASmK,GACpFoJ,EAAUha,EAAoBsG,GAAKtG,OAC7B,IAANuF,IACJpE,KAAKuK,EAAM9E,EAAGH,EAAKlB,GACnBgP,IACF,CACA,OAAOA,CACT,CAGQ/I,GAAWjC,EAAa1E,EAAc+B,EAAYsE,EAA4B+O,GACpF,IAAMhL,EAAI/D,EAAQ3E,QACd0I,EAAIrI,EAAEzE,GAAU8X,GAAShL,EAAIrI,EAAEzE,IACjCwB,EAAMsW,UAAgD,CAAC1Q,EAAK1E,EAAM+B,EAAEzE,EAAO8M,GAE/E,UACFiL,OAAAC,OAAAC,OAAAC,OAAApU,OAAAqU,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{e as t}from"./chunk-R5OJ52SF.js";import{b as r}from"./chunk-GGSHXG7N.js";function n(t){r(26,[t])}function e(t){r(27,[t])}function o(t){r(28,[t])}function a(t){r(29,[t])}function f(t){r(30,[t])}function u(t){return!(!t||isNaN(Number(t)))}function i(t,r){return u(t)||e(r),Number(t)}function y(t,r,e){return i(t?.[r]??n(e),e)}function c(t,r){return void 0!==r&&r.length>0?r[0]:t}var s=(t,r)=>({factory:n=>{let e=y(n,0,t);return n=>("number"!=typeof n&&o(t),r(n,e))},arity:[1,1]}),m={eq:{factory:(t,r)=>{let o=t?.[0]??n("eq"),a=c(o,r);return t=>"number"==typeof t?"string"!=typeof a?t===a:(u(o)||e("eq"),t===Number(o)):"string"==typeof t?t===o:t===a},arity:[1,1]},ne:{factory:(t,r)=>{let o=t?.[0]??n("ne"),a=c(o,r);return t=>"number"==typeof t?"string"!=typeof a?t!==a:(u(o)||e("ne"),t!==Number(o)):"string"==typeof t?t!==o:t!==a},arity:[1,1]},not:{factory:()=>t=>!t,arity:[0,0]},lt:s("lt",(t,r)=>t<r),le:s("le",(t,r)=>t<=r),gt:s("gt",(t,r)=>t>r),ge:s("ge",(t,r)=>t>=r),falsy:{factory:()=>t=>!t,arity:[0,0]},truthy:{factory:()=>t=>!!t,arity:[0,0]},boolean:{factory:()=>t=>!!t,arity:[0,0]}},b=!1;function g(){b||(b=!0,t(m))}export{n as a,o as b,a as c,f as d,i as e,y as f,c as g,s as h,m as i,g as j};
|
|
2
|
-
//# sourceMappingURL=chunk-BWGPKDHS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["optionsRequired","fnName","raise","optionMustBeNumber","valueMustBeNumber","valueMustBeDate","valueMustBeArray","validateNumberString","value","isNaN","Number","numberOption","requiredNumberOption","options","index","firstLiteral","opt","literals","length","numeric","name","op","factory","arity","coreFilters","eq","literal","ne","not","lt","le","gt","ge","falsy","truthy","boolean","installed","installCoreFilters","registerFilters","u","y","M","R","m","b","p","l","x","S"],"sources":["../../../src/filters/errorMessages.ts","../../../src/filters/options.ts","../../../src/filters/core.ts"],"sourcesContent":["/**\n * filters/errorMessages.ts — the filters' error messages, ported from `@wcstack/state`\n * (`formats/errorMessages.ts`). Numbered core messages (src/messages.ts): the sentences, the same\n * as the source's, are the diagnostics add-on's.\n */\n\nimport { raise, M } from \"../messages\";\n\n/** The filter requires an option but none was given (the factory-side guard; arity usually fires first). */\nexport function optionsRequired(fnName: string): never {\n raise(M.FilterOptionsRequired, [fnName]);\n}\n\n/** A numeric option is not a number. */\nexport function optionMustBeNumber(fnName: string): never {\n raise(M.FilterOptionNotNumber, [fnName]);\n}\n\n/** The value given to a numeric filter is not a number. */\nexport function valueMustBeNumber(fnName: string): never {\n raise(M.FilterValueNotNumber, [fnName]);\n}\n\n/** The value given to a date filter is not a Date. */\nexport function valueMustBeDate(fnName: string): never {\n raise(M.FilterValueNotDate, [fnName]);\n}\n\n/** The value given to an array filter is not an array. */\nexport function valueMustBeArray(fnName: string): never {\n raise(M.FilterValueNotArray, [fnName]);\n}\n","/**\n * filters/options.ts — option parsing shared by the core set and the formats add-on, ported\n * verbatim from `@wcstack/state` (`formats/builtinFilters.ts`).\n *\n * Numeric options are read **once, when the filter is built**: the checks stay in one place and the\n * `Number()` conversion stays off the apply path.\n */\nimport { optionMustBeNumber, optionsRequired } from \"./errorMessages\";\n\n/** `\"\"` and anything `Number()` cannot read are rejected (so `lt('')` is an error, not `lt(0)`). */\nexport function validateNumberString(value: string): boolean {\n if (!value || isNaN(Number(value))) {\n return false;\n }\n return true;\n}\n\n/** One numeric option, converted: non-numeric → `optionMustBeNumber`. */\nexport function numberOption(value: string, fnName: string): number {\n if (!validateNumberString(value)) {optionMustBeNumber(fnName);}\n return Number(value);\n}\n\n/** A required numeric option: missing → `optionsRequired`, non-numeric → `optionMustBeNumber`. */\nexport function requiredNumberOption(options: readonly string[] | undefined, index: number, fnName: string): number {\n return numberOption(options?.[index] ?? optionsRequired(fnName), fnName);\n}\n\n/**\n * The typed literal of the first argument (requirement B9): an unquoted `true` / `false` / `null` /\n * number arrives typed, a quoted argument as a string. Without literals (tooling calling a factory\n * directly) the raw option text stands in.\n */\nexport function firstLiteral(opt: string, literals: readonly unknown[] | undefined): unknown {\n return literals !== undefined && literals.length > 0 ? literals[0] : opt;\n}\n","/**\n * filters/core.ts — the core filter set (10): the conditions a binding tests, as opposed to the\n * values the formats add-on (`./formats`) computes and shows. Ported from `@wcstack/state`\n * (`formats/builtinFilters.ts`) with the semantics unchanged.\n *\n * - conditions: `eq ne not lt le gt ge truthy falsy boolean`\n *\n * The arithmetic (`add sub mul div mod abs clamp`), conversion (`number string int float`) and\n * missing-value (`defaults coalesce nullIfEmpty`) filters were here up to 4.0.0-rc.3; they are the\n * formats add-on's since, for the core's size target.\n *\n * `installCoreFilters()` puts them in the registry; the engine calls it before it plans bindings\n * (`else:` is built with an injected `not`, so the core set is never optional).\n */\nimport { optionMustBeNumber, optionsRequired, valueMustBeNumber } from \"./errorMessages\";\nimport { firstLiteral, requiredNumberOption, validateNumberString } from \"./options\";\nimport { registerFilters, type FilterDefinition, type FilterFn } from \"./registry\";\n\n/** Equality — compares with the option (a typed literal compares as itself, B9). */\nconst eq = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('eq');\n const literal = firstLiteral(opt, literals);\n return (value: unknown): boolean => {\n if (typeof value === 'number') {\n // A typed literal that is not a string compares as itself (B9): a number is never equal to\n // `true` / `false` / `null`, so `selectedId|eq(null)` is false once the id is a number instead\n // of throwing on every apply. Only an unquoted non-number (`eq(abc)`) still reports the type\n // mismatch, and it has to stay here: `eq` accepts values of any type (`status|eq(active)` is\n // valid), so it cannot be rejected at construction the way `lt` / `add` can.\n if (typeof literal !== 'string') {return value === literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('eq');}\n return value === Number(opt);\n }\n if (typeof value === 'string') {\n return value === opt;\n }\n // Booleans, null and the rest compare with the typed literal: eq(true) matches true (B9)\n return value === literal;\n };\n};\n\n/** Inequality — the negation of `eq`, with the same typing rules (B9). */\nconst ne = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('ne');\n const literal = firstLiteral(opt, literals);\n return (value: unknown): boolean => {\n if (typeof value === 'number') {\n if (typeof literal !== 'string') {return value !== literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('ne');}\n return value !== Number(opt);\n }\n if (typeof value === 'string') {\n return value !== opt;\n }\n return value !== literal;\n };\n};\n\n/**\n * Inverts truthiness (lenient `!value`). `else:` is built as the `if` condition plus an injected\n * `not`, and `if:` coerces with `Boolean()`; a strict `not` made `else:` throw — rendering neither\n * branch — whenever the condition was a falsy non-boolean (`0` / `\"\"` / `undefined` / `null`).\n */\nconst not = (): FilterFn => (value: unknown): boolean => !value;\n\n/**\n * A comparison or arithmetic filter: one numeric option, a number value (`lt` … `ge` here, `add` …\n * `mod` in the formats add-on).\n */\nexport const numeric = (name: string, op: (value: number, opt: number) => unknown): FilterDefinition => ({\n factory: (options: string[]): FilterFn => {\n const opt = requiredNumberOption(options, 0, name);\n return (value: unknown): unknown => {\n if (typeof value !== 'number') {valueMustBeNumber(name);}\n return op(value, opt);\n };\n },\n arity: [1, 1],\n});\n\n/** JavaScript's truthiness, the same as `boolean` (B10). */\nconst truthy = (): FilterFn => (value: unknown): boolean => !!value;\n\n/** JavaScript's falsiness (`!value`: false, null, undefined, 0, -0, 0n, '' and NaN — B10). */\nconst falsy = (): FilterFn => (value: unknown): boolean => !value;\n\nconst boolean = (): FilterFn => (value: unknown): boolean => Boolean(value);\n\n/**\n * The core set: factory and [min, max] argument count (B3 — the same bounds lint uses).\n *\n * The key order is the source's (`builtinFilterMeta`, which lint reads): the did-you-mean\n * suggestion breaks ties by registration order (see `installFormats` for the order the full\n * build registers).\n */\nexport const coreFilters: Readonly<Record<string, FilterDefinition>> = {\n eq: { factory: eq, arity: [1, 1] },\n ne: { factory: ne, arity: [1, 1] },\n not: { factory: not, arity: [0, 0] },\n lt: numeric('lt', (value, opt) => value < opt),\n le: numeric('le', (value, opt) => value <= opt),\n gt: numeric('gt', (value, opt) => value > opt),\n ge: numeric('ge', (value, opt) => value >= opt),\n falsy: { factory: falsy, arity: [0, 0] },\n truthy: { factory: truthy, arity: [0, 0] },\n boolean: { factory: boolean, arity: [0, 0] },\n};\n\nlet installed = false;\n\n/** Puts the core set in the registry. Idempotent; the engine calls it before planning any binding. */\nexport function installCoreFilters(): void {\n if (installed) return;\n installed = true;\n registerFilters(coreFilters);\n}\n"],"mappings":"gFASO,SAASA,EAAgBC,GAC9BC,KAA+B,CAACD,GAClC,CAGO,SAASE,EAAmBF,GACjCC,KAA+B,CAACD,GAClC,CAGO,SAASG,EAAkBH,GAChCC,KAA8B,CAACD,GACjC,CAGO,SAASI,EAAgBJ,GAC9BC,KAA4B,CAACD,GAC/B,CAGO,SAASK,EAAiBL,GAC/BC,KAA6B,CAACD,GAChC,CCrBO,SAASM,EAAqBC,GACnC,SAAKA,GAASC,MAAMC,OAAOF,IAI7B,CAGO,SA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ACX,EAAOQ,IAAQR,GAASQ,GAC3Ce,GAAIZ,EAAQ,KAAM,CAACX,EAAOQ,IAAQR,EAAQQ,GAC1CgB,GAAIb,EAAQ,KAAM,CAACX,EAAOQ,IAAQR,GAASQ,GAC3CiB,MAAO,CAAEX,QAnBG,IAAiBd,IAA6BA,EAmBjCe,MAAO,CAAC,EAAG,IACpCW,OAAQ,CAAEZ,QAvBG,IAAiBd,KAA8BA,EAuBjCe,MAAO,CAAC,EAAG,IACtCY,QAAS,CAAEb,QAnBG,IAAiBd,KAAoCA,EAmBtCe,MAAO,CAAC,EAAG,KAGtCa,GAAY,EAGT,SAASC,IACVD,IACJA,GAAY,EACZE,EAAgBd,GAClB,QAAAe,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["text","id","args","hooks","render","map","a","JSON","stringify","String","join","raise","subject","candidates","raiseError","s"],"sources":["../../../src/messages.ts"],"sourcesContent":["/**\n * The core's messages, by number. The prose lives in the diagnostics add-on\n * (`src/diagnostics/messages.ts`); without it a message reads `[@wcstack/state] #108 \"a|b(\"` —\n * the message number and the values it would have shown. With it (the full `auto` bundle installs\n * it) the message is the code shared with lint and the VS Code extension and the full sentence\n * (`[wcs/binding-syntax] Invalid filter format: …`), followed by the guidance.\n *\n * The hundreds of a number name its code (the diagnostics add-on's `CODES`, in the core up to\n * 4.0.0-rc.3): 1xx binding-syntax, 2xx template-syntax, …; 1–99 carry no code. Numbers are only\n * ever added, so a number read on a page keeps its meaning across versions. `M` is a const enum:\n * the build inlines the numbers.\n *\n * Kept as full text in the core, not numbered: the barriers a page without add-ons meets on\n * purpose (`[wcs/feature-not-installed]`, a formatting filter without the formats add-on).\n */\nimport { hooks } from \"./hooks\";\nimport { raiseError } from \"./parser/raiseError\";\n\nexport const enum M {\n // no code\n ScanRemoved = 1,\n GetterWithoutSetter = 2,\n NoRow = 3,\n ParentNotObject = 4,\n NotAMethod = 5,\n GetAllNoCommonLevel = 6,\n EqIndexNoRow = 7,\n Readonly = 8,\n SetAllNeedsIndexes = 9,\n SetAllSpreadLength = 10,\n DrainNotSettled = 11,\n BindingFailed = 12,\n LoadFailed = 13,\n ElementFailed = 14,\n NotInitialized = 15,\n NoScript = 16,\n TokenSubscriberThrew = 17,\n TokenListNotArray = 18,\n TokenEntryEmpty = 19,\n TokenEntryReserved = 20,\n TokenEntryDuplicated = 21,\n OnNotObject = 22,\n OnEntryUndeclared = 23,\n OnEntryNotFunction = 24,\n NamingLimit = 25,\n FilterOptionsRequired = 26,\n FilterOptionNotNumber = 27,\n FilterValueNotNumber = 28,\n FilterValueNotDate = 29,\n FilterValueNotArray = 30,\n DirectionalSyncDisabled = 31,\n SelectorRemoved = 32,\n ModifierUnknown = 33,\n ModifierTwice = 34,\n ModifierValue = 35,\n EventInitNone = 36,\n InitUnsupported = 37,\n MemberUndeclared = 38,\n InitIncompatible = 39,\n SyncConnectNeedsOutput = 40,\n RenderChain = 41,\n InlineBlocked = 42,\n InlineFailed = 43,\n OptionInvalid = 44,\n BehaviorChanged = 45,\n FeaturesNotArray = 46,\n SecondRoot = 47,\n LocaleInvalid = 48,\n InitFailed = 49,\n ConnectedFailed = 50,\n DisconnectedFailed = 51,\n // [wcs/binding-syntax]\n BindTextNoColon = 101,\n StructuralTakesNoModifiers = 102,\n ElseTakesNoValue = 103,\n SpreadNoPath = 104,\n SpreadNoFilters = 105,\n LeadingDotNamespace = 106,\n UnterminatedQuote = 107,\n FilterUnclosed = 108,\n FilterUnopened = 109,\n FilterParenOrder = 110,\n FilterTrailing = 111,\n FilterEmpty = 112,\n FilterNameHasModifiersInput = 113,\n FilterNameHasModifiersOutput = 114,\n OneModifierList = 115,\n NoPropertyName = 116,\n TooManySegments = 117,\n EmptySegment = 119,\n UnsafeSegment = 120,\n ForNoFilters = 121,\n NamespaceNeedsName = 122,\n // [wcs/template-syntax]\n StructuralNotSingle = 201,\n ElseWithoutIf = 202,\n OuterInTemplate = 203,\n TemplateHandedOver = 204,\n // [wcs/binding-path-missing]\n PathMissing = 301,\n // [wcs/binding-type-expectation]\n ClassNeedsBoolean = 401,\n // [wcs/filter-unknown]\n FilterUnknown = 501,\n // [wcs/filter-arity]\n FilterTooFewArgs = 601,\n FilterTooManyArgs = 602,\n // [wcs/getter-cycle]\n GetterCycle = 701,\n // [wcs/getter-depth-exceeded]\n GetterDepth = 801,\n // [wcs/index-arity]\n IndexArityExact = 901,\n IndexArityAtMost = 902,\n // [wcs/index-param-range]\n IndexParamRange = 1001,\n // [wcs/recursion-unsupported]\n RecursionUnsupported = 1101,\n // [wcs/token-misconfigured]\n CommandRightSide = 1201,\n NoBindable = 1202,\n NoCommand = 1203,\n NoProperty = 1204,\n NativeNoCommand = 1205,\n // [wcs/token-undeclared]\n EventTokenUndeclared = 1301,\n CommandTokenUndeclared = 1302,\n // [wcs/wildcard-rank]\n WildcardNoLoop = 1401,\n WildcardRelative = 1402,\n WildcardOtherList = 1403,\n // [wcs/spread-no-bindable]\n SpreadNoBindable = 1501,\n // [wcs/declaration-alias]\n DeclarationRemoved = 1601,\n // [wcs/name-alias]\n ApiRemoved = 1701,\n}\n\n/** A message without the `[@wcstack/state]` prefix: the code and the full sentence with diagnostics, else the number and the values. */\nexport function text(id: M, args: readonly unknown[] = []): string {\n return hooks.render?.(id, args) ?? `#${id}${args.map((a) => ` ${typeof a === \"string\" ? JSON.stringify(a) : String(a)}`).join(\"\")}`;\n}\n\n/** Throws message `id` (`subject` / `candidates` feed the diagnostics add-on's did-you-mean). */\nexport function raise(id: M, args?: readonly unknown[], subject?: string, candidates?: Iterable<string>): never {\n raiseError(text(id, args), subject, candidates);\n}\n"],"mappings":"+CA4IO,SAASA,EAAKC,EAAOC,EAA2B,IACrD,OAAOC,EAAMC,KAASH,EAAIC,IAAS,IAAID,IAAKC,EAAKG,IAAKC,GAAM,IAAiB,iBAANA,EAAiBC,KAAKC,UAAUF,GAAKG,OAAOH,MAAMI,KAAK,KAChI,CAGO,SAASC,EAAMV,EAAOC,EAA2BU,EAAkBC,GACxEC,EAAWd,EAAKC,EAAIC,GAAOU,EAASC,EACtC,QAAAP,OAAAS","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var t=class{constructor(t,l,i){this.c=[],this.getter=null,this.ie=null,this.se=!1,this.W=[],this.J=[],this.ft=null,this.A=-1,this.z=s,this.Ie=null,this.It=null,this.jt=null,this._=null,this.pn=!1,this.mn=!1,this.Wn=!1,this.Z=0,this.pt=new Set,this.t=t,this.d=i,this.s=l;let e=null===i?[null]:i.h.slice(),h="*"===l;h&&e.push(i),this.n=e.length-1,this.q=h?[]:null===i?[l]:[...i.q,l],this.h=e}_n(t){this.pt.has(t)||(this.pt.add(t),this.W.push(t),t.J.push(this))}Io(t){this.pt.delete(t);let s=this.W;s.splice(s.indexOf(t),1)}jo(){this.getter=null,this.ie=null,this.A=-1,this.z=s,this.W.length=0,this.pt.clear(),this.J.length=0,this.ft=null,this.Ie=null,this.It=null,this.jt=null,this._=null}ee(t){let s=this;for(;null!==s;){if(s===t)return!0;s=s.d}return!1}},s=Symbol("unset"),l=Symbol("dirty"),i=Symbol("failed"),e=class{constructor(t=null){this.mt=new Map,this.Vn=t}Dt(t){return this.mt.get(t)}get(s){let l=this.mt.get(s);if(void 0!==l)return l;let i=s.lastIndexOf("."),e=i<0?null:this.get(s.slice(0,i));return l=new t(s,s.slice(i+1),e),this.Vn?.(l),this.mt.set(s,l),e&&e.c.push(l),l}all(){return this.mt.values()}Lt(t){this.mt.delete(t.t)}},h=new Map;function n(t){let s=h.get(t);if(void 0!==s)return s;let l=!0,i=t.split("."),e=[];for(let t=0;t<i.length;t++){let s=i[t],h=s.charCodeAt(0);t>0&&h>=48&&h<=57?(l=!1,e.push(Number(s)),i[t]="*"):"*"===s&&e.push(-1)}if(!l)return{o:i.join("."),indexes:e};let n={o:t,indexes:null};return h.size>4095&&h.clear(),h.set(t,n),n}export{s as a,l as b,i as c,e as d,n as e};
|
|
2
|
-
//# sourceMappingURL=chunk-XEGL4FW5.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|