@wcstack/state 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +20 -17
- package/README.md +20 -17
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.esm.js +73 -34
- package/dist/parser.esm.js +10 -4
- package/dist/split/auto.js +1 -1
- package/dist/split/chunks/chunk-2RBI6DVS.js +2 -0
- package/dist/split/chunks/chunk-2RBI6DVS.js.map +1 -0
- package/dist/split/chunks/{chunk-V3HFN3MW.js → chunk-3Q7LGONS.js} +2 -2
- package/dist/split/chunks/{chunk-V3HFN3MW.js.map → chunk-3Q7LGONS.js.map} +1 -1
- package/dist/split/chunks/{chunk-UFIDBJBP.js → chunk-4ECL4ITF.js} +2 -2
- package/dist/split/chunks/{chunk-7ZU3CLEG.js → chunk-BGUJ3HF6.js} +2 -2
- package/dist/split/chunks/{chunk-4HLDITUB.js → chunk-BI4645UG.js} +2 -2
- package/dist/split/chunks/chunk-BI4645UG.js.map +1 -0
- package/dist/split/chunks/{chunk-JAEYZSVS.js → chunk-BYQBV3ZC.js} +2 -2
- package/dist/split/chunks/{chunk-R5OJ52SF.js → chunk-CIBJLAA3.js} +2 -2
- package/dist/split/chunks/{chunk-R5OJ52SF.js.map → chunk-CIBJLAA3.js.map} +1 -1
- package/dist/split/chunks/chunk-JK3B3LLB.js +2 -0
- package/dist/split/chunks/chunk-OKBVNGFK.js +2 -0
- package/dist/split/chunks/{chunk-56ZGITUJ.js.map → chunk-OKBVNGFK.js.map} +1 -1
- package/dist/split/chunks/{chunk-GGSHXG7N.js → chunk-UBGJGMSG.js} +2 -2
- package/dist/split/chunks/chunk-UBGJGMSG.js.map +1 -0
- package/dist/split/chunks/{chunk-7QVEF5E3.js → chunk-UPSLR4FS.js} +2 -2
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/diagnostics.js.map +1 -1
- package/dist/split/features/formats.d.ts +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/formats.js.map +1 -1
- package/dist/split/features/list-keys.js +1 -1
- package/dist/split/features/native-commands.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/split/features/temporal.js.map +1 -1
- package/dist/wcs-manifest.json +25 -7
- package/package.json +1 -1
- package/dist/split/chunks/chunk-4HLDITUB.js.map +0 -1
- package/dist/split/chunks/chunk-56ZGITUJ.js +0 -2
- package/dist/split/chunks/chunk-BWGPKDHS.js +0 -2
- package/dist/split/chunks/chunk-BWGPKDHS.js.map +0 -1
- package/dist/split/chunks/chunk-GGSHXG7N.js.map +0 -1
- package/dist/split/chunks/chunk-XEGL4FW5.js +0 -2
- /package/dist/split/chunks/{chunk-UFIDBJBP.js.map → chunk-4ECL4ITF.js.map} +0 -0
- /package/dist/split/chunks/{chunk-7ZU3CLEG.js.map → chunk-BGUJ3HF6.js.map} +0 -0
- /package/dist/split/chunks/{chunk-JAEYZSVS.js.map → chunk-BYQBV3ZC.js.map} +0 -0
- /package/dist/split/chunks/{chunk-XEGL4FW5.js.map → chunk-JK3B3LLB.js.map} +0 -0
- /package/dist/split/chunks/{chunk-7QVEF5E3.js.map → chunk-UPSLR4FS.js.map} +0 -0
|
@@ -20,7 +20,7 @@ interface Feature {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* The formats add-on (@wcstack/state/features/formats): the
|
|
23
|
+
* The formats add-on (@wcstack/state/features/formats): the 38 filters that compute and show a value
|
|
24
24
|
* (display, string shaping, dates — locale-aware —, arithmetic, conversions, missing values).
|
|
25
25
|
*/
|
|
26
26
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t,b as r,c as e,d as a,e as n,f as o,g as i,h as l,i as c}from"../chunks/chunk-
|
|
1
|
+
import{a as t,b as r,c as e,d as a,e as n,f as o,g as i,h as l,i as c,j as y,k as u}from"../chunks/chunk-2RBI6DVS.js";import{a as s,e as f}from"../chunks/chunk-CIBJLAA3.js";import{a as p}from"../chunks/chunk-UBGJGMSG.js";import"../chunks/chunk-BGUJ3HF6.js";var d,m=t=>r=>{let e=t(r);return t=>null==t?t:e(t)},g="en";function S(){if(s.locale!==d){d=s.locale;try{g=Intl.getCanonicalLocales(d)[0]}catch{console.warn(`[@wcstack/state] ${p(48,[d])}`),g="en"}}return g}var h=["full","long","medium","short"];function b(t,e){let[a,n]=t??[];return void 0===n&&void 0!==a&&h.includes(a)&&([a,n]=[void 0,a]),void 0!==n&&!h.includes(n)&&r(e,n),[a,n]}var{eq:M,ne:$,not:v,lt:k,le:j,gt:w,ge:F,falsy:D,truthy:L,boolean:x}=u,C={toFixed:{factory:t=>{let r=i(t?.[0]??"0","toFixed");return t=>("number"!=typeof t&&a("toFixed",t),t.toFixed(r))},arity:[0,1]},locale:{factory:t=>{let r=t?.[0];return t=>("number"!=typeof t&&a("locale",t),t.toLocaleString(r??S()))},arity:[0,1]},upper:{factory:m(()=>t=>String(t).toUpperCase()),arity:[0,0]},lower:{factory:m(()=>t=>String(t).toLowerCase()),arity:[0,0]},capitalize:{factory:m(()=>t=>{let r=String(t);return 0===r.length?r:1===r.length?r.toUpperCase():r.charAt(0).toUpperCase()+r.slice(1)}),arity:[0,0]},trim:{factory:m(()=>t=>String(t).trim()),arity:[0,0]},slice:{factory:m(t=>{let r=[l(t,0,"slice")],e=t?.[1];return typeof e<"u"&&r.push(i(e,"slice")),t=>String(t).slice(...r)}),arity:[1,2]},padStart:{factory:m(t=>{let r=l(t,0,"padStart"),e=t?.[1]??"0";return t=>String(t).padStart(r,e)}),arity:[1,2]},padEnd:{factory:m(t=>{let r=l(t,0,"padEnd"),e=t?.[1]??" ";return t=>String(t).padEnd(r,e)}),arity:[1,2]},repeat:{factory:m(t=>{let r=l(t,0,"repeat");return t=>String(t).repeat(r)}),arity:[1,1]},reverse:{factory:m(()=>t=>String(t).split("").reverse().join("")),arity:[0,0]},truncate:{factory:m(t=>{let r=l(t,0,"truncate"),e=t?.[1]??"…";return t=>{let a=String(t);return a.length<=r?a:a.slice(0,r)+e}}),arity:[1,2]},join:{factory:t=>{let r=t?.[0]??", ";return t=>(Array.isArray(t)||o("join"),t.join(r))},arity:[0,1]},round:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","round"));return t=>("number"!=typeof t&&a("round",t),Math.round(t*r)/r)},arity:[0,1]},floor:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","floor"));return t=>("number"!=typeof t&&a("floor",t),Math.floor(t*r)/r)},arity:[0,1]},ceil:{factory:t=>{let r=Math.pow(10,i(t?.[0]??"0","ceil"));return t=>("number"!=typeof t&&a("ceil",t),Math.ceil(t*r)/r)},arity:[0,1]},percent:{factory:t=>{let r=i(t?.[0]??"0","percent");return t=>("number"!=typeof t&&a("percent",t),`${(100*t).toFixed(r)}%`)},arity:[0,1]},unit:{factory:m(r=>{let e=r?.[0]??t("unit");return t=>String(t)+e}),arity:[1,1]},date:{factory:t=>{let[r,e]=b(t,"date"),a=e&&{dateStyle:e};return t=>(t instanceof Date||n("date",t),t.toLocaleDateString(r??S(),a))},arity:[0,2]},time:{factory:t=>{let[r,e]=b(t,"time"),a=e&&{timeStyle:e};return t=>(t instanceof Date||n("time",t),t.toLocaleTimeString(r??S(),a))},arity:[0,2]},datetime:{factory:t=>{let[r,e]=b(t,"datetime"),a=e&&{dateStyle:e,timeStyle:e};return t=>(t instanceof Date||n("datetime",t),t.toLocaleString(r??S(),a))},arity:[0,2]},ymd:{factory:t=>{let r=t?.[0]??"-";return t=>{t instanceof Date||n("ymd",t);let e=t.getFullYear().toString(),a=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},hms:{factory:t=>{let r=t?.[0]??":";return t=>{t instanceof Date||n("hms",t);let e=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0"),o=t.getSeconds().toString().padStart(2,"0");return`${e}${r}${a}${r}${o}`}},arity:[0,1]},eq:M,ne:$,not:v,lt:k,le:j,gt:w,ge:F,add:y("add",(t,r)=>t+r),sub:y("sub",(t,r)=>t-r),mul:y("mul",(t,r)=>t*r),div:y("div",(t,r)=>t/r),mod:y("mod",(t,r)=>t%r),abs:{factory:()=>t=>("number"!=typeof t&&a("abs",t),Math.abs(t)),arity:[0,0]},clamp:{factory:t=>{let r=l(t,0,"clamp"),e=l(t,1,"clamp");return t=>("number"!=typeof t&&a("clamp",t),Math.min(Math.max(t,r),e))},arity:[2,2]},int:{factory:()=>t=>parseInt(String(t),10),arity:[0,0]},float:{factory:()=>t=>parseFloat(String(t)),arity:[0,0]},falsy:D,truthy:L,defaults:{factory:(r,e)=>{let a=r?.[0]??t("defaults"),n=c(a,e);return t=>t||n},arity:[1,1]},coalesce:{factory:(r,e)=>{let a=r?.[0]??t("coalesce"),n=c(a,e);return t=>t??n},arity:[1,1]},boolean:x,number:{factory:()=>t=>Number(t),arity:[0,0]},string:{factory:()=>t=>String(t),arity:[0,0]},nullIfEmpty:{factory:()=>t=>""===t?null:t,arity:[0,0]},currency:{factory:r=>{let n=r?.[0]??t("currency"),o=r?.[1],i={style:"currency",currency:n};try{new Intl.NumberFormat("en",i);let t=Intl.supportedValuesOf?.("currency");if(t&&!t.includes(n.toUpperCase()))throw 0}catch{e(n)}return t=>("number"!=typeof t&&a("currency",t),t.toLocaleString(o??S(),i))},arity:[1,2]}},I=!1,U={name:"formats",install:function(){I||(I=!0,f(C))}},A=U;export{A as default,U as formats};
|
|
2
2
|
//# sourceMappingURL=formats.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["seen","nullishPassthrough","factory","options","filterFn","value","valid","defaultLocale","config","locale","Intl","getCanonicalLocales","console","warn","text","eq","ne","not","lt","le","gt","ge","falsy","truthy","boolean","coreFilters","registered","toFixed","opt","numberOption","valueMustBeNumber","arity","explicit","toLocaleString","upper","String","toUpperCase","lower","toLowerCase","capitalize","v","length","charAt","slice","trim","numberedOpts","requiredNumberOption","opt2","push","padStart","opt1","padEnd","repeat","reverse","split","join","truncate","maxLength","suffix","Array","isArray","valueMustBeArray","round","optValue","Math","pow","floor","ceil","percent","unit","optionsRequired","date","Date","valueMustBeDate","toLocaleDateString","time","toLocaleTimeString","datetime","ymd","year","getFullYear","toString","month","getMonth","day","getDate","hms","hours","getHours","minutes","getMinutes","seconds","getSeconds","add","numeric","sub","mul","div","mod","abs","clamp","min","max","int","parseInt","float","parseFloat","defaults","literals","fallback","firstLiteral","coalesce","number","Number","string","nullIfEmpty","installed","formats","name","install","registerFilters","formats_default"],"sources":["../../../src/filters/formats.ts","../../../src/features/formats.ts"],"sourcesContent":["/**\n * filters/formats.ts — the formats add-on (37 filters): the values a binding computes and shows, as\n * opposed to the conditions the core set (`./core`) tests. Ported from `@wcstack/state`\n * (`formats/builtinFilters.ts`) with the semantics unchanged.\n *\n * - number display: `toFixed round floor ceil percent unit locale`\n * - string shaping: `upper lower capitalize trim slice padStart padEnd repeat reverse truncate join`\n * (`substr` was removed in 4.0: `slice(start, start + length)`)\n * - date and time: `date time datetime ymd hms`\n * - arithmetic: `add sub mul div mod abs clamp`\n * - conversions: `number string int float`\n * - missing values: `defaults coalesce nullIfEmpty`\n *\n * (The last three groups were the core's up to 4.0.0-rc.3.)\n *\n * `installFormats()` puts them in the registry. Without it, one of these filters fails when the\n * bindings are planned with `[wcs/filter-unknown]` naming this add-on (never passes silently).\n * The locale-dependent four (`locale date time datetime`) read `config.locale` as their default.\n */\nimport { config } from \"../config\";\nimport { optionsRequired, valueMustBeArray, valueMustBeDate, valueMustBeNumber } from \"./errorMessages\";\nimport { firstLiteral, numberOption, requiredNumberOption } from \"./options\";\nimport { registerFilters, type FilterDefinition, type FilterFactory, type FilterFn } from \"./registry\";\nimport { coreFilters, numeric } from \"./core\";\nimport { M, text } from \"../messages\";\n\n/**\n * Extends the display-side empty-value contract (requirement B8) to the filters that build their\n * result with `String(value)`: those turn `undefined` / `null` into the *characters* \"undefined\" /\n * \"null\", so `attr.title: x|trim` wrote `title=\"undefined\"` where `attr.title: x` removes the\n * attribute. This family passes an absent value straight through and leaves the decision to the\n * apply side (attribute removed, class cleared, style cleared, text emptied).\n *\n * Deliberately **not** wrapped: the filters that reject a value of the wrong type (the number, date\n * and array families) — their throw is confined to the one binding and reported, a different\n * quality of failure from painting the word \"undefined\" into the page.\n */\nconst nullishPassthrough = (factory: (options: string[]) => FilterFn): FilterFactory =>\n (options: string[]): FilterFn => {\n const filterFn = factory(options);\n // `== null` matches both null and undefined (deliberately loose)\n return (value: unknown): unknown => (value == null ? value : filterFn(value));\n };\n\n/** Fixed decimals (default 0). */\nconst toFixed = (options: string[]): FilterFn => {\n const opt = numberOption(options?.[0] ?? \"0\", 'toFixed');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('toFixed');}\n return value.toFixed(opt);\n };\n};\n\n/** Rounds to the given decimals (default 0). */\nconst round = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'round'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round');}\n return Math.round(value * optValue) / optValue;\n };\n};\n\n/** Rounds down to the given decimals (default 0). */\nconst floor = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'floor'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor');}\n return Math.floor(value * optValue) / optValue;\n };\n};\n\n/** Rounds up to the given decimals (default 0). */\nconst ceil = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'ceil'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil');}\n return Math.ceil(value * optValue) / optValue;\n };\n};\n\n/** `0.123` → `\"12%\"` with the given decimals (default 0). */\nconst percent = (options: string[]): FilterFn => {\n const opt = numberOption(options?.[0] ?? '0', 'percent');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent');}\n return `${(value * 100).toFixed(opt)}%`;\n };\n};\n\n/**\n * Appends a CSS unit (or any suffix). Accepts strings as well as numbers **on purpose**: the useful\n * chains run through `toFixed` / `percent`, which already return strings\n * (`style.height: cpu|clamp(0,100)|toFixed(0)|unit(%)`). null / undefined pass through\n * (`nullishPassthrough`) rather than becoming \"undefinedpx\".\n */\nconst unit = (options: string[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): string => String(value) + opt;\n};\n\nlet seen: string | undefined;\nlet valid = \"en\";\n\n/**\n * The default locale (`config.locale`) as Intl takes it, checked when it changes (an identity\n * compare per apply): one it does not (`<html lang=\"en_US\">`) is \"en\" (as 3.x), with a warning.\n */\nfunction defaultLocale(): string {\n if (config.locale !== seen) {\n seen = config.locale;\n try {\n valid = Intl.getCanonicalLocales(seen)[0];\n } catch {\n console.warn(`[@wcstack/state] ${text(M.LocaleInvalid, [seen])}`);\n valid = \"en\";\n }\n }\n return valid;\n}\n\n/**\n * Locale-formatted number. The locale-dependent filters (`locale date time datetime`) fix an\n * **explicit** locale at construction but read the default `config.locale` **on every apply**: a\n * default baked into the closure at binding time would make an ordering accident (locale settled\n * after the bindings) permanent, since `config.locale` is not in the dependency graph. Read per\n * apply, a re-applied binding at least recovers.\n */\nconst locale = (options: string[]): FilterFn => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('locale');}\n return value.toLocaleString(explicit ?? defaultLocale());\n };\n};\n\nconst upper = (): FilterFn => (value: unknown): string => String(value).toUpperCase();\n\nconst lower = (): FilterFn => (value: unknown): string => String(value).toLowerCase();\n\nconst capitalize = (): FilterFn => (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\nconst trim = (): FilterFn => (value: unknown): string => String(value).trim();\n\n/** `slice(start[, end])`. */\nconst slice = (options: string[]): FilterFn => {\n const numberedOpts: number[] = [requiredNumberOption(options, 0, 'slice')];\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n numberedOpts.push(numberOption(opt2, 'slice'));\n }\n return (value: unknown): string => String(value).slice(...numberedOpts);\n};\n\n/** Pads the start to a length; the pad string defaults to '0' (JavaScript's default is a space). */\nconst padStart = (options: string[]): FilterFn => {\n const opt1 = requiredNumberOption(options, 0, 'padStart');\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => String(value).padStart(opt1, opt2);\n};\n\n/** Pads the end to a length; the pad string defaults to ' ' (as in JavaScript). */\nconst padEnd = (options: string[]): FilterFn => {\n const opt1 = requiredNumberOption(options, 0, 'padEnd');\n const opt2 = options?.[1] ?? ' ';\n return (value: unknown): string => String(value).padEnd(opt1, opt2);\n};\n\nconst repeat = (options: string[]): FilterFn => {\n const opt = requiredNumberOption(options, 0, 'repeat');\n return (value: unknown): string => String(value).repeat(opt);\n};\n\nconst reverse = (): FilterFn => (value: unknown): string => String(value).split('').reverse().join('');\n\n/**\n * Shortens a string and appends a suffix (default '…', U+2026). The length counts **kept\n * characters**; a string at or below it is returned untouched (no suffix).\n */\nconst truncate = (options: string[]): FilterFn => {\n const maxLength = requiredNumberOption(options, 0, 'truncate');\n const suffix = options?.[1] ?? '…';\n return (value: unknown): string => {\n const v = String(value);\n if (v.length <= maxLength) {return v;}\n return v.slice(0, maxLength) + suffix;\n };\n};\n\n/**\n * Joins an array. The default separator is \", \" rather than \",\": a bare comma is what `String()`\n * already produces, so defaulting to it would make `|join` a no-op.\n */\nconst join = (options: string[]): FilterFn => {\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/** Locale-formatted date (the default locale is read per apply — see `locale`). */\nconst date = (options: string[]): FilterFn => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('date');}\n return value.toLocaleDateString(explicit ?? defaultLocale());\n };\n};\n\n/** Locale-formatted time (the default locale is read per apply — see `locale`). */\nconst time = (options: string[]): FilterFn => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('time');}\n return value.toLocaleTimeString(explicit ?? defaultLocale());\n };\n};\n\n/** Locale-formatted date and time (the default locale is read per apply — see `locale`). */\nconst datetime = (options: string[]): FilterFn => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('datetime');}\n return value.toLocaleString(explicit ?? defaultLocale());\n };\n};\n\n/** YYYY-MM-DD with a configurable separator (default '-'), locale-independent. */\nconst ymd = (options: string[]): FilterFn => {\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/** HH:MM:SS with a configurable separator (default ':'), zero-padded and locale-independent. */\nconst hms = (options: string[]): FilterFn => {\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\nconst abs = (): FilterFn => (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('abs');}\n return Math.abs(value);\n};\n\n/** Constrains a number to the inclusive range [min, max] (`style.width: ratio|clamp(0,1)|percent(0)`). */\nconst clamp = (options: string[]): FilterFn => {\n const min = requiredNumberOption(options, 0, 'clamp');\n const max = requiredNumberOption(options, 1, 'clamp');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('clamp');}\n return Math.min(Math.max(value, min), max);\n };\n};\n\n// The conversions convert — an absent value is converted too (`string` gives \"undefined\");\n// put `coalesce` in front when a missing value should not be converted.\nconst number = (): FilterFn => (value: unknown): number => Number(value);\n\nconst string = (): FilterFn => (value: unknown): string => String(value);\n\nconst int = (): FilterFn => (value: unknown): number => parseInt(String(value), 10);\n\nconst float = (): FilterFn => (value: unknown): number => parseFloat(String(value));\n\n/** Replaces a falsy value (JavaScript's truthiness) with the typed literal: defaults(0) gives 0, defaults('0') \"0\" (B9). */\nconst defaults = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('defaults');\n const fallback = firstLiteral(opt, literals);\n return (value: unknown): unknown => {\n if (!value) {return fallback;}\n return value;\n };\n};\n\n/** Replaces only null / undefined (`defaults` also replaces 0, false and \"\") — SQL's COALESCE. */\nconst coalesce = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('coalesce');\n const fallback = firstLiteral(opt, literals);\n return (value: unknown): unknown => value ?? fallback;\n};\n\n/** \"\" → null, anything else unchanged. */\nconst nullIfEmpty = (): FilterFn => (value: unknown): unknown => (value === \"\") ? null : value;\n\nconst { eq, ne, not, lt, le, gt, ge, falsy, truthy, boolean } = coreFilters;\n\n/**\n * What `installFormats()` registers: factory and [min, max] argument count (B3 — the same bounds\n * lint uses), in the order the registry keeps them. The did-you-mean suggestion gives a tie to the\n * first registered, so the order is the one the full build registered up to 4.0.0-rc.3, when this\n * add-on had the 23 display filters and the core 24: the display filters, then that core set, each\n * in the source's (lint's) relative order. The core's 10 are registered here too, in their place\n * (the core registers them again when it first plans a binding, and a name registered again keeps\n * its place).\n */\nconst registered: Readonly<Record<string, FilterDefinition>> = {\n toFixed: { factory: toFixed, arity: [0, 1] },\n locale: { factory: locale, arity: [0, 1] },\n\n // The `String(value)` family passes an absent value through (B8 — see nullishPassthrough)\n upper: { factory: nullishPassthrough(upper), arity: [0, 0] },\n lower: { factory: nullishPassthrough(lower), arity: [0, 0] },\n capitalize: { factory: nullishPassthrough(capitalize), arity: [0, 0] },\n trim: { factory: nullishPassthrough(trim), arity: [0, 0] },\n slice: { factory: nullishPassthrough(slice), arity: [1, 2] },\n // The length is required too (the implementation reads both)\n padStart: { factory: nullishPassthrough(padStart), arity: [1, 2] },\n padEnd: { factory: nullishPassthrough(padEnd), arity: [1, 2] },\n repeat: { factory: nullishPassthrough(repeat), arity: [1, 1] },\n reverse: { factory: nullishPassthrough(reverse), arity: [0, 0] },\n truncate: { factory: nullishPassthrough(truncate), arity: [1, 2] },\n join: { factory: join, arity: [0, 1] },\n\n round: { factory: round, arity: [0, 1] },\n floor: { factory: floor, arity: [0, 1] },\n ceil: { factory: ceil, arity: [0, 1] },\n percent: { factory: percent, arity: [0, 1] },\n unit: { factory: nullishPassthrough(unit), arity: [1, 1] },\n\n // The locale-dependent three take a locale like `locale` does (`date(ja-JP)`)\n date: { factory: date, arity: [0, 1] },\n time: { factory: time, arity: [0, 1] },\n datetime: { factory: datetime, arity: [0, 1] },\n ymd: { factory: ymd, arity: [0, 1] },\n hms: { factory: hms, arity: [0, 1] },\n\n // the core set of 4.0.0-rc.3 (the core's own: eq ne not lt le gt ge falsy truthy boolean)\n eq, ne, not, lt, le, gt, ge,\n add: numeric('add', (value, opt) => value + opt),\n sub: numeric('sub', (value, opt) => value - opt),\n mul: numeric('mul', (value, opt) => value * opt),\n div: numeric('div', (value, opt) => value / opt),\n mod: numeric('mod', (value, opt) => value % opt),\n abs: { factory: abs, arity: [0, 0] },\n clamp: { factory: clamp, arity: [2, 2] },\n int: { factory: int, arity: [0, 0] },\n float: { factory: float, arity: [0, 0] },\n falsy, truthy,\n defaults: { factory: defaults, arity: [1, 1] },\n coalesce: { factory: coalesce, arity: [1, 1] },\n boolean,\n number: { factory: number, arity: [0, 0] },\n string: { factory: string, arity: [0, 0] },\n nullIfEmpty: { factory: nullIfEmpty, arity: [0, 0] },\n};\n\n/** The formats add-on's own filters (what `registered` holds beyond the core set), in that order. */\nexport const formatFilters: Readonly<Record<string, FilterDefinition>> = /*#__PURE__*/ Object.fromEntries(\n /*#__PURE__*/ Object.entries(registered).filter(([name]) => !(name in coreFilters)),\n);\n\nlet installed = false;\n\n/** Puts the formats add-on in the registry. Idempotent. */\nexport function installFormats(): void {\n if (installed) return;\n installed = true;\n registerFilters(registered);\n}\n","/**\n * The formats add-on (@wcstack/state/features/formats): the 37 filters that compute and show a value\n * (display, string shaping, dates — locale-aware —, arithmetic, conversions, missing values).\n */\nimport type { Feature } from \"../hooks\";\nimport { installFormats } from \"../filters/formats\";\n\nexport const formats: Feature = { name: \"formats\", install: installFormats };\nexport default formats;\n"],"mappings":"mPAqCA,IA+DIA,EA/DEC,EAAsBC,GACzBC,IACC,IAAMC,EAAWF,EAAQC,GAEzB,OAAQE,GAAsC,MAATA,EAAgBA,EAAQD,EAASC,IA4DtEC,EAAQ,KAMZ,SAASC,IACP,GAAIC,EAAOC,SAAWT,EAAM,CAC1BA,EAAOQ,EAAOC,OACd,IACEH,EAAQI,KAAKC,oBAAoBX,GAAM,EACzC,OACEY,QAAQC,KAAK,oBAAoBC,KAAsB,CAACd,OACxDM,EAAQ,IACV,CACF,CACA,OAAOA,CACT,CASA,IA8KQS,KAAIC,KAAIC,MAAKC,KAAIC,KAAIC,KAAIC,KAAIC,QAAOC,SAAQC,WAAYC,EAW1DC,EAAyD,CAC7DC,QAAS,CAAEzB,QA5QIC,IACf,IAAMyB,EAAMC,EAAa1B,IAAU,IAAM,IAAK,WAC9C,OAAQE,IACe,iBAAVA,GAAqByB,EAAkB,WAC3CzB,EAAMsB,QAAQC,KAwQMG,MAAO,CAAC,EAAG,IACxCtB,OAAQ,CAAEP,QA3LIC,IACd,IAAM6B,EAAW7B,IAAU,GAC3B,OAAQE,IACe,iBAAVA,GAAqByB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AAO,CAAEvG,QA1EG,IAAiBG,GAA2BqG,WAAWvE,OAAO9B,IA0EjD0B,MAAO,CAAC,EAAG,IACpCT,QAAOC,SACPoF,SAAU,CAAEzG,QAzEG,CAACC,EAAmByG,KACnC,IAAMhF,EAAMzB,IAAU,IAAMmE,EAAgB,YACtCuC,EAAWC,EAAalF,EAAKgF,GACnC,OAAQvG,GACDA,GAAewG,GAqES9E,MAAO,CAAC,EAAG,IAC1CgF,SAAU,CAAE7G,QAhEG,CAACC,EAAmByG,KACnC,IAAMhF,EAAMzB,IAAU,IAAMmE,EAAgB,YACtCuC,EAAWC,EAAalF,EAAKgF,GACnC,OAAQvG,GAA4BA,GAASwG,GA6Dd9E,MAAO,CAAC,EAAG,IAC1CP,UACAwF,OAAQ,CAAE9G,QArFG,IAAiBG,GAA2B4G,OAAO5G,GAqFrC0B,MAAO,CAAC,EAAG,IACtCmF,OAAQ,CAAEhH,QApFG,IAAiBG,GAA2B8B,OAAO9B,GAoFrC0B,MAAO,CAAC,EAAG,IACtCoF,YAAa,CAAEjH,QA7DG,IAAiBG,GAAuC,KAAVA,EAAgB,KAAOA,EA6DlD0B,MAAO,CAAC,EAAG,KAQ9CqF,GAAY,ECzWHC,EAAmB,CAAEC,KAAM,UAAWC,QD4W5C,WACDH,IACJA,GAAY,EACZI,EAAgB9F,GAClB,GC/WO+F,EAAQJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["seen","nullishPassthrough","factory","options","filterFn","value","valid","defaultLocale","config","locale","Intl","getCanonicalLocales","console","warn","text","STYLES","dateOptions","fn","loc","style","includes","styleInvalid","eq","ne","not","lt","le","gt","ge","falsy","truthy","boolean","coreFilters","registered","toFixed","opt","numberOption","valueMustBeNumber","arity","explicit","toLocaleString","upper","String","toUpperCase","lower","toLowerCase","capitalize","v","length","charAt","slice","trim","numberedOpts","requiredNumberOption","opt2","push","padStart","opt1","padEnd","repeat","reverse","split","join","truncate","maxLength","suffix","Array","isArray","valueMustBeArray","round","optValue","Math","pow","floor","ceil","percent","unit","optionsRequired","date","format","dateStyle","Date","valueMustBeDate","toLocaleDateString","time","timeStyle","toLocaleTimeString","datetime","ymd","year","getFullYear","toString","month","getMonth","day","getDate","hms","hours","getHours","minutes","getMinutes","seconds","getSeconds","add","numeric","sub","mul","div","mod","abs","clamp","min","max","int","parseInt","float","parseFloat","defaults","literals","fallback","firstLiteral","coalesce","number","Number","string","nullIfEmpty","currency","code","NumberFormat","known","supportedValuesOf","currencyInvalid","installed","formats","name","install","registerFilters","formats_default"],"sources":["../../../src/filters/formats.ts","../../../src/features/formats.ts"],"sourcesContent":["/**\n * filters/formats.ts — the formats add-on (38 filters): the values a binding computes and shows, as\n * opposed to the conditions the core set (`./core`) tests. Ported from `@wcstack/state`\n * (`formats/builtinFilters.ts`) with the semantics unchanged.\n *\n * - number display: `toFixed round floor ceil percent unit locale currency`\n * - string shaping: `upper lower capitalize trim slice padStart padEnd repeat reverse truncate join`\n * (`substr` was removed in 4.0: `slice(start, start + length)`)\n * - date and time: `date time datetime ymd hms`\n * - arithmetic: `add sub mul div mod abs clamp`\n * - conversions: `number string int float`\n * - missing values: `defaults coalesce nullIfEmpty`\n *\n * (The last three groups were the core's up to 4.0.0-rc.3.)\n *\n * `installFormats()` puts them in the registry. Without it, one of these filters fails when the\n * bindings are planned with `[wcs/filter-unknown]` naming this add-on (never passes silently).\n * The locale-dependent five (`locale currency date time datetime`) read `config.locale` as their default.\n */\nimport { config } from \"../config\";\nimport { currencyInvalid, optionsRequired, styleInvalid, valueMustBeArray, valueMustBeDate, valueMustBeNumber } from \"./errorMessages\";\nimport { firstLiteral, numberOption, requiredNumberOption } from \"./options\";\nimport { registerFilters, type FilterDefinition, type FilterFactory, type FilterFn } from \"./registry\";\nimport { coreFilters, numeric } from \"./core\";\nimport { M, text } from \"../messages\";\n\n/**\n * Extends the display-side empty-value contract (requirement B8) to the filters that build their\n * result with `String(value)`: those turn `undefined` / `null` into the *characters* \"undefined\" /\n * \"null\", so `attr.title: x|trim` wrote `title=\"undefined\"` where `attr.title: x` removes the\n * attribute. This family passes an absent value straight through and leaves the decision to the\n * apply side (attribute removed, class cleared, style cleared, text emptied).\n *\n * Deliberately **not** wrapped: the filters that reject a value of the wrong type (the number, date\n * and array families) — their throw is confined to the one binding and reported, a different\n * quality of failure from painting the word \"undefined\" into the page.\n */\nconst nullishPassthrough = (factory: (options: string[]) => FilterFn): FilterFactory =>\n (options: string[]): FilterFn => {\n const filterFn = factory(options);\n // `== null` matches both null and undefined (deliberately loose)\n return (value: unknown): unknown => (value == null ? value : filterFn(value));\n };\n\n/** Fixed decimals (default 0). */\nconst toFixed = (options: string[]): FilterFn => {\n const opt = numberOption(options?.[0] ?? \"0\", 'toFixed');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('toFixed', value);}\n return value.toFixed(opt);\n };\n};\n\n/** Rounds to the given decimals (default 0). */\nconst round = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'round'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('round', value);}\n return Math.round(value * optValue) / optValue;\n };\n};\n\n/** Rounds down to the given decimals (default 0). */\nconst floor = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'floor'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('floor', value);}\n return Math.floor(value * optValue) / optValue;\n };\n};\n\n/** Rounds up to the given decimals (default 0). */\nconst ceil = (options: string[]): FilterFn => {\n const optValue = Math.pow(10, numberOption(options?.[0] ?? '0', 'ceil'));\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('ceil', value);}\n return Math.ceil(value * optValue) / optValue;\n };\n};\n\n/** `0.123` → `\"12%\"` with the given decimals (default 0). */\nconst percent = (options: string[]): FilterFn => {\n const opt = numberOption(options?.[0] ?? '0', 'percent');\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('percent', value);}\n return `${(value * 100).toFixed(opt)}%`;\n };\n};\n\n/**\n * Appends a CSS unit (or any suffix). Accepts strings as well as numbers **on purpose**: the useful\n * chains run through `toFixed` / `percent`, which already return strings\n * (`style.height: cpu|clamp(0,100)|toFixed(0)|unit(%)`). null / undefined pass through\n * (`nullishPassthrough`) rather than becoming \"undefinedpx\".\n */\nconst unit = (options: string[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('unit');\n return (value: unknown): string => String(value) + opt;\n};\n\nlet seen: string | undefined;\nlet valid = \"en\";\n\n/**\n * The default locale (`config.locale`) as Intl takes it, checked when it changes (an identity\n * compare per apply): one it does not (`<html lang=\"en_US\">`) is \"en\" (as 3.x), with a warning.\n */\nfunction defaultLocale(): string {\n if (config.locale !== seen) {\n seen = config.locale;\n try {\n valid = Intl.getCanonicalLocales(seen)[0];\n } catch {\n console.warn(`[@wcstack/state] ${text(M.LocaleInvalid, [seen])}`);\n valid = \"en\";\n }\n }\n return valid;\n}\n\n/**\n * Locale-formatted number. The locale-dependent filters (`locale date time datetime`) fix an\n * **explicit** locale at construction but read the default `config.locale` **on every apply**: a\n * default baked into the closure at binding time would make an ordering accident (locale settled\n * after the bindings) permanent, since `config.locale` is not in the dependency graph. Read per\n * apply, a re-applied binding at least recovers.\n */\nconst locale = (options: string[]): FilterFn => {\n const explicit = options?.[0];\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('locale', value);}\n return value.toLocaleString(explicit ?? defaultLocale());\n };\n};\n\n/**\n * A number as money: `currency(code[, locale])`, the code ISO 4217 (`price|currency(JPY)` → \"¥1,800\",\n * `currency(EUR,de-DE)` → \"1.800,00 €\"). A code Intl does not take fails when the bindings are planned.\n * (docs/seam-apps.md, router-admin: the page built an `Intl.NumberFormat` per currency in getters.)\n */\nconst currency = (options: string[]): FilterFn => {\n const code = options?.[0] ?? optionsRequired('currency');\n const explicit = options?.[1];\n const format = { style: \"currency\", currency: code } as const;\n try {\n new Intl.NumberFormat(\"en\", format);\n // (Intl takes any three letters: the list of the ones it knows, where there is one)\n const known = (Intl as { supportedValuesOf?: (key: string) => string[] }).supportedValuesOf?.(\"currency\");\n if (known && !known.includes(code.toUpperCase())) throw 0;\n } catch {\n currencyInvalid(code);\n }\n return (value: unknown): string => {\n if (typeof value !== 'number') {valueMustBeNumber('currency', value);}\n return value.toLocaleString(explicit ?? defaultLocale(), format);\n };\n};\n\nconst upper = (): FilterFn => (value: unknown): string => String(value).toUpperCase();\n\nconst lower = (): FilterFn => (value: unknown): string => String(value).toLowerCase();\n\nconst capitalize = (): FilterFn => (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\nconst trim = (): FilterFn => (value: unknown): string => String(value).trim();\n\n/** `slice(start[, end])`. */\nconst slice = (options: string[]): FilterFn => {\n const numberedOpts: number[] = [requiredNumberOption(options, 0, 'slice')];\n const opt2 = options?.[1];\n if (typeof opt2 !== 'undefined') {\n numberedOpts.push(numberOption(opt2, 'slice'));\n }\n return (value: unknown): string => String(value).slice(...numberedOpts);\n};\n\n/** Pads the start to a length; the pad string defaults to '0' (JavaScript's default is a space). */\nconst padStart = (options: string[]): FilterFn => {\n const opt1 = requiredNumberOption(options, 0, 'padStart');\n const opt2 = options?.[1] ?? '0';\n return (value: unknown): string => String(value).padStart(opt1, opt2);\n};\n\n/** Pads the end to a length; the pad string defaults to ' ' (as in JavaScript). */\nconst padEnd = (options: string[]): FilterFn => {\n const opt1 = requiredNumberOption(options, 0, 'padEnd');\n const opt2 = options?.[1] ?? ' ';\n return (value: unknown): string => String(value).padEnd(opt1, opt2);\n};\n\nconst repeat = (options: string[]): FilterFn => {\n const opt = requiredNumberOption(options, 0, 'repeat');\n return (value: unknown): string => String(value).repeat(opt);\n};\n\nconst reverse = (): FilterFn => (value: unknown): string => String(value).split('').reverse().join('');\n\n/**\n * Shortens a string and appends a suffix (default '…', U+2026). The length counts **kept\n * characters**; a string at or below it is returned untouched (no suffix).\n */\nconst truncate = (options: string[]): FilterFn => {\n const maxLength = requiredNumberOption(options, 0, 'truncate');\n const suffix = options?.[1] ?? '…';\n return (value: unknown): string => {\n const v = String(value);\n if (v.length <= maxLength) {return v;}\n return v.slice(0, maxLength) + suffix;\n };\n};\n\n/**\n * Joins an array. The default separator is \", \" rather than \",\": a bare comma is what `String()`\n * already produces, so defaulting to it would make `|join` a no-op.\n */\nconst join = (options: string[]): FilterFn => {\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\nconst STYLES = [\"full\", \"long\", \"medium\", \"short\"];\n\n/**\n * The options of `date time datetime`: `(locale?, style?)`, the style Intl's `dateStyle` / `timeStyle`\n * (`date(en-US,medium)` → \"Oct 13, 2026\"). A style alone keeps the default locale (`date(long)`).\n * Without a style the format is the locale's numeric one, as before.\n */\nfunction dateOptions(options: string[], fn: string): [string | undefined, Intl.DateTimeFormatOptions[\"dateStyle\"]] {\n let [loc, style]: (string | undefined)[] = options ?? [];\n if (style === undefined && loc !== undefined && STYLES.includes(loc)) [loc, style] = [undefined, loc];\n if (style !== undefined && !STYLES.includes(style)) styleInvalid(fn, style);\n return [loc, style as Intl.DateTimeFormatOptions[\"dateStyle\"]];\n}\n\n/** Locale-formatted date (the default locale is read per apply — see `locale`). */\nconst date = (options: string[]): FilterFn => {\n const [explicit, style] = dateOptions(options, 'date');\n const format: Intl.DateTimeFormatOptions | undefined = style && { dateStyle: style };\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('date', value);}\n return value.toLocaleDateString(explicit ?? defaultLocale(), format);\n };\n};\n\n/** Locale-formatted time (the default locale is read per apply — see `locale`). */\nconst time = (options: string[]): FilterFn => {\n const [explicit, style] = dateOptions(options, 'time');\n const format: Intl.DateTimeFormatOptions | undefined = style && { timeStyle: style };\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('time', value);}\n return value.toLocaleTimeString(explicit ?? defaultLocale(), format);\n };\n};\n\n/** Locale-formatted date and time (the default locale is read per apply — see `locale`). */\nconst datetime = (options: string[]): FilterFn => {\n const [explicit, style] = dateOptions(options, 'datetime');\n const format: Intl.DateTimeFormatOptions | undefined = style && { dateStyle: style, timeStyle: style };\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('datetime', value);}\n return value.toLocaleString(explicit ?? defaultLocale(), format);\n };\n};\n\n/** YYYY-MM-DD with a configurable separator (default '-'), locale-independent. */\nconst ymd = (options: string[]): FilterFn => {\n const opt = options?.[0] ?? '-';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('ymd', value);}\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/** HH:MM:SS with a configurable separator (default ':'), zero-padded and locale-independent. */\nconst hms = (options: string[]): FilterFn => {\n const opt = options?.[0] ?? ':';\n return (value: unknown): string => {\n if (!(value instanceof Date)) {valueMustBeDate('hms', value);}\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\nconst abs = (): FilterFn => (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('abs', value);}\n return Math.abs(value);\n};\n\n/** Constrains a number to the inclusive range [min, max] (`style.width: ratio|clamp(0,1)|percent(0)`). */\nconst clamp = (options: string[]): FilterFn => {\n const min = requiredNumberOption(options, 0, 'clamp');\n const max = requiredNumberOption(options, 1, 'clamp');\n return (value: unknown): number => {\n if (typeof value !== 'number') {valueMustBeNumber('clamp', value);}\n return Math.min(Math.max(value, min), max);\n };\n};\n\n// The conversions convert — an absent value is converted too (`string` gives \"undefined\");\n// put `coalesce` in front when a missing value should not be converted.\nconst number = (): FilterFn => (value: unknown): number => Number(value);\n\nconst string = (): FilterFn => (value: unknown): string => String(value);\n\nconst int = (): FilterFn => (value: unknown): number => parseInt(String(value), 10);\n\nconst float = (): FilterFn => (value: unknown): number => parseFloat(String(value));\n\n/** Replaces a falsy value (JavaScript's truthiness) with the typed literal: defaults(0) gives 0, defaults('0') \"0\" (B9). */\nconst defaults = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('defaults');\n const fallback = firstLiteral(opt, literals);\n return (value: unknown): unknown => {\n if (!value) {return fallback;}\n return value;\n };\n};\n\n/** Replaces only null / undefined (`defaults` also replaces 0, false and \"\") — SQL's COALESCE. */\nconst coalesce = (options: string[], literals?: readonly unknown[]): FilterFn => {\n const opt = options?.[0] ?? optionsRequired('coalesce');\n const fallback = firstLiteral(opt, literals);\n return (value: unknown): unknown => value ?? fallback;\n};\n\n/** \"\" → null, anything else unchanged. */\nconst nullIfEmpty = (): FilterFn => (value: unknown): unknown => (value === \"\") ? null : value;\n\nconst { eq, ne, not, lt, le, gt, ge, falsy, truthy, boolean } = coreFilters;\n\n/**\n * What `installFormats()` registers: factory and [min, max] argument count (B3 — the same bounds\n * lint uses), in the order the registry keeps them. The did-you-mean suggestion gives a tie to the\n * first registered, so the order is the one the full build registered up to 4.0.0-rc.3, when this\n * add-on had the 23 display filters and the core 24: the display filters, then that core set, each\n * in the source's (lint's) relative order. The core's 10 are registered here too, in their place\n * (the core registers them again when it first plans a binding, and a name registered again keeps\n * its place).\n */\nconst registered: Readonly<Record<string, FilterDefinition>> = {\n toFixed: { factory: toFixed, arity: [0, 1] },\n locale: { factory: locale, arity: [0, 1] },\n\n // The `String(value)` family passes an absent value through (B8 — see nullishPassthrough)\n upper: { factory: nullishPassthrough(upper), arity: [0, 0] },\n lower: { factory: nullishPassthrough(lower), arity: [0, 0] },\n capitalize: { factory: nullishPassthrough(capitalize), arity: [0, 0] },\n trim: { factory: nullishPassthrough(trim), arity: [0, 0] },\n slice: { factory: nullishPassthrough(slice), arity: [1, 2] },\n // The length is required too (the implementation reads both)\n padStart: { factory: nullishPassthrough(padStart), arity: [1, 2] },\n padEnd: { factory: nullishPassthrough(padEnd), arity: [1, 2] },\n repeat: { factory: nullishPassthrough(repeat), arity: [1, 1] },\n reverse: { factory: nullishPassthrough(reverse), arity: [0, 0] },\n truncate: { factory: nullishPassthrough(truncate), arity: [1, 2] },\n join: { factory: join, arity: [0, 1] },\n\n round: { factory: round, arity: [0, 1] },\n floor: { factory: floor, arity: [0, 1] },\n ceil: { factory: ceil, arity: [0, 1] },\n percent: { factory: percent, arity: [0, 1] },\n unit: { factory: nullishPassthrough(unit), arity: [1, 1] },\n\n // The locale-dependent three take a locale like `locale` does (`date(ja-JP)`), and a style (`date(ja-JP,long)`)\n date: { factory: date, arity: [0, 2] },\n time: { factory: time, arity: [0, 2] },\n datetime: { factory: datetime, arity: [0, 2] },\n ymd: { factory: ymd, arity: [0, 1] },\n hms: { factory: hms, arity: [0, 1] },\n\n // the core set of 4.0.0-rc.3 (the core's own: eq ne not lt le gt ge falsy truthy boolean)\n eq, ne, not, lt, le, gt, ge,\n add: numeric('add', (value, opt) => value + opt),\n sub: numeric('sub', (value, opt) => value - opt),\n mul: numeric('mul', (value, opt) => value * opt),\n div: numeric('div', (value, opt) => value / opt),\n mod: numeric('mod', (value, opt) => value % opt),\n abs: { factory: abs, arity: [0, 0] },\n clamp: { factory: clamp, arity: [2, 2] },\n int: { factory: int, arity: [0, 0] },\n float: { factory: float, arity: [0, 0] },\n falsy, truthy,\n defaults: { factory: defaults, arity: [1, 1] },\n coalesce: { factory: coalesce, arity: [1, 1] },\n boolean,\n number: { factory: number, arity: [0, 0] },\n string: { factory: string, arity: [0, 0] },\n nullIfEmpty: { factory: nullIfEmpty, arity: [0, 0] },\n // (added in 4.2: last, so the order of the others is unchanged)\n currency: { factory: currency, arity: [1, 2] },\n};\n\n/** The formats add-on's own filters (what `registered` holds beyond the core set), in that order. */\nexport const formatFilters: Readonly<Record<string, FilterDefinition>> = /*#__PURE__*/ Object.fromEntries(\n /*#__PURE__*/ Object.entries(registered).filter(([name]) => !(name in coreFilters)),\n);\n\nlet installed = false;\n\n/** Puts the formats add-on in the registry. Idempotent. */\nexport function installFormats(): void {\n if (installed) return;\n installed = true;\n registerFilters(registered);\n}\n","/**\n * The formats add-on (@wcstack/state/features/formats): the 38 filters that compute and show a value\n * (display, string shaping, dates — locale-aware —, arithmetic, conversions, missing values).\n */\nimport type { Feature } from \"../hooks\";\nimport { installFormats } from \"../filters/formats\";\n\nexport const formats: Feature = { name: \"formats\", install: installFormats };\nexport default formats;\n"],"mappings":"iQAqCA,IA+DIA,EA/DEC,EAAsBC,GACzBC,IACC,IAAMC,EAAWF,EAAQC,GAEzB,OAAQE,GAAsC,MAATA,EAAgBA,EAAQD,EAASC,IA4DtEC,EAAQ,KAMZ,SAASC,IACP,GAAIC,EAAOC,SAAWT,EAAM,CAC1BA,EAAOQ,EAAOC,OACd,IACEH,EAAQI,KAAKC,oBAAoBX,GAAM,EACzC,OACEY,QAAQC,KAAK,oBAAoBC,KAAsB,CAACd,OACxDM,EAAQ,IACV,CACF,CACA,OAAOA,CACT,CASA,IAqGMS,EAAS,CAAC,OAAQ,OAAQ,SAAU,SAO1C,SAASC,EAAYb,EAAmBc,GACtC,IAAKC,EAAKC,GAAiChB,GAAW,GACtD,YAAc,IAAVgB,QAA+B,IAARD,GAAqBH,EAAOK,SAASF,MAAOA,EAAKC,GAAS,MAAC,EAAWD,SACnF,IAAVC,IAAwBJ,EAAOK,SAASD,IAAQE,EAAaJ,EAAIE,GAC9D,CAACD,EAAKC,EACf,CAGA,IAkGQG,KAAIC,KAAIC,SAAKC,EAAIC,KAAIC,KAAIC,KAAIC,QAAOC,SAAQC,WAAYC,EAW1DC,EAAyD,CAC7DC,QAAS,CAAEhC,QApTIC,IACf,IAAMgC,EAAMC,EAAajC,IAAU,IAAM,IAAK,WAC9C,OAAQE,IACe,iBAAVA,GAAqBgC,EAAkB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ChB,IAAM4H,EAAO5H,IAAU,IAAM0E,EAAgB,YACvCtC,EAAWpC,IAAU,GACrB4E,EAAS,CAAE5D,MAAO,WAAY2G,SAAUC,GAC9C,IACE,IAAIrH,KAAKsH,aAAa,KAAMjD,GAE5B,IAAMkD,EAASvH,KAA2DwH,oBAAoB,YAC9F,GAAID,IAAUA,EAAM7G,SAAS2G,EAAKpF,eAAgB,MAAM,CAC1D,OACEwF,EAAgBJ,EAClB,CACA,OAAQ1H,IACe,iBAAVA,GAAqBgC,EAAkB,WAAYhC,GACvDA,EAAMmC,eAAeD,GAAYhC,IAAiBwE,KAwP5BzC,MAAO,CAAC,EAAG,KAQxC8F,GAAY,ECnZHC,EAAmB,CAAEC,KAAM,UAAWC,QDsZ5C,WACDH,IACJA,GAAY,EACZI,EAAgBvG,GAClB,GCzZOwG,EAAQJ","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-
|
|
1
|
+
import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-BGUJ3HF6.js";var s=new WeakMap,r=!1,i=/^(?!prototype$)[^\d.*$][^.*]*$/;function f(t,e){let l=e.$listKeys,n=new Map;if(void 0!==l){(null===l||"object"!=typeof l)&&o("$listKeys must be an object mapping list paths to a key field or function.");for(let e of Object.keys(l)){let s=l[e];"string"==typeof s?n.set(t.o(e),t=>t[s]):"function"==typeof s?n.set(t.o(e),s):o(`$listKeys "${e}" must be a field name or a function.`)}}s.set(e,n)}function u(t){if(null===t||"object"!=typeof t)return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function a(t,e,l){let n=new Map;for(let s of e){u(s)||o(`$listKeys "${t}": rows must be plain objects.`);let e=l(s);null==e&&o(`$listKeys "${t}": a row has no key.`),n.has(e)&&o(`$listKeys "${t}": duplicate key ${JSON.stringify(e)}.`),n.set(e,s)}return n}function y(t,e,l,n){if(r||!Array.isArray(n))return!1;let o=s.get(t.target)?.get(e);if(void 0===o)return!1;let f=t.it(e,l);if(!Array.isArray(f)||f===n)return!1;let u=a(e.t,f,o);a(e.t,n,o);let y=[],p=[],c=f.length===n.length;for(let t=0;t<n.length;t++){let e=n[t],l=u.get(o(e));y.push(l??e),void 0!==l&&p.push([t,l,e]),y[t]!==f[t]&&(c=!1)}let $=[];for(let[t,e,l]of p){for(let n of Object.keys(l))Object.is(e[n],l[n])||$.push([t,n,l[n]]);for(let n of Object.keys(e))!(n in l)&&null!==e[n]&&$.push([t,n,null])}if(c&&0===$.length)return!0;if(!c){r=!0;try{t.T(e,l,y)}finally{r=!1}}if($.length>0){let n=t.Ve(0===e.n?null:l,e);for(let[l,o,s]of $){if("__proto__"===o)continue;let r=n.f[l],f=i.test(o)?t.o(`${e.t}.*.${o}`):null;null===f?.getter?t.T(f,r,s):(r.R[o]=s,t.T(t.o(`${e.t}.*`),r,r.R,!0))}}return!0}var p={name:"list-keys",install(){t.de=e(t.de,f),t.Fe=l(n,t.Fe,y)}},c=p;export{c as default,p as listKeys};
|
|
2
2
|
//# sourceMappingURL=list-keys.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as e}from"../chunks/chunk-
|
|
1
|
+
import{b as e}from"../chunks/chunk-UBGJGMSG.js";import{a as t}from"../chunks/chunk-BGUJ3HF6.js";var i={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function o(t,o){let a=t.localName;if(a.includes("-"))return null;let l=(e=>[...i["*"],...Object.hasOwn(i,e)?i[e]:[]])(a);return l.includes(o)||e(1205,[a,o,l.join(", ")],o,l),(e,t)=>e[o](...t[0]instanceof Event?[]:t)}var a={name:"native-commands",install(){t.or=o}},l=a;export{l as default,a as nativeCommands};
|
|
2
2
|
//# sourceMappingURL=native-commands.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{m as e}from"../chunks/chunk-
|
|
1
|
+
import{m as e}from"../chunks/chunk-UPSLR4FS.js";import{b as t}from"../chunks/chunk-UBGJGMSG.js";import{a as r,b as l,c as n,d as s,j as a}from"../chunks/chunk-BGUJ3HF6.js";var i="$recursion",o=new WeakMap,c=new WeakSet,u=new WeakSet,h=0,d=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$=e=>`[wcs/recursion-${e}]`;function f(e,t){let r=r=>a(`${$("declaration-invalid")} ${i} ${e} "${String(t)}" ${r}`);("string"!=typeof t||""===t)&&a(`${$("declaration-invalid")} ${i} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&r('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&r("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&r('must have exactly one "*", at the end.'),t.includes("#")&&r('must not contain "#".')}return"$"===t[0]&&r('must not start with "$".'),t}var p=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function g(e,t){let r=`${e.l}.**`,l=t.slice(r.length);return(!t.startsWith(r)||""!==l&&"."!==l[0]||l.includes("**"))&&a(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function m(e,t,r){let l=g(e,t),n=function(e,t){for(let r=t;null!==r;r=r.l.ae){let t=e.nodeList.exec(r.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r}}return null}(e,r);return null===n&&a(`[wcs/recursion-context] "${t}" uses "**", which is bound to the depth of the row it is evaluated in; there is none here — use $getAll("${t}", []) for every depth.`),p(e,n.k)+l}function y(e,t,r){let l=new Set,n=new Set,s=(e,r,s)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&a(`${$("cycle")} "${r}" is reachable from itself: the data under "${t.l}" must be a tree.`),n.has(e)&&a(`${$("shared-list")} "${r}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),s+1>128&&a(`${$("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${s+1} (the limit is 128).`),n.add(e),0)),i=(n,a)=>{for(let o of n){r(a,o);let n=e.o(`${p(t,a)}.${t.key}`),c=e.read(n,o);s(c,n.t,a+1)&&(l.add(c),i(e.Ve(o,n).f,a+1),l.delete(c))}},o=e.o(t.l),c=e.read(o,null);s(c,t.l,0)&&(l.add(c),i(e.Ve(null,o).f,0))}function w(r,l){let n=function(t){let r=t[i],l=[],n=new Set;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e))!n.has(t)&&t.includes("**")&&l.push([t,Object.getOwnPropertyDescriptor(e,t)]),n.add(t);if(void 0===r)return l.length>0&&e(l[0][0]),null;(null===r||"object"!=typeof r||Array.isArray(r))&&a(`${$("declaration-invalid")} ${i} must be an object mapping one anchor path to its repeating sub-path.`);let s=Object.entries(r);1!==s.length&&a(`${$("declaration-invalid")} ${i} must declare exactly one anchor (it declares ${s.length}).`);let o=f("anchor",s[0][0]),c=f("repeat",s[0][1]),u=o.slice(0,-2),h=c.slice(0,-2),p=`.${c}`,g=new Map,m=[],y=`${u}.**`;for(let[e,t]of l){let r=e.slice(y.length);(!e.startsWith(y)||""!==r&&"."!==r[0]||r.includes("**"))&&a(`[wcs/recursion-anchor] "${e}": a recursive key is "${y}" followed by a path (the anchor is "${o}").`),(""===r||r.split(".").slice(1).some(e=>""===e))&&a(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&a(`${$("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),g.set(r,t.get),m.push([new RegExp(`^${d(o)}((?:${d(p)})*)${d(r)}$`),r])}return{l:u,step:p,key:h,families:g,matchers:m,owners:new Map,nodeList:new RegExp(`^${d(u)}((?:${d(`.*.${h}`)})*)$`)}}(l),s=o.has(r);null!==n?(s||h++,o.set(r,n),u.add(r),c.has(r)||function(r){c.add(r);let l=r,n=l.ot;l.ot=t=>{let s=o.get(r);if(t.t.includes("**")){let l=r.I.jt(t.t)===t;return void(u.has(r)||void 0===s&&l?t.getter=()=>e(t.t):l||n.call(r,t))}if(void 0!==s&&null===t.getter)for(let[e,r]of s.matchers)if(e.test(t.t)){t.getter=s.families.get(r),t.n>0&&(t.A=l.je++),s.owners.set(t,s.l+".**"+r);break}n.call(r,t)};let s=l.resolve;l.resolve=(e,t)=>{let l=o.get(r);return s.call(r,void 0!==l&&e.includes("**")?m(l,e,t):e,t)};let i=l.getAll;l.getAll=(e,t)=>{let n=o.get(r);if(void 0===n||!e.includes("**"))return i.call(r,e,t);if(void 0===t)return i.call(r,m(n,e,l.u));(!Array.isArray(t)||t.length>0)&&a(`${$("getall-form")} $getAll("${e}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=g(n,e),c=[];return y(r,n,(e,t)=>{for(let l of i.call(r,p(n,e)+s,r.H(t)))c.push(l)}),c};let h=l.yn;l.yn=(e,n,s,i)=>{let c=o.get(r);if(void 0===c||!e.includes("**"))return h.call(r,e,n,s,i);Array.isArray(n)||t(9,[e]),n.length>0&&a(`${$("setall-form")} $setAll("${e}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof s||!0===i?.spread)&&a(`${$("setall-form")} $setAll("${e}", [], value) with "**" takes a plain value (no mapper, no spread).`),l.Le>0&&t(8);let u=g(c,e),d=u.replace(/\.\d+(?=\.|$)/g,".*");for(;d.startsWith(c.step);)d=d.slice(c.step.length);let f=c.key.split(".");(""===d||d===`.${c.key}.length`||f.some((e,t)=>d===`.${f.slice(0,t+1).join(".")}`))&&a(`${$("structural-write")} "${e}" writes the recursion structure itself (a node, its "${c.key}" list or that list's length, or an object on the way to it).`);for(let t of c.families.keys()){let r=t;for(;r.startsWith(c.step);)r=r.slice(c.step.length);(d===r||d.startsWith(`${r}.`))&&a(`${$("readonly")} "${e}" writes into the recursive getter "${c.l}.**${t}".`)}let m=[];y(r,c,(e,t)=>m.push([e,t]));let w=0;for(let[e,t]of m)w+=h.call(r,p(c,e)+u,r.H(t),s);return w}}(r)):s&&(o.delete(r),h--)}function v(e,t){if(0===h)return!1;let r=o.get(e);if(void 0===r)return!1;for(let e=t;null!==e;e=e.d){let l=r.owners.get(e);void 0!==l&&a(`${$("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var k={name:"recursion",install(){r.de=l(r.de,w),r.element=l(r.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){u.delete(e)}(e)}),r.Fe=n(s,r.Fe,v)}},b=k;export{b as default,k as recursion};
|
|
2
2
|
//# sourceMappingURL=recursion.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,b as t,d as n}from"../chunks/chunk-JAEYZSVS.js";import{b as o,n as l,o as r,p as i}from"../chunks/chunk-UFIDBJBP.js";import"../chunks/chunk-BWGPKDHS.js";import{e as a,f as s}from"../chunks/chunk-4HLDITUB.js";import{a as u}from"../chunks/chunk-R5OJ52SF.js";import"../chunks/chunk-XEGL4FW5.js";import"../chunks/chunk-7QVEF5E3.js";import"../chunks/chunk-GGSHXG7N.js";import{a as c,b as d,c as f,d as h,f as p,h as m,j as g}from"../chunks/chunk-7ZU3CLEG.js";var $=new WeakMap,b=new WeakMap,w="will not graft: the root state failed to initialize.",y=new WeakSet,v=new WeakMap,k=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],j=["$commandTokens","$eventTokens","$on","$errorCallback"],O=e=>`[@wcstack/state] <${u.tagNames.state} mount="${e}">`,x=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),N=e=>e?.element?.isConnected?e:void 0;function C(e){let t=b.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function A(e,t){let n=b.get(t);if(b.delete(t),Array.isArray(n))for(let t of n)W(t,e)}function P(e){let t=$.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function S(e,t){console.error(`${O(e.t)} ${t}`),P(e),e.Je?.(),e.Je=null}function M(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function W(e,t){if(y.has(t))return S(e,"will not graft: its component is wired to its host.");let n=e.state,o=t.target,l=e.t.split("."),r=o;for(let e of l)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return S(e,`will not graft: the root state already has "${e.t}".`);let i=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,o){if("symbol"==typeof o)return;if(36!==o.charCodeAt(0))return e.proxy[n(o)];let l=e.proxy[o];return"$eqPath"===o?(e,t)=>l(n(e),n(t)):x.has(o)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,o,l)=>"symbol"!=typeof o&&(e.proxy[n(o)]=l,!0)})}(t,e.t);e.chroot=i;let a={},s={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:o,set:l,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==o||void 0!==l)s[`${e.t}.${n}`]={get:o&&function(){return o.call(i)},set:l&&function(e){l.call(i,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(i);s[`${e.t}.${n}`]={get:()=>t}}else a[n]=r}}if(void 0===r){for(let e=1;e<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.it(n,null)&&t.T(n,null,{})}t.T(t.o(e.t),null,a)}t.to(Object.defineProperties({},s));for(let e in s)t.Ve(t.o(e),null);e.engine=t;let c=v.get(t);void 0===c&&v.set(t,c=[]),c.push(e),e.el.isConnected&&M(e,"$connectedCallback"),e.Je?.(),e.Je=null}function E(e,t){let n=b.get(e);if(Array.isArray(n))for(let e of n)S(e,w);b.set(e,t)}var D=new WeakMap;function L(e,t){let n=e.getAttribute("mount");if(null===n)return null;let o={el:e,root:t,t:n,state:null,engine:null,chroot:null,Je:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(u.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=$.get(t);void 0===e&&$.set(t,e=new Map);let l=e.get(n);if(void 0!==l&&l!==o&&(null===l.engine?l.el.isConnected:N(l.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===l?.engine){let e=b.get(t);Array.isArray(e)&&b.set(t,e.filter(e=>e!==l)),l.Je?.(),l.Je=null}e.set(n,o)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{xo:!0,start(e){if(null!==r)return S(o,r);if($.get(t).get(n)===o){for(let t of k)if(void 0!==e[t])return S(o,`${t} is not run in a volume — declare it on the root state.`);for(let t of j)void 0!==e[t]&&console.warn(`${O(n)} ${t} is not run in a volume (it belongs to the root).`);return o.state=e,new Promise(e=>{o.Je=e;let n=N(l.get(t)),r=b.get(t);void 0!==n?W(o,n):C(t)?S(o,w):b.set(t,[...Array.isArray(r)?r:[],o])})}},Ge(){null!==o.engine&&M(o,"$connectedCallback")},Ln(){null!==o.engine&&M(o,"$disconnectedCallback")},reset(){g(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var J=new WeakMap,T=new WeakMap;function G(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||g(`${t} must be an array of state member names.`);let o=new Set;for(let e of n)("string"!=typeof e||""===e)&&g(`${t} entries must be non-empty strings.`),"$"===e[0]&&g(`${t} entry "${e}": internal ($) members are never exposed.`),o.has(e)&&g(`${t} entry "${e}" is duplicated.`),o.add(e);return n}function R(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let o=document.createDocumentFragment();for(let e of[...t.childNodes])o.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&g("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,o){e.includes("-")||g(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&g(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(o),r=G(o,"$bindables"),i=G(o,"$commands");for(let e of r){let t=l.get(e);void 0===t&&g(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&g(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of i){let t=l.get(e);void 0===t&&g(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&g(`$commands entry "${e}" is not a method: list it in $bindables.`)}let a={tag:e,bindables:r},s=new WeakMap,c=new WeakMap,d=o=>{if(s.has(o))return s.get(o);if(o.hasAttribute("data-wc-definition"))return null;let l=o.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let i=l.querySelector(u.tagNames.state);return s.set(o,i),J.set(o,a),null===i&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${u.tagNames.state}>: no change events.`),i},f=e=>d(e)?.engine??null,h=e=>Promise.resolve(d(e)?.initializePromise).then(()=>{let t=c.get(e);c.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,o]of t)n.proxy[e]=o});class p extends HTMLElement{static{this.wcBindable=0===r.length&&0===i.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===i.length?{}:{commands:i.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==d(this)&&h(this)}get stateElement(){return d(this)}}for(let[e,t]of l)"function"==typeof t.value?Object.defineProperty(p.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(p.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=c.get(this);void 0===n&&c.set(this,n=[]),n.push([e,t])}}});customElements.define(e,p)}(n.localName,o,l,t)},Ge(){},Ln(){},reset(){g("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var q=new WeakMap,z=new WeakSet,H=new WeakMap,V=new WeakMap,B="data-wcs-wired",F=new WeakMap,X=new WeakMap,I=new WeakMap,U=0,Y=new Set,K={},Z=["$watch","$stream","$renderedCallback"],Q=e=>e.split(".",1)[0];function _(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ee(e,t){let n=e.a,o=Q(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(B);else if(!ne(n,o)){let e=n.getAttribute(B)?.split(" ")??[];e.includes(o)||n.setAttribute(B,[...e,o].join(" "))}F.get(n)?.pe===o&&g(`<${n.localName}>.${o} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=q.get(n);void 0===l&&q.set(n,l=[]),l.push(e),t&&z.add(e);let r=H.get(n);return void 0===r&&H.set(n,r=new Map),r.has(o)||r.set(o,n[o]),V.get(n)?.(),!1}function te(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${u.tagNames.state}[bind-component]`)}function ne(e,t){let n=e.getAttribute(u.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function oe(t){let n=t.parentElement;for(;null!==n&&!te(n);)n=n.parentElement;let o=l.get(n??t.getRootNode()),r=o?.element;(r?.isConnected?r.V:null===n)&&(null===n?e(t):i(o,t))}var le=new Set;function re(e,t){le.has(e)||(le.add(e),console.warn(`[@wcstack/state] ${t}`))}var ie=(e,t)=>t in e.state;function ae(e,t){let n=se(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function se(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function ue(e,t,n){if(null!==n.getter)return;let o,l=e.host,r=l.engine,i=Q(n.t),s=l.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.d)return function(e,t){let n,o=t.d;for(;null!==o&&void 0===(n=e.dt.get(o));)o=o.d;if(null===o||void 0===n)return;let l=e.x,r=e.host.engine,i=r.o(n.p.t+t.t.slice(o.t.length));if(null===i.getter)return;let s=n,u=()=>{let n=ce(e,s.r);return 0===t.n?n:(r.resolve(_(i.t,[...r.H(n),...l.H(a(l.u,t.n))]),null),r.rr)};t.getter=()=>{let e=u();return i.n>0&&null===e?void 0:r.v(i,e)},null!==i.ie&&(t.ie=n=>{let o=u();de(e,s.e,()=>r.T(i,o,n)),e.dn=t}),t.n>0&&(t.A=l.je++),e.dt.set(t,{e:s.e,p:i,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==i?ie(l,i):ae(l,i))return;o=s.me}else{if(null===t||null!==n.d||"$"===i[0]||ie(l,i))return;s=t,o=r.o(`${t.me.t}.${i}`)}let u=s.r,c=s;n.getter=()=>r.v(o,ce(e,u)),n.ie=t=>{de(e,c,()=>r.T(o,u,t)),e.dn=n},e.dt.set(n,{e:s,p:o,r:u})}function ce(e,t){return null!==t&&!t.y&&g(`The host row of <${e.host.el.localName}> was removed.`),t}function de(e,t,n){let o=Y.has(e.x);Y.add(e.x),e.from=t;try{n()}finally{o||Y.delete(e.x),e.from=null}}var fe=(e,t)=>t||!Y.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function he(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,U+=t?1:-1;let n=e.host.engine,o=I.get(n);void 0===o&&I.set(n,o=new Map);for(let n of e.fe){let e=o.get(n.e.me);void 0===e&&o.set(n.e.me,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.$);if(void 0!==l){null===e.re&&function(e,t){let n=e.host,o=n.engine;e.re=new Map;let l=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let i of Object.getOwnPropertyNames(r)){if(l.has(i))continue;l.add(i);let a=Object.getOwnPropertyDescriptor(r,i);if(void 0===a.get&&void 0===a.set||"$"===i[0]||i.includes("*"))continue;let s=Q(i);if(i!==s&&!ie(n,s))continue;let u=o.o(`${t.me.t}.${i}`);if(null===u.getter)ge(o,u,t.me);else if(!pe.has(u.getter))continue;e.re.set(u,e.x.o(i))}}(e,l);for(let o of e.re.keys())t&&null===o.getter&&ge(n,o,l.me),n.P.be(n,o,l.r);e.re.size>0&&n.we(),t&&function(e,t){let n=e.host.engine;for(let[o,l]of e.re){let r=n.v(o.d,t.r);if(null===r||"object"!=typeof r||!(o.s in r))continue;let i=e.host.el.localName;re(`${i}|${o.t}`,`[wcs/mount-export-shadowed] <${i}>.${e.host.pe}.${l.t} is exported at "${o.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var pe=new WeakSet;function me(e,t,n,o){let l=I.get(e)?.get(t)?.get(n);if(void 0===l)return null;let r=null;for(let e of l)""!==e.e.$||!0!==e.m.re?.has(o)||e.m===r||(null!==r&&g(`[wcs/mount-export-ambiguous] "${o.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function ge(e,t,n){let o=t.d,l=t.s,r=()=>{let t=e.read(o,e.u);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let o=r();if(null!==o)return o[l];let i=me(e,n,e.u,t);return null===i?void 0:i.x.read(i.re.get(t),null)},pe.add(t.getter),t.ie=i=>{let a=null===r()?me(e,n,e.u,t):null;if(null===a){let t=e.read(o,e.u);return void(null!==t&&"object"==typeof t&&(t[l]=i))}let s=a.re.get(t);void 0===se(a.host.state,s.t)?.set&&g(`Cannot write to "${s.t}" on mounted <${a.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),a.x.T(s,null,i)},t.n>0&&(t.A=e.je++)}function $e(e,t,n,o,l,r){if(null!==t.getter)return e.P.be(e,t,n),void e.we();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Xt(n),null!==n.c)for(let t of n.c.values())e.X(t)}else e.$n(t,n);c.ve?.(e,t,n,o,l,r),e.Ve(t,n)}function be(e){let t=e.m.x;for(let[n,o]of e.m.dt)o.e===e.e&&(0===n.n?t.P.be(t,n,null):t.nn(n.h[n.n],e=>t.P.be(t,n,e)));t.we()}function we(e,t,n,o,l,r,i){let s=n.t.slice(t.t.length);if(""===s)return be(e);let u,c=e.m,d=c.x;if(""===e.e.$){u=s.slice(1);let e=Q(u);if("$"===e[0]||ie(c.host,e)||c.host.entries.some(e=>""!==e.$&&(u===e.$||u.startsWith(`${e.$}.`))))return}else u=e.e.$+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(a(o,e).b);d.resolve(_(u,f),null);let h=d.rp,p=d.rr;h.n>0&&null===p||$e(d,h,p,l,r,i)}function ye(e,t,n,o,l,r,i){if(0===U)return;let s=Y.has(e);Y.add(e);try{let s=X.get(e);!i&&void 0!==s&&s.fn&&!Y.has(s.host.engine)&&function(e,t,n,o,l,r){let i,a=t;for(;null!==a&&void 0===(i=e.dt.get(a));)a=a.d;if(null===a||void 0===i)return;let s=e.host.engine;if(a===t&&e.dn===t)return void(e.dn=null);if(null!==i.r&&!i.r.y)return;let u=[...s.H(i.r),...e.x.H(n)];s.resolve(_(i.p.t+t.t.slice(a.t.length),u),null);let c=s.rp,d=s.rr;c.n>0&&null===d||de(e,i.e,()=>$e(s,c,d,o,l,r))}(s,t,n,o,l,r),i&&void 0!==s&&s.fn&&null!==s.re&&function(e,t){let n=e.host.entries.find(e=>""===e.$),o=e.host.engine;for(let[l,r]of e.re)r===t&&(o.P.be(o,l,n.r),o.we())}(s,t);let u=I.get(e);if(void 0===u)return;for(let[e,s]of u)if(t.ee(e)){let u=s.get(0===e.n?null:a(n,e.n));if(void 0!==u)for(let a of[...u])fe(a,i)&&we(a,e,t,n,o,l,r)}else if(e.ee(t))for(let[e,o]of[...s])if(0===t.n||a(e,t.n)===n)for(let e of[...o])fe(e,i)&&be(e)}finally{s||Y.delete(e)}}async function ve(e,o,l,i,a){if(i===K)return;let d=m(i);d&&await d;let f=F.get(o);f.engine&&i.$recursion&&g(`[wcs/mount-dollar-declaration] <${o.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let h=f.O;if(null!==h&&h.el!==e&&h.el.isConnected&&g(`<${o.localName}> already has a connected <${u.tagNames.state} bind-component="${f.pe}">.`),null!==h&&he(h,!1),null!==h&&function(e,t,n){let o=e.x,l=`[${u.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),i=new Set,a=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&i.add(e)},s=(e,t)=>{for(let n=e.Cn(t);null!==n&&n!==t;n=n.nextSibling)a(n);a(t)};for(let e of o.ce.values())for(let t of e)if(null===t.j)a(t.a);else for(let e of t.j.G)s(t.j,e.S);for(let e of o.oe.values())for(let t of[e.E,...e.B??[]])null!==t&&s(t,t.S);for(let t of e.L)t.parentNode===n&&r(t)&&i.add(t);if(0===i.size)return!1;let c=[...n.childNodes].filter(n=>n!==t&&!i.has(n)&&!e.L.includes(n)&&(r(n)||o.Wt&&n.textContent.includes("{{")));return c.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${c.length} node(s) added beside the content taken over are not bound.`),!0}(h,e,l))return async function(e,t,n,o){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await ke(e,o):o()}(h,e,l,a);let p=new s(i,new n);p.element=e,e.engine=p,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let o=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof o&&"constructor"!==t&&n.set(o,null)}let o=(t,n,o)=>Reflect.apply(t,e.proxy,o);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:o})),t}}(p,i);let $={el:e,L:[],x:p,host:f,fe:[],dt:new Map,fn:!1,dn:null,from:null,re:null};for(let e of f.entries)$.fe.push({m:$,e});f.O=$,X.set(p,$);let b=null===f.engine;b?c.element?.(p,"mounting"):(function(e){let t=e.x,n=e.host,o=n.engine,l=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Q(e.$);ie(n,t)&&(e.$!==t||ae(n,t))&&re(`${l}.${e.$}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.pe}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=o.v(r.me,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&re(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${r.me.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let i=Z.filter(e=>void 0!==n.state[e]);i.length>0&&re(`${l}.${n.pe}$`,`[wcs/mount-dollar-declaration] <${l}>: ${i.join(", ")} ${1===i.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let a=t.ot;t.ot=n=>{ue(e,r,n),a.call(t,n)};let s=[...t.I.all()];for(let t of s)ue(e,r,t);for(let e of s)a.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=X.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}($),he($,!0),y.add(p),A(p,l));let w=c.hr?.(l);r(p,l),w?.(),$.L=[...l.childNodes],t(),b&&p.En(),Object.defineProperty(o,f.pe,{configurable:!0,enumerable:!0,get:()=>p.proxy});let v=o.$stateReadyCallback;if("function"==typeof v)try{let e=v.call(o,f.pe);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}a(),e.isConnected?(await p.Se("$connectedCallback"),b&&e.isConnected&&c.element?.(p,"connected")):he($,!1)}async function ke(e,t){he(e,!0);for(let t of e.fe)be(t);t?.(),!e.broken&&(await e.x.Se("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function je(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=l.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){E(t,e);for(let e of D.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,a=i?r.host:r instanceof Element?r:null,s=()=>{let t=null===a?void 0:F.get(a)?.O;return t?.el===e?t:null},d=t=>{throw i&&E(r,e),t},f=!1;return{wt:()=>(null!==a&&a.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&g(`<${u.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await o(n).whenDefined(r);let i=F.get(n);if(void 0!==i)return i.pe!==t&&g(`<${r}> already has a <${u.tagNames.state} bind-component="${i.pe}">.`),i.state;let a=()=>(q.get(n)??[]).filter(e=>Q(e.name)===t),s=ne(n,t);if(s&&0===a().length&&oe(n),0===a().length&&(s||((e,t)=>!0===e.getAttribute(B)?.split(" ").includes(t))(n,t))){let e;await new Promise((o,l)=>{V.set(n,o),e=function(e,t){C(e)&&t();let n=D.get(e)??new Set;return D.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>l(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}V.delete(n);let c=a(),d=H.get(n),f=void 0!==d&&d.has(t)?d.get(t):n[t];if((null===f||"object"!=typeof f)&&g(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===f?"null":typeof f}.`),0===c.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${u.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),K}let h=[];for(let e of c){let o=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===o)&&g(`<${r}> maps "${e.name}" twice.`);let l=o.split(".").indexOf("*");if(l>=0){let n=o.split(".").slice(0,l).join(".");g(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:o,me:e.o,r:e.r,ro:z.has(e)}),e.engine.xn(e),""!==o&&delete n[e.name]}let p=0===c.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(f):f;return F.set(n,i={el:n,pe:t,state:p,engine:0===c.length?null:c[0].engine,entries:h,O:null}),p}(e,n,a,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${u.tagNames.state}> to be a direct child of a custom element.`))).catch(d),async start(t,n){await ve(e,a,i?r:a,t,()=>{f=!0,n()}).catch(e=>{let t=s();return!f&&null!==t&&(t.broken=!0),d(e)})},Ge(){let t=s();null!==t?ke(t).catch(e=>console.error(e)):f?Promise.resolve().then(()=>{if(e.parentNode===r)return ve(e,a,i?r:a,F.get(a).state,()=>{})}).catch(e=>console.error(e)):V.has(a)&&oe(a)},Ln(){let e=s();null!==e&&(he(e,!1),!e.broken&&(e.x.Se("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){g(`re-setting a component's state is not supported: write <${a?.localName}>.${n} instead.`)}}}var Oe={name:"scopes",install(){c.ct=f(p,c.ct,L),c.ct=f(p,c.ct,R),c.ct=f(p,c.ct,je),c.ar=ee,c.$o=te,c.element=d(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=v.get(e)??[];if("disconnected"===t)for(let e of n)P(e);else if("reset"!==t&&N(l.get(e.root))===e){A(e,e.root);for(let e of n)$.get(e.root).has(e.t)||$.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();A(e,n),function(e,t){let n=t.host,o=void 0===n?void 0:J.get(n);void 0!==o&&T.set(e,{host:n,def:o})}(e,n)}),c.ve=d(c.ve,(e,t,n,o,l,r)=>{(function(e,t,n,o){let l=T.get(e);if(void 0===l)return;let r=t.t.split(".",1)[0];if(!l.def.bindables.includes(r))return;let i=o&&t.t===r;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${r}-changed`,{detail:i?n:void 0,bubbles:!0}))})(e,t,l,r),ye(e,t,n,o,l,r,!1)}),c.ke=d(c.ke,(e,t,n)=>ye(e,t,n,void 0,void 0,!1,!0)),c.Ae=f(h,c.Ae,(e,t,n,o,l)=>(function(e,t){let n=v.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&g(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let o,l=X.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===o;e=e.d)o=l.dt.get(e);if(void 0===o)return!1;let r=o.e;return!((null===r.r||r.r.y)&&!r.ro)&&(!!n||(ce(l,r.r),void g(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.pe}${""===r.$?"":`.${r.$}`}#ro: ${r.me.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let e=c.de;c.de=(t,n)=>{let o=v.get(t);void 0!==o&&o.length>0&&g(`re-setting a root state with grafted volumes (${o.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=I.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&g("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},xe=Oe;export{xe as default,Oe as scopes};
|
|
1
|
+
import{a as e,b as t,d as n}from"../chunks/chunk-BYQBV3ZC.js";import{b as o,n as l,o as r,p as i}from"../chunks/chunk-4ECL4ITF.js";import"../chunks/chunk-2RBI6DVS.js";import{e as a,f as s}from"../chunks/chunk-BI4645UG.js";import{a as u}from"../chunks/chunk-CIBJLAA3.js";import"../chunks/chunk-JK3B3LLB.js";import"../chunks/chunk-UPSLR4FS.js";import"../chunks/chunk-UBGJGMSG.js";import{a as c,b as f,c as d,d as h,f as p,h as m,j as g}from"../chunks/chunk-BGUJ3HF6.js";var $=new WeakMap,b=new WeakMap,w="will not graft: the root state failed to initialize.",y=new WeakSet,v=new WeakMap,k=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],j=["$commandTokens","$eventTokens","$on","$errorCallback"],O=e=>`[@wcstack/state] <${u.tagNames.state} mount="${e}">`,x=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),N=e=>e?.element?.isConnected?e:void 0;function C(e){let t=b.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function A(e,t){let n=b.get(t);if(b.delete(t),Array.isArray(n))for(let t of n)W(t,e)}function P(e){let t=$.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function S(e,t){console.error(`${O(e.t)} ${t}`),P(e),e.Qe?.(),e.Qe=null}function M(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function W(e,t){if(y.has(t))return S(e,"will not graft: its component is wired to its host.");let n=e.state,o=t.target,l=e.t.split("."),r=o;for(let e of l)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return S(e,`will not graft: the root state already has "${e.t}".`);let i=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,o){if("symbol"==typeof o)return;if(36!==o.charCodeAt(0))return e.proxy[n(o)];let l=e.proxy[o];return"$eqPath"===o?(e,t)=>l(n(e),n(t)):x.has(o)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,o,l)=>"symbol"!=typeof o&&(e.proxy[n(o)]=l,!0)})}(t,e.t);e.chroot=i;let a={},s={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:o,set:l,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==o||void 0!==l)s[`${e.t}.${n}`]={get:o&&function(){return o.call(i)},set:l&&function(e){l.call(i,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(i);s[`${e.t}.${n}`]={get:()=>t}}else a[n]=r}}if(void 0===r){for(let e=1;e<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.it(n,null)&&t.T(n,null,{})}t.T(t.o(e.t),null,a)}t.to(Object.defineProperties({},s));for(let e in s)t.He(t.o(e),null);e.engine=t;let c=v.get(t);void 0===c&&v.set(t,c=[]),c.push(e),e.el.isConnected&&M(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function D(e,t){let n=b.get(e);if(Array.isArray(n))for(let e of n)S(e,w);b.set(e,t)}var E=new WeakMap;function L(e,t){let n=e.getAttribute("mount");if(null===n)return null;let o={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(u.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=$.get(t);void 0===e&&$.set(t,e=new Map);let l=e.get(n);if(void 0!==l&&l!==o&&(null===l.engine?l.el.isConnected:N(l.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===l?.engine){let e=b.get(t);Array.isArray(e)&&b.set(t,e.filter(e=>e!==l)),l.Qe?.(),l.Qe=null}e.set(n,o)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{xo:!0,start(e){if(null!==r)return S(o,r);if($.get(t).get(n)===o){for(let t of k)if(void 0!==e[t])return S(o,`${t} is not run in a volume — declare it on the root state.`);for(let t of j)void 0!==e[t]&&console.warn(`${O(n)} ${t} is not run in a volume (it belongs to the root).`);return o.state=e,new Promise(e=>{o.Qe=e;let n=N(l.get(t)),r=b.get(t);void 0!==n?W(o,n):C(t)?S(o,w):b.set(t,[...Array.isArray(r)?r:[],o])})}},Je(){null!==o.engine&&M(o,"$connectedCallback")},Ln(){null!==o.engine&&M(o,"$disconnectedCallback")},reset(){g(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var B=new WeakMap,R=new WeakMap;function T(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||g(`${t} must be an array of state member names.`);let o=new Set;for(let e of n)("string"!=typeof e||""===e)&&g(`${t} entries must be non-empty strings.`),"$"===e[0]&&g(`${t} entry "${e}": internal ($) members are never exposed.`),o.has(e)&&g(`${t} entry "${e}" is duplicated.`),o.add(e);return n}function q(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let o=document.createDocumentFragment();for(let e of[...t.childNodes])o.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&g("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,o){e.includes("-")||g(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&g(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(o),r=T(o,"$bindables"),i=T(o,"$commands");for(let e of r){let t=l.get(e);void 0===t&&g(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&g(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of i){let t=l.get(e);void 0===t&&g(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&g(`$commands entry "${e}" is not a method: list it in $bindables.`)}let a={tag:e,bindables:r},s=new WeakMap,c=new WeakMap,f=o=>{if(s.has(o))return s.get(o);if(o.hasAttribute("data-wc-definition"))return null;let l=o.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let i=l.querySelector(u.tagNames.state);return s.set(o,i),B.set(o,a),null===i&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${u.tagNames.state}>: no change events.`),i},d=e=>f(e)?.engine??null,h=e=>Promise.resolve(f(e)?.initializePromise).then(()=>{let t=c.get(e);c.delete(e);let n=d(e);if(void 0!==t&&null!==n)for(let[e,o]of t)n.proxy[e]=o});class p extends HTMLElement{static{this.wcBindable=0===r.length&&0===i.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===i.length?{}:{commands:i.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==f(this)&&h(this)}get stateElement(){return f(this)}}for(let[e,t]of l)"function"==typeof t.value?Object.defineProperty(p.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=d(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(p.prototype,e,{configurable:!0,get(){return d(this)?.proxy[e]},set(t){let n=d(this);if(null!==n)n.proxy[e]=t;else{let n=c.get(this);void 0===n&&c.set(this,n=[]),n.push([e,t])}}});customElements.define(e,p)}(n.localName,o,l,t)},Je(){},Ln(){},reset(){g("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Q=new WeakMap,z=new WeakSet,H=new WeakMap,F=new WeakMap,J="data-wcs-wired",G=new WeakMap,I=new WeakMap,U=new WeakMap,V=0,X=new Set,Y={},K=["$watch","$stream","$renderedCallback"],Z=e=>e.split(".",1)[0];function _(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ee(e,t){let n=e.a,o=Z(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(J);else if(!ne(n,o)){let e=n.getAttribute(J)?.split(" ")??[];e.includes(o)||n.setAttribute(J,[...e,o].join(" "))}G.get(n)?.pe===o&&g(`<${n.localName}>.${o} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=Q.get(n);void 0===l&&Q.set(n,l=[]),l.push(e),t&&z.add(e);let r=H.get(n);return void 0===r&&H.set(n,r=new Map),r.has(o)||r.set(o,n[o]),F.get(n)?.(),!1}function te(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${u.tagNames.state}[bind-component]`)}function ne(e,t){let n=e.getAttribute(u.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function oe(t){let n=t.parentElement;for(;null!==n&&!te(n);)n=n.parentElement;let o=l.get(n??t.getRootNode()),r=o?.element;(r?.isConnected?r.V:null===n)&&(null===n?e(t):i(o,t))}var le=new Set;function re(e,t){le.has(e)||(le.add(e),console.warn(`[@wcstack/state] ${t}`))}var ie=(e,t)=>t in e.state;function ae(e,t){let n=se(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function se(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function ue(e,t,n){if(null!==n.getter)return;let o,l=e.host,r=l.engine,i=Z(n.t),s=l.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.d)return function(e,t){let n,o=t.d;for(;null!==o&&void 0===(n=e.ft.get(o));)o=o.d;if(null===o||void 0===n)return;let l=e.x,r=e.host.engine,i=r.o(n.p.t+t.t.slice(o.t.length));if(null===i.getter)return;let s=n,u=()=>{let n=ce(e,s.r);return 0===t.n?n:(r.resolve(_(i.t,[...r.H(n),...l.H(a(l.u,t.n))]),null),r.rr)};t.getter=()=>{let e=u();return i.n>0&&null===e?void 0:r.v(i,e)},null!==i.ie&&(t.ie=n=>{let o=u();fe(e,s.e,()=>r.T(i,o,n)),e.dn=t}),t.n>0&&(t.A=l.je++),e.ft.set(t,{e:s.e,p:i,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==i?ie(l,i):ae(l,i))return;o=s.me}else{if(null===t||null!==n.d||"$"===i[0]||ie(l,i))return;s=t,o=r.o(`${t.me.t}.${i}`)}let u=s.r,c=s;n.getter=()=>r.v(o,ce(e,u)),n.ie=t=>{fe(e,c,()=>r.T(o,u,t)),e.dn=n},e.ft.set(n,{e:s,p:o,r:u})}function ce(e,t){return null!==t&&!t.y&&g(`The host row of <${e.host.el.localName}> was removed.`),t}function fe(e,t,n){let o=X.has(e.x);X.add(e.x),e.from=t;try{n()}finally{o||X.delete(e.x),e.from=null}}var de=(e,t)=>t||!X.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function he(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,V+=t?1:-1;let n=e.host.engine,o=U.get(n);void 0===o&&U.set(n,o=new Map);for(let n of e.fe){let e=o.get(n.e.me);void 0===e&&o.set(n.e.me,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.$);if(void 0!==l){null===e.re&&function(e,t){let n=e.host,o=n.engine;e.re=new Map;let l=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let i of Object.getOwnPropertyNames(r)){if(l.has(i))continue;l.add(i);let a=Object.getOwnPropertyDescriptor(r,i);if(void 0===a.get&&void 0===a.set||"$"===i[0]||i.includes("*"))continue;let s=Z(i);if(i!==s&&!ie(n,s))continue;let u=o.o(`${t.me.t}.${i}`);if(null===u.getter)ge(o,u,t.me);else if(!pe.has(u.getter))continue;e.re.set(u,e.x.o(i))}}(e,l);for(let o of e.re.keys())t&&null===o.getter&&ge(n,o,l.me),n.P.be(n,o,l.r);e.re.size>0&&n.we(),t&&function(e,t){let n=e.host.engine;for(let[o,l]of e.re){let r=n.v(o.d,t.r);if(null===r||"object"!=typeof r||!(o.s in r))continue;let i=e.host.el.localName;re(`${i}|${o.t}`,`[wcs/mount-export-shadowed] <${i}>.${e.host.pe}.${l.t} is exported at "${o.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var pe=new WeakSet;function me(e,t,n,o){let l=U.get(e)?.get(t)?.get(n);if(void 0===l)return null;let r=null;for(let e of l)""!==e.e.$||!0!==e.m.re?.has(o)||e.m===r||(null!==r&&g(`[wcs/mount-export-ambiguous] "${o.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function ge(e,t,n){let o=t.d,l=t.s,r=()=>{let t=e.read(o,e.u);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let o=r();if(null!==o)return o[l];let i=me(e,n,e.u,t);return null===i?void 0:i.x.read(i.re.get(t),null)},pe.add(t.getter),t.ie=i=>{let a=null===r()?me(e,n,e.u,t):null;if(null===a){let t=e.read(o,e.u);return void(null!==t&&"object"==typeof t&&(t[l]=i))}let s=a.re.get(t);void 0===se(a.host.state,s.t)?.set&&g(`Cannot write to "${s.t}" on mounted <${a.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),a.x.T(s,null,i)},t.n>0&&(t.A=e.je++)}function $e(e,t,n,o,l,r){if(null!==t.getter)return e.P.be(e,t,n),void e.we();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Xt(n),null!==n.c)for(let t of n.c.values())e.X(t)}else e.$n(t,n);c.ve?.(e,t,n,o,l,r),e.He(t,n)}function be(e){let t=e.m.x;for(let[n,o]of e.m.ft)o.e===e.e&&(0===n.n?t.P.be(t,n,null):t.nn(n.h[n.n],e=>t.P.be(t,n,e)));t.we()}function we(e,t,n,o,l,r,i){let s=n.t.slice(t.t.length);if(""===s)return be(e);let u,c=e.m,f=c.x;if(""===e.e.$){u=s.slice(1);let e=Z(u);if("$"===e[0]||ie(c.host,e)||c.host.entries.some(e=>""!==e.$&&(u===e.$||u.startsWith(`${e.$}.`))))return}else u=e.e.$+s;let d=[];for(let e=t.n+1;e<=n.n;e++)d.push(a(o,e).b);f.resolve(_(u,d),null);let h=f.rp,p=f.rr;h.n>0&&null===p||$e(f,h,p,l,r,i)}function ye(e,t,n,o,l,r,i){if(0===V)return;let s=X.has(e);X.add(e);try{let s=I.get(e);!i&&void 0!==s&&s.fn&&!X.has(s.host.engine)&&function(e,t,n,o,l,r){let i,a=t;for(;null!==a&&void 0===(i=e.ft.get(a));)a=a.d;if(null===a||void 0===i)return;let s=e.host.engine;if(a===t&&e.dn===t)return void(e.dn=null);if(null!==i.r&&!i.r.y)return;let u=[...s.H(i.r),...e.x.H(n)];s.resolve(_(i.p.t+t.t.slice(a.t.length),u),null);let c=s.rp,f=s.rr;c.n>0&&null===f||fe(e,i.e,()=>$e(s,c,f,o,l,r))}(s,t,n,o,l,r),i&&void 0!==s&&s.fn&&null!==s.re&&function(e,t){let n=e.host.entries.find(e=>""===e.$),o=e.host.engine;for(let[l,r]of e.re)r===t&&(o.P.be(o,l,n.r),o.we())}(s,t);let u=U.get(e);if(void 0===u)return;for(let[e,s]of u)if(t.ee(e)){let u=s.get(0===e.n?null:a(n,e.n));if(void 0!==u)for(let a of[...u])de(a,i)&&we(a,e,t,n,o,l,r)}else if(e.ee(t))for(let[e,o]of[...s])if(0===t.n||a(e,t.n)===n)for(let e of[...o])de(e,i)&&be(e)}finally{s||X.delete(e)}}async function ve(e,o,l,i,a){if(i===Y)return;let f=m(i);f&&await f;let d=G.get(o);d.engine&&i.$recursion&&g(`[wcs/mount-dollar-declaration] <${o.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let h=d.O;if(null!==h&&h.el!==e&&h.el.isConnected&&g(`<${o.localName}> already has a connected <${u.tagNames.state} bind-component="${d.pe}">.`),null!==h&&he(h,!1),null!==h&&function(e,t,n){let o=e.x,l=`[${u.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),i=new Set,a=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&i.add(e)},s=(e,t)=>{for(let n=e.Cn(t);null!==n&&n!==t;n=n.nextSibling)a(n);a(t)};for(let e of o.ce.values())for(let t of e)if(null===t.D)a(t.a);else for(let e of t.D.G)s(t.D,e.S);for(let e of o.oe.values())for(let t of[e.E,...e.B??[]])null!==t&&s(t,t.S);for(let t of e.L)t.parentNode===n&&r(t)&&i.add(t);if(0===i.size)return!1;let c=[...n.childNodes].filter(n=>n!==t&&!i.has(n)&&!e.L.includes(n)&&(r(n)||o.Wt&&n.textContent.includes("{{")));return c.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${c.length} node(s) added beside the content taken over are not bound.`),!0}(h,e,l))return async function(e,t,n,o){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await ke(e,o):o()}(h,e,l,a);let p=new s(i,new n);p.element=e,e.engine=p,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let o=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof o&&"constructor"!==t&&n.set(o,null)}let o=(t,n,o)=>Reflect.apply(t,e.proxy,o);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:o})),t}}(p,i);let $={el:e,L:[],x:p,host:d,fe:[],ft:new Map,fn:!1,dn:null,from:null,re:null};for(let e of d.entries)$.fe.push({m:$,e});d.O=$,I.set(p,$);let b=null===d.engine;b?c.element?.(p,"mounting"):(function(e){let t=e.x,n=e.host,o=n.engine,l=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Z(e.$);ie(n,t)&&(e.$!==t||ae(n,t))&&re(`${l}.${e.$}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.pe}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=o.v(r.me,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&re(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${r.me.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let i=K.filter(e=>void 0!==n.state[e]);i.length>0&&re(`${l}.${n.pe}$`,`[wcs/mount-dollar-declaration] <${l}>: ${i.join(", ")} ${1===i.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let a=t.ot;t.ot=n=>{ue(e,r,n),a.call(t,n)};let s=[...t.I.all()];for(let t of s)ue(e,r,t);for(let e of s)a.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=I.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}($),he($,!0),y.add(p),A(p,l));let w=c.hr?.(l);r(p,l),w?.(),$.L=[...l.childNodes],t(),b&&p.En(),Object.defineProperty(o,d.pe,{configurable:!0,enumerable:!0,get:()=>p.proxy});let v=o.$stateReadyCallback;if("function"==typeof v)try{let e=v.call(o,d.pe);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}a(),e.isConnected?(await p.Se("$connectedCallback"),b&&e.isConnected&&c.element?.(p,"connected")):he($,!1)}async function ke(e,t){he(e,!0);for(let t of e.fe)be(t);t?.(),!e.broken&&(await e.x.Se("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function je(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=l.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){D(t,e);for(let e of E.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,a=i?r.host:r instanceof Element?r:null,s=()=>{let t=null===a?void 0:G.get(a)?.O;return t?.el===e?t:null},f=t=>{throw i&&D(r,e),t},d=!1;return{bt:()=>(null!==a&&a.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&g(`<${u.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await o(n).whenDefined(r);let i=G.get(n);if(void 0!==i)return i.pe!==t&&g(`<${r}> already has a <${u.tagNames.state} bind-component="${i.pe}">.`),i.state;let a=()=>(Q.get(n)??[]).filter(e=>Z(e.name)===t),s=ne(n,t);if(s&&0===a().length&&oe(n),0===a().length&&(s||((e,t)=>!0===e.getAttribute(J)?.split(" ").includes(t))(n,t))){let e;await new Promise((o,l)=>{F.set(n,o),e=function(e,t){C(e)&&t();let n=E.get(e)??new Set;return E.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>l(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}F.delete(n);let c=a(),f=H.get(n),d=void 0!==f&&f.has(t)?f.get(t):n[t];if((null===d||"object"!=typeof d)&&g(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===d?"null":typeof d}.`),0===c.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${u.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Y}let h=[];for(let e of c){let o=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===o)&&g(`<${r}> maps "${e.name}" twice.`);let l=o.split(".").indexOf("*");if(l>=0){let n=o.split(".").slice(0,l).join(".");g(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:o,me:e.o,r:e.r,ro:z.has(e)}),e.engine.xn(e),""!==o&&delete n[e.name]}let p=0===c.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(d):d;return G.set(n,i={el:n,pe:t,state:p,engine:0===c.length?null:c[0].engine,entries:h,O:null}),p}(e,n,a,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${u.tagNames.state}> to be a direct child of a custom element.`))).catch(f),async start(t,n){await ve(e,a,i?r:a,t,()=>{d=!0,n()}).catch(e=>{let t=s();return!d&&null!==t&&(t.broken=!0),f(e)})},Je(){let t=s();null!==t?ke(t).catch(e=>console.error(e)):d?Promise.resolve().then(()=>{if(e.parentNode===r)return ve(e,a,i?r:a,G.get(a).state,()=>{})}).catch(e=>console.error(e)):F.has(a)&&oe(a)},Ln(){let e=s();null!==e&&(he(e,!1),!e.broken&&(e.x.Se("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){g(`re-setting a component's state is not supported: write <${a?.localName}>.${n} instead.`)}}}var Oe={name:"scopes",install(){c.ct=d(p,c.ct,L),c.ct=d(p,c.ct,q),c.ct=d(p,c.ct,je),c.ar=ee,c.$o=te,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=v.get(e)??[];if("disconnected"===t)for(let e of n)P(e);else if("reset"!==t&&N(l.get(e.root))===e){A(e,e.root);for(let e of n)$.get(e.root).has(e.t)||$.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();A(e,n),function(e,t){let n=t.host,o=void 0===n?void 0:B.get(n);void 0!==o&&R.set(e,{host:n,def:o})}(e,n)}),c.ve=f(c.ve,(e,t,n,o,l,r)=>{(function(e,t,n,o){let l=R.get(e);if(void 0===l)return;let r=t.t.split(".",1)[0];if(!l.def.bindables.includes(r))return;let i=o&&t.t===r;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${r}-changed`,{detail:i?n:void 0,bubbles:!0}))})(e,t,l,r),ye(e,t,n,o,l,r,!1)}),c.ke=f(c.ke,(e,t,n)=>ye(e,t,n,void 0,void 0,!1,!0)),c.Fe=d(h,c.Fe,(e,t,n,o,l)=>(function(e,t){let n=v.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&g(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let o,l=I.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===o;e=e.d)o=l.ft.get(e);if(void 0===o)return!1;let r=o.e;return!((null===r.r||r.r.y)&&!r.ro)&&(!!n||(ce(l,r.r),void g(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.pe}${""===r.$?"":`.${r.$}`}#ro: ${r.me.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let e=c.de;c.de=(t,n)=>{let o=v.get(t);void 0!==o&&o.length>0&&g(`re-setting a root state with grafted volumes (${o.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=U.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&g("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},xe=Oe;export{xe as default,Oe as scopes};
|
|
2
2
|
//# sourceMappingURL=scopes.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"../chunks/chunk-56ZGITUJ.js";import{b as t,c as l}from"../chunks/chunk-V3HFN3MW.js";import"../chunks/chunk-JAEYZSVS.js";import{a as n,i as r,j as o,k as i,l as s,m as a}from"../chunks/chunk-UFIDBJBP.js";import"../chunks/chunk-BWGPKDHS.js";import"../chunks/chunk-4HLDITUB.js";import{a as c}from"../chunks/chunk-R5OJ52SF.js";import"../chunks/chunk-XEGL4FW5.js";import"../chunks/chunk-7QVEF5E3.js";import"../chunks/chunk-GGSHXG7N.js";import{a as u,b as f}from"../chunks/chunk-7ZU3CLEG.js";var d=e=>e.split(".").slice(0,2).join("."),p=class extends t{static find(e){return e.querySelector?.(c.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return d(this.version)===d(e)}};function m(e){let t=c.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends p{})}var h=()=>c.tagNames.ssr,g=Symbol.for("wcstack.ssr.snapshotBuilder"),b=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),v=e=>document.createComment(e),y=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,w=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),S=new WeakMap,N=new WeakMap,A=new WeakMap,x=new WeakSet,k=new WeakMap;function $(e,t){let l=[];for(let n=e;null!==n&&(l.push(n),n!==t);n=n.nextSibling);return l}function j(e,t,...l){for(let l of Array.from(e.attributes))t.setAttribute(l.name,l.value);return(t.content??t).append(...l),t}var T=e=>null===e.L?e.qe:e.L[e.L.length-1];function E(e,t,l){let n=[v(null===l?"wcs-[":`wcs-[:${l}`)];for(let e of t)null===l&&n.push(v("wcs-|")),n.push(...$(e.qe,T(e)));n.push(v("wcs-]")),e.after(...n);for(let e of n)x.add(e)}function q(e){if(e instanceof r){E(e.S,e.Re,null);for(let t of e.Re)W(t);return}let t=e.O;null!==t&&(E(e.G[e.G.length-1].S,[t],e.b),W(t))}function W(e){if(null!==e.c)for(let t of e.c)q(t)}var C=new Set(["script","style","template","textarea","title"]),O="data-wcs-raw",I=e=>C.has(e.localName)||e.localName===h();function M(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(v("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(v("wcs-s")):1===t.nodeType&&!I(t)&&M(t)}var R=0;function G(t,l){let n=t.getRootNode(),r=[l];for(let e of N.get(n)??[])e!==l&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let o=new Map;for(let e of r){let t=S.get(e);if(void 0===t)continue;let l=new Map;for(let t of e.oe.values())if(null!==t.E&&l.set(t.E.S,t.E),null!==t.B)for(let e of t.B)l.set(e.S,e);for(let t of e.ce.values())for(let e of t)if(null!==e.j)for(let t of e.j.G)l.set(t.S,e.j);let n=new Set;for(let[e,r]of t){o.set(e,r);let t=l.get(e);void 0!==t&&!n.has(t)&&e.isConnected&&(n.add(t),q(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=A.get(e);if(void 0!==t){let l=document.createTreeWalker(e,133,{acceptNode:e=>x.has(e)||1===e.nodeType&&t.has(e)&&D(e)?2:1}),n=[];for(let e=l.nextNode();null!==e;e=l.nextNode()){let l=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(I(e.parentNode)?k.has(e):t.has(l)&&w(l,"wcs-t:"))&&(k.has(e)||t.get(e)!==e.data):!t.has(e))&&n.push(e)}for(let e of n)e.remove()}let l=Array.from(e.childNodes);I(e)&&l.some(e=>k.has(e))&&e.setAttribute(O,l.map(e=>k.has(e)?`{{ ${k.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}M(9===n.nodeType?n.body:n);let i=document.createElement(h());i.setAttribute("version",e);let s=document.createElement("script");s.type="application/json",s.textContent=function(e){return JSON.stringify(e).replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`)}(function(e){let t={};for(let l of Object.keys(e)){if("$"===l[0])continue;let n=Object.getOwnPropertyDescriptor(e,l);void 0!==n.get||void 0!==n.set||"function"==typeof n.value||(t[l]=n.value)}return t}(l.target)),i.append(s);for(let[e,t]of o){if(!e.isConnected)continue;let l=e.parentNode;for(;null!==l&&"svg"!==l.localName&&"foreignObject"!==l.localName;)l=l.parentElement;let n="svg"===l?.localName,r=`wcs-${n?"s":"t"}${R++}`;e.replaceWith(v(`wcs-p:${r}`));let o=document.importNode(a(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(j(e,document.createElement("template"),...e.childNodes));if(n){let e=document.createElementNS(l.namespaceURI,"svg");e.append(o),o=e}let s=document.createElement("template");s.id=r,i.append(j(t,s,o))}t.before(i)}function P(e){!function(e){if(null!==e.querySelector(c.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>k.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${c.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===h())continue;let e=t.engine;null!=e&&G(t,e)}}var U=Symbol.for("wcstack.state.ssr.impl"),B=new Map,J=new WeakMap,D=e=>!0===u.$o?.(e),L=e=>1===e.nodeType&&!I(e)&&!D(e),V=e=>e.f.flat().concat(e.q??[]),F=e=>{for(let t of V(e))t.remove()};function H(e,t,l){let n=/^wcs-\[(?::(\d+))?/.exec(e.data),r=e.previousSibling,o=e.parentNode,i=[],a=e.nextSibling;for(e.remove();null!==a&&!y(a,"wcs-]");){let e=a.nextSibling;if(y(a,"wcs-|"))i.push([]),a.remove();else{0===i.length&&i.push([]);let l=i[i.length-1];w(a,"wcs-[")?e=H(a,t,l):(l.push(a),L(a)&&Z(a,t))}a=e}let c={branch:void 0===n[1]?null:Number(n[1]),f:i,q:a??o.appendChild(v("wcs-]"))},u=V(c);a=c.q.nextSibling;for(let e of u)l?.push(e),t&&s.add(e);return t&&null!==r?B.set(r,c):F(c),a}function Z(e,t){for(let l=e.firstChild;null!==l;)w(l,"wcs-[")?l=H(l,t):(L(l)&&Z(l,t),l=l.nextSibling)}function z(e,t,l){let n=e=>{for(let r of Array.from(e.childNodes))if(r.parentNode===e)if(8===r.nodeType){let e=r.data;try{if("wcs-s"===e)r.remove();else if("wcs-e"===e)r.replaceWith("");else if(e.startsWith("wcs-t:")){let t=v(`@@:${decodeURIComponent(e.slice(6))}`),l=r.nextSibling;for(;null!==l&&!y(l,"wcs-/t");){let e=l.nextSibling;l.remove(),l=e}l?.remove(),r.replaceWith(t)}else if(e.startsWith("wcs-p:")){let l=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==l){let t=r.parentNode,n="s"===e[10]?j(l,document.createElementNS(t.namespaceURI,"template"),...document.importNode(l.content.firstChild,!0).childNodes):document.importNode(l,!0);n.removeAttribute("id"),t.replaceChild(n,r)}}}catch{}}else 1===r.nodeType&&!I(r)&&(D(r)?J.set(r,{ssr:t,Oe:l}):n(r))};n(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let l=t.previousSibling;null!==l&&(8===l.nodeType||te(l)||"template"===l.localName);l=l.previousSibling)e.unshift(l);let l=0,n=0;if(e.forEach((e,t)=>{w(e,"wcs-[")?n++:y(e,"wcs-]")&&--n<0&&(n=0,l=t+1)}),0===n)continue;let r=0;for(let n=t.firstChild;null!==n;n=n.nextSibling)if(w(n,"wcs-["))r++;else if(y(n,"wcs-]")&&0===r--){t.prepend(...e.slice(l));break}}}(e),Z(e,l)}function X(e){let t=J.get(e);if(void 0===t||(J.delete(e),z(e,t.ssr,t.Oe),!t.Oe))return null;let l=u.Oe;return u.Oe=re,()=>{u.Oe=l,K()}}function K(){for(let e of B.values())F(e);B.clear()}function Q(e){let t=[];for(let l=document.createTreeWalker(e,128);l.nextNode();)t.push(l.currentNode);return t}function Y(e,t,l,n){let r=null;for(let n of e){let e=n[l];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===r||e.length>r[l].length)&&(r=n)}let o=r?.[n];if(null==o)return null;let i=r[l],s=""===i?t:t.slice(i.length+1);return""===o?s:""===s?o:`${o}.${s}`}function _(e,t,l){if(b()){if(l instanceof Array){for(let e=l.length;e-- >0;)o(l[e])&&l.splice(e,1);let e=t;if(l.some(i))x.add(e);else if(e.localName.includes("-")&&!D(e)){let t=new Map;for(let l=document.createTreeWalker(e,133);l.nextNode();)t.set(l.currentNode,l.currentNode.data);A.set(e,t)}return}if("string"==typeof l){if(k.set(t,l),I(t.parentNode))return;let e=v(`wcs-t:${encodeURIComponent(l)}`),n=v("wcs-/t");return t.before(e),void t.after(n)}let n=S.get(e);void 0===n&&S.set(e,n=new Map),n.set(t,l);let r=t.getRootNode(),s=N.get(r);return void 0===s&&N.set(r,s=new Set),void s.add(e)}if("string"!=typeof l&&B.size>0){let e=B.get(l);void 0!==e&&(B.delete(l),B.set(t,e))}}var ee=e=>null!==e&&8===e.nodeType&&[c.commentIfPrefix,c.commentElseIfPrefix,c.commentElsePrefix].includes(e.data),te=e=>3===e.nodeType&&""===e.data.trim(),le=e=>(B.get(e)?.q??e).nextSibling;function ne(e,t){if(t.length!==e.ln.childNodes.length)return!1;let l=e.On;for(let n=0;n<l.length;n++){let r=l[n],o=e.ln,i=t[r[0]];for(let e=0;;){if(o=o.childNodes[r[e]],i?.nodeName!==o.nodeName)return!1;if(++e===r.length)break;i=i.firstChild;for(let t=r[e];t>0&&null!==i;t--)i=le(i)}e.ko[n]=i}return!0}function re(e,t,l){if(0===B.size)return null;let n=t,r=0;if(!l){let e=c.commentIfPrefix;if(!y(t,e))for(let l=t.previousSibling;null!==l&&1!==l.nodeType&&(ee(l)&&r++,!y(l,e));l=l.previousSibling);for(let l=t.nextSibling;!B.has(n)&&null!==l&&!y(l,e)&&1!==l.nodeType;l=l.nextSibling)ee(l)&&(n=l)}let o=B.get(n);if(void 0===o)return null;if(!l&&o.branch!==r)return B.delete(n),F(o),null;let i=o.f.shift();if(0===o.f.length&&B.delete(n),o.q?.replaceWith(...$(t,n)),o.q=null,void 0===i)return null;let s=[];for(let e=0;e<i.length;e++){let t=B.get(i[e]);if(s.push(i[e]),void 0!==t)for(;e<i.length&&i[e]!==t.q;)e++}if(!ne(e,s)){let l=(e.In?e.root:e.ln).cloneNode(!0);s=e.In?[l]:[...l.childNodes],ne(e,s),(i[0]??o.f.find(e=>e.length>0)?.[0]??t).before(l);for(let e of i)e.remove()}return s}var oe={name:"ssr",install(){u.jn=_,u.hr=X;let t=u.element;u.element=(l,r)=>{"mounting"===r&&function(t){let l=t.element;if(!l.hasAttribute("enable-ssr")||b())return;let r=l.previousElementSibling,o=r?.localName===h(),i=o?r.getAttribute("version"):null,s=null===i||d(i)===d(e);if(s){let e=t,l=e.Se;e.Se=(e,n)=>"$connectedCallback"===e?void 0:l.call(t,e,n)}if(!o)return;let a=!s&&parseInt(i)<4,f=/^3\.(\d+)\.(\d+)$/.exec(i),p=null!==f&&(+f[1]-5||+f[2]-3)>=0;s||console.warn(`[@wcstack/state] <${h()} version="${i}"> does not match ${e}: its snapshot is discarded, and the page renders on the client from its own state.${a&&!p?" 3.x output keeps only the path of a text binding outside a template, so such a binding loses its filters: deploy @wcstack/server 4.0 with this client.":""}`);let m=s?r.querySelector('script[type="application/json"]'):null;if(null!==m){let e=JSON.parse(m.textContent||"{}"),l=t.target;for(let t of Object.keys(e)){let n=Object.getOwnPropertyDescriptor(l,t);void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)||(l[t]=e[t])}t.hydrated=!0}let g=l.getRootNode();for(let e of Array.from(g.querySelectorAll(`[${O}]`)))e.textContent=e.getAttribute(O),e.removeAttribute(O);let w=9===g.nodeType?g.body:g;a?function(e,t,l){let r=new Map,o=e=>{let t=e.parentElement;for(;null!==t&&!D(t);)t=t.parentElement;if(null===t)return null;let l=r.get(t);if(void 0===l){let e=o(t),i=t.querySelector(`:scope > ${c.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,l=[]);for(let r of n(t.getAttribute(c.bindAttributeName)??"")){let t=r.Ze;r.Ee[0]===i&&l.push([e?Y(e,t,1,0):t,r.Ee.slice(1).join("."),e&&t])}}return l},i=(e,t,l)=>{let n=o(e);if(null===n)return t;let r=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===r)return l?t:Y(n,t,0,1)??t;let i=r[1].replace(/#m\d+\./g,"").slice(0,-1);return n.some(e=>""===e[1]&&(e[0]===i||e[2]===i))?r[2]:Y(n,r[2],2,1)??r[2]};for(let t of Q(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let n=t.nextSibling;for(;null!==n&&!y(n,`@@wcs-${e[1]}-end:${e[2]}`);)n=n.nextSibling;if(null!==n){for(;t.nextSibling!==n;)t.nextSibling.remove();n.remove(),t.replaceWith(..."text"===e[1]?[v(`@@:${i(t,e[2],l)}`)]:[])}}let s=(e,l)=>{for(let n of Q(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(n.data)?.[1],r=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===r)continue;let o=document.importNode(r,!0),a=c.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,r)=>t+i(l??n,r))),s(o.content,l??n);let u=o.content.firstChild;n.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?o.content.childNodes:[o])}};s(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(w,r,p):z(w,r,s),r.remove(),s&&(u.Oe=re,queueMicrotask(()=>{K(),u.Oe=null}))}(l),t?.(l,r)},function(){let e=globalThis;e[U]={build:P,reset(){R=0}},void 0===e[g]&&(e[g]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[U].build(t),reset:()=>e[U].reset()})}(),u.To=f(u.To,m);for(let e of l())m(e)}},ie=oe;export{ie as default,oe as ssr};
|
|
1
|
+
import{a as e}from"../chunks/chunk-OKBVNGFK.js";import{b as t,c as l}from"../chunks/chunk-3Q7LGONS.js";import"../chunks/chunk-BYQBV3ZC.js";import{a as n,i as r,j as o,k as i,l as s,m as a}from"../chunks/chunk-4ECL4ITF.js";import"../chunks/chunk-2RBI6DVS.js";import"../chunks/chunk-BI4645UG.js";import{a as c}from"../chunks/chunk-CIBJLAA3.js";import"../chunks/chunk-JK3B3LLB.js";import"../chunks/chunk-UPSLR4FS.js";import"../chunks/chunk-UBGJGMSG.js";import{a as u,b as f}from"../chunks/chunk-BGUJ3HF6.js";var d=e=>e.split(".").slice(0,2).join("."),p=class extends t{static find(e){return e.querySelector?.(c.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return d(this.version)===d(e)}};function m(e){let t=c.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends p{})}var h=()=>c.tagNames.ssr,g=Symbol.for("wcstack.ssr.snapshotBuilder"),b=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),v=e=>document.createComment(e),y=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,w=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),S=new WeakMap,N=new WeakMap,A=new WeakMap,x=new WeakSet,k=new WeakMap;function C(e,t){let l=[];for(let n=e;null!==n&&(l.push(n),n!==t);n=n.nextSibling);return l}function $(e,t,...l){for(let l of Array.from(e.attributes))t.setAttribute(l.name,l.value);return(t.content??t).append(...l),t}var T=e=>null===e.L?e.ze:e.L[e.L.length-1];function j(e,t,l){let n=[v(null===l?"wcs-[":`wcs-[:${l}`)];for(let e of t)null===l&&n.push(v("wcs-|")),n.push(...C(e.ze,T(e)));n.push(v("wcs-]")),e.after(...n);for(let e of n)x.add(e)}function q(e){if(e instanceof r){j(e.S,e.Re,null);for(let t of e.Re)E(t);return}let t=e.O;null!==t&&(j(e.G[e.G.length-1].S,[t],e.b),E(t))}function E(e){if(null!==e.c)for(let t of e.c)q(t)}var W=new Set(["script","style","template","textarea","title"]),I="data-wcs-raw",M=e=>W.has(e.localName)||e.localName===h();function O(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(v("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(v("wcs-s")):1===t.nodeType&&!M(t)&&O(t)}var B=0;function R(t,l){let n=t.getRootNode(),r=[l];for(let e of N.get(n)??[])e!==l&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let o=new Map;for(let e of r){let t=S.get(e);if(void 0===t)continue;let l=new Map;for(let t of e.oe.values())if(null!==t.E&&l.set(t.E.S,t.E),null!==t.B)for(let e of t.B)l.set(e.S,e);for(let t of e.ce.values())for(let e of t)if(null!==e.D)for(let t of e.D.G)l.set(t.S,e.D);let n=new Set;for(let[e,r]of t){o.set(e,r);let t=l.get(e);void 0!==t&&!n.has(t)&&e.isConnected&&(n.add(t),q(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=A.get(e);if(void 0!==t){let l=document.createTreeWalker(e,133,{acceptNode:e=>x.has(e)||1===e.nodeType&&t.has(e)&&P(e)?2:1}),n=[];for(let e=l.nextNode();null!==e;e=l.nextNode()){let l=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(M(e.parentNode)?k.has(e):t.has(l)&&w(l,"wcs-t:"))&&(k.has(e)||t.get(e)!==e.data):!t.has(e))&&n.push(e)}for(let e of n)e.remove()}let l=Array.from(e.childNodes);M(e)&&l.some(e=>k.has(e))&&e.setAttribute(I,l.map(e=>k.has(e)?`{{ ${k.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}O(9===n.nodeType?n.body:n);let i=document.createElement(h());i.setAttribute("version",e);let s=document.createElement("script");s.type="application/json",s.textContent=function(e){return JSON.stringify(e).replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`)}(function(e){let t={};for(let l of Object.keys(e)){if("$"===l[0])continue;let n=Object.getOwnPropertyDescriptor(e,l);void 0!==n.get||void 0!==n.set||"function"==typeof n.value||(t[l]=n.value)}return t}(l.target)),i.append(s);for(let[e,t]of o){if(!e.isConnected)continue;let l=e.parentNode;for(;null!==l&&"svg"!==l.localName&&"foreignObject"!==l.localName;)l=l.parentElement;let n="svg"===l?.localName,r=`wcs-${n?"s":"t"}${B++}`;e.replaceWith(v(`wcs-p:${r}`));let o=document.importNode(a(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith($(e,document.createElement("template"),...e.childNodes));if(n){let e=document.createElementNS(l.namespaceURI,"svg");e.append(o),o=e}let s=document.createElement("template");s.id=r,i.append($(t,s,o))}t.before(i)}function G(e){!function(e){if(null!==e.querySelector(c.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>k.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${c.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===h())continue;let e=t.engine;null!=e&&R(t,e)}}var L=Symbol.for("wcstack.state.ssr.impl"),U=new Map,D=new WeakMap,P=e=>!0===u.$o?.(e),J=e=>1===e.nodeType&&!M(e)&&!P(e),V=e=>e.f.flat().concat(e.q??[]),z=e=>{for(let t of V(e))t.remove()};function F(e,t,l){let n=/^wcs-\[(?::(\d+))?/.exec(e.data),r=e.previousSibling,o=e.parentNode,i=[],a=e.nextSibling;for(e.remove();null!==a&&!y(a,"wcs-]");){let e=a.nextSibling;if(y(a,"wcs-|"))i.push([]),a.remove();else{0===i.length&&i.push([]);let l=i[i.length-1];w(a,"wcs-[")?e=F(a,t,l):(l.push(a),J(a)&&K(a,t))}a=e}let c={branch:void 0===n[1]?null:Number(n[1]),f:i,q:a??o.appendChild(v("wcs-]"))},u=V(c);a=c.q.nextSibling;for(let e of u)l?.push(e),t&&s.add(e);return t&&null!==r?U.set(r,c):z(c),a}function K(e,t){for(let l=e.firstChild;null!==l;)w(l,"wcs-[")?l=F(l,t):(J(l)&&K(l,t),l=l.nextSibling)}function Q(e,t,l){let n=e=>{for(let r of Array.from(e.childNodes))if(r.parentNode===e)if(8===r.nodeType){let e=r.data;try{if("wcs-s"===e)r.remove();else if("wcs-e"===e)r.replaceWith("");else if(e.startsWith("wcs-t:")){let t=v(`@@:${decodeURIComponent(e.slice(6))}`),l=r.nextSibling;for(;null!==l&&!y(l,"wcs-/t");){let e=l.nextSibling;l.remove(),l=e}l?.remove(),r.replaceWith(t)}else if(e.startsWith("wcs-p:")){let l=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==l){let t=r.parentNode,n="s"===e[10]?$(l,document.createElementNS(t.namespaceURI,"template"),...document.importNode(l.content.firstChild,!0).childNodes):document.importNode(l,!0);n.removeAttribute("id"),t.replaceChild(n,r)}}}catch{}}else 1===r.nodeType&&!M(r)&&(P(r)?D.set(r,{ssr:t,Ce:l}):n(r))};n(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let l=t.previousSibling;null!==l&&(8===l.nodeType||te(l)||"template"===l.localName);l=l.previousSibling)e.unshift(l);let l=0,n=0;if(e.forEach((e,t)=>{w(e,"wcs-[")?n++:y(e,"wcs-]")&&--n<0&&(n=0,l=t+1)}),0===n)continue;let r=0;for(let n=t.firstChild;null!==n;n=n.nextSibling)if(w(n,"wcs-["))r++;else if(y(n,"wcs-]")&&0===r--){t.prepend(...e.slice(l));break}}}(e),K(e,l)}function Z(e){let t=D.get(e);if(void 0===t||(D.delete(e),Q(e,t.ssr,t.Ce),!t.Ce))return null;let l=u.Ce;return u.Ce=re,()=>{u.Ce=l,H()}}function H(){for(let e of U.values())z(e);U.clear()}function Y(e){let t=[];for(let l=document.createTreeWalker(e,128);l.nextNode();)t.push(l.currentNode);return t}function X(e,t,l,n){let r=null;for(let n of e){let e=n[l];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===r||e.length>r[l].length)&&(r=n)}let o=r?.[n];if(null==o)return null;let i=r[l],s=""===i?t:t.slice(i.length+1);return""===o?s:""===s?o:`${o}.${s}`}function _(e,t,l){if(b()){if(l instanceof Array){for(let e=l.length;e-- >0;)o(l[e])&&l.splice(e,1);let e=t;if(l.some(i))x.add(e);else if(e.localName.includes("-")&&!P(e)){let t=new Map;for(let l=document.createTreeWalker(e,133);l.nextNode();)t.set(l.currentNode,l.currentNode.data);A.set(e,t)}return}if("string"==typeof l){if(k.set(t,l),M(t.parentNode))return;let e=v(`wcs-t:${encodeURIComponent(l)}`),n=v("wcs-/t");return t.before(e),void t.after(n)}let n=S.get(e);void 0===n&&S.set(e,n=new Map),n.set(t,l);let r=t.getRootNode(),s=N.get(r);return void 0===s&&N.set(r,s=new Set),void s.add(e)}if("string"!=typeof l&&U.size>0){let e=U.get(l);void 0!==e&&(U.delete(l),U.set(t,e))}}var ee=e=>null!==e&&8===e.nodeType&&[c.commentIfPrefix,c.commentElseIfPrefix,c.commentElsePrefix].includes(e.data),te=e=>3===e.nodeType&&""===e.data.trim(),le=e=>(U.get(e)?.q??e).nextSibling;function ne(e,t){if(t.length!==e.ln.childNodes.length)return!1;let l=e.On;for(let n=0;n<l.length;n++){let r=l[n],o=e.ln,i=t[r[0]];for(let e=0;;){if(o=o.childNodes[r[e]],i?.nodeName!==o.nodeName)return!1;if(++e===r.length)break;i=i.firstChild;for(let t=r[e];t>0&&null!==i;t--)i=le(i)}e.ko[n]=i}return!0}function re(e,t,l){if(0===U.size)return null;let n=t,r=0;if(!l){let e=c.commentIfPrefix;if(!y(t,e))for(let l=t.previousSibling;null!==l&&1!==l.nodeType&&(ee(l)&&r++,!y(l,e));l=l.previousSibling);for(let l=t.nextSibling;!U.has(n)&&null!==l&&!y(l,e)&&1!==l.nodeType;l=l.nextSibling)ee(l)&&(n=l)}let o=U.get(n);if(void 0===o)return null;if(!l&&o.branch!==r)return U.delete(n),z(o),null;let i=o.f.shift();if(0===o.f.length&&U.delete(n),o.q?.replaceWith(...C(t,n)),o.q=null,void 0===i)return null;let s=[];for(let e=0;e<i.length;e++){let t=U.get(i[e]);if(s.push(i[e]),void 0!==t)for(;e<i.length&&i[e]!==t.q;)e++}if(!ne(e,s)){let l=(e.In?e.root:e.ln).cloneNode(!0);s=e.In?[l]:[...l.childNodes],ne(e,s),(i[0]??o.f.find(e=>e.length>0)?.[0]??t).before(l);for(let e of i)e.remove()}return s}var oe={name:"ssr",install(){u.Dn=_,u.hr=Z;let t=u.element;u.element=(l,r)=>{"mounting"===r&&function(t){let l=t.element;if(!l.hasAttribute("enable-ssr")||b())return;let r=l.previousElementSibling,o=r?.localName===h(),i=o?r.getAttribute("version"):null,s=null===i||d(i)===d(e);if(s){let e=t,l=e.Se;e.Se=(e,n)=>"$connectedCallback"===e?void 0:l.call(t,e,n)}if(!o)return;let a=!s&&parseInt(i)<4,f=/^3\.(\d+)\.(\d+)$/.exec(i),p=null!==f&&(+f[1]-5||+f[2]-3)>=0;s||console.warn(`[@wcstack/state] <${h()} version="${i}"> does not match ${e}: its snapshot is discarded, and the page renders on the client from its own state.${a&&!p?" 3.x output keeps only the path of a text binding outside a template, so such a binding loses its filters: deploy @wcstack/server 4.0 with this client.":""}`);let m=s?r.querySelector('script[type="application/json"]'):null;if(null!==m){let e=JSON.parse(m.textContent||"{}"),l=t.target;for(let t of Object.keys(e)){let n=Object.getOwnPropertyDescriptor(l,t);void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)||(l[t]=e[t])}t.hydrated=!0}let g=l.getRootNode();for(let e of Array.from(g.querySelectorAll(`[${I}]`)))e.textContent=e.getAttribute(I),e.removeAttribute(I);let w=9===g.nodeType?g.body:g;a?function(e,t,l){let r=new Map,o=e=>{let t=e.parentElement;for(;null!==t&&!P(t);)t=t.parentElement;if(null===t)return null;let l=r.get(t);if(void 0===l){let e=o(t),i=t.querySelector(`:scope > ${c.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,l=[]);for(let r of n(t.getAttribute(c.bindAttributeName)??"")){let t=r.Ze;r.Ee[0]===i&&l.push([e?X(e,t,1,0):t,r.Ee.slice(1).join("."),e&&t])}}return l},i=(e,t,l)=>{let n=o(e);if(null===n)return t;let r=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===r)return l?t:X(n,t,0,1)??t;let i=r[1].replace(/#m\d+\./g,"").slice(0,-1);return n.some(e=>""===e[1]&&(e[0]===i||e[2]===i))?r[2]:X(n,r[2],2,1)??r[2]};for(let t of Y(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let n=t.nextSibling;for(;null!==n&&!y(n,`@@wcs-${e[1]}-end:${e[2]}`);)n=n.nextSibling;if(null!==n){for(;t.nextSibling!==n;)t.nextSibling.remove();n.remove(),t.replaceWith(..."text"===e[1]?[v(`@@:${i(t,e[2],l)}`)]:[])}}let s=(e,l)=>{for(let n of Y(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(n.data)?.[1],r=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===r)continue;let o=document.importNode(r,!0),a=c.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,r)=>t+i(l??n,r))),s(o.content,l??n);let u=o.content.firstChild;n.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?o.content.childNodes:[o])}};s(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(w,r,p):Q(w,r,s),r.remove(),s&&(u.Ce=re,queueMicrotask(()=>{H(),u.Ce=null}))}(l),t?.(l,r)},function(){let e=globalThis;e[L]={build:G,reset(){B=0}},void 0===e[g]&&(e[g]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[L].build(t),reset:()=>e[L].reset()})}(),u.To=f(u.To,m);for(let e of l())m(e)}},ie=oe;export{ie as default,oe as ssr};
|
|
2
2
|
//# sourceMappingURL=ssr.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t,c as e}from"../chunks/chunk-
|
|
1
|
+
import{a as t,c as e}from"../chunks/chunk-JK3B3LLB.js";import{a as n,b as r,c as s,d as i,e as l,j as o}from"../chunks/chunk-BGUJ3HF6.js";var a={},h=/\.\d/,u=new Set(Object.getOwnPropertyNames(Object.prototype)),f=0,c=!1,d=null,p=()=>{c=!1,f++};function m(){if(null===d)if("function"==typeof MessageChannel){let t=new MessageChannel;t.port1.onmessage=p,t.port1.unref?.(),d=()=>t.port2.postMessage(0)}else d=()=>setTimeout(p,0);return c||(c=!0,d()),f}function g(t,e){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(!n.has(t)){n.add(t);for(let n of t.Q){for(let r of e)if(n.ee(r)&&(n.n===r.n||!(r.n<t.n&&t.h[r.n+1].ee(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var y=class{constructor(t,e){this.active=!1,this.Pe=new Map,this.early=[],this.n=0,this.Ao=-1,this.Bn=new Set,this.He=null,this.engine=t,this.Ie=e}ur(){let t=this.engine;this.Pe.clear();let e=this.early;this.early=[];for(let e of this.Ie)e.getter=null!==e.p.getter||e.p.se,e.s=new WeakMap,this.prime(e,()=>{0===e.p.n?e.getter&&e.s.set(a,t.v(e.p,null)):this.Mn(e.p,1,null,n=>{e.getter&&this.prime(e,()=>e.s.set(n,t.v(e.p,n)))})});this.active=!0;let n=new Set;for(let[r,s,i,l]of e)if((null===s||s.y)&&Object.is(t.v(r,s),l)){n.add(r);for(let t of this.Ie)t.p===r&&this.ut(t,s,i,!0)}for(let t of this.Ie)t.getter&&0===t.p.n&&!this.Pe.has(t)&&g(v(t.p),n)&&this.ut(t,null,void 0,!0);this.Pe.size>0&&t.we()}prime(t,e){try{e()}catch(e){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,e),n.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:e})}}Fo(){this.active=!1,this.Pe.clear(),this.early=[]}Mn(t,e,n,r){let s=this.engine.Ve(n,t.h[e]);for(let n of s.f)e===t.n?r(n):this.Mn(t,e+1,n,r)}ut(t,e,n,r){let s=this.Pe.get(t);void 0===s&&this.Pe.set(t,s=new Map);let i=s.get(e);void 0===i?s.set(e,[n,this.n,r]):(i[1]<this.n&&(i[1]=this.n),i[2]||=r)}ve(t,e,n,r,s,i){if(this.active){(this.He??=new Set).add(t);for(let i of this.Ie){let l=i.p;l.n!==t.n||!l.ee(t)||this.ut(i,e,i.getter?i.s.get(e??a):l===t&&s&&this.engine._t&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else i&&this.early.push([t,e,n,r])}ke(t,e){if(this.active)for(let n of this.Ie)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===t.n&&n.p.ee(t)&&this.ut(n,e,n.s.get(e??a),!1)}Qt(t,e){if(!this.active)return;let n=null;for(let r of this.Ie){let s=r.p;if(!(s.n<t.n||s.h[t.n]!==t.o)){n??=new Set(e);for(let e of t.f)n.has(e)||(s.n===t.n?this.ut(r,e,void 0,!0):this.Mn(s,t.n+1,e,t=>this.ut(r,t,void 0,!0)))}}}Oe(){let t=this.He;if(this.He=null,!this.active||0===this.Pe.size)return;let e=this.Pe;this.Pe=new Map;let r=this.engine,s=[];for(let i of this.Ie){let l=e.get(i);if(void 0===l)continue;let o,u=[...l].filter(([t])=>null===t||t.y);u.length>1&&u.sort((t,e)=>$(t[0],e[0]));for(let[e,[l,f,c]]of u){let u,d="evaluate",p=r.u;this.n=f+1,r.Ae++;try{if(u=r.v(i.p,e),i.getter&&(i.s.set(e??a,u),Object.is(u,l)&&(h.test(i.t)||null!==e&&!c&&!(o??=null!==t&&g(v(i.p),t)))))continue;if(f>32){s.includes(i.t)||s.push(i.t);continue}r.u=e,n.at?.(r,{type:"state:watch-fired",path:i.t}),d="handler",i.handler.call(r.proxy,u,l,...r.H(e))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),n.at?.(r,{type:"state:watch-error",phase:d,path:i.t,error:t})}finally{r.u=p,this.n=0,r.Ae--}}}s.length>0&&this.Oo(s)}Oo(t){let e=m();e!==this.Ao&&(this.Ao=e,this.Bn.clear());let r=t.filter(t=>!this.Bn.has(t));if(0!==r.length){for(let t of r)this.Bn.add(t);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),n.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:r})}}};function v(t){for(;null===t.getter&&null!==t.d;)t=t.d;return t}function $(t,e){let n=[],r=[];for(let e=t;null!==e;e=e.l.ae)n.unshift(e.b);for(let t=e;null!==t;t=t.l.ae)r.unshift(t.b);for(let t=0;t<n.length&&t<r.length;t++)if(n[t]!==r[t])return n[t]-r[t];return n.length-r.length}var w="$streamStatus",b="$streamError",M=new Set(Object.getOwnPropertyNames(Object.prototype)),O=!1;function k(t,e){for(let n=t;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let t=Object.getOwnPropertyDescriptor(n,e);if(void 0!==t)return void 0!==t.get||void 0!==t.set||"function"==typeof t.value}return!1}var j=class{constructor(t,e,n){this.engine=t,this.entries=e,this.M=n}set(t,e,n){O=!0;try{this.engine.T(this.engine.o(`${t}.${e}`),null,n)}finally{O=!1}}dr(){for(let t of this.entries)this.start(t,!0)}fr(){for(let t of this.entries)t.dt=!1,t.J?.abort(),t.J=null}pr(){for(let t of this.entries)t.dt=!1,null!==t.J&&(t.J.abort(),t.J=null),this.set(w,t.name,"idle")}ke(t){let e=this.M.n;for(let n of this.entries)n.g===t&&(n.n=n.dt?Math.max(n.n,e):e,n.dt=!0)}Oe(){let t=this.engine,n=this.M,r=[];for(let s of this.entries){if(!s.dt)continue;let i=s.n;if(s.dt=!1,i>32)r.push(s.name),s.g.z=e;else{n.n=i+1,t.Ae++;try{this.start(s,!1)}finally{t.Ae--,n.n=0}}}r.length>0&&n.Oo(r)}start(t,n){let r,s=this.engine;if(null!==t.J&&t.J.abort(),t.J=null,null!==t.g){let i=t.g;i.getter=t.args;let l=i.Q.slice();J(i);try{r=s.read(i,null),function(t,e,n){null!==n&&"function"==typeof n?.then&&o(`$stream "${t}": args must be synchronous (it returned a Promise).`);for(let n of e.Q)n.n>0&&o(`$stream "${t}": args must not read a wildcard path ("${n.t}").`),(n.t===t||n.t===`${w}.${t}`||n.t===`${b}.${t}`)&&o(`$stream "${t}": args must not read the stream itself ("${n.t}").`)}(t.name,i,r)}catch(r){J(i);for(let t of l)t._n(i);if(i.z=e,n)throw r;return this.set(b,t.name,r),void this.set(w,t.name,"error")}}let i=new AbortController;t.J=i,s.T(s.o(t.name),null,t.U),this.set(b,t.name,null),this.set(w,t.name,"active"),this.mr(t,i,r)}async mr(t,e,n){let r=this.engine,s=e.signal,i=()=>!s.aborted&&t.J===e,l=r.o(t.name),o=this.M.n,a=m(),h=t=>{m()===a&&(this.M.n=o);try{t()}finally{this.M.n=0}},u=t.U;try{let e=await t.source(n,s);if(!i())return;let o=e=>{u=void 0!==t.Co?t.Co(u,e):e,h(()=>r.T(l,null,u))};if(null!==e&&"function"==typeof e?.getReader){let t=e.getReader();for(s.addEventListener("abort",()=>{t.cancel().catch(()=>{})});;){let e=await t.read();if(!i())return;if(e.done)break;o(e.value)}}else{if(null===e||"function"!=typeof e?.[Symbol.asyncIterator])throw new TypeError(`$stream "${t.name}": source must return an async iterable or a ReadableStream`);{let t=e[Symbol.asyncIterator]();for(s.addEventListener("abort",()=>{t.return?.()});;){let e=await t.next();if(!i())return;if(e.done)break;o(e.value)}}}if(!i())return;t.J=null,h(()=>this.set(w,t.name,"done"))}catch(n){if(!i())return;t.J=null,e.abort(),h(()=>{this.set(b,t.name,n),this.set(w,t.name,"error")})}}};function J(e){for(let t of e.Q){let n=t.W.indexOf(e);n>=0&&t.W.splice(n,1),t.mt.delete(e)}e.Q.length=0,e.z=t}var P=new WeakMap;function C(t){let e=P.get(t);return e?.target===t.target?e:void 0}function S(t,e){let r=new y(t,function(t,e){if(void 0===e)return[];(null===e||"object"!=typeof e)&&o("$watch must be an object mapping paths to handler functions.");let r=[];for(let s of Object.keys(e)){let i=e[s];(""===s||"$"===s[0]||s.includes("@")||u.has(s))&&o(`$watch path "${s}" is not a path of the state tree.`),"function"!=typeof i&&o(`$watch entry "${s}" must be a function.`);let l=t.o(s);n.So?.(t,l,!0),r.push({t:s,p:l,handler:i,getter:!1,s:new WeakMap})}return r}(t,e.$watch)),s=new j(t,function(t,e){let n=e.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&o("$stream must be an object mapping stream names to definitions.");let r=[],s={},i={};for(let l of Object.keys(n)){let a=n[l];(""===l||"$"===l[0]||/[.*]/.test(l)||M.has(l))&&o(`$stream entry "${l}" must be a flat property name.`),(null===a||"object"!=typeof a)&&o(`$stream entry "${l}" must be an object.`);let h=a.source,u=a.fold,f=a.args,c=a.initial;"function"!=typeof h&&o(`$stream entry "${l}" needs a source function.`),void 0!==u&&"function"!=typeof u&&o(`$stream entry "${l}": fold must be a function.`),void 0!==u&&!("initial"in a)&&o(`$stream entry "${l}": fold needs an initial value.`),void 0!==f&&"function"!=typeof f&&o(`$stream entry "${l}": args must be a function.`),k(e,l)&&o(`$stream entry "${l}" collides with a getter, setter or method of the state.`),void 0===e[l]&&(e[l]=c),s[l]="idle",i[l]=null,r.push({name:l,source:h,Co:u,U:c,J:null,dt:!1,n:0,g:void 0===f?null:t.o(`$streamArgs.${l}`),args:void 0===f?null:function(){return f(this)}})}return e[w]=s,e[b]=i,r}(t,e),r),i=P.get(t);void 0!==i&&(i.M.Fo(),i.Ct.fr()),P.set(t,{M:r,Ct:s,Je:i?.Je??!1,target:e})}function A(t,e){let n=P.get(t);if(void 0!==n&&"mounting"!==e&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==e&&(n.Je="connected"===e),n.target===t.target)){if("disconnected"===e)return n.M.Fo(),void n.Ct.pr();n.Je&&(n.M.ur(),n.Ct.dr())}}var I=["$streamStatus","$streamError"],Q={name:"temporal",install(){n.de=r(n.de,S),n.element=r(n.element,A),n.ve=r(n.ve,(t,e,n,r,s,i,l)=>C(t)?.M.ve(e,n,r,s,i,l)),n.ke=r(n.ke,(t,e,n)=>{let r=C(t);void 0!==r&&(r.M.ke(e,n),r.Ct.ke(e))}),n.Qt=r(n.Qt,(t,e,n)=>C(t)?.M.Qt(e,n)),n.Oe=r(n.Oe,t=>{let e=C(t);void 0!==e&&(e.M.Oe(),e.Ct.Oe())}),n.rt=s(l,n.rt,(t,e)=>{let n=e.split(".",1)[0];if(I.includes(n))return n===e?t.target[e]:t.read(t.o(e),null)}),n.Fe=s(i,n.Fe,(t,e)=>(!O&&36===e.t.charCodeAt(0)&&I.includes(e.t.split(".",1)[0])&&o(`"${e.t}" is read-only (the stream runtime owns it).`),!1))}},B=Q;export{B as default,Q as temporal};
|
|
2
2
|
//# sourceMappingURL=temporal.js.map
|