@wcstack/state 3.3.0 → 3.5.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 (43) hide show
  1. package/README.ja.md +94 -27
  2. package/README.md +94 -27
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.d.ts +52 -1
  6. package/dist/index.esm.js +1 -1
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/split/chunks/binder.js +1 -1
  9. package/dist/split/chunks/binder.js.map +1 -1
  10. package/dist/split/chunks/checkDependency.js +1 -1
  11. package/dist/split/chunks/checkDependency.js.map +1 -1
  12. package/dist/split/chunks/declarationAliases.js.map +1 -1
  13. package/dist/split/chunks/diagnosticsHooks.js.map +1 -1
  14. package/dist/split/chunks/featureBridge.js +1 -1
  15. package/dist/split/chunks/filterRegistry.js +1 -1
  16. package/dist/split/chunks/filterRegistry.js.map +1 -1
  17. package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
  18. package/dist/split/chunks/lifecycleHooks.js +1 -1
  19. package/dist/split/chunks/lifecycleHooks.js.map +1 -1
  20. package/dist/split/chunks/pathDiagnostics.js +1 -1
  21. package/dist/split/chunks/pathDiagnostics.js.map +1 -1
  22. package/dist/split/chunks/registerComponents.js +1 -1
  23. package/dist/split/chunks/registerComponents.js.map +1 -1
  24. package/dist/split/chunks/setAll.js +1 -1
  25. package/dist/split/chunks/setAll.js.map +1 -1
  26. package/dist/split/chunks/version.js +1 -1
  27. package/dist/split/core.d.ts +77 -1
  28. package/dist/split/core.js +1 -1
  29. package/dist/split/features/devtools.js +1 -1
  30. package/dist/split/features/devtools.js.map +1 -1
  31. package/dist/split/features/diagnostics.js +1 -1
  32. package/dist/split/features/diagnostics.js.map +1 -1
  33. package/dist/split/features/formats.js +1 -1
  34. package/dist/split/features/formats.js.map +1 -1
  35. package/dist/split/features/recursion.js +1 -1
  36. package/dist/split/features/recursion.js.map +1 -1
  37. package/dist/split/features/scopes.js +1 -1
  38. package/dist/split/features/scopes.js.map +1 -1
  39. package/dist/split/features/ssr.js +1 -1
  40. package/dist/split/features/ssr.js.map +1 -1
  41. package/dist/split/features/temporal.js +1 -1
  42. package/dist/split/features/temporal.js.map +1 -1
  43. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"formats.js","sources":["../../../../../src/formats/errorMessages.ts","../../../../../src/filters/filterAliases.ts","../../../../../src/formats/builtinFilters.ts","../../../../../src/formats/install.ts","../../../../../src/features/formats.ts"],"sourcesContent":["/**\n * errorMessages.ts\n *\n * Error message generation utilities used by filter functions.\n *\n * Main responsibilities:\n * - Throws clear error messages when filter options or value type checks fail\n * - Takes function name as argument to specify which filter caused the error\n *\n * Design points:\n * - optionsRequired: Error when required option is not specified\n * - optionMustBeNumber: Error when option value is not a number\n * - valueMustBeNumber: Error when value is not a number\n * - valueMustBeDate: Error when value is not a Date\n * - valueMustBeArray: Error when value is not an array\n */\nimport { raiseError } from \"../raiseError\";\n\n/**\n * Throws error when filter requires at least one option but none provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function optionsRequired(fnName:string): never {\n raiseError(`filter ${fnName} requires at least one option`);\n}\n\n/**\n * Throws error when filter option must be a number but invalid value provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function optionMustBeNumber(fnName:string): never {\n raiseError(`filter ${fnName} requires a number as option`);\n}\n\n/**\n * Throws error when filter requires numeric value but non-number provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeNumber(fnName:string): never {\n raiseError(`filter ${fnName} requires a number value`);\n}\n\n/**\n * Throws error when filter requires Date value but non-Date provided.\n *\n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeDate(fnName:string): never {\n raiseError(`filter ${fnName} requires a date value`);\n}\n\n/**\n * Throws error when filter requires array value but non-array provided.\n *\n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeArray(fnName:string): never {\n raiseError(`filter ${fnName} requires an array value`);\n}","/**\n * filters/filterAliases.ts — 組み込みフィルタの旧名 → 正式名(要件 B12・docs/state-3x-naming.ja.md V1〜V9)。\n *\n * 旧名は 3.x の間エイリアスとして残り、4.0 で外す(D4)。解決は登録簿(core/filterRegistry)が行い、\n * 実装・引数の個数・メタデータは正式名だけが持つ。formats の install と manifest(tooling)の両方が読むので、\n * 実装にもメタデータにも依存しない小さな表として独立させている。\n */\nexport const builtinFilterAliases: Readonly<Record<string, string>> = {\n inc: \"add\",\n dec: \"sub\",\n fix: \"toFixed\",\n uc: \"upper\",\n lc: \"lower\",\n cap: \"capitalize\",\n rep: \"repeat\",\n rev: \"reverse\",\n pad: \"padStart\",\n null: \"nullIfEmpty\",\n};\n","/**\n * builtinFilters.ts\n *\n * Implementation file for built-in filter functions available in Structive.\n *\n * Main responsibilities:\n * - Provides filters for conversion, comparison, formatting, and validation of numbers, strings, dates, booleans, etc.\n * - Defines functions with options for each filter name, enabling flexible use during binding\n * - Designed for common use as both input and output filters\n *\n * Design points:\n * - Comprehensive coverage of diverse filters: eq, ne, lt, gt, inc, abs, clamp, fix, locale, uc, lc, cap, trim, slice, pad, truncate, join, int, float, round, percent, unit, date, time, ymd, hms, falsy, truthy, defaults, boolean, number, string, null, etc.\n * - Rich type checking and error handling for option values\n * - Centralized management of filter functions with FilterWithOptions type, easy to extend\n * - Dynamic retrieval of filter functions from filter names and options via builtinFilterFn\n */\nimport { config } from \"../config.js\";\nimport { didYouMean, LINT_HINT } from \"../errorGuidance.js\";\nimport { raiseError } from \"../raiseError.js\";\nimport { optionMustBeNumber, optionsRequired, valueMustBeArray, valueMustBeDate, valueMustBeNumber } from \"./errorMessages.js\";\nimport { FilterFn, FilterWithOptions, FilterWithOptionsFn } from \"../filters/types\";\nimport { builtinFilterAliases } from \"../filters/filterAliases\";\n\nfunction validateNumberString(value: string): boolean {\n if (!value || isNaN(Number(value))) {\n return false;\n }\n return true;\n}\n\n/**\n * Reads one numeric option **at construction time** and returns the number itself.\n *\n * Every numeric filter used to write out the same three lines (`options?.[i] ?? optionsRequired`,\n * `validateNumberString`, `optionMustBeNumber`) and then call `Number(opt)` again on **every\n * apply**. Folding it here keeps the option checks in one place and takes the conversion off the\n * hot path.\n */\nfunction numberOption(value: string, fnName: string): number {\n if (!validateNumberString(value)) {optionMustBeNumber(fnName);}\n return Number(value);\n}\n\n/** A required numeric option: missing → `optionsRequired`, non-numeric → `optionMustBeNumber`. */\nfunction requiredNumberOption(options: string[] | undefined, index: number, fnName: string): number {\n return numberOption(options?.[index] ?? optionsRequired(fnName), fnName);\n}\n\n/**\n * Extends the display-side empty-value contract (requirement B8) to the formatting filters.\n *\n * A filter that builds its result with `String(value)` turns `undefined` / `null` into the\n * *characters* `\"undefined\"` / `\"null\"`, so `attr.title: x|trim` wrote `title=\"undefined\"` where\n * the unfiltered `attr.title: x` correctly removes the attribute — one filter was enough to undo\n * what B8 established. This family therefore passes an absent value straight through and leaves\n * the decision to the apply side (attribute removed, class cleared, style cleared, text emptied).\n *\n * Deliberately **not** wrapped:\n * - filters for which an absent value *is* the input: `defaults` / `coalesce` / `nullIfEmpty` /\n * `boolean` / `truthy` / `falsy` / `not` / `eq` / `ne`;\n * - the conversions, whose whole job is to convert: `int` / `float` / `number` / `string`;\n * - the filters that reject a value of the wrong type (the number, date and array families).\n * Their throw is confined to the one binding and reported through `$errorCallback`\n * (`apply/applyChangeFromBindings.ts`), which is a different quality of failure from silently\n * painting the word \"undefined\" into the page.\n */\nconst nullishPassthrough = (factory: (options?: string[]) => FilterFn<string>): FilterWithOptionsFn =>\n (options?: string[]): FilterFn => {\n const filterFn = factory(options);\n // `== null` は null と undefined の両方(意図的な緩い比較)\n return (value: unknown): unknown => (value == null ? value : filterFn(value));\n };\n\n/**\n * Equality filter - compares value with option.\n * \n * @param options - Array with comparison value as first element\n * @returns Filter function that returns boolean\n */\nconst eq = (options?:string[], literals?: readonly unknown[]): FilterFn<boolean> => {\n const opt = options?.[0] ?? optionsRequired('eq');\n // The typed literal (B9): unquoted true / false / null / numbers are typed, quoted arguments are strings\n const literal = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): boolean => {\n // Align types for comparison\n if (typeof value === 'number') {\n // A typed literal that is not a string compares as itself (B9). A number is never equal to\n // `true` / `false` / `null`, so `selectedId|eq(null)` is simply false once the id is a\n // number — it used to throw `optionMustBeNumber` on **every apply**, which broke every\n // binding on a path that is sometimes null and sometimes numeric. Only an unquoted\n // non-number (a bare string such as `eq(abc)`) still reports the type mismatch, and it has\n // to stay inside the closure: `eq` accepts values of any type, so `status|eq(active)` is\n // perfectly valid and cannot be rejected at construction the way `lt` / `add` can.\n if (typeof literal !== 'string') {return value === literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('eq');}\n return value === Number(opt);\n }\n if (typeof value === 'string') {\n return value === opt;\n }\n // Booleans, null and the rest compare with the typed literal: eq(true) matches true (B9)\n return value === literal;\n }\n}\n\n/**\n * Inequality filter - compares value with option.\n * \n * @param options - Array with comparison value as first element\n * @returns Filter function that returns boolean\n */\nconst ne = (options?:string[], literals?: readonly unknown[]): FilterFn<boolean> => {\n const opt = options?.[0] ?? optionsRequired('ne');\n const literal = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): boolean => {\n // Align types for comparison\n if (typeof value === 'number') {\n // Same as `eq`: a typed `true` / `false` / `null` compares as itself instead of being\n // forced through `Number()` (B9)\n if (typeof literal !== 'string') {return value !== literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('ne');}\n return value !== Number(opt);\n }\n if (typeof value === 'string') {\n return value !== opt;\n }\n // Booleans, null and the rest compare with the typed literal (B9)\n return value !== literal;\n }\n}\n\n/**\n * Boolean NOT filter - inverts the truthiness of the value.\n *\n * Deliberately the same lenient `!value` as the engine-owned copy in\n * `core/filterRegistry.ts` (`CORE_FILTERS.not`). `if:` / `else:` are built as one\n * `if` parse result plus an engine-injected `not` (`structural/createNotFilter.ts`),\n * and `apply/applyChangeToIf.ts` coerces the `if` side with `Boolean()`. A strict\n * `not` therefore made `else:` throw — and render neither branch — whenever the\n * condition was a falsy non-boolean (`0` / `\"\"` / `undefined` / `null`). Keeping the\n * two implementations identical also means a page behaves the same whether or not\n * `features/formats` is installed (the split core entry registers no `not`).\n *\n * @param options - Unused\n * @returns Filter function that returns the inverted truthiness\n */\nconst not = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => !value;\n}\n\n/**\n * Less than filter - checks if value is less than option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst lt = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'lt');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('lt');}\n return value < opt;\n }\n}\n\n/**\n * Less than or equal filter - checks if value is less than or equal to option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst le = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'le');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('le');}\n return value <= opt;\n }\n}\n\n/**\n * Greater than filter - checks if value is greater than option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst gt = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'gt');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('gt');}\n return value > opt;\n }\n}\n\n/**\n * Greater than or equal filter - checks if value is greater than or equal to option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst ge = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'ge');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('ge');}\n return value >= opt;\n }\n}\n\n/**\n * Increment filter - adds option value to input value.\n * \n * @param options - Array with increment number as first element\n * @returns Filter function that returns incremented number\n */\nconst inc = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'add');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('add');}\n return value + opt;\n }\n}\n\n/**\n * Decrement filter - subtracts option value from input value.\n * \n * @param options - Array with decrement number as first element\n * @returns Filter function that returns decremented number\n */\nconst dec = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'sub');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('sub');}\n return value - opt;\n }\n}\n\n/**\n * Multiply filter - multiplies value by option.\n * \n * @param options - Array with multiplier number as first element\n * @returns Filter function that returns multiplied number\n */\nconst mul = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'mul');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mul');}\n return value * opt;\n }\n}\n\n/**\n * Divide filter - divides value by option.\n * \n * @param options - Array with divisor number as first element\n * @returns Filter function that returns divided number\n */\nconst div = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'div');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('div');}\n return value / opt;\n }\n}\n\n/**\n * Modulo filter - returns remainder of division.\n * \n * @param options - Array with divisor number as first element\n * @returns Filter function that returns remainder\n */\nconst mod = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'mod');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mod');}\n return value % opt;\n }\n}\n\n/**\n * Absolute value filter - returns the magnitude of a number.\n *\n * @param options - Unused\n * @returns Filter function that returns the absolute value\n */\nconst abs = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('abs');}\n return Math.abs(value);\n }\n}\n\n/**\n * Clamp filter - constrains a number to the inclusive range [min, max].\n *\n * Saturating conversion in the same family as round/floor/ceil, so it stays on\n * the wire rather than in state. Pairs with `unit` for style bindings:\n * `style.width: ratio|clamp(0,1)|percent(0)`.\n *\n * @param options - Array with minimum as first element and maximum as second (both required)\n * @returns Filter function that returns the clamped number\n */\nconst clamp = (options?:string[]): FilterFn<number> => {\n const min = requiredNumberOption(options, 0, 'clamp');\n const max = requiredNumberOption(options, 1, 'clamp');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('clamp');}\n return Math.min(Math.max(value, min), max);\n }\n}\n\n/**\n * Fixed decimal filter - formats number to fixed decimal places.\n *\n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns formatted string\n */\nconst fix = (options?:string[]): FilterFn<string> => {\n const opt = numberOption(options?.[0] ?? \"0\", 'toFixed');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('toFixed');}\n return value.toFixed(opt);\n }\n}\n\n/**\n * Locale number filter - formats number according to locale.\n *\n * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は\n * **明示引数だけを構築時に確定し、既定の `config.locale` は適用のたびに読む**。\n *\n * 以前は `options?.[0] ?? config.locale` を返り値の関数の**外**で解決していた。\n * フィルタ関数はバインド構築時に一度だけ作られるので、これはロケールを\n * クロージャに焼き込むことを意味する。`config.locale` の確定がバインド構築より\n * 遅れると、それ以降どう直しても「同じページの中で日付だけ既定ロケール」が\n * 永続し、しかも `config.locale` は依存グラフに載らないので再描画で回復もしない。\n * 症状(日付だけ英語)は原因(起動順序)から遠く、追いにくい。\n *\n * 適用のたびに読めば、少なくとも**再適用されたバインドは回復する**。ロケールは\n * 起動時に確定する前提(docs/i18n-design.md D1)なので通常この差は現れず、\n * これは順序事故から復帰できるようにするための保険である。\n *\n * 明示引数(`|date(ja-JP)`)は構築時に固定でよい — バインド式の一部であり、\n * 実行中に変わらない。\n *\n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns localized number string\n */\nconst locale = (options?:string[]): FilterFn<string> => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('locale');}\n return value.toLocaleString(explicit ?? config.locale);\n }\n}\n\n/**\n * Uppercase filter - converts string to uppercase.\n * \n * @param options - Unused\n * @returns Filter function that returns uppercase string\n */\nconst uc = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).toUpperCase();\n }\n}\n\n/**\n * Lowercase filter - converts string to lowercase.\n * \n * @param options - Unused\n * @returns Filter function that returns lowercase string\n */\nconst lc = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).toLowerCase();\n }\n}\n\n/**\n * Capitalize filter - capitalizes first character of string.\n * \n * @param options - Unused\n * @returns Filter function that returns capitalized string\n */\nconst cap = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n const v = String(value);\n if (v.length === 0) {return v;}\n if (v.length === 1) {return v.toUpperCase();}\n return v.charAt(0).toUpperCase() + v.slice(1);\n }\n}\n\n/**\n * Trim filter - removes whitespace from both ends of string.\n * \n * @param options - Unused\n * @returns Filter function that returns trimmed string\n */\nconst trim = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).trim();\n }\n}\n\n/**\n * Slice filter - extracts portion of string from specified index.\n * \n * @param options - Array with start index and optional end index\n * @returns Filter function that returns sliced string\n */\nconst slice = (options?:string[]): FilterFn<string> => {\n const numberedOpts: number[] = [requiredNumberOption(options, 0, 'slice')];\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n numberedOpts.push(numberOption(opt2, 'slice'));\n }\n return (value: unknown): string => {\n return String(value).slice(...numberedOpts);\n }\n}\n\n/**\n * Substring filter - extracts substring from specified position and length.\n * \n * @param options - Array with start index and length\n * @returns Filter function that returns substring\n */\nconst substr = (options?:string[]): FilterFn<string> => {\n const opt1 = requiredNumberOption(options, 0, 'substr');\n const opt2 = requiredNumberOption(options, 1, 'substr');\n return (value: unknown): string => {\n return String(value).substr(opt1, opt2);\n }\n}\n\n/**\n * Pad filter - pads string to specified length from start.\n * \n * @param options - Array with target length and pad string (default: '0')\n * @returns Filter function that returns padded string\n */\nconst pad = (options?:string[]): FilterFn<string> => {\n const opt1 = requiredNumberOption(options, 0, 'padStart');\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => {\n return String(value).padStart(opt1, opt2);\n }\n}\n\n/**\n * padEnd filter - pads string to specified length from the end (the pair of `padStart`, requirement B12).\n *\n * @param options - Array with target length and pad string (default: ' ')\n * @returns Filter function that returns padded string\n */\nconst padEnd = (options?:string[]): FilterFn<string> => {\n const opt1 = requiredNumberOption(options, 0, 'padEnd');\n const opt2 = options?.[1] ?? ' ';\n return (value: unknown): string => {\n return String(value).padEnd(opt1, opt2);\n }\n}\n\n/**\n * Repeat filter - repeats string specified number of times.\n * \n * @param options - Array with repeat count as first element\n * @returns Filter function that returns repeated string\n */\nconst rep = (options?:string[]): FilterFn<string> => {\n const opt = requiredNumberOption(options, 0, 'repeat');\n return (value: unknown): string => {\n return String(value).repeat(opt);\n }\n}\n\n/**\n * Reverse filter - reverses character order in string.\n * \n * @param options - Unused\n * @returns Filter function that returns reversed string\n */\nconst rev = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).split('').reverse().join('');\n }\n}\n\n/**\n * Integer filter - parses value to integer.\n * \n * @param options - Unused\n * @returns Filter function that returns integer\n */\nconst int = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return parseInt(String(value), 10);\n }\n}\n\n/**\n * Float filter - parses value to floating point number.\n * \n * @param options - Unused\n * @returns Filter function that returns float\n */\nconst float = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return parseFloat(String(value));\n }\n}\n\n/**\n * Round filter - rounds number to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns rounded number\n */\nconst round = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'round'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round');}\n return Math.round(value * optValue) / optValue;\n }\n}\n\n/**\n * Floor filter - rounds number down to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns floored number\n */\nconst floor = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'floor'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor');}\n return Math.floor(value * optValue) / optValue;\n }\n}\n\n/**\n * Ceiling filter - rounds number up to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns ceiled number\n */\nconst ceil = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'ceil'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil');}\n return Math.ceil(value * optValue) / optValue;\n }\n}\n\n/**\n * Percent filter - formats number as percentage string.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns percentage string with '%'\n */\nconst percent = (options?:string[]): FilterFn<string> => {\n const opt = numberOption(options?.[0] ?? '0', 'percent');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent');}\n return `${(value * 100).toFixed(opt)}%`;\n }\n}\n\n/**\n * Unit filter - appends a CSS unit (or any suffix) to the value.\n *\n * A number alone does nothing in CSS, so without this the unit has to be built in\n * state — which drags presentation into the source of truth, and in the worst case\n * forces a whole derived array just to carry `\"42%\"` strings.\n * `style.height: samples.*.cpu|clamp(0,100)|fix(0)|unit(%)` keeps it on the wire.\n *\n * Accepts strings as well as numbers **on purpose**: the useful chains run through\n * `fix` / `percent`, which already return strings. Rejecting non-numbers here would\n * break exactly the combination this filter exists for.\n *\n * `null` / `undefined` pass through untouched rather than becoming `\"undefinedpx\"`, so the\n * binding layer's \"undefined skips the write, null clears\" semantics survive. That guard is no\n * longer written here: it is `nullishPassthrough`, shared with the rest of the `String(value)`\n * family, which used to paint `\"undefined\"` into the page for exactly the same reason.\n *\n * @param options - Array with the unit/suffix as first element (required)\n * @returns Filter function that returns the value with the unit appended\n */\nconst unit = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): string => {\n return String(value) + opt;\n }\n}\n\n/**\n * Join filter - joins array elements into a string.\n *\n * The default separator is `\", \"` rather than `\",\"`: a bare comma is what `String()`\n * already produces without any filter, so defaulting to it would make `|join` a no-op.\n *\n * @param options - Array with separator as first element (default: ', ')\n * @returns Filter function that returns the joined string\n */\nconst join = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? ', ';\n return (value: unknown): string => {\n if (!Array.isArray(value)) {valueMustBeArray('join');}\n return value.join(opt);\n }\n}\n\n/**\n * Truncate filter - shortens a string and appends an ellipsis.\n *\n * The length option counts **kept characters**, not the total including the suffix,\n * matching the existing `slice(0, n)` reading. A string at or below the limit is\n * returned untouched (no suffix).\n *\n * @param options - Array with max kept length as first element and suffix as second (default: '…')\n * @returns Filter function that returns the truncated string\n */\nconst truncate = (options?:string[]): FilterFn<string> => {\n const maxLength = requiredNumberOption(options, 0, 'truncate');\n const suffix = options?.[1] ?? '…';\n return (value: unknown): string => {\n const v = String(value);\n if (v.length <= maxLength) {return v;}\n return v.slice(0, maxLength) + suffix;\n }\n}\n\n/**\n * Date filter - formats Date object as localized date string.\n *\n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns date string\n */\nconst date = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('date');}\n return value.toLocaleDateString(explicit ?? config.locale);\n }\n}\n\n/**\n * Time filter - formats Date object as localized time string.\n * \n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns time string\n */\nconst time = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('time');}\n return value.toLocaleTimeString(explicit ?? config.locale);\n }\n}\n\n/**\n * DateTime filter - formats Date object as localized date and time string.\n * \n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns datetime string\n */\nconst datetime = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('datetime');}\n return value.toLocaleString(explicit ?? config.locale);\n }\n}\n\n/**\n * Year-Month-Day filter - formats Date object as YYYY-MM-DD string.\n * \n * @param options - Array with separator string as first element (default: '-')\n * @returns Filter function that returns formatted date string\n */\nconst ymd = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? '-';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('ymd');}\n const year = value.getFullYear().toString();\n const month = (value.getMonth() + 1).toString().padStart(2, '0');\n const day = value.getDate().toString().padStart(2, '0');\n return `${year}${opt}${month}${opt}${day}`;\n }\n}\n\n/**\n * Hour-Minute-Second filter - formats Date object as HH:MM:SS string.\n *\n * The counterpart of `ymd`: a fixed, zero-padded, locale-independent rendering with a\n * configurable separator, for when `time` (locale-formatted) is not stable enough.\n *\n * @param options - Array with separator string as first element (default: ':')\n * @returns Filter function that returns formatted time string\n */\nconst hms = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? ':';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('hms');}\n const hours = value.getHours().toString().padStart(2, '0');\n const minutes = value.getMinutes().toString().padStart(2, '0');\n const seconds = value.getSeconds().toString().padStart(2, '0');\n return `${hours}${opt}${minutes}${opt}${seconds}`;\n }\n}\n\n/**\n * Falsy filter - checks if value is falsy, by JavaScript's own truthiness (`!value`: false, null,\n * undefined, 0, -0, 0n, '' and NaN). Before 3.0 the list was spelled out and missed 0n (B10).\n *\n * @param options - Unused\n * @returns Filter function that returns true for falsy values\n */\nconst falsy = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => !value;\n}\n\n/**\n * Truthy filter - checks if value is truthy.\n * \n * @param options - Unused\n * @returns Filter function that returns true for non-falsy values\n */\nconst truthy = (_options?:string[]): FilterFn<boolean> => {\n // JavaScript's truthiness, the same as the `boolean` filter (B10)\n return (value: unknown): boolean => !!value;\n}\n\n/**\n * Default filter - returns default value if input is falsy (JavaScript's truthiness, as `falsy`).\n * \n * @param options - Array with default value as first element\n * @returns Filter function that returns value or default\n */\nconst defaults = (options?:string[], literals?: readonly unknown[]): FilterFn<unknown> => {\n const opt = options?.[0] ?? optionsRequired('defaults');\n // The fallback is the typed literal (B9): defaults(0) gives 0, defaults(null) gives null, defaults('0') gives \"0\"\n const fallback = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): unknown => {\n if (!value) {return fallback;}\n return value;\n }\n}\n\n/**\n * coalesce filter - returns the default only for null / undefined (`defaults` also replaces 0, false and \"\").\n * Requirement B12: the nullish counterpart of `defaults`, read like SQL COALESCE.\n *\n * @param options - Array with default value as first element\n * @returns Filter function that returns value or default\n */\nconst coalesce = (options?:string[], literals?: readonly unknown[]): FilterFn<unknown> => {\n const opt = options?.[0] ?? optionsRequired('coalesce');\n const fallback = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): unknown => value ?? fallback;\n}\n\n/**\n * Boolean filter - converts value to boolean.\n * \n * @param options - Unused\n * @returns Filter function that returns boolean\n */\nconst boolean = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => {\n return Boolean(value);\n }\n}\n\n/**\n * Number filter - converts value to number.\n * \n * @param options - Unused\n * @returns Filter function that returns number\n */\nconst number = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return Number(value);\n }\n}\n\n/**\n * String filter - converts value to string.\n * \n * @param options - Unused\n * @returns Filter function that returns string\n */\nconst string = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value);\n }\n}\n\n/**\n * Null filter - converts empty string to null.\n * \n * @param options - Unused\n * @returns Filter function that returns null for empty string, otherwise original value\n */\nconst _null = (_options?:string[]): FilterFn<unknown> => {\n return (value: unknown): unknown => {\n return (value === \"\") ? null : value;\n } \n}\n\nconst builtinFilters: FilterWithOptions = {\n \"eq\": eq,\n \"ne\": ne,\n \"not\": not,\n\n \"lt\": lt,\n \"le\": le,\n \"gt\": gt,\n \"ge\": ge,\n\n \"add\": inc,\n \"sub\": dec,\n \"mul\": mul,\n \"div\": div,\n \"mod\": mod,\n \"abs\": abs,\n \"clamp\": clamp,\n\n \"toFixed\": fix,\n \"locale\": locale,\n // `String(value)` で組み立てる族は、値が無いときに素通しする(要件 B8 — nullishPassthrough を参照)\n \"upper\": nullishPassthrough(uc),\n \"lower\": nullishPassthrough(lc),\n \"capitalize\": nullishPassthrough(cap),\n \"trim\": nullishPassthrough(trim),\n \"slice\": nullishPassthrough(slice),\n \"substr\": nullishPassthrough(substr),\n \"padStart\": nullishPassthrough(pad),\n \"padEnd\": nullishPassthrough(padEnd),\n \"repeat\": nullishPassthrough(rep),\n \"reverse\": nullishPassthrough(rev),\n \"truncate\": nullishPassthrough(truncate),\n \"join\": join,\n\n \"int\": int,\n \"float\": float,\n \"round\": round,\n \"floor\": floor,\n \"ceil\": ceil,\n \"percent\": percent,\n \"unit\": nullishPassthrough(unit),\n\n \"date\": date,\n \"time\": time,\n \"datetime\": datetime,\n \"ymd\": ymd,\n \"hms\": hms,\n\n \"falsy\": falsy,\n \"truthy\": truthy,\n \"defaults\": defaults,\n \"coalesce\": coalesce,\n\n \"boolean\": boolean,\n \"number\": number,\n \"string\": string,\n \"nullIfEmpty\": _null,\n};\n\n/**\n * The argument count each built-in accepts, [min, max] — checked when the bindings are planned\n * (`[wcs/filter-arity]`, requirement B3), with the same bounds lint uses. It is the same data as\n * `builtinFilterMeta` (filters/filterMeta.ts) without the descriptions, so that installing the formats\n * does not pull the metadata into the page; a test keeps the two equal.\n */\nexport const builtinFilterArity: Readonly<Record<string, readonly [number, number]>> = {\n eq: [1, 1],\n not: [0, 0],\n ne: [1, 1],\n lt: [1, 1],\n le: [1, 1],\n gt: [1, 1],\n ge: [1, 1],\n add: [1, 1],\n sub: [1, 1],\n mul: [1, 1],\n div: [1, 1],\n mod: [1, 1],\n abs: [0, 0],\n clamp: [2, 2],\n toFixed: [0, 1],\n locale: [0, 1],\n upper: [0, 0],\n lower: [0, 0],\n capitalize: [0, 0],\n trim: [0, 0],\n slice: [1, 2],\n // `substr` は長さも必須(実装が両方読む・README も `substr(start, length)`)。\n // [1, 2] だったころは `substr(0)` が引数の個数の検査を素通りし、工場の\n // 「requires at least one option」という的外れな文言で落ちていた\n substr: [2, 2],\n padStart: [1, 2],\n padEnd: [1, 2],\n repeat: [1, 1],\n reverse: [0, 0],\n truncate: [1, 2],\n join: [0, 1],\n int: [0, 0],\n float: [0, 0],\n round: [0, 1],\n floor: [0, 1],\n ceil: [0, 1],\n percent: [0, 1],\n unit: [1, 1],\n // ロケール依存の 3 つは `locale` と同じく引数 1 つ(`date(ja-JP)`)を受ける。\n // [0, 0] だったころは、README が規範として書いている `timestamp|date(ja-JP)` が\n // 束縛計画の段で必ず `[wcs/filter-arity]` になっていた(2.x には検査自体が無かった)\n date: [0, 1],\n time: [0, 1],\n datetime: [0, 1],\n ymd: [0, 1],\n hms: [0, 1],\n falsy: [0, 0],\n truthy: [0, 0],\n defaults: [1, 1],\n coalesce: [1, 1],\n boolean: [0, 0],\n number: [0, 0],\n string: [0, 0],\n nullIfEmpty: [0, 0],\n};\n\nexport const outputBuiltinFilters = builtinFilters;\nexport const inputBuiltinFilters = builtinFilters;\n\nexport const builtinFiltersByFilterIOType = {\n \"input\": inputBuiltinFilters,\n \"output\": outputBuiltinFilters,\n} as const;\n\n/**\n * Retrieves built-in filter function by name and options.\n *\n * **Test / tooling only.** The binding pipeline never goes through here: it resolves\n * filters from the registry with `core/filterRegistry.ts#resolveFilterFn`, which also\n * checks `builtinFilterArity` and passes the **typed literals** (requirement B9).\n * This helper takes raw option strings only, so `builtinFilterFn(\"coalesce\", [\"0\"])`\n * yields the string `\"0\"` where the runtime yields the number `0`. Prefer\n * `resolveFilterFn` in any new code, and treat a difference between the two as a\n * limitation of this helper rather than of the runtime.\n *\n * @param name - Filter name (a 3.x alias such as `uc` resolves to its canonical name)\n * @param options - Array of option strings\n * @returns Function that takes FilterWithOptions and returns filter function\n */\nexport const builtinFilterFn = (name:string, options: string[]) => (filters: FilterWithOptions) => {\n // 自前のキーだけを引く。素のオブジェクトへのブラケット参照だと `Object.prototype` のメンバが\n // フィルタとして通り(`toString` / `constructor` / `valueOf`)、`[wcs/filter-unknown]` の代わりに\n // `\"[object Undefined]\"` や素の TypeError が出ていた。登録簿(core/filterRegistry.ts)が\n // まさにこの穴のために `Map` を採っているのと同じ規準\n const own = Object.prototype.hasOwnProperty;\n const canonical = own.call(builtinFilterAliases, name) ? builtinFilterAliases[name] : name;\n const filter = own.call(filters, canonical) ? filters[canonical] : undefined;\n if (!filter) {\n // lint の wcs/filter-unknown と同じ語彙・同じ did-you-mean 規準(三面同語彙)。\n raiseError(`[wcs/filter-unknown] filter not found: ${name}.${didYouMean(name, Object.keys(filters))}${LINT_HINT}`);\n }\n return filter(options);\n}\n\n","/**\n * formats/install.ts — 書式フィルタ群の install(設計案 §4、要件 D16)。\n *\n * `uc` / `date` / `round` / `truncate` … の実装を core の登録簿へ置く。core 自身が持つのは\n * エンジンが差し込む `not` だけなので、この機能を入れないページでは、宣言されたフィルタが\n * 束縛計画の段で `[wcs/filter-unknown]` として名指しで落ちる(黙って素通ししない)。\n */\nimport { registerFilters } from \"../core/filterRegistry\";\nimport { builtinFilterArity, inputBuiltinFilters, outputBuiltinFilters } from \"./builtinFilters\";\nimport { builtinFilterAliases } from \"../filters/filterAliases\";\n\nlet installed = false;\n/** 冪等。full / auto では `bootstrapState()` が呼ぶ */\nexport function installFormats(): void {\n if (installed) return;\n installed = true;\n registerFilters(\"input\", inputBuiltinFilters, builtinFilterArity, builtinFilterAliases);\n registerFilters(\"output\", outputBuiltinFilters, builtinFilterArity, builtinFilterAliases);\n}\n","/**\n * features/formats.ts — 書式フィルタ群(@wcstack/state/features/formats)。\n * `|uc` `|date(…)` `|round(…)` のような宣言が要求する実関数を core の登録簿へ置く。\n */\nimport type { IStateFeature } from \"../core/features\";\nimport { installFormats } from \"../formats/install\";\n\nexport const formats: IStateFeature = {\n name: \"formats\",\n install(): void {\n installFormats();\n },\n};\nexport default formats;\n"],"names":["optionsRequired","fnName","raiseError","optionMustBeNumber","valueMustBeNumber","valueMustBeDate","builtinFilterAliases","inc","dec","fix","uc","lc","cap","rep","rev","pad","null","validateNumberString","value","isNaN","Number","numberOption","requiredNumberOption","options","index","nullishPassthrough","factory","filterFn","builtinFilters","eq","literals","opt","literal","undefined","length","ne","not","_options","lt","le","gt","ge","add","sub","mul","div","mod","abs","Math","clamp","min","max","toFixed","locale","explicit","toLocaleString","config","upper","String","toUpperCase","lower","toLowerCase","capitalize","v","charAt","slice","trim","numberedOpts","opt2","push","substr","opt1","padStart","padEnd","repeat","reverse","split","join","truncate","maxLength","suffix","Array","isArray","int","parseInt","float","parseFloat","round","optValue","pow","floor","ceil","percent","unit","date","Date","toLocaleDateString","time","toLocaleTimeString","datetime","ymd","year","getFullYear","toString","month","getMonth","day","getDate","hms","hours","getHours","minutes","getMinutes","seconds","getSeconds","falsy","truthy","defaults","fallback","coalesce","boolean","Boolean","number","string","nullIfEmpty","builtinFilterArity","outputBuiltinFilters","inputBuiltinFilters","installed","formats","name","install","registerFilters"],"mappings":"iGAwBM,SAAUA,EAAgBC,GAC9BC,EAAW,UAAUD,iCACvB,CAQM,SAAUE,EAAmBF,GACjCC,EAAW,UAAUD,gCACvB,CAQM,SAAUG,EAAkBH,GAChCC,EAAW,UAAUD,4BACvB,CAQM,SAAUI,EAAgBJ,GAC9BC,EAAW,UAAUD,0BACvB,CCjDO,MAAMK,EAAyD,CACpEC,IAAK,MACLC,IAAK,MACLC,IAAK,UACLC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AAC,EAAG,GACdC,OAAQ,CAAC,EAAG,GACZC,OAAQ,CAAC,EAAG,GACZC,QAAS,CAAC,EAAG,GACbG,SAAU,CAAC,EAAG,GACdD,KAAM,CAAC,EAAG,GACVM,IAAK,CAAC,EAAG,GACTE,MAAO,CAAC,EAAG,GACXE,MAAO,CAAC,EAAG,GACXG,MAAO,CAAC,EAAG,GACXC,KAAM,CAAC,EAAG,GACVC,QAAS,CAAC,EAAG,GACbC,KAAM,CAAC,EAAG,GAIVC,KAAM,CAAC,EAAG,GACVG,KAAM,CAAC,EAAG,GACVE,SAAU,CAAC,EAAG,GACdC,IAAK,CAAC,EAAG,GACTQ,IAAK,CAAC,EAAG,GACTO,MAAO,CAAC,EAAG,GACXC,OAAQ,CAAC,EAAG,GACZC,SAAU,CAAC,EAAG,GACdE,SAAU,CAAC,EAAG,GACdC,QAAS,CAAC,EAAG,GACbE,OAAQ,CAAC,EAAG,GACZC,OAAQ,CAAC,EAAG,GACZC,YAAa,CAAC,EAAG,IAGNE,EAAuBlG,EACvBmG,EAAsBnG,EC75BnC,IAAIoG,GAAY,ECJT,MAAMC,EAAyB,CACpCC,KAAM,UACN,OAAAC,GDKIH,IACJA,GAAY,EACZI,EAAgB,QAASL,EAAqBF,EAAoBvH,GAClE8H,EAAgB,SAAUN,EAAsBD,EAAoBvH,GCNpE"}
1
+ {"version":3,"file":"formats.js","sources":["../../../../../src/formats/errorMessages.ts","../../../../../src/filters/filterAliases.ts","../../../../../src/formats/builtinFilters.ts","../../../../../src/formats/install.ts","../../../../../src/features/formats.ts"],"sourcesContent":["/**\n * errorMessages.ts\n *\n * Error message generation utilities used by filter functions.\n *\n * Main responsibilities:\n * - Throws clear error messages when filter options or value type checks fail\n * - Takes function name as argument to specify which filter caused the error\n *\n * Design points:\n * - optionsRequired: Error when required option is not specified\n * - optionMustBeNumber: Error when option value is not a number\n * - valueMustBeNumber: Error when value is not a number\n * - valueMustBeDate: Error when value is not a Date\n * - valueMustBeArray: Error when value is not an array\n */\nimport { raiseError } from \"../raiseError\";\n\n/**\n * Throws error when filter requires at least one option but none provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function optionsRequired(fnName:string): never {\n raiseError(`filter ${fnName} requires at least one option`);\n}\n\n/**\n * Throws error when filter option must be a number but invalid value provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function optionMustBeNumber(fnName:string): never {\n raiseError(`filter ${fnName} requires a number as option`);\n}\n\n/**\n * Throws error when filter requires numeric value but non-number provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeNumber(fnName:string): never {\n raiseError(`filter ${fnName} requires a number value`);\n}\n\n/**\n * Throws error when filter requires Date value but non-Date provided.\n *\n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeDate(fnName:string): never {\n raiseError(`filter ${fnName} requires a date value`);\n}\n\n/**\n * Throws error when filter requires array value but non-array provided.\n *\n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeArray(fnName:string): never {\n raiseError(`filter ${fnName} requires an array value`);\n}","/**\n * filters/filterAliases.ts — 組み込みフィルタの旧名 → 正式名(要件 B12・docs/state-3x-naming.ja.md V1〜V9)。\n *\n * 旧名は 3.x の間エイリアスとして残り、4.0 で外す(D4)。解決は登録簿(core/filterRegistry)が行い、\n * 実装・引数の個数・メタデータは正式名だけが持つ。formats の install と manifest(tooling)の両方が読むので、\n * 実装にもメタデータにも依存しない小さな表として独立させている。\n */\nexport const builtinFilterAliases: Readonly<Record<string, string>> = {\n inc: \"add\",\n dec: \"sub\",\n fix: \"toFixed\",\n uc: \"upper\",\n lc: \"lower\",\n cap: \"capitalize\",\n rep: \"repeat\",\n rev: \"reverse\",\n pad: \"padStart\",\n null: \"nullIfEmpty\",\n};\n","/**\n * builtinFilters.ts\n *\n * Implementation file for built-in filter functions available in Structive.\n *\n * Main responsibilities:\n * - Provides filters for conversion, comparison, formatting, and validation of numbers, strings, dates, booleans, etc.\n * - Defines functions with options for each filter name, enabling flexible use during binding\n * - Designed for common use as both input and output filters\n *\n * Design points:\n * - Comprehensive coverage of diverse filters: eq, ne, lt, gt, inc, abs, clamp, fix, locale, uc, lc, cap, trim, slice, pad, truncate, join, int, float, round, percent, unit, date, time, ymd, hms, falsy, truthy, defaults, boolean, number, string, null, etc.\n * - Rich type checking and error handling for option values\n * - Centralized management of filter functions with FilterWithOptions type, easy to extend\n * - Dynamic retrieval of filter functions from filter names and options via builtinFilterFn\n */\nimport { config } from \"../config.js\";\nimport { didYouMean, LINT_HINT } from \"../errorGuidance.js\";\nimport { raiseError } from \"../raiseError.js\";\nimport { optionMustBeNumber, optionsRequired, valueMustBeArray, valueMustBeDate, valueMustBeNumber } from \"./errorMessages.js\";\nimport { FilterFn, FilterWithOptions, FilterWithOptionsFn } from \"../filters/types\";\nimport { builtinFilterAliases } from \"../filters/filterAliases\";\nimport { v4Migration } from \"../core/v4MigrationHooks\";\n\nfunction validateNumberString(value: string): boolean {\n if (!value || isNaN(Number(value))) {\n return false;\n }\n return true;\n}\n\n/**\n * Reads one numeric option **at construction time** and returns the number itself.\n *\n * Every numeric filter used to write out the same three lines (`options?.[i] ?? optionsRequired`,\n * `validateNumberString`, `optionMustBeNumber`) and then call `Number(opt)` again on **every\n * apply**. Folding it here keeps the option checks in one place and takes the conversion off the\n * hot path.\n */\nfunction numberOption(value: string, fnName: string): number {\n if (!validateNumberString(value)) {optionMustBeNumber(fnName);}\n return Number(value);\n}\n\n/** A required numeric option: missing → `optionsRequired`, non-numeric → `optionMustBeNumber`. */\nfunction requiredNumberOption(options: string[] | undefined, index: number, fnName: string): number {\n return numberOption(options?.[index] ?? optionsRequired(fnName), fnName);\n}\n\n/**\n * Extends the display-side empty-value contract (requirement B8) to the formatting filters.\n *\n * A filter that builds its result with `String(value)` turns `undefined` / `null` into the\n * *characters* `\"undefined\"` / `\"null\"`, so `attr.title: x|trim` wrote `title=\"undefined\"` where\n * the unfiltered `attr.title: x` correctly removes the attribute — one filter was enough to undo\n * what B8 established. This family therefore passes an absent value straight through and leaves\n * the decision to the apply side (attribute removed, class cleared, style cleared, text emptied).\n *\n * Deliberately **not** wrapped:\n * - filters for which an absent value *is* the input: `defaults` / `coalesce` / `nullIfEmpty` /\n * `boolean` / `truthy` / `falsy` / `not` / `eq` / `ne`;\n * - the conversions, whose whole job is to convert: `int` / `float` / `number` / `string`;\n * - the filters that reject a value of the wrong type (the number, date and array families).\n * Their throw is confined to the one binding and reported through `$errorCallback`\n * (`apply/applyChangeFromBindings.ts`), which is a different quality of failure from silently\n * painting the word \"undefined\" into the page.\n */\nconst nullishPassthrough = (factory: (options?: string[]) => FilterFn<string>): FilterWithOptionsFn =>\n (options?: string[]): FilterFn => {\n const filterFn = factory(options);\n // `== null` は null と undefined の両方(意図的な緩い比較)\n return (value: unknown): unknown => (value == null ? value : filterFn(value));\n };\n\n/**\n * Equality filter - compares value with option.\n * \n * @param options - Array with comparison value as first element\n * @returns Filter function that returns boolean\n */\nconst eq = (options?:string[], literals?: readonly unknown[]): FilterFn<boolean> => {\n const opt = options?.[0] ?? optionsRequired('eq');\n // The typed literal (B9): unquoted true / false / null / numbers are typed, quoted arguments are strings\n const literal = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): boolean => {\n // Align types for comparison\n if (typeof value === 'number') {\n // A typed literal that is not a string compares as itself (B9). A number is never equal to\n // `true` / `false` / `null`, so `selectedId|eq(null)` is simply false once the id is a\n // number — it used to throw `optionMustBeNumber` on **every apply**, which broke every\n // binding on a path that is sometimes null and sometimes numeric. Only an unquoted\n // non-number (a bare string such as `eq(abc)`) still reports the type mismatch, and it has\n // to stay inside the closure: `eq` accepts values of any type, so `status|eq(active)` is\n // perfectly valid and cannot be rejected at construction the way `lt` / `add` can.\n if (typeof literal !== 'string') {return value === literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('eq');}\n return value === Number(opt);\n }\n if (typeof value === 'string') {\n return value === opt;\n }\n // Booleans, null and the rest compare with the typed literal: eq(true) matches true (B9)\n return value === literal;\n }\n}\n\n/**\n * Inequality filter - compares value with option.\n * \n * @param options - Array with comparison value as first element\n * @returns Filter function that returns boolean\n */\nconst ne = (options?:string[], literals?: readonly unknown[]): FilterFn<boolean> => {\n const opt = options?.[0] ?? optionsRequired('ne');\n const literal = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): boolean => {\n // Align types for comparison\n if (typeof value === 'number') {\n // Same as `eq`: a typed `true` / `false` / `null` compares as itself instead of being\n // forced through `Number()` (B9)\n if (typeof literal !== 'string') {return value !== literal;}\n if (!validateNumberString(opt)) {optionMustBeNumber('ne');}\n return value !== Number(opt);\n }\n if (typeof value === 'string') {\n return value !== opt;\n }\n // Booleans, null and the rest compare with the typed literal (B9)\n return value !== literal;\n }\n}\n\n/**\n * Boolean NOT filter - inverts the truthiness of the value.\n *\n * Deliberately the same lenient `!value` as the engine-owned copy in\n * `core/filterRegistry.ts` (`CORE_FILTERS.not`). `if:` / `else:` are built as one\n * `if` parse result plus an engine-injected `not` (`structural/createNotFilter.ts`),\n * and `apply/applyChangeToIf.ts` coerces the `if` side with `Boolean()`. A strict\n * `not` therefore made `else:` throw — and render neither branch — whenever the\n * condition was a falsy non-boolean (`0` / `\"\"` / `undefined` / `null`). Keeping the\n * two implementations identical also means a page behaves the same whether or not\n * `features/formats` is installed (the split core entry registers no `not`).\n *\n * @param options - Unused\n * @returns Filter function that returns the inverted truthiness\n */\nconst not = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => !value;\n}\n\n/**\n * Less than filter - checks if value is less than option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst lt = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'lt');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('lt');}\n return value < opt;\n }\n}\n\n/**\n * Less than or equal filter - checks if value is less than or equal to option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst le = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'le');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('le');}\n return value <= opt;\n }\n}\n\n/**\n * Greater than filter - checks if value is greater than option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst gt = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'gt');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('gt');}\n return value > opt;\n }\n}\n\n/**\n * Greater than or equal filter - checks if value is greater than or equal to option.\n * \n * @param options - Array with comparison number as first element\n * @returns Filter function that returns boolean\n */\nconst ge = (options?:string[]): FilterFn<boolean> => {\n const opt = requiredNumberOption(options, 0, 'ge');\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('ge');}\n return value >= opt;\n }\n}\n\n/**\n * Increment filter - adds option value to input value.\n * \n * @param options - Array with increment number as first element\n * @returns Filter function that returns incremented number\n */\nconst inc = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'add');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('add');}\n return value + opt;\n }\n}\n\n/**\n * Decrement filter - subtracts option value from input value.\n * \n * @param options - Array with decrement number as first element\n * @returns Filter function that returns decremented number\n */\nconst dec = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'sub');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('sub');}\n return value - opt;\n }\n}\n\n/**\n * Multiply filter - multiplies value by option.\n * \n * @param options - Array with multiplier number as first element\n * @returns Filter function that returns multiplied number\n */\nconst mul = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'mul');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mul');}\n return value * opt;\n }\n}\n\n/**\n * Divide filter - divides value by option.\n * \n * @param options - Array with divisor number as first element\n * @returns Filter function that returns divided number\n */\nconst div = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'div');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('div');}\n return value / opt;\n }\n}\n\n/**\n * Modulo filter - returns remainder of division.\n * \n * @param options - Array with divisor number as first element\n * @returns Filter function that returns remainder\n */\nconst mod = (options?:string[]): FilterFn<number> => {\n const opt = requiredNumberOption(options, 0, 'mod');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mod');}\n return value % opt;\n }\n}\n\n/**\n * Absolute value filter - returns the magnitude of a number.\n *\n * @param options - Unused\n * @returns Filter function that returns the absolute value\n */\nconst abs = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('abs');}\n return Math.abs(value);\n }\n}\n\n/**\n * Clamp filter - constrains a number to the inclusive range [min, max].\n *\n * Saturating conversion in the same family as round/floor/ceil, so it stays on\n * the wire rather than in state. Pairs with `unit` for style bindings:\n * `style.width: ratio|clamp(0,1)|percent(0)`.\n *\n * @param options - Array with minimum as first element and maximum as second (both required)\n * @returns Filter function that returns the clamped number\n */\nconst clamp = (options?:string[]): FilterFn<number> => {\n const min = requiredNumberOption(options, 0, 'clamp');\n const max = requiredNumberOption(options, 1, 'clamp');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('clamp');}\n return Math.min(Math.max(value, min), max);\n }\n}\n\n/**\n * Fixed decimal filter - formats number to fixed decimal places.\n *\n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns formatted string\n */\nconst fix = (options?:string[]): FilterFn<string> => {\n const opt = numberOption(options?.[0] ?? \"0\", 'toFixed');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('toFixed');}\n return value.toFixed(opt);\n }\n}\n\n/**\n * Locale number filter - formats number according to locale.\n *\n * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は\n * **明示引数だけを構築時に確定し、既定の `config.locale` は適用のたびに読む**。\n *\n * 以前は `options?.[0] ?? config.locale` を返り値の関数の**外**で解決していた。\n * フィルタ関数はバインド構築時に一度だけ作られるので、これはロケールを\n * クロージャに焼き込むことを意味する。`config.locale` の確定がバインド構築より\n * 遅れると、それ以降どう直しても「同じページの中で日付だけ既定ロケール」が\n * 永続し、しかも `config.locale` は依存グラフに載らないので再描画で回復もしない。\n * 症状(日付だけ英語)は原因(起動順序)から遠く、追いにくい。\n *\n * 適用のたびに読めば、少なくとも**再適用されたバインドは回復する**。ロケールは\n * 起動時に確定する前提(docs/i18n-design.md D1)なので通常この差は現れず、\n * これは順序事故から復帰できるようにするための保険である。\n *\n * 明示引数(`|date(ja-JP)`)は構築時に固定でよい — バインド式の一部であり、\n * 実行中に変わらない。\n *\n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns localized number string\n */\nconst locale = (options?:string[]): FilterFn<string> => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('locale');}\n return value.toLocaleString(explicit ?? config.locale);\n }\n}\n\n/**\n * Uppercase filter - converts string to uppercase.\n * \n * @param options - Unused\n * @returns Filter function that returns uppercase string\n */\nconst uc = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).toUpperCase();\n }\n}\n\n/**\n * Lowercase filter - converts string to lowercase.\n * \n * @param options - Unused\n * @returns Filter function that returns lowercase string\n */\nconst lc = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).toLowerCase();\n }\n}\n\n/**\n * Capitalize filter - capitalizes first character of string.\n * \n * @param options - Unused\n * @returns Filter function that returns capitalized string\n */\nconst cap = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n const v = String(value);\n if (v.length === 0) {return v;}\n if (v.length === 1) {return v.toUpperCase();}\n return v.charAt(0).toUpperCase() + v.slice(1);\n }\n}\n\n/**\n * Trim filter - removes whitespace from both ends of string.\n * \n * @param options - Unused\n * @returns Filter function that returns trimmed string\n */\nconst trim = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).trim();\n }\n}\n\n/**\n * Slice filter - extracts portion of string from specified index.\n * \n * @param options - Array with start index and optional end index\n * @returns Filter function that returns sliced string\n */\nconst slice = (options?:string[]): FilterFn<string> => {\n const numberedOpts: number[] = [requiredNumberOption(options, 0, 'slice')];\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n numberedOpts.push(numberOption(opt2, 'slice'));\n }\n return (value: unknown): string => {\n return String(value).slice(...numberedOpts);\n }\n}\n\n/**\n * Substring filter - extracts substring from specified position and length.\n * \n * @param options - Array with start index and length\n * @returns Filter function that returns substring\n */\nconst substr = (options?:string[]): FilterFn<string> => {\n // 4.0 removes `substr` in favour of `slice` (3.5 notice, D39). The registry caches the resolved\n // function per argument list, so this factory runs once per distinct use\n v4Migration?.removed('substr');\n const opt1 = requiredNumberOption(options, 0, 'substr');\n const opt2 = requiredNumberOption(options, 1, 'substr');\n return (value: unknown): string => {\n return String(value).substr(opt1, opt2);\n }\n}\n\n/**\n * Pad filter - pads string to specified length from start.\n * \n * @param options - Array with target length and pad string (default: '0')\n * @returns Filter function that returns padded string\n */\nconst pad = (options?:string[]): FilterFn<string> => {\n const opt1 = requiredNumberOption(options, 0, 'padStart');\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => {\n return String(value).padStart(opt1, opt2);\n }\n}\n\n/**\n * padEnd filter - pads string to specified length from the end (the pair of `padStart`, requirement B12).\n *\n * @param options - Array with target length and pad string (default: ' ')\n * @returns Filter function that returns padded string\n */\nconst padEnd = (options?:string[]): FilterFn<string> => {\n const opt1 = requiredNumberOption(options, 0, 'padEnd');\n const opt2 = options?.[1] ?? ' ';\n return (value: unknown): string => {\n return String(value).padEnd(opt1, opt2);\n }\n}\n\n/**\n * Repeat filter - repeats string specified number of times.\n * \n * @param options - Array with repeat count as first element\n * @returns Filter function that returns repeated string\n */\nconst rep = (options?:string[]): FilterFn<string> => {\n const opt = requiredNumberOption(options, 0, 'repeat');\n return (value: unknown): string => {\n return String(value).repeat(opt);\n }\n}\n\n/**\n * Reverse filter - reverses character order in string.\n * \n * @param options - Unused\n * @returns Filter function that returns reversed string\n */\nconst rev = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value).split('').reverse().join('');\n }\n}\n\n/**\n * Integer filter - parses value to integer.\n * \n * @param options - Unused\n * @returns Filter function that returns integer\n */\nconst int = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return parseInt(String(value), 10);\n }\n}\n\n/**\n * Float filter - parses value to floating point number.\n * \n * @param options - Unused\n * @returns Filter function that returns float\n */\nconst float = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return parseFloat(String(value));\n }\n}\n\n/**\n * Round filter - rounds number to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns rounded number\n */\nconst round = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'round'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round');}\n return Math.round(value * optValue) / optValue;\n }\n}\n\n/**\n * Floor filter - rounds number down to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns floored number\n */\nconst floor = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'floor'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor');}\n return Math.floor(value * optValue) / optValue;\n }\n}\n\n/**\n * Ceiling filter - rounds number up to specified decimal places.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns ceiled number\n */\nconst ceil = (options?:string[]): FilterFn<number> => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'ceil'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil');}\n return Math.ceil(value * optValue) / optValue;\n }\n}\n\n/**\n * Percent filter - formats number as percentage string.\n * \n * @param options - Array with decimal places as first element (default: 0)\n * @returns Filter function that returns percentage string with '%'\n */\nconst percent = (options?:string[]): FilterFn<string> => {\n const opt = numberOption(options?.[0] ?? '0', 'percent');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent');}\n return `${(value * 100).toFixed(opt)}%`;\n }\n}\n\n/**\n * Unit filter - appends a CSS unit (or any suffix) to the value.\n *\n * A number alone does nothing in CSS, so without this the unit has to be built in\n * state — which drags presentation into the source of truth, and in the worst case\n * forces a whole derived array just to carry `\"42%\"` strings.\n * `style.height: samples.*.cpu|clamp(0,100)|fix(0)|unit(%)` keeps it on the wire.\n *\n * Accepts strings as well as numbers **on purpose**: the useful chains run through\n * `fix` / `percent`, which already return strings. Rejecting non-numbers here would\n * break exactly the combination this filter exists for.\n *\n * `null` / `undefined` pass through untouched rather than becoming `\"undefinedpx\"`, so the\n * binding layer's \"undefined skips the write, null clears\" semantics survive. That guard is no\n * longer written here: it is `nullishPassthrough`, shared with the rest of the `String(value)`\n * family, which used to paint `\"undefined\"` into the page for exactly the same reason.\n *\n * @param options - Array with the unit/suffix as first element (required)\n * @returns Filter function that returns the value with the unit appended\n */\nconst unit = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): string => {\n return String(value) + opt;\n }\n}\n\n/**\n * Join filter - joins array elements into a string.\n *\n * The default separator is `\", \"` rather than `\",\"`: a bare comma is what `String()`\n * already produces without any filter, so defaulting to it would make `|join` a no-op.\n *\n * @param options - Array with separator as first element (default: ', ')\n * @returns Filter function that returns the joined string\n */\nconst join = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? ', ';\n return (value: unknown): string => {\n if (!Array.isArray(value)) {valueMustBeArray('join');}\n return value.join(opt);\n }\n}\n\n/**\n * Truncate filter - shortens a string and appends an ellipsis.\n *\n * The length option counts **kept characters**, not the total including the suffix,\n * matching the existing `slice(0, n)` reading. A string at or below the limit is\n * returned untouched (no suffix).\n *\n * @param options - Array with max kept length as first element and suffix as second (default: '…')\n * @returns Filter function that returns the truncated string\n */\nconst truncate = (options?:string[]): FilterFn<string> => {\n const maxLength = requiredNumberOption(options, 0, 'truncate');\n const suffix = options?.[1] ?? '…';\n return (value: unknown): string => {\n const v = String(value);\n if (v.length <= maxLength) {return v;}\n return v.slice(0, maxLength) + suffix;\n }\n}\n\n/**\n * Date filter - formats Date object as localized date string.\n *\n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns date string\n */\nconst date = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('date');}\n return value.toLocaleDateString(explicit ?? config.locale);\n }\n}\n\n/**\n * Time filter - formats Date object as localized time string.\n * \n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns time string\n */\nconst time = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('time');}\n return value.toLocaleTimeString(explicit ?? config.locale);\n }\n}\n\n/**\n * DateTime filter - formats Date object as localized date and time string.\n * \n * @param options - Array with locale string as first element (default: config.locale)\n * @returns Filter function that returns datetime string\n */\nconst datetime = (options?:string[]): FilterFn<string> => {\n // 既定ロケールは適用のたびに読む(`locale` フィルタの注記を参照)\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('datetime');}\n return value.toLocaleString(explicit ?? config.locale);\n }\n}\n\n/**\n * Year-Month-Day filter - formats Date object as YYYY-MM-DD string.\n * \n * @param options - Array with separator string as first element (default: '-')\n * @returns Filter function that returns formatted date string\n */\nconst ymd = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? '-';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('ymd');}\n const year = value.getFullYear().toString();\n const month = (value.getMonth() + 1).toString().padStart(2, '0');\n const day = value.getDate().toString().padStart(2, '0');\n return `${year}${opt}${month}${opt}${day}`;\n }\n}\n\n/**\n * Hour-Minute-Second filter - formats Date object as HH:MM:SS string.\n *\n * The counterpart of `ymd`: a fixed, zero-padded, locale-independent rendering with a\n * configurable separator, for when `time` (locale-formatted) is not stable enough.\n *\n * @param options - Array with separator string as first element (default: ':')\n * @returns Filter function that returns formatted time string\n */\nconst hms = (options?:string[]): FilterFn<string> => {\n const opt = options?.[0] ?? ':';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('hms');}\n const hours = value.getHours().toString().padStart(2, '0');\n const minutes = value.getMinutes().toString().padStart(2, '0');\n const seconds = value.getSeconds().toString().padStart(2, '0');\n return `${hours}${opt}${minutes}${opt}${seconds}`;\n }\n}\n\n/**\n * Falsy filter - checks if value is falsy, by JavaScript's own truthiness (`!value`: false, null,\n * undefined, 0, -0, 0n, '' and NaN). Before 3.0 the list was spelled out and missed 0n (B10).\n *\n * @param options - Unused\n * @returns Filter function that returns true for falsy values\n */\nconst falsy = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => !value;\n}\n\n/**\n * Truthy filter - checks if value is truthy.\n * \n * @param options - Unused\n * @returns Filter function that returns true for non-falsy values\n */\nconst truthy = (_options?:string[]): FilterFn<boolean> => {\n // JavaScript's truthiness, the same as the `boolean` filter (B10)\n return (value: unknown): boolean => !!value;\n}\n\n/**\n * Default filter - returns default value if input is falsy (JavaScript's truthiness, as `falsy`).\n * \n * @param options - Array with default value as first element\n * @returns Filter function that returns value or default\n */\nconst defaults = (options?:string[], literals?: readonly unknown[]): FilterFn<unknown> => {\n const opt = options?.[0] ?? optionsRequired('defaults');\n // The fallback is the typed literal (B9): defaults(0) gives 0, defaults(null) gives null, defaults('0') gives \"0\"\n const fallback = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): unknown => {\n if (!value) {return fallback;}\n return value;\n }\n}\n\n/**\n * coalesce filter - returns the default only for null / undefined (`defaults` also replaces 0, false and \"\").\n * Requirement B12: the nullish counterpart of `defaults`, read like SQL COALESCE.\n *\n * @param options - Array with default value as first element\n * @returns Filter function that returns value or default\n */\nconst coalesce = (options?:string[], literals?: readonly unknown[]): FilterFn<unknown> => {\n const opt = options?.[0] ?? optionsRequired('coalesce');\n const fallback = literals !== undefined && literals.length > 0 ? literals[0] : opt;\n return (value: unknown): unknown => value ?? fallback;\n}\n\n/**\n * Boolean filter - converts value to boolean.\n * \n * @param options - Unused\n * @returns Filter function that returns boolean\n */\nconst boolean = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => {\n return Boolean(value);\n }\n}\n\n/**\n * Number filter - converts value to number.\n * \n * @param options - Unused\n * @returns Filter function that returns number\n */\nconst number = (_options?:string[]): FilterFn<number> => {\n return (value: unknown): number => {\n return Number(value);\n }\n}\n\n/**\n * String filter - converts value to string.\n * \n * @param options - Unused\n * @returns Filter function that returns string\n */\nconst string = (_options?:string[]): FilterFn<string> => {\n return (value: unknown): string => {\n return String(value);\n }\n}\n\n/**\n * Null filter - converts empty string to null.\n * \n * @param options - Unused\n * @returns Filter function that returns null for empty string, otherwise original value\n */\nconst _null = (_options?:string[]): FilterFn<unknown> => {\n return (value: unknown): unknown => {\n return (value === \"\") ? null : value;\n } \n}\n\nconst builtinFilters: FilterWithOptions = {\n \"eq\": eq,\n \"ne\": ne,\n \"not\": not,\n\n \"lt\": lt,\n \"le\": le,\n \"gt\": gt,\n \"ge\": ge,\n\n \"add\": inc,\n \"sub\": dec,\n \"mul\": mul,\n \"div\": div,\n \"mod\": mod,\n \"abs\": abs,\n \"clamp\": clamp,\n\n \"toFixed\": fix,\n \"locale\": locale,\n // `String(value)` で組み立てる族は、値が無いときに素通しする(要件 B8 — nullishPassthrough を参照)\n \"upper\": nullishPassthrough(uc),\n \"lower\": nullishPassthrough(lc),\n \"capitalize\": nullishPassthrough(cap),\n \"trim\": nullishPassthrough(trim),\n \"slice\": nullishPassthrough(slice),\n \"substr\": nullishPassthrough(substr),\n \"padStart\": nullishPassthrough(pad),\n \"padEnd\": nullishPassthrough(padEnd),\n \"repeat\": nullishPassthrough(rep),\n \"reverse\": nullishPassthrough(rev),\n \"truncate\": nullishPassthrough(truncate),\n \"join\": join,\n\n \"int\": int,\n \"float\": float,\n \"round\": round,\n \"floor\": floor,\n \"ceil\": ceil,\n \"percent\": percent,\n \"unit\": nullishPassthrough(unit),\n\n \"date\": date,\n \"time\": time,\n \"datetime\": datetime,\n \"ymd\": ymd,\n \"hms\": hms,\n\n \"falsy\": falsy,\n \"truthy\": truthy,\n \"defaults\": defaults,\n \"coalesce\": coalesce,\n\n \"boolean\": boolean,\n \"number\": number,\n \"string\": string,\n \"nullIfEmpty\": _null,\n};\n\n/**\n * The argument count each built-in accepts, [min, max] — checked when the bindings are planned\n * (`[wcs/filter-arity]`, requirement B3), with the same bounds lint uses. It is the same data as\n * `builtinFilterMeta` (filters/filterMeta.ts) without the descriptions, so that installing the formats\n * does not pull the metadata into the page; a test keeps the two equal.\n */\nexport const builtinFilterArity: Readonly<Record<string, readonly [number, number]>> = {\n eq: [1, 1],\n not: [0, 0],\n ne: [1, 1],\n lt: [1, 1],\n le: [1, 1],\n gt: [1, 1],\n ge: [1, 1],\n add: [1, 1],\n sub: [1, 1],\n mul: [1, 1],\n div: [1, 1],\n mod: [1, 1],\n abs: [0, 0],\n clamp: [2, 2],\n toFixed: [0, 1],\n locale: [0, 1],\n upper: [0, 0],\n lower: [0, 0],\n capitalize: [0, 0],\n trim: [0, 0],\n slice: [1, 2],\n // `substr` は長さも必須(実装が両方読む・README も `substr(start, length)`)。\n // [1, 2] だったころは `substr(0)` が引数の個数の検査を素通りし、工場の\n // 「requires at least one option」という的外れな文言で落ちていた\n substr: [2, 2],\n padStart: [1, 2],\n padEnd: [1, 2],\n repeat: [1, 1],\n reverse: [0, 0],\n truncate: [1, 2],\n join: [0, 1],\n int: [0, 0],\n float: [0, 0],\n round: [0, 1],\n floor: [0, 1],\n ceil: [0, 1],\n percent: [0, 1],\n unit: [1, 1],\n // ロケール依存の 3 つは `locale` と同じく引数 1 つ(`date(ja-JP)`)を受ける。\n // [0, 0] だったころは、README が規範として書いている `timestamp|date(ja-JP)` が\n // 束縛計画の段で必ず `[wcs/filter-arity]` になっていた(2.x には検査自体が無かった)\n date: [0, 1],\n time: [0, 1],\n datetime: [0, 1],\n ymd: [0, 1],\n hms: [0, 1],\n falsy: [0, 0],\n truthy: [0, 0],\n defaults: [1, 1],\n coalesce: [1, 1],\n boolean: [0, 0],\n number: [0, 0],\n string: [0, 0],\n nullIfEmpty: [0, 0],\n};\n\nexport const outputBuiltinFilters = builtinFilters;\nexport const inputBuiltinFilters = builtinFilters;\n\nexport const builtinFiltersByFilterIOType = {\n \"input\": inputBuiltinFilters,\n \"output\": outputBuiltinFilters,\n} as const;\n\n/**\n * Retrieves built-in filter function by name and options.\n *\n * **Test / tooling only.** The binding pipeline never goes through here: it resolves\n * filters from the registry with `core/filterRegistry.ts#resolveFilterFn`, which also\n * checks `builtinFilterArity` and passes the **typed literals** (requirement B9).\n * This helper takes raw option strings only, so `builtinFilterFn(\"coalesce\", [\"0\"])`\n * yields the string `\"0\"` where the runtime yields the number `0`. Prefer\n * `resolveFilterFn` in any new code, and treat a difference between the two as a\n * limitation of this helper rather than of the runtime.\n *\n * @param name - Filter name (a 3.x alias such as `uc` resolves to its canonical name)\n * @param options - Array of option strings\n * @returns Function that takes FilterWithOptions and returns filter function\n */\nexport const builtinFilterFn = (name:string, options: string[]) => (filters: FilterWithOptions) => {\n // 自前のキーだけを引く。素のオブジェクトへのブラケット参照だと `Object.prototype` のメンバが\n // フィルタとして通り(`toString` / `constructor` / `valueOf`)、`[wcs/filter-unknown]` の代わりに\n // `\"[object Undefined]\"` や素の TypeError が出ていた。登録簿(core/filterRegistry.ts)が\n // まさにこの穴のために `Map` を採っているのと同じ規準\n const own = Object.prototype.hasOwnProperty;\n const canonical = own.call(builtinFilterAliases, name) ? builtinFilterAliases[name] : name;\n const filter = own.call(filters, canonical) ? filters[canonical] : undefined;\n if (!filter) {\n // lint の wcs/filter-unknown と同じ語彙・同じ did-you-mean 規準(三面同語彙)。\n raiseError(`[wcs/filter-unknown] filter not found: ${name}.${didYouMean(name, Object.keys(filters))}${LINT_HINT}`);\n }\n return filter(options);\n}\n\n","/**\n * formats/install.ts — 書式フィルタ群の install(設計案 §4、要件 D16)。\n *\n * `uc` / `date` / `round` / `truncate` … の実装を core の登録簿へ置く。core 自身が持つのは\n * エンジンが差し込む `not` だけなので、この機能を入れないページでは、宣言されたフィルタが\n * 束縛計画の段で `[wcs/filter-unknown]` として名指しで落ちる(黙って素通ししない)。\n */\nimport { registerFilters } from \"../core/filterRegistry\";\nimport { builtinFilterArity, inputBuiltinFilters, outputBuiltinFilters } from \"./builtinFilters\";\nimport { builtinFilterAliases } from \"../filters/filterAliases\";\n\nlet installed = false;\n/** 冪等。full / auto では `bootstrapState()` が呼ぶ */\nexport function installFormats(): void {\n if (installed) return;\n installed = true;\n registerFilters(\"input\", inputBuiltinFilters, builtinFilterArity, builtinFilterAliases);\n registerFilters(\"output\", outputBuiltinFilters, builtinFilterArity, builtinFilterAliases);\n}\n","/**\n * features/formats.ts — 書式フィルタ群(@wcstack/state/features/formats)。\n * `|uc` `|date(…)` `|round(…)` のような宣言が要求する実関数を core の登録簿へ置く。\n */\nimport type { IStateFeature } from \"../core/features\";\nimport { installFormats } from \"../formats/install\";\n\nexport const formats: IStateFeature = {\n name: \"formats\",\n install(): void {\n installFormats();\n },\n};\nexport default formats;\n"],"names":["optionsRequired","fnName","raiseError","optionMustBeNumber","valueMustBeNumber","valueMustBeDate","builtinFilterAliases","inc","dec","fix","uc","lc","cap","rep","rev","pad","null","validateNumberString","value","isNaN","Number","numberOption","requiredNumberOption","options","index","nullishPassthrough","factory","filterFn","builtinFilters","eq","literals","opt","literal","undefined","length","ne","not","_options","lt","le","gt","ge","add","sub","mul","div","mod","abs","Math","clamp","min","max","toFixed","locale","explicit","toLocaleString","config","upper","String","toUpperCase","lower","toLowerCase","capitalize","v","charAt","slice","trim","numberedOpts","opt2","push","substr","opt1","padStart","padEnd","repeat","reverse","split","join","truncate","maxLength","suffix","Array","isArray","int","parseInt","float","parseFloat","round","optValue","pow","floor","ceil","percent","unit","date","Date","toLocaleDateString","time","toLocaleTimeString","datetime","ymd","year","getFullYear","toString","month","getMonth","day","getDate","hms","hours","getHours","minutes","getMinutes","seconds","getSeconds","falsy","truthy","defaults","fallback","coalesce","boolean","Boolean","number","string","nullIfEmpty","builtinFilterArity","outputBuiltinFilters","inputBuiltinFilters","installed","formats","name","install","registerFilters"],"mappings":"iGAwBM,SAAUA,EAAgBC,GAC9BC,EAAW,UAAUD,iCACvB,CAQM,SAAUE,EAAmBF,GACjCC,EAAW,UAAUD,gCACvB,CAQM,SAAUG,EAAkBH,GAChCC,EAAW,UAAUD,4BACvB,CAQM,SAAUI,EAAgBJ,GAC9BC,EAAW,UAAUD,0BACvB,CCjDO,MAAMK,EAAyD,CACpEC,IAAK,MACLC,IAAK,MACLC,IAAK,UACLC,GAAI,QACJC,GAAI,QACJC,IAAK,aACLC,IAAK,SACLC,IAAK,UACLC,IAAK,WACLC,KAAM,eCOR,SAASC,EAAqBC,GAC5B,SAAKA,GAASC,MAAMC,OAAOF,IAI7B,CAUA,SAASG,EAAaH,EAAejB,GAEnC,OADKgB,EAAqBC,IAASf,EAAmBF,GAC/CmB,OAAOF,EAChB,CAGA,SAASI,EAAqBC,EAA+BC,EAAevB,GAC1E,OAAOoB,EAAaE,IAAUC,IAAUxB,EAAgBC,GAASA,EACnE,CAoBA,MAAMwB,EAAsBC,GACzBH,IACC,MAAMI,EAAWD,EAAQH,GAEzB,OAAQL,GAAsC,MAATA,EAAgBA,EAAQS,EAAST,IA0uBpEU,EAAoC,CACxCC,GAluBS,CA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AAG,GACZC,SAAU,CAAC,EAAG,GACdE,SAAU,CAAC,EAAG,GACdC,QAAS,CAAC,EAAG,GACbE,OAAQ,CAAC,EAAG,GACZC,OAAQ,CAAC,EAAG,GACZC,YAAa,CAAC,EAAG,IAGNE,EAAuBlG,EACvBmG,EAAsBnG,ECj6BnC,IAAIoG,GAAY,ECJT,MAAMC,EAAyB,CACpCC,KAAM,UACN,OAAAC,GDKIH,IACJA,GAAY,EACZI,EAAgB,QAASL,EAAqBF,EAAoBvH,GAClE8H,EAAgB,SAAUN,EAAsBD,EAAoBvH,GCNpE"}
@@ -1,2 +1,2 @@
1
- import{r as e}from"../chunks/declarationHooks.js";import{R as t,D as n,W as r,M as s,s as i,g as o,t as a,r as c}from"../chunks/pathDiagnostics.js";import{g as l,a as h,s as u,b as d,c as f,d as p,e as g}from"../chunks/setAll.js";import{M as m,j as v,l as $,N as w,O as y}from"../chunks/binder.js";import{r as x,N as P,g as _}from"../chunks/getAllPropertyDescriptors.js";import{r as A}from"../chunks/errorGuidance.js";import"../chunks/checkDependency.js";import"../chunks/filterRegistry.js";function b(e){return-1!==e.indexOf(t)}function k(e,t){if(t===e.recursiveAnchor)return"";const s=e.recursiveAnchor+n;if(!t.startsWith(s))return null;const i=t.slice(e.recursiveAnchor.length);if(b(i))return null;const o=i.slice(n.length).split(n);return o[0]===r||o.some(e=>0===e.length)?null:i}function I(e){return 0===e.length?e:n+L(e.slice(n.length))}function j(e,t,r){const s=n+e.repeat,i=t.length<=r.length?t:r,o=t.length<=r.length?r:t;if(!o.endsWith(i))return!1;const a=o.slice(0,o.length-i.length);if(0===a.length)return!0;if(a.length%s.length!==0)return!1;for(let e=0;e<a.length;e+=s.length)if(!a.startsWith(s,e))return!1;return!0}function R(e,t,r){for(let s=r.length;s>0;s=r.lastIndexOf(n,s-1))if(j(e,t,r.slice(0,s)))return!0;return!1}function L(e){const t=e.split(n);for(let e=0;e<t.length;e++)t[e]===r||Number.isNaN(Number(t[e]))||(t[e]=r);return t.join(n)}function O(e,t){const r=e.repeat.split(n),s=n+e.repeat;let i=t;for(;i.startsWith(s);)i=i.slice(s.length);if(0===i.length||i===n+e.repeatList+n+"length")return!0;for(let e=1;e<r.length;e++)if(i===n+r.slice(0,e).join(n))return!0;return!1}function W(e,t,i){i<0&&A(`Recursion depth must not be negative (got ${i}).`);let o=e.anchor;for(let t=0;t<i;t++)o+=n+e.repeat;const a=o+t;let c=0;for(const e of a.split(n))e===r&&c++;return c>s&&A(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${i} ("${a}"), which needs ${c} wildcard levels — the limit is ${s}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),a}function S(e,t){return W(e,"",t)}function N(e,t,r){if(!r.startsWith(e.anchor))return null;if(t.length>0&&!r.endsWith(t))return null;if(r.length<e.anchor.length+t.length)return null;const s=r.slice(e.anchor.length,r.length-t.length);if(0===s.length)return 0;const i=n+e.repeat;let o=0,a=0;for(;a<s.length;){if(!s.startsWith(i,a))return null;a+=i.length,o++}return o}function B(e,t){if(0===e.addressStackLength)return null;const r=e.lastAddressStack;if(null===r)return null;const s=t.accessorFor(r.pathInfo.path);return null!==s?s.depth:function(e,t){const r=e.spec;if(!t.startsWith(r.anchor))return null;const s=n+r.repeat;let i=0,o=r.anchor.length;for(;t.startsWith(s,o);)o+=s.length,i++;return o!==t.length&&46!==t.charCodeAt(o)?null:i}(t,r.pathInfo.path)}function E(e,t,n){const r=e.recursionRegistry,s=k(r.spec,n);null===s&&A(i(n,r.spec.recursiveAnchor));const o=B(t,r);return null===o&&A(`[wcs/recursion-context] "${n}" uses "**", which is bound to the depth of the recursive getter being evaluated, and there is no recursion context here. Read it from inside a recursive getter or a row getter under "${r.spec.anchor}", or name a concrete depth (for example "${r.spec.anchor}${n.slice(r.spec.recursiveAnchor.length)}"). The depth comes from the innermost frame only: a plain getter reached from a recursive getter has no row of its own, so read "**" in the recursive getter and pass the value on.`),r.concretePathAt(s,o)}function C(e,t,r,s,i){const a=s.spec,c=[],h=new Map,u=[],d=a.repeatList,f=a.anchorList,p=new Set,g=new Set,x=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void c.push(v(e,n));const s=P(r[t],n,null).rows;for(let n=0;n<s.length;n++)x(e,t+1,s[n])};function P(n,s,i){const o=v(n,s),c=$(r.stateElement,o),u=l(e,o,t,r),f=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return p.has(r)&&A(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${a.anchor}" walked into a list that one of its own ancestors already owns. The data contains a cycle, which this version does not support.`),n.has(r)&&A(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${a.anchor}" needs a tree: give each node its own "${d}" array.`),r})(n.path,u,i),g=w(s,y(c),u);return h.set(c,Array.isArray(u)?u:[]),null!==f&&null!==i&&i.add(f),{rows:g.newIndexes,tracked:f}}const _=(e,t,r)=>{const{rows:a,tracked:l}=P(t,r,g);if(0===a.length)return;const h=(e=>{const t=u[e];if(void 0!==t)return t;const r=s.concretePathAt(i,e),a=0===i.length?r:s.concretePathAt("",e),c={nodePath:a,concretePathInfo:o(r),childListPathInfo:o(a+n+d)};return u[e]=c,c})(e),f=l;p.add(f);const m=h.concretePathInfo.wildcardCount===e+1;for(let t=0;t<a.length;t++){const n=a[t];m?c.push(v(h.concretePathInfo,n)):x(h.concretePathInfo,e+1,n),_(e+1,h.childListPathInfo,n)}p.delete(f)};_(0,o(f),null);for(const[e,t]of h)m(e,t);return c}function D(e,t,n,r,s,o,c){h(n);const l=n.stateElement.recursionRegistry,d=k(l.spec,r);null===d&&A(i(r,l.spec.recursiveAnchor));const f=I(d);Array.isArray(s)||A(a(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&A(`[wcs/recursion-setall-form] $setAll("${r}", indexes, …) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Pass [] to broadcast to every depth.`),"function"==typeof o&&A(a(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===c?.spread&&A(a(r,'with "**" does not take { spread: true } — handing a flat array to a tree needs the author to know the walk order, which is not a usable contract.')),function(e,t,n){O(e,n)&&A(`[wcs/recursion-structural-write] "${t}" writes the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). This version broadcasts to leaf properties only — replacing a node would invalidate the child addresses already resolved for this write.`)}(l.spec,r,f);const p=l.conflictingRecursiveGetter(f);null!==p&&A(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${p}", which has no setter — the two name the same family of concrete paths (or this path points inside the value that getter derives). Write the values it derives from instead.`);const g=C(e,t,n,l,d);let m=0;for(let r=0;r<g.length;r++)void 0!==o&&(u(e,g[r],o,t,n),m++);return m}const G={write(e,t){if(!0!==e.hasRecursion)return P;const n=e.recursionRegistry.recursiveGetterOwningPath(t.pathInfo);return null!==n&&A(`[wcs/recursion-readonly] "${t.pathInfo.path}" writes into the recursive getter "${n}" (this path is that getter at one depth, or a path inside the value it derives), which has no setter. Write the values it derives from instead.`),P},get(e,t,n,r){if(!0!==e.stateElement.hasRecursion)return P;if("$getAll"===t)return(s,o)=>{if(b(s)){if(void 0!==o)return function(e,t,n,r,s){const o=n.stateElement.recursionRegistry,a=k(o.spec,r);null===a&&A(i(r,o.spec.recursiveAnchor)),Array.isArray(s)||A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes either no indexes (to read the depth of the recursive getter being evaluated) or [] (to walk every depth) — got ${null===s?"null":typeof s}.`),s.length>0&&A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Omit the indexes to read the depth of the recursive getter being evaluated, or pass [] to walk every depth.`);const c=C(e,t,n,o,a),h=[];for(let r=0;r<c.length;r++)h.push(l(e,c[r],t,n));return h}(r,n,e,s,o);s=E(e.stateElement,e,s)}return d(r,t,n,e)(s,o)};if("$setAll"===t)return(s,i,o,a)=>b(s)?D(r,n,e,s,i,o,a):f(r,t,n,e)(s,i,o,a);if(36!==t.charCodeAt(0)&&b(t)){const s=p(E(e.stateElement,e,t)),i=g(r,s,n,e);return l(r,v(s.pathInfo,i),n,e)}return P}};let z=!1;function M(e,s){"string"==typeof s&&0!==s.length||A(`[wcs/recursion-declaration-invalid] ${c} ${e} must be a non-empty string.`);const i=s.split(n);i.some(e=>0===e.length)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain empty path segments.`),i.length<2&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must name a list element: a property path ending with "${n}${r}" (for example "nodes${n}${r}").`),i[i.length-1]!==r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must end with "${n}${r}" — it names the element of the list, not the list itself.`),36===i[0].charCodeAt(0)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not start with "$" — that namespace is reserved.`),-1!==s.indexOf("#")&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "#" — that segment is reserved for mounts.`);for(let n=0;n<i.length-1;n++)i[n]===r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must have exactly one "${r}", at the end. Wildcards in the middle are not supported in this version.`),i[n]===t&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "${t}" — the declaration is what gives "${t}" its meaning.`),isNaN(Number(i[n]))||A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain an index segment ("${i[n]}") — the recursion is declared over the shape of the tree, not over one row.`)}const T=new WeakSet;function F(e){return"function"==typeof e.get&&T.has(e.get)}const H="[wcs/recursion-declaration-invalid]";class q{spec;_definitions=new Map;_accessors=new Map;_ownerByPath=new Map;_ownerByPathInfo=new WeakMap;_accessorByPathInfo=new WeakMap;_concreteBySuffix=new Map;_registeredListPaths=new Set;constructor(e,t){this.spec=e;const r=_(t);for(const[t,s]of Object.entries(r)){if(!b(t))continue;"function"==typeof s.set&&A(`${H} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof s.get&&A(`${H} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=k(e,t);null===r&&A(i(t,e.recursiveAnchor)),0===r.length&&A(`${H} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${n}total"), not the node.`),O(e,I(r))&&A(`${H} "${t}" names the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). A recursive getter would hide the real child list at every depth — "**" names a computed leaf under a node (for example "${e.recursiveAnchor}${n}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:s.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(b(t)||F(n))continue;const e=this._matchExpansion(t);null!==e&&A(`${H} "${t}" is already defined on the state, so the recursive getter "${e}" cannot expand to it. Rename one of them.`)}}_assertNoColliding(){const e=Array.from(this._definitions.values());for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)j(this.spec,e[t].suffix,e[n].suffix)&&A(`${H} "${e[t].recursivePath}" and "${e[n].recursivePath}" expand to the same concrete path at different depths (they differ by whole repetitions of "${this.spec.repeat}"). Rename one of them.`)}get hasDefinitions(){return this._definitions.size>0}conflictingRecursiveGetter(e){for(const t of this._definitions.values())if(R(this.spec,t.suffix,e))return t.recursivePath;return null}recursiveGetterOwningPath(e){const t=this._ownerByPathInfo.get(e);if(void 0!==t)return t;const n=this.recursiveGetterOwning(e.path);return this._ownerByPathInfo.set(e,n),n}recursiveGetterOwning(e){const t=this._accessors.get(e);if(void 0!==t)return t.recursivePath;const r=L(e),s=this._ownerByPath.get(r);if(void 0!==s)return s;let i=null;if(r.startsWith(this.spec.anchor)){i=this._matchExpansion(r);for(let e=r.lastIndexOf(n);null===i&&e>this.spec.anchor.length;e=r.lastIndexOf(n,e-1))i=this._matchExpansion(r.slice(0,e))}return this._ownerByPath.set(r,i),i}_matchExpansion(e){for(const t of this._definitions.values())if(null!==N(this.spec,t.suffix,e))return t.recursivePath;return null}materializeForPathInfo(e,t){if(0===this._definitions.size)return null;const n=this._accessorByPathInfo.get(t);if(void 0!==n)return n;const r=this.materializeFor(e,t.path);return this._accessorByPathInfo.set(t,r),r}materializeFor(e,t){const n=this._accessors.get(t);if(void 0!==n)return n;if(!t.startsWith(this.spec.anchor))return null;let r=null,s=0;for(const e of this._definitions.values()){const n=N(this.spec,e.suffix,t);null!==n&&(null!==r&&A(`"${t}" matches both "${r.recursivePath}" and "${e.recursivePath}".`),r=e,s=n)}return null===r?null:this._define(e,r,s,t)}_define(e,t,n,r){const s=e.findStateDescriptor(r);void 0===s||F(s)||A(`"${r}" is already defined on the state, so the recursive getter "${t.recursivePath}" cannot expand to it. Rename one of them.`);const i=Object.freeze({recursivePath:t.recursivePath,depth:n}),o=t.get,a=function(){return o.call(this)};var c;return c=a,T.add(c),e.defineTreeAccessor(r,{get:a,enumerable:!1,configurable:!0}),this._registerListPaths(e,n),this._accessors.set(r,i),i}_registerListPaths(e,t){for(const r of function(e,t){const r=[];r.push(e.anchorList);for(let s=0;s<t;s++)r.push(S(e,s)+n+e.repeatList);return r}(this.spec,t))this._registeredListPaths.has(r)||(this._registeredListPaths.add(r),e.addListPath(r))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return function(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&F(n)&&delete t[e]}for(const t of[e.staticDependency,e.dynamicDependency]){for(const e of n)t.delete(e);for(const[e,r]of t){let s=null;for(let e=0;e<r.length;e++)n.has(r[e])?s??=r.slice(0,e):s?.push(r[e]);null!==s&&(0===s.length?t.delete(e):t.set(e,s))}}}}(e,t,n),n}concretePathAt(e,t){let n=this._concreteBySuffix.get(e);void 0===n&&(n=[],this._concreteBySuffix.set(e,n));let r=n[t];return void 0===r&&(r=W(this.spec,e,t),n[t]=r),r}accessorFor(e){return this._accessors.get(e)??null}get materializedPaths(){return new Set(this._accessors.keys())}}const J="recursionSpec",K="recursionRegistry",Q={order:5,validateEarly(e,s,i){const o=function(e){const s=e[c];if(void 0===s)return null;"object"==typeof s&&null!==s||A(`[wcs/recursion-declaration-invalid] ${c} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const i=Object.entries(s);0===i.length&&A(`[wcs/recursion-declaration-invalid] ${c} must declare exactly one anchor; it is empty.`),i.length>1&&A(`[wcs/recursion-declaration-invalid] ${c} declares ${i.length} anchors (${i.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[o,a]=i[0];M("anchor",o),"string"!=typeof a&&A(`[wcs/recursion-declaration-invalid] ${c} entry "${o}" must map to the repeating sub-path as a string (for example "children${n}${r}").`),M("repeating sub-path",a);const l=o.slice(0,o.lastIndexOf(n)),h=a.slice(0,a.lastIndexOf(n)),u=l+n+t;return Object.freeze({anchor:o,repeat:a,recursiveAnchor:u,anchorList:l,repeatList:h})}(s);i.set(J,o),i.set(K,null===o?null:new q(o,s))},preCommit(e,t,n){const r=e.recursionRegistry;if(null!==r)for(const t of r.forgetGenerated(e,n.get("previousState")))e.addGeneratedPath?.(t);const s=n.get(K)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",c)},apply(e,t,n){const r=n.get(J)??null;null!==r&&e.addListPath(r.anchorList)}};let U=!1;function V(){U||(U=!0,z||(z=!0,x("recursion",G)),e("recursion",Q))}const X={name:"recursion",install(){V()}};export{X as default,X as recursion};
1
+ import{r as e}from"../chunks/declarationHooks.js";import{R as t,D as n,W as r,M as s,s as i,g as o,t as a,r as c}from"../chunks/pathDiagnostics.js";import{g as l}from"../chunks/checkDependency.js";import{M as h,j as u,l as d,N as f,O as p}from"../chunks/binder.js";import{r as g,N as m,g as v}from"../chunks/getAllPropertyDescriptors.js";import{g as $,a as w,s as y,b as x,c as P,d as _}from"../chunks/setAll.js";import{r as A}from"../chunks/errorGuidance.js";import"../chunks/filterRegistry.js";function b(e){return-1!==e.indexOf(t)}function k(e,t){if(t===e.recursiveAnchor)return"";const s=e.recursiveAnchor+n;if(!t.startsWith(s))return null;const i=t.slice(e.recursiveAnchor.length);if(b(i))return null;const o=i.slice(n.length).split(n);return o[0]===r||o.some(e=>0===e.length)?null:i}function I(e){return 0===e.length?e:n+L(e.slice(n.length))}function j(e,t,r){const s=n+e.repeat,i=t.length<=r.length?t:r,o=t.length<=r.length?r:t;if(!o.endsWith(i))return!1;const a=o.slice(0,o.length-i.length);if(0===a.length)return!0;if(a.length%s.length!==0)return!1;for(let e=0;e<a.length;e+=s.length)if(!a.startsWith(s,e))return!1;return!0}function R(e,t,r){for(let s=r.length;s>0;s=r.lastIndexOf(n,s-1))if(j(e,t,r.slice(0,s)))return!0;return!1}function L(e){const t=e.split(n);for(let e=0;e<t.length;e++)t[e]===r||Number.isNaN(Number(t[e]))||(t[e]=r);return t.join(n)}function O(e,t){const r=e.repeat.split(n),s=n+e.repeat;let i=t;for(;i.startsWith(s);)i=i.slice(s.length);if(0===i.length||i===n+e.repeatList+n+"length")return!0;for(let e=1;e<r.length;e++)if(i===n+r.slice(0,e).join(n))return!0;return!1}function W(e,t,i){i<0&&A(`Recursion depth must not be negative (got ${i}).`);let o=e.anchor;for(let t=0;t<i;t++)o+=n+e.repeat;const a=o+t;let c=0;for(const e of a.split(n))e===r&&c++;return c>s&&A(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${i} ("${a}"), which needs ${c} wildcard levels — the limit is ${s}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),a}function S(e,t){return W(e,"",t)}function N(e,t,r){if(!r.startsWith(e.anchor))return null;if(t.length>0&&!r.endsWith(t))return null;if(r.length<e.anchor.length+t.length)return null;const s=r.slice(e.anchor.length,r.length-t.length);if(0===s.length)return 0;const i=n+e.repeat;let o=0,a=0;for(;a<s.length;){if(!s.startsWith(i,a))return null;a+=i.length,o++}return o}function B(e,t){if(0===e.addressStackLength)return null;const r=e.lastAddressStack;if(null===r)return null;const s=t.accessorFor(r.pathInfo.path);return null!==s?s.depth:function(e,t){const r=e.spec;if(!t.startsWith(r.anchor))return null;const s=n+r.repeat;let i=0,o=r.anchor.length;for(;t.startsWith(s,o);)o+=s.length,i++;return o!==t.length&&46!==t.charCodeAt(o)?null:i}(t,r.pathInfo.path)}function E(e,t,n){const r=e.recursionRegistry,s=k(r.spec,n);null===s&&A(i(n,r.spec.recursiveAnchor));const o=B(t,r);return null===o&&A(`[wcs/recursion-context] "${n}" uses "**", which is bound to the depth of the recursive getter being evaluated, and there is no recursion context here. Read it from inside a recursive getter or a row getter under "${r.spec.anchor}", or name a concrete depth (for example "${r.spec.anchor}${n.slice(r.spec.recursiveAnchor.length)}"). The depth comes from the innermost frame only: a plain getter reached from a recursive getter has no row of its own, so read "**" in the recursive getter and pass the value on.`),r.concretePathAt(s,o)}function C(e,t,r,s,i){const a=s.spec,c=[],l=new Map,g=[],m=a.repeatList,v=a.anchorList,w=new Set,y=new Set,x=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void c.push(u(e,n));const s=P(r[t],n,null).rows;for(let n=0;n<s.length;n++)x(e,t+1,s[n])};function P(n,s,i){const o=u(n,s),c=d(r.stateElement,o),h=$(e,o,t,r),g=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return w.has(r)&&A(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${a.anchor}" walked into a list that one of its own ancestors already owns. The data contains a cycle, which this version does not support.`),n.has(r)&&A(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${a.anchor}" needs a tree: give each node its own "${m}" array.`),r})(n.path,h,i),v=f(s,p(c),h);return l.set(c,Array.isArray(h)?h:[]),null!==g&&null!==i&&i.add(g),{rows:v.newIndexes,tracked:g}}const _=(e,t,r)=>{const{rows:a,tracked:l}=P(t,r,y);if(0===a.length)return;const h=(e=>{const t=g[e];if(void 0!==t)return t;const r=s.concretePathAt(i,e),a=0===i.length?r:s.concretePathAt("",e),c={nodePath:a,concretePathInfo:o(r),childListPathInfo:o(a+n+m)};return g[e]=c,c})(e),d=l;w.add(d);const f=h.concretePathInfo.wildcardCount===e+1;for(let t=0;t<a.length;t++){const n=a[t];f?c.push(u(h.concretePathInfo,n)):x(h.concretePathInfo,e+1,n),_(e+1,h.childListPathInfo,n)}w.delete(d)};_(0,o(v),null);for(const[e,t]of l)h(e,t);return c}function D(e,t,n,r,s,o,c){w(n);const l=n.stateElement.recursionRegistry,h=k(l.spec,r);null===h&&A(i(r,l.spec.recursiveAnchor));const u=I(h);Array.isArray(s)||A(a(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&A(`[wcs/recursion-setall-form] $setAll("${r}", indexes, …) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Pass [] to broadcast to every depth.`),"function"==typeof o&&A(a(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===c?.spread&&A(a(r,'with "**" does not take { spread: true } — handing a flat array to a tree needs the author to know the walk order, which is not a usable contract.')),function(e,t,n){O(e,n)&&A(`[wcs/recursion-structural-write] "${t}" writes the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). This version broadcasts to leaf properties only — replacing a node would invalidate the child addresses already resolved for this write.`)}(l.spec,r,u);const d=l.conflictingRecursiveGetter(u);null!==d&&A(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${d}", which has no setter — the two name the same family of concrete paths (or this path points inside the value that getter derives). Write the values it derives from instead.`);const f=C(e,t,n,l,h);let p=0;for(let r=0;r<f.length;r++)void 0!==o&&(y(e,f[r],o,t,n),p++);return p}const G={write(e,t){if(!0!==e.hasRecursion)return m;const n=e.recursionRegistry.recursiveGetterOwningPath(t.pathInfo);return null!==n&&A(`[wcs/recursion-readonly] "${t.pathInfo.path}" writes into the recursive getter "${n}" (this path is that getter at one depth, or a path inside the value it derives), which has no setter. Write the values it derives from instead.`),m},get(e,t,n,r){if(!0!==e.stateElement.hasRecursion)return m;if("$getAll"===t)return(s,o)=>{if(b(s)){if(void 0!==o)return function(e,t,n,r,s){const o=n.stateElement.recursionRegistry,a=k(o.spec,r);null===a&&A(i(r,o.spec.recursiveAnchor)),Array.isArray(s)||A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes either no indexes (to read the depth of the recursive getter being evaluated) or [] (to walk every depth) — got ${null===s?"null":typeof s}.`),s.length>0&&A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Omit the indexes to read the depth of the recursive getter being evaluated, or pass [] to walk every depth.`);const c=C(e,t,n,o,a),l=[];for(let r=0;r<c.length;r++)l.push($(e,c[r],t,n));return l}(r,n,e,s,o);s=E(e.stateElement,e,s)}return x(r,t,n,e)(s,o)};if("$setAll"===t)return(s,i,o,a)=>b(s)?D(r,n,e,s,i,o,a):P(r,t,n,e)(s,i,o,a);if(36!==t.charCodeAt(0)&&b(t)){const s=l(E(e.stateElement,e,t)),i=_(r,s,n,e);return $(r,u(s.pathInfo,i),n,e)}return m}};let z=!1;function M(e,s){"string"==typeof s&&0!==s.length||A(`[wcs/recursion-declaration-invalid] ${c} ${e} must be a non-empty string.`);const i=s.split(n);i.some(e=>0===e.length)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain empty path segments.`),i.length<2&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must name a list element: a property path ending with "${n}${r}" (for example "nodes${n}${r}").`),i[i.length-1]!==r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must end with "${n}${r}" — it names the element of the list, not the list itself.`),36===i[0].charCodeAt(0)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not start with "$" — that namespace is reserved.`),-1!==s.indexOf("#")&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "#" — that segment is reserved for mounts.`);for(let n=0;n<i.length-1;n++)i[n]===r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must have exactly one "${r}", at the end. Wildcards in the middle are not supported in this version.`),i[n]===t&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "${t}" — the declaration is what gives "${t}" its meaning.`),isNaN(Number(i[n]))||A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain an index segment ("${i[n]}") — the recursion is declared over the shape of the tree, not over one row.`)}const T=new WeakSet;function F(e){return"function"==typeof e.get&&T.has(e.get)}const H="[wcs/recursion-declaration-invalid]";class q{spec;_definitions=new Map;_accessors=new Map;_ownerByPath=new Map;_ownerByPathInfo=new WeakMap;_accessorByPathInfo=new WeakMap;_concreteBySuffix=new Map;_registeredListPaths=new Set;constructor(e,t){this.spec=e;const r=v(t);for(const[t,s]of Object.entries(r)){if(!b(t))continue;"function"==typeof s.set&&A(`${H} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof s.get&&A(`${H} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=k(e,t);null===r&&A(i(t,e.recursiveAnchor)),0===r.length&&A(`${H} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${n}total"), not the node.`),O(e,I(r))&&A(`${H} "${t}" names the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). A recursive getter would hide the real child list at every depth — "**" names a computed leaf under a node (for example "${e.recursiveAnchor}${n}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:s.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(b(t)||F(n))continue;const e=this._matchExpansion(t);null!==e&&A(`${H} "${t}" is already defined on the state, so the recursive getter "${e}" cannot expand to it. Rename one of them.`)}}_assertNoColliding(){const e=Array.from(this._definitions.values());for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)j(this.spec,e[t].suffix,e[n].suffix)&&A(`${H} "${e[t].recursivePath}" and "${e[n].recursivePath}" expand to the same concrete path at different depths (they differ by whole repetitions of "${this.spec.repeat}"). Rename one of them.`)}get hasDefinitions(){return this._definitions.size>0}conflictingRecursiveGetter(e){for(const t of this._definitions.values())if(R(this.spec,t.suffix,e))return t.recursivePath;return null}recursiveGetterOwningPath(e){const t=this._ownerByPathInfo.get(e);if(void 0!==t)return t;const n=this.recursiveGetterOwning(e.path);return this._ownerByPathInfo.set(e,n),n}recursiveGetterOwning(e){const t=this._accessors.get(e);if(void 0!==t)return t.recursivePath;const r=L(e),s=this._ownerByPath.get(r);if(void 0!==s)return s;let i=null;if(r.startsWith(this.spec.anchor)){i=this._matchExpansion(r);for(let e=r.lastIndexOf(n);null===i&&e>this.spec.anchor.length;e=r.lastIndexOf(n,e-1))i=this._matchExpansion(r.slice(0,e))}return this._ownerByPath.set(r,i),i}_matchExpansion(e){for(const t of this._definitions.values())if(null!==N(this.spec,t.suffix,e))return t.recursivePath;return null}materializeForPathInfo(e,t){if(0===this._definitions.size)return null;const n=this._accessorByPathInfo.get(t);if(void 0!==n)return n;const r=this.materializeFor(e,t.path);return this._accessorByPathInfo.set(t,r),r}materializeFor(e,t){const n=this._accessors.get(t);if(void 0!==n)return n;if(!t.startsWith(this.spec.anchor))return null;let r=null,s=0;for(const e of this._definitions.values()){const n=N(this.spec,e.suffix,t);null!==n&&(null!==r&&A(`"${t}" matches both "${r.recursivePath}" and "${e.recursivePath}".`),r=e,s=n)}return null===r?null:this._define(e,r,s,t)}_define(e,t,n,r){const s=e.findStateDescriptor(r);void 0===s||F(s)||A(`"${r}" is already defined on the state, so the recursive getter "${t.recursivePath}" cannot expand to it. Rename one of them.`);const i=Object.freeze({recursivePath:t.recursivePath,depth:n}),o=t.get,a=function(){return o.call(this)};var c;return c=a,T.add(c),e.defineTreeAccessor(r,{get:a,enumerable:!1,configurable:!0}),this._registerListPaths(e,n),this._accessors.set(r,i),i}_registerListPaths(e,t){for(const r of function(e,t){const r=[];r.push(e.anchorList);for(let s=0;s<t;s++)r.push(S(e,s)+n+e.repeatList);return r}(this.spec,t))this._registeredListPaths.has(r)||(this._registeredListPaths.add(r),e.addListPath(r))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return function(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&F(n)&&delete t[e]}for(const t of[e.staticDependency,e.dynamicDependency]){for(const e of n)t.delete(e);for(const[e,r]of t){let s=null;for(let e=0;e<r.length;e++)n.has(r[e])?s??=r.slice(0,e):s?.push(r[e]);null!==s&&(0===s.length?t.delete(e):t.set(e,s))}}}}(e,t,n),n}concretePathAt(e,t){let n=this._concreteBySuffix.get(e);void 0===n&&(n=[],this._concreteBySuffix.set(e,n));let r=n[t];return void 0===r&&(r=W(this.spec,e,t),n[t]=r),r}accessorFor(e){return this._accessors.get(e)??null}get materializedPaths(){return new Set(this._accessors.keys())}}const J="recursionSpec",K="recursionRegistry",Q={order:5,validateEarly(e,s,i){const o=function(e){const s=e[c];if(void 0===s)return null;"object"==typeof s&&null!==s||A(`[wcs/recursion-declaration-invalid] ${c} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const i=Object.entries(s);0===i.length&&A(`[wcs/recursion-declaration-invalid] ${c} must declare exactly one anchor; it is empty.`),i.length>1&&A(`[wcs/recursion-declaration-invalid] ${c} declares ${i.length} anchors (${i.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[o,a]=i[0];M("anchor",o),"string"!=typeof a&&A(`[wcs/recursion-declaration-invalid] ${c} entry "${o}" must map to the repeating sub-path as a string (for example "children${n}${r}").`),M("repeating sub-path",a);const l=o.slice(0,o.lastIndexOf(n)),h=a.slice(0,a.lastIndexOf(n)),u=l+n+t;return Object.freeze({anchor:o,repeat:a,recursiveAnchor:u,anchorList:l,repeatList:h})}(s);i.set(J,o),i.set(K,null===o?null:new q(o,s))},preCommit(e,t,n){const r=e.recursionRegistry;if(null!==r)for(const t of r.forgetGenerated(e,n.get("previousState")))e.addGeneratedPath?.(t);const s=n.get(K)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",c)},apply(e,t,n){const r=n.get(J)??null;null!==r&&e.addListPath(r.anchorList)}};let U=!1;function V(){U||(U=!0,z||(z=!0,g("recursion",G)),e("recursion",Q))}const X={name:"recursion",install(){V()}};export{X as default,X as recursion};
2
2
  //# sourceMappingURL=recursion.js.map