@wcstack/state 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +25 -17
- package/README.md +25 -17
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/define.d.ts +11 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +12 -1
- package/dist/manifest.esm.js +90 -35
- package/dist/split/chunks/declarationAliases.js +2 -0
- package/dist/split/chunks/declarationAliases.js.map +1 -0
- package/dist/split/chunks/filterRegistry.js +1 -1
- package/dist/split/chunks/filterRegistry.js.map +1 -1
- package/dist/split/chunks/mount.js +1 -1
- package/dist/split/chunks/mount.js.map +1 -1
- package/dist/split/chunks/pathDiagnostics.js +1 -1
- package/dist/split/chunks/pathDiagnostics.js.map +1 -1
- package/dist/split/chunks/registerComponents.js +1 -1
- package/dist/split/chunks/registerComponents.js.map +1 -1
- package/dist/split/chunks/version.js +1 -1
- package/dist/split/core.d.ts +11 -7
- package/dist/split/core.js +1 -1
- package/dist/split/core.js.map +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/devtools.js.map +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/formats.js.map +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/ssr.js.map +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/split/features/temporal.js.map +1 -1
- package/dist/wcs-manifest.json +64 -25
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sources":["../../../../../src/formats/errorMessages.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 * - valueMustBeBoolean: Error when value is not boolean\n * - valueMustBeDate: Error when value is not a Date\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 numeric value but non-number provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeString(fnName:string): never {\n raiseError(`filter ${fnName} requires a string value`);\n}\n\n/**\n * Throws error when filter requires boolean value but non-boolean provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeBoolean(fnName:string): never {\n raiseError(`filter ${fnName} requires a boolean 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 * 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, valueMustBeBoolean, valueMustBeDate, valueMustBeNumber } from \"./errorMessages.js\";\nimport { FilterFn, FilterWithOptions } from \"../filters/types\";\n\nfunction validateNumberString(value: string): boolean {\n if (!value || isNaN(Number(value))) {\n return false;\n }\n return true;\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 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 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 boolean value.\n * \n * @param options - Unused\n * @returns Filter function that returns inverted boolean\n */\nconst not = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => {\n if (typeof value !== 'boolean') {valueMustBeBoolean('not');}\n return !value;\n }\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 = options?.[0] ?? optionsRequired('lt');\n if (!validateNumberString(opt)) {optionMustBeNumber('lt');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('lt');}\n return value < Number(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 = options?.[0] ?? optionsRequired('le');\n if (!validateNumberString(opt)) {optionMustBeNumber('le');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('le');}\n return value <= Number(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 = options?.[0] ?? optionsRequired('gt');\n if (!validateNumberString(opt)) {optionMustBeNumber('gt');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('gt');}\n return value > Number(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 = options?.[0] ?? optionsRequired('ge');\n if (!validateNumberString(opt)) {optionMustBeNumber('ge');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('ge');}\n return value >= Number(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 = options?.[0] ?? optionsRequired('inc');\n if (!validateNumberString(opt)) {optionMustBeNumber('inc');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('inc');}\n return value + Number(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 = options?.[0] ?? optionsRequired('dec');\n if (!validateNumberString(opt)) {optionMustBeNumber('dec');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('dec');}\n return value - Number(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 = options?.[0] ?? optionsRequired('mul');\n if (!validateNumberString(opt)) {optionMustBeNumber('mul');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mul');}\n return value * Number(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 = options?.[0] ?? optionsRequired('div');\n if (!validateNumberString(opt)) {optionMustBeNumber('div');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('div');}\n return value / Number(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 = options?.[0] ?? optionsRequired('mod');\n if (!validateNumberString(opt)) {optionMustBeNumber('mod');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mod');}\n return value % Number(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 opt1 = options?.[0] ?? optionsRequired('clamp');\n if (!validateNumberString(opt1)) {optionMustBeNumber('clamp');}\n const opt2 = options?.[1] ?? optionsRequired('clamp');\n if (!validateNumberString(opt2)) {optionMustBeNumber('clamp');}\n const min = Number(opt1);\n const max = Number(opt2);\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 = options?.[0] ?? \"0\";\n if (!validateNumberString(opt)) {optionMustBeNumber('fix');}\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('fix');}\n return value.toFixed(Number(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[] = [];\n const opt1 = options?.[0] ?? optionsRequired('slice');\n if (!validateNumberString(opt1)) {optionMustBeNumber('slice');}\n numberedOpts.push(Number(opt1));\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n if (!validateNumberString(opt2)) {optionMustBeNumber('slice');}\n numberedOpts.push(Number(opt2));\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 = options?.[0] ?? optionsRequired('substr');\n if (!validateNumberString(opt1)) {optionMustBeNumber('substr');}\n const opt2 = options?.[1] ?? optionsRequired('substr');\n if (!validateNumberString(opt2)) {optionMustBeNumber('substr');}\n return (value: unknown): string => {\n return String(value).substr(Number(opt1), Number(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 = options?.[0] ?? optionsRequired('pad');\n if (!validateNumberString(opt1)) {optionMustBeNumber('pad');}\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => {\n return String(value).padStart(Number(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 = options?.[0] ?? optionsRequired('rep');\n if (!validateNumberString(opt)) {optionMustBeNumber('rep');}\n return (value: unknown): string => {\n return String(value).repeat(Number(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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('round');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round');}\n const optValue = Math.pow(10, Number(opt));\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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('floor');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor');}\n const optValue = Math.pow(10, Number(opt));\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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('ceil');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil');}\n const optValue = Math.pow(10, Number(opt));\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 = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('percent');}\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent');}\n return `${(value * 100).toFixed(Number(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\"`,\n * so the binding layer's \"undefined skips the write, null clears\" semantics survive.\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<unknown> => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): unknown => {\n if (value === null || typeof value === 'undefined') {return value;}\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 opt1 = options?.[0] ?? optionsRequired('truncate');\n if (!validateNumberString(opt1)) {optionMustBeNumber('truncate');}\n const maxLength = Number(opt1);\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 * 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 \"inc\": inc,\n \"dec\": dec,\n \"mul\": mul,\n \"div\": div,\n \"mod\": mod,\n \"abs\": abs,\n \"clamp\": clamp,\n\n \"fix\": fix,\n \"locale\": locale,\n \"uc\": uc,\n \"lc\": lc,\n \"cap\": cap,\n \"trim\": trim,\n \"slice\": slice,\n \"substr\": substr,\n \"pad\": pad,\n \"rep\": rep,\n \"rev\": rev,\n \"truncate\": 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\": 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\n \"boolean\": boolean,\n \"number\": number,\n \"string\": string,\n \"null\": _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 inc: [0, 1],\n dec: [0, 1],\n mul: [1, 1],\n div: [1, 1],\n mod: [1, 1],\n abs: [0, 0],\n clamp: [2, 2],\n fix: [0, 1],\n locale: [0, 1],\n uc: [0, 0],\n lc: [0, 0],\n cap: [0, 0],\n trim: [0, 0],\n slice: [1, 2],\n substr: [1, 2],\n pad: [1, 2],\n rep: [1, 1],\n rev: [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 date: [0, 0],\n time: [0, 0],\n datetime: [0, 0],\n ymd: [0, 1],\n hms: [0, 1],\n falsy: [0, 0],\n truthy: [0, 0],\n defaults: [1, 1],\n boolean: [0, 0],\n number: [0, 0],\n string: [0, 0],\n null: [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 * @param name - Filter 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 const filter = filters[name];\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\";\n\nlet installed = false;\n/** 冪等。full / auto では `bootstrapState()` が呼ぶ */\nexport function installFormats(): void {\n if (installed) return;\n installed = true;\n registerFilters(\"input\", inputBuiltinFilters, builtinFilterArity);\n registerFilters(\"output\", outputBuiltinFilters, builtinFilterArity);\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","validateNumberString","value","isNaN","Number","builtinFilters","eq","options","literals","opt","literal","undefined","length","ne","not","_options","lt","le","gt","ge","inc","dec","mul","div","mod","abs","Math","clamp","opt1","opt2","min","max","fix","toFixed","locale","explicit","toLocaleString","config","uc","String","toUpperCase","lc","toLowerCase","cap","v","charAt","slice","trim","numberedOpts","push","substr","pad","padStart","rep","repeat","rev","split","reverse","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","boolean","Boolean","number","string","null","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,CA4BM,SAAUI,EAAgBJ,GAC9BC,EAAW,UAAUD,0BACvB,CCtDA,SAASK,EAAqBC,GAC5B,SAAKA,GAASC,MAAMC,OAAOF,IAI7B,CAQA,MAgtBMG,EAAoC,CACxCC,GAjtBS,CAACC,EAAmBC,KAC7B,MAAMC,EAAMF,IAAU,IAAMZ,EAAgB,MAEtCe,OAAuBC,IAAbH,GAA0BA,EAASI,OAAS,EAAIJ,EAAS,GAAKC,EAC9E,OAAQP,GAEe,iBAAVA,GACJD,EAAqBQ,IAAOX,EAAmB,MAC7CI,IAAUE,OAAOK,IAEL,iBAAVP,EACFA,IAAUO,EAGZP,IAAUQ,GAosBnBG,GA1rBS,CAACN,EAAmBC,KAC7B,MAAMC,EAAMF,IAAU,IAAMZ,EAAgB,MACtCe,OAAuBC,IAAbH,GAA0BA,EAASI,OAAS,EAAIJ,EAAS,GAAKC,EAC9E,OAAQP,GAEe,iBAAVA,GACJD,EAAqBQ,IAAOX,EAAmB,MAC7CI,IAAUE,OAAOK,IAEL,iBAAVP,EACFA,IAAUO,EAGZP,IAAUQ,GA8qBnBI,IApqBWC,GACHb,IACe,kBAAVA,GDnBbL,EAAW,UCmB2C,mCAC5CK,GAmqBVc,GAzpBUT,IACV,MAAME,EAAMF,IAAU,IAAMZ,EAAgB,MAE5C,OADKM,EAAqBQ,IAAOX,EAAmB,MAC5CI,IACe,iBAAVA,GAAqBH,EAAkB,MAC3CG,EAAQE,OAAOK,KAqpBxBQ,GA3oBUV,IACV,MAAME,EAAMF,IAAU,IAAM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ASL,EAAqBF,GAC9CO,EAAgB,SAAUN,EAAsBD,GCLhD"}
|
|
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 * - valueMustBeBoolean: Error when value is not boolean\n * - valueMustBeDate: Error when value is not a Date\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 numeric value but non-number provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeString(fnName:string): never {\n raiseError(`filter ${fnName} requires a string value`);\n}\n\n/**\n * Throws error when filter requires boolean value but non-boolean provided.\n * \n * @param fnName - Name of the filter function\n * @returns Never returns (always throws)\n */\nexport function valueMustBeBoolean(fnName:string): never {\n raiseError(`filter ${fnName} requires a boolean 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, valueMustBeBoolean, valueMustBeDate, valueMustBeNumber } from \"./errorMessages.js\";\nimport { FilterFn, FilterWithOptions } 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 * 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 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 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 boolean value.\n * \n * @param options - Unused\n * @returns Filter function that returns inverted boolean\n */\nconst not = (_options?:string[]): FilterFn<boolean> => {\n return (value: unknown): boolean => {\n if (typeof value !== 'boolean') {valueMustBeBoolean('not');}\n return !value;\n }\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 = options?.[0] ?? optionsRequired('lt');\n if (!validateNumberString(opt)) {optionMustBeNumber('lt');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('lt');}\n return value < Number(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 = options?.[0] ?? optionsRequired('le');\n if (!validateNumberString(opt)) {optionMustBeNumber('le');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('le');}\n return value <= Number(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 = options?.[0] ?? optionsRequired('gt');\n if (!validateNumberString(opt)) {optionMustBeNumber('gt');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('gt');}\n return value > Number(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 = options?.[0] ?? optionsRequired('ge');\n if (!validateNumberString(opt)) {optionMustBeNumber('ge');}\n return (value: unknown): boolean => {\n if (typeof value !== 'number') {valueMustBeNumber('ge');}\n return value >= Number(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 = options?.[0] ?? optionsRequired('add');\n if (!validateNumberString(opt)) {optionMustBeNumber('add');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('add');}\n return value + Number(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 = options?.[0] ?? optionsRequired('sub');\n if (!validateNumberString(opt)) {optionMustBeNumber('sub');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('sub');}\n return value - Number(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 = options?.[0] ?? optionsRequired('mul');\n if (!validateNumberString(opt)) {optionMustBeNumber('mul');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mul');}\n return value * Number(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 = options?.[0] ?? optionsRequired('div');\n if (!validateNumberString(opt)) {optionMustBeNumber('div');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('div');}\n return value / Number(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 = options?.[0] ?? optionsRequired('mod');\n if (!validateNumberString(opt)) {optionMustBeNumber('mod');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('mod');}\n return value % Number(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 opt1 = options?.[0] ?? optionsRequired('clamp');\n if (!validateNumberString(opt1)) {optionMustBeNumber('clamp');}\n const opt2 = options?.[1] ?? optionsRequired('clamp');\n if (!validateNumberString(opt2)) {optionMustBeNumber('clamp');}\n const min = Number(opt1);\n const max = Number(opt2);\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 = options?.[0] ?? \"0\";\n if (!validateNumberString(opt)) {optionMustBeNumber('toFixed');}\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('toFixed');}\n return value.toFixed(Number(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[] = [];\n const opt1 = options?.[0] ?? optionsRequired('slice');\n if (!validateNumberString(opt1)) {optionMustBeNumber('slice');}\n numberedOpts.push(Number(opt1));\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n if (!validateNumberString(opt2)) {optionMustBeNumber('slice');}\n numberedOpts.push(Number(opt2));\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 = options?.[0] ?? optionsRequired('substr');\n if (!validateNumberString(opt1)) {optionMustBeNumber('substr');}\n const opt2 = options?.[1] ?? optionsRequired('substr');\n if (!validateNumberString(opt2)) {optionMustBeNumber('substr');}\n return (value: unknown): string => {\n return String(value).substr(Number(opt1), Number(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 = options?.[0] ?? optionsRequired('padStart');\n if (!validateNumberString(opt1)) {optionMustBeNumber('padStart');}\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => {\n return String(value).padStart(Number(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 = options?.[0] ?? optionsRequired('padEnd');\n if (!validateNumberString(opt1)) {optionMustBeNumber('padEnd');}\n const opt2 = options?.[1] ?? ' ';\n return (value: unknown): string => {\n return String(value).padEnd(Number(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 = options?.[0] ?? optionsRequired('repeat');\n if (!validateNumberString(opt)) {optionMustBeNumber('repeat');}\n return (value: unknown): string => {\n return String(value).repeat(Number(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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('round');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round');}\n const optValue = Math.pow(10, Number(opt));\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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('floor');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor');}\n const optValue = Math.pow(10, Number(opt));\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 opt = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('ceil');}\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil');}\n const optValue = Math.pow(10, Number(opt));\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 = options?.[0] ?? '0';\n if (!validateNumberString(opt)) {optionMustBeNumber('percent');}\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent');}\n return `${(value * 100).toFixed(Number(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\"`,\n * so the binding layer's \"undefined skips the write, null clears\" semantics survive.\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<unknown> => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): unknown => {\n if (value === null || typeof value === 'undefined') {return value;}\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 opt1 = options?.[0] ?? optionsRequired('truncate');\n if (!validateNumberString(opt1)) {optionMustBeNumber('truncate');}\n const maxLength = Number(opt1);\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 \"upper\": uc,\n \"lower\": lc,\n \"capitalize\": cap,\n \"trim\": trim,\n \"slice\": slice,\n \"substr\": substr,\n \"padStart\": pad,\n \"padEnd\": padEnd,\n \"repeat\": rep,\n \"reverse\": rev,\n \"truncate\": 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\": 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: [1, 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 date: [0, 0],\n time: [0, 0],\n datetime: [0, 0],\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 * @param name - Filter 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 const filter = filters[name] ?? filters[builtinFilterAliases[name]];\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","builtinFilters","eq","options","literals","opt","literal","undefined","length","ne","not","_options","lt","le","gt","ge","add","sub","mul","div","mod","abs","Math","clamp","opt1","opt2","min","max","toFixed","locale","explicit","toLocaleString","config","upper","String","toUpperCase","lower","toLowerCase","capitalize","v","charAt","slice","trim","numberedOpts","push","substr","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,CA4BM,SAAUI,EAAgBJ,GAC9BC,EAAW,UAAUD,0BACvB,CCrEO,MAAMK,EAAyD,CACpEC,IAAK,MACLC,IAAK,MACLC,IAAK,UACLC,GAAI,QACJC,GAAI,QACJC,IAAK,aACLC,IAAK,SACLC,IAAK,UACLC,IAAK,WACLC,KAAM,eCMR,SAASC,EAAqBC,GAC5B,SAAKA,GAASC,MAAMC,OAAOF,IAI7B,CAQA,MA4uBMG,EAAoC,CACxCC,GA7uBS,CAACC,EAAmBC,KAC7B,MAAMC,EAAMF,IAAU,IAAMvB,EAAgB,MAEtC0B,OAAuBC,IAAbH,GAA0BA,EAASI,OAAS,EAAIJ,EAAS,GAAKC,EAC9E,OAAQP,GAEe,iBAAVA,GACJD,EAAqBQ,IAAOtB,EAAmB,MAC7Ce,IAAUE,OAAOK,IAEL,iBAAVP,EACFA,IAAUO,EAGZP,IAAUQ,GAguBnBG,GAttBS,CAACN,EAAmBC,KAC7B,MAAMC,EAAMF,IAAU,IAAMvB,EAAgB,MACtC0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AC,EAAG,GACbC,OAAQ,CAAC,EAAG,GACZI,MAAO,CAAC,EAAG,GACXG,MAAO,CAAC,EAAG,GACXE,WAAY,CAAC,EAAG,GAChBI,KAAM,CAAC,EAAG,GACVD,MAAO,CAAC,EAAG,GACXI,OAAQ,CAAC,EAAG,GACZC,SAAU,CAAC,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,GACVC,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,EAAuBnG,EACvBoG,EAAsBpG,ECz3BnC,IAAIqG,GAAY,ECJT,MAAMC,EAAyB,CACpCC,KAAM,UACN,OAAAC,GDKIH,IACJA,GAAY,EACZI,EAAgB,QAASL,EAAqBF,EAAoBjH,GAClEwH,EAAgB,SAAUN,EAAsBD,EAAoBjH,GCNpE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as t,l as e,a as n,C as o}from"../chunks/lifecycleHooks.js";import{f as r,h as s,a,i,D as c,V as l,j as u,g as d,k as f,W as h,l as m,m as p,n as g,R as y,o as b}from"../chunks/pathDiagnostics.js";import{r as $,d as w}from"../chunks/errorGuidance.js";import{a as v,g as k,N as S}from"../chunks/getAllPropertyDescriptors.js";import{c as P}from"../chunks/filterRegistry.js";import{h as j,u as C,i as I,j as A,k as x,m as N,n as R,o as M,p as O,q as E,t as D,v as W,w as z,x as L,y as V,z as B,A as F,B as _,C as q,D as T,E as U}from"../chunks/binder.js";import{f as H,t as K,a as G,b as X,c as J,s as Q,g as Y,d as Z,e as tt,r as et,h as nt,i as ot,j as rt,k as st,l as at,m as it,n as ct,w as lt}from"../chunks/mount.js";import{p as ut}from"../chunks/diagnosticsHooks.js";import{c as dt}from"../chunks/checkDependency.js";import{y as ft,z as ht,A as mt}from"../chunks/watchRuntime.js";const pt={written:function(t,e,n){const o=t.bindableEventMap,r=o[e.path],s="string"==typeof r,a=s?r:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof a)return;const i=t.rootNode;i instanceof ShadowRoot&&i.host.dispatchEvent(new CustomEvent(a,{detail:s&&void 0!==n?n.value:void 0,bubbles:!0}))}};let gt=!1;function yt(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function bt(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function $t(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function wt(t){return t.startsWith("$")}function vt(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function kt(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||$(`${e} must be an array of strings.`);const o=[],r=new Set;for(const t of n)"string"==typeof t&&0!==t.length||$(`${e} entries must be non-empty strings.`),t.startsWith("$")&&$(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),r.has(t)&&$(`${e} entry "${t}" is duplicated.`),r.add(t),o.push(t);return o}function St(t){const e=kt(t,r)??[],n=kt(t,s)??[],o=k(t),i=function(t){const e=t[a];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),c=[];for(const t of e){const e=o[t];if(void 0===e){if(i.has(t)){c.push(t);continue}$(`${r} entry "${t}" is not declared on the state.${w(t,vt(o,"value"))}`)}"function"==typeof e.value&&$(`${r} entry "${t}" is a method. Declare it in ${s} instead.`)}for(const t of n){const e=o[t];void 0===e&&$(`${s} entry "${t}" is not declared on the state.${w(t,vt(o,"method"))}`),"function"!=typeof e.value&&$(`${s} entry "${t}" is not a method. Declare it in ${r} instead.`)}return{bindables:e,commands:n,streamBackedBindables:c}}function Pt(t,e,n){const o=t.tagName.toLowerCase();o.includes("-")||$(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`);const s=j(t);null!==s&&"function"==typeof s.define||$(`DCC: CustomElementRegistry is unavailable for "${o}".`),s.get(o)&&$(`DCC: "${o}" is already registered. A custom element name can only be defined once.`);const a=document.createElement("template"),c=a.content.ownerDocument;for(const t of Array.from(e.childNodes))a.content.appendChild(c.importNode(t,!0));const l=e.mode,{bindables:u,commands:d,streamBackedBindables:f}=St(n),h=u.length>0||d.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const r=n.map(t=>({name:t,async:!0}));return{...o,commands:r}}(o,u,d):null,m=u.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(o,u):{},p=P.tagNames.state,g=class extends HTMLElement{static template=a;static shadowRootMode=l;static wcBindable=h;static bindableEventMap=m;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(i))return null;this._shadow=this.attachShadow({mode:g.shadowRootMode}),this._shadow.appendChild(g.template.content.cloneNode(!0));const t=j(this._shadow);return null!==t&&C(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(g.bindableEventMap).length>0){const e=t.querySelector(p);e?(gt||(gt=!0,v("dcc",pt)),e.setBindableEventMap(g.bindableEventMap)):console.warn(`[@wcstack/state] DCC: "${o}" declares ${r} but its template has no <${P.tagNames.state}>. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(p)??null}},y=k(n);for(const[t,e]of Object.entries(y)){if(wt(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=$t(t,o)}else n.get=yt(t),n.set=bt(t);Object.defineProperty(g.prototype,t,n)}for(const t of f)Object.defineProperty(g.prototype,t,{configurable:!0,enumerable:!0,get:yt(t),set:bt(t)});s.define(o,g)}async function jt(t,o,r){const s=t;try{s.hasAttribute("bind-component")&&$(`"bind-component" cannot be used inside a [${i}] host. DCC state comes from the template, not from a component property.`);const a=await async function(t,o){try{if(t.hasAttribute("src")){const n=t.getAttribute("src");if(n.endsWith(".js"))return await e(n);$(`DCC: Unsupported src type: ${n}`)}const r=t.querySelector('script[type="module"]');if(r)return await n(r,o.tagName.toLowerCase());$(`DCC: No state source found for "${o.tagName.toLowerCase()}".`)}catch(t){$(`DCC: Failed to load state: ${t}`)}}(s,o);Pt(o,r,a),t.markTreeless(),t.markInitialized(),t.clearConnectedRootNode(),t.settleInitialization()}catch(e){t.failInitializeLoudly(e)}}const Ct={order:10,connecting(t){const e=t.parentNode;return e instanceof ShadowRoot&&e.host.hasAttribute(i)?jt(t,e.host,e):null}};let It=!1;const At=new WeakMap;function xt(t,e,n){let o=At.get(t);void 0===o&&(o=new Map,At.set(t,o));const r=o.get(e);null!=r&&$(`Volume slot "${e}" is already mounted on this tree.`),o.set(e,n)}function Nt(t,e){if(null===t)return!1;const n=At.get(t);if(void 0===n||0===n.size)return!1;for(const t of n.keys())if(e===t||e.startsWith(t+c)||t.startsWith(e+c))return!0;return!1}const Rt=new WeakMap;const Mt=[];function Ot(t,e,n,o){if(e.length>0){const r=n.split(c),s=H(e,r);if(null!==s)return o&&s.readonly&&$(`[wcs/mount-readonly] volume "${t}" cannot write "${n}": it is injected read-only ("${l}.${s.innerSegments.join(c)}#${u}: ${s.outerPathInfo.path}"). Write "${s.outerPathInfo.path}" on the root, or drop #${u} from the injection.`),K(s,r)}return t+c+n}function Et(t,e,n){for(const t of e){const e=t.outerPathInfo.path;if(n===e)return t.innerSegments.join(c);if(n.startsWith(e+c))return t.innerSegments.join(c)+n.slice(e.length)}return n===t?"":n.startsWith(t+c)?n.slice(t.length+1):null}function Dt(t,e,n=Mt){return new Proxy({},{get(o,r){if("string"==typeof r&&"then"!==r){if("$"===r[0]){if("$postUpdate"===r||"$getAll"===r){const o=r;return(r,...s)=>e[o](Ot(t,n,r,!1),...s)}return"$setAll"===r?(o,...r)=>e.$setAll(Ot(t,n,o,!0),...r):"$resolve"===r?(o,...r)=>e.$resolve(Ot(t,n,o,r.length>1),...r):e[r]}return e[Ot(t,n,r,!1)]}},set:(o,r,s)=>("string"!=typeof r||(e[Ot(t,n,r,!0)]=s),!0),has:(t,e)=>"string"==typeof e&&"$"!==e[0]&&"#"!==e[0]})}const Wt=new WeakMap,zt=[];const Lt=new WeakMap,Vt=new WeakSet;function Bt(t){console.error(`[@wcstack/state] volume "${t.mountPath}" was not grafted — the root state element on this root node failed to initialize (its own diagnostic is reported separately). The volume is not at fault: fix the root <wcs-state>.`),t.onGrafted(null)}let Ft=null;const _t=new WeakMap,qt=new Set;function Tt(t,e,n,o){let r=_t.get(t);if(void 0===r){if(!o)return null;r=new Map,_t.set(t,r)}let s=r.get(e);if(void 0===s){if(!o)return null;s=new Map,r.set(e,s)}let a=s.get(n);if(void 0===a){if(!o)return null;a={holders:new Set,byListIndex:new WeakMap,noIndex:null},s.set(n,a)}return a}function Ut(t,e){if(!t.component.isConnected)return!1;const n=I(t.component)?.listIndex??null;if(null===e)return null===n;let o=n;for(;null!==o;){if(o===e)return!0;o=o.parentListIndex}return!1}function Ht(t,e,n,o){const r=Tt(t,e,n,!1);if(null===r)return null;const s=null===o?r.noIndex:r.byListIndex.get(o)??null;if(null!==s){const t=function(t,e){const n=t.ref.deref();return void 0!==n&&Ut(n,e)?n:null}(s,o);if(null!==t)return{record:t,entry:s.entry}}let a=null,i=null;for(const t of r.holders){const s=t.ref.deref();void 0!==s?Ut(s,o)&&(null!==i&&$(`[wcs/mount-export-ambiguous] "${e}${c}${n}" is exported by two mounted components on the same instance: <${i.component.tagName.toLowerCase()}> and <${s.component.tagName.toLowerCase()}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),a=t,i=s):r.holders.delete(t)}return null===a||null===i?null:(null===o?r.noIndex=a:r.byListIndex.set(o,a),{record:i,entry:a.entry})}function Kt(t){const e=t.parentStateElement,n=I(t.component);if(!(!1===e.isConnected||t.delta>0&&null===n))for(const o of t.exports.values())e.createState("readonly",t=>{t[A](n,()=>{t.$postUpdate(o.exportedPath)})})}const Gt=new WeakMap;class Xt{record;markerParentPath;listIndex;isBase;receiver;handler;constructor(t,e,n,o,r,s){this.record=t,this.markerParentPath=e,this.listIndex=n,this.isBase=o,this.receiver=r,this.handler=s}accessorNameFor(t){return this.record.accessorBySuffixByMarkerParent.get(this.markerParentPath)?.get(t)?.accessorName}accessorAddress(t){return x(d(this.markerParentPath+c+t),this.listIndex)}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e);if("then"===e)return;if("$"===e[0]){if("$postUpdate"===e)return t=>{this.receiver.$postUpdate(G(this.record,t))};if("$getAll"===e||"$setAll"===e||"$resolve"===e){const t=this.record,n=this.listIndex?.indexes??[],o=this.receiver;if("$resolve"===e)return(e,r,...s)=>{const a=s.length>0?X(t,e):G(t,e),i=J(t,e,a,r??[],n);return o.$resolve(a,i,...s)};const r=e;return(e,s,...a)=>{const i="$setAll"===r?X(t,e):G(t,e),c=J(t,e,i,s,n);return o[r](i,c,...a)}}return this.receiver[e]}const o=this.accessorNameFor(e);if(void 0!==o){this.handler.pushAddress(this.accessorAddress(e));try{return Reflect.get(this.record.stateObject,o,n)}finally{this.handler.popAddress()}}if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return dt(this.handler,this.accessorAddress(e)),t[e];const o=this.record.stateObject[e];if("function"==typeof o)return o.bind(n)}return this.receiver[G(this.record,e)]}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n);const r=this.accessorNameFor(e);if(void 0!==r){this.record.setterKeys.has(r)||$(`Cannot write to "${r}" on mounted <${this.record.component.tagName.toLowerCase()}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),this.handler.pushAddress(this.accessorAddress(e)),this.handler.beginUntrack();try{return Reflect.set(this.record.stateObject,r,n,o)}finally{this.handler.endUntrack(),this.handler.popAddress()}}return this.isBase&&Object.prototype.hasOwnProperty.call(t,e)?(t[e]=n,!0):(this.receiver[X(this.record,e)]=n,!0)}has(t,e){if("string"!=typeof e)return Reflect.has(t,e);if("$"===e[0]||"#"===e[0])return!1;if(void 0!==this.accessorNameFor(e))return!0;if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return!0;if("function"==typeof this.record.stateObject[e])return!0}try{return G(this.record,e),!0}catch{return!1}}}function Jt(t,e,n,o){const r=e.pathInfo.path,s=r===t.markerBasePath,a=s?function(t,e){let n=Gt.get(t);if(void 0===n&&(n={byListIndex:new WeakMap,noIndex:null},Gt.set(t,n)),null===e)return n.noIndex??={...t.privateSnapshot};let o=n.byListIndex.get(e);return void 0===o&&(o={...t.privateSnapshot},n.byListIndex.set(e,o)),o}(t,e.listIndex):{};return new Proxy(a,new Xt(t,r,e.listIndex,s,n,o))}function Qt(t){const e=t.parentStateElement,n=(e,n)=>{const o=I(t.component);let r;return e[A](o,()=>{r=n()}),r};return new Proxy({},{get(o,r){if("string"!=typeof r||"then"===r)return;if("$getAll"===r||"$setAll"===r||"$resolve"===r||"$postUpdate"===r)return function(t,e,n){const o=t.parentStateElement,r=(t,e)=>{let r;return o.createState(t,t=>{r=n(t,()=>e(t))}),r};return"$postUpdate"===e?e=>r("readonly",n=>n.$postUpdate(G(t,e))):(n,o,...s)=>{const a="$setAll"===e||"$resolve"===e&&s.length>0,i=a?X(t,n):G(t,n),c=I(t.component)?.listIndex.indexes??[],l=J(t,n,i,"$resolve"===e?o??[]:o,c);return r(a?"writable":"readonly",t=>t[e](i,l,...s))}}(t,r,n);let s;return e.createState("readonly",e=>{s=n(e,()=>e["$"===r[0]?r:G(t,r)])}),s},set:(o,r,s)=>("string"!=typeof r||e.createState("writable",e=>{n(e,()=>{e["$"===r[0]?r:X(t,r)]=s})}),!0),has(e,n){if("string"!=typeof n||"$"===n[0]||"#"===n[0])return!1;if(Object.prototype.hasOwnProperty.call(t.stateObject,n))return!0;try{return G(t,n),!0}catch{return!1}}})}function Yt(t,e){const n=tt(e);null!==n&&n.stateProp!==t.stateProp&&$(`A mount scope is already initialized on this component for "${n.stateProp}" — one <wcs-state bind-component> per component (v2). Merge the "${t.stateProp}" wiring into "${n.stateProp}" or split the component.`),null!==n&&N(e).dispose(),et(e,t),e instanceof ShadowRoot&&O(e,t.parentStateElement),function(t,e){const n=(e,n)=>nt(t,e,n);D(e);const o=I(t.component),r=e instanceof ShadowRoot?e:e.getRootNode();W(r,e,void 0,n),z(e,o,n)}(t,e),function(t){if(t.exports.size>0||null===t.rootEntry)return;const e=new Set([...t.getterKeys,...t.setterKeys]);for(const n of e){let e;try{e=G(t,n)}catch{continue}const o=e.indexOf(c+t.marker);if(-1===o)continue;const r=e.slice(0,o+1+t.marker.length),s=e.slice(r.length+1),a=e.slice(0,o)+c+s,i=d(a);if(i.wildcardCount!==t.delta)continue;const l={markerTerminalPath:r,suffix:s,markerPath:e,exportedPath:a};t.exports.set(a,l),Tt(t.parentStateElement,i.parentPath,i.lastSegment,!0).holders.add({ref:new WeakRef(t),entry:l}),t.parentStateElement.addDynamicDependency(e,a),ut?.markExported(t.parentStateElement,a)}t.parentStateElement.markHasMounts?.()}(t),function(t){const e=I(t.component);if(t.delta>0&&null===e)return;const n=t.component.tagName.toLowerCase();for(const o of t.exports.values()){const r=`${n}|${o.exportedPath}`;if(qt.has(r))continue;const s=d(o.exportedPath);let a;t.parentStateElement.createState("readonly",t=>{t[A](e,()=>{a=t[s.parentPath]})}),null!=a&&s.lastSegment in Object(a)&&(qt.add(r),console.warn(`[@wcstack/state] [wcs/mount-export-shadowed] <${n}>.${t.stateProp}.${o.suffix} is exported at "${o.exportedPath}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`))}}(t),Kt(t),E(e,Promise.resolve())}function Zt(t,e){const n=N(e),o=I(t.component);n.forEachActiveBindingNode(t=>R(t,o));const r=n.rebindAddresses();M(r),Kt(t)}function te(t,e){for(let n=e.firstNode;null!==n;n=n.nextSibling){if(n===t||n.contains(t))return!0;if(n===e.lastNode)break}return!1}const ee={read(t,e,n,o){if(!0===t.hasMounts&&35===e.pathInfo.lastSegment.charCodeAt(0)){const r=rt(t,e.pathInfo.path);if(null!==r)return Jt(r,e,n,o)}return S},readMissing(t,e,n,o,r){if(null===n){if(Nt(t.rootNode??null,e.pathInfo.path))return;return S}if(!0===t.hasMounts){const n=Ht(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r){const s=Jt(t,x(d(e.markerTerminalPath),n),o,r);return Reflect.get(s,e.suffix)}(n.record,n.entry,e.listIndex,o,r)}return S},write(t,e){if(!0===t.hasGraftedVolumes){const n=e.pathInfo.path,o=function(t,e){const n=Rt.get(t);if(void 0===n||0===n.size)return null;const o=e+c;for(const t of n)if(t.startsWith(o))return t;return null}(t,n);null!==o&&$(`Cannot replace "${n}" wholesale: a volume is mounted at "${o}" under it (D22). Replacing an ancestor of a mount point silently discards the grafted data while its accessors remain. Write "${o}" itself, or individual fields inside "${n}", instead.`)}return S},writeMissing(t,e,n,o,r,s,a){if(!0===t.hasMounts){const n=Ht(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r,s){const a=Jt(t,x(d(e.markerTerminalPath),n),r,s);return Reflect.set(a,e.suffix,o)}(n.record,n.entry,e.listIndex,r,s,a)}return S},indexShift(t,e){const n=t.stateElement,o=e.pathInfo.path;if(!0===n.hasMounts&&-1!==o.indexOf("#")){const t=rt(n,o);if(null!==t)return st(t,o)}return 0},handlerScope(t,e,n,o,r){if(!0!==t.hasMounts)return r;const s=ot(e,n);if(null===s)return r;const a=s.indexShiftByLoopElementPath.get(o.pathInfo.path);return void 0!==a?r-a:0},updated(t,e,n){const o=function(t){return Wt.get(t)??zt}(t);for(const r of o){const o=new Set,s={};for(const n of e){if(n.absolutePathInfo.stateElement!==t)continue;const e=n.absolutePathInfo.pathInfo.path;if(-1!==e.indexOf("#"))continue;const a=Et(r.mountPath,r.injections,e);if(null===a||""===a)continue;o.add(a);const i=n.absolutePathInfo.pathInfo.wildcardCount;if(i>0&&null!==n.listIndex){const t=L(n.listIndex,i);(s[a]??=[]).push(t)}}if(o.size>0)try{r.callback.call(Dt(r.mountPath,n,r.injections),Array.from(o),s)}catch(t){console.error(`[@wcstack/state] volume "${r.mountPath}" $updatedCallback threw.`,t)}}},suppressPathDiagnostic:(t,e)=>Nt(!1===t.isConnected?null:t.rootNode??null,e),rowReused(t,e){!function(t,e){if(Q(e))for(const n of Y(e)){if(!te(n.component,t))continue;const e=Z(n);null!==e&&Zt(n,e)}}(e,t)}};let ne=!1;const oe=new WeakMap;function re(t){let e=oe.get(t);return void 0===e&&(e={graftInfo:null,initializing:!1,mountPath:null,slotRootNode:null,detachedFrom:null},oe.set(t,e)),e}function se(t,e){null!==e.slotRootNode&&(!function(t,e,n){const o=At.get(t);o?.get(e)===n&&o.set(e,null)}(e.slotRootNode,e.mountPath,t),e.slotRootNode=null)}function ae(t,e,n){if(e.slotRootNode===n)return!0;const o=e.mountPath;try{xt(n,o,t)}catch{return console.error(`[@wcstack/state] <${P.tagNames.state} mount="${o}"> will not graft: another volume already holds the "${o}" slot on this root. Keep one volume per mount path.`),!1}return V(n)?.markHasVolume?.(),e.slotRootNode=n,!0}async function ie(t,e){const n=t,o=t.connectedRootNode,r=n.getAttribute("mount");let s;try{!function(t){0===t.length&&$('"mount" requires a non-empty tree path.');const e=d(t);for(const n of e.segments)0===n.length&&$(`"mount" path "${t}" has an empty segment.`),n===h&&$(`"mount" path "${t}" must be static (wildcards are not allowed).`),(n.includes("$")||n.includes("#")||n.includes("@"))&&$(`"mount" path "${t}" must not use reserved characters ($, #, @).`)}(r),s=function(t,e){const n=[],o=new Set;for(const r of T(t)){if(r.propSegments[0]!==l)continue;const t=r.propSegments.slice(1),s=r.statePathInfo,a=t=>$(`[wcs/mount-path-invalid] <${P.tagNames.state} mount="${e}"> "${r.propName}: ${r.statePathName}": ${t}`);1===t.length&&t[0]&&t[0]!==h&&"$"!==t[0][0]&&"#"!==t[0][0]||a(`inject one key at a time ("${l}.<key>: path"); change "mount" to move the whole volume.`),(s.wildcardCount>0||"$"===s.path[0]||"#"===s.path[0])&&a("the injected path must be a static path on the root tree (a volume has no loop context)."),(r.inFilters.length>0||r.outFilters.length>0)&&a("an injection takes no filters."),r.propModifiers.some(t=>t!==u)&&a(`an injection accepts only #${u}.`),o.has(t[0])&&a(`"${t[0]}" is injected twice.`),o.add(t[0]),n.push({innerSegments:t,outerPathInfo:s,readonly:r.propModifiers.includes(u)})}return n}(n.getAttribute(P.bindAttributeName)??"",r),n.hasAttribute("bind-component")&&$('"mount" cannot be combined with "bind-component".'),n.hasAttribute("enable-ssr")&&console.warn(`[@wcstack/state] <${P.tagNames.state} mount="${r}"> ignores "enable-ssr" — snapshots are per root tree (the root state element aggregates volume data).`),xt(o,r,t),V(o)?.markHasVolume?.(),e.mountPath=r,e.slotRootNode=o}catch(e){throw t.settleInitialization(),e}e.initializing=!0,null===V(o)&&function(t,e){const n=()=>{if(null!==V(t))return;const n=t.querySelectorAll(P.tagNames.state);for(const t of n)if(!t.hasAttribute("mount")&&!t.hasAttribute("bind-component"))return;console.error(`[@wcstack/state] <${P.tagNames.state} mount="${e}"> has no root state tree to graft onto (D11). A volume mounts onto the root tree — add a root <${P.tagNames.state}> to this root node (an empty <${P.tagNames.state}></${P.tagNames.state}> is enough). If the root is added dynamically later, the graft will still complete and this report can be ignored.`)},o=t.ownerDocument??t;"loading"===o.readyState?o.addEventListener("DOMContentLoaded",()=>queueMicrotask(n),{once:!0}):setTimeout(n,0)}(o,r);const a=n=>{e.graftInfo=n,t.markInitialized(),null===n&&se(t,e),t.settleInitialization()};let i;try{i=await t.loadStateFromSource()}catch(t){return console.error(`[@wcstack/state] volume "${r}" failed to load.`,t),void a(null)}const c=t.connectedRootNode??null;null!==c&&ae(t,e,c)?function(t,e,n,o,r,s,a=[]){const i={mountPath:n,volumeState:o,injections:a,onGrafted:r,acquireSlot:s};if(null!==e)return void Ee(e,i);We(),function(t,e){if(Vt.has(t))return void Bt(e);let n=Lt.get(t);void 0===n&&(n=[],Lt.set(t,n)),n.push(e)}(t,i)}(c,V(c),r,i,a,()=>ae(t,e,c),s):a(null)}const ce={order:20,connecting(t){if(!t.hasAttribute("mount"))return null;const e=re(t);if(e.initializing){const n=t.connectedRootNode;if(null!=n&&e.detachedFrom===n)try{xt(n,e.mountPath,t),V(n)?.markHasVolume?.(),e.slotRootNode=n}catch{}return e.detachedFrom=null,o}return ie(t,e)},reconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=re(t),n=t.connectedRootNode??null;return null!==e.graftInfo&&null!==n&&V(n)===e.graftInfo.rootStateElement&&Re(e.graftInfo,"$connectedCallback"),!0},replacingState(t){if(!0!==oe.get(t)?.initializing)return;const e=t.getAttribute("mount");$(`Cannot replace the state of <${P.tagNames.state} mount="${e}"> after it has loaded: a volume's data is copied into the root tree when it grafts, so a new state would never reach the page. Write the paths under "${e}" on the root state instead.`)},initializeFailed(t,e){!function(t){Vt.add(t);const e=Lt.get(t);if(void 0!==e){Lt.delete(t);for(const t of e)Bt(t)}}(e)},initializeFailureCleared(t,e){!function(t){Vt.delete(t)}(e)},disconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=re(t);return null!==e.graftInfo&&Re(e.graftInfo,"$disconnectedCallback"),!0!==t.initialized&&(e.detachedFrom=e.slotRootNode,se(t,e)),t.clearConnectedRootNode(),!0}};let le=!1;const ue=new WeakMap;function de(t,e){let n=ue.get(t);n||(n=new Set,ue.set(t,n)),n.add(e)}const fe=new WeakMap;const he=new WeakMap,me=new WeakMap;const pe=new WeakMap;const ge={isComplete:function(t,e){return!0===ue.get(t)?.has(e)},isDeclared:function(t,e){return!0===fe.get(t)?.has(e)},rememberOverwrittenObject:function(t,e,n){let o=he.get(t);o||(o=new Map,he.set(t,o)),o.has(e)||o.set(e,n)},recordInjectedKey:function(t,e,n){let o=me.get(t);o||(o=new Map,me.set(t,o));let r=o.get(e);r||(r=new Set,o.set(e,r)),r.add(n)},rememberOverwrittenValue:function(t,e,n,o){let r=pe.get(t);r||(r=new Map,pe.set(t,r));let s=r.get(e);s||(s=new Map,r.set(e,s)),s.has(n)||s.set(n,o)}};function ye(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}const be=new WeakMap;class $e{_innerStateElement;constructor(t,e){this._innerStateElement=function(t,e){const n=be.get(t);return n?n.get(e)??null:null}(t,e)??$("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const we=t=>()=>t;function ve(t,e,n,o){!function(t,e,n){let o=be.get(t);o||(o=new Map,be.set(t,o)),o.set(e,n)}(e,n,t),t.setInitialState(ye(o));const r=function(t,e){const n=new $e(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:we(r),enumerable:!0,configurable:!0}),de(e,n),ke(e,n)}function ke(t,e){if(f in t){const n=t[f];"function"==typeof n?n.call(t,e).catch(t=>{$(`Error in ${f}: ${t instanceof Error?t.message:String(t)}`)}):$(`${f} is not a function.`)}}const Se=new Set;function Pe(t,e){Se.has(t)||(Se.add(t),console.warn(`[@wcstack/state] [wcs/mount-own-key-shadow] ${e} See docs/state-mount-design.md §4-3.`))}function je(t){const e=t.rootEntry,n=I(t.component);if(e.outerPathInfo.wildcardCount>0&&null===n)return;let o;return t.parentStateElement.createState("readonly",t=>{t[A](n,()=>{o=t[e.outerPathInfo.path]})}),o}const Ce=new WeakMap;function Ie(t,e){t.landInitialization(),$(e)}async function Ae(t,e){const n=t;if(n.hasAttribute("bind-component")){const o=n.parentNode,r=o instanceof ShadowRoot?o.host:o instanceof Element?o:null,s=r?_(r):null;null!==r&&null!==s||$(`"bind-component" requires <${P.tagNames.state}> to be a direct child of a custom element.`),o instanceof ShadowRoot||r.hasAttribute(P.bindAttributeName)||Ie(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${n.getAttribute("bind-component")}: path").`);const a=["state","src","json"].filter(t=>n.hasAttribute(t));null!==n.querySelector('script[type="module"]')&&a.push('<script type="module">'),a.length>0&&$(`"bind-component" cannot be combined with ${a.join(", ")}. The component's "${n.getAttribute("bind-component")}" property is the only state source.`);const i=n.getAttribute("bind-component");!function(t,e){let n=fe.get(t);n||(n=new Set,fe.set(t,n)),n.add(e)}(r,i);const c=j(r);null===c&&$(`CustomElementRegistry is unavailable for <${s}>.`),await c.whenDefined(s.toLowerCase()),r.hasAttribute(P.bindAttributeName)&&await q(r),i in r||$(`Component does not have property "${i}" for state binding.`);let l=r[i];"object"==typeof l&&null!==l||$(`Component property "${i}" is not an object for state binding.`);const u=function(t,e){const n=he.get(t);if(!n)return;const o=n.get(e);return n.delete(e),o}(r,i);if(void 0!==u&&function(t,e){if(!t.hasAttribute(P.bindAttributeName))return!1;const n=B(t);if(null===n)return!1;for(const t of n)if(1===t.propSegments.length&&t.propSegments[0]===e)return!0;return!1}(r,i)&&(r[i]=u,l=u),e.boundComponent=r,e.boundComponentStateProp=i,t.setBoundComponent(r,i),o instanceof ShadowRoot||(B(r)??[]).some(t=>t.propSegments[0]===i)||Ie(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${i}: path").`),r.hasAttribute(P.bindAttributeName)){const a=(B(r)??[]).filter(t=>t.propSegments[0]===i);if(a.length>0){const c=V(r.getRootNode())??Ie(t,`No state tree found on this root for mount host <${s}>.`);let u=it(r,i);const d=null!==u;if(null===u&&(function(t,e,n){const o=pe.get(t)?.get(e);if(void 0!==o){for(const[t,e]of o)n[t]=e;pe.get(t).delete(e)}}(r,i,l),u=ct(r,i,a,c,l,function(t,e){return me.get(t)?.get(e)}(r,i)),function(t){const e=Object.keys(t.privateSnapshot);if(0===e.length)return;const n=t.component.tagName.toLowerCase(),o=t.stateProp;let r,s=!1;for(const a of e){if(null===t.rootEntry)continue;if(s||(r=je(t),s=!0),"object"!=typeof r||null===r||!(a in r))continue;const e=t.rootEntry.outerPathInfo.path;Pe(`${n}|${o}|${a}|root`,`<${n}>.${o}.${a} is private and hides the mounted tree key "${e}.${a}" (${o}: ${e}). Remove the default to read the tree, or rename it to keep it private.`)}}(u)),e.mountRecord=u,n.parentNode!==o)return;try{Yt(u,o instanceof ShadowRoot?o:r)}catch(e){throw t.landInitialization(),e}if(!d){const t=Qt(u);Object.defineProperty(r,i,{get:()=>t,enumerable:!0,configurable:!0}),de(r,i)}return ke(r,i),lt(u),void at(u,"$connectedCallback")}}ve(t,e.boundComponent,e.boundComponentStateProp,l)}}const xe={order:30,preparing(t){if(!t.hasAttribute("bind-component"))return null;const e=function(t){let e=Ce.get(t);return void 0===e&&(e={boundComponent:null,boundComponentStateProp:null,mountRecord:null},Ce.set(t,e)),e}(t);return Ae(t,e).then(()=>null!==e.mountRecord&&(t.markInitialized(),t.settleInitialization(),!0))},reconnecting(t){const e=Ce.get(t);if(void 0===e||null===e.mountRecord)return!1;const n=e.mountRecord,o=t.parentNode;return queueMicrotask(()=>{null!=t.connectedRootNode&&Zt(n,o)}),at(n,"$connectedCallback"),!0},disconnecting(t){const e=Ce.get(t);return void 0!==e&&null!==e.mountRecord&&(at(e.mountRecord,"$disconnectedCallback"),Kt(e.mountRecord),t.clearConnectedRootNode(),!0)}};let Ne=!1;function Re(t,e){const n=t.volumeState[e];"function"==typeof n&&t.rootStateElement.createState("writable",o=>{const r=n.call(Dt(t.mountPath,o,t.injections));r instanceof Promise&&r.catch(n=>{console.error(`[@wcstack/state] volume "${t.mountPath}" ${e} failed.`,n)})})}function Me(t,e,n,o){const r=n[m];if(void 0!==r){const n=[],s=new Set;let a=0;for(const[i,c]of Object.entries(r)){const r=Ot(e,o,i,!1),l=function(t,n,...r){c.call(Dt(e,this,o),t,n,...r)};n.push({path:r,pathInfo:d(r),handler:l,order:1e6+a++}),s.add(r),t.setPathInfo(r,"prop","watch")}n.length>0&&(ht(t,n),t.addVolumeWatchPaths?.(s),mt(t))}const s=n[p];if(void 0!==s){const n=new Map;for(const[t,r]of Object.entries(s))n.set(Ot(e,o,t,!1),r);t.mergeVolumeListKeys?.(n)}const a=n[b];"function"==typeof a&&(!function(t,e){let n=Wt.get(t);void 0===n&&(n=[],Wt.set(t,n)),n.push(e),t.markHasVolume?.()}(t,{mountPath:e,injections:o,callback:a}),t.enableUpdatedCallback?.());for(const t of["$commandTokens","$eventTokens","$on","$errorCallback"])void 0!==n[t]&&console.warn(`[@wcstack/state] volume "${e}" declares ${t}, which volumes do not support. Declare it on the root state instead.`)}function Oe(t,e,n,o=[]){!function(t,e,n,o){for(const t of o){const o=t.innerSegments[0],r=Object.getOwnPropertyDescriptor(n,o);void 0===r||"function"!=typeof r.get&&"function"!=typeof r.set&&"function"!=typeof r.value||$(`Volume "${e}" declares "${o}" as an accessor or a method and also injects it ("${l}.${o}: ${t.outerPathInfo.path}"). Rename one of them.`)}const r=n[m];if(void 0!==r){"object"==typeof r&&null!==r||$(`${m} must be an object mapping state paths to handler functions.`);for(const[t,e]of Object.entries(r))"function"!=typeof e&&$(`${m} entry "${t}" must be a function.`),ft(t)}const s=n[p];if(void 0!==s){"object"==typeof s&&null!==s||$(`${p} must be an object mapping list paths to key specs.`);for(const[n,r]of Object.entries(s)){(0===n.length||"string"!=typeof r&&"function"!=typeof r)&&$(`${p} entry "${n}" must map a list path to a field name or a key function.`);const s=Ot(e,o,n,!1);t.listKeys?.has(s)&&$(`${p} entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`)}}void 0!==n.$streams&&$(`Volume "${e}" declares $streams, which volumes do not support yet. Declare the stream on the root state.`),void 0!==n.$scan&&$(`Volume "${e}" declares $scan, which volumes do not support yet. Declare the scan on the root state.`),void 0!==n[g]&&$(`Volume "${e}" declares ${g}, which volumes do not support yet. Declare the recursion anchor on the root state — the anchor path is resolved against the root tree.`);for(const t of Object.keys(k(n)))-1!==t.indexOf(y)&&$(`Volume "${e}" declares "${t}", which uses "${y}". Volumes do not support recursive getters yet — declare them on the root state.`)}(t,e,n,o);const{data:r,accessors:s}=function(t,e){const n={},o=new Map;for(const[r,s]of Object.entries(Object.getOwnPropertyDescriptors(t)))r.startsWith("$")||e.has(r)||("function"!=typeof s.get&&"function"!=typeof s.set?"function"!=typeof s.value&&(n[r]=s.value):o.set(r,s));return{data:n,accessors:o}}(n,new Set(o.map(t=>t.innerSegments[0]))),a=d(e),i=!0===t.hydratedFromSsr;t.createState("writable",t=>{if(1===a.segments.length&&e in t){if(i)return;$(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}let n="";for(let e=0;e<a.segments.length-1;e++){const o=a.segments[e],r=""===n?o in t:void 0!==t[n+c+o];n=""===n?o:n+c+o,r||(t[n]={})}if(a.segments.length>1&&void 0!==t[e]){if(i)return;$(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}t[e]=r}),function(t,e){let n=Rt.get(t);void 0===n&&(n=new Set,Rt.set(t,n)),n.add(e)}(t,e),t.markHasGraftedVolumes?.();for(const[n,r]of s){const s=e+c+n,a=r.get,i=r.set,l={enumerable:!1,configurable:!0};"function"==typeof a&&(l.get=function(){return a.call(Dt(e,this,o))}),"function"==typeof i&&(l.set=function(t){i.call(Dt(e,this,o),t)}),t.defineTreeAccessor(s,l)}Me(t,e,n,o);const u=n.$connectedCallback;return"function"==typeof u&&t.createState("writable",t=>{let n;try{n=u.call(Dt(e,t,o))}catch(t){return void console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)}n instanceof Promise&&n.catch(t=>{console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)})}),{rootStateElement:t,mountPath:e,volumeState:n,injections:o}}function Ee(t,e){if(!e.acquireSlot())return void e.onGrafted(null);let n=null;try{n=Oe(t,e.mountPath,e.volumeState,e.injections)}catch(t){console.error(`[@wcstack/state] volume "${e.mountPath}" failed to graft.`,t)}finally{e.onGrafted(n)}}let De=!1;function We(){De||(De=!0,ne||(ne=!0,v("scopes",ee)),le||(le=!0,t("scopes",ce)),Ne||(Ne=!0,t("bindComponent",xe),F(ge)),Ft=Ee,U(ze))}function ze(t,e){(function(t){const e=At.get(t);return void 0!==e&&e.size>0})(t)&&e.markHasVolume?.(),function(t,e){Vt.delete(t);const n=Lt.get(t);if(void 0===n||0===n.length||null===Ft)return;Lt.delete(t);const o=Ft;queueMicrotask(()=>{for(const t of n)o(e,t)})}(t,e)}const Le={name:"scopes",install(){We(),It||(It=!0,t("dcc",Ct))}};export{Le as default,Le as scopes};
|
|
1
|
+
import{r as t,l as e,a as n,C as o}from"../chunks/lifecycleHooks.js";import{f as r,h as s,a,i,D as c,V as l,j as u,g as d,k as f,W as h,l as m,m as p,n as g,R as y,o as b}from"../chunks/pathDiagnostics.js";import{r as w,d as $}from"../chunks/errorGuidance.js";import{a as v,g as k,N as S}from"../chunks/getAllPropertyDescriptors.js";import{c as P}from"../chunks/filterRegistry.js";import{n as j}from"../chunks/declarationAliases.js";import{h as C,u as I,i as A,j as x,k as N,m as R,n as M,o as O,p as E,q as D,t as W,v as z,w as L,x as V,y as B,z as F,A as _,B as q,C as T,D as U,E as H}from"../chunks/binder.js";import{f as K,t as G,a as X,b as J,c as Q,s as Y,g as Z,d as tt,e as et,r as nt,h as ot,i as rt,j as st,k as at,l as it,m as ct,n as lt,w as ut}from"../chunks/mount.js";import{p as dt}from"../chunks/diagnosticsHooks.js";import{c as ft}from"../chunks/checkDependency.js";import{y as ht,z as mt,A as pt}from"../chunks/watchRuntime.js";const gt={written:function(t,e,n){const o=t.bindableEventMap,r=o[e.path],s="string"==typeof r,a=s?r:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof a)return;const i=t.rootNode;i instanceof ShadowRoot&&i.host.dispatchEvent(new CustomEvent(a,{detail:s&&void 0!==n?n.value:void 0,bubbles:!0}))}};let yt=!1;function bt(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function wt(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function $t(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function vt(t){return t.startsWith("$")}function kt(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function St(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||w(`${e} must be an array of strings.`);const o=[],r=new Set;for(const t of n)"string"==typeof t&&0!==t.length||w(`${e} entries must be non-empty strings.`),t.startsWith("$")&&w(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),r.has(t)&&w(`${e} entry "${t}" is duplicated.`),r.add(t),o.push(t);return o}function Pt(t){j(t);const e=St(t,r)??[],n=St(t,s)??[],o=k(t),i=function(t){const e=t[a];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),c=[];for(const t of e){const e=o[t];if(void 0===e){if(i.has(t)){c.push(t);continue}w(`${r} entry "${t}" is not declared on the state.${$(t,kt(o,"value"))}`)}"function"==typeof e.value&&w(`${r} entry "${t}" is a method. Declare it in ${s} instead.`)}for(const t of n){const e=o[t];void 0===e&&w(`${s} entry "${t}" is not declared on the state.${$(t,kt(o,"method"))}`),"function"!=typeof e.value&&w(`${s} entry "${t}" is not a method. Declare it in ${r} instead.`)}return{bindables:e,commands:n,streamBackedBindables:c}}function jt(t,e,n){const o=t.tagName.toLowerCase();o.includes("-")||w(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`);const s=C(t);null!==s&&"function"==typeof s.define||w(`DCC: CustomElementRegistry is unavailable for "${o}".`),s.get(o)&&w(`DCC: "${o}" is already registered. A custom element name can only be defined once.`);const a=document.createElement("template"),c=a.content.ownerDocument;for(const t of Array.from(e.childNodes))a.content.appendChild(c.importNode(t,!0));const l=e.mode,{bindables:u,commands:d,streamBackedBindables:f}=Pt(n),h=u.length>0||d.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const r=n.map(t=>({name:t,async:!0}));return{...o,commands:r}}(o,u,d):null,m=u.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(o,u):{},p=P.tagNames.state,g=class extends HTMLElement{static template=a;static shadowRootMode=l;static wcBindable=h;static bindableEventMap=m;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(i))return null;this._shadow=this.attachShadow({mode:g.shadowRootMode}),this._shadow.appendChild(g.template.content.cloneNode(!0));const t=C(this._shadow);return null!==t&&I(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(g.bindableEventMap).length>0){const e=t.querySelector(p);e?(yt||(yt=!0,v("dcc",gt)),e.setBindableEventMap(g.bindableEventMap)):console.warn(`[@wcstack/state] DCC: "${o}" declares ${r} but its template has no <${P.tagNames.state}>. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(p)??null}},y=k(n);for(const[t,e]of Object.entries(y)){if(vt(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=$t(t,o)}else n.get=bt(t),n.set=wt(t);Object.defineProperty(g.prototype,t,n)}for(const t of f)Object.defineProperty(g.prototype,t,{configurable:!0,enumerable:!0,get:bt(t),set:wt(t)});s.define(o,g)}async function Ct(t,o,r){const s=t;try{s.hasAttribute("bind-component")&&w(`"bind-component" cannot be used inside a [${i}] host. DCC state comes from the template, not from a component property.`);const a=await async function(t,o){try{if(t.hasAttribute("src")){const n=t.getAttribute("src");if(n.endsWith(".js"))return await e(n);w(`DCC: Unsupported src type: ${n}`)}const r=t.querySelector('script[type="module"]');if(r)return await n(r,o.tagName.toLowerCase());w(`DCC: No state source found for "${o.tagName.toLowerCase()}".`)}catch(t){w(`DCC: Failed to load state: ${t}`)}}(s,o);jt(o,r,a),t.markTreeless(),t.markInitialized(),t.clearConnectedRootNode(),t.settleInitialization()}catch(e){t.failInitializeLoudly(e)}}const It={order:10,connecting(t){const e=t.parentNode;return e instanceof ShadowRoot&&e.host.hasAttribute(i)?Ct(t,e.host,e):null}};let At=!1;const xt=new WeakMap;function Nt(t,e,n){let o=xt.get(t);void 0===o&&(o=new Map,xt.set(t,o));const r=o.get(e);null!=r&&w(`Volume slot "${e}" is already mounted on this tree.`),o.set(e,n)}function Rt(t,e){if(null===t)return!1;const n=xt.get(t);if(void 0===n||0===n.size)return!1;for(const t of n.keys())if(e===t||e.startsWith(t+c)||t.startsWith(e+c))return!0;return!1}const Mt=new WeakMap;const Ot=[];function Et(t,e,n,o){if(e.length>0){const r=n.split(c),s=K(e,r);if(null!==s)return o&&s.readonly&&w(`[wcs/mount-readonly] volume "${t}" cannot write "${n}": it is injected read-only ("${l}.${s.innerSegments.join(c)}#${u}: ${s.outerPathInfo.path}"). Write "${s.outerPathInfo.path}" on the root, or drop #${u} from the injection.`),G(s,r)}return t+c+n}function Dt(t,e,n){for(const t of e){const e=t.outerPathInfo.path;if(n===e)return t.innerSegments.join(c);if(n.startsWith(e+c))return t.innerSegments.join(c)+n.slice(e.length)}return n===t?"":n.startsWith(t+c)?n.slice(t.length+1):null}function Wt(t,e,n=Ot){return new Proxy({},{get(o,r){if("string"==typeof r&&"then"!==r){if("$"===r[0]){if("$postUpdate"===r||"$getAll"===r){const o=r;return(r,...s)=>e[o](Et(t,n,r,!1),...s)}return"$setAll"===r?(o,...r)=>e.$setAll(Et(t,n,o,!0),...r):"$resolve"===r?(o,...r)=>e.$resolve(Et(t,n,o,r.length>1),...r):e[r]}return e[Et(t,n,r,!1)]}},set:(o,r,s)=>("string"!=typeof r||(e[Et(t,n,r,!0)]=s),!0),has:(t,e)=>"string"==typeof e&&"$"!==e[0]&&"#"!==e[0]})}const zt=new WeakMap,Lt=[];const Vt=new WeakMap,Bt=new WeakSet;function Ft(t){console.error(`[@wcstack/state] volume "${t.mountPath}" was not grafted — the root state element on this root node failed to initialize (its own diagnostic is reported separately). The volume is not at fault: fix the root <wcs-state>.`),t.onGrafted(null)}let _t=null;const qt=new WeakMap,Tt=new Set;function Ut(t,e,n,o){let r=qt.get(t);if(void 0===r){if(!o)return null;r=new Map,qt.set(t,r)}let s=r.get(e);if(void 0===s){if(!o)return null;s=new Map,r.set(e,s)}let a=s.get(n);if(void 0===a){if(!o)return null;a={holders:new Set,byListIndex:new WeakMap,noIndex:null},s.set(n,a)}return a}function Ht(t,e){if(!t.component.isConnected)return!1;const n=A(t.component)?.listIndex??null;if(null===e)return null===n;let o=n;for(;null!==o;){if(o===e)return!0;o=o.parentListIndex}return!1}function Kt(t,e,n,o){const r=Ut(t,e,n,!1);if(null===r)return null;const s=null===o?r.noIndex:r.byListIndex.get(o)??null;if(null!==s){const t=function(t,e){const n=t.ref.deref();return void 0!==n&&Ht(n,e)?n:null}(s,o);if(null!==t)return{record:t,entry:s.entry}}let a=null,i=null;for(const t of r.holders){const s=t.ref.deref();void 0!==s?Ht(s,o)&&(null!==i&&w(`[wcs/mount-export-ambiguous] "${e}${c}${n}" is exported by two mounted components on the same instance: <${i.component.tagName.toLowerCase()}> and <${s.component.tagName.toLowerCase()}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),a=t,i=s):r.holders.delete(t)}return null===a||null===i?null:(null===o?r.noIndex=a:r.byListIndex.set(o,a),{record:i,entry:a.entry})}function Gt(t){const e=t.parentStateElement,n=A(t.component);if(!(!1===e.isConnected||t.delta>0&&null===n))for(const o of t.exports.values())e.createState("readonly",t=>{t[x](n,()=>{t.$postUpdate(o.exportedPath)})})}const Xt=new WeakMap;class Jt{record;markerParentPath;listIndex;isBase;receiver;handler;constructor(t,e,n,o,r,s){this.record=t,this.markerParentPath=e,this.listIndex=n,this.isBase=o,this.receiver=r,this.handler=s}accessorNameFor(t){return this.record.accessorBySuffixByMarkerParent.get(this.markerParentPath)?.get(t)?.accessorName}accessorAddress(t){return N(d(this.markerParentPath+c+t),this.listIndex)}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e);if("then"===e)return;if("$"===e[0]){if("$postUpdate"===e)return t=>{this.receiver.$postUpdate(X(this.record,t))};if("$getAll"===e||"$setAll"===e||"$resolve"===e){const t=this.record,n=this.listIndex?.indexes??[],o=this.receiver;if("$resolve"===e)return(e,r,...s)=>{const a=s.length>0?J(t,e):X(t,e),i=Q(t,e,a,r??[],n);return o.$resolve(a,i,...s)};const r=e;return(e,s,...a)=>{const i="$setAll"===r?J(t,e):X(t,e),c=Q(t,e,i,s,n);return o[r](i,c,...a)}}return this.receiver[e]}const o=this.accessorNameFor(e);if(void 0!==o){this.handler.pushAddress(this.accessorAddress(e));try{return Reflect.get(this.record.stateObject,o,n)}finally{this.handler.popAddress()}}if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return ft(this.handler,this.accessorAddress(e)),t[e];const o=this.record.stateObject[e];if("function"==typeof o)return o.bind(n)}return this.receiver[X(this.record,e)]}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n);const r=this.accessorNameFor(e);if(void 0!==r){this.record.setterKeys.has(r)||w(`Cannot write to "${r}" on mounted <${this.record.component.tagName.toLowerCase()}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),this.handler.pushAddress(this.accessorAddress(e)),this.handler.beginUntrack();try{return Reflect.set(this.record.stateObject,r,n,o)}finally{this.handler.endUntrack(),this.handler.popAddress()}}return this.isBase&&Object.prototype.hasOwnProperty.call(t,e)?(t[e]=n,!0):(this.receiver[J(this.record,e)]=n,!0)}has(t,e){if("string"!=typeof e)return Reflect.has(t,e);if("$"===e[0]||"#"===e[0])return!1;if(void 0!==this.accessorNameFor(e))return!0;if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return!0;if("function"==typeof this.record.stateObject[e])return!0}try{return X(this.record,e),!0}catch{return!1}}}function Qt(t,e,n,o){const r=e.pathInfo.path,s=r===t.markerBasePath,a=s?function(t,e){let n=Xt.get(t);if(void 0===n&&(n={byListIndex:new WeakMap,noIndex:null},Xt.set(t,n)),null===e)return n.noIndex??={...t.privateSnapshot};let o=n.byListIndex.get(e);return void 0===o&&(o={...t.privateSnapshot},n.byListIndex.set(e,o)),o}(t,e.listIndex):{};return new Proxy(a,new Jt(t,r,e.listIndex,s,n,o))}function Yt(t){const e=t.parentStateElement,n=(e,n)=>{const o=A(t.component);let r;return e[x](o,()=>{r=n()}),r};return new Proxy({},{get(o,r){if("string"!=typeof r||"then"===r)return;if("$getAll"===r||"$setAll"===r||"$resolve"===r||"$postUpdate"===r)return function(t,e,n){const o=t.parentStateElement,r=(t,e)=>{let r;return o.createState(t,t=>{r=n(t,()=>e(t))}),r};return"$postUpdate"===e?e=>r("readonly",n=>n.$postUpdate(X(t,e))):(n,o,...s)=>{const a="$setAll"===e||"$resolve"===e&&s.length>0,i=a?J(t,n):X(t,n),c=A(t.component)?.listIndex.indexes??[],l=Q(t,n,i,"$resolve"===e?o??[]:o,c);return r(a?"writable":"readonly",t=>t[e](i,l,...s))}}(t,r,n);let s;return e.createState("readonly",e=>{s=n(e,()=>e["$"===r[0]?r:X(t,r)])}),s},set:(o,r,s)=>("string"!=typeof r||e.createState("writable",e=>{n(e,()=>{e["$"===r[0]?r:J(t,r)]=s})}),!0),has(e,n){if("string"!=typeof n||"$"===n[0]||"#"===n[0])return!1;if(Object.prototype.hasOwnProperty.call(t.stateObject,n))return!0;try{return X(t,n),!0}catch{return!1}}})}function Zt(t,e){const n=et(e);null!==n&&n.stateProp!==t.stateProp&&w(`A mount scope is already initialized on this component for "${n.stateProp}" — one <wcs-state bind-component> per component (v2). Merge the "${t.stateProp}" wiring into "${n.stateProp}" or split the component.`),null!==n&&R(e).dispose(),nt(e,t),e instanceof ShadowRoot&&E(e,t.parentStateElement),function(t,e){const n=(e,n)=>ot(t,e,n);W(e);const o=A(t.component),r=e instanceof ShadowRoot?e:e.getRootNode();z(r,e,void 0,n),L(e,o,n)}(t,e),function(t){if(t.exports.size>0||null===t.rootEntry)return;const e=new Set([...t.getterKeys,...t.setterKeys]);for(const n of e){let e;try{e=X(t,n)}catch{continue}const o=e.indexOf(c+t.marker);if(-1===o)continue;const r=e.slice(0,o+1+t.marker.length),s=e.slice(r.length+1),a=e.slice(0,o)+c+s,i=d(a);if(i.wildcardCount!==t.delta)continue;const l={markerTerminalPath:r,suffix:s,markerPath:e,exportedPath:a};t.exports.set(a,l),Ut(t.parentStateElement,i.parentPath,i.lastSegment,!0).holders.add({ref:new WeakRef(t),entry:l}),t.parentStateElement.addDynamicDependency(e,a),dt?.markExported(t.parentStateElement,a)}t.parentStateElement.markHasMounts?.()}(t),function(t){const e=A(t.component);if(t.delta>0&&null===e)return;const n=t.component.tagName.toLowerCase();for(const o of t.exports.values()){const r=`${n}|${o.exportedPath}`;if(Tt.has(r))continue;const s=d(o.exportedPath);let a;t.parentStateElement.createState("readonly",t=>{t[x](e,()=>{a=t[s.parentPath]})}),null!=a&&s.lastSegment in Object(a)&&(Tt.add(r),console.warn(`[@wcstack/state] [wcs/mount-export-shadowed] <${n}>.${t.stateProp}.${o.suffix} is exported at "${o.exportedPath}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`))}}(t),Gt(t),D(e,Promise.resolve())}function te(t,e){const n=R(e),o=A(t.component);n.forEachActiveBindingNode(t=>M(t,o));const r=n.rebindAddresses();O(r),Gt(t)}function ee(t,e){for(let n=e.firstNode;null!==n;n=n.nextSibling){if(n===t||n.contains(t))return!0;if(n===e.lastNode)break}return!1}const ne={read(t,e,n,o){if(!0===t.hasMounts&&35===e.pathInfo.lastSegment.charCodeAt(0)){const r=st(t,e.pathInfo.path);if(null!==r)return Qt(r,e,n,o)}return S},readMissing(t,e,n,o,r){if(null===n){if(Rt(t.rootNode??null,e.pathInfo.path))return;return S}if(!0===t.hasMounts){const n=Kt(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r){const s=Qt(t,N(d(e.markerTerminalPath),n),o,r);return Reflect.get(s,e.suffix)}(n.record,n.entry,e.listIndex,o,r)}return S},write(t,e){if(!0===t.hasGraftedVolumes){const n=e.pathInfo.path,o=function(t,e){const n=Mt.get(t);if(void 0===n||0===n.size)return null;const o=e+c;for(const t of n)if(t.startsWith(o))return t;return null}(t,n);null!==o&&w(`Cannot replace "${n}" wholesale: a volume is mounted at "${o}" under it (D22). Replacing an ancestor of a mount point silently discards the grafted data while its accessors remain. Write "${o}" itself, or individual fields inside "${n}", instead.`)}return S},writeMissing(t,e,n,o,r,s,a){if(!0===t.hasMounts){const n=Kt(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r,s){const a=Qt(t,N(d(e.markerTerminalPath),n),r,s);return Reflect.set(a,e.suffix,o)}(n.record,n.entry,e.listIndex,r,s,a)}return S},indexShift(t,e){const n=t.stateElement,o=e.pathInfo.path;if(!0===n.hasMounts&&-1!==o.indexOf("#")){const t=st(n,o);if(null!==t)return at(t,o)}return 0},handlerScope(t,e,n,o,r){if(!0!==t.hasMounts)return r;const s=rt(e,n);if(null===s)return r;const a=s.indexShiftByLoopElementPath.get(o.pathInfo.path);return void 0!==a?r-a:0},updated(t,e,n){const o=function(t){return zt.get(t)??Lt}(t);for(const r of o){const o=new Set,s={};for(const n of e){if(n.absolutePathInfo.stateElement!==t)continue;const e=n.absolutePathInfo.pathInfo.path;if(-1!==e.indexOf("#"))continue;const a=Dt(r.mountPath,r.injections,e);if(null===a||""===a)continue;o.add(a);const i=n.absolutePathInfo.pathInfo.wildcardCount;if(i>0&&null!==n.listIndex){const t=V(n.listIndex,i);(s[a]??=[]).push(t)}}if(o.size>0)try{r.callback.call(Wt(r.mountPath,n,r.injections),Array.from(o),s)}catch(t){console.error(`[@wcstack/state] volume "${r.mountPath}" $updatedCallback threw.`,t)}}},suppressPathDiagnostic:(t,e)=>Rt(!1===t.isConnected?null:t.rootNode??null,e),rowReused(t,e){!function(t,e){if(Y(e))for(const n of Z(e)){if(!ee(n.component,t))continue;const e=tt(n);null!==e&&te(n,e)}}(e,t)}};let oe=!1;const re=new WeakMap;function se(t){let e=re.get(t);return void 0===e&&(e={graftInfo:null,initializing:!1,mountPath:null,slotRootNode:null,detachedFrom:null},re.set(t,e)),e}function ae(t,e){null!==e.slotRootNode&&(!function(t,e,n){const o=xt.get(t);o?.get(e)===n&&o.set(e,null)}(e.slotRootNode,e.mountPath,t),e.slotRootNode=null)}function ie(t,e,n){if(e.slotRootNode===n)return!0;const o=e.mountPath;try{Nt(n,o,t)}catch{return console.error(`[@wcstack/state] <${P.tagNames.state} mount="${o}"> will not graft: another volume already holds the "${o}" slot on this root. Keep one volume per mount path.`),!1}return B(n)?.markHasVolume?.(),e.slotRootNode=n,!0}async function ce(t,e){const n=t,o=t.connectedRootNode,r=n.getAttribute("mount");let s;try{!function(t){0===t.length&&w('"mount" requires a non-empty tree path.');const e=d(t);for(const n of e.segments)0===n.length&&w(`"mount" path "${t}" has an empty segment.`),n===h&&w(`"mount" path "${t}" must be static (wildcards are not allowed).`),(n.includes("$")||n.includes("#")||n.includes("@"))&&w(`"mount" path "${t}" must not use reserved characters ($, #, @).`)}(r),s=function(t,e){const n=[],o=new Set;for(const r of U(t)){if(r.propSegments[0]!==l)continue;const t=r.propSegments.slice(1),s=r.statePathInfo,a=t=>w(`[wcs/mount-path-invalid] <${P.tagNames.state} mount="${e}"> "${r.propName}: ${r.statePathName}": ${t}`);1===t.length&&t[0]&&t[0]!==h&&"$"!==t[0][0]&&"#"!==t[0][0]||a(`inject one key at a time ("${l}.<key>: path"); change "mount" to move the whole volume.`),(s.wildcardCount>0||"$"===s.path[0]||"#"===s.path[0])&&a("the injected path must be a static path on the root tree (a volume has no loop context)."),(r.inFilters.length>0||r.outFilters.length>0)&&a("an injection takes no filters."),r.propModifiers.some(t=>t!==u)&&a(`an injection accepts only #${u}.`),o.has(t[0])&&a(`"${t[0]}" is injected twice.`),o.add(t[0]),n.push({innerSegments:t,outerPathInfo:s,readonly:r.propModifiers.includes(u)})}return n}(n.getAttribute(P.bindAttributeName)??"",r),n.hasAttribute("bind-component")&&w('"mount" cannot be combined with "bind-component".'),n.hasAttribute("enable-ssr")&&console.warn(`[@wcstack/state] <${P.tagNames.state} mount="${r}"> ignores "enable-ssr" — snapshots are per root tree (the root state element aggregates volume data).`),Nt(o,r,t),B(o)?.markHasVolume?.(),e.mountPath=r,e.slotRootNode=o}catch(e){throw t.settleInitialization(),e}e.initializing=!0,null===B(o)&&function(t,e){const n=()=>{if(null!==B(t))return;const n=t.querySelectorAll(P.tagNames.state);for(const t of n)if(!t.hasAttribute("mount")&&!t.hasAttribute("bind-component"))return;console.error(`[@wcstack/state] <${P.tagNames.state} mount="${e}"> has no root state tree to graft onto (D11). A volume mounts onto the root tree — add a root <${P.tagNames.state}> to this root node (an empty <${P.tagNames.state}></${P.tagNames.state}> is enough). If the root is added dynamically later, the graft will still complete and this report can be ignored.`)},o=t.ownerDocument??t;"loading"===o.readyState?o.addEventListener("DOMContentLoaded",()=>queueMicrotask(n),{once:!0}):setTimeout(n,0)}(o,r);const a=n=>{e.graftInfo=n,t.markInitialized(),null===n&&ae(t,e),t.settleInitialization()};let i;try{i=await t.loadStateFromSource()}catch(t){return console.error(`[@wcstack/state] volume "${r}" failed to load.`,t),void a(null)}const c=t.connectedRootNode??null;null!==c&&ie(t,e,c)?function(t,e,n,o,r,s,a=[]){const i={mountPath:n,volumeState:o,injections:a,onGrafted:r,acquireSlot:s};if(null!==e)return void De(e,i);ze(),function(t,e){if(Bt.has(t))return void Ft(e);let n=Vt.get(t);void 0===n&&(n=[],Vt.set(t,n)),n.push(e)}(t,i)}(c,B(c),r,i,a,()=>ie(t,e,c),s):a(null)}const le={order:20,connecting(t){if(!t.hasAttribute("mount"))return null;const e=se(t);if(e.initializing){const n=t.connectedRootNode;if(null!=n&&e.detachedFrom===n)try{Nt(n,e.mountPath,t),B(n)?.markHasVolume?.(),e.slotRootNode=n}catch{}return e.detachedFrom=null,o}return ce(t,e)},reconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=se(t),n=t.connectedRootNode??null;return null!==e.graftInfo&&null!==n&&B(n)===e.graftInfo.rootStateElement&&Me(e.graftInfo,"$connectedCallback"),!0},replacingState(t){if(!0!==re.get(t)?.initializing)return;const e=t.getAttribute("mount");w(`Cannot replace the state of <${P.tagNames.state} mount="${e}"> after it has loaded: a volume's data is copied into the root tree when it grafts, so a new state would never reach the page. Write the paths under "${e}" on the root state instead.`)},initializeFailed(t,e){!function(t){Bt.add(t);const e=Vt.get(t);if(void 0!==e){Vt.delete(t);for(const t of e)Ft(t)}}(e)},initializeFailureCleared(t,e){!function(t){Bt.delete(t)}(e)},disconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=se(t);return null!==e.graftInfo&&Me(e.graftInfo,"$disconnectedCallback"),!0!==t.initialized&&(e.detachedFrom=e.slotRootNode,ae(t,e)),t.clearConnectedRootNode(),!0}};let ue=!1;const de=new WeakMap;function fe(t,e){let n=de.get(t);n||(n=new Set,de.set(t,n)),n.add(e)}const he=new WeakMap;const me=new WeakMap,pe=new WeakMap;const ge=new WeakMap;const ye={isComplete:function(t,e){return!0===de.get(t)?.has(e)},isDeclared:function(t,e){return!0===he.get(t)?.has(e)},rememberOverwrittenObject:function(t,e,n){let o=me.get(t);o||(o=new Map,me.set(t,o)),o.has(e)||o.set(e,n)},recordInjectedKey:function(t,e,n){let o=pe.get(t);o||(o=new Map,pe.set(t,o));let r=o.get(e);r||(r=new Set,o.set(e,r)),r.add(n)},rememberOverwrittenValue:function(t,e,n,o){let r=ge.get(t);r||(r=new Map,ge.set(t,r));let s=r.get(e);s||(s=new Map,r.set(e,s)),s.has(n)||s.set(n,o)}};function be(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}const we=new WeakMap;class $e{_innerStateElement;constructor(t,e){this._innerStateElement=function(t,e){const n=we.get(t);return n?n.get(e)??null:null}(t,e)??w("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const ve=t=>()=>t;function ke(t,e,n,o){!function(t,e,n){let o=we.get(t);o||(o=new Map,we.set(t,o)),o.set(e,n)}(e,n,t),t.setInitialState(be(o));const r=function(t,e){const n=new $e(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:ve(r),enumerable:!0,configurable:!0}),fe(e,n),Se(e,n)}function Se(t,e){if(f in t){const n=t[f];"function"==typeof n?n.call(t,e).catch(t=>{w(`Error in ${f}: ${t instanceof Error?t.message:String(t)}`)}):w(`${f} is not a function.`)}}const Pe=new Set;function je(t,e){Pe.has(t)||(Pe.add(t),console.warn(`[@wcstack/state] [wcs/mount-own-key-shadow] ${e} See docs/state-mount-design.md §4-3.`))}function Ce(t){const e=t.rootEntry,n=A(t.component);if(e.outerPathInfo.wildcardCount>0&&null===n)return;let o;return t.parentStateElement.createState("readonly",t=>{t[x](n,()=>{o=t[e.outerPathInfo.path]})}),o}const Ie=new WeakMap;function Ae(t,e){t.landInitialization(),w(e)}async function xe(t,e){const n=t;if(n.hasAttribute("bind-component")){const o=n.parentNode,r=o instanceof ShadowRoot?o.host:o instanceof Element?o:null,s=r?q(r):null;null!==r&&null!==s||w(`"bind-component" requires <${P.tagNames.state}> to be a direct child of a custom element.`),o instanceof ShadowRoot||r.hasAttribute(P.bindAttributeName)||Ae(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${n.getAttribute("bind-component")}: path").`);const a=["state","src","json"].filter(t=>n.hasAttribute(t));null!==n.querySelector('script[type="module"]')&&a.push('<script type="module">'),a.length>0&&w(`"bind-component" cannot be combined with ${a.join(", ")}. The component's "${n.getAttribute("bind-component")}" property is the only state source.`);const i=n.getAttribute("bind-component");!function(t,e){let n=he.get(t);n||(n=new Set,he.set(t,n)),n.add(e)}(r,i);const c=C(r);null===c&&w(`CustomElementRegistry is unavailable for <${s}>.`),await c.whenDefined(s.toLowerCase()),r.hasAttribute(P.bindAttributeName)&&await T(r),i in r||w(`Component does not have property "${i}" for state binding.`);let l=r[i];"object"==typeof l&&null!==l||w(`Component property "${i}" is not an object for state binding.`);const u=function(t,e){const n=me.get(t);if(!n)return;const o=n.get(e);return n.delete(e),o}(r,i);if(void 0!==u&&function(t,e){if(!t.hasAttribute(P.bindAttributeName))return!1;const n=F(t);if(null===n)return!1;for(const t of n)if(1===t.propSegments.length&&t.propSegments[0]===e)return!0;return!1}(r,i)&&(r[i]=u,l=u),e.boundComponent=r,e.boundComponentStateProp=i,t.setBoundComponent(r,i),o instanceof ShadowRoot||(F(r)??[]).some(t=>t.propSegments[0]===i)||Ae(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${i}: path").`),r.hasAttribute(P.bindAttributeName)){const a=(F(r)??[]).filter(t=>t.propSegments[0]===i);if(a.length>0){const c=B(r.getRootNode())??Ae(t,`No state tree found on this root for mount host <${s}>.`);let u=ct(r,i);const d=null!==u;if(null===u&&(function(t,e,n){const o=ge.get(t)?.get(e);if(void 0!==o){for(const[t,e]of o)n[t]=e;ge.get(t).delete(e)}}(r,i,l),u=lt(r,i,a,c,l,function(t,e){return pe.get(t)?.get(e)}(r,i)),function(t){const e=Object.keys(t.privateSnapshot);if(0===e.length)return;const n=t.component.tagName.toLowerCase(),o=t.stateProp;let r,s=!1;for(const a of e){if(null===t.rootEntry)continue;if(s||(r=Ce(t),s=!0),"object"!=typeof r||null===r||!(a in r))continue;const e=t.rootEntry.outerPathInfo.path;je(`${n}|${o}|${a}|root`,`<${n}>.${o}.${a} is private and hides the mounted tree key "${e}.${a}" (${o}: ${e}). Remove the default to read the tree, or rename it to keep it private.`)}}(u)),e.mountRecord=u,n.parentNode!==o)return;try{Zt(u,o instanceof ShadowRoot?o:r)}catch(e){throw t.landInitialization(),e}if(!d){const t=Yt(u);Object.defineProperty(r,i,{get:()=>t,enumerable:!0,configurable:!0}),fe(r,i)}return Se(r,i),ut(u),void it(u,"$connectedCallback")}}ke(t,e.boundComponent,e.boundComponentStateProp,l)}}const Ne={order:30,preparing(t){if(!t.hasAttribute("bind-component"))return null;const e=function(t){let e=Ie.get(t);return void 0===e&&(e={boundComponent:null,boundComponentStateProp:null,mountRecord:null},Ie.set(t,e)),e}(t);return xe(t,e).then(()=>null!==e.mountRecord&&(t.markInitialized(),t.settleInitialization(),!0))},reconnecting(t){const e=Ie.get(t);if(void 0===e||null===e.mountRecord)return!1;const n=e.mountRecord,o=t.parentNode;return queueMicrotask(()=>{null!=t.connectedRootNode&&te(n,o)}),it(n,"$connectedCallback"),!0},disconnecting(t){const e=Ie.get(t);return void 0!==e&&null!==e.mountRecord&&(it(e.mountRecord,"$disconnectedCallback"),Gt(e.mountRecord),t.clearConnectedRootNode(),!0)}};let Re=!1;function Me(t,e){const n=t.volumeState[e];"function"==typeof n&&t.rootStateElement.createState("writable",o=>{const r=n.call(Wt(t.mountPath,o,t.injections));r instanceof Promise&&r.catch(n=>{console.error(`[@wcstack/state] volume "${t.mountPath}" ${e} failed.`,n)})})}function Oe(t,e,n,o){const r=n[m];if(void 0!==r){const n=[],s=new Set;let a=0;for(const[i,c]of Object.entries(r)){const r=Et(e,o,i,!1),l=function(t,n,...r){c.call(Wt(e,this,o),t,n,...r)};n.push({path:r,pathInfo:d(r),handler:l,order:1e6+a++}),s.add(r),t.setPathInfo(r,"prop","watch")}n.length>0&&(mt(t,n),t.addVolumeWatchPaths?.(s),pt(t))}const s=n[p];if(void 0!==s){const n=new Map;for(const[t,r]of Object.entries(s))n.set(Et(e,o,t,!1),r);t.mergeVolumeListKeys?.(n)}const a=n[b];"function"==typeof a&&(!function(t,e){let n=zt.get(t);void 0===n&&(n=[],zt.set(t,n)),n.push(e),t.markHasVolume?.()}(t,{mountPath:e,injections:o,callback:a}),t.enableUpdatedCallback?.());for(const t of["$commandTokens","$eventTokens","$on","$errorCallback"])void 0!==n[t]&&console.warn(`[@wcstack/state] volume "${e}" declares ${t}, which volumes do not support. Declare it on the root state instead.`)}function Ee(t,e,n,o=[]){j(n),function(t,e,n,o){for(const t of o){const o=t.innerSegments[0],r=Object.getOwnPropertyDescriptor(n,o);void 0===r||"function"!=typeof r.get&&"function"!=typeof r.set&&"function"!=typeof r.value||w(`Volume "${e}" declares "${o}" as an accessor or a method and also injects it ("${l}.${o}: ${t.outerPathInfo.path}"). Rename one of them.`)}const r=n[m];if(void 0!==r){"object"==typeof r&&null!==r||w(`${m} must be an object mapping state paths to handler functions.`);for(const[t,e]of Object.entries(r))"function"!=typeof e&&w(`${m} entry "${t}" must be a function.`),ht(t)}const s=n[p];if(void 0!==s){"object"==typeof s&&null!==s||w(`${p} must be an object mapping list paths to key specs.`);for(const[n,r]of Object.entries(s)){(0===n.length||"string"!=typeof r&&"function"!=typeof r)&&w(`${p} entry "${n}" must map a list path to a field name or a key function.`);const s=Et(e,o,n,!1);t.listKeys?.has(s)&&w(`${p} entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`)}}void 0!==n[a]&&w(`Volume "${e}" declares ${a}, which volumes do not support yet. Declare the stream on the root state.`),void 0!==n.$scan&&w(`Volume "${e}" declares $scan, which volumes do not support yet. Declare the scan on the root state.`),void 0!==n[g]&&w(`Volume "${e}" declares ${g}, which volumes do not support yet. Declare the recursion anchor on the root state — the anchor path is resolved against the root tree.`);for(const t of Object.keys(k(n)))-1!==t.indexOf(y)&&w(`Volume "${e}" declares "${t}", which uses "${y}". Volumes do not support recursive getters yet — declare them on the root state.`)}(t,e,n,o);const{data:r,accessors:s}=function(t,e){const n={},o=new Map;for(const[r,s]of Object.entries(Object.getOwnPropertyDescriptors(t)))r.startsWith("$")||e.has(r)||("function"!=typeof s.get&&"function"!=typeof s.set?"function"!=typeof s.value&&(n[r]=s.value):o.set(r,s));return{data:n,accessors:o}}(n,new Set(o.map(t=>t.innerSegments[0]))),i=d(e),u=!0===t.hydratedFromSsr;t.createState("writable",t=>{if(1===i.segments.length&&e in t){if(u)return;w(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}let n="";for(let e=0;e<i.segments.length-1;e++){const o=i.segments[e],r=""===n?o in t:void 0!==t[n+c+o];n=""===n?o:n+c+o,r||(t[n]={})}if(i.segments.length>1&&void 0!==t[e]){if(u)return;w(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}t[e]=r}),function(t,e){let n=Mt.get(t);void 0===n&&(n=new Set,Mt.set(t,n)),n.add(e)}(t,e),t.markHasGraftedVolumes?.();for(const[n,r]of s){const s=e+c+n,a=r.get,i=r.set,l={enumerable:!1,configurable:!0};"function"==typeof a&&(l.get=function(){return a.call(Wt(e,this,o))}),"function"==typeof i&&(l.set=function(t){i.call(Wt(e,this,o),t)}),t.defineTreeAccessor(s,l)}Oe(t,e,n,o);const f=n.$connectedCallback;return"function"==typeof f&&t.createState("writable",t=>{let n;try{n=f.call(Wt(e,t,o))}catch(t){return void console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)}n instanceof Promise&&n.catch(t=>{console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)})}),{rootStateElement:t,mountPath:e,volumeState:n,injections:o}}function De(t,e){if(!e.acquireSlot())return void e.onGrafted(null);let n=null;try{n=Ee(t,e.mountPath,e.volumeState,e.injections)}catch(t){console.error(`[@wcstack/state] volume "${e.mountPath}" failed to graft.`,t)}finally{e.onGrafted(n)}}let We=!1;function ze(){We||(We=!0,oe||(oe=!0,v("scopes",ne)),ue||(ue=!0,t("scopes",le)),Re||(Re=!0,t("bindComponent",Ne),_(ye)),_t=De,H(Le))}function Le(t,e){(function(t){const e=xt.get(t);return void 0!==e&&e.size>0})(t)&&e.markHasVolume?.(),function(t,e){Bt.delete(t);const n=Vt.get(t);if(void 0===n||0===n.length||null===_t)return;Vt.delete(t);const o=_t;queueMicrotask(()=>{for(const t of n)o(e,t)})}(t,e)}const Ve={name:"scopes",install(){ze(),At||(At=!0,t("dcc",It))}};export{Ve as default,Ve as scopes};
|
|
2
2
|
//# sourceMappingURL=scopes.js.map
|