@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.
Files changed (56) hide show
  1. package/README.ja.md +20 -10
  2. package/README.md +20 -9
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.esm.js +1 -1
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/manifest.esm.js +5 -4
  8. package/dist/split/auto.js +1 -1
  9. package/dist/split/chunks/chunk-467LYA2V.js +2 -0
  10. package/dist/split/chunks/chunk-467LYA2V.js.map +1 -0
  11. package/dist/split/chunks/{chunk-UPSLR4FS.js → chunk-CBMAVRYG.js} +2 -2
  12. package/dist/split/chunks/chunk-DUUQZITD.js +2 -0
  13. package/dist/split/chunks/{chunk-OKBVNGFK.js.map → chunk-DUUQZITD.js.map} +1 -1
  14. package/dist/split/chunks/{chunk-2RBI6DVS.js → chunk-FBBHQU7S.js} +2 -2
  15. package/dist/split/chunks/chunk-GBBBRPZR.js +2 -0
  16. package/dist/split/chunks/{chunk-BYQBV3ZC.js.map → chunk-GBBBRPZR.js.map} +1 -1
  17. package/dist/split/chunks/chunk-JWRQLKOQ.js +2 -0
  18. package/dist/split/chunks/chunk-NITPUCPA.js +2 -0
  19. package/dist/split/chunks/{chunk-CIBJLAA3.js → chunk-T3FN37DU.js} +2 -2
  20. package/dist/split/chunks/{chunk-BGUJ3HF6.js → chunk-TNYNJXEC.js} +2 -2
  21. package/dist/split/chunks/chunk-TNYNJXEC.js.map +1 -0
  22. package/dist/split/chunks/chunk-ULMHOGJ2.js +2 -0
  23. package/dist/split/chunks/chunk-ULMHOGJ2.js.map +1 -0
  24. package/dist/split/chunks/chunk-ZJYPRSTO.js +2 -0
  25. package/dist/split/chunks/chunk-ZJYPRSTO.js.map +1 -0
  26. package/dist/split/core.js +1 -1
  27. package/dist/split/features/devtools.js +1 -1
  28. package/dist/split/features/diagnostics.js +1 -1
  29. package/dist/split/features/diagnostics.js.map +1 -1
  30. package/dist/split/features/formats.js +1 -1
  31. package/dist/split/features/list-keys.js +1 -1
  32. package/dist/split/features/native-commands.js +1 -1
  33. package/dist/split/features/recursion.js +1 -1
  34. package/dist/split/features/scopes.js +1 -1
  35. package/dist/split/features/scopes.js.map +1 -1
  36. package/dist/split/features/ssr.js +1 -1
  37. package/dist/split/features/ssr.js.map +1 -1
  38. package/dist/split/features/temporal.js +1 -1
  39. package/dist/wcs-manifest.json +4 -8
  40. package/package.json +1 -1
  41. package/dist/split/chunks/chunk-3Q7LGONS.js +0 -2
  42. package/dist/split/chunks/chunk-3Q7LGONS.js.map +0 -1
  43. package/dist/split/chunks/chunk-4ECL4ITF.js +0 -2
  44. package/dist/split/chunks/chunk-4ECL4ITF.js.map +0 -1
  45. package/dist/split/chunks/chunk-BGUJ3HF6.js.map +0 -1
  46. package/dist/split/chunks/chunk-BI4645UG.js +0 -2
  47. package/dist/split/chunks/chunk-BI4645UG.js.map +0 -1
  48. package/dist/split/chunks/chunk-BYQBV3ZC.js +0 -2
  49. package/dist/split/chunks/chunk-JK3B3LLB.js +0 -2
  50. package/dist/split/chunks/chunk-OKBVNGFK.js +0 -2
  51. package/dist/split/chunks/chunk-UBGJGMSG.js +0 -2
  52. /package/dist/split/chunks/{chunk-UPSLR4FS.js.map → chunk-CBMAVRYG.js.map} +0 -0
  53. /package/dist/split/chunks/{chunk-2RBI6DVS.js.map → chunk-FBBHQU7S.js.map} +0 -0
  54. /package/dist/split/chunks/{chunk-UBGJGMSG.js.map → chunk-JWRQLKOQ.js.map} +0 -0
  55. /package/dist/split/chunks/{chunk-JK3B3LLB.js.map → chunk-NITPUCPA.js.map} +0 -0
  56. /package/dist/split/chunks/{chunk-CIBJLAA3.js.map → chunk-T3FN37DU.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"names":["editDistance","a","b","max","Math","abs","length","prev","Array","curr","j","i","cost","min","didYouMean","input","candidates","folded","toLowerCase","best","bestDistance","candidate","distance","LINT_HINT","CODES","codeOf","id","c","MOVED","was","v","String","Date","isArray","JSON","stringify","slice","NAMESPACES","element","tag","at","map","join","CSP_GUIDE","SENTENCES","p","parent","name","n","MAX_DRAIN_PASSES","MAX_RENDER_CHAIN","type","kind","src","status","detail","key","reserved","limit","fn","modifier","value","init","where","includes","l","t","keyword","prop","quote","args","f","trailing","lastIndexOf","source","mods","ns","given","api","depth","what","startsWith","method","allowed","over","loop","old","render","sentence","LINT_CODES","Set","GUIDES","RENAMED_FILTERS","inc","dec","fix","uc","lc","cap","rep","rev","pad","null","explain","message","subject","out","to","Object","hasOwn","removedFilter","re","text","m","exec","replace","_","Number","split","FORMATS_FILTER_NAMES","some","hasFilter","code","has","test","named","WeakMap","checked","due","WeakSet","settled","findDescriptor","o","x","prototype","getPrototypeOf","d","getOwnPropertyDescriptor","keysOf","k","getOwnPropertyNames","add","missing","engine","chain","q","unshift","target","segs","path","findIndex","s","indexOf","get","patterns","peek","parsePath","pattern","wildcardForm","getter","last","dropped","names","g","all","push","seg","set","schedule","setTimeout","delete","done","watch","root","querySelectorAll","config","tagNames","state","find","e","getAttribute","initializePromise","then","hooks","noticed","missingSegment","w","rowGetter","loops","lists","console","warn","check","declared","Map","esc","trustedTypesReported","failed","_engine","error","binding","TypeError","isHtmlSink","globalThis","cause","getTrustedTypesPolicy","createHTML","node","property","warnedDetail","el","reason","hasOwnProperty","call","said","localName","REMOVED_DECLARATIONS","REMOVED_APIS","$trackDependency","$untrackDependency","diagnostics","install","declare","$scan","raise","removedDeclarations","decl","$recursion","entries","anchor","repeat","endsWith","list","step","head","keys","families","filter","bad","why","raiseError","RegExp","checkRecursion","recheck","dollar","first","known","diagnostics_default"],"sources":["../../../src/diagnostics/guidance.ts","../../../src/diagnostics/messages.ts","../../../src/diagnostics/explain.ts","../../../src/features/diagnostics.ts"],"sourcesContent":["/**\n * diagnostics/guidance.ts — self-fix guidance for error messages, ported verbatim from\n * `@wcstack/state` (`errorGuidance.ts`). Only the diagnostics add-on uses it: the core's\n * messages state the fact, and the add-on appends this.\n *\n * The did-you-mean criteria (edit distance 2, ties go to the first candidate, case folded) are the\n * same as lint's suggestion, so the console, lint and the IDE never propose different names.\n */\n\n/** Insert / delete / substitute edit distance. Returns max + 1 early when the lengths differ by more than max. */\nfunction editDistance(a: string, b: string, max: number): number {\n if (Math.abs(a.length - b.length) > max) {\n return max + 1;\n }\n const prev: number[] = new Array(b.length + 1);\n const curr: number[] = new Array(b.length + 1);\n for (let j = 0; j <= b.length; j++) {\n prev[j] = j;\n }\n for (let i = 1; i <= a.length; i++) {\n curr[0] = i;\n for (let j = 1; j <= b.length; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);\n }\n for (let j = 0; j <= b.length; j++) {\n prev[j] = curr[j];\n }\n }\n return prev[b.length];\n}\n\n/**\n * The nearest candidate within edit distance 2 as ` Did you mean \"<best>\"?`, or `\"\"` when there is\n * none. An empty input (a trailing `a|` pipe) gets no suggestion.\n */\nexport function didYouMean(input: string, candidates: Iterable<string>): string {\n if (input.length === 0) {\n return \"\";\n }\n const folded = input.toLowerCase();\n let best: string | null = null;\n let bestDistance = 3;\n for (const candidate of candidates) {\n const distance = editDistance(folded, candidate.toLowerCase(), 2);\n if (distance < bestDistance) {\n best = candidate;\n bestDistance = distance;\n }\n }\n return best !== null ? ` Did you mean \"${best}\"?` : \"\";\n}\n\n/**\n * The pointer to lint. Attach it **only where lint actually detects the case** — a hint that sends\n * the author to a lint run that comes back clean costs the loop its credibility.\n */\nexport const LINT_HINT = \" Validate statically: npx @wcstack/lint <file>.\";\n","/**\n * The sentences of the core's numbered messages (src/messages.ts), in the diagnostics add-on:\n * the core carries the number and the values, this renders what the core used to say. Each\n * sentence follows its `[wcs/<code>] ` (`codeOf`: the code the hundreds of the number name).\n * `Record<M, …>` makes a number without a sentence a type error.\n */\nimport { M } from \"../messages\";\nimport { MAX_DRAIN_PASSES, MAX_INDEX_PARAM, MAX_RENDER_CHAIN } from \"../engine\";\nimport { MAX_PATH_SEGMENTS, MODIFIER_SEPARATOR, RECURSION_WILDCARD } from \"../parser/define\";\n\ntype Sentence = (...a: any[]) => string;\n\n/**\n * The code of each hundred of message numbers (\"\" = none): the code lint and the VS Code extension\n * report for the same case. The core carried this up to 4.0.0-rc.3; without this add-on a message\n * now reads as its number and values alone.\n */\nexport const CODES = [\n \"\", \"binding-syntax\", \"template-syntax\", \"binding-path-missing\", \"binding-type-expectation\",\n \"filter-unknown\", \"filter-arity\", \"getter-cycle\", \"getter-depth-exceeded\", \"index-arity\",\n \"index-param-range\", \"recursion-unsupported\", \"token-misconfigured\", \"token-undeclared\",\n \"wildcard-rank\", \"spread-no-bindable\", \"declaration-alias\", \"name-alias\",\n];\n\n/** `[wcs/<code>] ` for a message number, or \"\" when it has none. */\nexport const codeOf = (id: M): string => {\n const c = CODES[(id / 100) | 0];\n return c ? `[wcs/${c}] ` : \"\";\n};\n\n/** The options 4.0 moved from `bootstrapState` to the state's `$behavior`. */\nconst MOVED = [\"enableMustache\", \"sameValueGuard\", \"enableDirectionalInitialSync\"];\n\n/** `<tag a=\"v\" …>` from the tag and its attributes' names and values. */\n/** What a value given to a filter was (`a string (\"2026-10-13T…\")`), for the type messages. */\nconst was = (v: unknown): string =>\n v == null ? String(v)\n : v instanceof Date ? \"a Date\"\n : Array.isArray(v) ? \"an array\"\n : typeof v === \"string\" ? `a string (${JSON.stringify(v.length > 32 ? v.slice(0, 32) + \"…\" : v)})`\n : typeof v === \"object\" ? \"an object\" : `a ${typeof v} (${String(v)})`;\n/** The namespace a binding of kind 2–4 (dom/view.ts: K_CLASS, K_ATTR, K_STYLE) names its member under. */\nconst NAMESPACES = [\"\", \"\", \"class.\", \"attr.\", \"style.\"];\n\nconst element = (tag: string, at: string[]): string => `<${tag}${at.map((a, i) => (i % 2 ? `=\"${a}\"` : ` ${a}`)).join(\"\")}>`;\n\nconst CSP_GUIDE = \"https://github.com/wcstack/wcstack/blob/main/docs/csp.md\";\n\nexport const SENTENCES: Record<M, Sentence> = {\n [M.ScanRemoved]: () => \"$scan was removed (use $watch or $on)\",\n [M.GetterWithoutSetter]: (p) => `\"${p}\" is a getter without a setter`,\n [M.NoRow]: (p) => `no row for \"${p}\"`,\n [M.ParentNotObject]: (p, parent) => `cannot write \"${p}\": its parent is ${parent}`,\n [M.NotAMethod]: (name) => `\"${name}\" is not a method`,\n [M.GetAllNoCommonLevel]: (p) => `$getAll(\"${p}\"): no loop level in common with the context`,\n [M.EqIndexNoRow]: (p) => `$eqIndex(\"${p}\") needs a list row scope.`,\n [M.Readonly]: () => \"This state is readonly.\",\n [M.SetAllNeedsIndexes]: (p) => `$setAll(\"${p}\") needs indexes ([] for every match)`,\n [M.SetAllSpreadLength]: (p, n) => `$setAll(\"${p}\", …, { spread: true }) needs an array of ${n} values`,\n [M.DrainNotSettled]: () => `updates did not settle after ${MAX_DRAIN_PASSES} passes`,\n [M.RenderChain]: () => `render chain depth limit exceeded (${MAX_RENDER_CHAIN} drains that rendering itself started); bindings for this batch were not applied.`,\n // (named as written — `textContent: iso`, `class.active: x` — when the binding has a member; else its type)\n [M.BindingFailed]: (type, p, name, kind) => `binding \"${name ? (NAMESPACES[kind] ?? \"\") + name : type}: ${p}\" failed to apply.`,\n [M.LoadFailed]: (src, status) => `failed to load \"${src}\": ${status}`,\n [M.ElementFailed]: () => \"this <wcs-state> failed to initialize; create a new one\",\n [M.NotInitialized]: () => \"state is not initialized\",\n [M.NoScript]: (id) => `no <script> with id \"${id}\"`,\n [M.InlineBlocked]: () => `The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src=\"./state.js\") needs neither. See ${CSP_GUIDE}`,\n [M.InlineFailed]: (detail) => `Failed to evaluate the inline <script> of <wcs-state>: ${detail}. If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`,\n [M.TokenSubscriberThrew]: (name) => `a subscriber of token \"${name}\" threw.`,\n [M.TokenListNotArray]: (key) => `${key} must be an array of strings.`,\n [M.TokenEntryEmpty]: (key) => `${key} entries must be non-empty strings.`,\n [M.TokenEntryReserved]: (key, name, reserved) => `${key} entry \"${name}\" conflicts with the reserved namespace name \"${reserved}\".`,\n [M.TokenEntryDuplicated]: (key, name) => `${key} entry \"${name}\" is duplicated.`,\n [M.OnNotObject]: () => \"$on must be an object of handlers.\",\n [M.OnEntryUndeclared]: (name) => `$on entry \"${name}\" is not declared in $eventTokens.`,\n [M.OnEntryNotFunction]: (name) => `$on entry \"${name}\" must be a function.`,\n [M.NamingLimit]: (limit) => `view-transition naming-limit (${limit}) reached.`,\n [M.FilterOptionsRequired]: (fn) => `filter ${fn} requires at least one option`,\n [M.FilterOptionNotNumber]: (fn) => `filter ${fn} requires a number as option`,\n [M.FilterValueNotNumber]: (fn, v) => `filter ${fn} requires a number value, not ${was(v)}${typeof v === \"string\" ? ` — put |number before |${fn}, or convert it where it is read` : \"\"}`,\n [M.FilterValueNotDate]: (fn, v) => `filter ${fn} requires a date value (a Date), not ${was(v)}${typeof v === \"string\" || typeof v === \"number\" ? \" — make the Date where it is read: a getter returning new Date(…)\" : \"\"}`,\n [M.FilterStyleInvalid]: (fn, v) => `filter ${fn} takes a style of full, long, medium or short, not \"${v}\"`,\n [M.FilterCurrencyInvalid]: (v) => `filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not \"${v}\"`,\n [M.FilterValueNotArray]: (fn) => `filter ${fn} requires an array value`,\n [M.DirectionalSyncDisabled]: () => \"init=/sync= modifiers require enableDirectionalInitialSync.\",\n [M.ModifierUnknown]: (key, modifier) => `Unknown binding modifier \"${key}\" in \"${modifier}\".`,\n [M.ModifierTwice]: (key) => `Binding modifier \"${key}\" may only be specified once.`,\n [M.ModifierValue]: (key, value) => `Invalid ${key} modifier value \"${value}\".`,\n [M.EventInitNone]: () => \"Event bindings only allow init=none.\",\n [M.InitUnsupported]: (type, init) => `Binding type \"${type}\" does not support init=${init}.`,\n [M.MemberUndeclared]: (name) => `Property \"${name}\" is not declared by wcBindable.`,\n [M.InitIncompatible]: (init, name) => `init=${init} is incompatible with wcBindable member \"${name}\".`,\n [M.SyncConnectNeedsOutput]: (name) => `sync=connect requires observable property \"${name}\".`,\n [M.OptionInvalid]: (where, key) => `${where}: \"${key}\" is not one of its options, or not of the option's type.${where === \"bootstrapState\" && MOVED.includes(key) ? \" 4.0 moved it to the state's $behavior.\" : \"\"}`,\n [M.BehaviorChanged]: () => \"a re-set state may not change $behavior: create the element again.\",\n [M.SecondRoot]: () => \"a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount=\\\"path\\\"> (v1's name=\\\"…\\\" is gone: read the mounted state by its path).\",\n [M.LocaleInvalid]: (l) => `the locale \"${l}\" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use \"en\".`,\n [M.FeaturesNotArray]: () => '$features must be an array of add-on names ([\"temporal\", \"formats\"]).',\n [M.InitFailed]: (tag, ...at) => `${element(tag, at)} failed to initialize.`,\n [M.ConnectedFailed]: (tag, ...at) => `${element(tag, at)} $connectedCallback failed.`,\n [M.DisconnectedFailed]: (tag, ...at) => `${element(tag, at)} $disconnectedCallback failed.`,\n\n [M.BindTextNoColon]: (t) => `Invalid bindText: \"${t}\". Missing ':' separator between propPart and statePart.`,\n [M.StructuralTakesNoModifiers]: (t, keyword) => `\"${t}\": \"${keyword}\" takes no modifiers or filters on its left side — write \"${keyword}:\".`,\n [M.ElseTakesNoValue]: (t) => `\"${t}\": \"else\" takes no value — write \"else:\".`,\n [M.SpreadNoPath]: (t) => `Invalid spread binding \"${t}\": spread target path is required.`,\n [M.SpreadNoFilters]: (t) => `Invalid spread binding \"${t}\": filters are not allowed on spread targets.`,\n [M.LeadingDotNamespace]: (prop) => `\"${prop}\": a leading \".\" binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,\n [M.UnterminatedQuote]: (quote, args) => `unterminated ${quote} quote in the filter arguments \"(${args})\". Close the quote.`,\n [M.FilterUnclosed]: (f) => `Invalid filter format: missing closing parenthesis in \"${f}\".`,\n [M.FilterUnopened]: (f) => `Invalid filter format: missing opening parenthesis in \"${f}\".`,\n [M.FilterParenOrder]: (f) => `Invalid filter format: \")\" comes before \"(\" in \"${f}\".`,\n [M.FilterTrailing]: (f, trailing) => `\"${f}\": unexpected \"${trailing}\" after the filter's closing \")\" — separate filters with \"|\" (write \"${f.slice(0, f.lastIndexOf(\")\") + 1)}|${trailing}\").`,\n [M.FilterEmpty]: (source) => `an empty filter in \"${source}\" — remove the extra \"|\" or name the filter.`,\n [M.FilterNameHasModifiersInput]: (name, mods) => `\"${name}\" is not a filter name: a modifier list \"${MODIFIER_SEPARATOR}${mods}\" comes before the input filters, not inside one`,\n [M.FilterNameHasModifiersOutput]: (name) => `\"${name}\" is not a filter name: \"${MODIFIER_SEPARATOR}\" cannot appear in one.`,\n [M.OneModifierList]: (prop) => `\"${prop}\": a binding takes one modifier list after a single \"#\"`,\n [M.NoPropertyName]: (prop) => `\"${prop}\": the left side of a binding must name a property — write \"<property>: <path>\" (modifiers and input filters come after the name).`,\n [M.TooManySegments]: (p, n) => `\"${p}\" has ${n} path segments — the limit is ${MAX_PATH_SEGMENTS}.`,\n [M.SelectorRemoved]: (t) => `\"${t}\": the \"@name\" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount=\"...\">) and read it by its path prefix instead.`,\n [M.UnsafeSegment]: (p) => `\"${p}\": a state path cannot go through \"__proto__\" or \"prototype\" (it would reach every object's prototype).`,\n [M.ForNoFilters]: (t) => `\"${t}\": \"for:\" takes no filters — a row is \"<path>.<index>\", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it (\"for: <getter>\").`,\n [M.NamespaceNeedsName]: (t, ns) => ns === \"class\"\n ? `\"${t}\": \"class:\" needs a class name — \"class.NAME:\" toggles one class (a bare \"class:\" would set an element property named \"class\", which does nothing). To set the whole class attribute, bind \"className:\".`\n : `\"${t}\": \"attr:\" needs an attribute name — \"attr.NAME:\" sets one attribute (a bare \"attr:\" would set an element property named \"attr\", which does nothing).`,\n [M.EmptySegment]: (t) => `\"${t}\": the right side of a binding must name a state path — write \"<property>: <path>\" (a path segment cannot be empty; \".\" alone and a leading \".\" are the loop-relative shorthand).`,\n\n [M.StructuralNotSingle]: (t) => `Invalid bindText: \"${t}\". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,\n [M.ElseWithoutIf]: (type) => `\"${type}:\" must follow an \"if:\" template`,\n [M.TemplateHandedOver]: (type) => `a \"${type}:\" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,\n [M.OuterInTemplate]: (name) => `\"${name}:\" replaces its element, so it cannot be used inside a \"for\" / \"if\" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,\n\n [M.PathMissing]: (p) => `Path \"${p}\" does not exist on the state tree.`,\n\n [M.ClassNeedsBoolean]: (name, type) => `class.${name} needs a boolean, got ${type}.`,\n\n [M.FilterUnknown]: (name) => `filter not found: ${name}.`,\n\n [M.FilterTooFewArgs]: (name, min, given) => `filter \"${name}\" requires at least ${min} argument(s) (${given} given).`,\n [M.FilterTooManyArgs]: (name, max, given) => `filter \"${name}\" accepts at most ${max} argument(s) (${given} given).`,\n\n [M.GetterCycle]: (p) => `\"${p}\" depends on itself`,\n\n [M.GetterDepth]: (p) => `\"${p}\"`,\n\n [M.IndexArityExact]: (api, p, depth, n) => `${api}(\"${p}\") takes ${depth} index(es), got ${n}.`,\n [M.IndexArityAtMost]: (api, p, depth, n) => `${api}(\"${p}\") takes at most ${depth} index(es), got ${n}.`,\n\n [M.IndexParamRange]: (key) => `\"${key}\": list index parameters run from $1 to $${MAX_INDEX_PARAM}.`,\n\n [M.RecursionUnsupported]: (p) => `\"${p}\" uses \"${RECURSION_WILDCARD}\", which is not accepted here.`,\n\n [M.CommandRightSide]: (prop, p) => `\"${prop}: ${p}\": the right-hand side must be $command.<name>`,\n // a native element's command (no hyphen: never a custom element) is the native-commands add-on's\n [M.NoBindable]: (tag, what) => `<${tag}> declares no static wcBindable (${what}).${\n !tag.includes(\"-\") && what.startsWith(\"command.\") ? \" A native element's command needs the add-on @wcstack/state/features/native-commands.\" : \"\"}`,\n [M.NoCommand]: (tag, method) => `<${tag}> declares no command \"${method}\".`,\n [M.NoProperty]: (tag, prop) => `<${tag}> declares no property \"${prop}\".`,\n [M.NativeNoCommand]: (tag, method, allowed) => `<${tag}> has no command \"${method}\" (a native <${tag}>'s commands: ${allowed}).`,\n\n [M.EventTokenUndeclared]: (name) => `eventToken \"${name}\" is not declared in $eventTokens.`,\n [M.CommandTokenUndeclared]: (name) => `\"$command.${name}\" is not declared in $commandTokens.`,\n\n [M.WildcardNoLoop]: (p, depth, n = 0) => `\"${p}\" needs ${depth} enclosing loop level(s); the scope provides ${n}.`,\n [M.WildcardRelative]: (p) => `\"${p}\" is relative: it needs an enclosing \"for\" template`,\n [M.WildcardOtherList]: (p, over, loop) => `\"${p}\" ranges over the rows of \"${over}\", but the enclosing \"for\" template at that level renders \"${loop}\".`,\n\n [M.SpreadNoBindable]: (tag, what) => `<${tag}> declares no static wcBindable (${what}).`,\n\n [M.DeclarationRemoved]: (old, name) => `${old} was removed: write ${name}.`,\n\n [M.ApiRemoved]: (old, name) => `${old} was removed: write ${name}.`,\n};\n","/**\n * The diagnostics add-on's sentences and guidance: a numbered core message rendered as its\n * sentence (src/diagnostics/messages.ts), then how to fix it, the nearest name and the lint\n * pointer. The add-on installs these; so does `@wcstack/state/parser`, a bundle of its own.\n */\nimport { didYouMean, LINT_HINT } from \"./guidance\";\nimport { FORMATS_FILTER_NAMES, hasFilter } from \"../filters/registry\";\nimport type { M } from \"../messages\";\nimport { codeOf, SENTENCES } from \"./messages\";\n\n/** A numbered core message as its sentence (the number and the values if it is not known here). */\nexport function render(id: number, args: readonly unknown[]): string {\n const sentence = SENTENCES[id as M];\n return sentence === undefined ? `${codeOf(id)}#${id} ${args.join(\" \")}` : codeOf(id) + sentence(...args);\n}\n\n/** Codes lint detects statically: only these point the author to a lint run. */\nconst LINT_CODES = new Set([\n \"binding-syntax\", \"template-syntax\", \"filter-unknown\", \"filter-arity\", \"index-arity\",\n \"wildcard-rank\", \"token-undeclared\", \"binding-path-missing\", \"index-param-range\",\n]);\n\n/** How to fix it, by what the message says. */\nconst GUIDES: [RegExp, string][] = [\n [/no loop level in common with the context/, \"; pass indexes ([] for all).\"],\n [/\"([^\"#]+)#([^\"]*)\" is not a filter name: a modifier list .* comes before the input filters/, ' — write \"<property>#$2|$1\".'],\n [/\\[wcs\\/recursion-unsupported\\]/, \" It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll — and only when the state declares a $recursion anchor.\"],\n [/must be single binding/, ' Put the structural binding alone in its own data-wcs (e.g. <template data-wcs=\"for: items\">).'],\n [/\\[wcs\\/wildcard-rank\\] .* needs \\d+ enclosing/, ' Wrap it in that many \"for\" templates, or use $resolve(path, indexes) to name the row explicitly.'],\n [/\\[wcs\\/wildcard-rank\\] .* ranges over the rows of/, ' A \"*\" in a binding is the row of the loop around it: read a row of another list in a getter, with $resolve(path, indexes).'],\n [/\\[wcs\\/binding-type-expectation\\] class\\.([^ ]+)/, ' Write \"class.$1: path|truthy\" to toggle on truthiness.'],\n [/path segments — the limit/, \" Every prefix of a path is interned, so the cost grows with the square of the depth.\"],\n [/\\[wcs\\/index-arity\\] \\$resolve/, \" $resolve takes one index per \\\"*\\\"; $getAll / $setAll take at most that many (fewer expands the rest).\"],\n [/\"([^\"#]+)#[^\"]*\" is not a filter name: \"#\" cannot appear in one/, ' Modifiers belong on the left side of the binding, before the \":\" — write \"$1\" here.'],\n];\n\n/**\n * The filter names 3.2 renamed, which 3.x kept as aliases and 4.0 removed (3.x's `filterAliases`;\n * lint has the same table). Their message names the replacement, not the nearest name: for these\n * that is an unrelated filter (`dec` → `eq`, `fix` → `div`), and following it changes the meaning.\n */\nexport const RENAMED_FILTERS: Readonly<Record<string, string>> = {\n inc: \"add\", dec: \"sub\", fix: \"toFixed\", uc: \"upper\", lc: \"lower\", cap: \"capitalize\", rep: \"repeat\", rev: \"reverse\", pad: \"padStart\", null: \"nullIfEmpty\",\n};\n\n/** How to write a filter 4.0 removed, or null. */\nfunction removedFilter(name: string): string | null {\n // 4.0 folded substr(start, length) into slice(start, end): the second argument changes meaning\n if (name === \"substr\") return ' \"substr\" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';\n const to = Object.hasOwn(RENAMED_FILTERS, name) ? RENAMED_FILTERS[name] : null;\n return to === null ? null : ` \"${name}\" was renamed \"${to}\" in 3.2 and removed in 4.0 — write \"${to}\".`;\n}\n\nexport function explain(message: string, subject?: string, candidates?: Iterable<string>): string {\n const removed = subject !== undefined && message.includes(\"[wcs/filter-unknown]\") ? removedFilter(subject) : null;\n let out = removed ?? (subject !== undefined && candidates !== undefined ? didYouMean(subject, candidates) : \"\");\n for (const [re, text] of GUIDES) {\n const m = re.exec(message);\n if (m !== null) out += text.replace(/\\$(\\d)/g, (_, i: string) => m[Number(i)]);\n }\n // \"value#ro#wo\": one modifier list — the fix joins them\n const mods = /\"([^\"#]+)#([^\"]+)\": a binding takes one modifier list/.exec(message);\n if (mods !== null) out += ` — write \"${mods[1]}#${mods[2].split(\"#\").join(\",\")}\".`;\n // a formatting filter on a page without the formats add-on (the core names installFeatures), or a\n // typo on a page with no formatting filters at all: the formats add-on may be what is missing\n if (message.includes(\"[wcs/filter-unknown]\")) {\n if (message.includes(\"formats add-on\")) out += ` On a split auto page: features=\"formats\" on the root, or \"$features\": [\"formats\"].`;\n else if (!FORMATS_FILTER_NAMES.some(hasFilter)) {\n out += ` No formatting filters are installed — add the formats add-on: installFeatures([formats]) from \"@wcstack/state/features/formats\" (a split auto page: features=\"formats\", or \"$features\").`;\n }\n }\n const code = /\\[wcs\\/([\\w-]+)\\]/.exec(message);\n // (not something lint reports: the path-length limit is a runtime cost, a template handed over at\n // the top of inserted content (#204) is the page's order of loading, not its markup, and lint's\n // manifest knows the formatting filters — one missing because the formats add-on is not installed\n // is the page's. A row of another list (#1403) and an `outerHTML:` in a template (#203) lint does\n // report, as of its 4.0 parser)\n if (code !== null && LINT_CODES.has(code[1]) && !/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(message)) out += LINT_HINT;\n return out;\n}\n","/**\n * The diagnostics add-on (@wcstack/state/features/diagnostics): the sentences and the self-fix\n * guidance of error messages. The core states the message number and the values\n * (`#901 \"$resolve\" \"m.*.*\" 2 1`); with this installed, the message is the code shared with lint\n * and the sentence (`[wcs/index-arity] $resolve(\"m.*.*\") takes 2 index(es), got 1.`), followed by the\n * nearest name (did-you-mean, the same rule as lint), how to fix it, and a pointer to lint where\n * lint really detects the case. The full `auto` bundle installs it.\n */\nimport { chain, first, hooks, known, type Feature } from \"../hooks\";\nimport type { Engine } from \"../engine\";\nimport { parsePath, type Pattern } from \"../pattern\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { config } from \"../config\";\nimport type { WcsState } from \"../element\";\nimport type { Binding } from \"../dom/view\";\nimport { getTrustedTypesPolicy, isHtmlSink } from \"../trustedTypes\";\nimport { didYouMean, LINT_HINT } from \"../diagnostics/guidance\";\nimport { explain, render } from \"../diagnostics/explain\";\nimport { raise, M } from \"../messages\";\n\n// ---------------------------------------------------------------- paths that do not resolve\n\n/** Paths bindings and `$watch` keys named, by engine: checked one macrotask later (and after a re-set). */\nconst named = new WeakMap<Engine, Map<Pattern, boolean>>();\nconst checked = new WeakMap<Engine, Set<Pattern>>();\nconst due = new WeakSet<Engine>();\n/** Volumes (`<wcs-state mount>`) whose loading settled: the paths under them are checked from then on. */\nconst settled = new WeakSet<Element>();\n\nfunction findDescriptor(o: object, key: string): PropertyDescriptor | undefined {\n for (let x: object | null = o; x !== null && x !== Object.prototype; x = Object.getPrototypeOf(x)) {\n const d = Object.getOwnPropertyDescriptor(x, key);\n if (d !== undefined) return d;\n }\n return undefined;\n}\n\nfunction keysOf(o: object): string[] {\n const out = new Set<string>();\n for (let x: object | null = o; x !== null && x !== Object.prototype; x = Object.getPrototypeOf(x)) {\n for (const k of Object.getOwnPropertyNames(x)) if (k[0] !== \"$\" && k !== \"constructor\") out.add(k);\n }\n return [...out];\n}\n\n/**\n * The pattern a path with an explicit index reads through: an index with no `*` after it\n * (`items.0.x`) has an accessor of its own (Engine.markupAccessor), so whether it reads a getter\n * is the question of the pattern it names (`items.*.x`). A `*` after the index (`groups.0.items.*.x`,\n * a row of `for: groups.0.items`) reads its row's own item: the pattern itself. So does a path the\n * author declared a getter under (`get \"groups.0.items\"()`): that getter is what it reads (#388).\n */\nfunction wildcardForm(engine: Engine, q: Pattern): Pattern | undefined {\n const segs = q.path.split(\".\");\n // (a leading numeric segment is a root key, not an index: parsePath)\n const i = segs.findIndex((s, j) => j > 0 && /^\\d/.test(s));\n return i < 0 || segs.indexOf(\"*\", i) >= 0 || findDescriptor(engine.target, q.path)?.get !== undefined\n ? q : engine.patterns.peek(parsePath(q.path).pattern);\n}\n\n/**\n * The segment of `p` that certainly does not exist, with the names that do at its level; null\n * when the path exists or it cannot be told without evaluating a getter (a getter on the way, a\n * null or primitive on the way, a list with no row to look into).\n */\nfunction missing(engine: Engine, p: Pattern): { seg: string; names: string[] } | null {\n const chain: Pattern[] = [];\n for (let q: Pattern | null = p; q !== null; q = q.parent) chain.unshift(q);\n let v: any = engine.target;\n const named = (q: Pattern | null): Pattern | null | undefined => (q === null ? null : wildcardForm(engine, q));\n // a getter anywhere on the path answers it — also one declared deeper than a segment the data\n // lacks (\\`get \"box.label\"()\\` with no \\`box\\` key: it renders and updates — docs/seam-apps.md)\n if (chain.some((q) => named(q)?.getter != null)) return null;\n for (const q of chain) {\n if (v === null || typeof v !== \"object\") return null;\n if (q.last === \"*\") {\n if (!Array.isArray(v) || v.length === 0) return null;\n v = v[0];\n continue;\n }\n if (Array.isArray(v) && /^\\d+$/.test(q.last)) {\n // an explicit index: only a row that is there can be looked into\n if (Number(q.last) >= v.length) return null;\n v = v[Number(q.last)];\n continue;\n }\n const d = findDescriptor(v, q.last);\n // a top-level key a re-set dropped is declared: it reads undefined, and a write fills it\n if (d === undefined && q.parent === null && engine.dropped.has(q.last)) return null;\n if (d === undefined) {\n const names = keysOf(v);\n // getters declared one level under the same parent (`items.*.subtotal`)\n const parent = named(q.parent);\n for (const g of engine.patterns.all()) if (g.parent === parent && g.getter !== null) names.push(g.last);\n return { seg: q.last, names };\n }\n if (d.get !== undefined || d.set !== undefined) return null;\n v = d.value;\n }\n return null;\n}\n\nfunction check(engine: Engine): void {\n due.delete(engine);\n const map = named.get(engine);\n if (map === undefined) return;\n let done = checked.get(engine);\n if (done === undefined) checked.set(engine, (done = new Set()));\n for (const [p, watch] of map) {\n if (done.has(p)) continue;\n done.add(p);\n const m = missing(engine, p);\n if (m === null) continue;\n // under the mount path of a volume on the page still loading: checked again once it settles (3.x D22)\n const v = [...((engine.root as ParentNode | null)?.querySelectorAll(`${config.tagNames.state}[mount]`) ?? [])]\n .find((e) => !settled.has(e) && (p.path + \".\").startsWith(e.getAttribute(\"mount\") + \".\"));\n if (v !== undefined) {\n done.delete(p);\n void (v as WcsState).initializePromise.then(() => {\n settled.add(v);\n schedule(engine);\n });\n continue;\n }\n const [code, subject] = watch ? [\"watch-path-missing\", \"$watch path\"] : [\"binding-path-missing\", \"Bound path\"];\n hooks.noticed?.(engine, { \"type\": \"state:path-unresolved\", \"source\": watch ? \"watch\" : \"binding\", \"path\": p.path, \"missingSegment\": m.seg });\n // a row of `for: groups.0.items` with a row getter declared on `groups.*.items.*` (#388)\n const w = engine.patterns.peek(parsePath(p.path).pattern);\n let rowGetter = \"\";\n if (w !== undefined && w !== p && w.getter !== null) {\n const loops = w.lists.slice(1).map((l, k) => `for: ${k === 0 ? l!.path : l!.path.slice(w.lists[k]!.path.length + 2)}`);\n rowGetter = ` The getter \"${w.path}\" is declared for the rows of ${loops.join(\" → \")}; a list named by an index has rows of its own.`;\n }\n console.warn(`[@wcstack/state] [wcs/${code}] ${subject} \"${p.path}\" does not resolve on the state tree: \"${m.seg}\" is not declared.${didYouMean(m.seg, m.names)}${rowGetter} Updates to this path will be silently dropped.${LINT_HINT}`);\n }\n}\n\nfunction schedule(engine: Engine): void {\n if (due.has(engine)) return;\n due.add(engine);\n setTimeout(() => check(engine), 0);\n}\n\n/** The `declared` hook: a path a binding or a `$watch` key names. */\nfunction declared(engine: Engine, p: Pattern, watch = false): void {\n // a missing top-level key already fails the binding's read (the core's error)\n if (p.path[0] === \"$\" || p.path.includes(\"#\") || (!watch && p.parent === null)) return;\n let map = named.get(engine);\n if (map === undefined) named.set(engine, (map = new Map()));\n if (!map.has(p)) map.set(p, watch);\n schedule(engine);\n}\n\n/** A re-set: every path is checked again against the new state. */\nfunction recheck(engine: Engine): void {\n checked.delete(engine);\n if (named.has(engine)) schedule(engine);\n}\n\n// ---------------------------------------------------------------- recursion's static checks\n\n/**\n * `$recursion` families that can never work (approved simplification: these checks moved out of\n * the core): a suffix naming the recursion structure itself, two families one of which is the\n * other a few repeats deeper, and a concrete key that one of the families expands to.\n */\nfunction checkRecursion(target: Record<string, any>): void {\n const decl = target.$recursion;\n if (decl === null || typeof decl !== \"object\") return;\n const entries = Object.entries(decl);\n if (entries.length !== 1 || typeof entries[0][1] !== \"string\") return;\n const [anchor, repeat] = entries[0] as [string, string];\n if (!anchor.endsWith(\".*\") || !repeat.endsWith(\".*\")) return;\n const list = anchor.slice(0, -2);\n const key = repeat.slice(0, -2);\n const step = `.${repeat}`;\n const head = `${list}.**`;\n const keys = keysOf(target);\n const families = keys.filter((k) => k.startsWith(head)).map((k) => k.slice(head.length));\n const bad = (why: string): never => raiseError(`[wcs/recursion-declaration-invalid] ${why}`);\n for (const s of families) {\n if (s === `.${key}` || s.startsWith(`.${key}.`)) {\n bad(`\"${head}${s}\" names the recursion structure itself (the \"${key}\" lists): recursive getters compute values over the nodes.`);\n }\n for (const t of families) {\n if (t.length > s.length && t.endsWith(s) && new RegExp(`^(?:${esc(step)})+$`).test(t.slice(0, t.length - s.length))) {\n bad(`\"${head}${s}\" and \"${head}${t}\" expand to the same concrete path at different depths (they differ by whole repetitions of \"${repeat}\"). Rename one of them.`);\n }\n }\n const re = new RegExp(`^${esc(anchor)}(?:${esc(step)})*${esc(s)}$`);\n for (const k of keys) {\n if (!k.includes(\"**\") && re.test(k)) bad(`\"${k}\" is already defined on the state, so the recursive getter \"${head}${s}\" cannot expand to it.`);\n }\n }\n}\n\nconst esc = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nlet trustedTypesReported = false;\n\n/**\n * An HTML sink write Trusted Types blocked: the browser's message names no fix, so say once\n * per page what to install (the same report as @wcstack/state 3.3).\n */\nfunction failed(_engine: Engine, error: unknown, binding: Binding): void {\n const prop = binding.name === \"html\" ? \"innerHTML\" : binding.name;\n if (trustedTypesReported || !(error instanceof TypeError) || !isHtmlSink(prop) || !(\"trustedTypes\" in globalThis)) return;\n trustedTypesReported = true;\n const cause = typeof getTrustedTypesPolicy()?.createHTML === \"function\"\n ? \"The injected policy's createHTML() did not return a TrustedHTML.\"\n : \"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.\";\n console.error(\n `[@wcstack/state] Writing to \"${prop}\" was blocked by Trusted Types (require-trusted-types-for 'script'). ${cause}\\n`\n + `Install a sanitizing policy before the first binding is applied:\\n`\n + ` globalThis[Symbol.for(\"wcstack.trustedTypes.policy\")] =\\n`\n + ` trustedTypes.createPolicy(\"my-app\", { createHTML: (s) => DOMPurify.sanitize(s) });\\n`\n + `Or bind the value as text instead of HTML. See docs/csp.md section 7.`,\n { element: binding.node, property: prop },\n );\n}\n\n// ---------------------------------------------------------------- the default getter\n\nconst warnedDetail = new WeakMap<Element, Set<string>>();\n\n/**\n * A wc-bindable property's event read with the default getter (`e.detail`): warns once per\n * element and property about the two shapes that cannot be what the element meant (README\n * \"What the element writes back\", as @wcstack/state 3.3). The write is applied as it is.\n * (a) no detail while the element's property has a value — a plain Event, or a forgotten detail;\n * (b) a detail object with a `<name>` key while the property is not an object — a wrapper.\n */\nfunction detail(el: Element, name: string, v: unknown): void {\n const prop = (el as any)[name];\n const reason = v === undefined\n ? prop === undefined ? null : `the event carried no detail (undefined) while element.${name} is ${typeof prop}`\n : v !== null && typeof v === \"object\" && Object.prototype.hasOwnProperty.call(v, name) && (prop === null || typeof prop !== \"object\")\n ? `the event's detail is an object with a \"${name}\" key while element.${name} is ${typeof prop}`\n : null;\n if (reason === null) return;\n let said = warnedDetail.get(el);\n if (said === undefined) warnedDetail.set(el, (said = new Set()));\n if (said.has(name)) return;\n said.add(name);\n console.warn(\n `[@wcstack/state] [wcs/default-getter-mismatch] <${el.localName}> \"${name}\": ${reason}. `\n + \"With no getter, state receives e.detail as-is. Dispatch the value itself as detail, or declare \"\n + `getter (e.g. (e) => e.detail.${name}, or (e) => e.target.${name}) on that wcBindable property.`,\n );\n}\n\n// ---------------------------------------------------------------- 3.x names 4.0 removed\n\n/**\n * Declarations 3.2 renamed, whose old names 4.0 removed: a declaration under one would do nothing.\n * (The core detected these and the two APIs below up to 4.0.0-rc.3; without this add-on they are\n * ignored like any other unknown `$` key.)\n */\nconst REMOVED_DECLARATIONS: [string, string][] = [[\"$streams\", \"$stream\"], [\"$updatedCallback\", \"$renderedCallback\"]];\n/** APIs 3.2 renamed, whose old names 4.0 removed: reading one fails with the name to write. */\nconst REMOVED_APIS: Readonly<Record<string, string>> = { \"$trackDependency\": \"$dependOn\", \"$untrackDependency\": \"$untracked\" };\n\n/** A state that declares a 3.x name 4.0 removed (`$scan` has no successor: $watch or $on). */\nfunction removedDeclarations(target: Record<string, any>): void {\n if (target.$scan !== undefined) raise(M.ScanRemoved);\n for (const [old, name] of REMOVED_DECLARATIONS) if (target[old] !== undefined) raise(M.DeclarationRemoved, [old, name]);\n}\n\nexport const diagnostics: Feature = {\n name: \"diagnostics\",\n install(): void {\n hooks.explain = explain;\n hooks.render = render;\n hooks.declared = declared;\n hooks.detail = detail;\n hooks.failed = chain(hooks.failed, failed);\n // the removed names first, before what is installed (the core checked them before it took the\n // state in): a refused state never reaches the other add-ons' runtimes\n const prev = hooks.declare;\n hooks.declare = (engine, target) => {\n removedDeclarations(target);\n prev?.(engine, target);\n checkRecursion(target);\n recheck(engine);\n };\n hooks.dollar = first(known, hooks.dollar, (_engine, key) => (Object.hasOwn(REMOVED_APIS, key) ? raise(M.ApiRemoved, [key, REMOVED_APIS[key]]) : undefined));\n },\n};\nexport default diagnostics;\n"],"mappings":"mVAUA,SAASA,EAAaC,EAAWC,EAAWC,GAC1C,GAAIC,KAAKC,IAAIJ,EAAEK,OAASJ,EAAEI,QAAUH,EAClC,OAAOA,EAAM,EAEf,IAAMI,EAAiB,IAAIC,MAAMN,EAAEI,OAAS,GACtCG,EAAiB,IAAID,MAAMN,EAAEI,OAAS,GAC5C,QAASI,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAC7BH,EAAKG,GAAKA,EAEZ,QAASC,EAAI,EAAGA,GAAKV,EAAEK,OAAQK,IAAK,CAClCF,EAAK,GAAKE,EACV,QAASD,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAAK,CAClC,IAAME,EAAOX,EAAEU,EAAI,KAAOT,EAAEQ,EAAI,GAAK,EAAI,EACzCD,EAAKC,GAAKN,KAAKS,IAAIN,EAAKG,GAAK,EAAGD,EAAKC,EAAI,GAAK,EAAGH,EAAKG,EAAI,GAAKE,EACjE,CACA,QAASF,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAC7BH,EAAKG,GAAKD,EAAKC,EAEnB,CACA,OAAOH,EAAKL,EAAEI,OAChB,CAMO,SAASQ,EAAWC,EAAeC,GACxC,GAAqB,IAAjBD,EAAMT,OACR,MAAO,GAET,IAAMW,EAASF,EAAMG,cACjBC,EAAsB,KACtBC,EAAe,EACnB,QAAWC,KAAaL,EAAY,CAClC,IA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ClC,CA8HMoG,CAAQpG,IAEVwC,EAAM6D,GAASC,EAAMC,EAAO/D,EAAM6D,GAAQ,CAAC9C,EAAS9I,IAASoD,OAAOC,OAAO4G,EAAcjK,GAAOwK,OAAoB,CAACxK,EAAKiK,EAAajK,UAAS,EAClJ,GAEK+L,EAAQ3B","ignoreList":[]}
1
+ {"version":3,"names":["editDistance","a","b","max","Math","abs","length","prev","Array","curr","j","i","cost","min","didYouMean","input","candidates","folded","toLowerCase","best","bestDistance","candidate","distance","LINT_HINT","CODES","codeOf","id","c","MOVED","was","v","String","Date","isArray","JSON","stringify","slice","NAMESPACES","element","tag","at","map","join","CSP_GUIDE","SENTENCES","p","parent","name","n","MAX_DRAIN_PASSES","MAX_RENDER_CHAIN","type","kind","src","status","detail","key","reserved","limit","fn","modifier","value","init","where","includes","l","t","keyword","prop","quote","args","f","trailing","lastIndexOf","source","mods","ns","given","api","depth","what","startsWith","method","allowed","over","loop","old","render","sentence","LINT_CODES","Set","GUIDES","RENAMED_FILTERS","inc","dec","fix","uc","lc","cap","rep","rev","pad","null","explain","message","subject","out","to","Object","hasOwn","removedFilter","re","text","m","exec","replace","_","Number","split","FORMATS_FILTER_NAMES","some","hasFilter","code","has","test","named","WeakMap","checked","due","WeakSet","settled","findDescriptor","o","x","prototype","getPrototypeOf","d","getOwnPropertyDescriptor","keysOf","k","getOwnPropertyNames","add","missing","engine","chain","q","unshift","segs","path","findIndex","s","indexOf","target","get","patterns","peek","parsePath","pattern","wildcardForm","getter","under","last","first","row","seg","names","push","dropped","g","all","set","schedule","setTimeout","delete","done","todo","Map","readers","dependents","find","markup","root","querySelectorAll","config","tagNames","state","e","getAttribute","initializePromise","then","w","rowGetter","loops","lists","near","hooks","noticed","missingSegment","console","warn","check","declared","watch","note","wrapped","posting","declaredKeys","written","keys","wrappedTokens","loud","emit","said","size","apply","explained","handlerThrew","drained","loose","esc","trustedTypesReported","failed","_engine","error","binding","TypeError","isHtmlSink","globalThis","cause","getTrustedTypesPolicy","createHTML","node","property","warnedDetail","el","reason","hasOwnProperty","call","localName","REMOVED_DECLARATIONS","REMOVED_APIS","$trackDependency","$untrackDependency","diagnostics","install","declare","$scan","raise","removedDeclarations","decl","$recursion","entries","anchor","repeat","endsWith","list","step","head","families","filter","bad","why","raiseError","RegExp","checkRecursion","recheck","post","$postUpdate","watchPostUpdate","commands","defineProperty","configurable","values","watchCommands","dollar","known","diagnostics_default"],"sources":["../../../src/diagnostics/guidance.ts","../../../src/diagnostics/messages.ts","../../../src/diagnostics/explain.ts","../../../src/features/diagnostics.ts"],"sourcesContent":["/**\n * diagnostics/guidance.ts — self-fix guidance for error messages, ported verbatim from\n * `@wcstack/state` (`errorGuidance.ts`). Only the diagnostics add-on uses it: the core's\n * messages state the fact, and the add-on appends this.\n *\n * The did-you-mean criteria (edit distance 2, ties go to the first candidate, case folded) are the\n * same as lint's suggestion, so the console, lint and the IDE never propose different names.\n */\n\n/** Insert / delete / substitute edit distance. Returns max + 1 early when the lengths differ by more than max. */\nfunction editDistance(a: string, b: string, max: number): number {\n if (Math.abs(a.length - b.length) > max) {\n return max + 1;\n }\n const prev: number[] = new Array(b.length + 1);\n const curr: number[] = new Array(b.length + 1);\n for (let j = 0; j <= b.length; j++) {\n prev[j] = j;\n }\n for (let i = 1; i <= a.length; i++) {\n curr[0] = i;\n for (let j = 1; j <= b.length; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);\n }\n for (let j = 0; j <= b.length; j++) {\n prev[j] = curr[j];\n }\n }\n return prev[b.length];\n}\n\n/**\n * The nearest candidate within edit distance 2 as ` Did you mean \"<best>\"?`, or `\"\"` when there is\n * none. An empty input (a trailing `a|` pipe) gets no suggestion.\n */\nexport function didYouMean(input: string, candidates: Iterable<string>): string {\n if (input.length === 0) {\n return \"\";\n }\n const folded = input.toLowerCase();\n let best: string | null = null;\n let bestDistance = 3;\n for (const candidate of candidates) {\n const distance = editDistance(folded, candidate.toLowerCase(), 2);\n if (distance < bestDistance) {\n best = candidate;\n bestDistance = distance;\n }\n }\n return best !== null ? ` Did you mean \"${best}\"?` : \"\";\n}\n\n/**\n * The pointer to lint. Attach it **only where lint actually detects the case** — a hint that sends\n * the author to a lint run that comes back clean costs the loop its credibility.\n */\nexport const LINT_HINT = \" Validate statically: npx @wcstack/lint <file>.\";\n","/**\n * The sentences of the core's numbered messages (src/messages.ts), in the diagnostics add-on:\n * the core carries the number and the values, this renders what the core used to say. Each\n * sentence follows its `[wcs/<code>] ` (`codeOf`: the code the hundreds of the number name).\n * `Record<M, …>` makes a number without a sentence a type error.\n */\nimport { M } from \"../messages\";\nimport { MAX_DRAIN_PASSES, MAX_INDEX_PARAM, MAX_RENDER_CHAIN } from \"../engine\";\nimport { MAX_PATH_SEGMENTS, MODIFIER_SEPARATOR, RECURSION_WILDCARD } from \"../parser/define\";\n\ntype Sentence = (...a: any[]) => string;\n\n/**\n * The code of each hundred of message numbers (\"\" = none): the code lint and the VS Code extension\n * report for the same case. The core carried this up to 4.0.0-rc.3; without this add-on a message\n * now reads as its number and values alone.\n */\nexport const CODES = [\n \"\", \"binding-syntax\", \"template-syntax\", \"binding-path-missing\", \"binding-type-expectation\",\n \"filter-unknown\", \"filter-arity\", \"getter-cycle\", \"getter-depth-exceeded\", \"index-arity\",\n \"index-param-range\", \"recursion-unsupported\", \"token-misconfigured\", \"token-undeclared\",\n \"wildcard-rank\", \"spread-no-bindable\", \"declaration-alias\", \"name-alias\",\n];\n\n/** `[wcs/<code>] ` for a message number, or \"\" when it has none. */\nexport const codeOf = (id: M): string => {\n const c = CODES[(id / 100) | 0];\n return c ? `[wcs/${c}] ` : \"\";\n};\n\n/** The options 4.0 moved from `bootstrapState` to the state's `$behavior`. */\nconst MOVED = [\"enableMustache\", \"sameValueGuard\", \"enableDirectionalInitialSync\"];\n\n/** `<tag a=\"v\" …>` from the tag and its attributes' names and values. */\n/** What a value given to a filter was (`a string (\"2026-10-13T…\")`), for the type messages. */\nconst was = (v: unknown): string =>\n v == null ? String(v)\n : v instanceof Date ? \"a Date\"\n : Array.isArray(v) ? \"an array\"\n : typeof v === \"string\" ? `a string (${JSON.stringify(v.length > 32 ? v.slice(0, 32) + \"…\" : v)})`\n : typeof v === \"object\" ? \"an object\" : `a ${typeof v} (${String(v)})`;\n/** The namespace a binding of kind 2–4 (dom/view.ts: K_CLASS, K_ATTR, K_STYLE) names its member under. */\nconst NAMESPACES = [\"\", \"\", \"class.\", \"attr.\", \"style.\"];\n\nconst element = (tag: string, at: string[]): string => `<${tag}${at.map((a, i) => (i % 2 ? `=\"${a}\"` : ` ${a}`)).join(\"\")}>`;\n\nconst CSP_GUIDE = \"https://github.com/wcstack/wcstack/blob/main/docs/csp.md\";\n\nexport const SENTENCES: Record<M, Sentence> = {\n [M.ScanRemoved]: () => \"$scan was removed (use $watch or $on)\",\n [M.GetterWithoutSetter]: (p) => `\"${p}\" is a getter without a setter`,\n [M.NoRow]: (p) => `no row for \"${p}\"`,\n [M.ParentNotObject]: (p, parent) => `cannot write \"${p}\": its parent is ${parent}`,\n [M.NotAMethod]: (name) => `\"${name}\" is not a method`,\n [M.GetAllNoCommonLevel]: (p) => `$getAll(\"${p}\"): no loop level in common with the context`,\n [M.EqIndexNoRow]: (p) => `$eqIndex(\"${p}\") needs a list row scope.`,\n [M.Readonly]: () => \"This state is readonly.\",\n [M.SetAllNeedsIndexes]: (p) => `$setAll(\"${p}\") needs indexes ([] for every match)`,\n [M.SetAllSpreadLength]: (p, n) => `$setAll(\"${p}\", …, { spread: true }) needs an array of ${n} values`,\n [M.DrainNotSettled]: () => `updates did not settle after ${MAX_DRAIN_PASSES} passes`,\n [M.RenderChain]: () => `render chain depth limit exceeded (${MAX_RENDER_CHAIN} drains that rendering itself started); bindings for this batch were not applied.`,\n // (named as written — `textContent: iso`, `class.active: x` — when the binding has a member; else its type)\n [M.BindingFailed]: (type, p, name, kind) => `binding \"${name ? (NAMESPACES[kind] ?? \"\") + name : type}: ${p}\" failed to apply.`,\n [M.LoadFailed]: (src, status) => `failed to load \"${src}\": ${status}`,\n [M.ElementFailed]: () => \"this <wcs-state> failed to initialize; create a new one\",\n [M.NotInitialized]: () => \"state is not initialized\",\n [M.NoScript]: (id) => `no <script> with id \"${id}\"`,\n [M.InlineBlocked]: () => `The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src=\"./state.js\") needs neither. See ${CSP_GUIDE}`,\n [M.InlineFailed]: (detail) => `Failed to evaluate the inline <script> of <wcs-state>: ${detail}. If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`,\n [M.TokenSubscriberThrew]: (name) => `a subscriber of token \"${name}\" threw.`,\n [M.TokenListNotArray]: (key) => `${key} must be an array of strings.`,\n [M.TokenEntryEmpty]: (key) => `${key} entries must be non-empty strings.`,\n [M.TokenEntryReserved]: (key, name, reserved) => `${key} entry \"${name}\" conflicts with the reserved namespace name \"${reserved}\".`,\n [M.TokenEntryDuplicated]: (key, name) => `${key} entry \"${name}\" is duplicated.`,\n [M.OnNotObject]: () => \"$on must be an object of handlers.\",\n [M.OnEntryUndeclared]: (name) => `$on entry \"${name}\" is not declared in $eventTokens.`,\n [M.OnEntryNotFunction]: (name) => `$on entry \"${name}\" must be a function.`,\n [M.NamingLimit]: (limit) => `view-transition naming-limit (${limit}) reached.`,\n [M.FilterOptionsRequired]: (fn) => `filter ${fn} requires at least one option`,\n [M.FilterOptionNotNumber]: (fn) => `filter ${fn} requires a number as option`,\n [M.FilterValueNotNumber]: (fn, v) => `filter ${fn} requires a number value, not ${was(v)}${typeof v === \"string\" ? ` — put |number before |${fn}, or convert it where it is read` : \"\"}`,\n [M.FilterValueNotDate]: (fn, v) => `filter ${fn} requires a date value (a Date), not ${was(v)}${typeof v === \"string\" || typeof v === \"number\" ? \" — make the Date where it is read: a getter returning new Date(…)\" : \"\"}`,\n [M.FilterStyleInvalid]: (fn, v) => `filter ${fn} takes a style of full, long, medium or short, not \"${v}\"`,\n [M.FilterCurrencyInvalid]: (v) => `filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not \"${v}\"`,\n [M.FilterValueNotArray]: (fn) => `filter ${fn} requires an array value`,\n [M.DirectionalSyncDisabled]: () => \"init=/sync= modifiers require enableDirectionalInitialSync.\",\n [M.ModifierUnknown]: (key, modifier) => `Unknown binding modifier \"${key}\" in \"${modifier}\".`,\n [M.ModifierTwice]: (key) => `Binding modifier \"${key}\" may only be specified once.`,\n [M.ModifierValue]: (key, value) => `Invalid ${key} modifier value \"${value}\".`,\n [M.EventInitNone]: () => \"Event bindings only allow init=none.\",\n [M.InitUnsupported]: (type, init) => `Binding type \"${type}\" does not support init=${init}.`,\n [M.MemberUndeclared]: (name) => `Property \"${name}\" is not declared by wcBindable.`,\n [M.InitIncompatible]: (init, name) => `init=${init} is incompatible with wcBindable member \"${name}\".`,\n [M.SyncConnectNeedsOutput]: (name) => `sync=connect requires observable property \"${name}\".`,\n [M.OptionInvalid]: (where, key) => `${where}: \"${key}\" is not one of its options, or not of the option's type.${where === \"bootstrapState\" && MOVED.includes(key) ? \" 4.0 moved it to the state's $behavior.\" : \"\"}`,\n [M.BehaviorChanged]: () => \"a re-set state may not change $behavior: create the element again.\",\n [M.SecondRoot]: () => \"a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount=\\\"path\\\"> (v1's name=\\\"…\\\" is gone: read the mounted state by its path).\",\n [M.LocaleInvalid]: (l) => `the locale \"${l}\" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use \"en\".`,\n [M.FeaturesNotArray]: () => '$features must be an array of add-on names ([\"temporal\", \"formats\"]).',\n [M.InitFailed]: (tag, ...at) => `${element(tag, at)} failed to initialize.`,\n [M.ConnectedFailed]: (tag, ...at) => `${element(tag, at)} $connectedCallback failed.`,\n [M.DisconnectedFailed]: (tag, ...at) => `${element(tag, at)} $disconnectedCallback failed.`,\n\n [M.BindTextNoColon]: (t) => `Invalid bindText: \"${t}\". Missing ':' separator between propPart and statePart.`,\n [M.StructuralTakesNoModifiers]: (t, keyword) => `\"${t}\": \"${keyword}\" takes no modifiers or filters on its left side — write \"${keyword}:\".`,\n [M.ElseTakesNoValue]: (t) => `\"${t}\": \"else\" takes no value — write \"else:\".`,\n [M.SpreadNoPath]: (t) => `Invalid spread binding \"${t}\": spread target path is required.`,\n [M.SpreadNoFilters]: (t) => `Invalid spread binding \"${t}\": filters are not allowed on spread targets.`,\n [M.LeadingDotNamespace]: (prop) => `\"${prop}\": a leading \".\" binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,\n [M.UnterminatedQuote]: (quote, args) => `unterminated ${quote} quote in the filter arguments \"(${args})\". Close the quote.`,\n [M.FilterUnclosed]: (f) => `Invalid filter format: missing closing parenthesis in \"${f}\".`,\n [M.FilterUnopened]: (f) => `Invalid filter format: missing opening parenthesis in \"${f}\".`,\n [M.FilterParenOrder]: (f) => `Invalid filter format: \")\" comes before \"(\" in \"${f}\".`,\n [M.FilterTrailing]: (f, trailing) => `\"${f}\": unexpected \"${trailing}\" after the filter's closing \")\" — separate filters with \"|\" (write \"${f.slice(0, f.lastIndexOf(\")\") + 1)}|${trailing}\").`,\n [M.FilterEmpty]: (source) => `an empty filter in \"${source}\" — remove the extra \"|\" or name the filter.`,\n [M.FilterNameHasModifiersInput]: (name, mods) => `\"${name}\" is not a filter name: a modifier list \"${MODIFIER_SEPARATOR}${mods}\" comes before the input filters, not inside one`,\n [M.FilterNameHasModifiersOutput]: (name) => `\"${name}\" is not a filter name: \"${MODIFIER_SEPARATOR}\" cannot appear in one.`,\n [M.OneModifierList]: (prop) => `\"${prop}\": a binding takes one modifier list after a single \"#\"`,\n [M.NoPropertyName]: (prop) => `\"${prop}\": the left side of a binding must name a property — write \"<property>: <path>\" (modifiers and input filters come after the name).`,\n [M.TooManySegments]: (p, n) => `\"${p}\" has ${n} path segments — the limit is ${MAX_PATH_SEGMENTS}.`,\n [M.SelectorRemoved]: (t) => `\"${t}\": the \"@name\" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount=\"...\">) and read it by its path prefix instead.`,\n [M.UnsafeSegment]: (p) => `\"${p}\": a state path cannot go through \"__proto__\" or \"prototype\" (it would reach every object's prototype).`,\n [M.ForNoFilters]: (t) => `\"${t}\": \"for:\" takes no filters — a row is \"<path>.<index>\", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it (\"for: <getter>\").`,\n [M.NamespaceNeedsName]: (t, ns) => ns === \"class\"\n ? `\"${t}\": \"class:\" needs a class name — \"class.NAME:\" toggles one class (a bare \"class:\" would set an element property named \"class\", which does nothing). To set the whole class attribute, bind \"className:\".`\n : `\"${t}\": \"attr:\" needs an attribute name — \"attr.NAME:\" sets one attribute (a bare \"attr:\" would set an element property named \"attr\", which does nothing).`,\n [M.EmptySegment]: (t) => `\"${t}\": the right side of a binding must name a state path — write \"<property>: <path>\" (a path segment cannot be empty; \".\" alone and a leading \".\" are the loop-relative shorthand).`,\n\n [M.StructuralNotSingle]: (t) => `Invalid bindText: \"${t}\". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,\n [M.ElseWithoutIf]: (type) => `\"${type}:\" must follow an \"if:\" template`,\n [M.TemplateHandedOver]: (type) => `a \"${type}:\" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,\n [M.OuterInTemplate]: (name) => `\"${name}:\" replaces its element, so it cannot be used inside a \"for\" / \"if\" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,\n\n [M.PathMissing]: (p) => `Path \"${p}\" does not exist on the state tree.`,\n\n [M.ClassNeedsBoolean]: (name, type) => `class.${name} needs a boolean, got ${type}.`,\n\n [M.FilterUnknown]: (name) => `filter not found: ${name}.`,\n\n [M.FilterTooFewArgs]: (name, min, given) => `filter \"${name}\" requires at least ${min} argument(s) (${given} given).`,\n [M.FilterTooManyArgs]: (name, max, given) => `filter \"${name}\" accepts at most ${max} argument(s) (${given} given).`,\n\n [M.GetterCycle]: (p) => `\"${p}\" depends on itself`,\n\n [M.GetterDepth]: (p) => `\"${p}\"`,\n\n [M.IndexArityExact]: (api, p, depth, n) => `${api}(\"${p}\") takes ${depth} index(es), got ${n}.`,\n [M.IndexArityAtMost]: (api, p, depth, n) => `${api}(\"${p}\") takes at most ${depth} index(es), got ${n}.`,\n\n [M.IndexParamRange]: (key) => `\"${key}\": list index parameters run from $1 to $${MAX_INDEX_PARAM}.`,\n\n [M.RecursionUnsupported]: (p) => `\"${p}\" uses \"${RECURSION_WILDCARD}\", which is not accepted here.`,\n\n [M.CommandRightSide]: (prop, p) => `\"${prop}: ${p}\": the right-hand side must be $command.<name>`,\n // a native element's command (no hyphen: never a custom element) is the native-commands add-on's\n [M.NoBindable]: (tag, what) => `<${tag}> declares no static wcBindable (${what}).${\n !tag.includes(\"-\") && what.startsWith(\"command.\") ? \" A native element's command needs the add-on @wcstack/state/features/native-commands.\" : \"\"}`,\n [M.NoCommand]: (tag, method) => `<${tag}> declares no command \"${method}\".`,\n [M.NoProperty]: (tag, prop) => `<${tag}> declares no property \"${prop}\".`,\n [M.NativeNoCommand]: (tag, method, allowed) => `<${tag}> has no command \"${method}\" (a native <${tag}>'s commands: ${allowed}).`,\n\n [M.EventTokenUndeclared]: (name) => `eventToken \"${name}\" is not declared in $eventTokens.`,\n [M.CommandTokenUndeclared]: (name) => `\"$command.${name}\" is not declared in $commandTokens.`,\n\n [M.WildcardNoLoop]: (p, depth, n = 0) => `\"${p}\" needs ${depth} enclosing loop level(s); the scope provides ${n}.`,\n [M.WildcardRelative]: (p) => `\"${p}\" is relative: it needs an enclosing \"for\" template`,\n [M.WildcardOtherList]: (p, over, loop) => `\"${p}\" ranges over the rows of \"${over}\", but the enclosing \"for\" template at that level renders \"${loop}\".`,\n\n [M.SpreadNoBindable]: (tag, what) => `<${tag}> declares no static wcBindable (${what}).`,\n\n [M.DeclarationRemoved]: (old, name) => `${old} was removed: write ${name}.`,\n\n [M.ApiRemoved]: (old, name) => `${old} was removed: write ${name}.`,\n};\n","/**\n * The diagnostics add-on's sentences and guidance: a numbered core message rendered as its\n * sentence (src/diagnostics/messages.ts), then how to fix it, the nearest name and the lint\n * pointer. The add-on installs these; so does `@wcstack/state/parser`, a bundle of its own.\n */\nimport { didYouMean, LINT_HINT } from \"./guidance\";\nimport { FORMATS_FILTER_NAMES, hasFilter } from \"../filters/registry\";\nimport type { M } from \"../messages\";\nimport { codeOf, SENTENCES } from \"./messages\";\n\n/** A numbered core message as its sentence (the number and the values if it is not known here). */\nexport function render(id: number, args: readonly unknown[]): string {\n const sentence = SENTENCES[id as M];\n return sentence === undefined ? `${codeOf(id)}#${id} ${args.join(\" \")}` : codeOf(id) + sentence(...args);\n}\n\n/** Codes lint detects statically: only these point the author to a lint run. */\nconst LINT_CODES = new Set([\n \"binding-syntax\", \"template-syntax\", \"filter-unknown\", \"filter-arity\", \"index-arity\",\n \"wildcard-rank\", \"token-undeclared\", \"binding-path-missing\", \"index-param-range\",\n]);\n\n/** How to fix it, by what the message says. */\nconst GUIDES: [RegExp, string][] = [\n [/no loop level in common with the context/, \"; pass indexes ([] for all).\"],\n [/\"([^\"#]+)#([^\"]*)\" is not a filter name: a modifier list .* comes before the input filters/, ' — write \"<property>#$2|$1\".'],\n [/\\[wcs\\/recursion-unsupported\\]/, \" It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll — and only when the state declares a $recursion anchor.\"],\n [/must be single binding/, ' Put the structural binding alone in its own data-wcs (e.g. <template data-wcs=\"for: items\">).'],\n [/\\[wcs\\/wildcard-rank\\] .* needs \\d+ enclosing/, ' Wrap it in that many \"for\" templates, or use $resolve(path, indexes) to name the row explicitly.'],\n [/\\[wcs\\/wildcard-rank\\] .* ranges over the rows of/, ' A \"*\" in a binding is the row of the loop around it: read a row of another list in a getter, with $resolve(path, indexes).'],\n [/\\[wcs\\/binding-type-expectation\\] class\\.([^ ]+)/, ' Write \"class.$1: path|truthy\" to toggle on truthiness.'],\n [/path segments — the limit/, \" Every prefix of a path is interned, so the cost grows with the square of the depth.\"],\n [/\\[wcs\\/index-arity\\] \\$resolve/, \" $resolve takes one index per \\\"*\\\"; $getAll / $setAll take at most that many (fewer expands the rest).\"],\n [/\"([^\"#]+)#[^\"]*\" is not a filter name: \"#\" cannot appear in one/, ' Modifiers belong on the left side of the binding, before the \":\" — write \"$1\" here.'],\n];\n\n/**\n * The filter names 3.2 renamed, which 3.x kept as aliases and 4.0 removed (3.x's `filterAliases`;\n * lint has the same table). Their message names the replacement, not the nearest name: for these\n * that is an unrelated filter (`dec` → `eq`, `fix` → `div`), and following it changes the meaning.\n */\nexport const RENAMED_FILTERS: Readonly<Record<string, string>> = {\n inc: \"add\", dec: \"sub\", fix: \"toFixed\", uc: \"upper\", lc: \"lower\", cap: \"capitalize\", rep: \"repeat\", rev: \"reverse\", pad: \"padStart\", null: \"nullIfEmpty\",\n};\n\n/** How to write a filter 4.0 removed, or null. */\nfunction removedFilter(name: string): string | null {\n // 4.0 folded substr(start, length) into slice(start, end): the second argument changes meaning\n if (name === \"substr\") return ' \"substr\" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';\n const to = Object.hasOwn(RENAMED_FILTERS, name) ? RENAMED_FILTERS[name] : null;\n return to === null ? null : ` \"${name}\" was renamed \"${to}\" in 3.2 and removed in 4.0 — write \"${to}\".`;\n}\n\nexport function explain(message: string, subject?: string, candidates?: Iterable<string>): string {\n const removed = subject !== undefined && message.includes(\"[wcs/filter-unknown]\") ? removedFilter(subject) : null;\n let out = removed ?? (subject !== undefined && candidates !== undefined ? didYouMean(subject, candidates) : \"\");\n for (const [re, text] of GUIDES) {\n const m = re.exec(message);\n if (m !== null) out += text.replace(/\\$(\\d)/g, (_, i: string) => m[Number(i)]);\n }\n // \"value#ro#wo\": one modifier list — the fix joins them\n const mods = /\"([^\"#]+)#([^\"]+)\": a binding takes one modifier list/.exec(message);\n if (mods !== null) out += ` — write \"${mods[1]}#${mods[2].split(\"#\").join(\",\")}\".`;\n // a formatting filter on a page without the formats add-on (the core names installFeatures), or a\n // typo on a page with no formatting filters at all: the formats add-on may be what is missing\n if (message.includes(\"[wcs/filter-unknown]\")) {\n if (message.includes(\"formats add-on\")) out += ` On a split auto page: features=\"formats\" on the root, or \"$features\": [\"formats\"].`;\n else if (!FORMATS_FILTER_NAMES.some(hasFilter)) {\n out += ` No formatting filters are installed — add the formats add-on: installFeatures([formats]) from \"@wcstack/state/features/formats\" (a split auto page: features=\"formats\", or \"$features\").`;\n }\n }\n const code = /\\[wcs\\/([\\w-]+)\\]/.exec(message);\n // (not something lint reports: the path-length limit is a runtime cost, a template handed over at\n // the top of inserted content (#204) is the page's order of loading, not its markup, and lint's\n // manifest knows the formatting filters — one missing because the formats add-on is not installed\n // is the page's. A row of another list (#1403) and an `outerHTML:` in a template (#203) lint does\n // report, as of its 4.0 parser)\n if (code !== null && LINT_CODES.has(code[1]) && !/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(message)) out += LINT_HINT;\n return out;\n}\n","/**\n * The diagnostics add-on (@wcstack/state/features/diagnostics): the sentences and the self-fix\n * guidance of error messages. The core states the message number and the values\n * (`#901 \"$resolve\" \"m.*.*\" 2 1`); with this installed, the message is the code shared with lint\n * and the sentence (`[wcs/index-arity] $resolve(\"m.*.*\") takes 2 index(es), got 1.`), followed by the\n * nearest name (did-you-mean, the same rule as lint), how to fix it, and a pointer to lint where\n * lint really detects the case. The full `auto` bundle installs it.\n */\nimport { chain, first, hooks, known, type Feature } from \"../hooks\";\nimport type { Engine } from \"../engine\";\nimport { parsePath, type Pattern } from \"../pattern\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { config } from \"../config\";\nimport type { WcsState } from \"../element\";\nimport type { Binding } from \"../dom/view\";\nimport { getTrustedTypesPolicy, isHtmlSink } from \"../trustedTypes\";\nimport { didYouMean, LINT_HINT } from \"../diagnostics/guidance\";\nimport { explain, render } from \"../diagnostics/explain\";\nimport { raise, M } from \"../messages\";\nimport type { Token } from \"../token\";\n\n// ---------------------------------------------------------------- paths that do not resolve\n\n/** What named a path: a binding, a `$watch` key, a `$postUpdate` call, a getter's read. */\nconst BINDING = 0;\nconst WATCH = 1;\nconst POST = 2;\nconst READ = 3;\n/** Paths bindings, `$watch` keys and `$postUpdate` named, by engine: checked one macrotask later (and after a re-set). */\nconst named = new WeakMap<Engine, Map<Pattern, number>>();\nconst checked = new WeakMap<Engine, Set<Pattern>>();\nconst due = new WeakSet<Engine>();\n/** Volumes (`<wcs-state mount>`) whose loading settled: the paths under them are checked from then on. */\nconst settled = new WeakSet<Element>();\n\nfunction findDescriptor(o: object, key: string): PropertyDescriptor | undefined {\n for (let x: object | null = o; x !== null && x !== Object.prototype; x = Object.getPrototypeOf(x)) {\n const d = Object.getOwnPropertyDescriptor(x, key);\n if (d !== undefined) return d;\n }\n return undefined;\n}\n\nfunction keysOf(o: object): string[] {\n const out = new Set<string>();\n for (let x: object | null = o; x !== null && x !== Object.prototype; x = Object.getPrototypeOf(x)) {\n for (const k of Object.getOwnPropertyNames(x)) if (k[0] !== \"$\" && k !== \"constructor\") out.add(k);\n }\n return [...out];\n}\n\n/**\n * The pattern a path with an explicit index reads through: an index with no `*` after it\n * (`items.0.x`) has an accessor of its own (Engine.markupAccessor), so whether it reads a getter\n * is the question of the pattern it names (`items.*.x`). A `*` after the index (`groups.0.items.*.x`,\n * a row of `for: groups.0.items`) reads its row's own item: the pattern itself. So does a path the\n * author declared a getter under (`get \"groups.0.items\"()`): that getter is what it reads (#388).\n */\nfunction wildcardForm(engine: Engine, q: Pattern): Pattern | undefined {\n const segs = q.path.split(\".\");\n // (a leading numeric segment is a root key, not an index: parsePath)\n const i = segs.findIndex((s, j) => j > 0 && /^\\d/.test(s));\n return i < 0 || segs.indexOf(\"*\", i) >= 0 || findDescriptor(engine.target, q.path)?.get !== undefined\n ? q : engine.patterns.peek(parsePath(q.path).pattern);\n}\n\n/**\n * The segment of `p` that certainly does not exist, with the names that do at its level; null\n * when the path exists or it cannot be told without evaluating a getter (a getter on the way, a\n * null or primitive on the way, a list with no row to look into).\n */\nfunction missing(engine: Engine, p: Pattern): { seg: string; names: string[]; row: boolean } | null {\n const chain: Pattern[] = [];\n for (let q: Pattern | null = p; q !== null; q = q.parent) chain.unshift(q);\n const named = (q: Pattern | null): Pattern | null | undefined => (q === null ? null : wildcardForm(engine, q));\n // a getter anywhere on the path answers it — also one declared deeper than a segment the data\n // lacks (\\`get \"box.label\"()\\` with no \\`box\\` key: it renders and updates — docs/seam-apps.md)\n if (chain.some((q) => named(q)?.getter != null)) return null;\n return under(engine, chain, 0, engine.target, named);\n}\n\n/** `missing` from `chain[k]` on, in `v`. */\nfunction under(engine: Engine, chain: Pattern[], k: number, v: any, named: (q: Pattern | null) => Pattern | null | undefined): { seg: string; names: string[]; row: boolean } | null {\n for (; k < chain.length; k++) {\n const q = chain[k];\n if (v === null || typeof v !== \"object\") return null;\n if (q.last === \"*\") {\n if (!Array.isArray(v) || v.length === 0) return null;\n // a row field is declared when any row has it — an optional one (`pending` on the rows a page\n // added itself) is not missing because the first row lacks it (docs/seam-apps.md, ssr-news)\n // (missing in every row: the names any row has are the candidates)\n let first: { seg: string; names: string[]; row: boolean } | null = null;\n for (const row of v) {\n const m = under(engine, chain, k + 1, row, named);\n if (m === null) return null;\n if (first === null) first = m;\n else if (m.seg === first.seg) for (const n of m.names) if (!first.names.includes(n)) first.names.push(n);\n }\n return first;\n }\n if (Array.isArray(v) && /^\\d+$/.test(q.last)) {\n // an explicit index: only a row that is there can be looked into\n if (Number(q.last) >= v.length) return null;\n v = v[Number(q.last)];\n continue;\n }\n const d = findDescriptor(v, q.last);\n // a top-level key a re-set dropped is declared: it reads undefined, and a write fills it\n if (d === undefined && q.parent === null && engine.dropped.has(q.last)) return null;\n if (d === undefined) {\n const names = keysOf(v);\n // getters declared one level under the same parent (`items.*.subtotal`)\n const parent = named(q.parent);\n for (const g of engine.patterns.all()) if (g.parent === parent && g.getter !== null) names.push(g.last);\n return { seg: q.last, names, row: chain.slice(0, k).some((x) => x.last === \"*\") };\n }\n if (d.get !== undefined || d.set !== undefined) return null;\n v = d.value;\n }\n return null;\n}\n\nfunction check(engine: Engine): void {\n due.delete(engine);\n const map = named.get(engine);\n if (map === undefined) return;\n let done = checked.get(engine);\n if (done === undefined) checked.set(engine, (done = new Set()));\n // The paths named, and those a getter read (`this[\"items.*.pirce\"]`, `$getAll(\"items.*.pirce\")`): such a read\n // gets undefined, and what is computed from it is wrong without a word (an outside evaluation, a tax return\n // draft). A top-level key the state lacks already fails the read (the core's error); a named path is reported\n // as named; the engine's own accessor of an index path (`items.0.x`) reads for the binding that named it\n const todo = new Map(map);\n const readers = new Map<Pattern, Pattern>();\n for (const p of engine.patterns.all()) {\n const g = p.parent === null || done.has(p) || map.has(p) ? undefined : p.dependents.find((d) => !d.markup);\n if (g === undefined) continue;\n readers.set(p, g);\n todo.set(p, READ);\n }\n for (const [p, kind] of todo) {\n if (done.has(p)) continue;\n done.add(p);\n const m = missing(engine, p);\n if (m === null) continue;\n // under the mount path of a volume on the page still loading: checked again once it settles (3.x D22)\n const v = [...((engine.root as ParentNode | null)?.querySelectorAll(`${config.tagNames.state}[mount]`) ?? [])]\n .find((e) => !settled.has(e) && (p.path + \".\").startsWith(e.getAttribute(\"mount\") + \".\"));\n if (v !== undefined) {\n done.delete(p);\n void (v as WcsState).initializePromise.then(() => {\n settled.add(v);\n schedule(engine);\n });\n continue;\n }\n // a row of `for: groups.0.items` with a row getter declared on `groups.*.items.*` (#388)\n const w = engine.patterns.peek(parsePath(p.path).pattern);\n let rowGetter = \"\";\n if (w !== undefined && w !== p && w.getter !== null) {\n const loops = w.lists.slice(1).map((l, k) => `for: ${k === 0 ? l!.path : l!.path.slice(w.lists[k]!.path.length + 2)}`);\n rowGetter = ` The getter \"${w.path}\" is declared for the rows of ${loops.join(\" → \")}; a list named by an index has rows of its own.`;\n }\n const near = didYouMean(m.seg, m.names);\n // A row field no row has is not a sign of a mistake: rows are data, and an optional field (the\n // `pending` a page puts on its own rows) is absent from the server's (docs/seam-apps.md, ssr-news).\n // Reported only with a near name — a likely typo (`.nmae` beside `name`) — or a row getter of\n // another list form. So is a getter's read: `this[\"opts.flag\"] ?? false` reads an optional key on purpose\n if ((m.row || kind === READ) && near === \"\" && rowGetter === \"\") continue;\n const [code, subject, source] = kind === WATCH ? [\"watch-path-missing\", \"$watch path\", \"watch\"]\n : kind === POST ? [\"post-update-path-missing\", \"$postUpdate path\", \"postUpdate\"]\n : kind === READ ? [\"read-path-missing\", \"Path\", \"getter\"]\n : [\"binding-path-missing\", \"Bound path\", \"binding\"];\n hooks.noticed?.(engine, { \"type\": \"state:path-unresolved\", \"source\": source, \"path\": p.path, \"missingSegment\": m.seg });\n console.warn(`[@wcstack/state] [wcs/${code}] ${subject} \"${p.path}\"${kind === READ ? ` read by the getter \"${readers.get(p)!.path}\"` : \"\"} does not resolve on the state tree: \"${m.seg}\" is not declared.${near}${rowGetter} ${kind === POST ? \"The call updates nothing.\" : kind === READ ? \"The getter reads undefined.\" : \"Updates to this path will be silently dropped.\"}${LINT_HINT}`);\n }\n}\n\nfunction schedule(engine: Engine): void {\n if (due.has(engine)) return;\n due.add(engine);\n setTimeout(() => check(engine), 0);\n}\n\n/** The `declared` hook: a path a binding or a `$watch` key names. */\nfunction declared(engine: Engine, p: Pattern, watch = false): void {\n note(engine, p, watch ? WATCH : BINDING);\n}\n\nfunction note(engine: Engine, p: Pattern, kind: number): void {\n // a missing top-level key already fails the binding's read (the core's error)\n if (p.path[0] === \"$\" || p.path.includes(\"#\") || (kind === BINDING && p.parent === null)) return;\n let map = named.get(engine);\n if (map === undefined) named.set(engine, (map = new Map()));\n if (!map.has(p)) map.set(p, kind);\n schedule(engine);\n}\n\nconst wrapped = new WeakSet<Engine>();\n/** A `$postUpdate` is running: what it lands is not a write (see written). */\nlet posting = false;\n\n/**\n * `$postUpdate(path)` says what at a path changed in place; a path that does not resolve updates nothing,\n * and said nothing (`rows.${r}.cell.${c}.text` for `cells` — a 7GUIs evaluation's Cells). Its pattern is\n * checked as a binding's is, the top-level key too (no read fails for it).\n */\nfunction watchPostUpdate(engine: Engine): void {\n if (wrapped.has(engine)) return;\n wrapped.add(engine);\n const api = (engine as any).api as Record<string, (path: string) => void>;\n const post = api.$postUpdate;\n api.$postUpdate = (path: string) => {\n posting = true;\n try {\n post(path);\n } finally {\n posting = false;\n }\n const p = engine.patterns.peek(parsePath(path).pattern);\n if (p !== undefined) note(engine, p, POST);\n };\n}\n\n/** The top-level keys a state declared (its own and its prototypes'), and those written since, by engine. */\nconst declaredKeys = new WeakMap<Engine, Set<string>>();\n\n/**\n * A write of a top-level key the state did not declare, beside a near one it did (`this.selectedID` and\n * `selectedId`): 4.0 creates the key, and nothing bound to the declared one changes (a 7GUIs evaluation's\n * CRUD). Warned once per key; a key with no near name is one the state adds on purpose.\n */\nfunction written(engine: Engine, p: Pattern): void {\n const keys = declaredKeys.get(engine);\n const key = p.last;\n if (p.parent !== null || posting || keys === undefined || keys.has(key) || key[0] === \"$\" || engine.dropped.has(key)) return;\n const near = didYouMean(key, [...keys]);\n keys.add(key);\n // (a volume grafts its state at its mount path, and the keys on the way to it: those keys are the page's)\n if (near !== \"\" && ![...((engine.root as ParentNode | undefined)?.querySelectorAll(`${config.tagNames.state}[mount]`) ?? [])]\n .some((e) => `${e.getAttribute(\"mount\")}.`.startsWith(`${key}.`))) {\n console.warn(`[@wcstack/state] [wcs/write-path-missing] \"${key}\" is not declared: writing it creates a new key.${near}${LINT_HINT}`);\n }\n}\n\n// ---------------------------------------------------------------- commands that reach nothing\n\n/**\n * A command token emitted while nothing subscribes to it: the call is lost, and tokens keep nothing to replay.\n * Its `command.` binding may not be attached yet — the element is defined later (an autoloader, a slow CDN),\n * or it is in an `if:` branch the same update renders (emit from `$renderedCallback`) — or there is none.\n * Warned once per token (the author's decision, docs/v4-direction-2026-10.md §5.2 — a 7GUIs evaluation's Timer\n * and Cells). The engine's `commands` is watched from its first declaration on, so the tokens of a re-set\n * are wrapped too.\n */\nfunction watchCommands(engine: Engine): void {\n if (Object.getOwnPropertyDescriptor(engine, \"commands\")?.set !== undefined) return;\n let ns = engine.commands;\n Object.defineProperty(engine, \"commands\", {\n configurable: true,\n get: () => ns,\n set: (v: Readonly<Record<string, Token>>) => {\n ns = v;\n for (const t of Object.values(v)) loud(t);\n },\n });\n}\n\nconst wrappedTokens = new WeakSet<Token>();\n\nfunction loud(t: Token): void {\n if (wrappedTokens.has(t)) return;\n wrappedTokens.add(t);\n const emit = t.emit;\n let said = false;\n (t as any).emit = (...args: unknown[]): unknown[] => {\n if (t.size === 0 && !said) {\n said = true;\n console.warn(`[@wcstack/state] [wcs/command-token-unbound] \"$command.${t.name}\" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${LINT_HINT}`);\n }\n return emit.apply(t, args);\n };\n}\n\n/** The handlers whose failure was explained, by engine. */\nconst explained = new WeakMap<Engine, Set<string>>();\n\n/**\n * The handler of a delegated `on<type>:` threw, and it reads `event.currentTarget`: that is the root there,\n * not the element (`getBoundingClientRect` is not a function, a `.value` is undefined). Said once per handler,\n * after the error (the author's decision, docs/v4-direction-2026-10.md §5.2 — a 7GUIs evaluation).\n */\nfunction handlerThrew(engine: Engine, path: string, type: string): void {\n let v: any = engine.target;\n for (const seg of path.split(\".\")) v = v == null ? undefined : findDescriptor(v, seg)?.value;\n if (typeof v !== \"function\" || !String(v).includes(\"currentTarget\")) return;\n let said = explained.get(engine);\n if (said === undefined) explained.set(engine, (said = new Set()));\n if (said.has(path)) return;\n said.add(path);\n console.warn(`[@wcstack/state] [wcs/delegated-current-target] \"${path}\" reads event.currentTarget, the root for a delegated on${type}:. Write on${type}#direct:, or use event.target.closest(…).${LINT_HINT}`);\n}\n\n/**\n * A drain made patterns (`loose`, before its sweep): a getter may have read a path for the first time — in a\n * row added since, or down a branch of its own code. Checked as the bindings' are; a drain that read no new\n * path schedules nothing.\n */\nfunction drained(engine: Engine): void {\n if (named.has(engine) && ((engine as any).loose as Pattern[]).length > 0) schedule(engine);\n}\n\n/** A re-set: every path is checked again against the new state. */\nfunction recheck(engine: Engine): void {\n checked.delete(engine);\n if (named.has(engine)) schedule(engine);\n}\n\n// ---------------------------------------------------------------- recursion's static checks\n\n/**\n * `$recursion` families that can never work (approved simplification: these checks moved out of\n * the core): a suffix naming the recursion structure itself, two families one of which is the\n * other a few repeats deeper, and a concrete key that one of the families expands to.\n */\nfunction checkRecursion(target: Record<string, any>): void {\n const decl = target.$recursion;\n if (decl === null || typeof decl !== \"object\") return;\n const entries = Object.entries(decl);\n if (entries.length !== 1 || typeof entries[0][1] !== \"string\") return;\n const [anchor, repeat] = entries[0] as [string, string];\n if (!anchor.endsWith(\".*\") || !repeat.endsWith(\".*\")) return;\n const list = anchor.slice(0, -2);\n const key = repeat.slice(0, -2);\n const step = `.${repeat}`;\n const head = `${list}.**`;\n const keys = keysOf(target);\n const families = keys.filter((k) => k.startsWith(head)).map((k) => k.slice(head.length));\n const bad = (why: string): never => raiseError(`[wcs/recursion-declaration-invalid] ${why}`);\n for (const s of families) {\n if (s === `.${key}` || s.startsWith(`.${key}.`)) {\n bad(`\"${head}${s}\" names the recursion structure itself (the \"${key}\" lists): recursive getters compute values over the nodes.`);\n }\n for (const t of families) {\n if (t.length > s.length && t.endsWith(s) && new RegExp(`^(?:${esc(step)})+$`).test(t.slice(0, t.length - s.length))) {\n bad(`\"${head}${s}\" and \"${head}${t}\" expand to the same concrete path at different depths (they differ by whole repetitions of \"${repeat}\"). Rename one of them.`);\n }\n }\n const re = new RegExp(`^${esc(anchor)}(?:${esc(step)})*${esc(s)}$`);\n for (const k of keys) {\n if (!k.includes(\"**\") && re.test(k)) bad(`\"${k}\" is already defined on the state, so the recursive getter \"${head}${s}\" cannot expand to it.`);\n }\n }\n}\n\nconst esc = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nlet trustedTypesReported = false;\n\n/**\n * An HTML sink write Trusted Types blocked: the browser's message names no fix, so say once\n * per page what to install (the same report as @wcstack/state 3.3).\n */\nfunction failed(_engine: Engine, error: unknown, binding: Binding): void {\n const prop = binding.name === \"html\" ? \"innerHTML\" : binding.name;\n if (trustedTypesReported || !(error instanceof TypeError) || !isHtmlSink(prop) || !(\"trustedTypes\" in globalThis)) return;\n trustedTypesReported = true;\n const cause = typeof getTrustedTypesPolicy()?.createHTML === \"function\"\n ? \"The injected policy's createHTML() did not return a TrustedHTML.\"\n : \"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.\";\n console.error(\n `[@wcstack/state] Writing to \"${prop}\" was blocked by Trusted Types (require-trusted-types-for 'script'). ${cause}\\n`\n + `Install a sanitizing policy before the first binding is applied:\\n`\n + ` globalThis[Symbol.for(\"wcstack.trustedTypes.policy\")] =\\n`\n + ` trustedTypes.createPolicy(\"my-app\", { createHTML: (s) => DOMPurify.sanitize(s) });\\n`\n + `Or bind the value as text instead of HTML. See docs/csp.md section 7.`,\n { element: binding.node, property: prop },\n );\n}\n\n// ---------------------------------------------------------------- the default getter\n\nconst warnedDetail = new WeakMap<Element, Set<string>>();\n\n/**\n * A wc-bindable property's event read with the default getter (`e.detail`): warns once per\n * element and property about the two shapes that cannot be what the element meant (README\n * \"What the element writes back\", as @wcstack/state 3.3). The write is applied as it is.\n * (a) no detail while the element's property has a value — a plain Event, or a forgotten detail;\n * (b) a detail object with a `<name>` key while the property is not an object — a wrapper.\n */\nfunction detail(el: Element, name: string, v: unknown): void {\n const prop = (el as any)[name];\n const reason = v === undefined\n ? prop === undefined ? null : `the event carried no detail (undefined) while element.${name} is ${typeof prop}`\n : v !== null && typeof v === \"object\" && Object.prototype.hasOwnProperty.call(v, name) && (prop === null || typeof prop !== \"object\")\n ? `the event's detail is an object with a \"${name}\" key while element.${name} is ${typeof prop}`\n : null;\n if (reason === null) return;\n let said = warnedDetail.get(el);\n if (said === undefined) warnedDetail.set(el, (said = new Set()));\n if (said.has(name)) return;\n said.add(name);\n console.warn(\n `[@wcstack/state] [wcs/default-getter-mismatch] <${el.localName}> \"${name}\": ${reason}. `\n + \"With no getter, state receives e.detail as-is. Dispatch the value itself as detail, or declare \"\n + `getter (e.g. (e) => e.detail.${name}, or (e) => e.target.${name}) on that wcBindable property.`,\n );\n}\n\n// ---------------------------------------------------------------- 3.x names 4.0 removed\n\n/**\n * Declarations 3.2 renamed, whose old names 4.0 removed: a declaration under one would do nothing.\n * (The core detected these and the two APIs below up to 4.0.0-rc.3; without this add-on they are\n * ignored like any other unknown `$` key.)\n */\nconst REMOVED_DECLARATIONS: [string, string][] = [[\"$streams\", \"$stream\"], [\"$updatedCallback\", \"$renderedCallback\"]];\n/** APIs 3.2 renamed, whose old names 4.0 removed: reading one fails with the name to write. */\nconst REMOVED_APIS: Readonly<Record<string, string>> = { \"$trackDependency\": \"$dependOn\", \"$untrackDependency\": \"$untracked\" };\n\n/** A state that declares a 3.x name 4.0 removed (`$scan` has no successor: $watch or $on). */\nfunction removedDeclarations(target: Record<string, any>): void {\n if (target.$scan !== undefined) raise(M.ScanRemoved);\n for (const [old, name] of REMOVED_DECLARATIONS) if (target[old] !== undefined) raise(M.DeclarationRemoved, [old, name]);\n}\n\nexport const diagnostics: Feature = {\n name: \"diagnostics\",\n install(): void {\n hooks.explain = explain;\n hooks.render = render;\n hooks.declared = declared;\n hooks.detail = detail;\n hooks.failed = chain(hooks.failed, failed);\n // the removed names first, before what is installed (the core checked them before it took the\n // state in): a refused state never reaches the other add-ons' runtimes\n const prev = hooks.declare;\n hooks.declare = (engine, target) => {\n removedDeclarations(target);\n prev?.(engine, target);\n checkRecursion(target);\n recheck(engine);\n watchPostUpdate(engine);\n watchCommands(engine);\n declaredKeys.set(engine, new Set(keysOf(target)));\n };\n hooks.handlerThrew = handlerThrew;\n hooks.written = chain(hooks.written, written);\n hooks.drained = chain(hooks.drained, drained);\n hooks.dollar = first(known, hooks.dollar, (_engine, key) => (Object.hasOwn(REMOVED_APIS, key) ? raise(M.ApiRemoved, [key, REMOVED_APIS[key]]) : undefined));\n },\n};\nexport default diagnostics;\n"],"mappings":"mVAUA,SAASA,EAAaC,EAAWC,EAAWC,GAC1C,GAAIC,KAAKC,IAAIJ,EAAEK,OAASJ,EAAEI,QAAUH,EAClC,OAAOA,EAAM,EAEf,IAAMI,EAAiB,IAAIC,MAAMN,EAAEI,OAAS,GACtCG,EAAiB,IAAID,MAAMN,EAAEI,OAAS,GAC5C,QAASI,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAC7BH,EAAKG,GAAKA,EAEZ,QAASC,EAAI,EAAGA,GAAKV,EAAEK,OAAQK,IAAK,CAClCF,EAAK,GAAKE,EACV,QAASD,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAAK,CAClC,IAAME,EAAOX,EAAEU,EAAI,KAAOT,EAAEQ,EAAI,GAAK,EAAI,EACzCD,EAAKC,GAAKN,KAAKS,IAAIN,EAAKG,GAAK,EAAGD,EAAKC,EAAI,GAAK,EAAGH,EAAKG,EAAI,GAAKE,EACjE,CACA,QAASF,EAAI,EAAGA,GAAKR,EAAEI,OAAQI,IAC7BH,EAAKG,GAAKD,EAAKC,EAEnB,CACA,OAAOH,EAAKL,EAAEI,OAChB,CAMO,SAASQ,EAAWC,EAAeC,GACxC,GAAqB,IAAjBD,EAAMT,OACR,MAAO,GAET,IAAMW,EAASF,EAAMG,cACjBC,EAAsB,KACtBC,EAAe,EACnB,QAAWC,KAAaL,EAAY,CAClC,IAAMM,EAAWtB,EAAaiB,EAAQI,EAAUH,cAAe,GAC3DI,EAAWF,IACbD,EAAOE,EACPD,EAAeE,EAEnB,CACA,OAAgB,OAATH,EAAgB,kBAAkBA,MAAW,EACtD,CAMO,IAAMI,EAAY,kDCxCZC,EAAQ,CACnB,GAAI,iBAAkB,kBAAmB,uBAAwB,2BACjE,iBAAkB,eAAgB,eA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ACfhB,EAAQ8C,OAAO9B,GACXlB,EAAMF,IAAIoB,IAAS4B,EAAS5B,EAClC,CA8HM0H,CAAQ1H,GA3Od,SAAyBA,GACvB,GAAI6D,EAAQjF,IAAIoB,GAAS,OACzB6D,EAAQ/D,IAAIE,GACZ,IAAMjE,EAAOiE,EAAejE,GACtB4L,EAAO5L,EAAI6L,YACjB7L,EAAI6L,YAAevH,IACjByD,GAAU,EACV,IACE6D,EAAKtH,EACP,SACEyD,GAAU,CACZ,CACA,IAAMhK,EAAIkG,EAAOW,EAASC,GAAKC,EAAUR,GAAMS,QACrC,IAANhH,GAAiB8J,EAAK5D,EAAQlG,EAlMzB,GAoMb,CA6NM+N,CAAgB7H,GA5LtB,SAAuBA,GACrB,QAAiE,IAA7DnC,OAAO6B,yBAAyBM,EAAQ,aAAa2B,IAAmB,OAC5E,IAAI9F,EAAKmE,EAAO8H,SAChBjK,OAAOkK,eAAe/H,EAAQ,WAAY,CACxCgI,cAAc,EACdtH,IAAK,IAAM7E,EACX8F,IAAM5I,IACJ8C,EAAK9C,EACL,QAAWoC,KAAK0C,OAAOoK,OAAOlP,GAAIoL,EAAKhJ,KAG7C,CAkLM+M,CAAclI,GACd+D,EAAapC,IAAI3B,EAAQ,IAAIrD,IAAIgD,EAAOc,MAE1C2C,EAAMqB,aAAeA,EACrBrB,EAAMY,GAAU/D,EAAMmD,EAAMY,GAASA,GACrCZ,EAAMsB,GAAUzE,EAAMmD,EAAMsB,GAASA,GACrCtB,EAAM+E,GAAShH,EAAMiH,EAAOhF,EAAM+E,GAAQ,CAACpD,EAAStK,IAASoD,OAAOC,OAAOmI,GAAcxL,GAAO+L,OAAoB,CAAC/L,EAAKwL,GAAaxL,UAAS,EAClJ,GAEK4N,GAAQjC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import{a as t,b as r,c as e,d as a,e as n,f as o,g as i,h as l,i as c,j as y,k as u}from"../chunks/chunk-2RBI6DVS.js";import{a as s,e as f}from"../chunks/chunk-CIBJLAA3.js";import{a as p}from"../chunks/chunk-UBGJGMSG.js";import"../chunks/chunk-BGUJ3HF6.js";var d,m=t=>r=>{let e=t(r);return t=>null==t?t:e(t)},g="en";function S(){if(s.locale!==d){d=s.locale;try{g=Intl.getCanonicalLocales(d)[0]}catch{console.warn(`[@wcstack/state] ${p(48,[d])}`),g="en"}}return g}var h=["full","long","medium","short"];function b(t,e){let[a,n]=t??[];return void 0===n&&void 0!==a&&h.includes(a)&&([a,n]=[void 0,a]),void 0!==n&&!h.includes(n)&&r(e,n),[a,n]}var{eq:M,ne:$,not:v,lt:k,le:j,gt:w,ge:F,falsy:D,truthy:L,boolean:x}=u,C={toFixed:{factory:t=>{let r=i(t?.[0]??"0","toFixed");return t=>("number"!=typeof t&&a("toFixed",t),t.toFixed(r))},arity:[0,1]},locale:{factory:t=>{let r=t?.[0];return t=>("number"!=typeof t&&a("locale",t),t.toLocaleString(r??S()))},arity:[0,1]},upper:{factory:m(()=>t=>String(t).toUpperCase()),arity:[0,0]},lower:{factory:m(()=>t=>String(t).toLowerCase()),arity:[0,0]},capitalize:{factory:m(()=>t=>{let r=String(t);return 0===r.length?r:1===r.length?r.toUpperCase():r.charAt(0).toUpperCase()+r.slice(1)}),arity:[0,0]},trim:{factory:m(()=>t=>String(t).trim()),arity:[0,0]},slice:{factory:m(t=>{let r=[l(t,0,"slice")],e=t?.[1];return typeof e<"u"&&r.push(i(e,"slice")),t=>String(t).slice(...r)}),arity:[1,2]},padStart:{factory:m(t=>{let r=l(t,0,"padStart"),e=t?.[1]??"0";return t=>String(t).padStart(r,e)}),arity:[1,2]},padEnd:{factory:m(t=>{let r=l(t,0,"padEnd"),e=t?.[1]??" ";return t=>String(t).padEnd(r,e)}),arity:[1,2]},repeat:{factory:m(t=>{let r=l(t,0,"repeat");return t=>String(t).repeat(r)}),arity:[1,1]},reverse:{factory:m(()=>t=>String(t).split("").reverse().join("")),arity:[0,0]},truncate:{factory:m(t=>{let r=l(t,0,"truncate"),e=t?.[1]??"…";return t=>{let a=String(t);return a.length<=r?a:a.slice(0,r)+e}}),arity:[1,2]},join:{factory:t=>{let r=t?.[0]??", ";return t=>(Array.isArray(t)||o("join"),t.join(r))},arity:[0,1]},round:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","round"));return t=>("number"!=typeof t&&a("round",t),Math.round(t*r)/r)},arity:[0,1]},floor:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","floor"));return t=>("number"!=typeof t&&a("floor",t),Math.floor(t*r)/r)},arity:[0,1]},ceil:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","ceil"));return t=>("number"!=typeof t&&a("ceil",t),Math.ceil(t*r)/r)},arity:[0,1]},percent:{factory:t=>{let r=i(t?.[0]??"0","percent");return t=>("number"!=typeof t&&a("percent",t),`${(100*t).toFixed(r)}%`)},arity:[0,1]},unit:{factory:m(r=>{let e=r?.[0]??t("unit");return t=>String(t)+e}),arity:[1,1]},date:{factory:t=>{let[r,e]=b(t,"date"),a=e&&{dateStyle:e};return t=>(t instanceof Date||n("date",t),t.toLocaleDateString(r??S(),a))},arity:[0,2]},time:{factory:t=>{let[r,e]=b(t,"time"),a=e&&{timeStyle:e};return t=>(t instanceof Date||n("time",t),t.toLocaleTimeString(r??S(),a))},arity:[0,2]},datetime:{factory:t=>{let[r,e]=b(t,"datetime"),a=e&&{dateStyle:e,timeStyle:e};return t=>(t instanceof Date||n("datetime",t),t.toLocaleString(r??S(),a))},arity:[0,2]},ymd:{factory:t=>{let r=t?.[0]??"-";return t=>{t instanceof Date||n("ymd",t);let e=t.getFullYear().toString(),a=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},hms:{factory:t=>{let r=t?.[0]??":";return t=>{t instanceof Date||n("hms",t);let e=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0"),o=t.getSeconds().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},eq:M,ne:$,not:v,lt:k,le:j,gt:w,ge:F,add:y("add",(t,r)=>t+r),sub:y("sub",(t,r)=>t-r),mul:y("mul",(t,r)=>t*r),div:y("div",(t,r)=>t/r),mod:y("mod",(t,r)=>t%r),abs:{factory:()=>t=>("number"!=typeof t&&a("abs",t),Math.abs(t)),arity:[0,0]},clamp:{factory:t=>{let r=l(t,0,"clamp"),e=l(t,1,"clamp");return t=>("number"!=typeof t&&a("clamp",t),Math.min(Math.max(t,r),e))},arity:[2,2]},int:{factory:()=>t=>parseInt(String(t),10),arity:[0,0]},float:{factory:()=>t=>parseFloat(String(t)),arity:[0,0]},falsy:D,truthy:L,defaults:{factory:(r,e)=>{let a=r?.[0]??t("defaults"),n=c(a,e);return t=>t||n},arity:[1,1]},coalesce:{factory:(r,e)=>{let a=r?.[0]??t("coalesce"),n=c(a,e);return t=>t??n},arity:[1,1]},boolean:x,number:{factory:()=>t=>Number(t),arity:[0,0]},string:{factory:()=>t=>String(t),arity:[0,0]},nullIfEmpty:{factory:()=>t=>""===t?null:t,arity:[0,0]},currency:{factory:r=>{let n=r?.[0]??t("currency"),o=r?.[1],i={style:"currency",currency:n};try{new Intl.NumberFormat("en",i);let t=Intl.supportedValuesOf?.("currency");if(t&&!t.includes(n.toUpperCase()))throw 0}catch{e(n)}return t=>("number"!=typeof t&&a("currency",t),t.toLocaleString(o??S(),i))},arity:[1,2]}},I=!1,U={name:"formats",install:function(){I||(I=!0,f(C))}},A=U;export{A as default,U as formats};
1
+ import{a as t,b as r,c as e,d as a,e as n,f as o,g as i,h as l,i as c,j as y,k as u}from"../chunks/chunk-FBBHQU7S.js";import{a as s,e as f}from"../chunks/chunk-T3FN37DU.js";import{a as p}from"../chunks/chunk-JWRQLKOQ.js";import"../chunks/chunk-TNYNJXEC.js";var d,m=t=>r=>{let e=t(r);return t=>null==t?t:e(t)},g="en";function S(){if(s.locale!==d){d=s.locale;try{g=Intl.getCanonicalLocales(d)[0]}catch{console.warn(`[@wcstack/state] ${p(48,[d])}`),g="en"}}return g}var h=["full","long","medium","short"];function b(t,e){let[a,n]=t??[];return void 0===n&&void 0!==a&&h.includes(a)&&([a,n]=[void 0,a]),void 0!==n&&!h.includes(n)&&r(e,n),[a,n]}var{eq:$,ne:v,not:M,lt:k,le:F,gt:j,ge:w,falsy:D,truthy:L,boolean:x}=u,C={toFixed:{factory:t=>{let r=i(t?.[0]??"0","toFixed");return t=>("number"!=typeof t&&a("toFixed",t),t.toFixed(r))},arity:[0,1]},locale:{factory:t=>{let r=t?.[0];return t=>("number"!=typeof t&&a("locale",t),t.toLocaleString(r??S()))},arity:[0,1]},upper:{factory:m(()=>t=>String(t).toUpperCase()),arity:[0,0]},lower:{factory:m(()=>t=>String(t).toLowerCase()),arity:[0,0]},capitalize:{factory:m(()=>t=>{let r=String(t);return 0===r.length?r:1===r.length?r.toUpperCase():r.charAt(0).toUpperCase()+r.slice(1)}),arity:[0,0]},trim:{factory:m(()=>t=>String(t).trim()),arity:[0,0]},slice:{factory:m(t=>{let r=[l(t,0,"slice")],e=t?.[1];return typeof e<"u"&&r.push(i(e,"slice")),t=>String(t).slice(...r)}),arity:[1,2]},padStart:{factory:m(t=>{let r=l(t,0,"padStart"),e=t?.[1]??"0";return t=>String(t).padStart(r,e)}),arity:[1,2]},padEnd:{factory:m(t=>{let r=l(t,0,"padEnd"),e=t?.[1]??" ";return t=>String(t).padEnd(r,e)}),arity:[1,2]},repeat:{factory:m(t=>{let r=l(t,0,"repeat");return t=>String(t).repeat(r)}),arity:[1,1]},reverse:{factory:m(()=>t=>String(t).split("").reverse().join("")),arity:[0,0]},truncate:{factory:m(t=>{let r=l(t,0,"truncate"),e=t?.[1]??"…";return t=>{let a=String(t);return a.length<=r?a:a.slice(0,r)+e}}),arity:[1,2]},join:{factory:t=>{let r=t?.[0]??", ";return t=>(Array.isArray(t)||o("join"),t.join(r))},arity:[0,1]},round:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","round"));return t=>("number"!=typeof t&&a("round",t),Math.round(t*r)/r)},arity:[0,1]},floor:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","floor"));return t=>("number"!=typeof t&&a("floor",t),Math.floor(t*r)/r)},arity:[0,1]},ceil:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","ceil"));return t=>("number"!=typeof t&&a("ceil",t),Math.ceil(t*r)/r)},arity:[0,1]},percent:{factory:t=>{let r=i(t?.[0]??"0","percent");return t=>("number"!=typeof t&&a("percent",t),`${(100*t).toFixed(r)}%`)},arity:[0,1]},unit:{factory:m(r=>{let e=r?.[0]??t("unit");return t=>String(t)+e}),arity:[1,1]},date:{factory:t=>{let[r,e]=b(t,"date"),a=e&&{dateStyle:e};return t=>(t instanceof Date||n("date",t),t.toLocaleDateString(r??S(),a))},arity:[0,2]},time:{factory:t=>{let[r,e]=b(t,"time"),a=e&&{timeStyle:e};return t=>(t instanceof Date||n("time",t),t.toLocaleTimeString(r??S(),a))},arity:[0,2]},datetime:{factory:t=>{let[r,e]=b(t,"datetime"),a=e&&{dateStyle:e,timeStyle:e};return t=>(t instanceof Date||n("datetime",t),t.toLocaleString(r??S(),a))},arity:[0,2]},ymd:{factory:t=>{let r=t?.[0]??"-";return t=>{t instanceof Date||n("ymd",t);let e=t.getFullYear().toString(),a=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},hms:{factory:t=>{let r=t?.[0]??":";return t=>{t instanceof Date||n("hms",t);let e=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0"),o=t.getSeconds().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},eq:$,ne:v,not:M,lt:k,le:F,gt:j,ge:w,add:y("add",(t,r)=>t+r),sub:y("sub",(t,r)=>t-r),mul:y("mul",(t,r)=>t*r),div:y("div",(t,r)=>t/r),mod:y("mod",(t,r)=>t%r),abs:{factory:()=>t=>("number"!=typeof t&&a("abs",t),Math.abs(t)),arity:[0,0]},clamp:{factory:t=>{let r=l(t,0,"clamp"),e=l(t,1,"clamp");return t=>("number"!=typeof t&&a("clamp",t),Math.min(Math.max(t,r),e))},arity:[2,2]},int:{factory:()=>t=>parseInt(String(t),10),arity:[0,0]},float:{factory:()=>t=>parseFloat(String(t)),arity:[0,0]},falsy:D,truthy:L,defaults:{factory:(r,e)=>{let a=r?.[0]??t("defaults"),n=c(a,e);return t=>t||n},arity:[1,1]},coalesce:{factory:(r,e)=>{let a=r?.[0]??t("coalesce"),n=c(a,e);return t=>t??n},arity:[1,1]},boolean:x,number:{factory:()=>t=>Number(t),arity:[0,0]},string:{factory:()=>t=>String(t),arity:[0,0]},nullIfEmpty:{factory:()=>t=>""===t?null:t,arity:[0,0]},currency:{factory:r=>{let n=r?.[0]??t("currency"),o=r?.[1],i={style:"currency",currency:n};try{new Intl.NumberFormat("en",i);let t=Intl.supportedValuesOf?.("currency");if(t&&!t.includes(n.toUpperCase()))throw 0}catch{e(n)}return t=>("number"!=typeof t&&a("currency",t),t.toLocaleString(o??S(),i))},arity:[1,2]}},U=!1,E={name:"formats",install:function(){U||(U=!0,f(C))}},I=E;export{I as default,E as formats};
2
2
  //# sourceMappingURL=formats.js.map
@@ -1,2 +1,2 @@
1
- import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-BGUJ3HF6.js";var s=new WeakMap,r=!1,i=/^(?!prototype$)[^\d.*$][^.*]*$/;function f(t,e){let l=e.$listKeys,n=new Map;if(void 0!==l){(null===l||"object"!=typeof l)&&o("$listKeys must be an object mapping list paths to a key field or function.");for(let e of Object.keys(l)){let s=l[e];"string"==typeof s?n.set(t.o(e),t=>t[s]):"function"==typeof s?n.set(t.o(e),s):o(`$listKeys "${e}" must be a field name or a function.`)}}s.set(e,n)}function u(t){if(null===t||"object"!=typeof t)return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function a(t,e,l){let n=new Map;for(let s of e){u(s)||o(`$listKeys "${t}": rows must be plain objects.`);let e=l(s);null==e&&o(`$listKeys "${t}": a row has no key.`),n.has(e)&&o(`$listKeys "${t}": duplicate key ${JSON.stringify(e)}.`),n.set(e,s)}return n}function y(t,e,l,n){if(r||!Array.isArray(n))return!1;let o=s.get(t.target)?.get(e);if(void 0===o)return!1;let f=t.it(e,l);if(!Array.isArray(f)||f===n)return!1;let u=a(e.t,f,o);a(e.t,n,o);let y=[],p=[],c=f.length===n.length;for(let t=0;t<n.length;t++){let e=n[t],l=u.get(o(e));y.push(l??e),void 0!==l&&p.push([t,l,e]),y[t]!==f[t]&&(c=!1)}let $=[];for(let[t,e,l]of p){for(let n of Object.keys(l))Object.is(e[n],l[n])||$.push([t,n,l[n]]);for(let n of Object.keys(e))!(n in l)&&null!==e[n]&&$.push([t,n,null])}if(c&&0===$.length)return!0;if(!c){r=!0;try{t.T(e,l,y)}finally{r=!1}}if($.length>0){let n=t.Ve(0===e.n?null:l,e);for(let[l,o,s]of $){if("__proto__"===o)continue;let r=n.f[l],f=i.test(o)?t.o(`${e.t}.*.${o}`):null;null===f?.getter?t.T(f,r,s):(r.R[o]=s,t.T(t.o(`${e.t}.*`),r,r.R,!0))}}return!0}var p={name:"list-keys",install(){t.de=e(t.de,f),t.Fe=l(n,t.Fe,y)}},c=p;export{c as default,p as listKeys};
1
+ import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-TNYNJXEC.js";var s=new WeakMap,r=!1,i=/^(?!prototype$)[^\d.*$][^.*]*$/;function f(t,e){let l=e.$listKeys,n=new Map;if(void 0!==l){(null===l||"object"!=typeof l)&&o("$listKeys must be an object mapping list paths to a key field or function.");for(let e of Object.keys(l)){let s=l[e];"string"==typeof s?n.set(t.o(e),t=>t[s]):"function"==typeof s?n.set(t.o(e),s):o(`$listKeys "${e}" must be a field name or a function.`)}}s.set(e,n)}function u(t){if(null===t||"object"!=typeof t)return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function a(t,e,l){let n=new Map;for(let s of e){u(s)||o(`$listKeys "${t}": rows must be plain objects.`);let e=l(s);null==e&&o(`$listKeys "${t}": a row has no key.`),n.has(e)&&o(`$listKeys "${t}": duplicate key ${JSON.stringify(e)}.`),n.set(e,s)}return n}function y(t,e,l,n){if(r||!Array.isArray(n))return!1;let o=s.get(t.target)?.get(e);if(void 0===o)return!1;let f=t.it(e,l);if(!Array.isArray(f)||f===n)return!1;let u=a(e.t,f,o);a(e.t,n,o);let y=[],p=[],c=f.length===n.length;for(let t=0;t<n.length;t++){let e=n[t],l=u.get(o(e));y.push(l??e),void 0!==l&&p.push([t,l,e]),y[t]!==f[t]&&(c=!1)}let $=[];for(let[t,e,l]of p){for(let n of Object.keys(l))Object.is(e[n],l[n])||$.push([t,n,l[n]]);for(let n of Object.keys(e))!(n in l)&&null!==e[n]&&$.push([t,n,null])}if(c&&0===$.length)return!0;if(!c){r=!0;try{t.A(e,l,y)}finally{r=!1}}if($.length>0){let n=t.Ke(0===e.n?null:l,e);for(let[l,o,s]of $){if("__proto__"===o)continue;let r=n.f[l],f=i.test(o)?t.o(`${e.t}.*.${o}`):null;null===f?.getter?t.A(f,r,s):(r.E[o]=s,t.A(t.o(`${e.t}.*`),r,r.E,!0))}}return!0}var p={name:"list-keys",install(){t.fe=e(t.fe,f),t.Ie=l(n,t.Ie,y)}},c=p;export{c as default,p as listKeys};
2
2
  //# sourceMappingURL=list-keys.js.map
@@ -1,2 +1,2 @@
1
- import{b as e}from"../chunks/chunk-UBGJGMSG.js";import{a as t}from"../chunks/chunk-BGUJ3HF6.js";var i={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function o(t,o){let a=t.localName;if(a.includes("-"))return null;let l=(e=>[...i["*"],...Object.hasOwn(i,e)?i[e]:[]])(a);return l.includes(o)||e(1205,[a,o,l.join(", ")],o,l),(e,t)=>e[o](...t[0]instanceof Event?[]:t)}var a={name:"native-commands",install(){t.or=o}},l=a;export{l as default,a as nativeCommands};
1
+ import{b as e}from"../chunks/chunk-JWRQLKOQ.js";import{a as t}from"../chunks/chunk-TNYNJXEC.js";var i={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function o(t,o){let a=t.localName;if(a.includes("-"))return null;let l=(e=>[...i["*"],...Object.hasOwn(i,e)?i[e]:[]])(a);return l.includes(o)||e(1205,[a,o,l.join(", ")],o,l),(e,t)=>e[o](...t[0]instanceof Event?[]:t)}var a={name:"native-commands",install(){t.or=o}},l=a;export{l as default,a as nativeCommands};
2
2
  //# sourceMappingURL=native-commands.js.map
@@ -1,2 +1,2 @@
1
- import{m as e}from"../chunks/chunk-UPSLR4FS.js";import{b as t}from"../chunks/chunk-UBGJGMSG.js";import{a as r,b as l,c as n,d as s,j as a}from"../chunks/chunk-BGUJ3HF6.js";var i="$recursion",o=new WeakMap,c=new WeakSet,u=new WeakSet,h=0,d=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$=e=>`[wcs/recursion-${e}]`;function f(e,t){let r=r=>a(`${$("declaration-invalid")} ${i} ${e} "${String(t)}" ${r}`);("string"!=typeof t||""===t)&&a(`${$("declaration-invalid")} ${i} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&r('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&r("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&r('must have exactly one "*", at the end.'),t.includes("#")&&r('must not contain "#".')}return"$"===t[0]&&r('must not start with "$".'),t}var p=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function g(e,t){let r=`${e.l}.**`,l=t.slice(r.length);return(!t.startsWith(r)||""!==l&&"."!==l[0]||l.includes("**"))&&a(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function m(e,t,r){let l=g(e,t),n=function(e,t){for(let r=t;null!==r;r=r.l.ae){let t=e.nodeList.exec(r.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r}}return null}(e,r);return null===n&&a(`[wcs/recursion-context] "${t}" uses "**", which is bound to the depth of the row it is evaluated in; there is none here — use $getAll("${t}", []) for every depth.`),p(e,n.k)+l}function y(e,t,r){let l=new Set,n=new Set,s=(e,r,s)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&a(`${$("cycle")} "${r}" is reachable from itself: the data under "${t.l}" must be a tree.`),n.has(e)&&a(`${$("shared-list")} "${r}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),s+1>128&&a(`${$("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${s+1} (the limit is 128).`),n.add(e),0)),i=(n,a)=>{for(let o of n){r(a,o);let n=e.o(`${p(t,a)}.${t.key}`),c=e.read(n,o);s(c,n.t,a+1)&&(l.add(c),i(e.Ve(o,n).f,a+1),l.delete(c))}},o=e.o(t.l),c=e.read(o,null);s(c,t.l,0)&&(l.add(c),i(e.Ve(null,o).f,0))}function w(r,l){let n=function(t){let r=t[i],l=[],n=new Set;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e))!n.has(t)&&t.includes("**")&&l.push([t,Object.getOwnPropertyDescriptor(e,t)]),n.add(t);if(void 0===r)return l.length>0&&e(l[0][0]),null;(null===r||"object"!=typeof r||Array.isArray(r))&&a(`${$("declaration-invalid")} ${i} must be an object mapping one anchor path to its repeating sub-path.`);let s=Object.entries(r);1!==s.length&&a(`${$("declaration-invalid")} ${i} must declare exactly one anchor (it declares ${s.length}).`);let o=f("anchor",s[0][0]),c=f("repeat",s[0][1]),u=o.slice(0,-2),h=c.slice(0,-2),p=`.${c}`,g=new Map,m=[],y=`${u}.**`;for(let[e,t]of l){let r=e.slice(y.length);(!e.startsWith(y)||""!==r&&"."!==r[0]||r.includes("**"))&&a(`[wcs/recursion-anchor] "${e}": a recursive key is "${y}" followed by a path (the anchor is "${o}").`),(""===r||r.split(".").slice(1).some(e=>""===e))&&a(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&a(`${$("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),g.set(r,t.get),m.push([new RegExp(`^${d(o)}((?:${d(p)})*)${d(r)}$`),r])}return{l:u,step:p,key:h,families:g,matchers:m,owners:new Map,nodeList:new RegExp(`^${d(u)}((?:${d(`.*.${h}`)})*)$`)}}(l),s=o.has(r);null!==n?(s||h++,o.set(r,n),u.add(r),c.has(r)||function(r){c.add(r);let l=r,n=l.ot;l.ot=t=>{let s=o.get(r);if(t.t.includes("**")){let l=r.I.jt(t.t)===t;return void(u.has(r)||void 0===s&&l?t.getter=()=>e(t.t):l||n.call(r,t))}if(void 0!==s&&null===t.getter)for(let[e,r]of s.matchers)if(e.test(t.t)){t.getter=s.families.get(r),t.n>0&&(t.A=l.je++),s.owners.set(t,s.l+".**"+r);break}n.call(r,t)};let s=l.resolve;l.resolve=(e,t)=>{let l=o.get(r);return s.call(r,void 0!==l&&e.includes("**")?m(l,e,t):e,t)};let i=l.getAll;l.getAll=(e,t)=>{let n=o.get(r);if(void 0===n||!e.includes("**"))return i.call(r,e,t);if(void 0===t)return i.call(r,m(n,e,l.u));(!Array.isArray(t)||t.length>0)&&a(`${$("getall-form")} $getAll("${e}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=g(n,e),c=[];return y(r,n,(e,t)=>{for(let l of i.call(r,p(n,e)+s,r.H(t)))c.push(l)}),c};let h=l.yn;l.yn=(e,n,s,i)=>{let c=o.get(r);if(void 0===c||!e.includes("**"))return h.call(r,e,n,s,i);Array.isArray(n)||t(9,[e]),n.length>0&&a(`${$("setall-form")} $setAll("${e}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof s||!0===i?.spread)&&a(`${$("setall-form")} $setAll("${e}", [], value) with "**" takes a plain value (no mapper, no spread).`),l.Le>0&&t(8);let u=g(c,e),d=u.replace(/\.\d+(?=\.|$)/g,".*");for(;d.startsWith(c.step);)d=d.slice(c.step.length);let f=c.key.split(".");(""===d||d===`.${c.key}.length`||f.some((e,t)=>d===`.${f.slice(0,t+1).join(".")}`))&&a(`${$("structural-write")} "${e}" writes the recursion structure itself (a node, its "${c.key}" list or that list's length, or an object on the way to it).`);for(let t of c.families.keys()){let r=t;for(;r.startsWith(c.step);)r=r.slice(c.step.length);(d===r||d.startsWith(`${r}.`))&&a(`${$("readonly")} "${e}" writes into the recursive getter "${c.l}.**${t}".`)}let m=[];y(r,c,(e,t)=>m.push([e,t]));let w=0;for(let[e,t]of m)w+=h.call(r,p(c,e)+u,r.H(t),s);return w}}(r)):s&&(o.delete(r),h--)}function v(e,t){if(0===h)return!1;let r=o.get(e);if(void 0===r)return!1;for(let e=t;null!==e;e=e.d){let l=r.owners.get(e);void 0!==l&&a(`${$("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var k={name:"recursion",install(){r.de=l(r.de,w),r.element=l(r.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){u.delete(e)}(e)}),r.Fe=n(s,r.Fe,v)}},b=k;export{b as default,k as recursion};
1
+ import{m as e}from"../chunks/chunk-CBMAVRYG.js";import{b as t}from"../chunks/chunk-JWRQLKOQ.js";import{a as r,b as l,c as n,d as s,j as a}from"../chunks/chunk-TNYNJXEC.js";var i="$recursion",o=new WeakMap,c=new WeakSet,u=new WeakSet,h=0,d=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$=e=>`[wcs/recursion-${e}]`;function f(e,t){let r=r=>a(`${$("declaration-invalid")} ${i} ${e} "${String(t)}" ${r}`);("string"!=typeof t||""===t)&&a(`${$("declaration-invalid")} ${i} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&r('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&r("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&r('must have exactly one "*", at the end.'),t.includes("#")&&r('must not contain "#".')}return"$"===t[0]&&r('must not start with "$".'),t}var p=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function g(e,t){let r=`${e.l}.**`,l=t.slice(r.length);return(!t.startsWith(r)||""!==l&&"."!==l[0]||l.includes("**"))&&a(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function m(e,t,r){let l=g(e,t),n=function(e,t){for(let r=t;null!==r;r=r.l.ce){let t=e.nodeList.exec(r.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r}}return null}(e,r);return null===n&&a(`[wcs/recursion-context] "${t}" uses "**", which is bound to the depth of the row it is evaluated in; there is none here — use $getAll("${t}", []) for every depth.`),p(e,n.k)+l}function w(e,t,r){let l=new Set,n=new Set,s=(e,r,s)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&a(`${$("cycle")} "${r}" is reachable from itself: the data under "${t.l}" must be a tree.`),n.has(e)&&a(`${$("shared-list")} "${r}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),s+1>128&&a(`${$("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${s+1} (the limit is 128).`),n.add(e),0)),i=(n,a)=>{for(let o of n){r(a,o);let n=e.o(`${p(t,a)}.${t.key}`),c=e.read(n,o);s(c,n.t,a+1)&&(l.add(c),i(e.Ke(o,n).f,a+1),l.delete(c))}},o=e.o(t.l),c=e.read(o,null);s(c,t.l,0)&&(l.add(c),i(e.Ke(null,o).f,0))}function y(r,l){let n=function(t){let r=t[i],l=[],n=new Set;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e))!n.has(t)&&t.includes("**")&&l.push([t,Object.getOwnPropertyDescriptor(e,t)]),n.add(t);if(void 0===r)return l.length>0&&e(l[0][0]),null;(null===r||"object"!=typeof r||Array.isArray(r))&&a(`${$("declaration-invalid")} ${i} must be an object mapping one anchor path to its repeating sub-path.`);let s=Object.entries(r);1!==s.length&&a(`${$("declaration-invalid")} ${i} must declare exactly one anchor (it declares ${s.length}).`);let o=f("anchor",s[0][0]),c=f("repeat",s[0][1]),u=o.slice(0,-2),h=c.slice(0,-2),p=`.${c}`,g=new Map,m=[],w=`${u}.**`;for(let[e,t]of l){let r=e.slice(w.length);(!e.startsWith(w)||""!==r&&"."!==r[0]||r.includes("**"))&&a(`[wcs/recursion-anchor] "${e}": a recursive key is "${w}" followed by a path (the anchor is "${o}").`),(""===r||r.split(".").slice(1).some(e=>""===e))&&a(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&a(`${$("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),g.set(r,t.get),m.push([new RegExp(`^${d(o)}((?:${d(p)})*)${d(r)}$`),r])}return{l:u,step:p,key:h,families:g,matchers:m,owners:new Map,nodeList:new RegExp(`^${d(u)}((?:${d(`.*.${h}`)})*)$`)}}(l),s=o.has(r);null!==n?(s||h++,o.set(r,n),u.add(r),c.has(r)||function(r){c.add(r);let l=r,n=l.ot;l.ot=t=>{let s=o.get(r);if(t.t.includes("**")){let l=r.O.wt(t.t)===t;return void(u.has(r)||void 0===s&&l?t.getter=()=>e(t.t):l||n.call(r,t))}if(void 0!==s&&null===t.getter)for(let[e,r]of s.matchers)if(e.test(t.t)){t.getter=s.families.get(r),t.n>0&&(t.F=l.Le++),s.owners.set(t,s.l+".**"+r);break}n.call(r,t)};let s=l.resolve;l.resolve=(e,t)=>{let l=o.get(r);return s.call(r,void 0!==l&&e.includes("**")?m(l,e,t):e,t)};let i=l.getAll;l.getAll=(e,t)=>{let n=o.get(r);if(void 0===n||!e.includes("**"))return i.call(r,e,t);if(void 0===t)return i.call(r,m(n,e,l.d));(!Array.isArray(t)||t.length>0)&&a(`${$("getall-form")} $getAll("${e}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=g(n,e),c=[];return w(r,n,(e,t)=>{for(let l of i.call(r,p(n,e)+s,r.H(t)))c.push(l)}),c};let h=l.wn;l.wn=(e,n,s,i)=>{let c=o.get(r);if(void 0===c||!e.includes("**"))return h.call(r,e,n,s,i);Array.isArray(n)||t(9,[e]),n.length>0&&a(`${$("setall-form")} $setAll("${e}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof s||!0===i?.spread)&&a(`${$("setall-form")} $setAll("${e}", [], value) with "**" takes a plain value (no mapper, no spread).`),l.Be>0&&t(8);let u=g(c,e),d=u.replace(/\.\d+(?=\.|$)/g,".*");for(;d.startsWith(c.step);)d=d.slice(c.step.length);let f=c.key.split(".");(""===d||d===`.${c.key}.length`||f.some((e,t)=>d===`.${f.slice(0,t+1).join(".")}`))&&a(`${$("structural-write")} "${e}" writes the recursion structure itself (a node, its "${c.key}" list or that list's length, or an object on the way to it).`);for(let t of c.families.keys()){let r=t;for(;r.startsWith(c.step);)r=r.slice(c.step.length);(d===r||d.startsWith(`${r}.`))&&a(`${$("readonly")} "${e}" writes into the recursive getter "${c.l}.**${t}".`)}let m=[];w(r,c,(e,t)=>m.push([e,t]));let y=0;for(let[e,t]of m)y+=h.call(r,p(c,e)+u,r.H(t),s);return y}}(r)):s&&(o.delete(r),h--)}function v(e,t){if(0===h)return!1;let r=o.get(e);if(void 0===r)return!1;for(let e=t;null!==e;e=e.c){let l=r.owners.get(e);void 0!==l&&a(`${$("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var k={name:"recursion",install(){r.fe=l(r.fe,y),r.element=l(r.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){u.delete(e)}(e)}),r.Ie=n(s,r.Ie,v)}},b=k;export{b as default,k as recursion};
2
2
  //# sourceMappingURL=recursion.js.map
@@ -1,2 +1,2 @@
1
- import{a as e,b as t,d as n}from"../chunks/chunk-BYQBV3ZC.js";import{b as o,n as l,o as r,p as i}from"../chunks/chunk-4ECL4ITF.js";import"../chunks/chunk-2RBI6DVS.js";import{e as a,f as s}from"../chunks/chunk-BI4645UG.js";import{a as u}from"../chunks/chunk-CIBJLAA3.js";import"../chunks/chunk-JK3B3LLB.js";import"../chunks/chunk-UPSLR4FS.js";import"../chunks/chunk-UBGJGMSG.js";import{a as c,b as f,c as d,d as h,f as p,h as m,j as g}from"../chunks/chunk-BGUJ3HF6.js";var $=new WeakMap,b=new WeakMap,w="will not graft: the root state failed to initialize.",y=new WeakSet,v=new WeakMap,k=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],j=["$commandTokens","$eventTokens","$on","$errorCallback"],O=e=>`[@wcstack/state] <${u.tagNames.state} mount="${e}">`,x=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),N=e=>e?.element?.isConnected?e:void 0;function C(e){let t=b.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function A(e,t){let n=b.get(t);if(b.delete(t),Array.isArray(n))for(let t of n)W(t,e)}function P(e){let t=$.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function S(e,t){console.error(`${O(e.t)} ${t}`),P(e),e.Qe?.(),e.Qe=null}function M(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function W(e,t){if(y.has(t))return S(e,"will not graft: its component is wired to its host.");let n=e.state,o=t.target,l=e.t.split("."),r=o;for(let e of l)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return S(e,`will not graft: the root state already has "${e.t}".`);let i=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,o){if("symbol"==typeof o)return;if(36!==o.charCodeAt(0))return e.proxy[n(o)];let l=e.proxy[o];return"$eqPath"===o?(e,t)=>l(n(e),n(t)):x.has(o)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,o,l)=>"symbol"!=typeof o&&(e.proxy[n(o)]=l,!0)})}(t,e.t);e.chroot=i;let a={},s={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:o,set:l,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==o||void 0!==l)s[`${e.t}.${n}`]={get:o&&function(){return o.call(i)},set:l&&function(e){l.call(i,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(i);s[`${e.t}.${n}`]={get:()=>t}}else a[n]=r}}if(void 0===r){for(let e=1;e<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.it(n,null)&&t.T(n,null,{})}t.T(t.o(e.t),null,a)}t.to(Object.defineProperties({},s));for(let e in s)t.He(t.o(e),null);e.engine=t;let c=v.get(t);void 0===c&&v.set(t,c=[]),c.push(e),e.el.isConnected&&M(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function D(e,t){let n=b.get(e);if(Array.isArray(n))for(let e of n)S(e,w);b.set(e,t)}var E=new WeakMap;function L(e,t){let n=e.getAttribute("mount");if(null===n)return null;let o={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(u.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=$.get(t);void 0===e&&$.set(t,e=new Map);let l=e.get(n);if(void 0!==l&&l!==o&&(null===l.engine?l.el.isConnected:N(l.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===l?.engine){let e=b.get(t);Array.isArray(e)&&b.set(t,e.filter(e=>e!==l)),l.Qe?.(),l.Qe=null}e.set(n,o)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{xo:!0,start(e){if(null!==r)return S(o,r);if($.get(t).get(n)===o){for(let t of k)if(void 0!==e[t])return S(o,`${t} is not run in a volume — declare it on the root state.`);for(let t of j)void 0!==e[t]&&console.warn(`${O(n)} ${t} is not run in a volume (it belongs to the root).`);return o.state=e,new Promise(e=>{o.Qe=e;let n=N(l.get(t)),r=b.get(t);void 0!==n?W(o,n):C(t)?S(o,w):b.set(t,[...Array.isArray(r)?r:[],o])})}},Je(){null!==o.engine&&M(o,"$connectedCallback")},Ln(){null!==o.engine&&M(o,"$disconnectedCallback")},reset(){g(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var B=new WeakMap,R=new WeakMap;function T(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||g(`${t} must be an array of state member names.`);let o=new Set;for(let e of n)("string"!=typeof e||""===e)&&g(`${t} entries must be non-empty strings.`),"$"===e[0]&&g(`${t} entry "${e}": internal ($) members are never exposed.`),o.has(e)&&g(`${t} entry "${e}" is duplicated.`),o.add(e);return n}function q(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let o=document.createDocumentFragment();for(let e of[...t.childNodes])o.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&g("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,o){e.includes("-")||g(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&g(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(o),r=T(o,"$bindables"),i=T(o,"$commands");for(let e of r){let t=l.get(e);void 0===t&&g(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&g(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of i){let t=l.get(e);void 0===t&&g(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&g(`$commands entry "${e}" is not a method: list it in $bindables.`)}let a={tag:e,bindables:r},s=new WeakMap,c=new WeakMap,f=o=>{if(s.has(o))return s.get(o);if(o.hasAttribute("data-wc-definition"))return null;let l=o.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let i=l.querySelector(u.tagNames.state);return s.set(o,i),B.set(o,a),null===i&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${u.tagNames.state}>: no change events.`),i},d=e=>f(e)?.engine??null,h=e=>Promise.resolve(f(e)?.initializePromise).then(()=>{let t=c.get(e);c.delete(e);let n=d(e);if(void 0!==t&&null!==n)for(let[e,o]of t)n.proxy[e]=o});class p extends HTMLElement{static{this.wcBindable=0===r.length&&0===i.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===i.length?{}:{commands:i.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==f(this)&&h(this)}get stateElement(){return f(this)}}for(let[e,t]of l)"function"==typeof t.value?Object.defineProperty(p.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=d(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(p.prototype,e,{configurable:!0,get(){return d(this)?.proxy[e]},set(t){let n=d(this);if(null!==n)n.proxy[e]=t;else{let n=c.get(this);void 0===n&&c.set(this,n=[]),n.push([e,t])}}});customElements.define(e,p)}(n.localName,o,l,t)},Je(){},Ln(){},reset(){g("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Q=new WeakMap,z=new WeakSet,H=new WeakMap,F=new WeakMap,J="data-wcs-wired",G=new WeakMap,I=new WeakMap,U=new WeakMap,V=0,X=new Set,Y={},K=["$watch","$stream","$renderedCallback"],Z=e=>e.split(".",1)[0];function _(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ee(e,t){let n=e.a,o=Z(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(J);else if(!ne(n,o)){let e=n.getAttribute(J)?.split(" ")??[];e.includes(o)||n.setAttribute(J,[...e,o].join(" "))}G.get(n)?.pe===o&&g(`<${n.localName}>.${o} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=Q.get(n);void 0===l&&Q.set(n,l=[]),l.push(e),t&&z.add(e);let r=H.get(n);return void 0===r&&H.set(n,r=new Map),r.has(o)||r.set(o,n[o]),F.get(n)?.(),!1}function te(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${u.tagNames.state}[bind-component]`)}function ne(e,t){let n=e.getAttribute(u.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function oe(t){let n=t.parentElement;for(;null!==n&&!te(n);)n=n.parentElement;let o=l.get(n??t.getRootNode()),r=o?.element;(r?.isConnected?r.V:null===n)&&(null===n?e(t):i(o,t))}var le=new Set;function re(e,t){le.has(e)||(le.add(e),console.warn(`[@wcstack/state] ${t}`))}var ie=(e,t)=>t in e.state;function ae(e,t){let n=se(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function se(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function ue(e,t,n){if(null!==n.getter)return;let o,l=e.host,r=l.engine,i=Z(n.t),s=l.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.d)return function(e,t){let n,o=t.d;for(;null!==o&&void 0===(n=e.ft.get(o));)o=o.d;if(null===o||void 0===n)return;let l=e.x,r=e.host.engine,i=r.o(n.p.t+t.t.slice(o.t.length));if(null===i.getter)return;let s=n,u=()=>{let n=ce(e,s.r);return 0===t.n?n:(r.resolve(_(i.t,[...r.H(n),...l.H(a(l.u,t.n))]),null),r.rr)};t.getter=()=>{let e=u();return i.n>0&&null===e?void 0:r.v(i,e)},null!==i.ie&&(t.ie=n=>{let o=u();fe(e,s.e,()=>r.T(i,o,n)),e.dn=t}),t.n>0&&(t.A=l.je++),e.ft.set(t,{e:s.e,p:i,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==i?ie(l,i):ae(l,i))return;o=s.me}else{if(null===t||null!==n.d||"$"===i[0]||ie(l,i))return;s=t,o=r.o(`${t.me.t}.${i}`)}let u=s.r,c=s;n.getter=()=>r.v(o,ce(e,u)),n.ie=t=>{fe(e,c,()=>r.T(o,u,t)),e.dn=n},e.ft.set(n,{e:s,p:o,r:u})}function ce(e,t){return null!==t&&!t.y&&g(`The host row of <${e.host.el.localName}> was removed.`),t}function fe(e,t,n){let o=X.has(e.x);X.add(e.x),e.from=t;try{n()}finally{o||X.delete(e.x),e.from=null}}var de=(e,t)=>t||!X.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function he(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,V+=t?1:-1;let n=e.host.engine,o=U.get(n);void 0===o&&U.set(n,o=new Map);for(let n of e.fe){let e=o.get(n.e.me);void 0===e&&o.set(n.e.me,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.$);if(void 0!==l){null===e.re&&function(e,t){let n=e.host,o=n.engine;e.re=new Map;let l=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let i of Object.getOwnPropertyNames(r)){if(l.has(i))continue;l.add(i);let a=Object.getOwnPropertyDescriptor(r,i);if(void 0===a.get&&void 0===a.set||"$"===i[0]||i.includes("*"))continue;let s=Z(i);if(i!==s&&!ie(n,s))continue;let u=o.o(`${t.me.t}.${i}`);if(null===u.getter)ge(o,u,t.me);else if(!pe.has(u.getter))continue;e.re.set(u,e.x.o(i))}}(e,l);for(let o of e.re.keys())t&&null===o.getter&&ge(n,o,l.me),n.P.be(n,o,l.r);e.re.size>0&&n.we(),t&&function(e,t){let n=e.host.engine;for(let[o,l]of e.re){let r=n.v(o.d,t.r);if(null===r||"object"!=typeof r||!(o.s in r))continue;let i=e.host.el.localName;re(`${i}|${o.t}`,`[wcs/mount-export-shadowed] <${i}>.${e.host.pe}.${l.t} is exported at "${o.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var pe=new WeakSet;function me(e,t,n,o){let l=U.get(e)?.get(t)?.get(n);if(void 0===l)return null;let r=null;for(let e of l)""!==e.e.$||!0!==e.m.re?.has(o)||e.m===r||(null!==r&&g(`[wcs/mount-export-ambiguous] "${o.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function ge(e,t,n){let o=t.d,l=t.s,r=()=>{let t=e.read(o,e.u);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let o=r();if(null!==o)return o[l];let i=me(e,n,e.u,t);return null===i?void 0:i.x.read(i.re.get(t),null)},pe.add(t.getter),t.ie=i=>{let a=null===r()?me(e,n,e.u,t):null;if(null===a){let t=e.read(o,e.u);return void(null!==t&&"object"==typeof t&&(t[l]=i))}let s=a.re.get(t);void 0===se(a.host.state,s.t)?.set&&g(`Cannot write to "${s.t}" on mounted <${a.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),a.x.T(s,null,i)},t.n>0&&(t.A=e.je++)}function $e(e,t,n,o,l,r){if(null!==t.getter)return e.P.be(e,t,n),void e.we();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Xt(n),null!==n.c)for(let t of n.c.values())e.X(t)}else e.$n(t,n);c.ve?.(e,t,n,o,l,r),e.He(t,n)}function be(e){let t=e.m.x;for(let[n,o]of e.m.ft)o.e===e.e&&(0===n.n?t.P.be(t,n,null):t.nn(n.h[n.n],e=>t.P.be(t,n,e)));t.we()}function we(e,t,n,o,l,r,i){let s=n.t.slice(t.t.length);if(""===s)return be(e);let u,c=e.m,f=c.x;if(""===e.e.$){u=s.slice(1);let e=Z(u);if("$"===e[0]||ie(c.host,e)||c.host.entries.some(e=>""!==e.$&&(u===e.$||u.startsWith(`${e.$}.`))))return}else u=e.e.$+s;let d=[];for(let e=t.n+1;e<=n.n;e++)d.push(a(o,e).b);f.resolve(_(u,d),null);let h=f.rp,p=f.rr;h.n>0&&null===p||$e(f,h,p,l,r,i)}function ye(e,t,n,o,l,r,i){if(0===V)return;let s=X.has(e);X.add(e);try{let s=I.get(e);!i&&void 0!==s&&s.fn&&!X.has(s.host.engine)&&function(e,t,n,o,l,r){let i,a=t;for(;null!==a&&void 0===(i=e.ft.get(a));)a=a.d;if(null===a||void 0===i)return;let s=e.host.engine;if(a===t&&e.dn===t)return void(e.dn=null);if(null!==i.r&&!i.r.y)return;let u=[...s.H(i.r),...e.x.H(n)];s.resolve(_(i.p.t+t.t.slice(a.t.length),u),null);let c=s.rp,f=s.rr;c.n>0&&null===f||fe(e,i.e,()=>$e(s,c,f,o,l,r))}(s,t,n,o,l,r),i&&void 0!==s&&s.fn&&null!==s.re&&function(e,t){let n=e.host.entries.find(e=>""===e.$),o=e.host.engine;for(let[l,r]of e.re)r===t&&(o.P.be(o,l,n.r),o.we())}(s,t);let u=U.get(e);if(void 0===u)return;for(let[e,s]of u)if(t.ee(e)){let u=s.get(0===e.n?null:a(n,e.n));if(void 0!==u)for(let a of[...u])de(a,i)&&we(a,e,t,n,o,l,r)}else if(e.ee(t))for(let[e,o]of[...s])if(0===t.n||a(e,t.n)===n)for(let e of[...o])de(e,i)&&be(e)}finally{s||X.delete(e)}}async function ve(e,o,l,i,a){if(i===Y)return;let f=m(i);f&&await f;let d=G.get(o);d.engine&&i.$recursion&&g(`[wcs/mount-dollar-declaration] <${o.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let h=d.O;if(null!==h&&h.el!==e&&h.el.isConnected&&g(`<${o.localName}> already has a connected <${u.tagNames.state} bind-component="${d.pe}">.`),null!==h&&he(h,!1),null!==h&&function(e,t,n){let o=e.x,l=`[${u.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),i=new Set,a=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&i.add(e)},s=(e,t)=>{for(let n=e.Cn(t);null!==n&&n!==t;n=n.nextSibling)a(n);a(t)};for(let e of o.ce.values())for(let t of e)if(null===t.D)a(t.a);else for(let e of t.D.G)s(t.D,e.S);for(let e of o.oe.values())for(let t of[e.E,...e.B??[]])null!==t&&s(t,t.S);for(let t of e.L)t.parentNode===n&&r(t)&&i.add(t);if(0===i.size)return!1;let c=[...n.childNodes].filter(n=>n!==t&&!i.has(n)&&!e.L.includes(n)&&(r(n)||o.Wt&&n.textContent.includes("{{")));return c.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${c.length} node(s) added beside the content taken over are not bound.`),!0}(h,e,l))return async function(e,t,n,o){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await ke(e,o):o()}(h,e,l,a);let p=new s(i,new n);p.element=e,e.engine=p,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let o=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof o&&"constructor"!==t&&n.set(o,null)}let o=(t,n,o)=>Reflect.apply(t,e.proxy,o);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:o})),t}}(p,i);let $={el:e,L:[],x:p,host:d,fe:[],ft:new Map,fn:!1,dn:null,from:null,re:null};for(let e of d.entries)$.fe.push({m:$,e});d.O=$,I.set(p,$);let b=null===d.engine;b?c.element?.(p,"mounting"):(function(e){let t=e.x,n=e.host,o=n.engine,l=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Z(e.$);ie(n,t)&&(e.$!==t||ae(n,t))&&re(`${l}.${e.$}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.pe}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=o.v(r.me,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&re(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${r.me.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let i=K.filter(e=>void 0!==n.state[e]);i.length>0&&re(`${l}.${n.pe}$`,`[wcs/mount-dollar-declaration] <${l}>: ${i.join(", ")} ${1===i.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let a=t.ot;t.ot=n=>{ue(e,r,n),a.call(t,n)};let s=[...t.I.all()];for(let t of s)ue(e,r,t);for(let e of s)a.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=I.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}($),he($,!0),y.add(p),A(p,l));let w=c.hr?.(l);r(p,l),w?.(),$.L=[...l.childNodes],t(),b&&p.En(),Object.defineProperty(o,d.pe,{configurable:!0,enumerable:!0,get:()=>p.proxy});let v=o.$stateReadyCallback;if("function"==typeof v)try{let e=v.call(o,d.pe);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}a(),e.isConnected?(await p.Se("$connectedCallback"),b&&e.isConnected&&c.element?.(p,"connected")):he($,!1)}async function ke(e,t){he(e,!0);for(let t of e.fe)be(t);t?.(),!e.broken&&(await e.x.Se("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function je(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=l.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){D(t,e);for(let e of E.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,a=i?r.host:r instanceof Element?r:null,s=()=>{let t=null===a?void 0:G.get(a)?.O;return t?.el===e?t:null},f=t=>{throw i&&D(r,e),t},d=!1;return{bt:()=>(null!==a&&a.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&g(`<${u.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await o(n).whenDefined(r);let i=G.get(n);if(void 0!==i)return i.pe!==t&&g(`<${r}> already has a <${u.tagNames.state} bind-component="${i.pe}">.`),i.state;let a=()=>(Q.get(n)??[]).filter(e=>Z(e.name)===t),s=ne(n,t);if(s&&0===a().length&&oe(n),0===a().length&&(s||((e,t)=>!0===e.getAttribute(J)?.split(" ").includes(t))(n,t))){let e;await new Promise((o,l)=>{F.set(n,o),e=function(e,t){C(e)&&t();let n=E.get(e)??new Set;return E.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>l(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}F.delete(n);let c=a(),f=H.get(n),d=void 0!==f&&f.has(t)?f.get(t):n[t];if((null===d||"object"!=typeof d)&&g(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===d?"null":typeof d}.`),0===c.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${u.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Y}let h=[];for(let e of c){let o=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===o)&&g(`<${r}> maps "${e.name}" twice.`);let l=o.split(".").indexOf("*");if(l>=0){let n=o.split(".").slice(0,l).join(".");g(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:o,me:e.o,r:e.r,ro:z.has(e)}),e.engine.xn(e),""!==o&&delete n[e.name]}let p=0===c.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(d):d;return G.set(n,i={el:n,pe:t,state:p,engine:0===c.length?null:c[0].engine,entries:h,O:null}),p}(e,n,a,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${u.tagNames.state}> to be a direct child of a custom element.`))).catch(f),async start(t,n){await ve(e,a,i?r:a,t,()=>{d=!0,n()}).catch(e=>{let t=s();return!d&&null!==t&&(t.broken=!0),f(e)})},Je(){let t=s();null!==t?ke(t).catch(e=>console.error(e)):d?Promise.resolve().then(()=>{if(e.parentNode===r)return ve(e,a,i?r:a,G.get(a).state,()=>{})}).catch(e=>console.error(e)):F.has(a)&&oe(a)},Ln(){let e=s();null!==e&&(he(e,!1),!e.broken&&(e.x.Se("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){g(`re-setting a component's state is not supported: write <${a?.localName}>.${n} instead.`)}}}var Oe={name:"scopes",install(){c.ct=d(p,c.ct,L),c.ct=d(p,c.ct,q),c.ct=d(p,c.ct,je),c.ar=ee,c.$o=te,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=v.get(e)??[];if("disconnected"===t)for(let e of n)P(e);else if("reset"!==t&&N(l.get(e.root))===e){A(e,e.root);for(let e of n)$.get(e.root).has(e.t)||$.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();A(e,n),function(e,t){let n=t.host,o=void 0===n?void 0:B.get(n);void 0!==o&&R.set(e,{host:n,def:o})}(e,n)}),c.ve=f(c.ve,(e,t,n,o,l,r)=>{(function(e,t,n,o){let l=R.get(e);if(void 0===l)return;let r=t.t.split(".",1)[0];if(!l.def.bindables.includes(r))return;let i=o&&t.t===r;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${r}-changed`,{detail:i?n:void 0,bubbles:!0}))})(e,t,l,r),ye(e,t,n,o,l,r,!1)}),c.ke=f(c.ke,(e,t,n)=>ye(e,t,n,void 0,void 0,!1,!0)),c.Fe=d(h,c.Fe,(e,t,n,o,l)=>(function(e,t){let n=v.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&g(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let o,l=I.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===o;e=e.d)o=l.ft.get(e);if(void 0===o)return!1;let r=o.e;return!((null===r.r||r.r.y)&&!r.ro)&&(!!n||(ce(l,r.r),void g(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.pe}${""===r.$?"":`.${r.$}`}#ro: ${r.me.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let e=c.de;c.de=(t,n)=>{let o=v.get(t);void 0!==o&&o.length>0&&g(`re-setting a root state with grafted volumes (${o.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=U.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&g("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},xe=Oe;export{xe as default,Oe as scopes};
1
+ import{a as e,b as t,d as n}from"../chunks/chunk-GBBBRPZR.js";import{b as o,p as l,q as r,r as i}from"../chunks/chunk-467LYA2V.js";import"../chunks/chunk-FBBHQU7S.js";import{e as a,f as s}from"../chunks/chunk-ZJYPRSTO.js";import{a as u}from"../chunks/chunk-T3FN37DU.js";import"../chunks/chunk-NITPUCPA.js";import"../chunks/chunk-CBMAVRYG.js";import"../chunks/chunk-JWRQLKOQ.js";import{a as c,b as d,c as f,d as h,f as p,h as m,j as g}from"../chunks/chunk-TNYNJXEC.js";var $=new WeakMap,y=new WeakMap,b="will not graft: the root state failed to initialize.",w=new WeakSet,v=new WeakMap,k=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],j=["$commandTokens","$eventTokens","$on","$errorCallback"],P=e=>`[@wcstack/state] <${u.tagNames.state} mount="${e}">`,N=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),O=e=>e?.element?.isConnected?e:void 0;function A(e){let t=y.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function C(e,t){let n=y.get(t);if(y.delete(t),Array.isArray(n))for(let t of n)W(t,e)}function x(e){let t=$.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function M(e,t){console.error(`${P(e.t)} ${t}`),x(e),e.Qe?.(),e.Qe=null}function S(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function W(e,t){if(w.has(t))return M(e,"will not graft: its component is wired to its host.");let n=e.state,o=t.target,l=e.t.split("."),r=o;for(let e of l)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return M(e,`will not graft: the root state already has "${e.t}".`);let i=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,o){if("symbol"==typeof o)return;if(36!==o.charCodeAt(0))return e.proxy[n(o)];let l=e.proxy[o];return"$eqPath"===o?(e,t)=>l(n(e),n(t)):N.has(o)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,o,l)=>"symbol"!=typeof o&&(e.proxy[n(o)]=l,!0)})}(t,e.t);e.chroot=i;let a={},s={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:o,set:l,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==o||void 0!==l)s[`${e.t}.${n}`]={get:o&&function(){return o.call(i)},set:l&&function(e){l.call(i,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(i);s[`${e.t}.${n}`]={get:()=>t}}else a[n]=r}}if(void 0===r){for(let e=1;e<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.it(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,a)}t.no(Object.defineProperties({},s));for(let e in s)t.Ue(t.o(e),null);e.engine=t;let c=v.get(t);void 0===c&&v.set(t,c=[]),c.push(e),e.el.isConnected&&S(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function D(e,t){let n=y.get(e);if(Array.isArray(n))for(let e of n)M(e,b);y.set(e,t)}var E=new WeakMap;function T(e,t){let n=e.getAttribute("mount");if(null===n)return null;let o={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(u.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=$.get(t);void 0===e&&$.set(t,e=new Map);let l=e.get(n);if(void 0!==l&&l!==o&&(null===l.engine?l.el.isConnected:O(l.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===l?.engine){let e=y.get(t);Array.isArray(e)&&y.set(t,e.filter(e=>e!==l)),l.Qe?.(),l.Qe=null}e.set(n,o)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Po:!0,start(e){if(null!==r)return M(o,r);if($.get(t).get(n)===o){for(let t of k)if(void 0!==e[t])return M(o,`${t} is not run in a volume — declare it on the root state.`);for(let t of j)void 0!==e[t]&&console.warn(`${P(n)} ${t} is not run in a volume (it belongs to the root).`);return o.state=e,new Promise(e=>{o.Qe=e;let n=O(l.get(t)),r=y.get(t);void 0!==n?W(o,n):A(t)?M(o,b):y.set(t,[...Array.isArray(r)?r:[],o])})}},Je(){null!==o.engine&&S(o,"$connectedCallback")},Bn(){null!==o.engine&&S(o,"$disconnectedCallback")},reset(){g(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var R=new WeakMap,L=new WeakMap;function q(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||g(`${t} must be an array of state member names.`);let o=new Set;for(let e of n)("string"!=typeof e||""===e)&&g(`${t} entries must be non-empty strings.`),"$"===e[0]&&g(`${t} entry "${e}": internal ($) members are never exposed.`),o.has(e)&&g(`${t} entry "${e}" is duplicated.`),o.add(e);return n}function Q(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let o=document.createDocumentFragment();for(let e of[...t.childNodes])o.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&g("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,o){e.includes("-")||g(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&g(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(o),r=q(o,"$bindables"),i=q(o,"$commands");for(let e of r){let t=l.get(e);void 0===t&&g(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&g(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of i){let t=l.get(e);void 0===t&&g(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&g(`$commands entry "${e}" is not a method: list it in $bindables.`)}let a={tag:e,bindables:r},s=new WeakMap,c=new WeakMap,d=o=>{if(s.has(o))return s.get(o);if(o.hasAttribute("data-wc-definition"))return null;let l=o.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let i=l.querySelector(u.tagNames.state);return s.set(o,i),R.set(o,a),null===i&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${u.tagNames.state}>: no change events.`),i},f=e=>d(e)?.engine??null,h=e=>Promise.resolve(d(e)?.initializePromise).then(()=>{let t=c.get(e);c.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,o]of t)n.proxy[e]=o});class p extends HTMLElement{static{this.wcBindable=0===r.length&&0===i.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===i.length?{}:{commands:i.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==d(this)&&h(this)}get stateElement(){return d(this)}}for(let[e,t]of l)"function"==typeof t.value?Object.defineProperty(p.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(p.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=c.get(this);void 0===n&&c.set(this,n=[]),n.push([e,t])}}});customElements.define(e,p)}(n.localName,o,l,t)},Je(){},Bn(){},reset(){g("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var B=new WeakMap,I=new WeakSet,z=new WeakMap,F=new WeakMap,H="data-wcs-wired",J=new WeakMap,U=new WeakMap,Y=new WeakMap,V=0,X=new Set,G={},K=["$watch","$stream","$renderedCallback"],Z=e=>e.split(".",1)[0];function _(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ee(e,t){let n=e.a,o=Z(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(H);else if(!ne(n,o)){let e=n.getAttribute(H)?.split(" ")??[];e.includes(o)||n.setAttribute(H,[...e,o].join(" "))}J.get(n)?.he===o&&g(`<${n.localName}>.${o} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=B.get(n);void 0===l&&B.set(n,l=[]),l.push(e),t&&I.add(e);let r=z.get(n);return void 0===r&&z.set(n,r=new Map),r.has(o)||r.set(o,n[o]),F.get(n)?.(),!1}function te(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${u.tagNames.state}[bind-component]`)}function ne(e,t){let n=e.getAttribute(u.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function oe(t){let n=t.parentElement;for(;null!==n&&!te(n);)n=n.parentElement;let o=l.get(n??t.getRootNode()),r=o?.element;(r?.isConnected?r.V:null===n)&&(null===n?e(t):i(o,t))}var le=new Set;function re(e,t){le.has(e)||(le.add(e),console.warn(`[@wcstack/state] ${t}`))}var ie=(e,t)=>t in e.state;function ae(e,t){let n=se(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function se(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function ue(e,t,n){if(null!==n.getter)return;let o,l=e.host,r=l.engine,i=Z(n.t),s=l.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.c)return function(e,t){let n,o=t.c;for(;null!==o&&void 0===(n=e.pt.get(o));)o=o.c;if(null===o||void 0===n)return;let l=e.P,r=e.host.engine,i=r.o(n.p.t+t.t.slice(o.t.length));if(null===i.getter)return;let s=n,u=()=>{let n=ce(e,s.r);return 0===t.n?n:(r.resolve(_(i.t,[...r.H(n),...l.H(a(l.d,t.n))]),null),r.rr)};t.getter=()=>{let e=u();return i.n>0&&null===e?void 0:r.v(i,e)},null!==i.se&&(t.se=n=>{let o=u();de(e,s.e,()=>r.A(i,o,n)),e.dn=t}),t.n>0&&(t.F=l.Le++),e.pt.set(t,{e:s.e,p:i,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==i?ie(l,i):ae(l,i))return;o=s.ye}else{if(null===t||null!==n.c||"$"===i[0]||ie(l,i))return;s=t,o=r.o(`${t.ye.t}.${i}`)}let u=s.r,c=s;n.getter=()=>r.v(o,ce(e,u)),n.se=t=>{de(e,c,()=>r.A(o,u,t)),e.dn=n},e.pt.set(n,{e:s,p:o,r:u})}function ce(e,t){return null!==t&&!t.w&&g(`The host row of <${e.host.el.localName}> was removed.`),t}function de(e,t,n){let o=X.has(e.P);X.add(e.P),e.from=t;try{n()}finally{o||X.delete(e.P),e.from=null}}var fe=(e,t)=>t||!X.has(e.m.P)||null!==e.m.from&&e.m.from!==e.e;function he(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,V+=t?1:-1;let n=e.host.engine,o=Y.get(n);void 0===o&&Y.set(n,o=new Map);for(let n of e.pe){let e=o.get(n.e.ye);void 0===e&&o.set(n.e.ye,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.$);if(void 0!==l){null===e.ie&&function(e,t){let n=e.host,o=n.engine;e.ie=new Map;let l=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let i of Object.getOwnPropertyNames(r)){if(l.has(i))continue;l.add(i);let a=Object.getOwnPropertyDescriptor(r,i);if(void 0===a.get&&void 0===a.set||"$"===i[0]||i.includes("*"))continue;let s=Z(i);if(i!==s&&!ie(n,s))continue;let u=o.o(`${t.ye.t}.${i}`);if(null===u.getter)ge(o,u,t.ye);else if(!pe.has(u.getter))continue;e.ie.set(u,e.P.o(i))}}(e,l);for(let o of e.ie.keys())t&&null===o.getter&&ge(n,o,l.ye),n.T.ke(n,o,l.r);e.ie.size>0&&n.ve(),t&&function(e,t){let n=e.host.engine;for(let[o,l]of e.ie){let r=n.v(o.c,t.r);if(null===r||"object"!=typeof r||!(o.s in r))continue;let i=e.host.el.localName;re(`${i}|${o.t}`,`[wcs/mount-export-shadowed] <${i}>.${e.host.he}.${l.t} is exported at "${o.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var pe=new WeakSet;function me(e,t,n,o){let l=Y.get(e)?.get(t)?.get(n);if(void 0===l)return null;let r=null;for(let e of l)""!==e.e.$||!0!==e.m.ie?.has(o)||e.m===r||(null!==r&&g(`[wcs/mount-export-ambiguous] "${o.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function ge(e,t,n){let o=t.c,l=t.s,r=()=>{let t=e.read(o,e.d);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let o=r();if(null!==o)return o[l];let i=me(e,n,e.d,t);return null===i?void 0:i.P.read(i.ie.get(t),null)},pe.add(t.getter),t.se=i=>{let a=null===r()?me(e,n,e.d,t):null;if(null===a){let t=e.read(o,e.d);return void(null!==t&&"object"==typeof t&&(t[l]=i))}let s=a.ie.get(t);void 0===se(a.host.state,s.t)?.set&&g(`Cannot write to "${s.t}" on mounted <${a.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),a.P.A(s,null,i)},t.n>0&&(t.F=e.Le++)}function $e(e,t,n,o,l,r){if(null!==t.getter)return e.T.ke(e,t,n),void e.ve();if("*"===t.s){if(null===n)return;if(n.E=n.l.R[n.y],e.T.Xt(n),null!==n.u)for(let t of n.u.values())e.G(t)}else e.En(t,n);c.re?.(e,t,n,o,l,r),e.Ue(t,n)}function ye(e){let t=e.m.P;for(let[n,o]of e.m.pt)o.e===e.e&&(0===n.n?t.T.ke(t,n,null):t.nn(n.h[n.n],e=>t.T.ke(t,n,e)));t.ve()}function be(e,t,n,o,l,r,i){let s=n.t.slice(t.t.length);if(""===s)return ye(e);let u,c=e.m,d=c.P;if(""===e.e.$){u=s.slice(1);let e=Z(u);if("$"===e[0]||ie(c.host,e)||c.host.entries.some(e=>""!==e.$&&(u===e.$||u.startsWith(`${e.$}.`))))return}else u=e.e.$+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(a(o,e).y);d.resolve(_(u,f),null);let h=d.rp,p=d.rr;h.n>0&&null===p||$e(d,h,p,l,r,i)}function we(e,t,n,o,l,r,i){if(0===V)return;let s=X.has(e);X.add(e);try{let s=U.get(e);!i&&void 0!==s&&s.fn&&!X.has(s.host.engine)&&function(e,t,n,o,l,r){let i,a=t;for(;null!==a&&void 0===(i=e.pt.get(a));)a=a.c;if(null===a||void 0===i)return;let s=e.host.engine;if(a===t&&e.dn===t)return void(e.dn=null);if(null!==i.r&&!i.r.w)return;let u=[...s.H(i.r),...e.P.H(n)];s.resolve(_(i.p.t+t.t.slice(a.t.length),u),null);let c=s.rp,d=s.rr;c.n>0&&null===d||de(e,i.e,()=>$e(s,c,d,o,l,r))}(s,t,n,o,l,r),i&&void 0!==s&&s.fn&&null!==s.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.$),o=e.host.engine;for(let[l,r]of e.ie)r===t&&(o.T.ke(o,l,n.r),o.ve())}(s,t);let u=Y.get(e);if(void 0===u)return;for(let[e,s]of u)if(t.ee(e)){let u=s.get(0===e.n?null:a(n,e.n));if(void 0!==u)for(let a of[...u])fe(a,i)&&be(a,e,t,n,o,l,r)}else if(e.ee(t))for(let[e,o]of[...s])if(0===t.n||a(e,t.n)===n)for(let e of[...o])fe(e,i)&&ye(e)}finally{s||X.delete(e)}}async function ve(e,o,l,i,a){if(i===G)return;let d=m(i);d&&await d;let f=J.get(o);f.engine&&i.$recursion&&g(`[wcs/mount-dollar-declaration] <${o.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let h=f.I;if(null!==h&&h.el!==e&&h.el.isConnected&&g(`<${o.localName}> already has a connected <${u.tagNames.state} bind-component="${f.he}">.`),null!==h&&he(h,!1),null!==h&&function(e,t,n){let o=e.P,l=`[${u.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),i=new Set,a=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&i.add(e)},s=(e,t)=>{for(let n=e.In(t);null!==n&&n!==t;n=n.nextSibling)a(n);a(t)};for(let e of o.ue.values())for(let t of e)if(null===t.D)a(t.a);else for(let e of t.D.q)s(t.D,e.S);for(let e of o.oe.values())for(let t of[e.N,...e.M??[]])null!==t&&s(t,t.S);for(let t of e.L)t.parentNode===n&&r(t)&&i.add(t);if(0===i.size)return!1;let c=[...n.childNodes].filter(n=>n!==t&&!i.has(n)&&!e.L.includes(n)&&(r(n)||o.Wt&&n.textContent.includes("{{")));return c.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${c.length} node(s) added beside the content taken over are not bound.`),!0}(h,e,l))return async function(e,t,n,o){e.el.engine=null,e.el=t,e.P.element=t,t.engine=e.P,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await ke(e,o):o()}(h,e,l,a);let p=new s(i,new n);p.element=e,e.engine=p,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let o=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof o&&"constructor"!==t&&n.set(o,null)}let o=(t,n,o)=>Reflect.apply(t,e.proxy,o);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:o})),t}}(p,i);let $={el:e,L:[],P:p,host:f,pe:[],pt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of f.entries)$.pe.push({m:$,e});f.I=$,U.set(p,$);let y=null===f.engine;y?c.element?.(p,"mounting"):(function(e){let t=e.P,n=e.host,o=n.engine,l=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Z(e.$);ie(n,t)&&(e.$!==t||ae(n,t))&&re(`${l}.${e.$}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.he}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=o.v(r.ye,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&re(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${r.ye.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let i=K.filter(e=>void 0!==n.state[e]);i.length>0&&re(`${l}.${n.he}$`,`[wcs/mount-dollar-declaration] <${l}>: ${i.join(", ")} ${1===i.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let a=t.ot;t.ot=n=>{ue(e,r,n),a.call(t,n)};let s=[...t.O.all()];for(let t of s)ue(e,r,t);for(let e of s)a.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=U.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}($),he($,!0),w.add(p),C(p,l));let b=c.hr?.(l,p);r(p,l),b?.(),$.L=[...l.childNodes],t(),y&&p.Nn(),Object.defineProperty(o,f.he,{configurable:!0,enumerable:!0,get:()=>p.proxy});let v=o.$stateReadyCallback;if("function"==typeof v)try{let e=v.call(o,f.he);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}a(),e.isConnected?(await p.$e("$connectedCallback"),y&&e.isConnected&&c.element?.(p,"connected")):he($,!1)}async function ke(e,t){he(e,!0);for(let t of e.pe)ye(t);t?.(),!e.broken&&(await e.P.$e("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.P,"connected"))}function je(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=l.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){D(t,e);for(let e of E.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,a=i?r.host:r instanceof Element?r:null,s=()=>{let t=null===a?void 0:J.get(a)?.I;return t?.el===e?t:null},d=t=>{throw i&&D(r,e),t},f=!1;return{kt:()=>(null!==a&&a.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&g(`<${u.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await o(n).whenDefined(r);let i=J.get(n);if(void 0!==i)return i.he!==t&&g(`<${r}> already has a <${u.tagNames.state} bind-component="${i.he}">.`),i.state;let a=()=>(B.get(n)??[]).filter(e=>Z(e.name)===t),s=ne(n,t);if(s&&0===a().length&&oe(n),0===a().length&&(s||((e,t)=>!0===e.getAttribute(H)?.split(" ").includes(t))(n,t))){let e;await new Promise((o,l)=>{F.set(n,o),e=function(e,t){A(e)&&t();let n=E.get(e)??new Set;return E.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>l(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}F.delete(n);let c=a(),d=z.get(n),f=void 0!==d&&d.has(t)?d.get(t):n[t];if((null===f||"object"!=typeof f)&&g(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===f?"null":typeof f}.`),0===c.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${u.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),G}let h=[];for(let e of c){let o=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===o)&&g(`<${r}> maps "${e.name}" twice.`);let l=o.split(".").indexOf("*");if(l>=0){let n=o.split(".").slice(0,l).join(".");g(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:o,ye:e.o,r:e.r,ro:I.has(e)}),e.engine.Pn(e),""!==o&&delete n[e.name]}let p=0===c.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(f):f;return J.set(n,i={el:n,he:t,state:p,engine:0===c.length?null:c[0].engine,entries:h,I:null}),p}(e,n,a,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${u.tagNames.state}> to be a direct child of a custom element.`))).catch(d),async start(t,n){await ve(e,a,i?r:a,t,()=>{f=!0,n()}).catch(e=>{let t=s();return!f&&null!==t&&(t.broken=!0),d(e)})},Je(){let t=s();null!==t?ke(t).catch(e=>console.error(e)):f?Promise.resolve().then(()=>{if(e.parentNode===r)return ve(e,a,i?r:a,J.get(a).state,()=>{})}).catch(e=>console.error(e)):F.has(a)&&oe(a)},Bn(){let e=s();null!==e&&(he(e,!1),!e.broken&&(e.P.$e("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.P,"disconnected")))},reset(){g(`re-setting a component's state is not supported: write <${a?.localName}>.${n} instead.`)}}}var Pe={name:"scopes",install(){c.ut=f(p,c.ut,T),c.ut=f(p,c.ut,Q),c.ut=f(p,c.ut,je),c.ar=ee,c.Eo=te,c.element=d(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=v.get(e)??[];if("disconnected"===t)for(let e of n)x(e);else if("reset"!==t&&O(l.get(e.root))===e){C(e,e.root);for(let e of n)$.get(e.root).has(e.t)||$.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();C(e,n),function(e,t){let n=t.host,o=void 0===n?void 0:R.get(n);void 0!==o&&L.set(e,{host:n,def:o})}(e,n)}),c.re=d(c.re,(e,t,n,o,l,r)=>{(function(e,t,n,o){let l=L.get(e);if(void 0===l)return;let r=t.t.split(".",1)[0];if(!l.def.bindables.includes(r))return;let i=o&&t.t===r;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${r}-changed`,{detail:i?n:void 0,bubbles:!0}))})(e,t,l,r),we(e,t,n,o,l,r,!1)}),c.Se=d(c.Se,(e,t,n)=>we(e,t,n,void 0,void 0,!1,!0)),c.Ie=f(h,c.Ie,(e,t,n,o,l)=>(function(e,t){let n=v.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&g(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let o,l=U.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===o;e=e.c)o=l.pt.get(e);if(void 0===o)return!1;let r=o.e;return!((null===r.r||r.r.w)&&!r.ro)&&(!!n||(ce(l,r.r),void g(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.he}${""===r.$?"":`.${r.$}`}#ro: ${r.ye.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let e=c.fe;c.fe=(t,n)=>{let o=v.get(t);void 0!==o&&o.length>0&&g(`re-setting a root state with grafted volumes (${o.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Y.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&g("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},Ne=Pe;export{Ne as default,Pe as scopes};
2
2
  //# sourceMappingURL=scopes.js.map