@wcstack/state 4.2.0 → 4.4.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 -10
- package/README.md +20 -9
- 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 +5 -4
- package/dist/split/auto.js +1 -1
- package/dist/split/chunks/chunk-467LYA2V.js +2 -0
- package/dist/split/chunks/chunk-467LYA2V.js.map +1 -0
- package/dist/split/chunks/{chunk-UPSLR4FS.js → chunk-CBMAVRYG.js} +2 -2
- package/dist/split/chunks/chunk-DUUQZITD.js +2 -0
- package/dist/split/chunks/{chunk-OKBVNGFK.js.map → chunk-DUUQZITD.js.map} +1 -1
- package/dist/split/chunks/{chunk-2RBI6DVS.js → chunk-FBBHQU7S.js} +2 -2
- package/dist/split/chunks/chunk-GBBBRPZR.js +2 -0
- package/dist/split/chunks/{chunk-BYQBV3ZC.js.map → chunk-GBBBRPZR.js.map} +1 -1
- package/dist/split/chunks/chunk-JWRQLKOQ.js +2 -0
- package/dist/split/chunks/chunk-NITPUCPA.js +2 -0
- package/dist/split/chunks/{chunk-CIBJLAA3.js → chunk-T3FN37DU.js} +2 -2
- package/dist/split/chunks/{chunk-BGUJ3HF6.js → chunk-TNYNJXEC.js} +2 -2
- package/dist/split/chunks/chunk-TNYNJXEC.js.map +1 -0
- package/dist/split/chunks/chunk-ULMHOGJ2.js +2 -0
- package/dist/split/chunks/chunk-ULMHOGJ2.js.map +1 -0
- package/dist/split/chunks/chunk-ZJYPRSTO.js +2 -0
- package/dist/split/chunks/chunk-ZJYPRSTO.js.map +1 -0
- 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.js +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/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/ssr.js.map +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/wcs-manifest.json +4 -8
- package/package.json +1 -1
- package/dist/split/chunks/chunk-3Q7LGONS.js +0 -2
- package/dist/split/chunks/chunk-3Q7LGONS.js.map +0 -1
- package/dist/split/chunks/chunk-4ECL4ITF.js +0 -2
- package/dist/split/chunks/chunk-4ECL4ITF.js.map +0 -1
- package/dist/split/chunks/chunk-BGUJ3HF6.js.map +0 -1
- package/dist/split/chunks/chunk-BI4645UG.js +0 -2
- package/dist/split/chunks/chunk-BI4645UG.js.map +0 -1
- package/dist/split/chunks/chunk-BYQBV3ZC.js +0 -2
- package/dist/split/chunks/chunk-JK3B3LLB.js +0 -2
- package/dist/split/chunks/chunk-OKBVNGFK.js +0 -2
- package/dist/split/chunks/chunk-UBGJGMSG.js +0 -2
- /package/dist/split/chunks/{chunk-UPSLR4FS.js.map → chunk-CBMAVRYG.js.map} +0 -0
- /package/dist/split/chunks/{chunk-2RBI6DVS.js.map → chunk-FBBHQU7S.js.map} +0 -0
- /package/dist/split/chunks/{chunk-UBGJGMSG.js.map → chunk-JWRQLKOQ.js.map} +0 -0
- /package/dist/split/chunks/{chunk-JK3B3LLB.js.map → chunk-NITPUCPA.js.map} +0 -0
- /package/dist/split/chunks/{chunk-CIBJLAA3.js.map → chunk-T3FN37DU.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BINDER_KEY","Symbol","for","PENDING_KEY","TAKEN_KEY","early","Map","bind","subtree","options","nodeType","isConnected","engine","engines","get","getRootNode","element","set","mountSubtree","range","drainBinds","waiting","clear","binder","candidate","globalThis","protocol","version","getBinder","queue","globals","pendingQueue","length","pending","splice","taken","WeakSet","takenSet","add","flushPendingBinds","installBinder","slot","DirtyStrategy","constructor","this","name","mark","g","row","depth","v","rootValue","UNSET","DIRTY","c","cache","onWrite","p","getter","enqueueBound","walkDependents","onIndexChange","watchers","list","pattern","indexWatchers","visitGetter","forRowsUnder","r","invalidate","hooks","getterReached","readGetter","root","Array","slotCount","fill","FAILED","evalGetter","resetRow","dropped","patterns","all","forAllRows","lists","E","W","h"],"sources":["../../../src/protocol/binder.ts","../../../src/dom/binder.ts","../../../src/strategy/dirty.ts"],"sourcesContent":["// ===========================================================================\n// AUTO-GENERATED FILE - DO NOT EDIT.\n// Generated from /protocol/binder.ts by scripts/sync-protocol-types.mjs.\n// Run `node scripts/sync-protocol-types.mjs` after editing the source.\n// ===========================================================================\n\n// binder protocol — how a package that inserts DOM hands those nodes to whoever\n// owns data bindings on the page.\n//\n// The dual of transition-runner: that one hands a *mutation* to whoever animates\n// it, this one hands *new nodes* to whoever binds them.\n//\n// A `data-wcs` binding exists only for nodes @wcstack/state walked when it built\n// its bindings. Nodes that arrive later — the content of a route that was not\n// active at that moment, a <wcs-head> child reflected into <head> — were never\n// walked, so their bindings silently do nothing, however often they are inserted.\n// @wcstack/router must not depend on @wcstack/state (zero runtime dependencies,\n// independently publishable), so state installs a binder on a well-known global\n// symbol and inserters look it up lazily.\n//\n// No binder installed means nothing happens — byte-for-byte the behavior these\n// packages had before the protocol existed.\n//\n// docs/binder-protocol-design.md is the normative description.\n//\n// SINGLE SOURCE OF TRUTH: edit only this file (/protocol/binder.ts), then run\n// `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies\n// (packages/<pkg>/src/protocol/binder.ts). Those copies are generated — do not edit them.\n\n/**\n * Global key the binder installs itself under. `Symbol.for` so independently\n * loaded copies of this file (two CDN bundles on one page) still agree.\n */\nexport const BINDER_KEY = Symbol.for(\"wcstack.binder\");\n\n/**\n * What the caller declares about a subtree it hands over (the second argument of `bind`; additive\n * since version 1 — a binder that predates it ignores it, and leaving it out keeps the old contract).\n */\nexport interface IWcsBindOptions {\n /**\n * The caller carries the range the subtree sits in: on removal it takes everything from its own\n * start mark up to its end mark along — what the binder rendered beside the subtree included, as\n * the rows a structural template handed over at the top of the content renders before its anchor —\n * and puts it all back on reinsertion. Only with this may a binder render such a template: without\n * it, what the binder rendered beside the subtree would be left behind, so @wcstack/state 4.0\n * refuses one (#204). @wcstack/state 3.x ignores the option and renders no structural template\n * handed over itself, with or without it (docs/binder-protocol-design.md §2, §9-5, §9-6).\n */\n readonly range?: boolean;\n}\n\nexport interface IWcsBinder {\n readonly protocol: \"wcs-binder\";\n /** Integer protocol version. All versions >= 1 are participant-compatible. */\n readonly version: number;\n /**\n * Take a subtree that has just entered the document and bind whatever\n * declarations it carries.\n *\n * Contract (docs/binder-protocol-design.md §2):\n * - Synchronous. Initial values are applied before this returns, so the\n * caller never shows one frame of unbound markup.\n * - Idempotent. A subtree that is already bound is left alone, so a caller\n * may hand over the same nodes on every insertion without tracking which\n * ones are new.\n * - Binding survives later relocation, so this need not be called again when\n * the same nodes are moved (measured: design doc §8-3).\n * - Never throws for markup reasons; a subtree with no declarations is a\n * no-op.\n * - `options` (optional) is what the caller declares about the subtree\n * ({@link IWcsBindOptions}).\n */\n bind(subtree: Node, options?: IWcsBindOptions): void;\n}\n\n/**\n * The installed binder, or null when there is none or it speaks a version this\n * reader does not.\n *\n * Looked up on every call rather than cached, for the same reason\n * transition-runner does: the page's composition can change at any point, and a\n * stale cache would keep calling into a binder that is no longer there.\n */\nexport function getBinder(): IWcsBinder | null {\n const candidate = (globalThis as Record<symbol, unknown>)[BINDER_KEY] as IWcsBinder | undefined;\n if (candidate === undefined || candidate === null) return null;\n if (candidate.protocol !== \"wcs-binder\") return null;\n if (typeof candidate.version !== \"number\" || candidate.version < 1) return null;\n if (typeof candidate.bind !== \"function\") return null;\n return candidate;\n}\n\n/**\n * Subtrees offered before a binder existed, and the set of everything a binder\n * has taken. Both live on global symbols so that independently loaded copies of\n * this file — the router's and state's — share one queue.\n *\n * The queue is needed because of load order: the router's auto bundle runs\n * before state's, so `<wcs-head>` reflects its children into `<head>` while\n * there is still nothing to bind them. Offering them to a binder that arrives\n * later is the difference between working and silently blank.\n */\nconst PENDING_KEY = Symbol.for(\"wcstack.binder.pending\");\nconst TAKEN_KEY = Symbol.for(\"wcstack.binder.taken\");\n\nfunction pendingQueue(): Node[] {\n const globals = globalThis as Record<symbol, unknown>;\n let queue = globals[PENDING_KEY] as Node[] | undefined;\n if (queue === undefined) {\n queue = [];\n globals[PENDING_KEY] = queue;\n }\n return queue;\n}\n\nfunction takenSet(): WeakSet<Node> {\n const globals = globalThis as Record<symbol, unknown>;\n let taken = globals[TAKEN_KEY] as WeakSet<Node> | undefined;\n if (taken === undefined) {\n taken = new WeakSet<Node>();\n globals[TAKEN_KEY] = taken;\n }\n return taken;\n}\n\n/**\n * Hand `subtree` to the installed binder, or hold it for one that arrives later.\n *\n * Returns whether a binder took it *now*. A `false` does not yet mean the markup\n * is doomed — check {@link wasBoundBy} once module scripts have run.\n *\n * `options` goes to the binder with the subtree. A subtree held for a later binder\n * is handed over without it: that binder's first walk of the page binds what is\n * still in place there.\n */\nexport function bindSubtree(subtree: Node, options?: IWcsBindOptions): boolean {\n const binder = getBinder();\n if (binder === null) {\n pendingQueue().push(subtree);\n return false;\n }\n takenSet().add(subtree);\n binder.bind(subtree, options);\n return true;\n}\n\n/** Whether any binder has taken this subtree. */\nexport function wasBoundBy(subtree: Node): boolean {\n return takenSet().has(subtree);\n}\n\n/**\n * Bind everything offered before this binder existed. Called by the binder right\n * after it installs itself.\n */\nexport function flushPendingBinds(): void {\n const binder = getBinder();\n if (binder === null) return;\n const queue = pendingQueue();\n if (queue.length === 0) return;\n const pending = queue.splice(0, queue.length);\n const taken = takenSet();\n for (const subtree of pending) {\n taken.add(subtree);\n binder.bind(subtree);\n }\n}\n","import { BINDER_KEY, flushPendingBinds, type IWcsBinder, type IWcsBindOptions } from \"../protocol/binder\";\nimport { engines, mountSubtree } from \"./mount\";\n\n/**\n * The binder protocol's provider (docs/binder-protocol-design.md): a package that inserts\n * DOM after the mount — the router's route content, `<wcs-head>`'s clones in <head> —\n * hands the subtree over, and it is bound to the engine of its root, synchronously.\n * Only what is handed over is bound (no scan of every insertion), and binding twice is a\n * no-op, so the router may hand the same nodes over on every insertion.\n */\n\n/**\n * Subtrees handed over before their root's engine finished its first mount, or while it was out of the\n * page, with what the caller declared (a range: a route's top-level template is rendered then).\n */\nconst early = new Map<Element, IWcsBindOptions | undefined>();\n\nexport function bind(subtree: Node, options?: IWcsBindOptions): void {\n // not in a document (it left, or was replaced, as a chain's `else:` template by its anchor): nothing to bind\n if (subtree.nodeType !== 1 || !subtree.isConnected) return;\n // (a root taken out of the page lets go of its root node: it binds what waited here when it is back.\n // A component's, whose <wcs-state> alone left, is still registered: not one to bind to either)\n const engine = engines.get(subtree.getRootNode());\n // (once each: the router hands the same nodes over on every insertion. One handed over early is\n // walked by the first mount where it is: the declaration is not needed then)\n if (engine === undefined || (engine.element as Node | null)?.isConnected === false) early.set(subtree as Element, options);\n else mountSubtree(engine, subtree as Element, options?.range);\n}\n\n/**\n * After an engine's first mount, and when a root is back in the page: binds what was handed over\n * too early — to this binder before the mount or while the root was out, or (queued by the\n * protocol) before any binder existed.\n */\nexport function drainBinds(): void {\n // (one that left the document meanwhile is dropped: handed over again if it comes back)\n const waiting = [...early];\n early.clear();\n for (const [subtree, options] of waiting) bind(subtree, options);\n flushPendingBinds();\n}\n\n/** Installs the binder on the protocol's global slot, unless another copy already has it. */\nexport function installBinder(): void {\n const slot = globalThis as Record<symbol, unknown>;\n if (slot[BINDER_KEY] === undefined) slot[BINDER_KEY] = { protocol: \"wcs-binder\", version: 1, bind } satisfies IWcsBinder;\n}\n","import type { Engine } from \"../engine\";\nimport { DIRTY, FAILED, UNSET, type Pattern } from \"../pattern\";\nimport type { StateRow } from \"../list\";\nimport type { Strategy } from \"./types\";\nimport { hooks } from \"../hooks\";\n\n/**\n * Push invalidation: a write walks its dependents immediately, marks their caches\n * DIRTY and queues their bindings. A cache already DIRTY (or never computed) stops the\n * walk — whatever depends on it was reached when it was marked.\n */\nexport class DirtyStrategy implements Strategy {\n readonly name = \"dirty\";\n\n private readonly mark = (g: Pattern, row: StateRow | null): boolean => {\n // UNSET: nobody read it; DIRTY: already reached. FAILED was read (and threw): reach it.\n if (g.depth === 0) {\n const v = g.rootValue;\n if (v === UNSET || v === DIRTY) return false;\n g.rootValue = DIRTY;\n return true;\n }\n const c = row === null ? null : row.cache;\n if (c === null) return false;\n const v = c[g.slot];\n if (v === UNSET || v === DIRTY) return false;\n c[g.slot] = DIRTY;\n return true;\n };\n\n onWrite(engine: Engine, p: Pattern, row: StateRow | null): void {\n // a write through a getter's setter: the written occurrence itself is stale\n if (p.getter !== null) this.mark(p, row);\n engine.enqueueBound(p, row);\n engine.walkDependents(p, row, this.mark);\n }\n\n onIndexChange(engine: Engine, row: StateRow): void {\n const watchers = row.list.pattern.indexWatchers;\n if (watchers === null) return;\n for (const g of watchers) {\n // the row itself (a row getter reading its own index): no closure per moved row\n if (g.depth === row.list.depth) engine.visitGetter(g, row, this.mark);\n else engine.forRowsUnder(row, g, (r) => engine.visitGetter(g, r, this.mark));\n }\n }\n\n invalidate(engine: Engine, g: Pattern, row: StateRow | null): void {\n this.mark(g, row);\n hooks.getterReached?.(engine, g, row);\n engine.enqueueBound(g, row);\n engine.walkDependents(g, row, this.mark);\n }\n\n readGetter(engine: Engine, g: Pattern, row: StateRow | null): unknown {\n const root = g.depth === 0;\n if (!root && row === null) return undefined;\n const c = root ? null : (row!.cache ??= new Array(engine.slotCount).fill(UNSET));\n let v = c === null ? g.rootValue : c[g.slot];\n // a getter made after the row's cache (a recursive family, a mounted key, a binder's subtree) has\n // no entry yet — nor one whose slot lies before a later getter's written past the end (a hole)\n if (v !== UNSET && v !== DIRTY && v !== FAILED && (c === null || g.slot in c)) return v;\n v = FAILED;\n try {\n return (v = engine.evalGetter(g, c === null ? null : row));\n } finally {\n if (c === null) g.rootValue = v;\n else c[g.slot] = v;\n }\n }\n\n resetRow(row: StateRow): void {\n row.cache = null;\n }\n\n dropped(engine: Engine): void {\n // DIRTY says \"its readers were reached\", and they were dropped: FAILED is reached again\n for (const g of engine.patterns.all()) {\n if (g.getter === null) continue;\n if (g.depth === 0) {\n if (g.rootValue === DIRTY) g.rootValue = FAILED;\n } else {\n engine.forAllRows(g.lists[g.depth]!, (r) => {\n const c = r.cache;\n if (c !== null && c[g.slot] === DIRTY) c[g.slot] = FAILED;\n });\n }\n }\n }\n}\n"],"mappings":"wIAiCO,IAAMA,EAAaC,OAAOC,IAAI,kBAsE/BC,EAAcF,OAAOC,IAAI,0BACzBE,EAAYH,OAAOC,IAAI,wBCzF7B,IAAMG,EAAQ,IAAIC,IAEX,SAASC,EAAKC,EAAeC,GAElC,GAAyB,IAArBD,EAAQE,WAAmBF,EAAQG,YAAa,OAGpD,IAAMC,EAASC,EAAQC,IAAIN,EAAQO,oBAGpB,IAAXH,IAAyE,IAAhDA,EAAOI,SAAyBL,YAAuBN,EAAMY,IAAIT,EAAoBC,GAC7GS,EAAaN,EAAQJ,EAAoBC,GAASU,MACzD,CAOO,SAASC,IAEd,IAAMC,EAAU,IAAIhB,GACpBA,EAAMiB,QACN,QAAYd,EAASC,KAAYY,EAASd,EAAKC,EAASC,IDsHnD,WACL,IAAMc,EAzED,WACL,IAAMC,EAAaC,WAAuCzB,GAI1D,OAH6C,MAAdwB,GACJ,eAAvBA,EAAUE,UACmB,iBAAtBF,EAAUG,SAAwBH,EAAUG,QAAU,GACnC,mBAAnBH,EAAUjB,KAA4B,KAC1CiB,CACT,CAkEiBI,GACf,GAAe,OAAXL,EAAiB,OACrB,IAAMM,EArDR,WACE,IAAMC,EAAUL,WACZI,EAAQC,EAAQ3B,GACpB,YAAc,IAAV0B,IACFA,EAAQ,GACRC,EAAQ3B,GAAe0B,GAElBA,CACT,CA6CgBE,GACd,GAAqB,IAAjBF,EAAMG,OAAc,OACxB,IAAMC,EAAUJ,EAAMK,OAAO,EAAGL,EAAMG,QAChCG,EA9CR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AAKE,EAAKC,EAAGC,GACbsB,EAAMC,KAAgB3D,EAAQmC,EAAGC,GACjCpC,EAAO+C,GAAaZ,EAAGC,GACvBpC,EAAOgD,GAAeb,EAAGC,EAAKJ,KAAKE,EACrC,CAEA0B,GAAW5D,EAAgBmC,EAAYC,GACrC,IAAMyB,EAAmB,IAAZ1B,EAAEE,EACf,IAAKwB,GAAgB,OAARzB,EAAc,OAC3B,IAAMM,EAAImB,EAAO,KAAQzB,EAAKO,KAAU,IAAImB,MAAM9D,EAAO+D,IAAWC,KAAKxB,GACrEF,EAAU,OAANI,EAAaP,EAAEI,EAAYG,EAAEP,EAAEN,GAGvC,GAAIS,IAAME,GAASF,IAAMG,GAASH,IAAM2B,IAAiB,OAANvB,GAAcP,EAAEN,KAAQa,GAAI,OAAOJ,EACtFA,EAAI2B,EACJ,IACE,OAAQ3B,EAAItC,EAAOkE,GAAW/B,EAAS,OAANO,EAAa,KAAON,EACvD,SACY,OAANM,EAAYP,EAAEI,EAAYD,EACzBI,EAAEP,EAAEN,GAAQS,CACnB,CACF,CAEA6B,GAAS/B,GACPA,EAAIO,GAAQ,IACd,CAEAyB,GAAQpE,GAEN,QAAWmC,KAAKnC,EAAOqE,EAASC,MACb,OAAbnC,EAAEW,SACU,IAAZX,EAAEE,EACAF,EAAEI,IAAcE,IAAON,EAAEI,EAAY0B,GAEzCjE,EAAOuE,GAAWpC,EAAEqC,EAAMrC,EAAEE,GAAUmB,IACpC,IAAMd,EAAIc,EAAEb,GACF,OAAND,GAAcA,EAAEP,EAAEN,KAAUY,IAAOC,EAAEP,EAAEN,GAAQoC,KAI3D,UACFQ,OAAAC,OAAAvC,OAAAwC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["BINDER_KEY","Symbol","for","PENDING_KEY","TAKEN_KEY","early","Map","bind","subtree","options","nodeType","isConnected","engine","engines","get","getRootNode","element","set","mountSubtree","range","drainBinds","waiting","clear","binder","candidate","globalThis","protocol","version","getBinder","queue","globals","pendingQueue","length","pending","splice","taken","WeakSet","takenSet","add","flushPendingBinds","installBinder","slot","DirtyStrategy","constructor","this","name","mark","g","row","depth","v","rootValue","UNSET","DIRTY","c","cache","onWrite","p","getter","enqueueBound","walkDependents","onIndexChange","watchers","list","pattern","indexWatchers","visitGetter","forRowsUnder","r","invalidate","hooks","getterReached","readGetter","root","Array","slotCount","fill","FAILED","evalGetter","resetRow","dropped","patterns","all","forAllRows","lists","E","W","h"],"sources":["../../../src/protocol/binder.ts","../../../src/dom/binder.ts","../../../src/strategy/dirty.ts"],"sourcesContent":["// ===========================================================================\n// AUTO-GENERATED FILE - DO NOT EDIT.\n// Generated from /protocol/binder.ts by scripts/sync-protocol-types.mjs.\n// Run `node scripts/sync-protocol-types.mjs` after editing the source.\n// ===========================================================================\n\n// binder protocol — how a package that inserts DOM hands those nodes to whoever\n// owns data bindings on the page.\n//\n// The dual of transition-runner: that one hands a *mutation* to whoever animates\n// it, this one hands *new nodes* to whoever binds them.\n//\n// A `data-wcs` binding exists only for nodes @wcstack/state walked when it built\n// its bindings. Nodes that arrive later — the content of a route that was not\n// active at that moment, a <wcs-head> child reflected into <head> — were never\n// walked, so their bindings silently do nothing, however often they are inserted.\n// @wcstack/router must not depend on @wcstack/state (zero runtime dependencies,\n// independently publishable), so state installs a binder on a well-known global\n// symbol and inserters look it up lazily.\n//\n// No binder installed means nothing happens — byte-for-byte the behavior these\n// packages had before the protocol existed.\n//\n// docs/binder-protocol-design.md is the normative description.\n//\n// SINGLE SOURCE OF TRUTH: edit only this file (/protocol/binder.ts), then run\n// `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies\n// (packages/<pkg>/src/protocol/binder.ts). Those copies are generated — do not edit them.\n\n/**\n * Global key the binder installs itself under. `Symbol.for` so independently\n * loaded copies of this file (two CDN bundles on one page) still agree.\n */\nexport const BINDER_KEY = Symbol.for(\"wcstack.binder\");\n\n/**\n * What the caller declares about a subtree it hands over (the second argument of `bind`; additive\n * since version 1 — a binder that predates it ignores it, and leaving it out keeps the old contract).\n */\nexport interface IWcsBindOptions {\n /**\n * The caller carries the range the subtree sits in: on removal it takes everything from its own\n * start mark up to its end mark along — what the binder rendered beside the subtree included, as\n * the rows a structural template handed over at the top of the content renders before its anchor —\n * and puts it all back on reinsertion. Only with this may a binder render such a template: without\n * it, what the binder rendered beside the subtree would be left behind, so @wcstack/state 4.0\n * refuses one (#204). @wcstack/state 3.x ignores the option and renders no structural template\n * handed over itself, with or without it (docs/binder-protocol-design.md §2, §9-5, §9-6).\n */\n readonly range?: boolean;\n}\n\nexport interface IWcsBinder {\n readonly protocol: \"wcs-binder\";\n /** Integer protocol version. All versions >= 1 are participant-compatible. */\n readonly version: number;\n /**\n * Take a subtree that has just entered the document and bind whatever\n * declarations it carries.\n *\n * Contract (docs/binder-protocol-design.md §2):\n * - Synchronous. Initial values are applied before this returns, so the\n * caller never shows one frame of unbound markup.\n * - Idempotent. A subtree that is already bound is left alone, so a caller\n * may hand over the same nodes on every insertion without tracking which\n * ones are new.\n * - Binding survives later relocation, so this need not be called again when\n * the same nodes are moved (measured: design doc §8-3).\n * - Never throws for markup reasons; a subtree with no declarations is a\n * no-op.\n * - `options` (optional) is what the caller declares about the subtree\n * ({@link IWcsBindOptions}).\n */\n bind(subtree: Node, options?: IWcsBindOptions): void;\n}\n\n/**\n * The installed binder, or null when there is none or it speaks a version this\n * reader does not.\n *\n * Looked up on every call rather than cached, for the same reason\n * transition-runner does: the page's composition can change at any point, and a\n * stale cache would keep calling into a binder that is no longer there.\n */\nexport function getBinder(): IWcsBinder | null {\n const candidate = (globalThis as Record<symbol, unknown>)[BINDER_KEY] as IWcsBinder | undefined;\n if (candidate === undefined || candidate === null) return null;\n if (candidate.protocol !== \"wcs-binder\") return null;\n if (typeof candidate.version !== \"number\" || candidate.version < 1) return null;\n if (typeof candidate.bind !== \"function\") return null;\n return candidate;\n}\n\n/**\n * Subtrees offered before a binder existed, and the set of everything a binder\n * has taken. Both live on global symbols so that independently loaded copies of\n * this file — the router's and state's — share one queue.\n *\n * The queue is needed because of load order: the router's auto bundle runs\n * before state's, so `<wcs-head>` reflects its children into `<head>` while\n * there is still nothing to bind them. Offering them to a binder that arrives\n * later is the difference between working and silently blank.\n */\nconst PENDING_KEY = Symbol.for(\"wcstack.binder.pending\");\nconst TAKEN_KEY = Symbol.for(\"wcstack.binder.taken\");\n\nfunction pendingQueue(): Node[] {\n const globals = globalThis as Record<symbol, unknown>;\n let queue = globals[PENDING_KEY] as Node[] | undefined;\n if (queue === undefined) {\n queue = [];\n globals[PENDING_KEY] = queue;\n }\n return queue;\n}\n\nfunction takenSet(): WeakSet<Node> {\n const globals = globalThis as Record<symbol, unknown>;\n let taken = globals[TAKEN_KEY] as WeakSet<Node> | undefined;\n if (taken === undefined) {\n taken = new WeakSet<Node>();\n globals[TAKEN_KEY] = taken;\n }\n return taken;\n}\n\n/**\n * Hand `subtree` to the installed binder, or hold it for one that arrives later.\n *\n * Returns whether a binder took it *now*. A `false` does not yet mean the markup\n * is doomed — check {@link wasBoundBy} once module scripts have run.\n *\n * `options` goes to the binder with the subtree. A subtree held for a later binder\n * is handed over without it: that binder's first walk of the page binds what is\n * still in place there.\n */\nexport function bindSubtree(subtree: Node, options?: IWcsBindOptions): boolean {\n const binder = getBinder();\n if (binder === null) {\n pendingQueue().push(subtree);\n return false;\n }\n takenSet().add(subtree);\n binder.bind(subtree, options);\n return true;\n}\n\n/** Whether any binder has taken this subtree. */\nexport function wasBoundBy(subtree: Node): boolean {\n return takenSet().has(subtree);\n}\n\n/**\n * Bind everything offered before this binder existed. Called by the binder right\n * after it installs itself.\n */\nexport function flushPendingBinds(): void {\n const binder = getBinder();\n if (binder === null) return;\n const queue = pendingQueue();\n if (queue.length === 0) return;\n const pending = queue.splice(0, queue.length);\n const taken = takenSet();\n for (const subtree of pending) {\n taken.add(subtree);\n binder.bind(subtree);\n }\n}\n","import { BINDER_KEY, flushPendingBinds, type IWcsBinder, type IWcsBindOptions } from \"../protocol/binder\";\nimport { engines, mountSubtree } from \"./mount\";\n\n/**\n * The binder protocol's provider (docs/binder-protocol-design.md): a package that inserts\n * DOM after the mount — the router's route content, `<wcs-head>`'s clones in <head> —\n * hands the subtree over, and it is bound to the engine of its root, synchronously.\n * Only what is handed over is bound (no scan of every insertion), and binding twice is a\n * no-op, so the router may hand the same nodes over on every insertion.\n */\n\n/**\n * Subtrees handed over before their root's engine finished its first mount, or while it was out of the\n * page, with what the caller declared (a range: a route's top-level template is rendered then).\n */\nconst early = new Map<Element, IWcsBindOptions | undefined>();\n\nexport function bind(subtree: Node, options?: IWcsBindOptions): void {\n // not in a document (it left, or was replaced, as a chain's `else:` template by its anchor): nothing to bind\n if (subtree.nodeType !== 1 || !subtree.isConnected) return;\n // (a root taken out of the page lets go of its root node: it binds what waited here when it is back.\n // A component's, whose <wcs-state> alone left, is still registered: not one to bind to either)\n const engine = engines.get(subtree.getRootNode());\n // (once each: the router hands the same nodes over on every insertion. One handed over early is\n // walked by the first mount where it is: the declaration is not needed then)\n if (engine === undefined || (engine.element as Node | null)?.isConnected === false) early.set(subtree as Element, options);\n else mountSubtree(engine, subtree as Element, options?.range);\n}\n\n/**\n * After an engine's first mount, and when a root is back in the page: binds what was handed over\n * too early — to this binder before the mount or while the root was out, or (queued by the\n * protocol) before any binder existed.\n */\nexport function drainBinds(): void {\n // (one that left the document meanwhile is dropped: handed over again if it comes back)\n const waiting = [...early];\n early.clear();\n for (const [subtree, options] of waiting) bind(subtree, options);\n flushPendingBinds();\n}\n\n/** Installs the binder on the protocol's global slot, unless another copy already has it. */\nexport function installBinder(): void {\n const slot = globalThis as Record<symbol, unknown>;\n if (slot[BINDER_KEY] === undefined) slot[BINDER_KEY] = { protocol: \"wcs-binder\", version: 1, bind } satisfies IWcsBinder;\n}\n","import type { Engine } from \"../engine\";\nimport { DIRTY, FAILED, UNSET, type Pattern } from \"../pattern\";\nimport type { StateRow } from \"../list\";\nimport type { Strategy } from \"./types\";\nimport { hooks } from \"../hooks\";\n\n/**\n * Push invalidation: a write walks its dependents immediately, marks their caches\n * DIRTY and queues their bindings. A cache already DIRTY (or never computed) stops the\n * walk — whatever depends on it was reached when it was marked.\n */\nexport class DirtyStrategy implements Strategy {\n readonly name = \"dirty\";\n\n private readonly mark = (g: Pattern, row: StateRow | null): boolean => {\n // UNSET: nobody read it; DIRTY: already reached. FAILED was read (and threw): reach it.\n if (g.depth === 0) {\n const v = g.rootValue;\n if (v === UNSET || v === DIRTY) return false;\n g.rootValue = DIRTY;\n return true;\n }\n const c = row === null ? null : row.cache;\n if (c === null) return false;\n const v = c[g.slot];\n if (v === UNSET || v === DIRTY) return false;\n c[g.slot] = DIRTY;\n return true;\n };\n\n onWrite(engine: Engine, p: Pattern, row: StateRow | null): void {\n // a write through a getter's setter: the written occurrence itself is stale\n if (p.getter !== null) this.mark(p, row);\n engine.enqueueBound(p, row);\n engine.walkDependents(p, row, this.mark);\n }\n\n onIndexChange(engine: Engine, row: StateRow): void {\n const watchers = row.list.pattern.indexWatchers;\n if (watchers === null) return;\n for (const g of watchers) {\n // the row itself (a row getter reading its own index): no closure per moved row\n if (g.depth === row.list.depth) engine.visitGetter(g, row, this.mark);\n else engine.forRowsUnder(row, g, (r) => engine.visitGetter(g, r, this.mark));\n }\n }\n\n invalidate(engine: Engine, g: Pattern, row: StateRow | null): void {\n this.mark(g, row);\n hooks.getterReached?.(engine, g, row);\n engine.enqueueBound(g, row);\n engine.walkDependents(g, row, this.mark);\n }\n\n readGetter(engine: Engine, g: Pattern, row: StateRow | null): unknown {\n const root = g.depth === 0;\n if (!root && row === null) return undefined;\n const c = root ? null : (row!.cache ??= new Array(engine.slotCount).fill(UNSET));\n let v = c === null ? g.rootValue : c[g.slot];\n // a getter made after the row's cache (a recursive family, a mounted key, a binder's subtree) has\n // no entry yet — nor one whose slot lies before a later getter's written past the end (a hole)\n if (v !== UNSET && v !== DIRTY && v !== FAILED && (c === null || g.slot in c)) return v;\n v = FAILED;\n try {\n return (v = engine.evalGetter(g, c === null ? null : row));\n } finally {\n if (c === null) g.rootValue = v;\n else c[g.slot] = v;\n }\n }\n\n resetRow(row: StateRow): void {\n row.cache = null;\n }\n\n dropped(engine: Engine): void {\n // DIRTY says \"its readers were reached\", and they were dropped: FAILED is reached again\n for (const g of engine.patterns.all()) {\n if (g.getter === null) continue;\n if (g.depth === 0) {\n if (g.rootValue === DIRTY) g.rootValue = FAILED;\n } else {\n engine.forAllRows(g.lists[g.depth]!, (r) => {\n const c = r.cache;\n if (c !== null && c[g.slot] === DIRTY) c[g.slot] = FAILED;\n });\n }\n }\n }\n}\n"],"mappings":"6IAiCO,IAAMA,EAAaC,OAAOC,IAAI,kBAsE/BC,EAAcF,OAAOC,IAAI,0BACzBE,EAAYH,OAAOC,IAAI,wBCzF7B,IAAMG,EAAQ,IAAIC,IAEX,SAASC,EAAKC,EAAeC,GAElC,GAAyB,IAArBD,EAAQE,WAAmBF,EAAQG,YAAa,OAGpD,IAAMC,EAASC,EAAQC,IAAIN,EAAQO,oBAGpB,IAAXH,IAAyE,IAAhDA,EAAOI,SAAyBL,YAAuBN,EAAMY,IAAIT,EAAoBC,GAC7GS,EAAaN,EAAQJ,EAAoBC,GAASU,MACzD,CAOO,SAASC,IAEd,IAAMC,EAAU,IAAIhB,GACpBA,EAAMiB,QACN,QAAYd,EAASC,KAAYY,EAASd,EAAKC,EAASC,IDsHnD,WACL,IAAMc,EAzED,WACL,IAAMC,EAAaC,WAAuCzB,GAI1D,OAH6C,MAAdwB,GACJ,eAAvBA,EAAUE,UACmB,iBAAtBF,EAAUG,SAAwBH,EAAUG,QAAU,GACnC,mBAAnBH,EAAUjB,KAA4B,KAC1CiB,CACT,CAkEiBI,GACf,GAAe,OAAXL,EAAiB,OACrB,IAAMM,EArDR,WACE,IAAMC,EAAUL,WACZI,EAAQC,EAAQ3B,GACpB,YAAc,IAAV0B,IACFA,EAAQ,GACRC,EAAQ3B,GAAe0B,GAElBA,CACT,CA6CgBE,GACd,GAAqB,IAAjBF,EAAMG,OAAc,OACxB,IAAMC,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AE1E,CAEAuB,GAAWzD,EAAgBmC,EAAYC,GACrCJ,KAAKE,EAAKC,EAAGC,GACbsB,EAAMC,KAAgB3D,EAAQmC,EAAGC,GACjCpC,EAAO+C,GAAaZ,EAAGC,GACvBpC,EAAOgD,GAAeb,EAAGC,EAAKJ,KAAKE,EACrC,CAEA0B,GAAW5D,EAAgBmC,EAAYC,GACrC,IAAMyB,EAAmB,IAAZ1B,EAAEE,EACf,IAAKwB,GAAgB,OAARzB,EAAc,OAC3B,IAAMM,EAAImB,EAAO,KAAQzB,EAAKO,KAAU,IAAImB,MAAM9D,EAAO+D,IAAWC,KAAKxB,GACrEF,EAAU,OAANI,EAAaP,EAAEI,EAAYG,EAAEP,EAAEN,GAGvC,GAAIS,IAAME,GAASF,IAAMG,GAASH,IAAM2B,IAAiB,OAANvB,GAAcP,EAAEN,KAAQa,GAAI,OAAOJ,EACtFA,EAAI2B,EACJ,IACE,OAAQ3B,EAAItC,EAAOkE,GAAW/B,EAAS,OAANO,EAAa,KAAON,EACvD,SACY,OAANM,EAAYP,EAAEI,EAAYD,EACzBI,EAAEP,EAAEN,GAAQS,CACnB,CACF,CAEA6B,GAAS/B,GACPA,EAAIO,GAAQ,IACd,CAEAyB,GAAQpE,GAEN,QAAWmC,KAAKnC,EAAOqE,EAASC,MACb,OAAbnC,EAAEW,SACU,IAAZX,EAAEE,EACAF,EAAEI,IAAcE,IAAON,EAAEI,EAAY0B,GAEzCjE,EAAOuE,GAAWpC,EAAEqC,EAAMrC,EAAEE,GAAUmB,IACpC,IAAMd,EAAIc,EAAEb,GACF,OAAND,GAAcA,EAAEP,EAAEN,KAAUY,IAAOC,EAAEP,EAAEN,GAAQoC,KAI3D,UACFQ,EAAAC,OAAAvC,OAAAwC","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=class{constructor(t,l,e){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.B=[],this.Q=[],this.mt=null,this.F=-1,this.Y=s,this.je=null,this.Dt=null,this.jt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=t,this.c=e,this.s=l;let h=null===e?[null]:e.h.slice(),i="*"===l;i&&h.push(e),this.n=h.length-1,this.z=i?[]:null===e?[l]:[...e.z,l],this.h=h}_n(t){this.ht.has(t)||(this.ht.add(t),this.B.push(t),t.Q.push(this))}Do(t){this.ht.delete(t);let s=this.B;s.splice(s.indexOf(t),1)}jo(){this.getter=null,this.se=null,this.F=-1,this.Y=s,this.B.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.je=null,this.Dt=null,this.jt=null,this._=null}ee(t){let s=this;for(;null!==s;){if(s===t)return!0;s=s.c}return!1}},s=Symbol("unset"),l=Symbol("dirty"),e=Symbol("failed"),h=class{constructor(t=null){this.yt=new Map,this.Vn=t}wt(t){return this.yt.get(t)}get(s){let l=this.yt.get(s);if(void 0!==l)return l;let e=s.lastIndexOf("."),h=e<0?null:this.get(s.slice(0,e));return l=new t(s,s.slice(e+1),h),this.Vn?.(l),this.yt.set(s,l),h&&h.u.push(l),l}all(){return this.yt.values()}Lt(t){this.yt.delete(t.t)}},i=new Map;function n(t){let s=i.get(t);if(void 0!==s)return s;let l=!0,e=t.split("."),h=[];for(let t=0;t<e.length;t++){let s=e[t],i=s.charCodeAt(0);t>0&&i>=48&&i<=57?(l=!1,h.push(Number(s)),e[t]="*"):"*"===s&&h.push(-1)}if(!l)return{o:e.join("."),indexes:h};let n={o:t,indexes:null};return i.size>4095&&i.clear(),i.set(t,n),n}export{s as a,l as b,e as c,h as d,n as e};
|
|
2
|
+
//# sourceMappingURL=chunk-NITPUCPA.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as t}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{b as t}from"./chunk-JWRQLKOQ.js";import{j as e}from"./chunk-TNYNJXEC.js";var a={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1};function r(e){let r=a,s=a.tagNames,n=Object.entries(e).filter(([,t])=>void 0!==t),o=Object.entries(e.tagNames??{}).filter(([,t])=>void 0!==t);for(let[e,a]of n){let s=r[e];(!Object.hasOwn(r,e)||null===a||typeof a!=typeof s||Array.isArray(a)!==Array.isArray(s))&&t(44,["bootstrapState",e])}for(let[e,a]of o)(!Object.hasOwn(s,e)||"string"!=typeof a)&&t(44,["bootstrapState",`tagNames.${e}`]);for(let[t,e]of n)"tagNames"!==t&&(r[t]=e);for(let[t,e]of o)s[t]=e}var s=()=>a,n=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],o=new Map,i=new Map;function f(t){for(let e of Object.keys(t))o.set(e,{...t[e]});i.clear()}function l(t){return o.has(t)}function c(a,r,s){let f=`${a}${function(t,e){return`${JSON.stringify(t)}${JSON.stringify(e)}`}(r,s)}`,l=i.get(f);if(typeof l<"u")return l;let c=o.get(a);void 0===c&&function(a,r){n.includes(a)&&e(`[wcs/filter-unknown] filter not found: ${a}. "${a}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,a,r),t(501,[a],a,r)}(a,o.keys());let[m,u]=c.arity;r.length<m&&t(601,[a,m,r.length]),r.length>u&&t(602,[a,u,r.length]);let d=c.factory(r,s);return i.set(f,d),d}export{a,r as b,s as c,n as d,f as e,l as f,c as g};
|
|
2
|
+
//# sourceMappingURL=chunk-T3FN37DU.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={};function a(t,a){return null==t?a:(...e)=>{t(...e),a(...e)}}function e(t,a,e){return null==a?e:(...n)=>{let r=a(...n);return t(r)?r:e(...n)}}var n=t=>!0===t,r=t=>void 0!==t,s=t=>null!=t,l=new Set;function o(t){for(let a of t)l.has(a.name)||(l.add(a.name),a.install())}function u(a){let e=a.$features;if(null!=t.
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
var t={};function a(t,a){return null==t?a:(...e)=>{t(...e),a(...e)}}function e(t,a,e){return null==a?e:(...n)=>{let r=a(...n);return t(r)?r:e(...n)}}var n=t=>!0===t,r=t=>void 0!==t,s=t=>null!=t,l=new Set;function o(t){for(let a of t)l.has(a.name)||(l.add(a.name),a.install())}function u(a){let e=a.$features;if(null!=t.kt&&Array.isArray(e)){let a=e.filter(t=>!l.has(t));if(a.length>0)return t.kt(a)}}function f(t,a){if(!l.has(t))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${a} needs the add-on @wcstack/state/features/${t}`)}function i(a,e,n){throw new Error(`[@wcstack/state] ${a}${t.Bo?.(a,e,n)??""}`)}export{t as a,a as b,e as c,n as d,r as e,s as f,o as g,u as h,f as i,i as j};
|
|
2
|
+
//# sourceMappingURL=chunk-TNYNJXEC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hooks","chain","prev","fn","a","first","answered","r","handled","known","taken","installed","Set","installFeatures","features","f","has","name","add","install","loadFeatures","state","names","$features","load","Array","isArray","missing","filter","n","length","requireFeature","feature","what","Error","raiseError","message","subject","candidates","explain","i","d","s","u","g","c","m","w","v"],"sources":["../../../src/hooks.ts","../../../src/parser/raiseError.ts"],"sourcesContent":["/**\n * The places the core calls into add-ons (docs/state-engine-rewrite/addons-plan.ja.md §1.2).\n *\n * Add-ons ship as separate entries of the same build as the core (`features/*`): they reach\n * the core's internals directly, and the core only calls out through these slots. A slot is\n * empty until an installed feature fills it (the object starts with none: a list of null slots\n * would be the core's bytes), so a page without the feature pays one `?.` check. A feature\n * restoring a slot may set it to null.\n * Slots are added with the first feature that needs them; several features share one through\n * chain / first. The slots `element` and `detail` keep their names (a DevTools-facing field and a DOM\n * name share them); the others are shortened by the build. An empty slot is read through\n * Object.prototype: a page that polluted it (a value under `element`, say) breaks the core loudly\n * there, as it does wherever the core reads a plain object's keys (`$behavior`); not defended.\n */\nimport type { Engine } from \"./engine\";\nimport type { Pattern } from \"./pattern\";\nimport type { StateList, StateRow } from \"./list\";\nimport type { Binding, RowPlan, Spec } from \"./dom/view\";\n\nexport interface Hooks {\n /** Diagnostics: extra text for an error message (did-you-mean, lint pointer, how to fix). */\n explain?: ((message: string, subject?: string, candidates?: Iterable<string>) => string) | null;\n /** Diagnostics: the full sentence of a numbered core message (`src/messages.ts`). */\n render?: ((id: number, args: readonly unknown[]) => string) | null;\n /**\n * A write before it is applied (`element`: an element wrote it back, not code); true = the\n * add-on handled it ($listKeys, a read-only mount dropping an element's write).\n */\n beforeWrite?: ((engine: Engine, p: Pattern, row: StateRow | null, value: unknown, element: boolean) => boolean) | null;\n /** A write landed: `direct` for a data write (then `old` is the value before, `value` the new one). */\n /** `element`: an element wrote it (a binding's write-back or its initial value), not code. */\n written?: ((engine: Engine, p: Pattern, row: StateRow | null, old: unknown, value: unknown, direct: boolean, element?: boolean) => void) | null;\n /** A change reached a getter occurrence whose cached value was current (it may now differ). */\n getterReached?: ((engine: Engine, g: Pattern, row: StateRow | null) => void) | null;\n /** A list was reconciled with a new value; `old` are its rows before. */\n listSynced?: ((engine: Engine, list: StateList, old: StateRow[]) => void) | null;\n /** A drain ended (after its report and `$renderedCallback`). */\n drained?: ((engine: Engine) => void) | null;\n /** A state object was received (construction, or a re-set before it replaces the old one). */\n declare?: ((engine: Engine, target: Record<string, any>) => void) | null;\n /**\n * A root engine's lifecycle: \"mounting\" (created, its page not bound yet), \"back\" (its `<wcs-state>`\n * connected again, before `$connectedCallback` runs again: it holds its root again, unless another\n * one bound it meanwhile), \"connected\" (after `$connectedCallback`, and on reconnect), \"disconnected\",\n * \"reset\" (after a re-set).\n */\n element?: ((engine: Engine, phase: \"mounting\" | \"back\" | \"connected\" | \"disconnected\" | \"reset\") => void) | null;\n /**\n * A `<wcs-state>` an add-on takes over instead of it becoming a root (a volume, a DCC\n * definition): asked when it connects; the core then only loads its state.\n */\n claim?: ((el: HTMLElement, root: Node) => Claimed | null) | null;\n /** A `$` name the core does not know. */\n dollar?: ((engine: Engine, key: string) => unknown) | null;\n /** A binding failed to apply (reported after the drain, before `$errorCallback` / the console). */\n failed?: ((engine: Engine, error: unknown, binding: Binding) => void) | null;\n /**\n * A plain property binding on a custom element, made and not yet registered or applied (a\n * component mount's wiring, `state.x: path`); true = an add-on took it over.\n */\n hostBinding?: ((binding: Binding, ro: boolean) => boolean) | null;\n /** An element whose content an add-on binds (a Light DOM component): the walker leaves it. */\n componentScope?: ((el: Element) => boolean) | null;\n /**\n * The page walker replaced a structural template with its anchor (`source` is the template),\n * bound a mustache text node (`source` is its expression), or is about to bind an element\n * (`source` is its specs, which the hook may take some out of): SSR records the first two, and\n * on the server leaves `outerHTML:` to the client.\n */\n ssrMark?: ((engine: Engine, node: Node, source: Element | string | Spec[]) => void) | null;\n /**\n * A block is about to be cloned from `plan` for the view anchored at `anchor`: an add-on may\n * hand over existing nodes instead (SSR hydration) — the block's top-level nodes, already where\n * the block renders (the view inserts nothing), with the plan's nodes in them in `plan.scratch`.\n */\n adopt?: ((plan: RowPlan, anchor: Node, isFor: boolean) => ChildNode[] | null) | null;\n /**\n * A Light DOM component's engine is about to bind `root` (its host): SSR hands over the server's\n * nodes there too; the function returned is called when the walk is done.\n */\n adoptScope?: ((root: Node, engine: Engine) => (() => void) | null) | null;\n /** A path a binding (or, with `watch`, a `$watch` key) names: diagnostics checks it exists. */\n declared?: ((engine: Engine, p: Pattern, watch?: boolean) => void) | null;\n /** `<wcs-state>` was defined in `registry`: an add-on defines its own tags there (`<wcs-ssr>`). */\n tags?: ((registry: CustomElementRegistry) => void) | null;\n /** A wc-bindable property's event read with the default getter (`e.detail`): diagnostics checks its shape. */\n detail?: ((el: Element, name: string, detail: unknown) => void) | null;\n /** The handler `path` of a delegated `on<type>:` threw (reported already): diagnostics says when `currentTarget` is why. */\n handlerThrew?: ((engine: Engine, path: string, type: string) => void) | null;\n /**\n * `command.<method>:` on an element with no wc-bindable declaration: how a native element's\n * method is called (native-commands), or null for a custom element. The add-on throws for a\n * method a native element may not be commanded to run.\n */\n nativeCommand?: ((el: Element, method: string) => NativeCall | null) | null;\n /** The split auto entry: loads and installs add-ons of its build by name (a state's `$features`). */\n load?: ((names: string[]) => Promise<void>) | null;\n /**\n * An event an add-on (or the core) reports for the DevTools protocol (a `$watch` handler fired or\n * threw, a `$watch` chain or an update loop cut, a path that does not resolve): `event` is the\n * protocol's payload, its keys quoted (`{ \"type\": \"state:watch-fired\", \"path\": … }`). Called as\n * `hooks.noticed?.(engine, {…})`, the payload is built only while the slot is filled.\n */\n noticed?: ((engine: Engine, event: Record<string, unknown>) => void) | null;\n}\n\n/** Calls a native element's command method with what the token was emitted with. */\nexport type NativeCall = (target: Element, args: unknown[]) => unknown;\n\n/** What an add-on does with a `<wcs-state>` it claimed. */\nexport interface Claimed {\n /** Where the state comes from, when not from the element's own sources. */\n load?(): Promise<Record<string, any>>;\n /**\n * The loaded state; `connectedCallbackPromise` resolves when this is done, and `built` is called\n * once its bindings are built (before `$connectedCallback`: getBindingsReady resolves then, as for a\n * root). When it (or the load) throws, the core reports the failure and rejects the promise with\n * it — a DCC definition, a component mount: 3.x's README promises it for their configuration\n * errors, and 4.0 also rejects where 3.x did not (a component whose root failed: 3.x left it\n * unsettled; a second mount in one scope: 3.x resolved it) — or resolves it, for a lenient claim.\n */\n start(state: Record<string, any>, built: () => void): Promise<void> | void;\n /** A failure resolves `connectedCallbackPromise` instead (a volume settles without grafting, as 3.x). */\n lenient?: boolean;\n connected(): void;\n disconnected(): void;\n /** `setInitialState` after the start. */\n reset(state: Record<string, any>): void;\n}\n\nexport const hooks: Hooks = {};\n\ntype HookFn = (...args: any[]) => any;\n\n/*\n * A feature fills a slot by assigning it (`hooks.written = chain(hooks.written, fn)`), never by\n * its name as a string: the slot names are shortened by the build (mangle.mjs) like any internal\n * property.\n */\n\n/** A slot several features share: `fn` runs after whatever is there. */\nexport function chain<F extends HookFn>(prev: F | null | undefined, fn: F): F {\n return prev == null ? fn : ((...a: unknown[]) => { prev(...a); fn(...a); }) as F;\n}\n\n/** A slot whose first answer wins (`answered` tells one): `fn` is asked when what is there does not answer. */\nexport function first<F extends HookFn>(answered: (r: unknown) => boolean, prev: F | null | undefined, fn: F): F {\n return prev == null ? fn : ((...a: unknown[]) => { const r = prev(...a); return answered(r) ? r : fn(...a); }) as F;\n}\n\n/** `beforeWrite`: the first feature that handles the write. */\nexport const handled = (r: unknown): boolean => r === true;\n/** `dollar`: the first feature that knows the `$` name (a value, possibly null or false). */\nexport const known = (r: unknown): boolean => r !== undefined;\n/** `claim`: the first feature that takes the `<wcs-state>`. */\nexport const taken = (r: unknown): boolean => r != null;\n\n/** An add-on entry: `installFeatures([temporal, diagnostics])` before the state is defined. */\nexport interface Feature {\n readonly name: string;\n install(): void;\n}\n\nconst installed = new Set<string>();\n\nexport function installFeatures(features: readonly Feature[]): void {\n for (const f of features) {\n if (installed.has(f.name)) continue;\n installed.add(f.name);\n f.install();\n }\n}\n\n/**\n * A state's `$features` before its engine is made: the missing add-ons, loaded where an entry can\n * load them (`hooks.load`); undefined when there is nothing to wait for. The engine then checks\n * every name (a bundle or the full build only checks).\n */\nexport function loadFeatures(state: Record<string, any>): Promise<void> | undefined {\n const names = state.$features;\n if (hooks.load != null && Array.isArray(names)) {\n const missing = names.filter((n) => !installed.has(n));\n if (missing.length > 0) return hooks.load(missing);\n }\n}\n\n/** The barrier: a declaration that needs a feature the page did not install. */\nexport function requireFeature(feature: string, what: string): void {\n if (!installed.has(feature)) {\n throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${what} needs the add-on @wcstack/state/features/${feature}`);\n }\n}\n","import { hooks } from \"../hooks\";\n\n/**\n * Throws `[@wcstack/state] <message>`. The core's messages state the fact (a number and values); the\n * diagnostics add-on, when installed, appends the guidance (the nearest of `candidates` to\n * `subject`, how to fix it, the lint pointer).\n */\nexport function raiseError(message: string, subject?: string, candidates?: Iterable<string>): never {\n throw new Error(`[@wcstack/state] ${message}${hooks.explain?.(message, subject, candidates) ?? \"\"}`);\n}\n"],"mappings":"AAkIO,IAAMA,EAAe,CAAC,EAWtB,SAASC,EAAwBC,EAA4BC,GAClE,OAAe,MAARD,EAAeC,MAAUC,KAAmBF,KAAQE,GAAID,KAAMC,EAAI,CAC3E,CAGO,SAASC,EAAwBC,EAAmCJ,EAA4BC,GACrG,OAAe,MAARD,EAAeC,MAAUC,KAAmB,IAAMG,EAAIL,KAAQE,GAAI,OAAOE,EAASC,GAAKA,EAAIJ,KAAMC,EAAI,CAC9G,CAGO,IAAMI,EAAWD,IAA8B,IAANA,EAEnCE,EAASF,QAA8B,IAANA,EAEjCG,EAASH,GAA6B,MAALA,EAQxCI,EAAY,IAAIC,IAEf,SAASC,EAAgBC,GAC9B,QAAWC,KAAKD,EACVH,EAAUK,IAAID,EAAEE,QACpBN,EAAUO,IAAIH,EAAEE,MAChBF,EAAEI,UAEN,CAOO,SAASC,EAAaC,GAC3B,IAAMC,EAAQD,EAAME,UACpB,GAAkB,MAAdvB,EAAMwB,IAAgBC,MAAMC,QAAQJ,GAAQ,CAC9C,IAAMK,EAAUL,EAAMM,OAAQC,IAAOlB,EAAUK,IAAIa,IACnD,GAAIF,EAAQG,OAAS,EAAG,OAAO9B,EAAMwB,GAAKG,EAC5C,CACF,CAGO,SAASI,EAAeC,EAAiBC,GAC9C,IAAKtB,EAAUK,IAAIgB,GACjB,MAAM,IAAIE,MAAM,gDAAgDD,8CAAiDD,IAErH,CCxLO,SAASG,EAAWC,EAAiBC,EAAkBC,GAC5D,MAAM,IAAIJ,MAAM,oBAAoBE,IAAUpC,EAAMuC,KAAUH,EAASC,EAASC,IAAe,KACjG,QAAAE,OAAApC,OAAAqC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC,OAAAC","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as t,c as e,d as s}from"./chunk-GBBBRPZR.js";import{p as i,q as n}from"./chunk-467LYA2V.js";import{f as o}from"./chunk-ZJYPRSTO.js";import{a,b as r}from"./chunk-T3FN37DU.js";import{a as l,b as c}from"./chunk-JWRQLKOQ.js";import{a as h,h as u,i as d}from"./chunk-TNYNJXEC.js";var m=0,f=new WeakMap;function p(t,e=t.getRootNode()){f.set(e,[...f.get(e)??[],t].filter((t,e,s)=>t.isConnected&&s.lastIndexOf(t)===e))}function b(t){let e=f.get(t)??[],s=e.filter(e=>e.getRootNode()===t);return Promise.any(s.map(t=>t.initializePromise.then(()=>t.V||t.connectedCallbackPromise))).then(()=>{},i=>s.length?f.get(t)!==e?b(t):Promise.reject(i.errors[0]):void 0)}var g=typeof HTMLElement>"u"?class{}:HTMLElement,w=class extends g{constructor(){super(),this.engine=null,this.Ln=!1,this.Ye=!1,this.U=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((t,e)=>{this.cn=t,this.No=e}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(t=>{this.an=t})}static{this.getBindingsReady=b}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();p(this);let e=this.engine;if(null!==e){let s=e.root;s===this.getRootNode()&&!i.has(s)&&i.set(s,e),t(),h.element?.(e,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&h.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),s=h.ut?.(this,e);if(s)return this.Ge=s,!s.Po&&this.parentNode instanceof ShadowRoot&&p(this),void(void 0===s.kt?this.Ro():s.kt()).then(t=>(this.loaded=!0,s.start(t,()=>this.To()))).then(()=>{this.an(),this.cn()},t=>this.Pt(t,s.Po));this.start(e),p(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let t=this.engine;if(null===t)return;let e=t.root;i.get(e)===t&&i.delete(e),p(this,e),this.xo("$disconnectedCallback",51),h.element?.(t,"disconnected")}setInitialState(t){if(this.Ye&&c(14),this.loaded)this.Ge.reset(t);else if(null===this.engine)if(null!==this.un){let e=this.un;this.un=null,e(t)}else this.U=t;else this.engine.reset(t)}createState(t,e){let s=this.engine;null===s&&c(15),"readonly"===t&&s.Be++;try{e(s.proxy)}finally{"readonly"===t&&s.Be--}}async createStateAsync(t,e){let s=this.engine;null===s&&c(15),await e("writable"===t?s.proxy:new Proxy(s.proxy,{get(t,e,s){let i=Reflect.get(t,e,s);return"$setAll"===e||"$resolve"===e?(...t)=>(t.length>2&&c(8),i(...t)):i},set(){c(8)}}))}async Ro(){await 0;let t=this.getAttribute("state");if(null!==t){let e=e=>[...e.querySelectorAll('script[type="application/json"]')].find(e=>e.id===t),s=e(this.getRootNode())??e(document);return void 0===s?Promise.reject(new Error(`[@wcstack/state] ${l(16,[t])}`)):Promise.resolve(JSON.parse(s.textContent||"{}"))}let e=this.getAttribute("src");if(null!==e)return async function(t){let e=new URL(t,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(e)){let s=await fetch(e);return s.ok||c(13,[t,s.status]),await s.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(e)??e))).default??{}}(e);let s=this.getAttribute("json");if(null!==s)return Promise.resolve(JSON.parse(s));let i=this.querySelector('script[type="module"]');return null!==i?async function(t){let e=!1,s=t=>{t.effectiveDirective.startsWith("script-src")&&(e=!0)};document.addEventListener("securitypolicyviolation",s);let i="function"==typeof URL.createObjectURL,n=i?URL.createObjectURL(new Blob([t.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${t.text}\n//${++m}`);try{return(await(import(n))).default??{}}catch(t){throw await new Promise(t=>setTimeout(t)),new Error(`[@wcstack/state] ${e?l(42):l(43,[t instanceof Error?t.message:String(t)])}`,{cause:t})}finally{document.removeEventListener("securitypolicyviolation",s),i&&URL.revokeObjectURL(n)}}(i):null!==this.U?Promise.resolve(this.U):new Promise(t=>{this.un=t})}async start(e){try{let a=e.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||a?.hasAttribute("data-wc-definition"))&&d("scopes","<wcs-state>");let r=await this.Ro(),l=u(r);if(l&&await l,this.getRootNode()!==e)return this.U=r,this.Ln=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&d("ssr","enable-ssr");let m=i.get(e)?.element;m?.isConnected&&(m.V||m.Ge)&&c(47);let f=new o(r,new s);f.element=this,this.engine=f,h.element?.(f,"mounting"),n(f,e),t(),f.Nn(),this.To(),await f.$e("$connectedCallback"),this.isConnected&&h.element?.(f,"connected"),this.cn()}catch(t){this.Ye=!this.V,this.Pt(t)}}To(){this.V=!0,this.an()}Pt(t,e){this.ze(this.V?50:49,t),this.an(),e?this.cn():this.No(t)}ze(t,e){let s=["mount","bind-component","state","src"].flatMap(t=>this.hasAttribute(t)?[t,this.getAttribute(t)]:[]);console.error(`[@wcstack/state] ${l(t,[this.localName,...s])}`,e)}xo(t,e,s){(async()=>this.engine.$e(t))().then(s,t=>this.ze(e,t))}},y=[];function k(){return(y=y.filter(t=>t.deref())).map(t=>t.deref())}function v(t,s){t&&r(t),function(t=customElements){e(),k().includes(t)||y.push(new WeakRef(t));let s=a.tagNames.state;void 0===t.get(s)&&t.define(s,class extends w{}),h.Ao?.(t)}(s)}var R=t=>b(t);export{b as a,g as b,k as c,v as d,R as e};
|
|
2
|
+
//# sourceMappingURL=chunk-ULMHOGJ2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["loads","readyByRoot","WeakMap","enroll","el","root","getRootNode","set","get","filter","e","i","a","isConnected","lastIndexOf","getBindingsReady","list","els","Promise","any","map","initializePromise","then","bound","connectedCallbackPromise","length","reject","errors","HTMLElementBase","HTMLElement","WcsState","constructor","super","this","engine","started","failed","initial","claimed","loaded","receiveInitial","resolve","resolveConnected","rejectConnected","catch","resolveInitialize","hasConnectedCallbackPromise","connectedCallback","connected","engines","has","drainBinds","hooks","element","rerun","claim","lenient","parentNode","ShadowRoot","load","loadState","state","start","built","fail","disconnectedCallback","disconnected","delete","setInitialState","raise","reset","receive","createState","mutability","callback","readonlyDepth","proxy","createStateAsync","Proxy","t","k","receiver","v","Reflect","id","getAttribute","find","r","querySelectorAll","x","script","document","Error","text","JSON","parse","textContent","src","async","url","URL","baseURI","href","test","res","fetch","ok","status","json","globalThis","Symbol","for","default","loadSrc","querySelector","blocked","seen","effectiveDirective","startsWith","addEventListener","blob","createObjectURL","Blob","type","encodeURIComponent","setTimeout","message","String","cause","removeEventListener","revokeObjectURL","loadInnerScript","host","hasAttribute","requireFeature","loading","loadFeatures","other","Engine","DirtyStrategy","mount","watchRendered","callHook","report","at","flatMap","n","console","error","localName","name","refs","registries","deref","bootstrapState","partial","registry","setConfig","customElements","installBinder","includes","push","WeakRef","tag","config","tagNames","define","tags","buildBindings","R","j","I","z","q"],"sources":["../../../src/element.ts"],"sourcesContent":["import type { IWritableConfig } from \"./public/types\";\nimport { Engine } from \"./engine\";\nimport { engines, mount } from \"./dom/mount\";\nimport { drainBinds, installBinder } from \"./dom/binder\";\nimport { DirtyStrategy } from \"./strategy/dirty\";\nimport { config, setConfig } from \"./config\";\nimport type { Strategy } from \"./strategy/types\";\nimport { raise, M, text } from \"./messages\";\nimport { hooks, loadFeatures, requireFeature, type Claimed } from \"./hooks\";\n\nlet makeStrategy: () => Strategy = () => new DirtyStrategy();\n\n/** Chooses the invalidation strategy of every engine created from now on. */\nexport function configure(factory: () => Strategy): void {\n makeStrategy = factory;\n}\n\nlet loads = 0;\n\nasync function loadInnerScript(script: HTMLScriptElement): Promise<Record<string, any>> {\n // an import a Content-Security-Policy blocked rejects without saying why: the violation event\n // is the only witness (docs/csp.md §9)\n let blocked = false;\n const seen = (e: SecurityPolicyViolationEvent): void => {\n if (e.effectiveDirective.startsWith(\"script-src\")) blocked = true;\n };\n document.addEventListener(\"securitypolicyviolation\", seen);\n // a server (@wcstack/server) removes createObjectURL: a data: URL, unique so no load is cached\n const blob = typeof URL.createObjectURL === \"function\";\n const url = blob\n ? URL.createObjectURL(new Blob([script.text], { type: \"application/javascript\" }))\n : \"data:text/javascript;charset=utf-8,\" + encodeURIComponent(`${script.text}\\n//${++loads}`);\n try {\n const mod = await import(/* @vite-ignore */ url);\n return (mod.default ?? {}) as Record<string, any>;\n } catch (e) {\n // Firefox fires the violation a task after the rejection (Chromium and WebKit before it)\n await new Promise((r) => setTimeout(r));\n throw new Error(`[@wcstack/state] ${blocked ? text(M.InlineBlocked) : text(M.InlineFailed, [e instanceof Error ? e.message : String(e)])}`, { cause: e });\n } finally {\n document.removeEventListener(\"securitypolicyviolation\", seen);\n if (blob) URL.revokeObjectURL(url);\n }\n}\n\nasync function loadSrc(src: string): Promise<Record<string, any>> {\n const url = new URL(src, document.baseURI).href;\n if (/\\.json(?:[?#]|$)/.test(url)) {\n const res = await fetch(url);\n if (!res.ok) raise(M.LoadFailed, [src, res.status]);\n return (await res.json()) as Record<string, any>;\n }\n // on the server, the renderer's local module for the URL (protocol/ssr-snapshot.ts, resolveModule):\n // Node's loader reads no http: URL\n const mod = await import(/* @vite-ignore */ (globalThis as any)[Symbol.for(\"wcstack.ssr.resolveModule\")]?.(url) ?? url);\n return (mod.default ?? {}) as Record<string, any>;\n}\n\n/**\n * The root `<wcs-state>` elements of each root node (and the one a component mount or a DCC definition\n * has in its shadow root): a new list whenever one connects, without the ones no longer in the page.\n */\nconst readyByRoot = new WeakMap<Node, WcsState[]>();\n\n/**\n * Puts `el` among the `<wcs-state>` elements of `root` (a new list, without the ones that left) — or,\n * taken out of it, takes it off: the list holds nothing of a page that went.\n */\nfunction enroll(el: WcsState, root: Node = el.getRootNode()): void {\n readyByRoot.set(root, [...(readyByRoot.get(root) ?? []), el].filter((e, i, a) => e.isConnected && a.lastIndexOf(e) === i));\n}\n\n/**\n * Resolves when the bindings of `root` are built — by any `<wcs-state>` in it now, whatever its\n * `$connectedCallback` does then, as 3.x — and rejects, with the first failure, only when every one\n * failed before building them. A stray one (a second root, #47; one that fails to load) changes\n * nothing while another binds the root; one taken out of the page (or moved to another root) counts\n * no more (a root replaced: the new one decides). With none in it — none ever, or only ones that left —\n * it resolves at once: there is nothing to wait for (a page without state).\n */\nexport function getBindingsReady(root: Node): Promise<void> {\n const list = readyByRoot.get(root) ?? [];\n const els = list.filter((e) => e.getRootNode() === root);\n return Promise.any(els.map((el) => el.initializePromise.then((): unknown => el.bound || el.connectedCallbackPromise))).then(\n () => {},\n // none, or every one failed: one connected since (the list is a new one) may still bind the root\n // (quoted: `errors` is a name the build shortens, an AggregateError's is not)\n (e: AggregateError) => (els.length ? readyByRoot.get(root) !== list ? getBindingsReady(root) : Promise.reject(e[\"errors\"][0]) : undefined),\n );\n}\n\n/**\n * The base of the package's elements: HTMLElement, or — where there is none (Node without a DOM)\n * — an inert class, so the entries can be imported headless (a tool reading the manifest, a\n * server framework importing at the top level), as 3.x. Making an element stays a browser's.\n */\nexport const HTMLElementBase = (typeof HTMLElement === \"undefined\" ? class {} : HTMLElement) as typeof HTMLElement;\n\n/**\n * `<wcs-state>` — one engine per element, bound to the element's root node.\n * State resolution order: `state` (id of a JSON script) → `src` → `json` → inner\n * `<script type=\"module\">` → wait for `setInitialState()`.\n */\nexport class WcsState extends HTMLElementBase {\n static getBindingsReady = getBindingsReady;\n /** Servers (@wcstack/server) wait on connectedCallbackPromise when this is set. */\n static hasConnectedCallbackPromise = true;\n\n engine: Engine | null = null;\n readonly connectedCallbackPromise: Promise<void>;\n /**\n * Resolves once the state is loaded and bound (before `$connectedCallback`) — and also when\n * initialization fails: the failure is delivered on connectedCallbackPromise.\n */\n readonly initializePromise: Promise<void>;\n private resolveInitialize!: () => void;\n private resolveConnected!: () => void;\n private rejectConnected!: (e: unknown) => void;\n private started = false;\n /** Initialization failed before the page was bound: `setInitialState` refuses (#14). */\n private failed = false;\n private initial: Record<string, any> | null = null;\n /** Taken over by an add-on (a volume, a DCC definition): it never becomes a root. */\n private claimed: Claimed | null = null;\n /** A claimed element's state is loaded: `setInitialState` from now on is the add-on's re-set. */\n private loaded = false;\n /** The root's bindings are built (getBindingsReady resolves, whatever `$connectedCallback` does). */\n bound?: boolean;\n private receiveInitial: ((state: Record<string, any>) => void) | null = null;\n\n constructor() {\n super();\n this.connectedCallbackPromise = new Promise<void>((resolve, reject) => {\n this.resolveConnected = resolve;\n this.rejectConnected = reject;\n });\n this.connectedCallbackPromise.catch(() => {});\n this.initializePromise = new Promise<void>((resolve) => {\n this.resolveInitialize = resolve;\n });\n }\n\n connectedCallback(): void {\n if (this.started) {\n if (this.claimed !== null) {\n this.claimed.connected();\n return;\n }\n enroll(this);\n const engine = this.engine;\n if (engine !== null) {\n // back in the page: it holds its root again (unless another <wcs-state> bound it meanwhile),\n // binds what was handed over while it was out, and the add-ons hear of it (the volumes that\n // connected meanwhile graft) — then $connectedCallback runs again\n const root = engine.root;\n if (root === this.getRootNode() && !engines.has(root)) engines.set(root, engine);\n drainBinds();\n hooks.element?.(engine, \"back\");\n this.rerun(\"$connectedCallback\", M.ConnectedFailed, () => {\n if (this.isConnected) hooks.element?.(engine, \"connected\");\n });\n }\n return;\n }\n this.started = true;\n const root = this.getRootNode();\n const claimed = hooks.claim?.(this, root);\n if (claimed) {\n this.claimed = claimed;\n // the `<wcs-state>` of the shadow root it binds (a component's, a DCC definition's) is that\n // root's, as 3.x: getBindingsReady there waits for it — until its bindings are built, as a\n // root's — and fails with it (a volume never fails)\n if (!claimed.lenient && this.parentNode instanceof ShadowRoot) enroll(this);\n void (claimed.load === undefined ? this.loadState() : claimed.load()).then((state) => {\n this.loaded = true;\n return claimed.start(state, () => this.built());\n }).then(() => {\n this.resolveInitialize();\n this.resolveConnected();\n }, (e) => this.fail(e, claimed.lenient));\n return;\n }\n void this.start(root);\n enroll(this);\n }\n\n disconnectedCallback(): void {\n if (this.claimed !== null) {\n this.claimed.disconnected();\n return;\n }\n const engine = this.engine;\n if (engine === null) return;\n // out of the page, it lets go of its root (it holds it again when it is back): what outlives the\n // page's content — its root node, the document — does not keep its state and the DOM it bound\n // (a root that failed before its mount has none: enroll takes the root it is in now)\n const root = engine.root;\n if (engines.get(root!) === engine) engines.delete(root!);\n enroll(this, root);\n this.rerun(\"$disconnectedCallback\", M.DisconnectedFailed);\n hooks.element?.(engine, \"disconnected\");\n }\n\n /**\n * Supplies the initial state; on an initialized element, replaces the whole state and\n * re-applies every binding to it before returning (not a write: no `$renderedCallback`).\n */\n setInitialState(state: Record<string, any>): void {\n if (this.failed) raise(M.ElementFailed);\n // (until a claimed element's state is loaded, this supplies it like a root's)\n if (this.loaded) {\n this.claimed!.reset(state);\n return;\n }\n if (this.engine !== null) {\n this.engine.reset(state);\n return;\n }\n if (this.receiveInitial !== null) {\n const receive = this.receiveInitial;\n this.receiveInitial = null;\n receive(state);\n } else {\n this.initial = state;\n }\n }\n\n /** Runs `callback` with a state proxy; its writes are applied in the next drain. */\n createState(mutability: \"readonly\" | \"writable\", callback: (state: Record<string, any>) => void): void {\n const engine = this.engine;\n if (engine === null) raise(M.NotInitialized);\n if (mutability === \"readonly\") engine.readonlyDepth++;\n try {\n callback(engine.proxy);\n } finally {\n if (mutability === \"readonly\") engine.readonlyDepth--;\n }\n }\n\n /** `createState` whose callback may await; a readonly proxy stays readonly across its awaits. */\n async createStateAsync(mutability: \"readonly\" | \"writable\", callback: (state: Record<string, any>) => Promise<void>): Promise<void> {\n const engine = this.engine;\n if (engine === null) raise(M.NotInitialized);\n await callback(mutability === \"writable\" ? engine.proxy : new Proxy(engine.proxy, {\n // as in createState(\"readonly\"), the writes of $setAll and $resolve (path, indexes, value) refuse;\n // read with this view as the receiver, a method comes as it is and runs on this view\n get(t, k, receiver) {\n const v = Reflect.get(t, k, receiver);\n return k === \"$setAll\" || k === \"$resolve\" ? (...a: unknown[]) => (a.length > 2 && raise(M.Readonly), v(...a)) : v;\n },\n set() {\n raise(M.Readonly);\n },\n }));\n }\n\n private async loadState(): Promise<Record<string, any>> {\n // a parser that inserts the element before its children (a server render) has added them by now\n await 0;\n const id = this.getAttribute(\"state\");\n if (id !== null) {\n // a JSON script of that id (an element of user content with the same id, earlier, is not it)\n const find = (r: Node): HTMLScriptElement | undefined =>\n [...(r as Document).querySelectorAll<HTMLScriptElement>('script[type=\"application/json\"]')].find((x) => x.id === id);\n const script = find(this.getRootNode()) ?? find(document);\n if (script === undefined) return Promise.reject(new Error(`[@wcstack/state] ${text(M.NoScript, [id])}`));\n return Promise.resolve(JSON.parse(script.textContent || \"{}\"));\n }\n const src = this.getAttribute(\"src\");\n if (src !== null) return loadSrc(src);\n const json = this.getAttribute(\"json\");\n if (json !== null) return Promise.resolve(JSON.parse(json));\n const script = this.querySelector('script[type=\"module\"]') as HTMLScriptElement | null;\n if (script !== null) return loadInnerScript(script);\n if (this.initial !== null) return Promise.resolve(this.initial);\n return new Promise((resolve) => {\n this.receiveInitial = resolve;\n });\n }\n\n private async start(root: Node): Promise<void> {\n try {\n // what an add-on serves: a volume, a component mount, a DCC definition, server rendering\n const host = (root as ShadowRoot).host;\n if (this.hasAttribute(\"mount\") || this.hasAttribute(\"bind-component\") || host?.hasAttribute(\"data-wc-definition\")) {\n requireFeature(\"scopes\", \"<wcs-state>\");\n }\n const state = await this.loadState();\n const loading = loadFeatures(state);\n if (loading) await loading;\n // taken out of its root while it loaded (the page's content replaced, or moved to another root):\n // nothing is mounted on the root it left. It starts again where it is now, or when it connects\n // again. A state given by setInitialState() is kept for that; a state= / src= / json= / inline\n // script source is read again (a fetch runs again, an inline module is evaluated again)\n if (this.getRootNode() !== root) {\n this.initial = state;\n this.started = false;\n if (this.isConnected) this.connectedCallback();\n return;\n }\n if (this.hasAttribute(\"enable-ssr\")) requireFeature(\"ssr\", \"enable-ssr\");\n // one state tree per root: another <wcs-state> already bound this root (and still does —\n // whatever its $connectedCallback did then), or a component's took it\n const other = engines.get(root)?.element as WcsState | undefined;\n if (other?.isConnected && (other.bound || other.claimed)) raise(M.SecondRoot);\n const engine = new Engine(state, makeStrategy());\n engine.element = this;\n this.engine = engine;\n hooks.element?.(engine, \"mounting\");\n mount(engine, root as Document | ShadowRoot);\n drainBinds();\n engine.watchRendered();\n this.built();\n await engine.callHook(\"$connectedCallback\");\n if (this.isConnected) hooks.element?.(engine, \"connected\");\n this.resolveConnected();\n } catch (e) {\n // (a root that bound its page and whose $connectedCallback then failed has not: re-set stays open)\n this.failed = !this.bound;\n this.fail(e);\n }\n }\n\n /** The bindings are built (before `$connectedCallback`): getBindingsReady resolves, initializePromise too. */\n private built(): void {\n this.bound = true;\n this.resolveInitialize();\n }\n\n /**\n * Initialization failed: reported once, the element (and where its state comes from) before what\n * was thrown, as 3.5 — `<wcs-state src=\"./state.js\"> failed to initialize.`, or, once its\n * bindings were built, `… $connectedCallback failed.` — and connectedCallbackPromise rejects with\n * it, or resolves for a claim that is `lenient` (a volume).\n */\n private fail(e: unknown, lenient?: boolean): void {\n this.report(this.bound ? M.ConnectedFailed : M.InitFailed, e);\n this.resolveInitialize();\n if (lenient) this.resolveConnected();\n else this.rejectConnected(e);\n }\n\n /** Reports a failure once: the element (and where its state comes from), then what was thrown. */\n private report(id: M, e: unknown): void {\n const at = [\"mount\", \"bind-component\", \"state\", \"src\"].flatMap((n) => (this.hasAttribute(n) ? [n, this.getAttribute(n)] : []));\n console.error(`[@wcstack/state] ${text(id, [this.localName, ...at])}`, e);\n }\n\n /**\n * Runs a lifecycle callback of a root that connected before (on reconnect, on disconnect) at once: a\n * failure — thrown or rejected — is reported as a first connection's is, never thrown out of the\n * element's callback.\n */\n private rerun(name: string, id: M, then?: () => void): void {\n void (async () => this.engine!.callHook(name))().then(then, (e) => this.report(id, e));\n }\n}\n\n/**\n * The registries `<wcs-state>` was defined in: an add-on installed later defines its tags there\n * too. Weak: a server creates a registry per render, and holding them would keep every render's\n * registry (and every constructor defined in it) alive.\n */\nlet refs: WeakRef<CustomElementRegistry>[] = [];\n\n/**\n * The registries still alive (dead references are dropped). A registry deref() returned stays\n * alive until the end of this job, so the second deref() of each kept reference finds it.\n */\nexport function registries(): CustomElementRegistry[] {\n refs = refs.filter((r) => r.deref());\n return refs.map((r) => r.deref()!);\n}\n\n/**\n * Registers `<wcs-state>` (and the installed add-ons' tags) in `registry` — a scoped registry\n * does not inherit the global one, so a tree using one needs its own definitions.\n */\nexport function define(registry: CustomElementRegistry = customElements): void {\n installBinder();\n if (!registries().includes(registry)) refs.push(new WeakRef(registry));\n const tag = config.tagNames.state;\n if (registry.get(tag) === undefined) registry.define(tag, class extends WcsState {});\n hooks.tags?.(registry);\n}\n\n/** Applies `config` and registers `<wcs-state>`. The core only: install the add-ons first. */\nexport function bootstrapState(partial?: IWritableConfig, registry?: CustomElementRegistry): void {\n if (partial) setConfig(partial);\n define(registry);\n}\n\n/**\n * Waits for the bindings under `root` (3.x built them here; the new engine builds them when the\n * root's `<wcs-state>` loads its state, so this only waits — the same as getBindingsReady).\n */\nexport const buildBindings = (root: Document | ShadowRoot): Promise<void> => getBindingsReady(root);\n"],"mappings":"4RAUA,IAOIA,EAAQ,EA6CNC,EAAc,IAAIC,QAMxB,SAASC,EAAOC,EAAcC,EAAaD,EAAGE,eAC5CL,EAAYM,IAAIF,EAAM,IAAKJ,EAAYO,IAAIH,IAAS,GAAKD,GAAIK,OAAO,CAACC,EAAGC,EAAGC,IAAMF,EAAEG,aAAeD,EAAEE,YAAYJ,KAAOC,GACzH,CAUO,SAASI,EAAiBV,GAC/B,IAAMW,EAAOf,EAAYO,IAAIH,IAAS,GAChCY,EAAMD,EAAKP,OAAQC,GAAMA,EAAEJ,gBAAkBD,GACnD,OAAOa,QAAQC,IAAIF,EAAIG,IAAKhB,GAAOA,EAAGiB,kBAAkBC,KAAK,IAAelB,EAAGmB,GAASnB,EAAGoB,4BAA4BF,KACrH,OAGCZ,GAAuBO,EAAIQ,OAASxB,EAAYO,IAAIH,KAAUW,EAAOD,EAAiBV,GAAQa,QAAQQ,OAAOhB,EAAE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{b as t,d as e,e as i}from"./chunk-NITPUCPA.js";import{h as l,m as s}from"./chunk-CBMAVRYG.js";import{a as n,b as r}from"./chunk-JWRQLKOQ.js";import{a as h,i as o}from"./chunk-TNYNJXEC.js";var u=Symbol.for("wcstack.trustedTypes.policy");function f(){let t=globalThis[u];return null!==t&&"object"==typeof t?t:null}function a(t){globalThis[u]=t}function c(t){return"innerHTML"===t||"outerHTML"===t||"srcdoc"===t}function d(t){if(globalThis.trustedTypes?.isHTML(t))return t;let e=null==t?"":String(t),i=f(),l=i?.createHTML;return"function"==typeof l?l.call(i,e):e}var p=class{constructor(t,e,i){this.bt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=t,this.y=e,this.E=i}},g=class{constructor(t,e){this.R=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Bt=!1,this.vt=!1,this.o=t,this.ce=e,this.n=t.n+1}},y=[],v=class{constructor(t){this.St=new Set,this.name=t}get size(){return this.St.size}subscribe(t){return this.St.add(t),()=>{this.St.delete(t)}}unsubscribe(t){return this.St.delete(t)}emit(...t){let e=[];for(let i of this.St)try{e.push(i(...t))}catch(t){e.push(void 0),console.error(`[@wcstack/state] ${n(17,[this.name])}`,t)}return e}};function b(t,e,i){if(void 0===t)return[];Array.isArray(t)||r(18,[e]);let l=new Set;for(let s of t)("string"!=typeof s||""===s)&&r(19,[e]),s===i&&r(20,[e,s,i]),l.has(s)&&r(21,[e,s]),l.add(s);return t}var m=Symbol.for("wcstack.transition-runner");function w(t){let e=globalThis[m];return null==e||"wcs-transition-runner"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.run||"function"!=typeof e.accepts||!e.accepts(t)?null:e}function $(t,e,i){let l=w(t);if(null!==l)return l.run(e,{source:t,types:i});e()}var k=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],A=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function M(t){return t.includes("**")&&s(t),t}var O=0,T=32,j=100;function S(t,e,i){let l=t.get(e);return void 0===l&&t.set(e,l=i()),l}var _=()=>new Set,E=()=>[],R=new WeakMap;function H(t){return null!==t&&"object"==typeof t&&"function"==typeof t.then}function x(t,e){return t===e||t!=t&&e!=e}function z(t,e,i){let l=t._?.get(e);void 0!==l&&l.delete(i)&&0===l.size&&t._.delete(e)}function X(t,e){for(let i=0;i<e.length;i++){if(null==t)return;t=t[e[i]]}return t}function B(t,e){for(;null!==t&&t.l.n>e;)t=t.l.ce;return null!==t&&t.l.n===e?t:null}function q(t,e,i){let l=B(t,i);return null!==l&&l.l.o===e.h[i]?l:null}var N=class{constructor(t,i){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.$t=[],this.Me=null,this.Un=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Kt=new WeakMap,this.D=0,this.Ut=0,this.yn=!1,this.qt=!1,this.zt=!1,this.Ce=0,this.qn=()=>{this.D=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(t,e)=>t(this.proxy,...e),this.Yn=[],this.He=[],this.Xn={$untracked:t=>{let e=this.X;if(null===e)return t();e.be++;try{return t()}finally{e.be--}},$eqIndex:(t,e=1)=>{let i=B(this.d,e);null===i&&r(7,[t]);let l=this.o(t);if(null!==l.getter||l.ae)return this.watchIndex(e),i.y===this.read(l,null);let s=this.X;if(null!==s){let t=s.getter,i=l.je??(l.je=[]);if(!i.some(i=>i.getter===t&&i.Gn===e)){i.push({getter:t,Gn:e});let s=t.h[e];(s.Dt??(s.Dt=[])).push({source:l,getter:t})}}return i.y===this.v(l,null)},$eq:(t,e)=>this.eq(t,e),$eqPath:(t,e)=>{let i=this.o(e);return this.eq(t,this.v(i,B(this.d,i.n)))},$dependOn:t=>{this.resolve(M(t),this.d),null!==this.X&&0===this.X.be&&this.Jn(this.rp,this.rr,this.X)},$getAll:(t,e)=>this.getAll(t,e),$setAll:(t,e,i,l)=>this.wn(t,e,i,l),$resolve:(...t)=>{let e=M(t[0]),i=t[1]??[],l=this.o(e,!0);this.bn("$resolve",e,l,i,!0);let s=this.Qn(l,i,null);if(t.length<3)return this.read(l,s);this.A(l,s,t[2])},$postUpdate:t=>{this.resolve(M(t),this.d);let e=this.rp,i=this.rr;"*"===e.s&&null!==i&&(i.E=i.l.R[i.y],R.delete(i.l.R),this.T.Xt(i)),this.vn(e,i),null!==i&&this.Zn(i,e,void 0,i.E,!1),0===e.n&&this.eo(e,void 0,void 0,!0),this.Gt(e,i,void 0,void 0,!1)}},this.T=i,this.O=new e(t=>{this.He.push(t),this.ot(t)}),this.to(t);let l=this,s={getOwnPropertyDescriptor(t,e){let i=Reflect.getOwnPropertyDescriptor(l.target,e);return i&&(i.configurable=!0),i},get(t,e,i){let s=l.target;if("symbol"==typeof e)return Reflect.get(s,e);if(36===e.charCodeAt(0))return l.rt(e);if(e.indexOf(".")<0){let t=l.O.wt(e);if(void 0===t||null===t.getter){let t=s[e];if("function"==typeof t)return i===l.proxy&&l.V?.(t)||t}if(void 0!==t&&0===t.n)return l.read(t,null)}return l.resolve(e,l.d),l.read(l.rp,l.rr)},set:(t,e,i)=>"symbol"==typeof e?Reflect.set(l.target,e,i):(l.resolve(M(e),l.d),l.A(l.rp,l.rr,i),!0)};for(let t of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])s[t]=(e,...i)=>Reflect[t](l.target,...i);this.proxy=new Proxy({},s)}o(t,e){let i=this.O.get(t);return e||(i.pn=!0),i}no(t){let e=new Set;for(let i=t;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let t of Object.getOwnPropertyNames(i)){if(e.has(t))continue;e.add(t);let l=Object.getOwnPropertyDescriptor(i,t);if(void 0===l.get&&void 0===l.set)continue;let s=this.o(t);s.getter=l.get??null,s.se=l.set??null,null!==s.getter&&s.n>0&&(s.F=this.Le++)}for(let t of this.O.all())this.ot(t)}ot(t){t.t.includes("**")&&s(t.t),("__proto__"===t.s||"prototype"===t.s)&&r(120,[t.t]);let e=t.c;t.ae=null!==e&&"*"!==t.s&&e.n===t.n&&(null!==e.getter||e.ae),null===t.getter&&this.Vo(t)}Vo(t){let e=t.t,i=t.s;if(l.test(i))t.getter=function(){return this[i]};else{let l=e.split("."),s=l.findIndex((t,e)=>e>0&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57);if(s<0||l.indexOf("*",s)>=0)return;t.getter=()=>(this.resolve(e,this.d),this.rp!==t?this.read(this.rp,this.rr):this.read(t.c,this.d)?.[i]),t.se=l=>{if(this.resolve(e,this.d),this.rp!==t)return this.A(this.rp,this.rr,l);let s=this.read(t.c,this.d);null==s&&r(4,[e,s]),s[i]=l}}t.hn=!0,t.n>0&&(t.F=this.Le++)}Ke(t,e){let i=null===t?this.oe:t.u??=new Map,l=i.get(e);return void 0===l&&i.set(e,l=new g(e,t)),e.pn=!0,this.G(l),l}oo(t){try{this.G(t)}catch(e){this.Jt(e,t.o.t,t.N?.S??null,"for")}}G(t){let e=this.v(t.o,t.ce);if(e===t.R)return;this.io(t);let i=function(t,e,i){let l=Array.isArray(e)?e:y;if(l===t.R)return null;let s=t.f,n=l.length,r=s.length,h=new Array(n),o=0;for(;o<n&&o<r&&s[o].E===l[o];)h[o]=s[o],o++;let u=r-1,f=n-1;for(;u>=o&&f>=o&&s[u].E===l[f];)h[f]=s[u],u--,f--;if(o>u)for(let e=o;e<=f;e++)h[e]=new p(t,e,l[e]);else if(o>f)for(let t=o;t<=u;t++)i.Mt(s[t]);else{let e=u<f?u:f;for(let t=o;t<=e;t++)s[t].E===l[t]&&(h[t]=s[t]);let n=new Map;for(let t=u;t>=o;t--){let i=s[t];if(t<=e&&h[t]===i)continue;let l=n.get(i.E);void 0===l?n.set(i.E,i):Array.isArray(l)?l.push(i):n.set(i.E,[l,i])}for(let e=o;e<=f;e++){if(void 0!==h[e])continue;let i,s=l[e],r=n.get(s);void 0!==r&&(Array.isArray(r)?(i=r.pop(),0===r.length&&n.delete(s)):(i=r,n.delete(s))),h[e]=i??new p(t,e,s)}for(let t of n.values())if(Array.isArray(t))for(let e of t)i.Mt(e);else i.Mt(t)}for(let t=o;t<n;t++){let e=h[t];e.y!==t&&(e.y=t,i.Lo(e))}return t.f=h,t.R=l,s}(t,e,this);if(null===i)return;if(t.R===e){let i=S(this.Kt,e,E);if(i.push(t),i.length>1)for(let t of i)t.vt=!0}h.Qt?.(this,t,i),(null!==t.N||null!==t.M)&&!t.te&&(t.te=!0,this._e.push(t),this.ve());let l=t.o.Dt;if(null!==l)for(let{source:e,getter:s}of l){let l=this.v(e,null),n=i[l],r=t.f[l];n!==r&&(void 0!==n&&n.w&&this.kn(s,n),void 0!==r&&this.kn(s,r))}}Lo(t){this.T.Ho(this,t)}Mt(t){t.w=!1;let e=t._;if(null!==e){for(let t of e)z(t.source,t.key,t.sub);t._=null}if(null!==t.u)for(let e of t.u.values()){this.io(e);for(let t of e.f)this.Mt(t)}}io(t){let e=this.Kt.get(t.R);void 0!==e&&(e.splice(e.indexOf(t)>>>0,1),t.vt=!1,1===e.length&&(e[0].vt=!1))}resolve(t,e){let l=i(t),s=this.rp=this.o(l.o,!0),n=l.indexes;this.rr=0===s.n?null:null===n?q(e,s,s.n):this.Qn(s,n,e,t)}Qn(t,e,i,l){let s=null;for(let n,r=1,h=0;r<=t.n;r++){let o=t.h[r],u=this.Ke(s,o),f=e[h++];if(f<0)f=q(i,t,r)?.y??-1;else if(l&&u.R===y&&Object(n=this.v(o,s))===n){let e=t.t.split("."),i=o.t.split(".").length;e[i]=l.split(".")[i],t=this.o(e.join("."),!0),r--;continue}if(s=u.f[f]??null,null===s)break}return this.rp=t,s}it(t,e){return 0===t.n?X(this.target,t.z):null===e?void 0:X(e.E,t.z)}read(t,e){let i=this.X;if(null!==i&&0===i.be&&this.Jn(t,e,i),null!==t.getter)return this.T.Ko(this,t,e);if(t.ae){let i=this.read(t.c,e);return i?.[t.s]}return null===t.c&&!(t.s in this.target)&&!this.tt.has(t.s)&&"then"!==t.s&&"toJSON"!==t.s&&r(301,[t.t],t.s,Object.keys(this.target)),this.it(t,e)}v(t,e){let i=this.X;if(null===i)return this.read(t,e);i.be++;try{return this.read(t,e)}finally{i.be--}}Jn(t,e,i){let l=i.getter;t._n(l),0===l.n?t.Z!==i.de&&(t.Z=i.de,i.Sn.push(t)):t.n>0&&B(e,Math.min(t.n,l.n))!==B(i.r,Math.min(t.n,l.n))&&(l.mt??(l.mt=new Set)).add(t)}Uo(t,e){for(let i=0;i<this.Ht;i++){let l=this.Un[i];l.getter===t&&l.r===e&&r(701,[t.t])}this.Ht>=128&&r(801,[t.t]);let i=this.Ht++;this.Be++;let l=this.Un[i]??={getter:t,r:e,be:0,de:0,Sn:[]};l.getter=t,l.r=e,l.be=0,l.de=++O,l.Sn.length=0;let s=this.X;this.X=l;let n=this.d;this.d=e;try{let e=t.getter.call(this.proxy);return 0===t.n&&this.qo(t,l),e}finally{this.Be--,this.Ht--,this.X=s,this.d=n,l.r=null}}qo(t,e){let i=e.de;for(let t of e.Sn)t.Z=i;t.Q=t.Q.filter(e=>e.Z===i||e.n>0||!e.ae&&Array.isArray(null!==e.getter?e.Y:this.it(e,null))||this.so(e,t))}so(t,e){return t.Do(e),this.He.push(t),!1}zo(){for(let t=this.He;t.length>0;t=this.He){this.He=[];let e=new Set;for(let i of t)if(!(i.pn||i.mn||null===i.c||i.u.length>0||i.B.length>0)&&(null===i.getter||i.hn&&i.F<0)&&null===i._){i.mn=!0,this.O.Lt(i),e.add(i.c);for(let t of i.Q)this.so(t,i)}for(let t of e)(t.u=t.u.filter(t=>!t.mn)).length||this.He.push(t)}}watchIndex(t){let e=this.X;if(null!==e&&0===e.be){let i=e.getter,l=i.h[t];if(l){let t=l.jt??(l.jt=[]);t.includes(i)||t.push(i)}}}rt(t){let e=t.charCodeAt(1);if(e>=48&&e<=57){let i=2===t.length?e-48:l.test(t)?+t.slice(1):0;return(i<1||i>128)&&r(1001,[t]),this.watchIndex(i),B(this.d,i)?.y}let i=this.Xn[t];if(void 0!==i)return i;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return h.rt?.(this,t)}eq(t,e){this.resolve(t,this.d);let i=this.rp,l=this.rr;if(null!==i.getter||i.ae||i.n>0)return x(this.read(i,l),e);let s=this.X;return null!==s&&0===s.be&&this.Yo(i,e,s),x(this.v(i,null),e)}Yo(t,e,i){let l=i.getter,s=i.r,n=null===s?this.Yn:s._??(s._=[]);for(let s=0;s<n.length;s++){let r=n[s];if(r.sub.getter===l&&r.source===t){if(x(r.key,e))return void(r.de=i.de);r.de!==i.de&&(z(t,r.key,r.sub),n.splice(s--,1))}}let r={getter:l,r:s};S(t._??=new Map,e,_).add(r),n.push({source:t,key:e,sub:r,de:i.de})}eo(t,e,i,l){this.Zt(t,s=>{let n=s._;if(null===n&&null===s.je)return;let r=s===t?[]:s.t.slice(t.t.length+1).split("."),h=X(e,r),o=X(i,r);if(null!==s.je&&this.Xo(s,h,o,l),null!==n)for(let t of l?n.keys():[h,o]){let e=n.get(t);if(void 0!==e)for(let i of e)null===i.r||i.r.w?this.T.ke(this,i.getter,i.r):z(s,t,i)}})}A(t,e,i,l=!1,s=!1){if(this.Be>0&&r(8),s||this.Ce>0?this.qt=!0:this.zt=!0,h.Ie?.(this,t,e,i,s))return;if(null!==t.se){try{this.$n(t.se,e,[i])}finally{this.Gt(t,e,void 0,void 0,!1,s)}return}null!==t.getter&&r(2,[t.t]),t.n>0&&null===e&&r(3,[t.t]);let n=t.ae?this.v(t,e):this.it(t,e);if(l||!this._t||!Object.is(n,i)||Object(i)===i){if("*"===t.s){let t=e;t.l.R[t.y]=i,R.delete(t.l.R),t.E=i,this.T.Xt(t)}else{let l=1===t.z.length?0===t.n?this.target:e.E:this.v(t.c,e);null==l&&r(4,[t.t,l]),l[t.s]=i}this.En(t,e),null!==e&&this.Zn(e,t,n,i),0===t.n&&this.eo(t,n,i),this.Gt(t,e,n,i,!0,s)}}lo(t){return(this.Kt.get(t.R)??[]).filter(e=>e.R===t.R&&(null===e.ce||e.ce.w))}Zn(e,i,l,s,n=!0){let r=e.l,h=i.t.slice(r.o.t.length+2),o=""!==h&&function(t){let e=R.get(t);if(void 0===e){let i=new Set;R.set(t,e=t.some(t=>Object(t)===t&&(i.has(t)||!i.add(t))))}return e}(r.R);if(!o&&!r.vt&&null===r.o.getter&&!r.o.B.length)return;let u=e.E,f=(t,i)=>{if(void 0===i||i===e)return;let r=this.o(`${t.o.t}.*${h}`,!0);""===h&&(i.E=s,this.T.Xt(i)),n?this.En(r,i):this.vn(r,i),this.Gt(r,i,l,s,n)};for(let t of this.lo(r))if(f(t,t.f[e.y]),o)for(let i of t.f)i.E===u&&i.y!==e.y&&f(t,i);if(""===h)return;let a=new Set([r.R]),c=t=>Array.isArray(t)&&t.includes(u),d=(e,i)=>{if(!a.has(e)&&a.add(e))for(let t of this.Kt.get(e)??[])for(let e of t.f)e.E===u&&f(t,e);for(let l of i){let i=l.Y,s=i===t;s&&(i=this.oe.get(l)?.R),(s||c(i))&&!a.has(l.B)&&a.add(l.B)&&(!s&&i!==e&&this.T.ke(this,l,null),d(i,l.B))}},p=t=>{for(let e of t.Q)if(!a.has(e)&&a.add(e))if(null!==e.getter)p(e);else if(!e.ae){let t=this.it(e,null);c(t)&&d(t,e.B)}};null!==r.o.getter?p(r.o):d(r.R,r.o.B)}vn(t,e){this.Go(t,e,t=>{this.G(t);for(let e of t.vt?this.lo(t):[t]){let t=this.o(`${e.o.t}.*`);for(let i of e.f)this.Nt(t,i),this.vn(t,i)}})}En(t,e){let i=null===e?this.oe:e.u;if(null!==i)for(let e of i.values())e.o.ee(t)&&this.G(e)}Go(t,e,i){let l=null===e?this.oe:e.u;if(null!==l)for(let e of l.values())e.o.ee(t)&&i(e)}Xo(t,e,i,l){for(let{getter:s,Gn:n}of t.je)this.ao(s.h[n],t=>{for(let n of l?t.f.keys():[e,i]){let e="number"==typeof n?t.f[n]:void 0;void 0!==e&&this.kn(s,e)}})}kn(t,e){e.l.n===t.n?this.T.ke(this,t,e):this.en(e,t,e=>this.T.ke(this,t,e))}Gt(t,e,i,l,s,n){h.re?.(this,t,e,i,l,s,n),this.Ue(t,e)}Ue(t,e){this.T.Jo(this,t,e),this.ve()}co(t){let e=this.nt.get(t);if(void 0!==e)return e;let i=Symbol(`wcs.on${t}`);this.nt.set(t,i);let l=this.root,s=this.Kn;return l.addEventListener(t,e=>{for(let n=e.target;null!==n&&n!==l;n=n.parentNode){let l=n[i];if(void 0!==l&&(l(e),e.cancelBubble))return;let r=n[s];if(void 0!==r&&r.w&&r.Qo(t,e))return}}),i}reset(t){let e=this.target,i=this.tt;for(let t of this.O.all())null===t.c&&null!==t.getter&&i.add(t.s);this.to(t);for(let t in e)"$"!==t[0]&&i.add(t);for(let e of i)e in t&&i.delete(e);for(let t of this.ue.values())for(let e of t)this.tn(e);for(let t of this.oe.values())this.uo(t);this.Me=null;try{this.Yt()}finally{this.Nn()}h.element?.(this,"reset")}to(t){for(let[e,i]of k)void 0!==t[e]&&o(i,e);let e=t.$features;if(void 0!==e){Array.isArray(e)||r(46);for(let t of e)o(t,"$features")}let i=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof i||!i||Array.isArray(i))&&r(44,["state","$behavior"]);for(let t in i)(!A.includes(t)||"boolean"!=typeof i[t])&&r(44,["$behavior",t]);let[l,s,n]=A.map(t=>i[t]??!0);void 0!==this.target&&(l!==this.Wt||s!==this._t||n!==this.Vt)&&r(45);let u=function(t,e){let i={};for(let l of b(t.$commandTokens,"$commandTokens","$command"))i[l]=e?.[l]??new v(l);return Object.freeze(i)}(t,this.commands),f=function(t,e){let i=new Map;for(let e of b(t.$eventTokens,"$eventTokens"))i.set(e,new v(e));let l=t.$on;if(void 0===l)return i;(null===l||"object"!=typeof l)&&r(22);for(let[t,s]of Object.entries(l)){let l=i.get(t);void 0===l&&r(23,[t]),"function"!=typeof s&&r(24,[t]),l.subscribe((...t)=>e(s,t))}return i}(t,this._o);this.Wt=l,this._t=s,this.Vt=n,h.fe?.(this,t),this.target=t,this.Le=0;for(let t of this.O.all())t.jo();this.Yn.length=0,this.no(t),this.commands=u,this.Oe=f}uo(t){this.oo(t);let e=this.o(`${t.o.t}.*`);for(let i of t.f)if(i.bt=null,i._=null,this.Nt(e,i),null!==i.u)for(let t of i.u.values())this.uo(t)}H(t){let e=[];for(let i=t;null!==i;i=i.l.ce)e.unshift(i.y);return e}Zo(t,e,i){let l=this.Oe.get(t);void 0===l&&r(1301,[t],t,this.Oe.keys()),l.emit(e,...this.H(i))}command(t){let e=this.commands[t];return void 0===e&&r(1302,[t],t,Object.keys(this.commands)),e}er(t,e,i){this.command(t).emit(e,...this.H(i))}tr(t,e,i){let l=t.includes(".")?this.v(this.o(t),null):this.target[t];return"function"!=typeof l&&r(5,[t]),this.$n(l,i,[e,...this.H(i)])}$n(t,e,i){let l=this.d;this.d=e;try{return t.apply(this.proxy,i)}finally{this.d=l}}Nt(t,e){if(null!==t.getter){let i=null===e?this.oe:e.u;if(null!==i)for(let e of i.values())!e.Bt&&e.o.ee(t)&&(e.Bt=!0,this.Ve.push(e))}if(null===e)return void this.Zt(t,t=>{let e=this.ue.get(t);if(void 0!==e)for(let t of e)this.tn(t)});let i=e.we;if(null!==i)for(let e=0;e<i.length;e++)i[e].o.ee(t)&&this.tn(i[e]);let l=e.N;null!==l&&null!==l.pe&&l.fo(this,t);let s=e.l.M;if(null!==s)for(let i of s){let l=i.map.get(e);void 0!==l&&null!==l.pe&&l.fo(this,t)}}xn(t,e,i){this.Zt(t,t=>{let l=t.B;for(let s=0;s<l.length;s++){let n=l[s];if(0===n.n)this.st(n,null,i);else if(null===e||0===t.n||n.h[1]!==t.h[1]||null!==n.mt&&n.mt.has(t))this.nn(n.h[n.n],t=>this.st(n,t,i));else if(n.n<=t.n){let t=B(e,n.n);null!==t&&this.st(n,t,i)}else this.en(e,n,t=>this.st(n,t,i))}})}st(t,e,i){i(t,e)&&(h.Se?.(this,t,e),this.Nt(t,e),this.xn(t,e,i))}Zt(t,e){e(t);let i=t.u;for(let t=0;t<i.length;t++)this.Zt(i[t],e)}nn(t,e){this.ao(t,t=>{for(let i of t.f)e(i)})}ao(t,e){if(0===t.n){let i=this.oe.get(t);return void(void 0!==i&&e(i))}this.nn(t.h[t.n],i=>{let l=i.u?.get(t);void 0!==l&&e(l)})}en(t,e,i){if(t.l.n===e.n)return i(t);let l=t.u?.get(e.h[t.l.n+1]);if(void 0!==l)for(let t of l.f)this.en(t,e,i)}nr(t){let e=t.r;null===e?S(this.ue,t.o,_).add(t):(e.we??(e.we=[])).push(t)}Pn(t){let e=t.r;if(null===e)return void this.ue.get(t.o)?.delete(t);let i=e.we;e.w&&null!==i&&i.splice(i.indexOf(t)>>>0,1)}tn(t){t.te||(t.te=!0,this.We.push(t),this.ve())}ve(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Rn(){for(let t of this.We)t.te=!1;for(let t of this._e)t.te=!1;for(let t of this.Ve)t.Bt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(t,e){let i=[...new Set([...this.We,...this._e,...this.Ve].map(t=>t.o.t))];console.error(`[@wcstack/state] ${n(t)}`,i),h.at?.(this,{type:"state:render-chain-limit",maxDepth:e,paths:i}),this.Rn()}Yt(){this.Et=!1;let t=this.Ut;this.Ut=0;let e=0;if(!this.qt||this.zt?this.qn():t>0?e=t:1===(e=++this.D)&&setTimeout(this.qn,0),this.qt=this.zt=!1,e>100)101===e?this.po(41,100):this.Rn();else{this.gn=!0;try{for(let t=0;this.We.length>0||this._e.length>0||this.Ve.length>0;t++){if(t>=32){this.yn?this.Rn():this.po(11,32),this.yn=!0;break}let i=this.Ve;if(i.length>0){this.Ve=[];for(let t of i)t.Bt=!1,this.oo(t)}let l=this._e,s=this.We;this._e=[],this.We=[];let n=()=>{for(let t of l){t.te=!1;for(let e of[t.N,...t.M??[]])if(null!==e&&e.w)try{e.xt()}catch(i){this.Jt(i,t.o.t,e.S,"for")}}for(let t=0;t<2;t++)for(let e=0;e<s.length;e++){let i=s[e];!i.te||null===i.D==(0===t)||(i.te=!1,(null===i.Tn||i.Tn.w)&&this.qe(i))}this.gn||(this.ze(),this.Et&&(this.Ut=e+1))},r=l.length>0||s.some(t=>null!==t.D)?$("state",n):n();void 0!==r&&r.then(void 0,t=>console.error(t))}}finally{this.gn=!1}this.qt=this.zt=!1,this.ze(),h.me?.(this),this.zo(),t>0&&this.Et&&(this.Ut=e+1)}}Pt(t,e){this.$t.push([t,e])}Jt(t,e,i,l){this.Pt(t,{o:{t:e},a:i,on:()=>l})}qe(t){try{t.apply()}catch(e){return void this.$t.push([e,t])}null!==this.Me&&this.mo(t.o,t.r)}mo(t,e){let i=S(this.Me,t.t,E);null!==e&&i.push(this.H(e))}Nn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}ze(){let t=this.Me;if(null!==t&&t.size>0){this.Me=new Map;let e,i=[...t.keys()],l={};for(let[e,i]of t)i.length>0&&(l[e]=i);this.Ce++;try{e=this.$e("$renderedCallback",[i,l])}catch(t){console.error(t)}H(e)?e.then(this.zn,t=>{this.zn(),console.error(t)}):this.Ce--}if(0===this.$t.length)return;let e=this.$t;this.$t=[];let i=this.target.$errorCallback;for(let[t,l]of e){h.Ye?.(this,t,l);let e=l.o.t,s=l.on();if("function"==typeof i)try{let i=this.$e("$errorCallback",[t,{path:e,bindingType:s,node:l.a}]);H(i)&&i.then(void 0,t=>console.error(t))}catch(t){console.error(t)}else console.error(`[@wcstack/state] ${n(12,l.name?[s,e,l.name,l.i]:[s,e])}`,t,l.a)}}$e(t,e=[]){let i=this.target[t];return"function"==typeof i?this.$n(i,null,e):void 0}ho(t,e,i){if(0===t.n)return void i(null,[]);let l=[],s=(n,r)=>{let h=t.h[n];this.read(h,r);let o=this.Ke(r,h),u=e=>{l.push(e.y),n===t.n?i(e,l):s(n+1,e),l.pop()};for(let t of n-1<e.length?[o.f[e[n-1]]]:o.f)void 0!==t&&u(t)};s(1,null)}getAll(t,e){let i=this.o(t,!0);void 0!==e&&this.bn("$getAll",t,i,e,!1);let l=e;if(void 0===l){l=[];let e=this.d;if(null!==e&&i.n>0){for(let t=1;t<=i.n;t++){let s=q(e,i,t);if(null===s)break;l.push(s.y)}0===l.length&&r(6,[t])}}let s=[];return this.ho(i,l,t=>s.push(this.read(i,t))),s}wn(t,e,i,l){Array.isArray(e)||r(9,[t]),this.Be>0&&r(8);let s=this.o(t,!0);this.bn("$setAll",t,s,e,!1);let n=[];this.ho(s,e,(t,e)=>n.push([t,e.slice()]));let h=!0===l?.spread;h&&(!Array.isArray(i)||i.length!==n.length)&&r(10,[t,n.length]);let o=0;for(let t=0;t<n.length;t++){let[e,l]=n[t],r="function"==typeof i?i(this.v(s,e),...l):h?i[t]:i;void 0!==r&&(this.A(s,e,r),o++)}return o}bn(t,e,i,l,s){let n=l.length;(n>i.n||s&&n<i.n)&&r(s?901:902,[t,e,i.n,n])}};export{w as a,T as b,j as c,H as d,B as e,N as f,u as g,f as h,a as i,c as j,d as k};
|
|
2
|
+
//# sourceMappingURL=chunk-ZJYPRSTO.js.map
|