@wcstack/state 4.0.4 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.ja.md +6 -4
  2. package/README.md +6 -4
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.esm.js +1 -1
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/split/auto.js +1 -1
  8. package/dist/split/chunks/chunk-4HLDITUB.js +2 -0
  9. package/dist/split/chunks/chunk-4HLDITUB.js.map +1 -0
  10. package/dist/split/chunks/{chunk-TUQ3OPZQ.js → chunk-7QVEF5E3.js} +2 -2
  11. package/dist/split/chunks/{chunk-4NJBYXIT.js → chunk-7ZU3CLEG.js} +1 -1
  12. package/dist/split/chunks/chunk-7ZU3CLEG.js.map +1 -0
  13. package/dist/split/chunks/{chunk-PHAN6L23.js → chunk-BWGPKDHS.js} +2 -2
  14. package/dist/split/chunks/{chunk-M656SMUU.js → chunk-GGSHXG7N.js} +2 -2
  15. package/dist/split/chunks/chunk-JAEYZSVS.js +2 -0
  16. package/dist/split/chunks/{chunk-V6VVL4F3.js.map → chunk-JAEYZSVS.js.map} +1 -1
  17. package/dist/split/chunks/chunk-JZW5KGXQ.js +2 -0
  18. package/dist/split/chunks/{chunk-WE7XOZKS.js.map → chunk-JZW5KGXQ.js.map} +1 -1
  19. package/dist/split/chunks/{chunk-6MACFEK7.js → chunk-R5OJ52SF.js} +2 -2
  20. package/dist/split/chunks/chunk-UFIDBJBP.js +2 -0
  21. package/dist/split/chunks/{chunk-DFXQ7MFW.js → chunk-V3HFN3MW.js} +2 -2
  22. package/dist/split/chunks/{chunk-ZN52NEIB.js → chunk-XEGL4FW5.js} +2 -2
  23. package/dist/split/core.js +1 -1
  24. package/dist/split/features/devtools.js +1 -1
  25. package/dist/split/features/diagnostics.js +1 -1
  26. package/dist/split/features/diagnostics.js.map +1 -1
  27. package/dist/split/features/formats.js +1 -1
  28. package/dist/split/features/list-keys.js +1 -1
  29. package/dist/split/features/native-commands.js +1 -1
  30. package/dist/split/features/recursion.js +1 -1
  31. package/dist/split/features/scopes.js +1 -1
  32. package/dist/split/features/ssr.js +1 -1
  33. package/dist/split/features/temporal.js +1 -1
  34. package/dist/split/features/temporal.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/split/chunks/chunk-4NJBYXIT.js.map +0 -1
  37. package/dist/split/chunks/chunk-BMGEWHCR.js +0 -2
  38. package/dist/split/chunks/chunk-EM3Y3SJS.js +0 -2
  39. package/dist/split/chunks/chunk-EM3Y3SJS.js.map +0 -1
  40. package/dist/split/chunks/chunk-V6VVL4F3.js +0 -2
  41. package/dist/split/chunks/chunk-WE7XOZKS.js +0 -2
  42. /package/dist/split/chunks/{chunk-TUQ3OPZQ.js.map → chunk-7QVEF5E3.js.map} +0 -0
  43. /package/dist/split/chunks/{chunk-PHAN6L23.js.map → chunk-BWGPKDHS.js.map} +0 -0
  44. /package/dist/split/chunks/{chunk-M656SMUU.js.map → chunk-GGSHXG7N.js.map} +0 -0
  45. /package/dist/split/chunks/{chunk-6MACFEK7.js.map → chunk-R5OJ52SF.js.map} +0 -0
  46. /package/dist/split/chunks/{chunk-BMGEWHCR.js.map → chunk-UFIDBJBP.js.map} +0 -0
  47. /package/dist/split/chunks/{chunk-DFXQ7MFW.js.map → chunk-V3HFN3MW.js.map} +0 -0
  48. /package/dist/split/chunks/{chunk-ZN52NEIB.js.map → chunk-XEGL4FW5.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-4NJBYXIT.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.rt(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.We(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.Ae=l(n,t.Ae,y)}},c=p;export{c as default,p as listKeys};
1
+ import{a as t,b as e,c as l,d as n,j as o}from"../chunks/chunk-7ZU3CLEG.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._e(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.Ae=l(n,t.Ae,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-M656SMUU.js";import{a as t}from"../chunks/chunk-4NJBYXIT.js";var i={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function o(t,o){let a=t.localName;if(a.includes("-"))return null;let l=(e=>[...i["*"],...Object.hasOwn(i,e)?i[e]:[]])(a);return l.includes(o)||e(1205,[a,o,l.join(", ")],o,l),(e,t)=>e[o](...t[0]instanceof Event?[]:t)}var a={name:"native-commands",install(){t.or=o}},l=a;export{l as default,a as nativeCommands};
1
+ import{b as e}from"../chunks/chunk-GGSHXG7N.js";import{a as t}from"../chunks/chunk-7ZU3CLEG.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-TUQ3OPZQ.js";import{b as t}from"../chunks/chunk-M656SMUU.js";import{a as r,b as l,c as n,d as s,j as a}from"../chunks/chunk-4NJBYXIT.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.We(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.We(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.nt;l.nt=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.Ie++),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.je>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.Ae=n(s,r.Ae,v)}},b=k;export{b as default,k as recursion};
1
+ import{m as e}from"../chunks/chunk-7QVEF5E3.js";import{b as t}from"../chunks/chunk-GGSHXG7N.js";import{a as r,b as l,c as n,d as s,j as a}from"../chunks/chunk-7ZU3CLEG.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._e(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._e(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.Dt(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.De>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.Ae=n(s,r.Ae,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-V6VVL4F3.js";import{b as o,n as l,o as r,p as i}from"../chunks/chunk-BMGEWHCR.js";import"../chunks/chunk-PHAN6L23.js";import{e as a,f as s}from"../chunks/chunk-EM3Y3SJS.js";import{a as u}from"../chunks/chunk-6MACFEK7.js";import"../chunks/chunk-ZN52NEIB.js";import"../chunks/chunk-TUQ3OPZQ.js";import"../chunks/chunk-M656SMUU.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-4NJBYXIT.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 M(e,t){console.error(`${O(e.t)} ${t}`),P(e),e.Qe?.(),e.Qe=null}function S(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function W(e,t){if(y.has(t))return M(e,"will not graft: its component is wired to its host.");let n=e.state,o=t.target,l=e.t.split("."),r=o;for(let e of l)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return M(e,`will not graft: the root state already has "${e.t}".`);let i=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,o){if("symbol"==typeof o)return;if(36!==o.charCodeAt(0))return e.proxy[n(o)];let l=e.proxy[o];return"$eqPath"===o?(e,t)=>l(n(e),n(t)):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.rt(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._e(t.o(e),null);e.engine=t;let c=v.get(t);void 0===c&&v.set(t,c=[]),c.push(e),e.el.isConnected&&S(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function D(e,t){let n=b.get(e);if(Array.isArray(n))for(let e of n)M(e,w);b.set(e,t)}var E=new WeakMap;function T(e,t){let n=e.getAttribute("mount");if(null===n)return null;let o={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(u.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=$.get(t);void 0===e&&$.set(t,e=new Map);let l=e.get(n);if(void 0!==l&&l!==o&&(null===l.engine?l.el.isConnected: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 M(o,r);if($.get(t).get(n)===o){for(let t of k)if(void 0!==e[t])return M(o,`${t} is not run in a volume — declare it on the root state.`);for(let t of j)void 0!==e[t]&&console.warn(`${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)?M(o,w):b.set(t,[...Array.isArray(r)?r:[],o])})}},Xe(){null!==o.engine&&S(o,"$connectedCallback")},Ln(){null!==o.engine&&S(o,"$disconnectedCallback")},reset(){g(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var z=new WeakMap,Q=new WeakMap;function R(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=R(o,"$bindables"),i=R(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),z.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)},Xe(){},Ln(){},reset(){g("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var L=new WeakMap,H=new WeakSet,X=new WeakMap,I=new WeakMap,V="data-wcs-wired",_=new WeakMap,B=new WeakMap,F=new WeakMap,U=0,Y=new Set,G={},J=["$watch","$stream","$renderedCallback"],K=e=>e.split(".",1)[0];function Z(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=K(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(V);else if(!ne(n,o)){let e=n.getAttribute(V)?.split(" ")??[];e.includes(o)||n.setAttribute(V,[...e,o].join(" "))}_.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=L.get(n);void 0===l&&L.set(n,l=[]),l.push(e),t&&H.add(e);let r=X.get(n);return void 0===r&&X.set(n,r=new Map),r.has(o)||r.set(o,n[o]),I.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=K(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(Z(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.Ie++),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=F.get(n);void 0===o&&F.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=K(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.we(n,o,l.r);e.re.size>0&&n.Te(),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=F.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.Ie++)}function $e(e,t,n,o,l,r){if(null!==t.getter)return e.P.we(e,t,n),void e.Te();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Yt(n),null!==n.c)for(let t of n.c.values())e.X(t)}else e.$n(t,n);c.be?.(e,t,n,o,l,r),e._e(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.we(t,n,null):t.tn(n.h[n.n],e=>t.P.we(t,n,e)));t.Te()}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=K(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(Z(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=B.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(Z(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.we(o,l,n.r),o.Te())}(s,t);let u=F.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===G)return;let d=m(i);d&&await d;let 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._)a(t.a);else for(let e of t._.G)s(t._,e.S);for(let e of o.oe.values())for(let t of[e.E,...e.L??[]])null!==t&&s(t,t.S);for(let t of e.D)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.D.includes(n)&&(r(n)||o.Mt&&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.D=e.D.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,D:[],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=$,B.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=K(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=J.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.nt;t.nt=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.zt;t.zt=()=>{(function(e){for(;void 0!==e;e=B.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?.(),$.D=[...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.ke("$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.ke("$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:_.get(a)?.O;return t?.el===e?t:null},d=t=>{throw i&&D(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=_.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=()=>(L.get(n)??[]).filter(e=>K(e.name)===t),s=ne(n,t);if(s&&0===a().length&&oe(n),0===a().length&&(s||((e,t)=>!0===e.getAttribute(V)?.split(" ").includes(t))(n,t))){let e;await new Promise((o,l)=>{I.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())}I.delete(n);let c=a(),d=X.get(n),f=void 0!==d&&d.has(t)?d.get(t):n[t];if((null===f||"object"!=typeof f)&&g(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===f?"null":typeof f}.`),0===c.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${u.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),G}let h=[];for(let e of c){let o=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===o)&&g(`<${r}> maps "${e.name}" twice.`);let l=o.split(".").indexOf("*");if(l>=0){let n=o.split(".").slice(0,l).join(".");g(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:o,me:e.o,r:e.r,ro:H.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 _.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)})},Xe(){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,_.get(a).state,()=>{})}).catch(e=>console.error(e)):I.has(a)&&oe(a)},Ln(){let e=s();null!==e&&(he(e,!1),!e.broken&&(e.x.ke("$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.at=f(p,c.at,T),c.at=f(p,c.at,q),c.at=f(p,c.at,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:z.get(n);void 0!==o&&Q.set(e,{host:n,def:o})}(e,n)}),c.be=d(c.be,(e,t,n,o,l,r)=>{(function(e,t,n,o){let l=Q.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.ve=d(c.ve,(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=B.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=F.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-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};
2
2
  //# sourceMappingURL=scopes.js.map
@@ -1,2 +1,2 @@
1
- import{a as e}from"../chunks/chunk-WE7XOZKS.js";import{b as t,c as l}from"../chunks/chunk-DFXQ7MFW.js";import"../chunks/chunk-V6VVL4F3.js";import{a as n,i as r,j as o,k as i,l as s,m as a}from"../chunks/chunk-BMGEWHCR.js";import"../chunks/chunk-PHAN6L23.js";import"../chunks/chunk-EM3Y3SJS.js";import{a as c}from"../chunks/chunk-6MACFEK7.js";import"../chunks/chunk-ZN52NEIB.js";import"../chunks/chunk-TUQ3OPZQ.js";import"../chunks/chunk-M656SMUU.js";import{a as u,b as f}from"../chunks/chunk-4NJBYXIT.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),N=new WeakMap,S=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 T(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 j=e=>null===e.D?e.Ue:e.D[e.D.length-1];function W(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.Ue,j(e)));n.push(v("wcs-]")),e.after(...n);for(let e of n)x.add(e)}function E(e){if(e instanceof r){W(e.S,e.xe,null);for(let t of e.xe)q(t);return}let t=e.O;null!==t&&(W(e.G[e.G.length-1].S,[t],e.b),q(t))}function q(e){if(null!==e.c)for(let t of e.c)E(t)}var C=new Set(["script","style","template","textarea","title"]),O="data-wcs-raw",M=e=>C.has(e.localName)||e.localName===h();function I(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)&&I(t)}var U=0;function P(t,l){let n=t.getRootNode(),r=[l];for(let e of S.get(n)??[])e!==l&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let o=new Map;for(let e of r){let t=N.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.L)for(let e of t.L)l.set(e.S,e);for(let t of e.ce.values())for(let e of t)if(null!==e._)for(let t of e._.G)l.set(t.S,e._);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),E(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)&&B(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(O,l.map(e=>k.has(e)?`{{ ${k.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}I(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"}${U++}`;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(T(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(t,s,o))}t.before(i)}function R(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&&P(t,e)}}var D=Symbol.for("wcstack.state.ssr.impl"),J=new Map,V=new WeakMap,B=e=>!0===u.$o?.(e),F=e=>1===e.nodeType&&!M(e)&&!B(e),G=e=>e.f.flat().concat(e.q??[]),L=e=>{for(let t of G(e))t.remove()};function Q(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=Q(a,t,l):(l.push(a),F(a)&&X(a,t))}a=e}let c={branch:void 0===n[1]?null:Number(n[1]),f:i,q:a??o.appendChild(v("wcs-]"))},u=G(c);a=c.q.nextSibling;for(let e of u)l?.push(e),t&&s.add(e);return t&&null!==r?J.set(r,c):L(c),a}function X(e,t){for(let l=e.firstChild;null!==l;)w(l,"wcs-[")?l=Q(l,t):(F(l)&&X(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]?T(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)&&(B(r)?V.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),X(e,l)}function _(e){let t=V.get(e);if(void 0===t||(V.delete(e),Z(e,t.ssr,t.Oe),!t.Oe))return null;let l=u.Oe;return u.Oe=re,()=>{u.Oe=l,z()}}function z(){for(let e of J.values())L(e);J.clear()}function H(e){let t=[];for(let l=document.createTreeWalker(e,128);l.nextNode();)t.push(l.currentNode);return t}function K(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 Y(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("-")&&!B(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=N.get(e);void 0===n&&N.set(e,n=new Map),n.set(t,l);let r=t.getRootNode(),s=S.get(r);return void 0===s&&S.set(r,s=new Set),void s.add(e)}if("string"!=typeof l&&J.size>0){let e=J.get(l);void 0!==e&&(J.delete(l),J.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=>(J.get(e)?.q??e).nextSibling;function ne(e,t){if(t.length!==e.sn.childNodes.length)return!1;let l=e.On;for(let n=0;n<l.length;n++){let r=l[n],o=e.sn,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===J.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;!J.has(n)&&null!==l&&!y(l,e)&&1!==l.nodeType;l=l.nextSibling)ee(l)&&(n=l)}let o=J.get(n);if(void 0===o)return null;if(!l&&o.branch!==r)return J.delete(n),L(o),null;let i=o.f.shift();if(0===o.f.length&&J.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=J.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.sn).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=Y,u.hr=_;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.ke;e.ke=(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&&!B(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.Je;r.$e[0]===i&&l.push([e?K(e,t,1,0):t,r.$e.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:K(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]:K(n,r[2],2,1)??r[2]};for(let t of H(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 H(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(()=>{z(),u.Oe=null}))}(l),t?.(l,r)},function(){let e=globalThis;e[D]={build:R,reset(){U=0}},void 0===e[g]&&(e[g]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[D].build(t),reset:()=>e[D].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-JZW5KGXQ.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 W(e){if(e instanceof r){E(e.S,e.Re,null);for(let t of e.Re)q(t);return}let t=e.O;null!==t&&(E(e.G[e.G.length-1].S,[t],e.b),q(t))}function q(e){if(null!==e.c)for(let t of e.c)W(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),W(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 X(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 z(e){let t=J.get(e);if(void 0===t||(J.delete(e),X(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=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(`[${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):X(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};
2
2
  //# sourceMappingURL=ssr.js.map
@@ -1,2 +1,2 @@
1
- import{a as t,c as e}from"../chunks/chunk-ZN52NEIB.js";import{a as n,b as r,c as s,d as i,e as o,j as l}from"../chunks/chunk-4NJBYXIT.js";var a={},u=/\.\d/,h=new Set(Object.getOwnPropertyNames(Object.prototype)),f=0,c=!1,p=null,d=()=>{c=!1,f++};function m(){if(null===p)if("function"==typeof MessageChannel){let t=new MessageChannel;t.port1.onmessage=d,t.port1.unref?.(),p=()=>t.port2.postMessage(0)}else p=()=>setTimeout(d,0);return c||(c=!0,p()),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.J){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.Ge=new Map,this.n=0,this.Ao=-1,this.Bn=new Set,this._e=null,this.engine=t,this.ct=e}ur(){let t=this.engine;this.Ge.clear();for(let e of this.ct)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}prime(t,e){try{e()}catch(e){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,e),n.st?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:e})}}Fo(){this.active=!1,this.Ge.clear()}Mn(t,e,n,r){let s=this.engine.We(n,t.h[e]);for(let n of s.f)e===t.n?r(n):this.Mn(t,e+1,n,r)}un(t,e,n,r){let s=this.Ge.get(t);void 0===s&&this.Ge.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)}be(t,e,n,r,s){if(this.active){(this._e??=new Set).add(t);for(let i of this.ct){let o=i.p;o.n!==t.n||!o.ee(t)||this.un(i,e,i.getter?i.s.get(e??a):o===t&&s&&this.engine.Wt&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}}ve(t,e){if(this.active)for(let n of this.ct)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===t.n&&n.p.ee(t)&&this.un(n,e,n.s.get(e??a),!1)}Qt(t,e){if(!this.active)return;let n=null;for(let r of this.ct){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.un(r,e,void 0,!0):this.Mn(s,t.n+1,e,t=>this.un(r,t,void 0,!0)))}}}Fe(){let t=this._e;if(this._e=null,!this.active||0===this.Ge.size)return;let e=this.Ge;this.Ge=new Map;let r=this.engine,s=[];for(let i of this.ct){let o=e.get(i);if(void 0===o)continue;let l,h=[...o].filter(([t])=>null===t||t.y);h.length>1&&h.sort((t,e)=>$(t[0],e[0]));for(let[e,[o,f,c]]of h){let h,p="evaluate",d=r.u;this.n=f+1,r.Pe++;try{if(h=r.v(i.p,e),i.getter&&(i.s.set(e??a,h),Object.is(h,o)&&(u.test(i.t)||null!==e&&!c&&!(l??=null!==t&&g(v(i.p),t)))))continue;if(f>32){s.includes(i.t)||s.push(i.t);continue}r.u=e,n.st?.(r,{type:"state:watch-fired",path:i.t}),p="handler",i.handler.call(r.proxy,h,o,...r.H(e))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),n.st?.(r,{type:"state:watch-error",phase:p,path:i.t,error:t})}finally{r.u=d,this.n=0,r.Pe--}}}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.st?.(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 b="$streamStatus",w="$streamError",O=new Set(Object.getOwnPropertyNames(Object.prototype)),j=!1;function B(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 Q=class{constructor(t,e,n){this.engine=t,this.entries=e,this.B=n}set(t,e,n){j=!0;try{this.engine.T(this.engine.o(`${t}.${e}`),null,n)}finally{j=!1}}dr(){for(let t of this.entries)this.start(t,!0)}fr(){for(let t of this.entries)t.ut=!1,t.Q?.abort(),t.Q=null}pr(){for(let t of this.entries)t.ut=!1,null!==t.Q&&(t.Q.abort(),t.Q=null),this.set(b,t.name,"idle")}ve(t){let e=this.B.n;for(let n of this.entries)n.g===t&&(n.n=n.ut?Math.max(n.n,e):e,n.ut=!0)}Fe(){let t=this.engine,n=this.B,r=[];for(let s of this.entries){if(!s.ut)continue;let i=s.n;if(s.ut=!1,i>32)r.push(s.name),s.g.z=e;else{n.n=i+1,t.Pe++;try{this.start(s,!1)}finally{t.Pe--,n.n=0}}}r.length>0&&n.Oo(r)}start(t,n){let r,s=this.engine;if(null!==t.Q&&t.Q.abort(),t.Q=null,null!==t.g){let i=t.g;i.getter=t.args;let o=i.J.slice();k(i);try{r=s.read(i,null),function(t,e,n){null!==n&&"function"==typeof n?.then&&l(`$stream "${t}": args must be synchronous (it returned a Promise).`);for(let n of e.J)n.n>0&&l(`$stream "${t}": args must not read a wildcard path ("${n.t}").`),(n.t===t||n.t===`${b}.${t}`||n.t===`${w}.${t}`)&&l(`$stream "${t}": args must not read the stream itself ("${n.t}").`)}(t.name,i,r)}catch(r){k(i);for(let t of o)t._n(i);if(i.z=e,n)throw r;return this.set(w,t.name,r),void this.set(b,t.name,"error")}}let i=new AbortController;t.Q=i,s.T(s.o(t.name),null,t.U),this.set(w,t.name,null),this.set(b,t.name,"active"),this.mr(t,i,r)}async mr(t,e,n){let r=this.engine,s=e.signal,i=()=>!s.aborted&&t.Q===e,o=r.o(t.name),l=this.B.n,a=m(),u=t=>{m()===a&&(this.B.n=l);try{t()}finally{this.B.n=0}},h=t.U;try{let e=await t.source(n,s);if(!i())return;let l=e=>{h=void 0!==t.Co?t.Co(h,e):e,u(()=>r.T(o,null,h))};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;l(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;l(e.value)}}}if(!i())return;t.Q=null,u(()=>this.set(b,t.name,"done"))}catch(n){if(!i())return;t.Q=null,e.abort(),u(()=>{this.set(w,t.name,n),this.set(b,t.name,"error")})}}};function k(e){for(let t of e.J){let n=t.M.indexOf(e);n>=0&&t.M.splice(n,1),t.pt.delete(e)}e.J.length=0,e.z=t}var M=new WeakMap;function S(t){let e=M.get(t);return e?.target===t.target?e:void 0}function A(t,e){let r=new y(t,function(t,e){if(void 0===e)return[];(null===e||"object"!=typeof e)&&l("$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("@")||h.has(s))&&l(`$watch path "${s}" is not a path of the state tree.`),"function"!=typeof i&&l(`$watch entry "${s}" must be a function.`);let o=t.o(s);n.So?.(t,o,!0),r.push({t:s,p:o,handler:i,getter:!1,s:new WeakMap})}return r}(t,e.$watch)),s=new Q(t,function(t,e){let n=e.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&l("$stream must be an object mapping stream names to definitions.");let r=[],s={},i={};for(let o of Object.keys(n)){let a=n[o];(""===o||"$"===o[0]||/[.*]/.test(o)||O.has(o))&&l(`$stream entry "${o}" must be a flat property name.`),(null===a||"object"!=typeof a)&&l(`$stream entry "${o}" must be an object.`);let u=a.source,h=a.fold,f=a.args,c=a.initial;"function"!=typeof u&&l(`$stream entry "${o}" needs a source function.`),void 0!==h&&"function"!=typeof h&&l(`$stream entry "${o}": fold must be a function.`),void 0!==h&&!("initial"in a)&&l(`$stream entry "${o}": fold needs an initial value.`),void 0!==f&&"function"!=typeof f&&l(`$stream entry "${o}": args must be a function.`),B(e,o)&&l(`$stream entry "${o}" collides with a getter, setter or method of the state.`),void 0===e[o]&&(e[o]=c),s[o]="idle",i[o]=null,r.push({name:o,source:u,Co:h,U:c,Q:null,ut:!1,n:0,g:void 0===f?null:t.o(`$streamArgs.${o}`),args:void 0===f?null:function(){return f(this)}})}return e[b]=s,e[w]=i,r}(t,e),r),i=M.get(t);void 0!==i&&(i.B.Fo(),i.Ot.fr()),M.set(t,{B:r,Ot:s,Xe:i?.Xe??!1,target:e})}function F(t,e){let n=M.get(t);if(void 0!==n&&"mounting"!==e&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==e&&(n.Xe="connected"===e),n.target===t.target)){if("disconnected"===e)return n.B.Fo(),void n.Ot.pr();n.Xe&&(n.B.ur(),n.Ot.dr())}}var P=["$streamStatus","$streamError"],G={name:"temporal",install(){n.de=r(n.de,A),n.element=r(n.element,F),n.be=r(n.be,(t,e,n,r,s,i)=>S(t)?.B.be(e,n,r,s,i)),n.ve=r(n.ve,(t,e,n)=>{let r=S(t);void 0!==r&&(r.B.ve(e,n),r.Ot.ve(e))}),n.Qt=r(n.Qt,(t,e,n)=>S(t)?.B.Qt(e,n)),n.Fe=r(n.Fe,t=>{let e=S(t);void 0!==e&&(e.B.Fe(),e.Ot.Fe())}),n.ot=s(o,n.ot,(t,e)=>{let n=e.split(".",1)[0];if(P.includes(n))return n===e?t.target[e]:t.read(t.o(e),null)}),n.Ae=s(i,n.Ae,(t,e)=>(!j&&36===e.t.charCodeAt(0)&&P.includes(e.t.split(".",1)[0])&&l(`"${e.t}" is read-only (the stream runtime owns it).`),!1))}},C=G;export{C as default,G as temporal};
1
+ import{a as t,c as e}from"../chunks/chunk-XEGL4FW5.js";import{a as n,b as r,c as s,d as i,e as l,j as o}from"../chunks/chunk-7ZU3CLEG.js";var a={},h=/\.\d/,u=new Set(Object.getOwnPropertyNames(Object.prototype)),f=0,c=!1,p=null,d=()=>{c=!1,f++};function m(){if(null===p)if("function"==typeof MessageChannel){let t=new MessageChannel;t.port1.onmessage=d,t.port1.unref?.(),p=()=>t.port2.postMessage(0)}else p=()=>setTimeout(d,0);return c||(c=!0,p()),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.J){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.Ce=new Map,this.early=[],this.n=0,this.Ao=-1,this.Bn=new Set,this.Ve=null,this.engine=t,this.Qe=e}ur(){let t=this.engine;this.Ce.clear();let e=this.early;this.early=[];for(let e of this.Qe)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;for(let[n,r,s,i]of e)(null===r||r.y)&&Object.is(t.v(n.p,r),i)&&this.Ot(n,r,s,!0);this.Ce.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.Ce.clear(),this.early=[]}Mn(t,e,n,r){let s=this.engine._e(n,t.h[e]);for(let n of s.f)e===t.n?r(n):this.Mn(t,e+1,n,r)}Ot(t,e,n,r){let s=this.Ce.get(t);void 0===s&&this.Ce.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.Ve??=new Set).add(t);for(let i of this.Qe){let l=i.p;l.n!==t.n||!l.ee(t)||this.Ot(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 if(i)for(let s of this.Qe)s.p===t&&this.early.push([s,e,n,r])}ke(t,e){if(this.active)for(let n of this.Qe)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===t.n&&n.p.ee(t)&&this.Ot(n,e,n.s.get(e??a),!1)}Jt(t,e){if(!this.active)return;let n=null;for(let r of this.Qe){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.Ot(r,e,void 0,!0):this.Mn(s,t.n+1,e,t=>this.Ot(r,t,void 0,!0)))}}}Fe(){let t=this.Ve;if(this.Ve=null,!this.active||0===this.Ce.size)return;let e=this.Ce;this.Ce=new Map;let r=this.engine,s=[];for(let i of this.Qe){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,p="evaluate",d=r.u;this.n=f+1,r.Te++;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}),p="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:p,path:i.t,error:t})}finally{r.u=d,this.n=0,r.Te--}}}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 C(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 k=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.ut=!1,t.Q?.abort(),t.Q=null}pr(){for(let t of this.entries)t.ut=!1,null!==t.Q&&(t.Q.abort(),t.Q=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.ut?Math.max(n.n,e):e,n.ut=!0)}Fe(){let t=this.engine,n=this.M,r=[];for(let s of this.entries){if(!s.ut)continue;let i=s.n;if(s.ut=!1,i>32)r.push(s.name),s.g.z=e;else{n.n=i+1,t.Te++;try{this.start(s,!1)}finally{t.Te--,n.n=0}}}r.length>0&&n.Oo(r)}start(t,n){let r,s=this.engine;if(null!==t.Q&&t.Q.abort(),t.Q=null,null!==t.g){let i=t.g;i.getter=t.args;let l=i.J.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.J)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.Q=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.Q===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.Q=null,h(()=>this.set(w,t.name,"done"))}catch(n){if(!i())return;t.Q=null,e.abort(),h(()=>{this.set(b,t.name,n),this.set(w,t.name,"error")})}}};function j(e){for(let t of e.J){let n=t.W.indexOf(e);n>=0&&t.W.splice(n,1),t.pt.delete(e)}e.J.length=0,e.z=t}var Q=new WeakMap;function S(t){let e=Q.get(t);return e?.target===t.target?e:void 0}function F(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 k(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.`),C(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,Q:null,ut:!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=Q.get(t);void 0!==i&&(i.M.Fo(),i.Ct.fr()),Q.set(t,{M:r,Ct:s,Ge:i?.Ge??!1,target:e})}function A(t,e){let n=Q.get(t);if(void 0!==n&&"mounting"!==e&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==e&&(n.Ge="connected"===e),n.target===t.target)){if("disconnected"===e)return n.M.Fo(),void n.Ct.pr();n.Ge&&(n.M.ur(),n.Ct.dr())}}var J=["$streamStatus","$streamError"],T={name:"temporal",install(){n.de=r(n.de,F),n.element=r(n.element,A),n.ve=r(n.ve,(t,e,n,r,s,i,l)=>S(t)?.M.ve(e,n,r,s,i,l)),n.ke=r(n.ke,(t,e,n)=>{let r=S(t);void 0!==r&&(r.M.ke(e,n),r.Ct.ke(e))}),n.Jt=r(n.Jt,(t,e,n)=>S(t)?.M.Jt(e,n)),n.Fe=r(n.Fe,t=>{let e=S(t);void 0!==e&&(e.M.Fe(),e.Ct.Fe())}),n.rt=s(l,n.rt,(t,e)=>{let n=e.split(".",1)[0];if(J.includes(n))return n===e?t.target[e]:t.read(t.o(e),null)}),n.Ae=s(i,n.Ae,(t,e)=>(!O&&36===e.t.charCodeAt(0)&&J.includes(e.t.split(".",1)[0])&&o(`"${e.t}" is read-only (the stream runtime owns it).`),!1))}},E=T;export{E as default,T as temporal};
2
2
  //# sourceMappingURL=temporal.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ROOT","INDEX_PATH","PROTOTYPE_NAMES","Set","Object","getOwnPropertyNames","prototype","taskSeq","pinged","ping","nextTask","thisTask","MessageChannel","ch","port1","onmessage","unref","port2","postMessage","setTimeout","reads","g","changed","seen","stack","length","h","pop","has","add","s","sources","p","isUnder","depth","lists","getter","push","WatchRuntime","constructor","engine","watches","this","active","hits","Map","cutTask","reported","activate","clear","w","underGetter","last","WeakMap","prime","set","readUntracked","eachRow","row","read","error","console","path","hooks","noticed","type","phase","deactivate","k","parent","fn","list","childList","rows","hit","prev","landed","get","written","old","value","direct","wp","guard","getterReached","listSynced","before","pattern","r","drained","size","batch","cut","real","entries","filter","alive","sort","a","b","compareRows","cur","saved","ctx","feeding","is","test","getterOf","includes","handler","call","proxy","indexesOf","chainCut","paths","task","fresh","maxDepth","ia","ib","parentRow","unshift","index","i","STATUS","ERROR","internalWrite","hasAccessorOrMethod","target","name","o","getPrototypeOf","d","getOwnPropertyDescriptor","StreamRuntime","watch","ns","write","startAll","e","start","abortAll","restart","controller","abort","stopAll","Math","max","rootValue","FAILED","eager","args","kept","slice","untrack","then","raiseError","checkArgs","addDependent","ctrl","AbortController","initial","consume","signal","live","aborted","put","acc","producer","source","chunk","v","fold","getReader","reader","addEventListener","cancel","catch","done","Symbol","asyncIterator","TypeError","it","return","next","dependents","indexOf","splice","dependentSet","delete","UNSET","runtimes","rt","declare","decl","out","keys","declared","parseWatches","$watch","stream","$stream","status","errors","def","parseStreams","connected","element","document","documentElement","hasAttribute","NAMESPACES","temporal","install","chain","dollar","first","known","key","split","beforeWrite","handled","_engine","charCodeAt","temporal_default"],"sources":["../../../src/temporal/watch.ts","../../../src/temporal/stream.ts","../../../src/features/temporal.ts"],"sourcesContent":["/**\n * `$watch` — the headless subscription (README \"Watch\", docs/state-watch-hook-design.md).\n *\n * A handler fires at the end of a drain, once per location that landed in it: a write of its\n * path or of an object above it in the same row, a change that reached its getter, a row that\n * entered its list. `cur` is the value at the drain; `prev` the value before the batch's first\n * write when a primitive was written (for a getter: its previous evaluation). A change that reaches\n * a getter fires it, whether its value changed or not (3.x D4: a watch has no condition of its own).\n * A row's getter that no write of the batch changed — it read none of the written paths, directly or\n * through a getter it read — fires only if its value changed: a row a list kept when a write\n * re-synced or re-sorted the list (`items = [...items, x]`) is reached again through what it read\n * under the row, which did not change (#389). A write at the list (or above it) changes what a row\n * read there (`this.items.length`), not under its row.\n * Declaration order between handlers, ascending indexes between rows of one path.\n *\n * A handler's writes form the next batch. Each write carries a chain depth (as @wcstack/state\n * 3.4, #354): 0, or one more than the depth of what fired the handler making it — or restarted the\n * `$stream` making it (stream.ts: its run's values and end too, within the task the run started in).\n * For a data path that is the deepest write landing there in the batch; for a getter, the first write\n * since it was last evaluated (a reached getter is not reached again until it is read), and 0 when a\n * list re-synced in the drain reached it — loops through those are left to the render chain\n * (MAX_RENDER_CHAIN). A handler fired more than MAX_CHAIN deep does not\n * run (as 3.x: 33 links run): the chain is cut and reported once. Writes riding in the same batch (a\n * render's write-back) neither lengthen nor reset it.\n *\n * Differences from @wcstack/state 3.3 that rows make possible: a row watch needs neither a\n * `for` binding nor `$listKeys` (the watch keeps its lists synced itself), wildcard getters are\n * eager too, and a whole-array assignment fires only for the rows that entered the list (a row\n * kept by identity did not change).\n */\nimport type { Engine } from \"../engine\";\nimport type { Pattern } from \"../pattern\";\nimport type { StateList, StateRow } from \"../list\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { hooks } from \"../hooks\";\n\ntype Handler = (this: unknown, cur: unknown, prev: unknown, ...indexes: number[]) => unknown;\n\ninterface Watch {\n readonly path: string;\n readonly p: Pattern;\n readonly handler: Handler;\n /** A getter (or under one): kept evaluated, `prev` is its previous evaluation. */\n getter: boolean;\n /** Previous evaluation by row (getter watches; the root's under ROOT): a removed row takes its entry with it. */\n last: WeakMap<object, unknown>;\n}\n\n/**\n * A landing of a batch: `prev` (the first write's), the deepest write's chain depth, and whether a\n * write landed there (not only a change that reached a getter).\n */\ntype Hit = [prev: unknown, depth: number, landed: boolean];\n\nexport const MAX_CHAIN = 32;\nconst ROOT = {};\n/**\n * An explicit index (`items.0.v`, read like a getter): a write to another row, a list change,\n * reaches it unchanged. A leading numeric segment is a root key (`2024.total`), not an index.\n */\nconst INDEX_PATH = /\\.\\d/;\nconst PROTOTYPE_NAMES = new Set(Object.getOwnPropertyNames(Object.prototype));\n\n/**\n * The current task's number, bumped in the next task after it is asked for: a MessageChannel message\n * (neither throttled in a background tab nor replaced by a faked timer), or a timer where there is none.\n */\nlet taskSeq = 0;\nlet pinged = false;\nlet ping: (() => void) | null = null;\nconst nextTask = (): void => {\n pinged = false;\n taskSeq++;\n};\nexport function thisTask(): number {\n if (ping === null) {\n if (typeof MessageChannel === \"function\") {\n const ch = new MessageChannel();\n ch.port1.onmessage = nextTask;\n // (Node: the port must not keep the process alive)\n (ch.port1 as { unref?: () => void }).unref?.();\n ping = () => ch.port2.postMessage(0);\n } else ping = () => setTimeout(nextTask, 0);\n }\n if (!pinged) {\n pinged = true;\n ping();\n }\n return taskSeq;\n}\n\n/** Whether a write at a path of `changed` changed what getter `g` read (directly, or through a getter it read). */\nfunction reads(g: Pattern, changed: Set<Pattern>): boolean {\n const seen = new Set<Pattern>();\n const stack = [g];\n while (stack.length > 0) {\n const h = stack.pop()!;\n if (seen.has(h)) continue;\n seen.add(h);\n for (const s of h.sources) {\n for (const p of changed) {\n // a write at the list a row is in (or above it) changes what was read there, not under the row\n if (s.isUnder(p) && (s.depth === p.depth || !(p.depth < h.depth && h.lists[p.depth + 1]!.isUnder(p)))) return true;\n }\n if (s.getter !== null) stack.push(s);\n }\n }\n return false;\n}\n\nexport function parseWatches(engine: Engine, decl: unknown): Watch[] {\n if (decl === undefined) return [];\n if (decl === null || typeof decl !== \"object\") raiseError(\"$watch must be an object mapping paths to handler functions.\");\n const out: Watch[] = [];\n for (const path of Object.keys(decl)) {\n const handler = (decl as Record<string, unknown>)[path];\n if (path === \"\" || path[0] === \"$\" || path.includes(\"@\") || PROTOTYPE_NAMES.has(path)) raiseError(`$watch path \"${path}\" is not a path of the state tree.`);\n if (typeof handler !== \"function\") raiseError(`$watch entry \"${path}\" must be a function.`);\n const p = engine.pattern(path);\n hooks.declared?.(engine, p, true);\n out.push({ path, p, handler: handler as Handler, getter: false, last: new WeakMap() });\n }\n return out;\n}\n\nexport class WatchRuntime {\n readonly engine: Engine;\n readonly watches: Watch[];\n active = false;\n /** Landings of the current batch: watch → row → hit. */\n private hits = new Map<Watch, Map<StateRow | null, Hit>>();\n /** The chain depth of a write made now: 0, or one more than what fired the running handler (or restart). */\n depth = 0;\n /**\n * The paths a cut reported in task `cutTask`. A chain carries its depth only synchronously (and\n * through a `$stream`'s values within the task its run started in): a cut of the same paths later\n * in the task is the same chain's — what it left running reaching the limit again.\n */\n private cutTask = -1;\n private reported = new Set<string>();\n /** The paths written in the batch (what a change reaching a getter may have come from). */\n private changed: Set<Pattern> | null = null;\n\n constructor(engine: Engine, watches: Watch[]) {\n this.engine = engine;\n this.watches = watches;\n }\n\n /** After `$connectedCallback` (and on reconnect): watches see the writes from now on. */\n activate(): void {\n const engine = this.engine;\n this.hits.clear();\n for (const w of this.watches) {\n w.getter = w.p.getter !== null || w.p.underGetter;\n w.last = new WeakMap();\n // (the list a row watch reads can be a getter that throws too)\n this.prime(w, () => {\n if (w.p.depth === 0) {\n if (w.getter) w.last.set(ROOT, engine.readUntracked(w.p, null));\n } else {\n // a row watch keeps its lists synced, rendered or not; a getter watch is eager per row\n this.eachRow(w.p, 1, null, (row) => {\n if (w.getter) this.prime(w, () => w.last.set(row, engine.readUntracked(w.p, row)));\n });\n }\n });\n }\n this.active = true;\n }\n\n /** What a watch reads before the writes (its `prev`): what throws is reported, the others go on. */\n private prime(w: Watch, read: () => void): void {\n try {\n read();\n } catch (error) {\n console.error(`[@wcstack/state] $watch initial evaluation of \"${w.path}\" threw.`, error);\n hooks.noticed?.(this.engine, { \"type\": \"state:watch-error\", \"phase\": \"prime\", \"path\": w.path, \"error\": error });\n }\n }\n\n deactivate(): void {\n this.active = false;\n this.hits.clear();\n }\n\n /** Calls fn for every row at p.depth, creating the lists on the way (they then stay synced). */\n private eachRow(p: Pattern, k: number, parent: StateRow | null, fn: (row: StateRow) => void): void {\n const engine = this.engine;\n const list = engine.childList(parent, p.lists[k]!);\n for (const row of list.rows) {\n if (k === p.depth) fn(row);\n else this.eachRow(p, k + 1, row, fn);\n }\n }\n\n /** Records a landing at the current depth: the first `prev` stays, the deepest write's depth wins. */\n private hit(w: Watch, row: StateRow | null, prev: unknown, landed: boolean): void {\n let rows = this.hits.get(w);\n if (rows === undefined) this.hits.set(w, (rows = new Map()));\n const h = rows.get(row);\n if (h === undefined) rows.set(row, [prev, this.depth, landed]);\n else {\n if (h[1] < this.depth) h[1] = this.depth;\n h[2] ||= landed;\n }\n }\n\n written(p: Pattern, row: StateRow | null, old: unknown, value: unknown, direct: boolean): void {\n if (!this.active) return;\n (this.changed ??= new Set()).add(p);\n for (const w of this.watches) {\n const wp = w.p;\n // the watched path, or an object above it in the same row (a getter's row replaced included)\n if (wp.depth !== p.depth || !wp.isUnder(p)) continue;\n // `prev`: a getter's previous evaluation; for data, the old value the same-value guard reads\n // when a primitive was written there (none when it is off, or above it)\n this.hit(w, row, w.getter ? w.last.get(row ?? ROOT) : wp === p && direct && this.engine.guard && (value === null || (typeof value !== \"object\" && typeof value !== \"function\")) ? old : undefined, true);\n }\n }\n\n getterReached(g: Pattern, row: StateRow | null): void {\n if (!this.active) return;\n // a getter, or a path under it in the same row — also one that became so after the activation\n // (a mounted component's exported getter, a volume's accessor grafted later)\n for (const w of this.watches) {\n if ((w.getter ||= w.p.getter !== null || w.p.underGetter) && w.p.depth === g.depth && w.p.isUnder(g)) this.hit(w, row, w.last.get(row ?? ROOT), false);\n }\n }\n\n /** Rows that entered a list a row watch ranges over fire (and nested lists under them sync). */\n listSynced(list: StateList, old: StateRow[]): void {\n if (!this.active) return;\n let before: Set<StateRow> | null = null;\n for (const w of this.watches) {\n const wp = w.p;\n if (wp.depth < list.depth || wp.lists[list.depth] !== list.pattern) continue;\n before ??= new Set(old);\n for (const row of list.rows) {\n if (before.has(row)) continue;\n if (wp.depth === list.depth) this.hit(w, row, undefined, true);\n else this.eachRow(wp, list.depth + 1, row, (r) => this.hit(w, r, undefined, true));\n }\n }\n }\n\n drained(): void {\n const changed = this.changed;\n this.changed = null;\n if (!this.active || this.hits.size === 0) return;\n const batch = this.hits;\n this.hits = new Map();\n const engine = this.engine;\n const cut: string[] = [];\n for (const w of this.watches) {\n const rows = batch.get(w);\n if (rows === undefined) continue;\n const entries = [...rows].filter(([row]) => row === null || row.alive);\n if (entries.length > 1) entries.sort((a, b) => compareRows(a[0]!, b[0]!));\n // (whether a write of the batch changed what the watched getter read: asked once, for an unchanged row)\n let real: boolean | undefined;\n for (const [row, [prev, depth, landed]] of entries) {\n let cur: unknown;\n // (DevTools: the handler fired, or what threw — the value's evaluation or the handler)\n let phase = \"evaluate\";\n const saved = engine.ctx;\n this.depth = depth + 1;\n engine.feeding++;\n try {\n // (read past the limit too: a getter's cache is then current, and its next change reaches it)\n cur = engine.readUntracked(w.p, row);\n if (w.getter) {\n w.last.set(row ?? ROOT, cur);\n // unchanged: an explicit index, or a row no write of the batch changed (a row a list kept, #389)\n if (Object.is(cur, prev) && (INDEX_PATH.test(w.path) || (row !== null && !landed && !(real ??= changed !== null && reads(getterOf(w.p), changed))))) continue;\n }\n // fired more than MAX_CHAIN deep: the chain stops here (the batch's other handlers run)\n if (depth > MAX_CHAIN) {\n if (!cut.includes(w.path)) cut.push(w.path);\n continue;\n }\n engine.ctx = row;\n hooks.noticed?.(engine, { \"type\": \"state:watch-fired\", \"path\": w.path });\n phase = \"handler\";\n w.handler.call(engine.proxy, cur, prev, ...engine.indexesOf(row));\n } catch (error) {\n console.error(`[@wcstack/state] $watch \"${w.path}\" failed; the other watches still run.`, error);\n hooks.noticed?.(engine, { \"type\": \"state:watch-error\", \"phase\": phase, \"path\": w.path, \"error\": error });\n } finally {\n engine.ctx = saved;\n this.depth = 0;\n engine.feeding--;\n }\n }\n }\n if (cut.length > 0) this.chainCut(cut);\n }\n\n /** A chain of handlers / stream restarts went past MAX_CHAIN: reported once a task for its paths (nothing is rolled back). */\n chainCut(paths: string[]): void {\n const task = thisTask();\n if (task !== this.cutTask) {\n this.cutTask = task;\n this.reported.clear();\n }\n const fresh = paths.filter((path) => !this.reported.has(path));\n if (fresh.length === 0) return;\n for (const path of fresh) this.reported.add(path);\n console.error(`[@wcstack/state] $watch handlers / $stream restarts kept writing for ${MAX_CHAIN} batches; the chain is cut (nothing is rolled back).`);\n hooks.noticed?.(this.engine, { \"type\": \"state:watch-chain-limit\", \"maxDepth\": MAX_CHAIN, \"paths\": fresh });\n }\n}\n\n/** The getter a watched path is, or lies under (in the same row). */\nfunction getterOf(p: Pattern): Pattern {\n while (p.getter === null && p.parent !== null) p = p.parent;\n return p;\n}\n\n/** Ascending indexes, outermost first. */\nfunction compareRows(a: StateRow, b: StateRow): number {\n const ia: number[] = [];\n const ib: number[] = [];\n for (let r: StateRow | null = a; r !== null; r = r.list.parentRow) ia.unshift(r.index);\n for (let r: StateRow | null = b; r !== null; r = r.list.parentRow) ib.unshift(r.index);\n for (let i = 0; i < ia.length && i < ib.length; i++) if (ia[i] !== ib[i]) return ia[i] - ib[i];\n return ia.length - ib.length;\n}\n","/**\n * `$stream` — an async producer folded into one reactive property (README \"Streams\",\n * packages/state/docs/streams.md).\n *\n * `args` runs as a getter of its own (a pattern with no path in the state), so the paths it reads\n * are tracked like any getter's; a change that reaches it restarts the stream at the end of the\n * drain, once (switchMap: abort, reset to `initial`, re-run `args`, call `source`). Its\n * dependencies are captured afresh on every run. `$streamStatus.<name>` / `$streamError.<name>` are\n * read-only companions kept on the state.\n *\n * A restart's writes are reactions: they continue the render chain (MAX_RENDER_CHAIN), and the\n * `$watch` chain (watch.ts) one deeper than the write that reached `args` (#354). That depth is the\n * deepest such write's for a data path `args` reads, but the first one's since `args` was last\n * evaluated when the change came through a getter (a reached getter is not reached again until it\n * is read), and 0 when a list re-synced in the drain reached it: such loops are left to the render\n * chain. A restart more than MAX_CHAIN deep is not made (the chain is cut and reported); the next\n * change of its inputs restarts it.\n *\n * A run's own writes after its start — a value its source yields, the status `done` / `error` — made\n * within the task the run started in (synchronously or in its microtasks) are as deep as the run: the\n * `$watch` handlers they fire and the restarts they cause continue its chain, so a loop through a\n * source that yields at once (a `$watch` on the value moving what `args` reads, two streams reading\n * each other's values) is cut instead of running on microtasks alone. From a later task (a network\n * response, a message, a timer) they are new input, as a write from code: they start a chain afresh.\n */\nimport type { Engine } from \"../engine\";\nimport { FAILED, UNSET, type Pattern } from \"../pattern\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { MAX_CHAIN, thisTask, type WatchRuntime } from \"./watch\";\n\ntype Status = \"idle\" | \"active\" | \"done\" | \"error\";\n\ninterface Entry {\n readonly name: string;\n readonly source: (args: unknown, signal: AbortSignal) => unknown;\n readonly fold: ((acc: unknown, chunk: unknown) => unknown) | undefined;\n readonly initial: unknown;\n /** The `args` getter (null without args: start once). */\n readonly g: Pattern | null;\n readonly args: (() => unknown) | null;\n controller: AbortController | null;\n restart: boolean;\n /** The `$watch` chain depth of what asked for the restart (meaningful while `restart`). */\n depth: number;\n}\n\nconst STATUS = \"$streamStatus\";\nconst ERROR = \"$streamError\";\nconst PROTOTYPE_NAMES = new Set(Object.getOwnPropertyNames(Object.prototype));\n\n/** A read-only companion path is being written by the runtime itself. */\nexport let internalWrite = false;\n\nfunction hasAccessorOrMethod(target: object, name: string): boolean {\n for (let o: object | null = target; o !== null && o !== Object.prototype; o = Object.getPrototypeOf(o)) {\n const d = Object.getOwnPropertyDescriptor(o, name);\n if (d !== undefined) return d.get !== undefined || d.set !== undefined || typeof d.value === \"function\";\n }\n return false;\n}\n\n/** Validates `$stream` and materializes the value property and the companions on `target`. */\nexport function parseStreams(engine: Engine, target: Record<string, any>): Entry[] {\n const decl = target.$stream;\n if (decl === undefined) return [];\n if (decl === null || typeof decl !== \"object\") raiseError(\"$stream must be an object mapping stream names to definitions.\");\n const entries: Entry[] = [];\n const status: Record<string, Status> = {};\n const errors: Record<string, unknown> = {};\n for (const name of Object.keys(decl)) {\n // the author's object: read by quoted keys (the build shortens internal property names)\n const def = decl[name];\n if (name === \"\" || name[0] === \"$\" || /[.*]/.test(name) || PROTOTYPE_NAMES.has(name)) raiseError(`$stream entry \"${name}\" must be a flat property name.`);\n if (def === null || typeof def !== \"object\") raiseError(`$stream entry \"${name}\" must be an object.`);\n const source = def[\"source\"];\n const fold = def[\"fold\"];\n const args = def[\"args\"];\n const initial = def[\"initial\"];\n if (typeof source !== \"function\") raiseError(`$stream entry \"${name}\" needs a source function.`);\n if (fold !== undefined && typeof fold !== \"function\") raiseError(`$stream entry \"${name}\": fold must be a function.`);\n if (fold !== undefined && !(\"initial\" in def)) raiseError(`$stream entry \"${name}\": fold needs an initial value.`);\n if (args !== undefined && typeof args !== \"function\") raiseError(`$stream entry \"${name}\": args must be a function.`);\n if (hasAccessorOrMethod(target, name)) raiseError(`$stream entry \"${name}\" collides with a getter, setter or method of the state.`);\n if (target[name] === undefined) target[name] = initial;\n status[name] = \"idle\";\n errors[name] = null;\n entries.push({\n name, source, fold, initial, controller: null, restart: false, depth: 0,\n g: args === undefined ? null : engine.pattern(`$streamArgs.${name}`),\n args: args === undefined ? null : function (this: unknown) { return args(this); },\n });\n }\n target[STATUS] = status;\n target[ERROR] = errors;\n return entries;\n}\n\nexport class StreamRuntime {\n readonly engine: Engine;\n readonly entries: Entry[];\n /** The engine's `$watch` runtime: it holds the depth of the write made now, and reports a cut. */\n readonly watch: WatchRuntime;\n\n constructor(engine: Engine, entries: Entry[], watch: WatchRuntime) {\n this.engine = engine;\n this.entries = entries;\n this.watch = watch;\n }\n\n private set(ns: string, name: string, value: unknown): void {\n internalWrite = true;\n try {\n this.engine.write(this.engine.pattern(`${ns}.${name}`), null, value);\n } finally {\n internalWrite = false;\n }\n }\n\n /** Eager start after `$connectedCallback`: an `args` failure is thrown as is. */\n startAll(): void {\n for (const e of this.entries) this.start(e, true);\n }\n\n /** A re-set replaced the state: the old runs stop without touching the new state. */\n abortAll(): void {\n for (const e of this.entries) {\n e.restart = false;\n e.controller?.abort();\n e.controller = null;\n }\n }\n\n stopAll(): void {\n for (const e of this.entries) {\n e.restart = false;\n if (e.controller !== null) {\n e.controller.abort();\n e.controller = null;\n }\n this.set(STATUS, e.name, \"idle\");\n }\n }\n\n getterReached(g: Pattern): void {\n const depth = this.watch.depth;\n for (const e of this.entries) {\n if (e.g !== g) continue;\n // (a restart a stop or a re-set dropped leaves its depth behind)\n e.depth = e.restart ? Math.max(e.depth, depth) : depth;\n e.restart = true;\n }\n }\n\n /** At the end of a drain (after the watches): each stream whose `args` inputs changed restarts once. */\n drained(): void {\n const engine = this.engine;\n const watch = this.watch;\n const cut: string[] = [];\n for (const e of this.entries) {\n if (!e.restart) continue;\n const depth = e.depth;\n e.restart = false;\n if (depth > MAX_CHAIN) {\n cut.push(e.name);\n // reached, not re-run: the next change of its inputs must reach it again\n e.g!.rootValue = FAILED;\n continue;\n }\n watch.depth = depth + 1;\n engine.feeding++;\n try {\n this.start(e, false);\n } finally {\n engine.feeding--;\n watch.depth = 0;\n }\n }\n if (cut.length > 0) watch.chainCut(cut);\n }\n\n private start(e: Entry, eager: boolean): void {\n const engine = this.engine;\n if (e.controller !== null) e.controller.abort();\n e.controller = null;\n let args: unknown;\n if (e.g !== null) {\n const g = e.g;\n // (re)attached on every start: a re-set forgets every accessor of the old state\n g.getter = e.args;\n const kept = g.sources.slice();\n untrack(g);\n try {\n args = engine.read(g, null);\n checkArgs(e.name, g, args);\n } catch (error) {\n // the dependencies of the last successful run stay: touching one retries\n untrack(g);\n for (const s of kept) s.addDependent(g);\n g.rootValue = FAILED;\n if (eager) throw error;\n this.set(ERROR, e.name, error);\n this.set(STATUS, e.name, \"error\");\n return;\n }\n }\n const ctrl = new AbortController();\n e.controller = ctrl;\n engine.write(engine.pattern(e.name), null, e.initial);\n this.set(ERROR, e.name, null);\n this.set(STATUS, e.name, \"active\");\n void this.consume(e, ctrl, args);\n }\n\n private async consume(e: Entry, ctrl: AbortController, args: unknown): Promise<void> {\n const engine = this.engine;\n const signal = ctrl.signal;\n const live = (): boolean => !signal.aborted && e.controller === ctrl;\n const p = engine.pattern(e.name);\n // the run's depth and task: what it writes in that task continues its chain\n const depth = this.watch.depth;\n const task = thisTask();\n const put = (fn: () => void): void => {\n if (thisTask() === task) this.watch.depth = depth;\n try {\n fn();\n } finally {\n this.watch.depth = 0;\n }\n };\n let acc = e.initial;\n try {\n const producer: any = await e.source(args, signal);\n if (!live()) return;\n const chunk = (v: unknown): void => {\n acc = e.fold !== undefined ? e.fold(acc, v) : v;\n put(() => engine.write(p, null, acc));\n };\n if (producer !== null && typeof producer?.getReader === \"function\") {\n // a ReadableStream: only reader.cancel() can unwind a parked read\n const reader = producer.getReader();\n signal.addEventListener(\"abort\", () => { reader.cancel().catch(() => {}); });\n for (;;) {\n const r = await reader.read();\n if (!live()) return;\n if (r.done) break;\n chunk(r.value);\n }\n } else if (producer !== null && typeof producer?.[Symbol.asyncIterator] === \"function\") {\n const it = producer[Symbol.asyncIterator]();\n signal.addEventListener(\"abort\", () => { void it.return?.(); });\n for (;;) {\n const r = await it.next();\n if (!live()) return;\n if (r.done) break;\n chunk(r.value);\n }\n } else {\n throw new TypeError(`$stream \"${e.name}\": source must return an async iterable or a ReadableStream`);\n }\n if (!live()) return;\n e.controller = null;\n put(() => this.set(STATUS, e.name, \"done\"));\n } catch (error) {\n if (!live()) return;\n e.controller = null;\n ctrl.abort();\n put(() => {\n this.set(ERROR, e.name, error);\n this.set(STATUS, e.name, \"error\");\n });\n }\n }\n}\n\n/** Forgets what a getter read (its dependencies are captured again by the next evaluation). */\nfunction untrack(g: Pattern): void {\n for (const s of g.sources) {\n const i = s.dependents.indexOf(g);\n if (i >= 0) s.dependents.splice(i, 1);\n (s as any).dependentSet.delete(g);\n }\n g.sources.length = 0;\n g.rootValue = UNSET;\n}\n\nfunction checkArgs(name: string, g: Pattern, args: unknown): void {\n if (args !== null && typeof (args as any)?.then === \"function\") raiseError(`$stream \"${name}\": args must be synchronous (it returned a Promise).`);\n for (const s of g.sources) {\n if (s.depth > 0) raiseError(`$stream \"${name}\": args must not read a wildcard path (\"${s.path}\").`);\n if (s.path === name || s.path === `${STATUS}.${name}` || s.path === `${ERROR}.${name}`) raiseError(`$stream \"${name}\": args must not read the stream itself (\"${s.path}\").`);\n }\n}\n","/**\n * The temporal add-on (@wcstack/state/features/temporal): `$watch` and `$stream`.\n * At the end of every drain, after its report (`$renderedCallback`): the watches, then the\n * stream restarts. Both start after `$connectedCallback` and stop on disconnect.\n */\nimport type { Engine } from \"../engine\";\nimport { chain, first, handled, hooks, known, type Feature } from \"../hooks\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { parseWatches, WatchRuntime } from \"../temporal/watch\";\nimport { internalWrite, parseStreams, StreamRuntime } from \"../temporal/stream\";\n\ninterface Runtime {\n watch: WatchRuntime;\n stream: StreamRuntime;\n connected: boolean;\n /** The state it was made for: a re-set refused after it (list-keys, recursion) leaves the old one in place. */\n target: object;\n}\n\nconst runtimes = new WeakMap<Engine, Runtime>();\n/** The engine's runtime when it is its state's (not one a refused re-set left: that one never runs). */\nfunction live(engine: Engine): Runtime | undefined {\n const rt = runtimes.get(engine);\n return rt?.target === engine.target ? rt : undefined;\n}\n\nfunction declare(engine: Engine, target: Record<string, any>): void {\n const watch = new WatchRuntime(engine, parseWatches(engine, target.$watch));\n const stream = new StreamRuntime(engine, parseStreams(engine, target), watch);\n const old = runtimes.get(engine);\n if (old !== undefined) {\n old.watch.deactivate();\n old.stream.abortAll();\n }\n runtimes.set(engine, { watch, stream, connected: old?.connected ?? false, target });\n}\n\nfunction element(engine: Engine, phase: \"mounting\" | \"back\" | \"connected\" | \"disconnected\" | \"reset\"): void {\n const rt = runtimes.get(engine);\n // an engine made before the add-on was installed has no runtime (and declares nothing temporal);\n // a server render (@wcstack/server) keeps streams at their initial value and watches off\n if (rt === undefined || phase === \"mounting\" || document.documentElement?.hasAttribute(\"data-wcs-server\")) return;\n // (kept on a runtime a refused re-set left too: the next re-set takes it over. \"back\" comes after\n // \"disconnected\", before $connectedCallback runs again: not connected yet)\n if (phase !== \"reset\") rt.connected = phase === \"connected\";\n // a refused state's runtime never runs, nor stops (writes `$streamStatus`), on the state that stayed\n if (rt.target !== engine.target) return;\n if (phase === \"disconnected\") {\n rt.watch.deactivate();\n rt.stream.stopAll();\n return;\n }\n if (!rt.connected) return;\n rt.watch.activate();\n rt.stream.startAll();\n}\n\nconst NAMESPACES = [\"$streamStatus\", \"$streamError\"];\n\nexport const temporal: Feature = {\n name: \"temporal\",\n install(): void {\n hooks.declare = chain(hooks.declare, declare);\n hooks.element = chain(hooks.element, element);\n hooks.written = chain(hooks.written, (engine, p, row, old, value, direct) => live(engine)?.watch.written(p, row, old, value, direct));\n hooks.getterReached = chain(hooks.getterReached, (engine, g, row) => {\n const rt = live(engine);\n if (rt === undefined) return;\n rt.watch.getterReached(g, row);\n rt.stream.getterReached(g);\n });\n hooks.listSynced = chain(hooks.listSynced, (engine, list, old) => live(engine)?.watch.listSynced(list, old));\n hooks.drained = chain(hooks.drained, (engine) => {\n const rt = live(engine);\n if (rt === undefined) return;\n rt.watch.drained();\n rt.stream.drained();\n });\n // `this.$streamStatus` (the object, untracked) and `this[\"$streamStatus.x\"]` (tracked)\n hooks.dollar = first(known, hooks.dollar, (engine, key) => {\n const ns = key.split(\".\", 1)[0];\n if (!NAMESPACES.includes(ns)) return undefined;\n return ns === key ? engine.target[key] : engine.read(engine.pattern(key), null);\n });\n hooks.beforeWrite = first(handled, hooks.beforeWrite, (_engine, p) => {\n if (!internalWrite && p.path.charCodeAt(0) === 36 && NAMESPACES.includes(p.path.split(\".\", 1)[0])) {\n raiseError(`\"${p.path}\" is read-only (the stream runtime owns it).`);\n }\n return false;\n });\n },\n};\nexport default temporal;\n"],"mappings":"0IAsDO,IACDA,EAAO,CAAC,EAKRC,EAAa,OACbC,EAAkB,IAAIC,IAAIC,OAAOC,oBAAoBD,OAAOE,YAM9DC,EAAU,EACVC,GAAS,EACTC,EAA4B,KAC1BC,EAAW,KACfF,GAAS,EACTD,KAEK,SAASI,IACd,GAAa,OAATF,EACF,GAA8B,mBAAnBG,eAA+B,CACxC,IAAMC,EAAK,IAAID,eACfC,EAAGC,MAAMC,UAAYL,EAEpBG,EAAGC,MAAiCE,UACrCP,EAAO,IAAMI,EAAGI,MAAMC,YAAY,EACpC,MAAOT,EAAO,IAAMU,WAAWT,EAAU,GAE3C,OAAKF,IACHA,GAAS,EACTC,KAEKF,CACT,CAGA,SAASa,EAAMC,EAAYC,GACzB,IAAMC,EAAO,IAAIpB,IACXqB,EAAQ,CAACH,GACf,KAAOG,EAAMC,OAAS,GAAG,CACvB,IAAMC,EAAIF,EAAMG,MAChB,IAAIJ,EAAKK,IAAIF,GACb,CAAAH,EAAKM,IAAIH,GACT,QAAWI,KAAKJ,EAAEK,EAAS,CACzB,QAAWC,KAAKV,EAEd,GAAIQ,EAAEG,GAAQD,KAAOF,EAAEI,IAAUF,EAAEE,KAAWF,EAAEE,EAAQR,EAAEQ,GAASR,EAAES,EAAMH,EAAEE,EAAQ,GAAID,GAAQD,KAAM,OAAO,EAE/F,OAAbF,EAAEM,QAAiBZ,EAAMa,KAAKP,EACpC,EACF,C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AAS4B,GACzB,OAAOA,IAAOkF,EAAMlL,EAAOwF,OAAO0F,GAAOlL,EAAOmB,KAAKnB,EAAO+C,EAAQmI,GAAM,QAE5E3J,EAAM6J,GAAcJ,EAAMK,EAAS9J,EAAM6J,GAAa,CAACE,EAAS9L,MACzD8F,GAA0C,KAAzB9F,EAAE8B,EAAKiK,WAAW,IAAaZ,EAAWvG,SAAS5E,EAAE8B,EAAK6J,MAAM,IAAK,GAAG,KAC5F/D,EAAW,IAAI5H,EAAE8B,kDAEZ,GAEX,GAEKkK,EAAQZ","ignoreList":[]}
1
+ {"version":3,"names":["ROOT","INDEX_PATH","PROTOTYPE_NAMES","Set","Object","getOwnPropertyNames","prototype","taskSeq","pinged","ping","nextTask","thisTask","MessageChannel","ch","port1","onmessage","unref","port2","postMessage","setTimeout","reads","g","changed","seen","stack","length","h","pop","has","add","s","sources","p","isUnder","depth","lists","getter","push","WatchRuntime","constructor","engine","watches","this","active","hits","Map","early","cutTask","reported","activate","clear","w","underGetter","last","WeakMap","prime","set","readUntracked","eachRow","row","before","value","alive","is","hit","size","schedule","read","error","console","path","hooks","noticed","type","phase","deactivate","k","parent","fn","list","childList","rows","prev","landed","get","written","old","direct","element","wp","guard","getterReached","listSynced","pattern","r","drained","batch","cut","real","entries","filter","sort","a","b","compareRows","cur","saved","ctx","feeding","test","getterOf","includes","handler","call","proxy","indexesOf","chainCut","paths","task","fresh","maxDepth","ia","ib","parentRow","unshift","index","i","STATUS","ERROR","internalWrite","hasAccessorOrMethod","target","name","o","getPrototypeOf","d","getOwnPropertyDescriptor","StreamRuntime","watch","ns","write","startAll","e","start","abortAll","restart","controller","abort","stopAll","Math","max","rootValue","FAILED","eager","args","kept","slice","untrack","then","raiseError","checkArgs","addDependent","ctrl","AbortController","initial","consume","signal","live","aborted","put","acc","producer","source","chunk","v","fold","getReader","reader","addEventListener","cancel","catch","done","Symbol","asyncIterator","TypeError","it","return","next","dependents","indexOf","splice","dependentSet","delete","UNSET","runtimes","rt","declare","decl","out","keys","declared","parseWatches","$watch","stream","$stream","status","errors","def","parseStreams","connected","document","documentElement","hasAttribute","NAMESPACES","temporal","install","chain","dollar","first","known","key","split","beforeWrite","handled","_engine","charCodeAt","temporal_default"],"sources":["../../../src/temporal/watch.ts","../../../src/temporal/stream.ts","../../../src/features/temporal.ts"],"sourcesContent":["/**\n * `$watch` — the headless subscription (README \"Watch\", docs/state-watch-hook-design.md).\n *\n * A handler fires at the end of a drain, once per location that landed in it: a write of its\n * path or of an object above it in the same row, a change that reached its getter, a row that\n * entered its list. `cur` is the value at the drain; `prev` the value before the batch's first\n * write when a primitive was written (for a getter: its previous evaluation). A change that reaches\n * a getter fires it, whether its value changed or not (3.x D4: a watch has no condition of its own).\n * A row's getter that no write of the batch changed — it read none of the written paths, directly or\n * through a getter it read — fires only if its value changed: a row a list kept when a write\n * re-synced or re-sorted the list (`items = [...items, x]`) is reached again through what it read\n * under the row, which did not change (#389). A write at the list (or above it) changes what a row\n * read there (`this.items.length`), not under its row.\n * Declaration order between handlers, ascending indexes between rows of one path.\n *\n * A handler's writes form the next batch. Each write carries a chain depth (as @wcstack/state\n * 3.4, #354): 0, or one more than the depth of what fired the handler making it — or restarted the\n * `$stream` making it (stream.ts: its run's values and end too, within the task the run started in).\n * For a data path that is the deepest write landing there in the batch; for a getter, the first write\n * since it was last evaluated (a reached getter is not reached again until it is read), and 0 when a\n * list re-synced in the drain reached it — loops through those are left to the render chain\n * (MAX_RENDER_CHAIN). A handler fired more than MAX_CHAIN deep does not\n * run (as 3.x: 33 links run): the chain is cut and reported once. Writes riding in the same batch (a\n * render's write-back) neither lengthen nor reset it.\n *\n * Differences from @wcstack/state 3.3 that rows make possible: a row watch needs neither a\n * `for` binding nor `$listKeys` (the watch keeps its lists synced itself), wildcard getters are\n * eager too, and a whole-array assignment fires only for the rows that entered the list (a row\n * kept by identity did not change).\n */\nimport type { Engine } from \"../engine\";\nimport type { Pattern } from \"../pattern\";\nimport type { StateList, StateRow } from \"../list\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { hooks } from \"../hooks\";\n\ntype Handler = (this: unknown, cur: unknown, prev: unknown, ...indexes: number[]) => unknown;\n\ninterface Watch {\n readonly path: string;\n readonly p: Pattern;\n readonly handler: Handler;\n /** A getter (or under one): kept evaluated, `prev` is its previous evaluation. */\n getter: boolean;\n /** Previous evaluation by row (getter watches; the root's under ROOT): a removed row takes its entry with it. */\n last: WeakMap<object, unknown>;\n}\n\n/**\n * A landing of a batch: `prev` (the first write's), the deepest write's chain depth, and whether a\n * write landed there (not only a change that reached a getter).\n */\ntype Hit = [prev: unknown, depth: number, landed: boolean];\n\nexport const MAX_CHAIN = 32;\nconst ROOT = {};\n/**\n * An explicit index (`items.0.v`, read like a getter): a write to another row, a list change,\n * reaches it unchanged. A leading numeric segment is a root key (`2024.total`), not an index.\n */\nconst INDEX_PATH = /\\.\\d/;\nconst PROTOTYPE_NAMES = new Set(Object.getOwnPropertyNames(Object.prototype));\n\n/**\n * The current task's number, bumped in the next task after it is asked for: a MessageChannel message\n * (neither throttled in a background tab nor replaced by a faked timer), or a timer where there is none.\n */\nlet taskSeq = 0;\nlet pinged = false;\nlet ping: (() => void) | null = null;\nconst nextTask = (): void => {\n pinged = false;\n taskSeq++;\n};\nexport function thisTask(): number {\n if (ping === null) {\n if (typeof MessageChannel === \"function\") {\n const ch = new MessageChannel();\n ch.port1.onmessage = nextTask;\n // (Node: the port must not keep the process alive)\n (ch.port1 as { unref?: () => void }).unref?.();\n ping = () => ch.port2.postMessage(0);\n } else ping = () => setTimeout(nextTask, 0);\n }\n if (!pinged) {\n pinged = true;\n ping();\n }\n return taskSeq;\n}\n\n/** Whether a write at a path of `changed` changed what getter `g` read (directly, or through a getter it read). */\nfunction reads(g: Pattern, changed: Set<Pattern>): boolean {\n const seen = new Set<Pattern>();\n const stack = [g];\n while (stack.length > 0) {\n const h = stack.pop()!;\n if (seen.has(h)) continue;\n seen.add(h);\n for (const s of h.sources) {\n for (const p of changed) {\n // a write at the list a row is in (or above it) changes what was read there, not under the row\n if (s.isUnder(p) && (s.depth === p.depth || !(p.depth < h.depth && h.lists[p.depth + 1]!.isUnder(p)))) return true;\n }\n if (s.getter !== null) stack.push(s);\n }\n }\n return false;\n}\n\nexport function parseWatches(engine: Engine, decl: unknown): Watch[] {\n if (decl === undefined) return [];\n if (decl === null || typeof decl !== \"object\") raiseError(\"$watch must be an object mapping paths to handler functions.\");\n const out: Watch[] = [];\n for (const path of Object.keys(decl)) {\n const handler = (decl as Record<string, unknown>)[path];\n if (path === \"\" || path[0] === \"$\" || path.includes(\"@\") || PROTOTYPE_NAMES.has(path)) raiseError(`$watch path \"${path}\" is not a path of the state tree.`);\n if (typeof handler !== \"function\") raiseError(`$watch entry \"${path}\" must be a function.`);\n const p = engine.pattern(path);\n hooks.declared?.(engine, p, true);\n out.push({ path, p, handler: handler as Handler, getter: false, last: new WeakMap() });\n }\n return out;\n}\n\nexport class WatchRuntime {\n readonly engine: Engine;\n readonly watches: Watch[];\n active = false;\n /** Landings of the current batch: watch → row → hit. */\n private hits = new Map<Watch, Map<StateRow | null, Hit>>();\n /**\n * What elements wrote to a watched data path before the watches were active — the value an\n * element already had when its binding attached (an open `<wcs-sse>`, the router's first params):\n * [watch, row, the value before, the value the element wrote]. Whether that value is\n * there before or after the bindings attach depends on how fast the page loaded, so activate()\n * fires it once, when the path still holds it (docs/seam-apps.md: state-collab-board, router-admin).\n * A write from code before then (`$connectedCallback`) fires nothing, as before.\n */\n private early: [Watch, StateRow | null, unknown, unknown][] = [];\n /** The chain depth of a write made now: 0, or one more than what fired the running handler (or restart). */\n depth = 0;\n /**\n * The paths a cut reported in task `cutTask`. A chain carries its depth only synchronously (and\n * through a `$stream`'s values within the task its run started in): a cut of the same paths later\n * in the task is the same chain's — what it left running reaching the limit again.\n */\n private cutTask = -1;\n private reported = new Set<string>();\n /** The paths written in the batch (what a change reaching a getter may have come from). */\n private changed: Set<Pattern> | null = null;\n\n constructor(engine: Engine, watches: Watch[]) {\n this.engine = engine;\n this.watches = watches;\n }\n\n /** After `$connectedCallback` (and on reconnect): watches see the writes from now on. */\n activate(): void {\n const engine = this.engine;\n this.hits.clear();\n const early = this.early;\n this.early = [];\n for (const w of this.watches) {\n w.getter = w.p.getter !== null || w.p.underGetter;\n w.last = new WeakMap();\n // (the list a row watch reads can be a getter that throws too)\n this.prime(w, () => {\n if (w.p.depth === 0) {\n if (w.getter) w.last.set(ROOT, engine.readUntracked(w.p, null));\n } else {\n // a row watch keeps its lists synced, rendered or not; a getter watch is eager per row\n this.eachRow(w.p, 1, null, (row) => {\n if (w.getter) this.prime(w, () => w.last.set(row, engine.readUntracked(w.p, row)));\n });\n }\n });\n }\n this.active = true;\n // what elements brought before now, still there: fired once, as the writes of a batch\n for (const [w, row, before, value] of early) {\n if ((row === null || row.alive) && Object.is(engine.readUntracked(w.p, row), value)) this.hit(w, row, before, true);\n }\n if (this.hits.size > 0) engine.schedule();\n }\n\n /** What a watch reads before the writes (its `prev`): what throws is reported, the others go on. */\n private prime(w: Watch, read: () => void): void {\n try {\n read();\n } catch (error) {\n console.error(`[@wcstack/state] $watch initial evaluation of \"${w.path}\" threw.`, error);\n hooks.noticed?.(this.engine, { \"type\": \"state:watch-error\", \"phase\": \"prime\", \"path\": w.path, \"error\": error });\n }\n }\n\n deactivate(): void {\n this.active = false;\n this.hits.clear();\n this.early = [];\n }\n\n /** Calls fn for every row at p.depth, creating the lists on the way (they then stay synced). */\n private eachRow(p: Pattern, k: number, parent: StateRow | null, fn: (row: StateRow) => void): void {\n const engine = this.engine;\n const list = engine.childList(parent, p.lists[k]!);\n for (const row of list.rows) {\n if (k === p.depth) fn(row);\n else this.eachRow(p, k + 1, row, fn);\n }\n }\n\n /** Records a landing at the current depth: the first `prev` stays, the deepest write's depth wins. */\n private hit(w: Watch, row: StateRow | null, prev: unknown, landed: boolean): void {\n let rows = this.hits.get(w);\n if (rows === undefined) this.hits.set(w, (rows = new Map()));\n const h = rows.get(row);\n if (h === undefined) rows.set(row, [prev, this.depth, landed]);\n else {\n if (h[1] < this.depth) h[1] = this.depth;\n h[2] ||= landed;\n }\n }\n\n written(p: Pattern, row: StateRow | null, old: unknown, value: unknown, direct: boolean, element?: boolean): void {\n if (!this.active) {\n // an element's write to a watched data path itself, before the watches are active (see `early`)\n if (element) for (const w of this.watches) if (w.p === p) this.early.push([w, row, old, value]);\n return;\n }\n (this.changed ??= new Set()).add(p);\n for (const w of this.watches) {\n const wp = w.p;\n // the watched path, or an object above it in the same row (a getter's row replaced included)\n if (wp.depth !== p.depth || !wp.isUnder(p)) continue;\n // `prev`: a getter's previous evaluation; for data, the old value the same-value guard reads\n // when a primitive was written there (none when it is off, or above it)\n this.hit(w, row, w.getter ? w.last.get(row ?? ROOT) : wp === p && direct && this.engine.guard && (value === null || (typeof value !== \"object\" && typeof value !== \"function\")) ? old : undefined, true);\n }\n }\n\n getterReached(g: Pattern, row: StateRow | null): void {\n if (!this.active) return;\n // a getter, or a path under it in the same row — also one that became so after the activation\n // (a mounted component's exported getter, a volume's accessor grafted later)\n for (const w of this.watches) {\n if ((w.getter ||= w.p.getter !== null || w.p.underGetter) && w.p.depth === g.depth && w.p.isUnder(g)) this.hit(w, row, w.last.get(row ?? ROOT), false);\n }\n }\n\n /** Rows that entered a list a row watch ranges over fire (and nested lists under them sync). */\n listSynced(list: StateList, old: StateRow[]): void {\n if (!this.active) return;\n let before: Set<StateRow> | null = null;\n for (const w of this.watches) {\n const wp = w.p;\n if (wp.depth < list.depth || wp.lists[list.depth] !== list.pattern) continue;\n before ??= new Set(old);\n for (const row of list.rows) {\n if (before.has(row)) continue;\n if (wp.depth === list.depth) this.hit(w, row, undefined, true);\n else this.eachRow(wp, list.depth + 1, row, (r) => this.hit(w, r, undefined, true));\n }\n }\n }\n\n drained(): void {\n const changed = this.changed;\n this.changed = null;\n if (!this.active || this.hits.size === 0) return;\n const batch = this.hits;\n this.hits = new Map();\n const engine = this.engine;\n const cut: string[] = [];\n for (const w of this.watches) {\n const rows = batch.get(w);\n if (rows === undefined) continue;\n const entries = [...rows].filter(([row]) => row === null || row.alive);\n if (entries.length > 1) entries.sort((a, b) => compareRows(a[0]!, b[0]!));\n // (whether a write of the batch changed what the watched getter read: asked once, for an unchanged row)\n let real: boolean | undefined;\n for (const [row, [prev, depth, landed]] of entries) {\n let cur: unknown;\n // (DevTools: the handler fired, or what threw — the value's evaluation or the handler)\n let phase = \"evaluate\";\n const saved = engine.ctx;\n this.depth = depth + 1;\n engine.feeding++;\n try {\n // (read past the limit too: a getter's cache is then current, and its next change reaches it)\n cur = engine.readUntracked(w.p, row);\n if (w.getter) {\n w.last.set(row ?? ROOT, cur);\n // unchanged: an explicit index, or a row no write of the batch changed (a row a list kept, #389)\n if (Object.is(cur, prev) && (INDEX_PATH.test(w.path) || (row !== null && !landed && !(real ??= changed !== null && reads(getterOf(w.p), changed))))) continue;\n }\n // fired more than MAX_CHAIN deep: the chain stops here (the batch's other handlers run)\n if (depth > MAX_CHAIN) {\n if (!cut.includes(w.path)) cut.push(w.path);\n continue;\n }\n engine.ctx = row;\n hooks.noticed?.(engine, { \"type\": \"state:watch-fired\", \"path\": w.path });\n phase = \"handler\";\n w.handler.call(engine.proxy, cur, prev, ...engine.indexesOf(row));\n } catch (error) {\n console.error(`[@wcstack/state] $watch \"${w.path}\" failed; the other watches still run.`, error);\n hooks.noticed?.(engine, { \"type\": \"state:watch-error\", \"phase\": phase, \"path\": w.path, \"error\": error });\n } finally {\n engine.ctx = saved;\n this.depth = 0;\n engine.feeding--;\n }\n }\n }\n if (cut.length > 0) this.chainCut(cut);\n }\n\n /** A chain of handlers / stream restarts went past MAX_CHAIN: reported once a task for its paths (nothing is rolled back). */\n chainCut(paths: string[]): void {\n const task = thisTask();\n if (task !== this.cutTask) {\n this.cutTask = task;\n this.reported.clear();\n }\n const fresh = paths.filter((path) => !this.reported.has(path));\n if (fresh.length === 0) return;\n for (const path of fresh) this.reported.add(path);\n console.error(`[@wcstack/state] $watch handlers / $stream restarts kept writing for ${MAX_CHAIN} batches; the chain is cut (nothing is rolled back).`);\n hooks.noticed?.(this.engine, { \"type\": \"state:watch-chain-limit\", \"maxDepth\": MAX_CHAIN, \"paths\": fresh });\n }\n}\n\n/** The getter a watched path is, or lies under (in the same row). */\nfunction getterOf(p: Pattern): Pattern {\n while (p.getter === null && p.parent !== null) p = p.parent;\n return p;\n}\n\n/** Ascending indexes, outermost first. */\nfunction compareRows(a: StateRow, b: StateRow): number {\n const ia: number[] = [];\n const ib: number[] = [];\n for (let r: StateRow | null = a; r !== null; r = r.list.parentRow) ia.unshift(r.index);\n for (let r: StateRow | null = b; r !== null; r = r.list.parentRow) ib.unshift(r.index);\n for (let i = 0; i < ia.length && i < ib.length; i++) if (ia[i] !== ib[i]) return ia[i] - ib[i];\n return ia.length - ib.length;\n}\n","/**\n * `$stream` — an async producer folded into one reactive property (README \"Streams\",\n * packages/state/docs/streams.md).\n *\n * `args` runs as a getter of its own (a pattern with no path in the state), so the paths it reads\n * are tracked like any getter's; a change that reaches it restarts the stream at the end of the\n * drain, once (switchMap: abort, reset to `initial`, re-run `args`, call `source`). Its\n * dependencies are captured afresh on every run. `$streamStatus.<name>` / `$streamError.<name>` are\n * read-only companions kept on the state.\n *\n * A restart's writes are reactions: they continue the render chain (MAX_RENDER_CHAIN), and the\n * `$watch` chain (watch.ts) one deeper than the write that reached `args` (#354). That depth is the\n * deepest such write's for a data path `args` reads, but the first one's since `args` was last\n * evaluated when the change came through a getter (a reached getter is not reached again until it\n * is read), and 0 when a list re-synced in the drain reached it: such loops are left to the render\n * chain. A restart more than MAX_CHAIN deep is not made (the chain is cut and reported); the next\n * change of its inputs restarts it.\n *\n * A run's own writes after its start — a value its source yields, the status `done` / `error` — made\n * within the task the run started in (synchronously or in its microtasks) are as deep as the run: the\n * `$watch` handlers they fire and the restarts they cause continue its chain, so a loop through a\n * source that yields at once (a `$watch` on the value moving what `args` reads, two streams reading\n * each other's values) is cut instead of running on microtasks alone. From a later task (a network\n * response, a message, a timer) they are new input, as a write from code: they start a chain afresh.\n */\nimport type { Engine } from \"../engine\";\nimport { FAILED, UNSET, type Pattern } from \"../pattern\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { MAX_CHAIN, thisTask, type WatchRuntime } from \"./watch\";\n\ntype Status = \"idle\" | \"active\" | \"done\" | \"error\";\n\ninterface Entry {\n readonly name: string;\n readonly source: (args: unknown, signal: AbortSignal) => unknown;\n readonly fold: ((acc: unknown, chunk: unknown) => unknown) | undefined;\n readonly initial: unknown;\n /** The `args` getter (null without args: start once). */\n readonly g: Pattern | null;\n readonly args: (() => unknown) | null;\n controller: AbortController | null;\n restart: boolean;\n /** The `$watch` chain depth of what asked for the restart (meaningful while `restart`). */\n depth: number;\n}\n\nconst STATUS = \"$streamStatus\";\nconst ERROR = \"$streamError\";\nconst PROTOTYPE_NAMES = new Set(Object.getOwnPropertyNames(Object.prototype));\n\n/** A read-only companion path is being written by the runtime itself. */\nexport let internalWrite = false;\n\nfunction hasAccessorOrMethod(target: object, name: string): boolean {\n for (let o: object | null = target; o !== null && o !== Object.prototype; o = Object.getPrototypeOf(o)) {\n const d = Object.getOwnPropertyDescriptor(o, name);\n if (d !== undefined) return d.get !== undefined || d.set !== undefined || typeof d.value === \"function\";\n }\n return false;\n}\n\n/** Validates `$stream` and materializes the value property and the companions on `target`. */\nexport function parseStreams(engine: Engine, target: Record<string, any>): Entry[] {\n const decl = target.$stream;\n if (decl === undefined) return [];\n if (decl === null || typeof decl !== \"object\") raiseError(\"$stream must be an object mapping stream names to definitions.\");\n const entries: Entry[] = [];\n const status: Record<string, Status> = {};\n const errors: Record<string, unknown> = {};\n for (const name of Object.keys(decl)) {\n // the author's object: read by quoted keys (the build shortens internal property names)\n const def = decl[name];\n if (name === \"\" || name[0] === \"$\" || /[.*]/.test(name) || PROTOTYPE_NAMES.has(name)) raiseError(`$stream entry \"${name}\" must be a flat property name.`);\n if (def === null || typeof def !== \"object\") raiseError(`$stream entry \"${name}\" must be an object.`);\n const source = def[\"source\"];\n const fold = def[\"fold\"];\n const args = def[\"args\"];\n const initial = def[\"initial\"];\n if (typeof source !== \"function\") raiseError(`$stream entry \"${name}\" needs a source function.`);\n if (fold !== undefined && typeof fold !== \"function\") raiseError(`$stream entry \"${name}\": fold must be a function.`);\n if (fold !== undefined && !(\"initial\" in def)) raiseError(`$stream entry \"${name}\": fold needs an initial value.`);\n if (args !== undefined && typeof args !== \"function\") raiseError(`$stream entry \"${name}\": args must be a function.`);\n if (hasAccessorOrMethod(target, name)) raiseError(`$stream entry \"${name}\" collides with a getter, setter or method of the state.`);\n if (target[name] === undefined) target[name] = initial;\n status[name] = \"idle\";\n errors[name] = null;\n entries.push({\n name, source, fold, initial, controller: null, restart: false, depth: 0,\n g: args === undefined ? null : engine.pattern(`$streamArgs.${name}`),\n args: args === undefined ? null : function (this: unknown) { return args(this); },\n });\n }\n target[STATUS] = status;\n target[ERROR] = errors;\n return entries;\n}\n\nexport class StreamRuntime {\n readonly engine: Engine;\n readonly entries: Entry[];\n /** The engine's `$watch` runtime: it holds the depth of the write made now, and reports a cut. */\n readonly watch: WatchRuntime;\n\n constructor(engine: Engine, entries: Entry[], watch: WatchRuntime) {\n this.engine = engine;\n this.entries = entries;\n this.watch = watch;\n }\n\n private set(ns: string, name: string, value: unknown): void {\n internalWrite = true;\n try {\n this.engine.write(this.engine.pattern(`${ns}.${name}`), null, value);\n } finally {\n internalWrite = false;\n }\n }\n\n /** Eager start after `$connectedCallback`: an `args` failure is thrown as is. */\n startAll(): void {\n for (const e of this.entries) this.start(e, true);\n }\n\n /** A re-set replaced the state: the old runs stop without touching the new state. */\n abortAll(): void {\n for (const e of this.entries) {\n e.restart = false;\n e.controller?.abort();\n e.controller = null;\n }\n }\n\n stopAll(): void {\n for (const e of this.entries) {\n e.restart = false;\n if (e.controller !== null) {\n e.controller.abort();\n e.controller = null;\n }\n this.set(STATUS, e.name, \"idle\");\n }\n }\n\n getterReached(g: Pattern): void {\n const depth = this.watch.depth;\n for (const e of this.entries) {\n if (e.g !== g) continue;\n // (a restart a stop or a re-set dropped leaves its depth behind)\n e.depth = e.restart ? Math.max(e.depth, depth) : depth;\n e.restart = true;\n }\n }\n\n /** At the end of a drain (after the watches): each stream whose `args` inputs changed restarts once. */\n drained(): void {\n const engine = this.engine;\n const watch = this.watch;\n const cut: string[] = [];\n for (const e of this.entries) {\n if (!e.restart) continue;\n const depth = e.depth;\n e.restart = false;\n if (depth > MAX_CHAIN) {\n cut.push(e.name);\n // reached, not re-run: the next change of its inputs must reach it again\n e.g!.rootValue = FAILED;\n continue;\n }\n watch.depth = depth + 1;\n engine.feeding++;\n try {\n this.start(e, false);\n } finally {\n engine.feeding--;\n watch.depth = 0;\n }\n }\n if (cut.length > 0) watch.chainCut(cut);\n }\n\n private start(e: Entry, eager: boolean): void {\n const engine = this.engine;\n if (e.controller !== null) e.controller.abort();\n e.controller = null;\n let args: unknown;\n if (e.g !== null) {\n const g = e.g;\n // (re)attached on every start: a re-set forgets every accessor of the old state\n g.getter = e.args;\n const kept = g.sources.slice();\n untrack(g);\n try {\n args = engine.read(g, null);\n checkArgs(e.name, g, args);\n } catch (error) {\n // the dependencies of the last successful run stay: touching one retries\n untrack(g);\n for (const s of kept) s.addDependent(g);\n g.rootValue = FAILED;\n if (eager) throw error;\n this.set(ERROR, e.name, error);\n this.set(STATUS, e.name, \"error\");\n return;\n }\n }\n const ctrl = new AbortController();\n e.controller = ctrl;\n engine.write(engine.pattern(e.name), null, e.initial);\n this.set(ERROR, e.name, null);\n this.set(STATUS, e.name, \"active\");\n void this.consume(e, ctrl, args);\n }\n\n private async consume(e: Entry, ctrl: AbortController, args: unknown): Promise<void> {\n const engine = this.engine;\n const signal = ctrl.signal;\n const live = (): boolean => !signal.aborted && e.controller === ctrl;\n const p = engine.pattern(e.name);\n // the run's depth and task: what it writes in that task continues its chain\n const depth = this.watch.depth;\n const task = thisTask();\n const put = (fn: () => void): void => {\n if (thisTask() === task) this.watch.depth = depth;\n try {\n fn();\n } finally {\n this.watch.depth = 0;\n }\n };\n let acc = e.initial;\n try {\n const producer: any = await e.source(args, signal);\n if (!live()) return;\n const chunk = (v: unknown): void => {\n acc = e.fold !== undefined ? e.fold(acc, v) : v;\n put(() => engine.write(p, null, acc));\n };\n if (producer !== null && typeof producer?.getReader === \"function\") {\n // a ReadableStream: only reader.cancel() can unwind a parked read\n const reader = producer.getReader();\n signal.addEventListener(\"abort\", () => { reader.cancel().catch(() => {}); });\n for (;;) {\n const r = await reader.read();\n if (!live()) return;\n if (r.done) break;\n chunk(r.value);\n }\n } else if (producer !== null && typeof producer?.[Symbol.asyncIterator] === \"function\") {\n const it = producer[Symbol.asyncIterator]();\n signal.addEventListener(\"abort\", () => { void it.return?.(); });\n for (;;) {\n const r = await it.next();\n if (!live()) return;\n if (r.done) break;\n chunk(r.value);\n }\n } else {\n throw new TypeError(`$stream \"${e.name}\": source must return an async iterable or a ReadableStream`);\n }\n if (!live()) return;\n e.controller = null;\n put(() => this.set(STATUS, e.name, \"done\"));\n } catch (error) {\n if (!live()) return;\n e.controller = null;\n ctrl.abort();\n put(() => {\n this.set(ERROR, e.name, error);\n this.set(STATUS, e.name, \"error\");\n });\n }\n }\n}\n\n/** Forgets what a getter read (its dependencies are captured again by the next evaluation). */\nfunction untrack(g: Pattern): void {\n for (const s of g.sources) {\n const i = s.dependents.indexOf(g);\n if (i >= 0) s.dependents.splice(i, 1);\n (s as any).dependentSet.delete(g);\n }\n g.sources.length = 0;\n g.rootValue = UNSET;\n}\n\nfunction checkArgs(name: string, g: Pattern, args: unknown): void {\n if (args !== null && typeof (args as any)?.then === \"function\") raiseError(`$stream \"${name}\": args must be synchronous (it returned a Promise).`);\n for (const s of g.sources) {\n if (s.depth > 0) raiseError(`$stream \"${name}\": args must not read a wildcard path (\"${s.path}\").`);\n if (s.path === name || s.path === `${STATUS}.${name}` || s.path === `${ERROR}.${name}`) raiseError(`$stream \"${name}\": args must not read the stream itself (\"${s.path}\").`);\n }\n}\n","/**\n * The temporal add-on (@wcstack/state/features/temporal): `$watch` and `$stream`.\n * At the end of every drain, after its report (`$renderedCallback`): the watches, then the\n * stream restarts. Both start after `$connectedCallback` and stop on disconnect.\n */\nimport type { Engine } from \"../engine\";\nimport { chain, first, handled, hooks, known, type Feature } from \"../hooks\";\nimport { raiseError } from \"../parser/raiseError\";\nimport { parseWatches, WatchRuntime } from \"../temporal/watch\";\nimport { internalWrite, parseStreams, StreamRuntime } from \"../temporal/stream\";\n\ninterface Runtime {\n watch: WatchRuntime;\n stream: StreamRuntime;\n connected: boolean;\n /** The state it was made for: a re-set refused after it (list-keys, recursion) leaves the old one in place. */\n target: object;\n}\n\nconst runtimes = new WeakMap<Engine, Runtime>();\n/** The engine's runtime when it is its state's (not one a refused re-set left: that one never runs). */\nfunction live(engine: Engine): Runtime | undefined {\n const rt = runtimes.get(engine);\n return rt?.target === engine.target ? rt : undefined;\n}\n\nfunction declare(engine: Engine, target: Record<string, any>): void {\n const watch = new WatchRuntime(engine, parseWatches(engine, target.$watch));\n const stream = new StreamRuntime(engine, parseStreams(engine, target), watch);\n const old = runtimes.get(engine);\n if (old !== undefined) {\n old.watch.deactivate();\n old.stream.abortAll();\n }\n runtimes.set(engine, { watch, stream, connected: old?.connected ?? false, target });\n}\n\nfunction element(engine: Engine, phase: \"mounting\" | \"back\" | \"connected\" | \"disconnected\" | \"reset\"): void {\n const rt = runtimes.get(engine);\n // an engine made before the add-on was installed has no runtime (and declares nothing temporal);\n // a server render (@wcstack/server) keeps streams at their initial value and watches off\n if (rt === undefined || phase === \"mounting\" || document.documentElement?.hasAttribute(\"data-wcs-server\")) return;\n // (kept on a runtime a refused re-set left too: the next re-set takes it over. \"back\" comes after\n // \"disconnected\", before $connectedCallback runs again: not connected yet)\n if (phase !== \"reset\") rt.connected = phase === \"connected\";\n // a refused state's runtime never runs, nor stops (writes `$streamStatus`), on the state that stayed\n if (rt.target !== engine.target) return;\n if (phase === \"disconnected\") {\n rt.watch.deactivate();\n rt.stream.stopAll();\n return;\n }\n if (!rt.connected) return;\n rt.watch.activate();\n rt.stream.startAll();\n}\n\nconst NAMESPACES = [\"$streamStatus\", \"$streamError\"];\n\nexport const temporal: Feature = {\n name: \"temporal\",\n install(): void {\n hooks.declare = chain(hooks.declare, declare);\n hooks.element = chain(hooks.element, element);\n hooks.written = chain(hooks.written, (engine, p, row, old, value, direct, element) => live(engine)?.watch.written(p, row, old, value, direct, element));\n hooks.getterReached = chain(hooks.getterReached, (engine, g, row) => {\n const rt = live(engine);\n if (rt === undefined) return;\n rt.watch.getterReached(g, row);\n rt.stream.getterReached(g);\n });\n hooks.listSynced = chain(hooks.listSynced, (engine, list, old) => live(engine)?.watch.listSynced(list, old));\n hooks.drained = chain(hooks.drained, (engine) => {\n const rt = live(engine);\n if (rt === undefined) return;\n rt.watch.drained();\n rt.stream.drained();\n });\n // `this.$streamStatus` (the object, untracked) and `this[\"$streamStatus.x\"]` (tracked)\n hooks.dollar = first(known, hooks.dollar, (engine, key) => {\n const ns = key.split(\".\", 1)[0];\n if (!NAMESPACES.includes(ns)) return undefined;\n return ns === key ? engine.target[key] : engine.read(engine.pattern(key), null);\n });\n hooks.beforeWrite = first(handled, hooks.beforeWrite, (_engine, p) => {\n if (!internalWrite && p.path.charCodeAt(0) === 36 && NAMESPACES.includes(p.path.split(\".\", 1)[0])) {\n raiseError(`\"${p.path}\" is read-only (the stream runtime owns it).`);\n }\n return false;\n });\n },\n};\nexport default temporal;\n"],"mappings":"0IAsDO,IACDA,EAAO,CAAC,EAKRC,EAAa,OACbC,EAAkB,IAAIC,IAAIC,OAAOC,oBAAoBD,OAAOE,YAM9DC,EAAU,EACVC,GAAS,EACTC,EAA4B,KAC1BC,EAAW,KACfF,GAAS,EACTD,KAEK,SAASI,IACd,GAAa,OAATF,EACF,GAA8B,mBAAnBG,eAA+B,CACxC,IAAMC,EAAK,IAAID,eACfC,EAAGC,MAAMC,UAAYL,EAEpBG,EAAGC,MAAiCE,UACrCP,EAAO,IAAMI,EAAGI,MAAMC,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EAAShM,MACzDiG,GAA0C,KAAzBjG,EAAEsC,EAAK2J,WAAW,IAAaZ,EAAWtG,SAAS/E,EAAEsC,EAAKuJ,MAAM,IAAK,GAAG,KAC5F9D,EAAW,IAAI/H,EAAEsC,kDAEZ,GAEX,GAEK4J,EAAQZ","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/state",
3
- "version": "4.0.4",
3
+ "version": "4.1.1",
4
4
  "description": "Reactive state management with declarative data binding for Web Components. Zero dependencies, buildless.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",