@wcstack/state 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.ja.md +7 -6
  2. package/README.md +7 -6
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.esm.js +1 -1
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/manifest.esm.js +5 -4
  8. package/dist/split/auto.js +1 -1
  9. package/dist/split/chunks/{chunk-JK3B3LLB.js → chunk-5Q4M6A3C.js} +2 -2
  10. package/dist/split/chunks/{chunk-UPSLR4FS.js → chunk-6I7GGFNJ.js} +2 -2
  11. package/dist/split/chunks/chunk-BKLFDVOP.js +2 -0
  12. package/dist/split/chunks/chunk-BKLFDVOP.js.map +1 -0
  13. package/dist/split/chunks/{chunk-BYQBV3ZC.js → chunk-DOWWBZVS.js} +2 -2
  14. package/dist/split/chunks/chunk-F3DVWVH3.js +2 -0
  15. package/dist/split/chunks/chunk-F3DVWVH3.js.map +1 -0
  16. package/dist/split/chunks/chunk-M67C46SN.js +2 -0
  17. package/dist/split/chunks/{chunk-OKBVNGFK.js.map → chunk-M67C46SN.js.map} +1 -1
  18. package/dist/split/chunks/chunk-NMOSSDKJ.js +2 -0
  19. package/dist/split/chunks/chunk-NMOSSDKJ.js.map +1 -0
  20. package/dist/split/core.js +1 -1
  21. package/dist/split/features/devtools.js +1 -1
  22. package/dist/split/features/diagnostics.js +1 -1
  23. package/dist/split/features/diagnostics.js.map +1 -1
  24. package/dist/split/features/list-keys.js +1 -1
  25. package/dist/split/features/recursion.js +1 -1
  26. package/dist/split/features/scopes.js +1 -1
  27. package/dist/split/features/ssr.js +1 -1
  28. package/dist/split/features/ssr.js.map +1 -1
  29. package/dist/split/features/temporal.js +1 -1
  30. package/dist/wcs-manifest.json +4 -8
  31. package/package.json +1 -1
  32. package/dist/split/chunks/chunk-3Q7LGONS.js +0 -2
  33. package/dist/split/chunks/chunk-3Q7LGONS.js.map +0 -1
  34. package/dist/split/chunks/chunk-4ECL4ITF.js +0 -2
  35. package/dist/split/chunks/chunk-4ECL4ITF.js.map +0 -1
  36. package/dist/split/chunks/chunk-BI4645UG.js +0 -2
  37. package/dist/split/chunks/chunk-BI4645UG.js.map +0 -1
  38. package/dist/split/chunks/chunk-OKBVNGFK.js +0 -2
  39. /package/dist/split/chunks/{chunk-JK3B3LLB.js.map → chunk-5Q4M6A3C.js.map} +0 -0
  40. /package/dist/split/chunks/{chunk-UPSLR4FS.js.map → chunk-6I7GGFNJ.js.map} +0 -0
  41. /package/dist/split/chunks/{chunk-BYQBV3ZC.js.map → chunk-DOWWBZVS.js.map} +0 -0
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- var e={};function t(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function n(e,t,n){return null==t?n:(...r)=>{let l=t(...r);return e(l)?l:n(...r)}}var r=e=>!0===e,l=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.Ct&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.Ct(t)}}function a(e,t){if(!s.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}var u=class{constructor(e,t,n){this.c=[],this.getter=null,this.ie=null,this.se=!1,this._=[],this.Q=[],this.pt=null,this.P=-1,this.z=c,this.De=null,this.It=null,this.Dt=null,this.W=null,this.pn=!1,this.mn=!1,this._n=!1,this.Z=0,this.mt=new Set,this.t=e,this.d=n,this.s=t;let r=null===n?[null]:n.h.slice(),l="*"===t;l&&r.push(n),this.n=r.length-1,this.q=l?[]:null===n?[t]:[...n.q,t],this.h=r}Wn(e){this.mt.has(e)||(this.mt.add(e),this._.push(e),e.Q.push(this))}Io(e){this.mt.delete(e);let t=this._;t.splice(t.indexOf(e),1)}Do(){this.getter=null,this.ie=null,this.P=-1,this.z=c,this._.length=0,this.mt.clear(),this.Q.length=0,this.pt=null,this.De=null,this.It=null,this.Dt=null,this.W=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.d}return!1}},c=Symbol("unset"),f=Symbol("dirty"),h=Symbol("failed"),d=class{constructor(e=null){this.ht=new Map,this.Vn=e}jt(e){return this.ht.get(e)}get(e){let t=this.ht.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),r=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),r),this.Vn?.(t),this.ht.set(e,t),r&&r.c.push(t),t}all(){return this.ht.values()}Mt(e){this.ht.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,r=e.split("."),l=[];for(let e=0;e<r.length;e++){let t=r[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,l.push(Number(t)),r[e]="*"):"*"===t&&l.push(-1)}if(!n)return{o:r.join("."),indexes:l};let i={o:e,indexes:null};return p.size>4095&&p.clear(),p.set(e,i),i}var g=class{constructor(e,t,n){this.yt=null,this.$=null,this.ye=null,this.W=null,this.c=null,this.y=!0,this.l=e,this.w=t,this.R=n}},y=class{constructor(e,t){this.C=null,this.f=[],this.$=null,this.L=null,this.te=!1,this.Lt=!1,this.bt=!1,this.o=e,this.ae=t,this.n=e.n+1}},b=[];function v(t,n,r){throw new Error(`[@wcstack/state] ${t}${e.Mo?.(t,n,r)??""}`)}function $(t,n=[]){return e.Lo?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function w(e,t,n,r){v($(e,t),n,r)}var A=class{constructor(e){this.wt=new Set,this.name=e}get size(){return this.wt.size}subscribe(e){return this.wt.add(e),()=>{this.wt.delete(e)}}unsubscribe(e){return this.wt.delete(e)}emit(...e){let t=[];for(let n of this.wt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${$(17,[this.name])}`,e)}return t}};function k(e,t,n){if(void 0===e)return[];Array.isArray(e)||w(18,[t]);let r=new Set;for(let l of e)("string"!=typeof l||""===l)&&w(19,[t]),l===n&&w(20,[t,l,n]),r.has(l)&&w(21,[t,l]),r.add(l);return e}var x=Symbol.for("wcstack.transition-runner");function S(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function T(e,t,n){let r=S(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var N="else",O="eventToken",j="command",C="class",M="attr",P="style",E=/^\$[1-9]\d{0,2}$/,W=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function I(e){let t=[],n=[],r="",l=null,i=!1,s=-1,o=-1,a=e=>{let l=function(e,t,n){let r=-1===t?e.length:t,l=-1===n?0:n;return e.slice(r-e.slice(0,r).trimStart().length,l+e.slice(l).trimEnd().length)}(r,s,o);(!e||l||i)&&(t.push(l),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:W.test(e)?Number(e):e)}(l,i))),r="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];l?n===l?l=null:(-1===s&&(s=r.length),r+=n,o=r.length):'"'===n||"'"===n?(l=n,i=!0):","===n?a():r+=n}return null!==l&&w(107,[l,e]),a(!0),{args:t,literals:n}}var R=e=>e.trim();function D(e,t){let n=[],r=null;for(let l=0;l<e.length;l++){let i=e[l];null!==r?i===r&&(r=null):"'"===i||'"'===i?r=i:i===t&&n.push(l)}return n}var L=(e,t)=>D(e,t)[0]??-1;function q(e,t){let n=[],r=0;for(let l of D(e,t))n.push(e.slice(r,l)),r=l+1;return n.push(e.slice(r)),n}function z(e,t,n){let r=L(e,"|");if(-1===r)return[e.trim(),[]];let l=e.slice(r+1).trim(),i=n.get(l);return void 0===i&&(i=function(e,t,n){let r=n??e.join("|");return e.map(e=>{let n=L(e,"("),l=(e=>D(e,")").pop()??-1)(e);if(-1===l&&(l=e.lastIndexOf(")")),-1!==n&&-1===l&&w(108,[e]),-1!==l&&-1===n&&w(109,[e]),-1!==l&&l<n&&w(110,[e]),-1!==l&&e.slice(l+1).trim().length>0){let t=e.slice(l+1).trim();w(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&w(112,[r]),i.includes("#")){let[,e]=i.split("#");w("input"===t?113:114,[i,e])}return-1===n?{Hn:i,args:[],literals:[]}:{Hn:i,...I(e.substring(n+1,l))}})}(q(l,"|").map(R),t,e),n.set(l,i)),[e.slice(0,r).trim(),i]}var U=new Map;function F(e){w(1101,[e])}function _(e){let[t,n]=z(e,"output",U);t.includes("@")&&w(32,[t]);let r=t,l=r.startsWith("."),i=l?r.slice(1):r;return(i.length>0&&i.split(".").some(e=>0===e.length)||!l&&0===i.length)&&w(119,[e]),function(e){e.includes("**")&&F(e);let t=e.split(".").length;t>512&&w(117,[e,t])}(r),{Ze:r,et:n}}var V=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&F(e),e}var K=0;function J(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var Y=()=>new Set,G=()=>[];function X(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Q(e,t){return e===t||e!=e&&t!=t}function Z(e,t,n){let r=e.W?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e.W.delete(t)}function ee(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function te(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ae;return null!==e&&e.l.n===t?e:null}function ne(e,t,n){let r=te(e,n);return null!==r&&r.l.o===t.h[n]?r:null}var re=class{constructor(e,t){this.je=0,this.u=null,this.Me=0,this.vt=new Set,this.tt=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.St=[],this.Le=null,this.Un=[],this.Ht=0,this.Y=null,this.oe=new Map,this.ue=new Map,this.Be=[],this._e=[],this.We=[],this.kt=!1,this.hn=!1,this.Kt=new WeakMap,this.D=0,this.Ut=0,this.gn=!1,this.qt=!1,this.zt=!1,this.Pe=0,this.qn=()=>{this.D=0,this.gn=!1},this.zn=()=>{this.Pe--},this.rp=null,this.rr=null,this.Bo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.nt=[],this.Wo={$untracked:e=>{let t=this.Y;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=te(this.u,t);null===n&&w(7,[e]);let r=this.o(e);if(null!==r.getter||r.se)return this.watchIndex(t),n.w===this.read(r,null);let l=this.Y;if(null!==l){let e=l.getter,n=r.De??(r.De=[]);if(!n.some(n=>n.getter===e&&n.Xn===t)){n.push({getter:e,Xn:t});let l=e.h[t];(l.It??(l.It=[])).push({source:r,getter:e})}}return n.w===this.v(r,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,te(this.u,n.n)))},$dependOn:e=>{this.resolve(H(e),this.u),null!==this.Y&&0===this.Y.be&&this.Gn(this.rp,this.rr,this.Y)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,r)=>this.yn(e,t,n,r),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],r=this.o(t,!0);this.bn("$resolve",t,r,n,!0);let l=this.Jn(r,n,null);if(e.length<3)return this.read(r,l);this.A(r,l,e[2])},$postUpdate:e=>{this.resolve(H(e),this.u);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.R=n.l.C[n.w],this.T.Xt(n)),this.wn(t,n),null!==n&&this.Qn(n,t,void 0,n.R,!1),0===t.n&&this.Zn(t,void 0,void 0,!0),this.Gt(t,n,void 0,void 0,!1)}},this.T=t,this.I=new d(e=>{this.nt.push(e),this.ot(e)}),this.eo(e);let n=this,r={getOwnPropertyDescriptor(e,t){let r=Reflect.getOwnPropertyDescriptor(n.target,t);return r&&(r.configurable=!0),r},get(e,t,r){let l=n.target;if("symbol"==typeof t)return Reflect.get(l,t);if(36===t.charCodeAt(0))return n.rt(t);if(t.indexOf(".")<0){let e=n.I.jt(t);if(void 0===e||null===e.getter){let e=l[t];if("function"==typeof e)return r===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.u),n.read(n.rp,n.rr)},set:(e,t,r)=>"symbol"==typeof t?Reflect.set(n.target,t,r):(n.resolve(H(t),n.u),n.A(n.rp,n.rr,r),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])r[e]=(t,...r)=>Reflect[e](n.target,...r);this.proxy=new Proxy({},r)}o(e,t){let n=this.I.get(e);return t||(n.pn=!0),n}to(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let r=Object.getOwnPropertyDescriptor(n,e);if(void 0===r.get&&void 0===r.set)continue;let l=this.o(e);l.getter=r.get??null,l.ie=r.set??null,null!==l.getter&&l.n>0&&(l.P=this.je++)}for(let e of this.I.all())this.ot(e)}ot(e){e.t.includes("**")&&F(e.t),("__proto__"===e.s||"prototype"===e.s)&&w(120,[e.t]);let t=e.d;e.se=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.se),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(E.test(n))e.getter=function(){return this[n]};else{let r=t.split("."),l=r.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(l<0||r.indexOf("*",l)>=0)return;e.getter=()=>(this.resolve(t,this.u),this.rp!==e?this.read(this.rp,this.rr):this.read(e.d,this.u)?.[n]),e.ie=r=>{if(this.resolve(t,this.u),this.rp!==e)return this.A(this.rp,this.rr,r);let l=this.read(e.d,this.u);null==l&&w(4,[t,l]),l[n]=r}}e._n=!0,e.n>0&&(e.P=this.je++)}Ve(e,t){let n=null===e?this.oe:e.c??=new Map,r=n.get(t);return void 0===r&&n.set(t,r=new y(t,e)),t.pn=!0,this.X(r),r}no(e){try{this.X(e)}catch(t){this.Jt(t,e.o.t,e.$?.S??null,"for")}}X(t){let n=this.v(t.o,t.ae);if(n===t.C)return;this.oo(t);let r=function(e,t,n){let r=Array.isArray(t)?t:b;if(r===e.C)return null;let l=e.f,i=r.length,s=l.length,o=new Array(i),a=0;for(;a<i&&a<s&&l[a].R===r[a];)o[a]=l[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&l[u].R===r[c];)o[c]=l[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,r[t]);else if(a>c)for(let e=a;e<=u;e++)n.Bt(l[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)l[e].R===r[e]&&(o[e]=l[e]);let i=new Map;for(let e=u;e>=a;e--){let n=l[e];if(e<=t&&o[e]===n)continue;let r=i.get(n.R);void 0===r?i.set(n.R,n):Array.isArray(r)?r.push(n):i.set(n.R,[r,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,l=r[t],s=i.get(l);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(l)):(n=s,i.delete(l))),o[t]=n??new g(e,t,l)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Bt(t);else n.Bt(e)}for(let e=a;e<i;e++){let t=o[e];t.w!==e&&(t.w=e,n.jo(t))}return e.f=o,e.C=r,l}(t,n,this);if(null===r)return;if(t.C===n){let e=J(this.Kt,n,G);if(e.push(t),e.length>1)for(let t of e)t.bt=!0}e.Qt?.(this,t,r),(null!==t.$||null!==t.L)&&!t.te&&(t.te=!0,this._e.push(t),this.we());let l=t.o.It;if(null!==l)for(let{source:e,getter:n}of l){let l=this.v(e,null),i=r[l],s=t.f[l];i!==s&&(void 0!==i&&i.y&&this.vn(n,i),void 0!==s&&this.vn(n,s))}}jo(e){this.T.Ho(this,e)}Bt(e){e.y=!1;let t=e.W;if(null!==t){for(let e of t)Z(e.source,e.key,e.sub);e.W=null}if(null!==e.c)for(let t of e.c.values()){this.oo(t);for(let e of t.f)this.Bt(e)}}oo(e){let t=this.Kt.get(e.C);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.bt=!1,1===t.length&&(t[0].bt=!1))}resolve(e,t){let n=m(e),r=this.rp=this.o(n.o,!0),l=n.indexes;this.rr=0===r.n?null:null===l?ne(t,r,r.n):this.Jn(r,l,t,e)}Jn(e,t,n,r){let l=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.Ve(l,a),c=t[o++];if(c<0)c=ne(n,e,s)?.w??-1;else if(r&&u.C===b&&Object(i=this.v(a,l))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=r.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(l=u.f[c]??null,null===l)break}return this.rp=e,l}it(e,t){return 0===e.n?ee(this.target,e.q):null===t?void 0:ee(t.R,e.q)}read(e,t){let n=this.Y;if(null!==n&&0===n.be&&this.Gn(e,t,n),null!==e.getter)return this.T.Ko(this,e,t);if(e.se){let n=this.read(e.d,t);return n?.[e.s]}return null===e.d&&!(e.s in this.target)&&!this.vt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&w(301,[e.t],e.s,Object.keys(this.target)),this.it(e,t)}v(e,t){let n=this.Y;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Gn(e,t,n){let r=n.getter;e.Wn(r),0===r.n?e.Z!==n.de&&(e.Z=n.de,n.Sn.push(e)):e.n>0&&te(t,Math.min(e.n,r.n))!==te(n.r,Math.min(e.n,r.n))&&(r.pt??(r.pt=new Set)).add(e)}Uo(e,t){for(let n=0;n<this.Ht;n++){let r=this.Un[n];r.getter===e&&r.r===t&&w(701,[e.t])}this.Ht>=128&&w(801,[e.t]);let n=this.Ht++;this.Me++;let r=this.Un[n]??={getter:e,r:t,be:0,de:0,Sn:[]};r.getter=e,r.r=t,r.be=0,r.de=++K,r.Sn.length=0;let l=this.Y;this.Y=r;let i=this.u;this.u=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.qo(e,r),t}finally{this.Me--,this.Ht--,this.Y=l,this.u=i,r.r=null}}qo(e,t){let n=t.de;for(let e of t.Sn)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.se&&Array.isArray(null!==t.getter?t.z:this.it(t,null))||this.io(t,e))}io(e,t){return e.Io(t),this.nt.push(e),!1}zo(){for(let e=this.nt;e.length>0;e=this.nt){this.nt=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.d||n.c.length>0||n._.length>0)&&(null===n.getter||n._n&&n.P<0)&&null===n.W){n.mn=!0,this.I.Mt(n),t.add(n.d);for(let e of n.Q)this.io(e,n)}for(let e of t)(e.c=e.c.filter(e=>!e.mn)).length||this.nt.push(e)}}watchIndex(e){let t=this.Y;if(null!==t&&0===t.be){let n=t.getter,r=n.h[e];if(r){let e=r.Dt??(r.Dt=[]);e.includes(n)||e.push(n)}}}rt(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:E.test(t)?+t.slice(1):0;return(e<1||e>128)&&w(1001,[t]),this.watchIndex(e),te(this.u,e)?.w}let r=this.Wo[t];if(void 0!==r)return r;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.rt?.(this,t)}eq(e,t){this.resolve(e,this.u);let n=this.rp,r=this.rr;if(null!==n.getter||n.se||n.n>0)return Q(this.read(n,r),t);let l=this.Y;return null!==l&&0===l.be&&this.Yo(n,t,l),Q(this.v(n,null),t)}Yo(e,t,n){let r=n.getter,l=n.r,i=null===l?this.Yn:l.W??(l.W=[]);for(let l=0;l<i.length;l++){let s=i[l];if(s.sub.getter===r&&s.source===e){if(Q(s.key,t))return void(s.de=n.de);s.de!==n.de&&(Z(e,s.key,s.sub),i.splice(l--,1))}}let s={getter:r,r:l};J(e.W??=new Map,t,Y).add(s),i.push({source:e,key:t,sub:s,de:n.de})}Zn(e,t,n,r){this.Zt(e,l=>{let i=l.W;if(null===i&&null===l.De)return;let s=l===e?[]:l.t.slice(e.t.length+1).split("."),o=ee(t,s),a=ee(n,s);if(null!==l.De&&this.Xo(l,o,a,r),null!==i)for(let e of r?i.keys():[o,a]){let t=i.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.y?this.T.ve(this,n.getter,n.r):Z(l,e,n)}})}A(t,n,r,l=!1,i=!1){if(this.Me>0&&w(8),i||this.Pe>0?this.qt=!0:this.zt=!0,e.Fe?.(this,t,n,r,i))return;if(null!==t.ie){try{this.kn(t.ie,n,[r])}finally{this.Gt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&w(2,[t.t]),t.n>0&&null===n&&w(3,[t.t]);let s=t.se?this.v(t,n):this.it(t,n);if(l||!this.Wt||!Object.is(s,r)||Object(r)===r){if("*"===t.s){let e=n;e.l.C[e.w]=r,e.R=r,this.T.Xt(e)}else{let e=1===t.q.length?0===t.n?this.target:n.R:this.v(t.d,n);null==e&&w(4,[t.t,e]),e[t.s]=r}this.En(t,n),null!==n&&this.Qn(n,t,s,r),0===t.n&&this.Zn(t,s,r),this.Gt(t,n,s,r,!0,i)}}so(e){return(this.Kt.get(e.C)??[]).filter(t=>t.C===e.C&&(null===t.ae||t.ae.y))}Qn(e,t,n,r,l=!0){let i=e.l;if(!i.bt&&null===i.o.getter&&!i.o._.length)return;let s=e.R,o=t.t.slice(i.o.t.length+2),a=(t,i)=>{if(void 0===i||i===e)return;let s=this.o(`${t.o.t}.*${o}`,!0);""===o&&(i.R=r,this.T.Xt(i)),l?this.En(s,i):this.wn(s,i),this.Gt(s,i,n,r,l)};for(let t of this.so(i))a(t,t.f[e.w]);if(""===o)return;let u=new Set([i.C]),c=e=>Array.isArray(e)&&e.includes(s),h=(e,t)=>{if(!u.has(e)&&u.add(e))for(let t of this.Kt.get(e)??[])for(let e of t.f)e.R===s&&a(t,e);for(let n of t){let t=n.z,r=t===f;r&&(t=this.oe.get(n)?.C),(r||c(t))&&!u.has(n._)&&u.add(n._)&&(!r&&t!==e&&this.T.ve(this,n,null),h(t,n._))}},d=e=>{for(let t of e.Q)if(!u.has(t)&&u.add(t))if(null!==t.getter)d(t);else if(!t.se){let e=this.it(t,null);c(e)&&h(e,t._)}};null!==i.o.getter?d(i.o):h(i.C,i.o._)}wn(e,t){this.Go(e,t,e=>{this.X(e);for(let t of e.bt?this.so(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.Et(e,n),this.wn(e,n)}})}En(e,t){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.X(t)}Go(e,t,n){let r=null===t?this.oe:t.c;if(null!==r)for(let t of r.values())t.o.ee(e)&&n(t)}Xo(e,t,n,r){for(let{getter:l,Xn:i}of e.De)this.lo(l.h[i],e=>{for(let i of r?e.f.keys():[t,n]){let t="number"==typeof i?e.f[i]:void 0;void 0!==t&&this.vn(l,t)}})}vn(e,t){t.l.n===e.n?this.T.ve(this,e,t):this.en(t,e,t=>this.T.ve(this,e,t))}Gt(t,n,r,l,i,s){e.Se?.(this,t,n,r,l,i,s),this.He(t,n)}He(e,t){this.T.Jo(this,e,t),this.we()}ao(e){let t=this.tt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.tt.set(e,n);let r=this.root,l=this.Kn;return r.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==r;i=i.parentNode){let r=i[n];if(void 0!==r&&(r(t),t.cancelBubble))return;let s=i[l];if(void 0!==s&&s.y&&s.Qo(e,t))return}}),n}reset(t){let n=this.target,r=this.vt;for(let e of this.I.all())null===e.d&&null!==e.getter&&r.add(e.s);this.eo(t);for(let e in n)"$"!==e[0]&&r.add(e);for(let e of r)e in t&&r.delete(e);for(let e of this.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.co(e);this.Le=null;try{this.Yt()}finally{this.$n()}e.element?.(this,"reset")}eo(t){for(let[e,n]of V)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||w(46);for(let e of n)a(e,"$features")}let r=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof r||!r||Array.isArray(r))&&w(44,["state","$behavior"]);for(let e in r)(!B.includes(e)||"boolean"!=typeof r[e])&&w(44,["$behavior",e]);let[l,i,s]=B.map(e=>r[e]??!0);void 0!==this.target&&(l!==this._t||i!==this.Wt||s!==this.Vt)&&w(45);let o=function(e,t){let n={};for(let r of k(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new A(r);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new A(t));let r=e.$on;if(void 0===r)return n;(null===r||"object"!=typeof r)&&w(22);for(let[e,l]of Object.entries(r)){let r=n.get(e);void 0===r&&w(23,[e]),"function"!=typeof l&&w(24,[e]),r.subscribe((...e)=>t(l,e))}return n}(t,this._o);this._t=l,this.Wt=i,this.Vt=s,e.fe?.(this,t),this.target=t,this.je=0;for(let e of this.I.all())e.Do();this.Yn.length=0,this.to(t),this.commands=o,this.ce=u}co(e){this.no(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.yt=null,n.W=null,this.Et(t,n),null!==n.c)for(let e of n.c.values())this.co(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ae)t.unshift(n.w);return t}Zo(e,t,n){let r=this.ce.get(e);void 0===r&&w(1301,[e],e,this.ce.keys()),r.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&w(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let r=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof r&&w(5,[e]),this.kn(r,n,[t,...this.H(n)])}kn(e,t,n){let r=this.u;this.u=t;try{return e.apply(this.proxy,n)}finally{this.u=r}}Et(e,t){if(null!==e.getter){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.We.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.ye;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let r=t.$;null!==r&&null!==r.pe&&r.uo(this,e);let l=t.l.L;if(null!==l)for(let n of l){let r=n.map.get(t);void 0!==r&&null!==r.pe&&r.uo(this,e)}}xn(e,t,n){this.Zt(e,e=>{let r=e._;for(let l=0;l<r.length;l++){let i=r[l];if(0===i.n)this.st(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.pt&&i.pt.has(e))this.nn(i.h[i.n],e=>this.st(i,e,n));else if(i.n<=e.n){let e=te(t,i.n);null!==e&&this.st(i,e,n)}else this.en(t,i,e=>this.st(i,e,n))}})}st(t,n,r){r(t,n)&&(e.ke?.(this,t,n),this.Et(t,n),this.xn(t,n,r))}Zt(e,t){t(e);let n=e.c;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.lo(e,e=>{for(let n of e.f)t(n)})}lo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let r=n.c?.get(e);void 0!==r&&t(r)})}en(e,t,n){if(e.l.n===t.n)return n(e);let r=e.c?.get(t.h[e.l.n+1]);if(void 0!==r)for(let e of r.f)this.en(e,t,n)}nr(e){let t=e.r;null===t?J(this.ue,e.o,Y).add(e):(t.ye??(t.ye=[])).push(e)}Nn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.ye;t.y&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.Be.push(e),this.we())}we(){this.kt||(this.kt=!0,queueMicrotask(this.Bo))}Rn(){for(let e of this.Be)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.We)e.Lt=!1;this.Be=[],this._e=[],this.We=[],this.T.vt(this)}fo(t,n){let r=[...new Set([...this.Be,...this._e,...this.We].map(e=>e.o.t))];console.error(`[@wcstack/state] ${$(t)}`,r),e.at?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:r}),this.Rn()}Yt(){this.kt=!1;let t=this.Ut;this.Ut=0;let n=0;if(!this.qt||this.zt?this.qn():t>0?n=t:1===(n=++this.D)&&setTimeout(this.qn,0),this.qt=this.zt=!1,n>100)101===n?this.fo(41,100):this.Rn();else{this.hn=!0;try{for(let e=0;this.Be.length>0||this._e.length>0||this.We.length>0;e++){if(e>=32){this.gn?this.Rn():this.fo(11,32),this.gn=!0;break}let t=this.We;if(t.length>0){this.We=[];for(let e of t)e.Lt=!1,this.no(e)}let r=this._e,l=this.Be;this._e=[],this.Be=[];let i=()=>{for(let e of r){e.te=!1;for(let t of[e.$,...e.L??[]])if(null!==t&&t.y)try{t.$t()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<l.length;t++){let n=l[t];!n.te||null===n.D==(0===e)||(n.te=!1,(null===n.Tn||n.Tn.y)&&this.Ke(n))}this.hn||(this.Ue(),this.kt&&(this.Ut=n+1))},s=r.length>0||l.some(e=>null!==e.D)?T("state",i):i();void 0!==s&&s.then(void 0,e=>console.error(e))}}finally{this.hn=!1}this.qt=this.zt=!1,this.Ue(),e.Oe?.(this),this.zo(),t>0&&this.kt&&(this.Ut=n+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,r){this.xt(e,{o:{t},a:n,on:()=>r})}Ke(e){try{e.apply()}catch(t){return void this.St.push([t,e])}null!==this.Le&&this.po(e.o,e.r)}po(e,t){let n=J(this.Le,e.t,G);null!==t&&n.push(this.H(t))}$n(){this.Le="function"==typeof this.target.$renderedCallback?new Map:null}Ue(){let t=this.Le;if(null!==t&&t.size>0){this.Le=new Map;let e,n=[...t.keys()],r={};for(let[e,n]of t)n.length>0&&(r[e]=n);this.Pe++;try{e=this.Ee("$renderedCallback",[n,r])}catch(e){console.error(e)}X(e)?e.then(this.zn,e=>{this.zn(),console.error(e)}):this.Pe--}if(0===this.St.length)return;let n=this.St;this.St=[];let r=this.target.$errorCallback;for(let[t,l]of n){e.qe?.(this,t,l);let n=l.o.t,i=l.on();if("function"==typeof r)try{let e=this.Ee("$errorCallback",[t,{path:n,bindingType:i,node:l.a}]);X(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${$(12,l.name?[i,n,l.name,l.i]:[i,n])}`,t,l.a)}}Ee(e,t=[]){let n=this.target[e];return"function"==typeof n?this.kn(n,null,t):void 0}mo(e,t,n){if(0===e.n)return void n(null,[]);let r=[],l=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.Ve(s,o),u=t=>{r.push(t.w),i===e.n?n(t,r):l(i+1,t),r.pop()};for(let e of i-1<t.length?[a.f[t[i-1]]]:a.f)void 0!==e&&u(e)};l(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.bn("$getAll",e,n,t,!1);let r=t;if(void 0===r){r=[];let t=this.u;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let l=ne(t,n,e);if(null===l)break;r.push(l.w)}0===r.length&&w(6,[e])}}let l=[];return this.mo(n,r,e=>l.push(this.read(n,e))),l}yn(e,t,n,r){Array.isArray(t)||w(9,[e]),this.Me>0&&w(8);let l=this.o(e,!0);this.bn("$setAll",e,l,t,!1);let i=[];this.mo(l,t,(e,t)=>i.push([e,t.slice()]));let s=!0===r?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&w(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,r]=i[e],a="function"==typeof n?n(this.v(l,t),...r):s?n[e]:n;void 0!==a&&(this.A(l,t,a),o++)}return o}bn(e,t,n,r,l){let i=r.length;(i>n.n||l&&i<n.n)&&w(l?901:902,[e,t,n.n,i])}},le={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},ie=()=>le,se=new Map,oe=new Set(["if","elseif","else","for"]),ae=new Set([N,"if","elseif","for","..."]),ue=new Set([C,M,P,j,O,"state"]);function ce(e){let t=function(e){return q(e,";")}(e).map(R).filter(e=>e.length>0).map(e=>{let t=L(e,":");-1===t&&w(101,[e]);let n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),l=n.split("#")[0].split("|")[0].trim();if(ae.has(l)){let t;return l!==n&&w(102,[e,l]),l===N?(r.length>0&&w(103,[e]),t={Ze:"#else",et:[]}):"..."===l?(0===r.length&&w(104,[e]),t=_(r),t.et.length>0&&w(105,[e])):(t=_(r),"for"===l&&t.et.length>0&&w(121,[e])),{$e:l,xe:[l],rn:[],j:[],...t,b:"..."===l?"spread":l}}(l===C||l===M)&&w(122,[e,l]);let i=_(r),s=function(e){let[t,n]=z(e,"input",se),r=t.split("#").map(R);r.length>2&&w(115,[t]);let[l,i]=r,s=l.split(".").map(R);return!(s.length>1&&""===s[0])&&(0===l.length||s.some(e=>0===e.length))&&w(116,[e]),{$e:l,xe:s,rn:i?i.split(",").map(R):[],j:n}}(n),[o]=s.xe;if(""===o&&s.xe.length>1){let e=s.xe.slice(1);return(e.includes("")||ue.has(e[0]))&&w(106,[n]),{...s,$e:e.join("."),xe:e,...i,b:"prop"}}return{...s,...i,b:"radio"===l||"checkbox"===l?l:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>oe.has(e.b))&&w(201,[e]),t}var fe=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],he=new Map,de=new Map;function pe(e){for(let t of Object.keys(e))he.set(t,{...e[t]});de.clear()}function me(e){return he.has(e)}function ge(e){w(26,[e])}function ye(e){w(27,[e])}function be(e,t){w(28,[e,t])}function ve(e,t){w(29,[e,t])}function $e(e){return!(!e||isNaN(Number(e)))}function we(e,t){return $e(e)||ye(t),Number(e)}function Ae(e,t,n){return we(e?.[t]??ge(n),n)}function ke(e,t){return void 0!==t&&t.length>0?t[0]:e}var xe=(e,t)=>({factory:n=>{let r=Ae(n,0,e);return n=>("number"!=typeof n&&be(e,n),t(n,r))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??ge("eq"),r=ke(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:($e(n)||ye("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??ge("ne"),r=ke(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:($e(n)||ye("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:xe("lt",(e,t)=>e<t),le:xe("le",(e,t)=>e<=t),gt:xe("gt",(e,t)=>e>t),ge:xe("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Te=!1;function Ne(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Oe(e){return 0===e.length?null:(Te||(Te=!0,pe(Se)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,l=de.get(r);if(typeof l<"u")return l;let i=he.get(e);void 0===i&&function(e,t){fe.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),w(501,[e],e,t)}(e,he.keys());let[s,o]=i.arity;t.length<s&&w(601,[e,s,t.length]),t.length>o&&w(602,[e,o,t.length]);let a=i.factory(t,n);return de.set(r,a),a}(e.Hn,e.args,e.literals)))}var je=Symbol.for("wcstack.trustedTypes.policy");function Ce(){let e=globalThis[je];return null!==e&&"object"==typeof e?e:null}function Me(e){globalThis[je]=e}function Pe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ee(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ce(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var We=Symbol.for("wcstack.state.view-transition-naming"),Ie=new WeakSet;function Re(){let e=S("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var De=new WeakMap,Le=e=>e.customElementRegistry??customElements;function qe(e,t,n,r,l,i=!1){let s=n.localName;if(!s.includes("-"))return l(null);let o=Le(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>qe(e,t,n,r,l,!0));let a=()=>{let e=o.get(s);o.upgrade(n),l(e?function(e){if(De.has(e))return De.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,ho:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return De.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==r&&!r.y||function(e,t,n){let r=n;null!==t&&(t.Nt??=[]).push(()=>{r=null}),e.then(()=>r?.())}(o.whenDefined(s),r,()=>{try{a()}catch(r){Be(e,r,t,n)}e.we()})}function ze(t,n,r,l,i=n.o,s,o,a){let u=a.properties.get(l)??null,c=a.inputs.has(l),f=t.Vt;f&&null===u&&!c&&w(38,[l]);let h=n.K;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&w(39,[h,l]),"connect"===n.X&&null===u&&w(40,[l]);let d=f&&null!==u&&!c,p=new Je(t,_e,r,l,i,s,o,n.x,void 0);p.j=n.j,nt(t,p,!d),null!==u&&!n.ro&&r.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.ho||e.detail?.(r,l,i)),(!p.An||!Object.is(i,p.value))&&(i=Ne(p.j,i),null===p.x&&(p.value=i),t.A(p.o,p.r,i,u.ho,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.Ke(p);else if("element"===m||"auto"===m){let e=()=>{if(null!==o&&!o.y)return;if("auto"===m&&void 0!==t.v(p.o,p.r))return void(d||t.Ke(p));let e=r[l];null===p.x&&(p.value=e),t.A(p.o,p.r,e,!1,!0)};"connect"!==n.X||r.isConnected?e():Promise.resolve().then(e)}return p}function Ue(e,t,n){w(e,[t.localName,n])}var Fe=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),_e=11,Ve=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Be=(e,t,n,r)=>e.Jt(t,n.o?.t??n.Rt,r,Ve[n.i]),He=Symbol();function Ke(e,t,n){let r=t.K;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.U:He}var Je=class{constructor(e,t,n,r,l,i,s,o,a,u=null){this.te=!1,this.j=null,this.An=!1,this.engine=e,this.i=t,this.a=n,this.name=r,this.o=l,this.r=i,this.Tn=s,this.x=o,this.value=a,this.D=u}on(){return Ve[this.i]}apply(){if(null!==this.D)return void this.D.$t();let e=Ne(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===_e||8===this.i||Pe(this.name)))return;if(this.value===He)return void(this.value=e);let t=this.a;if(this.i!==_e)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ge(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ne(this.j,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let r=this.sn(),l=n.v(this.o,this.r),i=Array.isArray(l)?l:[],s=i.includes(r);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==r):[...i,r]}else e=Ne(this.j,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},Ye=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ge(e,t,n,r){switch(e){case 0:return void(t.data=null==r?"":String(r));case 1:return void(Ye(n)?t[n]="innerHTML"===n?Ee(r):null==r?"":String(r):Pe(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Ee(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Xe]=[n,r])));case 8:return void(t.innerHTML=Ee(r));case 2:return null!=r&&"boolean"!=typeof r&&w(401,[n,typeof r]),void t.classList.toggle(n,!0===r);case 3:return void(null==r?t.removeAttribute(n):t.setAttribute(n,String(r)));case 4:return void(n.includes("-")?null==r?t.style.removeProperty(n):t.style.setProperty(n,String(r)):t.style[n]=null==r?"":String(r))}}var Xe=Symbol();function Qe(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Xe];void 0!==n&&(t[n[0]]=n[1])}var Ze=class{constructor(e,t,n,r){this.y=!0,this.ye=null,this.c=null,this.Nt=null,this.Fn=null,this.r=e,this.ze=t,this.M=n,this.F=r}Qo(e,t){let n=t.target,r=this.F,l=[],i=null;for(let t of r.ce){if(t.name!==e)continue;let s=r.On[t.a],o=ft(null===this.M?this.ze:this.M[s[0]],s,1);o.contains(n)&&(o!==i&&l.unshift([]),l[0].push(t),i=o)}for(let e of l){for(let n of e)n.Pn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.M?this.ze:this.M[this.M.length-1]}Ye(){let e=this.Fn;return(null===e?null:e.Cn(this.ze))??this.ze}insertBefore(e,t){let n=this.s;for(let r=this.Ye();;){let l=r.nextSibling;if(e.insertBefore(r,t),r===n)return;r=l}}bo(){null===this.M?this.ze.remove():ht(this.Ye(),this.s)}Re(e){if(this.y=!1,null!==this.Nt)for(let e of this.Nt)e();let t=this.ye;if(null!==t)for(let n=0;n<t.length;n++)e.Nn(t[n]);if(null!==this.c)for(let e of this.c)e.Re()}},et=class extends Ze{constructor(e,t,n,r){super(e,t,n,r),this.wo=0,this.V=null,this.pe=0===r.Xe.length?null:new Array(2*r.Xe.length)}vo(e,t){let n=this.V??=new Array(this.F.Xe.length),r=n[t];if(void 0===r){let l=this.F.Xe[t],i=this.pe;r=n[t]=new Je(e,l.i,i[2*t],l.name,l.o,this.r,this,l.x,i[2*t+1])}return r}uo(e,t){let n=this.F.Xe;for(let r=0;r<n.length;r++)n[r].o.ee(t)&&e.tn(this.vo(e,r))}Re(e){let t=this.r;t.$===this&&(t.$=null),super.Re(e)}};function tt(e,t,n,r){let l=te(n,t.n);try{return e.Ve(l,t)}catch(n){return e.Jt(n,t.t,r,"for"),null===l?e.oe.get(t):l.c.get(t)}}function nt(e,t,n){n&&e.nr(t);let r=t.Tn;null!==r&&(r.ye??=[]).push(t)}var rt=null;function lt(){let e=rt;return rt=null,e}var it=-1;function st(t,n,r,l,i=null){let s,o=n.On,a=n.build,u=n.So,c=null,f=e.Ce?.(n,null===l?i:l.S,null!==l),h=!f&&n.In,d=f?document.createDocumentFragment():(h?n.root:n.ln).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=ft(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==l?(p=m=new et(r,s,c,n),null===l.map?r.$=m:l.map.set(r,m)):p=new Ze(r,s,c,n),it>=0&&function(e,t,n,r){let l=null;if(null===t)l=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===l;e++)1===t[e].nodeType&&(l=t[e]);let i=l?.style;if(null===l||void 0===i||Ie.has(l))return;let s=globalThis[We]??={counter:0,assigned:0,warned:!1};s.assigned>=r?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${$(25,[r])}`)):(Ie.add(l),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==l?"row":"branch",it),n.ce.length>0){let e=t.Kn;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.sr,y=t.Le,b=n.lr?u.slice(0,o.length):u,v=null===m?null:m.pe;if(null!==v){let e=n.Xe;for(let t=0;t<e.length;t++)v[2*t]=b[e[t].a],v[2*t+1]=e[t].U}for(let e=0;e<g.length;e++){let n=g[e],l=b[n.a],i=n.P;if(i>=0&&null!==v){let e=m.V?.[i];if(void 0!==e){e.te=!1,t.Ke(e);continue}try{let e=Ne(n.x,t.read(n.o,r));e!==n.U&&(Ge(n.i,l,n.name,e),v[2*i+1]=e),null!==y&&t.po(n.o,r)}catch(e){t.xt(e,m.vo(t,i))}continue}switch(n.i){case 6:{let e=new ct(t,n.F,tt(t,n.o,r,l),l);(p.c??=[]).push(e),l===s&&(p.Fn=e),e.$t();break}case 7:{let e=at(t,n.G.map(e=>({F:e.F,o:e.o,x:e.x,S:b[e.a]})),r,p);(p.c??=[]).push(e),l===s&&(p.Fn=e);break}default:try{ot(t,n,l,r,p)}catch(e){Be(t,e,n,l)}}}return rt=p,d}function ot(t,n,r,l,i){let s=r;switch(n.i){case 5:return void function(e,t,n,r,l){let i=n.Pn,s=e=>i(e,r);if(n.tt){let r=e.ao(n.name),l=t[r];t[r]=void 0===l?s:e=>{l(e),s(e)},n.Ne&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.yo&&null!==l&&(l.Nt??=[]).push(()=>t.removeEventListener(n.name,s))}(t,r,n,l,i);case 12:return void qe(t,n,s,i,r=>function(t,n,r,l,i){let s=n.name,o=t.command(n.Rt.slice(9)),a=null===i?e.or?.(r,s):null;a||(null===i&&Ue(1202,r,`command.${s}`),i.commands.has(s)||w(1203,[r.localName,s]));let u=new WeakRef(r),c=o.subscribe((...e)=>{let t=u.deref();if(void 0!==t)return t.isConnected?a?a(t,e):t[s](...e):void 0;c()});null!==l&&(l.Nt??=[]).push(c)}(t,n,s,i,r));case 13:return void qe(t,n,s,i,e=>function(e,t,n,r,l){let i=t.name;null===l&&Ue(1202,n,`eventToken.${i}`);let s=l.properties.get(i);void 0===s&&w(1204,[n.localName,i]);let o=t.Rt;n.addEventListener(s.event,n=>{t.Tt&&n.preventDefault(),t.At&&n.stopPropagation();try{e.Zo(o,n,r)}catch(e){console.error(e)}})}(t,n,s,l,e))}let o=n.o,a=te(l,o.n);if(14===n.i)return void qe(t,n,s,i,e=>function(e,t,n,r,l,i){null===i&&Ue(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.go?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:r;ze(e,{...t,K:null,X:null},n,o,s,a,l,i)}}(t,n,s,a,i,e));if(n.Ne&&1===n.i)return void qe(t,n,s,i,r=>function(t,n,r,l,i,s){if(null!==s)return void ze(t,n,r,n.name,n.o,l,i,s);let o=new Je(t,1,r,n.name,n.o,l,i,n.x,Ke(t,n,l));o.j=n.j,!e.ar?.(o,n.ro)&&(nt(t,o,!0),t.Ke(o))}(t,n,s,a,i,r));let u=new Je(t,n.i,r,n.name,o,a,i,n.x,Ke(t,n,a));u.j=n.j,nt(t,u,!0),t.Ke(u),null!==n.Pt&&r.addEventListener(n.Pt,()=>u.ir())}function at(e,t,n,r){let l=new ut(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Je(e,7,s.S,"if",t,te(n,t.n),r,null,void 0,l);nt(e,o,!0),null===r&&l.ue.push(o),i??=o}return e.Ke(i),l}var ut=class{constructor(e,t,n){this.y=!0,this.O=null,this.w=-1,this.ue=[],this.engine=e,this.G=t,this.r=n}Cn(e){return null!==this.O&&this.G[this.w].S===e?this.O.Ye():null}$t(){let e=this.engine,t=-1;for(let n=0;n<this.G.length;n++){let r=this.G[n];if(null===r.o||Ne(r.x,e.read(r.o,te(this.r,r.o.n)))){t=n;break}}if(t!==this.w&&(it=Re(),null!==this.O&&(this.O.bo(),this.O.Re(e),this.O=null),this.w=t,t>=0)){let n=this.G[t],r=st(e,n.F,this.r,null,n.S);this.O=lt();let l=n.S.parentNode;l.insertBefore(r,n.S),Qe(l)}}Re(){this.y=!1;for(let e of this.ue)this.engine.Nn(e);null!==this.O&&this.O.Re(this.engine)}},ct=class{constructor(e,t,n,r){this.y=!0,this.Te=[],this.engine=e,this.F=t,this.l=n,this.S=r,null===n.$?(n.$=this,this.map=null):((n.L??=[]).push(this),this.map=new Map)}Cn(e){return 0===this.Te.length?null:this.Te[0].Ye()}Ft(e){return null===this.map?e.$:this.map.get(e)??null}Mt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Re(this.engine)}$t(){let e=this.engine,t=this.l.f,n=this.Te;it=Re();let r=t.length,l=n.length,i=this.S,s=i.parentNode;if(0===r){if(l>0){let e=n[0].Ye(),t=n[l-1].s,r=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){r=null;break}r.push(n)}null!==r?s.replaceChildren(...r):ht(e,t);for(let e=0;e<l;e++)this.Mt(n[e])}return void(this.Te=[])}let o=new Array(r),a=0;for(;a<r&&a<l&&this.Ft(t[a])===n[a];)o[a]=n[a],a++;let u=l-1,c=r-1;for(;u>=a&&c>=a&&this.Ft(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],r=t.r;r.y&&this.Ft(r)===t?t.wo=e:(t.bo(),this.Mt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(l>0)for(let e=0;e<n;e++){let n=this.Ft(t[a+e]);null!==n&&n.y?(u[e]=n.wo,f=!0):u[e]=-1}let h=c+1<r?o[c+1].Ye():i;if(f){let r=function(e){let t=e.length,n=new Uint8Array(t),r=new Int32Array(t).fill(-1),l=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=l.length;for(;i<s;){let n=i+s>>1;e[l[n]]<t?i=n+1:s=n}i>0&&(r[n]=l[i-1]),l[i]=n}let i=l.length>0?l[l.length-1]:-1;for(;i>=0;)n[i]=1,i=r[i];return n}(u),l=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Ft(n);null!==u&&u.y?0===r[i]&&u.insertBefore(s,l):(s.insertBefore(st(e,this.F,n,this),l),u=lt()),o[a+i]=u,l=u.Ye()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(st(e,this.F,t[r],this)),o[r]=lt();s.insertBefore(n,h)}}this.Te=o,Qe(s)}Re(){this.y=!1;let e=this.l;if(e.$===this)e.$=null;else if(null!==e.L){let t=e.L.indexOf(this);t>=0&&e.L.splice(t,1),0===e.L.length&&(e.L=null)}for(let e of this.Te)e.Re(this.engine);this.map?.clear()}};function ft(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function ht(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var dt=()=>le.bindAttributeName;function pt(){return{a:0,i:1,name:"",o:null,x:null,U:c,Pn:null,F:null,G:null,j:null,Pt:null,Ne:!1,K:null,X:null,ro:!1,Tt:!1,At:!1,Rt:null,go:null,P:-1,tt:!1,yo:!1}}var mt=["state","element","auto","none"],gt=["call","connect"],yt="$command.";function bt(t,n,r){E.test(n)&&(null===r&&w(1401,[n,Number(n.slice(1))]),n=`${r.t}.*.${n}`);let l=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&w(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,r)),i=null===r?0:r.n+1;l.n>i&&w(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?r:r.h[e];l.h[e]!==t&&w(1403,[l.t,l.h[e].t,t.t])}return e.ko?.(t,l),l}var vt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),$t=e=>8===e.i||vt(e)||1===e.i&&Ye(e.name);function wt(e){w(202,[e])}function At(e,t,n,r,l){let i=ce(t).map(t=>function(e,t,n,r,l){let i=function(e,t){let n=t.find(e=>e.startsWith("on")),r=null,l=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||w(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&w(33,[i,n]),null!==(o?r:l)&&w(34,[i]),(o?mt:gt).includes(s)||w(35,[i,s]),o?r=s:l=s}return{ro:t.includes("ro"),Tt:t.includes("prevent"),At:t.includes("stop"),event:n?n.slice(2):null,K:r,X:l}}(e,t.rn),s=r.localName.includes("-"),o=t.xe,a=t.Ze;if("event"===t.b){if(null!==i.K&&"none"!==i.K&&w(36),"eventToken"===o[0])return{...pt(),a:l,i:13,name:o.slice(1).join("."),Rt:a,Ne:s,Tt:i.Tt,At:i.At};let n=a.startsWith(yt)?a.slice(9):null,{Tt:r,At:u}=i,c=t.$e.slice(2),f=t.rn.includes("direct"),h=!f&&Fe.has(c);return h&&e.ao(c),{...pt(),a:l,i:5,name:c,tt:h,Ne:s,yo:f,Pn(t,l){r&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.er(n,t,l);else{let n=e.tr(a,t,l);X(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.b)return{...pt(),a:l,i:14,o:bt(e,a,n),Ne:s};if("command"===o[0]&&o.length>1)return a.startsWith(yt)||w(1201,[t.$e,a]),{...pt(),a:l,i:12,name:o.slice(1).join("."),Rt:a,Ne:s};let u=bt(e,a,n),c={...pt(),a:l,i:1,name:t.$e,o:u,x:Oe(t.et),j:Oe(t.j),ro:i.ro,K:i.K,X:i.X};if("radio"===t.b||"checkbox"===t.b)return("element"===i.K||"auto"===i.K)&&w(37,[t.b,i.K]),c.i="radio"===t.b?9:10,i.ro||(c.Pt=i.event??"input"),c;if(o.length>1){let e=o.slice(1).join("."),t=o[0];if("class"===t||"attr"===t||"style"===t)return c.K=null,c.name=e,"class"===t?(c.i=2,c.U=r.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===r.localName?1:3:4,c}return"html"===t.$e?(c.i=8,c):(c.name="text"===t.$e?"textContent":t.$e,c.Ne=s&&!Pe(c.name),!s&&!i.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(r,c.name)&&(c.Pt=i.event??("select"===r.localName?"change":"input")),c)}(e,t,n,r,l));for(let e=0;e<i.length;e++)14===i[e].i&&(i[e].go=i.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return i}var kt=/\{\{([\s\S]+?)\}\}/g;function xt(e){let t=e.data,n=[],r=0;kt.lastIndex=0;for(let l=kt.exec(t);null!==l;l=kt.exec(t)){let i=kt.lastIndex-l[0].length;i>r&&e.before(t.slice(r,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({a:s,cr:l[1].trim()}),r=kt.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function St(e,t,n,r){let l=function(e){return{$e:"textContent",xe:["textContent"],rn:[],j:[],..._(e),b:"text"}}(t);return{...pt(),a:r,i:0,o:bt(e,l.Ze,n),x:Oe(l.et),U:""}}function Tt(e){let t=e.getAttribute(dt());if(null===t)return null;let n=ce(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var Nt=(e,t)=>0===e?le.commentIfPrefix:null===t.o?le.commentElsePrefix:le.commentElseIfPrefix;function Ot(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:bt(e,r.Ze,n),x:"else"===r.b?null:Oe(r.et)}),l=[r(t,Tt(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=Tt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(l.push(r(e,t)),"else"===t.b))break}return l}var jt=new WeakSet;function Ct(t,n,r,l,i,s,o,a){let u=(n,r)=>{let i=document.createComment(r);return n.replaceWith(i),l&&e.Dn?.(t,i,n),i},c=n=>{for(let f=0;f<n.length;f++){let h=n[f];if(null!==h.parentNode)if(1===h.nodeType){let n=h,a=n.localName;if(l){if("script"===a||"style"===a||jt.has(n))continue;if(jt.add(n),a===le.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?Tt(n):null;if(null!==f){if("for"===f.b){let e=bt(t,f.Ze,r),l=Et(t,n,e,!0);i(u(n,le.commentForPrefix),e,l)}else"if"===f.b?s(Ot(t,n,r).map((e,n)=>({F:Et(t,e.el,r,!1),o:e.o,x:e.x,S:u(e.el,Nt(n,e))}))):wt(f.b);continue}let d=n.getAttribute(dt()),p=null===d?null:At(t,d,r,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some($t)&&!e.Eo?.(n);try{l&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!l&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t._t&&h.data.includes("{{")&&!jt.has(h))for(let{a:e,cr:t}of xt(h))a(e,t);else if(8===h.nodeType){let e=Mt.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),a(t,e[1])}}}};c(n)}var Mt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Pt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Et(e,t,n,r){let l=document.importNode(Pt(t),!0),i=[],s=[],o=e=>i.push(e)-1;Ct(e,[...l.childNodes],n,!1,(e,t,n)=>{s.push({...pt(),a:o(e),i:6,o:t,F:n})},e=>{let t=e.map(e=>({a:o(e.S),F:e.F,o:e.o,x:e.x}));s.push({...pt(),a:t[0].a,i:7,G:t})},(e,t)=>{let n=o(e);for(let e of t)vt(e)&&w(203,[e.name]),e.a=n;s.push(...t),e.removeAttribute(dt())},(t,r)=>{s.push(St(e,r,n,o(t)))}),Dt(l,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let r=t;r!==e;r=r.parentNode){let e=0;for(let t=r.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(l,e)),u=1===l.childNodes.length&&8!==l.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=r?n.n+1:-1;for(let e of s){if(5===e.i&&e.tt&&!e.Ne&&!Wt(i[e.a],l)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&It(e)&&(e.P=f.push(e)-1),7===e.i)for(let t of e.G)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:l,root:u?l.firstChild:null,On:a,build:g,ce:d,sr:p,In:u,lr:c,So:[],Xe:f}}function Wt(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function It(e){if(null!==e.K)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.Ne&&null===e.Pt;default:return!1}}var Rt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Dt(e,t,n){for(let r=e.firstChild;null!==r;){let e=r.nextSibling;3===r.nodeType?n&&!t.has(r)&&""===r.data.trim()&&r.remove():1===r.nodeType&&Dt(r,t,Rt.has(r.localName)),r=e}}var Lt=new WeakMap;function qt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Lt.set(t,e),Ut(e,[...n.childNodes]),e.Ue()}function zt(e,t,n){try{let r="template"===t.localName?Tt(t):null;null!==r&&!n&&w(204,[r.b]),Ut(e,[t])}catch(e){console.error(e)}e.Ue()}function Ut(t,n){Ct(t,n,null,!0,(e,n,r)=>{new ct(t,r,tt(t,n,null,e),e).$t()},e=>{at(t,e,null,null)},(n,r)=>{e.Dn?.(t,n,r);for(let e of r)ot(t,e,n,null,null)},(n,r)=>{e.Dn?.(t,n,r),ot(t,St(t,r,null,0),n,null,null)})}var Ft=Symbol.for("wcstack.binder"),_t=Symbol.for("wcstack.binder.pending"),Vt=Symbol.for("wcstack.binder.taken");var Bt=new Map;function Ht(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Lt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Bt.set(e,t):zt(n,e,t?.range)}function Kt(){let e=[...Bt];Bt.clear();for(let[t,n]of e)Ht(t,n);!function(){let e=function(){let e=globalThis[Ft];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;let t=function(){let e=globalThis,t=e[_t];return void 0===t&&(t=[],e[_t]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),r=function(){let e=globalThis,t=e[Vt];return void 0===t&&(t=new WeakSet,e[Vt]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Jt=class{constructor(){this.name="dirty",this.Z=(e,t)=>{if(0===e.n){let t=e.z;return t!==c&&t!==f&&(e.z=f,!0)}let n=null===t?null:t.yt;if(null===n)return!1;let r=n[e.P];return r!==c&&r!==f&&(n[e.P]=f,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.Et(t,n),e.xn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Dt;if(null!==n)for(let r of n)r.n===t.l.n?e.st(r,t,this.Z):e.en(t,r,t=>e.st(r,t,this.Z))}ve(t,n,r){this.Z(n,r),e.ke?.(t,n,r),t.Et(n,r),t.xn(n,r,this.Z)}Ko(e,t,n){let r=0===t.n;if(!r&&null===n)return;let l=r?null:n.yt??=new Array(e.je).fill(c),i=null===l?t.z:l[t.P];if(i!==c&&i!==f&&i!==h&&(null===l||t.P in l))return i;i=h;try{return i=e.Uo(t,null===l?null:n)}finally{null===l?t.z=i:l[t.P]=i}}Xt(e){e.yt=null}vt(e){for(let t of e.I.all())null!==t.getter&&(0===t.n?t.z===f&&(t.z=h):e.nn(t.h[t.n],e=>{let n=e.yt;null!==n&&n[t.P]===f&&(n[t.P]=h)}))}},Yt=0,Gt=new WeakMap;function Xt(e,t=e.getRootNode()){Gt.set(t,[...Gt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Qt(e){let t=Gt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Gt.get(e)!==t?Qt(e):Promise.reject(r.errors[0]):void 0)}var Zt=typeof HTMLElement>"u"?class{}:HTMLElement,en=class extends Zt{constructor(){super(),this.engine=null,this.jn=!1,this.qe=!1,this.U=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.$o=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Qt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.jn){if(null!==this.Ge)return void this.Ge.Je();Xt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!Lt.has(n)&&Lt.set(n,t),Kt(),e.element?.(t,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.jn=!0;let t=this.getRootNode(),n=e.ct?.(this,t);if(n)return this.Ge=n,!n.No&&this.parentNode instanceof ShadowRoot&&Xt(this),void(void 0===n.Ct?this.Ro():n.Ct()).then(e=>(this.loaded=!0,n.start(e,()=>this.To()))).then(()=>{this.an(),this.cn()},e=>this.xt(e,n.No));this.start(t),Xt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Mn();let t=this.engine;if(null===t)return;let n=t.root;Lt.get(n)===t&&Lt.delete(n),Xt(this,n),this.xo("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.qe&&w(14),this.loaded)this.Ge.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.U=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&w(15),"readonly"===e&&n.Me++;try{t(n.proxy)}finally{"readonly"===e&&n.Me--}}async createStateAsync(e,t){let n=this.engine;null===n&&w(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let r=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&w(8),r(...e)):r},set(){w(8)}}))}async Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${$(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||w(13,[e,n.status]),await n.json()}return(await(import(t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let r=this.querySelector('script[type="module"]');return null!==r?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let r="function"==typeof URL.createObjectURL,l=r?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Yt}`);try{return(await(import(l))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?$(42):$(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),r&&URL.revokeObjectURL(l)}}(r):null!==this.U?Promise.resolve(this.U):new Promise(e=>{this.un=e})}async start(t){try{let n=t.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||n?.hasAttribute("data-wc-definition"))&&a("scopes","<wcs-state>");let r=await this.Ro(),l=o(r);if(l&&await l,this.getRootNode()!==t)return this.U=r,this.jn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=Lt.get(t)?.element;i?.isConnected&&(i.V||i.Ge)&&w(47);let s=new re(r,new Jt);s.element=this,this.engine=s,e.element?.(s,"mounting"),qt(s,t),Kt(),s.$n(),this.To(),await s.Ee("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.cn()}catch(e){this.qe=!this.V,this.xt(e)}}To(){this.V=!0,this.an()}xt(e,t){this.Ue(this.V?50:49,e),this.an(),t?this.cn():this.$o(e)}Ue(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${$(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.Ue(t,e))}},tn=[];function nn(){return(tn=tn.filter(e=>e.deref())).map(e=>e.deref())}function rn(t,n){t&&function(e){let t=le,n=le.tagNames,r=Object.entries(e).filter(([,e])=>void 0!==e),l=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of r){let r=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof r||Array.isArray(n)!==Array.isArray(r))&&w(44,["bootstrapState",e])}for(let[e,t]of l)(!Object.hasOwn(n,e)||"string"!=typeof t)&&w(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of r)"tagNames"!==e&&(t[e]=n);for(let[e,t]of l)n[e]=t}(t),function(t=customElements){(function(){let e=globalThis;void 0===e[Ft]&&(e[Ft]={protocol:"wcs-binder",version:1,bind:Ht})})(),nn().includes(t)||tn.push(new WeakRef(t));let n=le.tagNames.state;void 0===t.get(n)&&t.define(n,class extends en{}),e.Ao?.(t)}(n)}var ln,sn=e=>Qt(e),on=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},an="en";function un(){if(le.locale!==ln){ln=le.locale;try{an=Intl.getCanonicalLocales(ln)[0]}catch{console.warn(`[@wcstack/state] ${$(48,[ln])}`),an="en"}}return an}var cn=["full","long","medium","short"];function fn(e,t){let[n,r]=e??[];return void 0===r&&void 0!==n&&cn.includes(n)&&([n,r]=[void 0,n]),void 0!==r&&!cn.includes(r)&&function(e,t){w(52,[e,t])}(t,r),[n,r]}var{eq:hn,ne:dn,not:pn,lt:mn,le:gn,gt:yn,ge:bn,falsy:vn,truthy:$n,boolean:wn}=Se,An={toFixed:{factory:e=>{let t=we(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&be("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&be("locale",e),e.toLocaleString(t??un()))},arity:[0,1]},upper:{factory:on(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:on(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:on(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:on(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:on(e=>{let t=[Ae(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(we(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:on(e=>{let t=Ae(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:on(e=>{let t=Ae(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:on(e=>{let t=Ae(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:on(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:on(e=>{let t=Ae(e,0,"truncate"),n=e?.[1]??"…";return e=>{let r=String(e);return r.length<=t?r:r.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||w(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","round"));return e=>("number"!=typeof e&&be("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&be("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&be("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=we(e?.[0]??"0","percent");return e=>("number"!=typeof e&&be("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:on(e=>{let t=e?.[0]??ge("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=fn(e,"date"),r=n&&{dateStyle:n};return e=>(e instanceof Date||ve("date",e),e.toLocaleDateString(t??un(),r))},arity:[0,2]},time:{factory:e=>{let[t,n]=fn(e,"time"),r=n&&{timeStyle:n};return e=>(e instanceof Date||ve("time",e),e.toLocaleTimeString(t??un(),r))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=fn(e,"datetime"),r=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||ve("datetime",e),e.toLocaleString(t??un(),r))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ve("ymd",e);let n=e.getFullYear().toString(),r=(e.getMonth()+1).toString().padStart(2,"0"),l=e.getDate().toString().padStart(2,"0");return`${n}${t}${r}${t}${l}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ve("hms",e);let n=e.getHours().toString().padStart(2,"0"),r=e.getMinutes().toString().padStart(2,"0"),l=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${r}${t}${l}`}},arity:[0,1]},eq:hn,ne:dn,not:pn,lt:mn,le:gn,gt:yn,ge:bn,add:xe("add",(e,t)=>e+t),sub:xe("sub",(e,t)=>e-t),mul:xe("mul",(e,t)=>e*t),div:xe("div",(e,t)=>e/t),mod:xe("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&be("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=Ae(e,0,"clamp"),n=Ae(e,1,"clamp");return e=>("number"!=typeof e&&be("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:vn,truthy:$n,defaults:{factory:(e,t)=>{let n=ke(e?.[0]??ge("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=ke(e?.[0]??ge("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:wn,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??ge("currency"),n=e?.[1],r={style:"currency",currency:t};try{new Intl.NumberFormat("en",r);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){w(53,[e])}(t)}return e=>("number"!=typeof e&&be("currency",e),e.toLocaleString(n??un(),r))},arity:[1,2]}},kn=Object.fromEntries(Object.entries(An).filter(([e])=>!(e in Se))),xn=!1,Sn={name:"formats",install:function(){xn||(xn=!0,pe(An))}};function Tn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let r=new Array(t.length+1),l=new Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let n=1;n<=e.length;n++){l[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;l[i]=Math.min(r[i]+1,l[i-1]+1,r[i-1]+s)}for(let e=0;e<=t.length;e++)r[e]=l[e]}return r[t.length]}function Nn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),r=null,l=3;for(let e of t){let t=Tn(n,e.toLowerCase(),2);t<l&&(r=e,l=t)}return null!==r?` Did you mean "${r}"?`:""}var On=" Validate statically: npx @wcstack/lint <file>.",jn=["","binding-syntax","template-syntax","binding-path-missing","binding-type-expectation","filter-unknown","filter-arity","getter-cycle","getter-depth-exceeded","index-arity","index-param-range","recursion-unsupported","token-misconfigured","token-undeclared","wildcard-rank","spread-no-bindable","declaration-alias","name-alias"],Cn=e=>{let t=jn[e/100|0];return t?`[wcs/${t}] `:""},Mn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Pn=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,En=["","","class.","attr.","style."],Wn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,In="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Rn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,r)=>`binding "${n?(En[r]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${In}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${In}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${Pn(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${Pn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&Mn.includes(t)?" 4.0 moved it to the state's $behavior.":""}`,45:()=>"a re-set state may not change $behavior: create the element again.",47:()=>'a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount="path"> (v1\'s name="…" is gone: read the mounted state by its path).',48:e=>`the locale "${e}" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use "en".`,46:()=>'$features must be an array of add-on names (["temporal", "formats"]).',49:(e,...t)=>`${Wn(e,t)} failed to initialize.`,50:(e,...t)=>`${Wn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Wn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,r)=>`${e}("${t}") takes ${n} index(es), got ${r}.`,902:(e,t,n,r)=>`${e}("${t}") takes at most ${n} index(es), got ${r}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function Dn(e,t){let n=Rn[e];return void 0===n?`${Cn(e)}#${e} ${t.join(" ")}`:Cn(e)+n(...t)}var Ln=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),qn=[[/no loop level in common with the context/,"; pass indexes ([] for all)."],[/"([^"#]+)#([^"]*)" is not a filter name: a modifier list .* comes before the input filters/,' — write "<property>#$2|$1".'],[/\[wcs\/recursion-unsupported\]/," It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll — and only when the state declares a $recursion anchor."],[/must be single binding/,' Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).'],[/\[wcs\/wildcard-rank\] .* needs \d+ enclosing/,' Wrap it in that many "for" templates, or use $resolve(path, indexes) to name the row explicitly.'],[/\[wcs\/wildcard-rank\] .* ranges over the rows of/,' A "*" in a binding is the row of the loop around it: read a row of another list in a getter, with $resolve(path, indexes).'],[/\[wcs\/binding-type-expectation\] class\.([^ ]+)/,' Write "class.$1: path|truthy" to toggle on truthiness.'],[/path segments — the limit/," Every prefix of a path is interned, so the cost grows with the square of the depth."],[/\[wcs\/index-arity\] \$resolve/,' $resolve takes one index per "*"; $getAll / $setAll take at most that many (fewer expands the rest).'],[/"([^"#]+)#[^"]*" is not a filter name: "#" cannot appear in one/,' Modifiers belong on the left side of the binding, before the ":" — write "$1" here.']],zn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Un(e,t,n){let r=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(zn,e)?zn[e]:null;return null===t?null:` "${e}" was renamed "${t}" in 3.2 and removed in 4.0 — write "${t}".`}(t):null)??(void 0!==t&&void 0!==n?Nn(t,n):"");for(let[t,n]of qn){let l=t.exec(e);null!==l&&(r+=n.replace(/\$(\d)/g,(e,t)=>l[Number(t)]))}let l=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==l&&(r+=` — write "${l[1]}#${l[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?r+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':fe.some(me)||(r+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&Ln.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=On),r}var Fn=new WeakMap,_n=new WeakMap,Vn=new WeakSet,Bn=new WeakSet;function Hn(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 Kn(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"$"!==e[0]&&"constructor"!==e&&t.add(e);return[...t]}function Jn(e,t){let n=[];for(let e=t;null!==e;e=e.d)n.unshift(e);let r=e.target,l=t=>null===t?null:function(e,t){let n=t.t.split("."),r=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return r<0||n.indexOf("*",r)>=0||void 0!==Hn(e.target,t.t)?.get?t:e.I.jt(m(t.t).o)}(e,t);if(n.some(e=>null!=l(e)?.getter))return null;for(let t of n){if(null===r||"object"!=typeof r)return null;if("*"===t.s){if(!Array.isArray(r)||0===r.length)return null;r=r[0];continue}if(Array.isArray(r)&&/^\d+$/.test(t.s)){if(Number(t.s)>=r.length)return null;r=r[Number(t.s)];continue}let n=Hn(r,t.s);if(void 0===n&&null===t.d&&e.vt.has(t.s))return null;if(void 0===n){let n=Kn(r),i=l(t.d);for(let t of e.I.all())t.d===i&&null!==t.getter&&n.push(t.s);return{seg:t.s,names:n}}if(void 0!==n.get||void 0!==n.set)return null;r=n.value}return null}function Yn(t){Vn.has(t)||(Vn.add(t),setTimeout(()=>function(t){Vn.delete(t);let n=Fn.get(t);if(void 0===n)return;let r=_n.get(t);void 0===r&&_n.set(t,r=new Set);for(let[l,i]of n){if(r.has(l))continue;r.add(l);let n=Jn(t,l);if(null===n)continue;let s=[...t.root?.querySelectorAll(`${le.tagNames.state}[mount]`)??[]].find(e=>!Bn.has(e)&&(l.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==s){r.delete(l),s.initializePromise.then(()=>{Bn.add(s),Yn(t)});continue}let[o,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];e.at?.(t,{type:"state:path-unresolved",source:i?"watch":"binding",path:l.t,missingSegment:n.seg});let u=t.I.jt(m(l.t).o),c="";if(void 0!==u&&u!==l&&null!==u.getter){let e=u.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.h[t].t.length+2)}`);c=` The getter "${u.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}console.warn(`[@wcstack/state] [wcs/${o}] ${a} "${l.t}" does not resolve on the state tree: "${n.seg}" is not declared.${Nn(n.seg,n.names)}${c} Updates to this path will be silently dropped.${On}`)}}(t),0))}function Gn(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.d)return;let r=Fn.get(e);void 0===r&&Fn.set(e,r=new Map),r.has(t)||r.set(t,n),Yn(e)}var Xn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Qn=!1;function Zn(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(Qn||!(t instanceof TypeError)||!Pe(r)||!("trustedTypes"in globalThis))return;Qn=!0;let l="function"==typeof Ce()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${r}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${l}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:r})}var er=new WeakMap;function tr(e,t,n){let r=e[t],l=void 0===n?void 0===r?null:`the event carried no detail (undefined) while element.${t} is ${typeof r}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==r&&"object"==typeof r?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof r}`;if(null===l)return;let i=er.get(e);void 0===i&&er.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${l}. With no getter, state receives e.detail as-is. Dispatch the value itself as detail, or declare getter (e.g. (e) => e.detail.${t}, or (e) => e.target.${t}) on that wcBindable property.`))}var nr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],rr={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},lr={name:"diagnostics",install(){e.Mo=Un,e.Lo=Dn,e.ko=Gn,e.detail=tr,e.qe=t(e.qe,Zn);let r=e.fe;e.fe=(e,t)=>{(function(e){void 0!==e.$scan&&w(1);for(let[t,n]of nr)void 0!==e[t]&&w(1601,[t,n])})(t),r?.(e,t),function(e){let t=e.$recursion;if(null===t||"object"!=typeof t)return;let n=Object.entries(t);if(1!==n.length||"string"!=typeof n[0][1])return;let[r,l]=n[0];if(!r.endsWith(".*")||!l.endsWith(".*"))return;let i=r.slice(0,-2),s=l.slice(0,-2),o=`.${l}`,a=`${i}.**`,u=Kn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>v(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${s}`||e.startsWith(`.${s}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${s}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${Xn(o)})+$`).test(t.slice(0,t.length-e.length))&&f(`"${a}${e}" and "${a}${t}" expand to the same concrete path at different depths (they differ by whole repetitions of "${l}"). Rename one of them.`);let t=new RegExp(`^${Xn(r)}(?:${Xn(o)})*${Xn(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&f(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(t),function(e){_n.delete(e),Fn.has(e)&&Yn(e)}(e)},e.rt=n(l,e.rt,(e,t)=>Object.hasOwn(rr,t)?w(1701,[t,rr[t]]):void 0)}},ir={},sr=/\.\d/,or=new Set(Object.getOwnPropertyNames(Object.prototype)),ar=0,ur=!1,cr=null,fr=()=>{ur=!1,ar++};function hr(){if(null===cr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=fr,e.port1.unref?.(),cr=()=>e.port2.postMessage(0)}else cr=()=>setTimeout(fr,0);return ur||(ur=!0,cr()),ar}function dr(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let r of t)if(n.ee(r)&&(n.n===r.n||!(r.n<e.n&&e.h[r.n+1].ee(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var pr=class{constructor(e,t){this.active=!1,this.Ae=new Map,this.early=[],this.n=0,this.Po=-1,this.Ln=new Set,this.He=null,this.engine=e,this.Ie=t}ur(){let e=this.engine;this.Ae.clear();let t=this.early;this.early=[];for(let t of this.Ie)t.getter=null!==t.p.getter||t.p.se,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(ir,e.v(t.p,null)):this.Bn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[r,l,i,s]of t)if((null===l||l.y)&&Object.is(e.v(r,l),s)){n.add(r);for(let e of this.Ie)e.p===r&&this.ut(e,l,i,!0)}for(let e of this.Ie)e.getter&&0===e.p.n&&!this.Ae.has(e)&&dr(mr(e.p),n)&&this.ut(e,null,void 0,!0);this.Ae.size>0&&e.we()}prime(t,n){try{n()}catch(n){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,n),e.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}Fo(){this.active=!1,this.Ae.clear(),this.early=[]}Bn(e,t,n,r){let l=this.engine.Ve(n,e.h[t]);for(let n of l.f)t===e.n?r(n):this.Bn(e,t+1,n,r)}ut(e,t,n,r){let l=this.Ae.get(e);void 0===l&&this.Ae.set(e,l=new Map);let i=l.get(t);void 0===i?l.set(t,[n,this.n,r]):(i[1]<this.n&&(i[1]=this.n),i[2]||=r)}Se(e,t,n,r,l,i){if(this.active){(this.He??=new Set).add(e);for(let i of this.Ie){let s=i.p;s.n!==e.n||!s.ee(e)||this.ut(i,t,i.getter?i.s.get(t??ir):s===e&&l&&this.engine.Wt&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else i&&this.early.push([e,t,n,r])}ke(e,t){if(this.active)for(let n of this.Ie)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===e.n&&n.p.ee(e)&&this.ut(n,t,n.s.get(t??ir),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let r of this.Ie){let l=r.p;if(!(l.n<e.n||l.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(l.n===e.n?this.ut(r,t,void 0,!0):this.Bn(l,e.n+1,t,e=>this.ut(r,e,void 0,!0)))}}}Oe(){let t=this.He;if(this.He=null,!this.active||0===this.Ae.size)return;let n=this.Ae;this.Ae=new Map;let r=this.engine,l=[];for(let i of this.Ie){let s=n.get(i);if(void 0===s)continue;let o,a=[...s].filter(([e])=>null===e||e.y);a.length>1&&a.sort((e,t)=>gr(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=r.u;this.n=u+1,r.Pe++;try{if(a=r.v(i.p,n),i.getter&&(i.s.set(n??ir,a),Object.is(a,s)&&(sr.test(i.t)||null!==n&&!c&&!(o??=null!==t&&dr(mr(i.p),t)))))continue;if(u>32){l.includes(i.t)||l.push(i.t);continue}r.u=n,e.at?.(r,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(r.proxy,a,s,...r.H(n))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),e.at?.(r,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{r.u=h,this.n=0,r.Pe--}}}l.length>0&&this.Oo(l)}Oo(t){let n=hr();n!==this.Po&&(this.Po=n,this.Ln.clear());let r=t.filter(e=>!this.Ln.has(e));if(0!==r.length){for(let e of r)this.Ln.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:r})}}};function mr(e){for(;null===e.getter&&null!==e.d;)e=e.d;return e}function gr(e,t){let n=[],r=[];for(let t=e;null!==t;t=t.l.ae)n.unshift(t.w);for(let e=t;null!==e;e=e.l.ae)r.unshift(e.w);for(let e=0;e<n.length&&e<r.length;e++)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}var yr="$streamStatus",br="$streamError",vr=new Set(Object.getOwnPropertyNames(Object.prototype)),$r=!1;function wr(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 void 0!==e.get||void 0!==e.set||"function"==typeof e.value}return!1}var Ar=class{constructor(e,t,n){this.engine=e,this.entries=t,this.B=n}set(e,t,n){$r=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{$r=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.dt=!1,e.J?.abort(),e.J=null}pr(){for(let e of this.entries)e.dt=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(yr,e.name,"idle")}ke(e){let t=this.B.n;for(let n of this.entries)n.g===e&&(n.n=n.dt?Math.max(n.n,t):t,n.dt=!0)}Oe(){let e=this.engine,t=this.B,n=[];for(let r of this.entries){if(!r.dt)continue;let l=r.n;if(r.dt=!1,l>32)n.push(r.name),r.g.z=h;else{t.n=l+1,e.Pe++;try{this.start(r,!1)}finally{e.Pe--,t.n=0}}}n.length>0&&t.Oo(n)}start(e,t){let n,r=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let l=e.g;l.getter=e.args;let i=l.Q.slice();kr(l);try{n=r.read(l,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&v(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${yr}.${e}`||n.t===`${br}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,l,n)}catch(n){kr(l);for(let e of i)e.Wn(l);if(l.z=h,t)throw n;return this.set(br,e.name,n),void this.set(yr,e.name,"error")}}let l=new AbortController;e.J=l,r.A(r.o(e.name),null,e.U),this.set(br,e.name,null),this.set(yr,e.name,"active"),this.mr(e,l,n)}async mr(e,t,n){let r=this.engine,l=t.signal,i=()=>!l.aborted&&e.J===t,s=r.o(e.name),o=this.B.n,a=hr(),u=e=>{hr()===a&&(this.B.n=o);try{e()}finally{this.B.n=0}},c=e.U;try{let t=await e.source(n,l);if(!i())return;let o=t=>{c=void 0!==e.Co?e.Co(c,t):t,u(()=>r.A(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(l.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!i())return;if(t.done)break;o(t.value)}}else{if(null===t||"function"!=typeof t?.[Symbol.asyncIterator])throw new TypeError(`$stream "${e.name}": source must return an async iterable or a ReadableStream`);{let e=t[Symbol.asyncIterator]();for(l.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.J=null,u(()=>this.set(yr,e.name,"done"))}catch(n){if(!i())return;e.J=null,t.abort(),u(()=>{this.set(br,e.name,n),this.set(yr,e.name,"error")})}}};function kr(e){for(let t of e.Q){let n=t._.indexOf(e);n>=0&&t._.splice(n,1),t.mt.delete(e)}e.Q.length=0,e.z=c}var xr=new WeakMap;function Sr(e){let t=xr.get(e);return t?.target===e.target?t:void 0}function Tr(t,n){let r=new pr(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$watch must be an object mapping paths to handler functions.");let r=[];for(let l of Object.keys(n)){let i=n[l];(""===l||"$"===l[0]||l.includes("@")||or.has(l))&&v(`$watch path "${l}" is not a path of the state tree.`),"function"!=typeof i&&v(`$watch entry "${l}" must be a function.`);let s=t.o(l);e.ko?.(t,s,!0),r.push({t:l,p:s,handler:i,getter:!1,s:new WeakMap})}return r}(t,n.$watch)),l=new Ar(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$stream must be an object mapping stream names to definitions.");let r=[],l={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||vr.has(s))&&v(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&v(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&v(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&v(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${s}": args must be a function.`),wr(t,s)&&v(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),l[s]="idle",i[s]=null,r.push({name:s,source:a,Co:u,U:f,J:null,dt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[yr]=l,t[br]=i,r}(t,n),r),i=xr.get(t);void 0!==i&&(i.B.Fo(),i.Ot.fr()),xr.set(t,{B:r,Ot:l,Je:i?.Je??!1,target:n})}function Nr(e,t){let n=xr.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Je="connected"===t),n.target===e.target)){if("disconnected"===t)return n.B.Fo(),void n.Ot.pr();n.Je&&(n.B.ur(),n.Ot.dr())}}var Or=["$streamStatus","$streamError"],jr={name:"temporal",install(){e.fe=t(e.fe,Tr),e.element=t(e.element,Nr),e.Se=t(e.Se,(e,t,n,r,l,i,s)=>Sr(e)?.B.Se(t,n,r,l,i,s)),e.ke=t(e.ke,(e,t,n)=>{let r=Sr(e);void 0!==r&&(r.B.ke(t,n),r.Ot.ke(t))}),e.Qt=t(e.Qt,(e,t,n)=>Sr(e)?.B.Qt(t,n)),e.Oe=t(e.Oe,e=>{let t=Sr(e);void 0!==t&&(t.B.Oe(),t.Ot.Oe())}),e.rt=n(l,e.rt,(e,t)=>{let n=t.split(".",1)[0];if(Or.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Fe=n(r,e.Fe,(e,t)=>(!$r&&36===t.t.charCodeAt(0)&&Or.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Cr=new WeakMap,Mr=!1,Pr=/^(?!prototype$)[^\d.*$][^.*]*$/;function Er(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let l=n[t];"string"==typeof l?r.set(e.o(t),e=>e[l]):"function"==typeof l?r.set(e.o(t),l):v(`$listKeys "${t}" must be a field name or a function.`)}}Cr.set(t,r)}function Wr(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Ir(e,t,n){let r=new Map;for(let l of t){Wr(l)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(l);null==t&&v(`$listKeys "${e}": a row has no key.`),r.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,l)}return r}function Rr(e,t,n,r){if(Mr||!Array.isArray(r))return!1;let l=Cr.get(e.target)?.get(t);if(void 0===l)return!1;let i=e.it(t,n);if(!Array.isArray(i)||i===r)return!1;let s=Ir(t.t,i,l);Ir(t.t,r,l);let o=[],a=[],u=i.length===r.length;for(let e=0;e<r.length;e++){let t=r[e],n=s.get(l(t));o.push(n??t),void 0!==n&&a.push([e,n,t]),o[e]!==i[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let r of Object.keys(n))Object.is(t[r],n[r])||c.push([e,r,n[r]]);for(let r of Object.keys(t))!(r in n)&&null!==t[r]&&c.push([e,r,null])}if(u&&0===c.length)return!0;if(!u){Mr=!0;try{e.A(t,n,o)}finally{Mr=!1}}if(c.length>0){let r=e.Ve(0===t.n?null:n,t);for(let[n,l,i]of c){if("__proto__"===l)continue;let s=r.f[n],o=Pr.test(l)?e.o(`${t.t}.*.${l}`):null;null===o?.getter?e.A(o,s,i):(s.R[l]=i,e.A(e.o(`${t.t}.*`),s,s.R,!0))}}return!0}var Dr={name:"list-keys",install(){e.fe=t(e.fe,Er),e.Fe=n(r,e.Fe,Rr)}},Lr=new WeakMap,qr=new WeakMap,zr="will not graft: the root state failed to initialize.",Ur=new WeakSet,Fr=new WeakMap,_r=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Vr=["$commandTokens","$eventTokens","$on","$errorCallback"],Br=e=>`[@wcstack/state] <${le.tagNames.state} mount="${e}">`,Hr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Kr=e=>e?.element?.isConnected?e:void 0;function Jr(e){let t=qr.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function Yr(e,t){let n=qr.get(t);if(qr.delete(t),Array.isArray(n))for(let t of n)Zr(t,e)}function Gr(e){let t=Lr.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function Xr(e,t){console.error(`${Br(e.t)} ${t}`),Gr(e),e.Qe?.(),e.Qe=null}function Qr(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 Zr(e,t){if(Ur.has(t))return Xr(e,"will not graft: its component is wired to its host.");let n=e.state,r=t.target,l=e.t.split("."),i=r;for(let e of l)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return Xr(e,`will not graft: the root state already has "${e.t}".`);let s=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,r){if("symbol"==typeof r)return;if(36!==r.charCodeAt(0))return e.proxy[n(r)];let l=e.proxy[r];return"$eqPath"===r?(e,t)=>l(n(e),n(t)):Hr.has(r)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,r,l)=>"symbol"!=typeof r&&(e.proxy[n(r)]=l,!0)})}(t,e.t);e.chroot=s;let o={},a={},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:r,set:l,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==r||void 0!==l)a[`${e.t}.${n}`]={get:r&&function(){return r.call(s)},set:l&&function(e){l.call(s,e)}};else{if("$"===n[0])continue;if("function"==typeof i){let t=i.bind(s);a[`${e.t}.${n}`]={get:()=>t}}else o[n]=i}}if(void 0===i){for(let e=1;e<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.it(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,o)}t.to(Object.defineProperties({},a));for(let e in a)t.He(t.o(e),null);e.engine=t;let c=Fr.get(t);void 0===c&&Fr.set(t,c=[]),c.push(e),e.el.isConnected&&Qr(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function el(e,t){let n=qr.get(e);if(Array.isArray(n))for(let e of n)Xr(e,zr);qr.set(e,t)}var tl=new WeakMap;function nl(e,t){let n=e.getAttribute("mount");if(null===n)return null;let r={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},l=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(le.bindAttributeName))l='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Lr.get(t);void 0===e&&Lr.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==r&&(null===i.engine?i.el.isConnected:Kr(i.engine)))l=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=qr.get(t);Array.isArray(e)&&qr.set(t,e.filter(e=>e!==i)),i.Qe?.(),i.Qe=null}e.set(n,r)}}else l='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{No:!0,start(e){if(null!==l)return Xr(r,l);if(Lr.get(t).get(n)===r){for(let t of _r)if(void 0!==e[t])return Xr(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of Vr)void 0!==e[t]&&console.warn(`${Br(n)} ${t} is not run in a volume (it belongs to the root).`);return r.state=e,new Promise(e=>{r.Qe=e;let n=Kr(Lt.get(t)),l=qr.get(t);void 0!==n?Zr(r,n):Jr(t)?Xr(r,zr):qr.set(t,[...Array.isArray(l)?l:[],r])})}},Je(){null!==r.engine&&Qr(r,"$connectedCallback")},Mn(){null!==r.engine&&Qr(r,"$disconnectedCallback")},reset(){v(`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 rl=new WeakMap,ll=new WeakMap;function il(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||v(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&v(`${t} entries must be non-empty strings.`),"$"===e[0]&&v(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&v(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function sl(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let r=document.createDocumentFragment();for(let e of[...t.childNodes])r.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&v("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||v(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&v(`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}(r),i=il(r,"$bindables"),s=il(r,"$commands");for(let e of i){let t=l.get(e);void 0===t&&v(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&v(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of s){let t=l.get(e);void 0===t&&v(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&v(`$commands entry "${e}" is not a method: list it in $bindables.`)}let o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=r=>{if(a.has(r))return a.get(r);if(r.hasAttribute("data-wc-definition"))return null;let l=r.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let s=l.querySelector(le.tagNames.state);return a.set(r,s),rl.set(r,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${le.tagNames.state}>: no change events.`),s},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,r]of t)n.proxy[e]=r});class d extends HTMLElement{static{this.wcBindable=0===i.length&&0===s.length?null:{protocol:"wc-bindable",version:1,properties:i.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:i.map(e=>({name:e})),...0===s.length?{}:{commands:s.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of l)"function"==typeof t.value?Object.defineProperty(d.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(d.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=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,r,l,t)},Je(){},Mn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var ol=new WeakMap,al=new WeakSet,ul=new WeakMap,cl=new WeakMap,fl="data-wcs-wired",hl=new WeakMap,dl=new WeakMap,pl=new WeakMap,ml=0,gl=new Set,yl={},bl=["$watch","$stream","$renderedCallback"],vl=e=>e.split(".",1)[0];function $l(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function wl(e,t){let n=e.a,r=vl(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(fl);else if(!kl(n,r)){let e=n.getAttribute(fl)?.split(" ")??[];e.includes(r)||n.setAttribute(fl,[...e,r].join(" "))}hl.get(n)?.me===r&&v(`<${n.localName}>.${r} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=ol.get(n);void 0===l&&ol.set(n,l=[]),l.push(e),t&&al.add(e);let i=ul.get(n);return void 0===i&&ul.set(n,i=new Map),i.has(r)||i.set(r,n[r]),cl.get(n)?.(),!1}function Al(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${le.tagNames.state}[bind-component]`)}function kl(e,t){let n=e.getAttribute(le.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function xl(e){let t=e.parentElement;for(;null!==t&&!Al(t);)t=t.parentElement;let n=Lt.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.V:null===t)&&(null===t?Ht(e):zt(n,e))}var Sl=new Set;function Tl(e,t){Sl.has(e)||(Sl.add(e),console.warn(`[@wcstack/state] ${t}`))}var Nl=(e,t)=>t in e.state;function Ol(e,t){let n=jl(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function jl(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 Cl(e,t,n){if(null!==n.getter)return;let r,l=e.host,i=l.engine,s=vl(n.t),o=l.entries.find(e=>e.E===n.t);if(void 0===o&&null!==n.d)return function(e,t){let n,r=t.d;for(;null!==r&&void 0===(n=e.ft.get(r));)r=r.d;if(null===r||void 0===n)return;let l=e.N,i=e.host.engine,s=i.o(n.p.t+t.t.slice(r.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=Ml(e,o.r);return 0===t.n?n:(i.resolve($l(s.t,[...i.H(n),...l.H(te(l.u,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.ie&&(t.ie=n=>{let r=a();Pl(e,o.e,()=>i.A(s,r,n)),e.dn=t}),t.n>0&&(t.P=l.je++),e.ft.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.E!==s?Nl(l,s):Ol(l,s))return;r=o.he}else{if(null===t||null!==n.d||"$"===s[0]||Nl(l,s))return;o=t,r=i.o(`${t.he.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(r,Ml(e,a)),n.ie=t=>{Pl(e,u,()=>i.A(r,a,t)),e.dn=n},e.ft.set(n,{e:o,p:r,r:a})}function Ml(e,t){return null!==t&&!t.y&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Pl(e,t,n){let r=gl.has(e.N);gl.add(e.N),e.from=t;try{n()}finally{r||gl.delete(e.N),e.from=null}}var El=(e,t)=>t||!gl.has(e.m.N)||null!==e.m.from&&e.m.from!==e.e;function Wl(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,ml+=t?1:-1;let n=e.host.engine,r=pl.get(n);void 0===r&&pl.set(n,r=new Map);for(let n of e.pe){let e=r.get(n.e.he);void 0===e&&r.set(n.e.he,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.E);if(void 0!==l){null===e.re&&function(e,t){let n=e.host,r=n.engine;e.re=new Map;let l=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(l.has(s))continue;l.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=vl(s);if(s!==a&&!Nl(n,a))continue;let u=r.o(`${t.he.t}.${s}`);if(null===u.getter)Dl(r,u,t.he);else if(!Il.has(u.getter))continue;e.re.set(u,e.N.o(s))}}(e,l);for(let r of e.re.keys())t&&null===r.getter&&Dl(n,r,l.he),n.T.ve(n,r,l.r);e.re.size>0&&n.we(),t&&function(e,t){let n=e.host.engine;for(let[r,l]of e.re){let i=n.v(r.d,t.r);if(null===i||"object"!=typeof i||!(r.s in i))continue;let s=e.host.el.localName;Tl(`${s}|${r.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.me}.${l.t} is exported at "${r.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 Il=new WeakSet;function Rl(e,t,n,r){let l=pl.get(e)?.get(t)?.get(n);if(void 0===l)return null;let i=null;for(let e of l)""!==e.e.E||!0!==e.m.re?.has(r)||e.m===i||(null!==i&&v(`[wcs/mount-export-ambiguous] "${r.t}" is exported by two mounted components on the same instance: <${i.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.`),i=e.m);return i}function Dl(e,t,n){let r=t.d,l=t.s,i=()=>{let t=e.read(r,e.u);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let r=i();if(null!==r)return r[l];let s=Rl(e,n,e.u,t);return null===s?void 0:s.N.read(s.re.get(t),null)},Il.add(t.getter),t.ie=s=>{let o=null===i()?Rl(e,n,e.u,t):null;if(null===o){let t=e.read(r,e.u);return void(null!==t&&"object"==typeof t&&(t[l]=s))}let a=o.re.get(t);void 0===jl(o.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${o.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),o.N.A(a,null,s)},t.n>0&&(t.P=e.je++)}function Ll(t,n,r,l,i,s){if(null!==n.getter)return t.T.ve(t,n,r),void t.we();if("*"===n.s){if(null===r)return;if(r.R=r.l.C[r.w],t.T.Xt(r),null!==r.c)for(let e of r.c.values())t.X(e)}else t.En(n,r);e.Se?.(t,n,r,l,i,s),t.He(n,r)}function ql(e){let t=e.m.N;for(let[n,r]of e.m.ft)r.e===e.e&&(0===n.n?t.T.ve(t,n,null):t.nn(n.h[n.n],e=>t.T.ve(t,n,e)));t.we()}function zl(e,t,n,r,l,i,s){let o=n.t.slice(t.t.length);if(""===o)return ql(e);let a,u=e.m,c=u.N;if(""===e.e.E){a=o.slice(1);let e=vl(a);if("$"===e[0]||Nl(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(te(r,e).w);c.resolve($l(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Ll(c,h,d,l,i,s)}function Ul(e,t,n,r,l,i,s){if(0===ml)return;let o=gl.has(e);gl.add(e);try{let o=dl.get(e);!s&&void 0!==o&&o.fn&&!gl.has(o.host.engine)&&function(e,t,n,r,l,i){let s,o=t;for(;null!==o&&void 0===(s=e.ft.get(o));)o=o.d;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.dn===t)return void(e.dn=null);if(null!==s.r&&!s.r.y)return;let u=[...a.H(s.r),...e.N.H(n)];a.resolve($l(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Pl(e,s.e,()=>Ll(a,c,f,r,l,i))}(o,t,n,r,l,i),s&&void 0!==o&&o.fn&&null!==o.re&&function(e,t){let n=e.host.entries.find(e=>""===e.E),r=e.host.engine;for(let[l,i]of e.re)i===t&&(r.T.ve(r,l,n.r),r.we())}(o,t);let a=pl.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.ee(e)){let a=o.get(0===e.n?null:te(n,e.n));if(void 0!==a)for(let o of[...a])El(o,s)&&zl(o,e,t,n,r,l,i)}else if(e.ee(t))for(let[e,r]of[...o])if(0===t.n||te(e,t.n)===n)for(let e of[...r])El(e,s)&&ql(e)}finally{o||gl.delete(e)}}async function Fl(t,n,r,l,i){if(l===yl)return;let s=o(l);s&&await s;let a=hl.get(n);a.engine&&l.$recursion&&v(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.O;if(null!==u&&u.el!==t&&u.el.isConnected&&v(`<${n.localName}> already has a connected <${le.tagNames.state} bind-component="${a.me}">.`),null!==u&&Wl(u,!1),null!==u&&function(e,t,n){let r=e.N,l=`[${le.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),s=new Set,o=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&s.add(e)},a=(e,t)=>{for(let n=e.Cn(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of r.ue.values())for(let t of e)if(null===t.D)o(t.a);else for(let e of t.D.G)a(t.D,e.S);for(let e of r.oe.values())for(let t of[e.$,...e.L??[]])null!==t&&a(t,t.S);for(let t of e.M)t.parentNode===n&&i(t)&&s.add(t);if(0===s.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!s.has(n)&&!e.M.includes(n)&&(i(n)||r._t&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(u,t,r))return async function(e,t,n,r){e.el.engine=null,e.el=t,e.N.element=t,t.engine=e.N,e.M=e.M.filter(e=>e.parentNode===n),t.isConnected?await _l(e,r):r()}(u,t,r,i);let c=new re(l,new Jt);c.element=t,t.engine=c,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 r=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof r&&"constructor"!==t&&n.set(r,null)}let r=(t,n,r)=>Reflect.apply(t,e.proxy,r);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:r})),t}}(c,l);let f={el:t,M:[],N:c,host:a,pe:[],ft:new Map,fn:!1,dn:null,from:null,re:null};for(let e of a.entries)f.pe.push({m:f,e});a.O=f,dl.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.N,n=e.host,r=n.engine,l=n.el.localName,i=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=vl(e.E);Nl(n,t)&&(e.E!==t||Ol(n,t))&&Tl(`${l}.${e.E}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.me}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=r.v(i.he,i.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.E===t)&&Tl(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${i.he.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=bl.filter(e=>void 0!==n.state[e]);s.length>0&&Tl(`${l}.${n.me}$`,`[wcs/mount-dollar-declaration] <${l}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.ot;t.ot=n=>{Cl(e,i,n),o.call(t,n)};let a=[...t.I.all()];for(let t of a)Cl(e,i,t);for(let e of a)o.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=dl.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}(f),Wl(f,!0),Ur.add(c),Yr(c,r));let d=e.hr?.(r);qt(c,r),d?.(),f.M=[...r.childNodes],Kt(),h&&c.$n(),Object.defineProperty(n,a.me,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.me);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),t.isConnected?(await c.Ee("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):Wl(f,!1)}async function _l(t,n){Wl(t,!0);for(let e of t.pe)ql(e);n?.(),!t.broken&&(await t.N.Ee("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.N,"connected"))}function Vl(t,n){let r=t.getAttribute("bind-component");if(null===r)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Lt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){el(t,e);for(let e of tl.get(t)??[])e()}}),null}(t,n);let l=t.parentNode,i=l instanceof ShadowRoot,s=i?l.host:l instanceof Element?l:null,o=()=>{let e=null===s?void 0:hl.get(s)?.O;return e?.el===t?e:null},a=e=>{throw i&&el(l,t),e},u=!1;return{Ct:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,r){let l=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&v(`<${le.tagNames.state} bind-component> takes its state from <${l}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Le(n).whenDefined(l);let i=hl.get(n);if(void 0!==i)return i.me!==t&&v(`<${l}> already has a <${le.tagNames.state} bind-component="${i.me}">.`),i.state;let s=()=>(ol.get(n)??[]).filter(e=>vl(e.name)===t),o=kl(n,t);if(o&&0===s().length&&xl(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(fl)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,i)=>{cl.set(n,r),e=function(e,t){Jr(e)&&t();let n=tl.get(e)??new Set;return tl.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${l}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}cl.delete(n);let a=s(),u=ul.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${l}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&r){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${l}>, or mount it from the host (${le.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),yl}let f=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===r)&&v(`<${l}> maps "${e.name}" twice.`);let i=r.split(".").indexOf("*");if(i>=0){let n=r.split(".").slice(0,i).join(".");v(`<${l}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}f.push({E:r,he:e.o,r:e.r,ro:al.has(e)}),e.engine.Nn(e),""!==r&&delete n[e.name]}let h=0===a.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}(c):c;return hl.set(n,i={el:n,me:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,O:null}),h}(t,r,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${le.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await Fl(t,s,i?l:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Je(){let e=o();null!==e?_l(e).catch(e=>console.error(e)):u?Promise.resolve().then(()=>{if(t.parentNode===l)return Fl(t,s,i?l:s,hl.get(s).state,()=>{})}).catch(e=>console.error(e)):cl.has(s)&&xl(s)},Mn(){let t=o();null!==t&&(Wl(t,!1),!t.broken&&(t.N.Ee("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.N,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${s?.localName}>.${r} instead.`)}}}var Bl={name:"scopes",install(){e.ct=n(i,e.ct,nl),e.ct=n(i,e.ct,sl),e.ct=n(i,e.ct,Vl),e.ar=wl,e.Eo=Al,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Fr.get(e)??[];if("disconnected"===t)for(let e of n)Gr(e);else if("reset"!==t&&Kr(Lt.get(e.root))===e){Yr(e,e.root);for(let e of n)Lr.get(e.root).has(e.t)||Lr.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();Yr(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:rl.get(n);void 0!==r&&ll.set(e,{host:n,def:r})}(e,n)}),e.Se=t(e.Se,(e,t,n,r,l,i)=>{(function(e,t,n,r){let l=ll.get(e);if(void 0===l)return;let i=t.t.split(".",1)[0];if(!l.def.bindables.includes(i))return;let s=r&&t.t===i;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,l,i),Ul(e,t,n,r,l,i,!1)}),e.ke=t(e.ke,(e,t,n)=>Ul(e,t,n,void 0,void 0,!1,!0)),e.Fe=n(r,e.Fe,(e,t,n,r,l)=>(function(e,t){let n=Fr.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,l=dl.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===r;e=e.d)r=l.ft.get(e);if(void 0===r)return!1;let i=r.e;return!((null===i.r||i.r.y)&&!i.ro)&&(!!n||(Ml(l,i.r),void v(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.me}${""===i.E?"":`.${i.E}`}#ro: ${i.he.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let l=e.fe;e.fe=(e,t)=>{let n=Fr.get(e);void 0!==n&&n.length>0&&v(`re-setting a root state with grafted volumes (${n.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=pl.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&v("re-setting a root state with mounted components is not supported: they read its data."),l?.(e,t)}}},Hl="$recursion",Kl=new WeakMap,Jl=new WeakSet,Yl=new WeakSet,Gl=0,Xl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ql=e=>`[wcs/recursion-${e}]`;function Zl(e,t){let n=n=>v(`${Ql("declaration-invalid")} ${Hl} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${Ql("declaration-invalid")} ${Hl} ${e} must be a non-empty string.`);let r=t.split(".");(r.length<2||"*"!==r[r.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<r.length-1;e++){let t=r[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var ei=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function ti(e,t){let n=`${e.l}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),r}function ni(e,t,n){let r=ti(e,t),l=function(e,t){for(let n=t;null!==n;n=n.l.ae){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===l&&v(`[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.`),ei(e,l.k)+r}function ri(e,t,n){let r=new Set,l=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&v(`${Ql("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),l.has(e)&&v(`${Ql("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),i+1>128&&v(`${Ql("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${i+1} (the limit is 128).`),l.add(e),0)),s=(l,o)=>{for(let a of l){n(o,a);let l=e.o(`${ei(t,o)}.${t.key}`),u=e.read(l,a);i(u,l.t,o+1)&&(r.add(u),s(e.Ve(a,l).f,o+1),r.delete(u))}},o=e.o(t.l),a=e.read(o,null);i(a,t.l,0)&&(r.add(a),s(e.Ve(null,o).f,0))}function li(e,t){let n=function(e){let t=e[Hl],n=[],r=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!r.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),r.add(e);if(void 0===t)return n.length>0&&F(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${Ql("declaration-invalid")} ${Hl} must be an object mapping one anchor path to its repeating sub-path.`);let l=Object.entries(t);1!==l.length&&v(`${Ql("declaration-invalid")} ${Hl} must declare exactly one anchor (it declares ${l.length}).`);let i=Zl("anchor",l[0][0]),s=Zl("repeat",l[0][1]),o=i.slice(0,-2),a=s.slice(0,-2),u=`.${s}`,c=new Map,f=[],h=`${o}.**`;for(let[e,t]of n){let n=e.slice(h.length);(!e.startsWith(h)||""!==n&&"."!==n[0]||n.includes("**"))&&v(`[wcs/recursion-anchor] "${e}": a recursive key is "${h}" followed by a path (the anchor is "${i}").`),(""===n||n.split(".").slice(1).some(e=>""===e))&&v(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&v(`${Ql("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${Xl(i)}((?:${Xl(u)})*)${Xl(n)}$`),n])}return{l:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${Xl(o)}((?:${Xl(`.*.${a}`)})*)$`)}}(t),r=Kl.has(e);null!==n?(r||Gl++,Kl.set(e,n),Yl.add(e),Jl.has(e)||function(e){Jl.add(e);let t=e,n=t.ot;t.ot=r=>{let l=Kl.get(e);if(r.t.includes("**")){let t=e.I.jt(r.t)===r;return void(Yl.has(e)||void 0===l&&t?r.getter=()=>F(r.t):t||n.call(e,r))}if(void 0!==l&&null===r.getter)for(let[e,n]of l.matchers)if(e.test(r.t)){r.getter=l.families.get(n),r.n>0&&(r.P=t.je++),l.owners.set(r,l.l+".**"+n);break}n.call(e,r)};let r=t.resolve;t.resolve=(t,n)=>{let l=Kl.get(e);return r.call(e,void 0!==l&&t.includes("**")?ni(l,t,n):t,n)};let l=t.getAll;t.getAll=(n,r)=>{let i=Kl.get(e);if(void 0===i||!n.includes("**"))return l.call(e,n,r);if(void 0===r)return l.call(e,ni(i,n,t.u));(!Array.isArray(r)||r.length>0)&&v(`${Ql("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=ti(i,n),o=[];return ri(e,i,(t,n)=>{for(let r of l.call(e,ei(i,t)+s,e.H(n)))o.push(r)}),o};let i=t.yn;t.yn=(n,r,l,s)=>{let o=Kl.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,r,l,s);Array.isArray(r)||w(9,[n]),r.length>0&&v(`${Ql("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof l||!0===s?.spread)&&v(`${Ql("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Me>0&&w(8);let a=ti(o,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(o.step);)u=u.slice(o.step.length);let c=o.key.split(".");(""===u||u===`.${o.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${Ql("structural-write")} "${n}" writes the recursion structure itself (a node, its "${o.key}" list or that list's length, or an object on the way to it).`);for(let e of o.families.keys()){let t=e;for(;t.startsWith(o.step);)t=t.slice(o.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${Ql("readonly")} "${n}" writes into the recursive getter "${o.l}.**${e}".`)}let f=[];ri(e,o,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=i.call(e,ei(o,t)+a,e.H(n),l);return h}}(e)):r&&(Kl.delete(e),Gl--)}function ii(e,t){if(0===Gl)return!1;let n=Kl.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.d){let r=n.owners.get(e);void 0!==r&&v(`${Ql("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var si={name:"recursion",install(){e.fe=t(e.fe,li),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){Yl.delete(e)}(e)}),e.Fe=n(r,e.Fe,ii)}},oi="4.2.0",ai=e=>e.split(".").slice(0,2).join("."),ui=class extends Zt{static find(e){return e.querySelector?.(le.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 ai(this.version)===ai(oi)}};function ci(e){let t=le.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends ui{})}var fi=()=>le.tagNames.ssr,hi=Symbol.for("wcstack.ssr.snapshotBuilder"),di=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),pi=e=>document.createComment(e),mi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,gi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),yi=new WeakMap,bi=new WeakMap,vi=new WeakMap,$i=new WeakSet,wi=new WeakMap;function Ai(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function ki(e,t,...n){for(let n of Array.from(e.attributes))t.setAttribute(n.name,n.value);return(t.content??t).append(...n),t}var xi=e=>null===e.M?e.ze:e.M[e.M.length-1];function Si(e,t,n){let r=[pi(null===n?"wcs-[":`wcs-[:${n}`)];for(let e of t)null===n&&r.push(pi("wcs-|")),r.push(...Ai(e.ze,xi(e)));r.push(pi("wcs-]")),e.after(...r);for(let e of r)$i.add(e)}function Ti(e){if(e instanceof ct){Si(e.S,e.Te,null);for(let t of e.Te)Ni(t);return}let t=e.O;null!==t&&(Si(e.G[e.G.length-1].S,[t],e.w),Ni(t))}function Ni(e){if(null!==e.c)for(let t of e.c)Ti(t)}var Oi=new Set(["script","style","template","textarea","title"]),ji="data-wcs-raw",Ci=e=>Oi.has(e.localName)||e.localName===fi();function Mi(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(pi("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(pi("wcs-s")):1===t.nodeType&&!Ci(t)&&Mi(t)}var Pi=0;function Ei(e,t){let n=e.getRootNode(),r=[t];for(let e of bi.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let l=new Map;for(let e of r){let t=yi.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.$&&n.set(t.$.S,t.$),null!==t.L)for(let e of t.L)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.D)for(let t of e.D.G)n.set(t.S,e.D);let r=new Set;for(let[e,i]of t){l.set(e,i);let t=n.get(e);void 0!==t&&!r.has(t)&&e.isConnected&&(r.add(t),Ti(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=vi.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>$i.has(e)||1===e.nodeType&&t.has(e)&&Li(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Ci(e.parentNode)?wi.has(e):t.has(n)&&gi(n,"wcs-t:"))&&(wi.has(e)||t.get(e)!==e.data):!t.has(e))&&r.push(e)}for(let e of r)e.remove()}let n=Array.from(e.childNodes);Ci(e)&&n.some(e=>wi.has(e))&&e.setAttribute(ji,n.map(e=>wi.has(e)?`{{ ${wi.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Mi(9===n.nodeType?n.body:n);let i=document.createElement(fi());i.setAttribute("version",oi);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 n of Object.keys(e)){if("$"===n[0])continue;let r=Object.getOwnPropertyDescriptor(e,n);void 0!==r.get||void 0!==r.set||"function"==typeof r.value||(t[n]=r.value)}return t}(t.target)),i.append(s);for(let[e,t]of l){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let r="svg"===n?.localName,l=`wcs-${r?"s":"t"}${Pi++}`;e.replaceWith(pi(`wcs-p:${l}`));let s=document.importNode(Pt(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(ki(e,document.createElement("template"),...e.childNodes));if(r){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=l,i.append(ki(t,o,s))}e.before(i)}function Wi(e){!function(e){if(null!==e.querySelector(le.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=>wi.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(`${le.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===fi())continue;let e=t.engine;null!=e&&Ei(t,e)}}var Ii=Symbol.for("wcstack.state.ssr.impl"),Ri=new Map,Di=new WeakMap,Li=t=>!0===e.Eo?.(t),qi=e=>1===e.nodeType&&!Ci(e)&&!Li(e),zi=e=>e.f.flat().concat(e.q??[]),Ui=e=>{for(let t of zi(e))t.remove()};function Fi(e,t,n){let r=/^wcs-\[(?::(\d+))?/.exec(e.data),l=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!mi(o,"wcs-]");){let e=o.nextSibling;if(mi(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];gi(o,"wcs-[")?e=Fi(o,t,n):(n.push(o),qi(o)&&_i(o,t))}o=e}let a={branch:void 0===r[1]?null:Number(r[1]),f:s,q:o??i.appendChild(pi("wcs-]"))},u=zi(a);o=a.q.nextSibling;for(let e of u)n?.push(e),t&&jt.add(e);return t&&null!==l?Ri.set(l,a):Ui(a),o}function _i(e,t){for(let n=e.firstChild;null!==n;)gi(n,"wcs-[")?n=Fi(n,t):(qi(n)&&_i(n,t),n=n.nextSibling)}function Vi(e,t,n){let r=e=>{for(let l of Array.from(e.childNodes))if(l.parentNode===e)if(8===l.nodeType){let e=l.data;try{if("wcs-s"===e)l.remove();else if("wcs-e"===e)l.replaceWith("");else if(e.startsWith("wcs-t:")){let t=pi(`@@:${decodeURIComponent(e.slice(6))}`),n=l.nextSibling;for(;null!==n&&!mi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),l.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=l.parentNode,r="s"===e[10]?ki(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);r.removeAttribute("id"),t.replaceChild(r,l)}}}catch{}}else 1===l.nodeType&&!Ci(l)&&(Li(l)?Di.set(l,{ssr:t,Ce:n}):r(l))};r(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||Xi(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{gi(e,"wcs-[")?r++:mi(e,"wcs-]")&&--r<0&&(r=0,n=t+1)}),0===r)continue;let l=0;for(let r=t.firstChild;null!==r;r=r.nextSibling)if(gi(r,"wcs-["))l++;else if(mi(r,"wcs-]")&&0===l--){t.prepend(...e.slice(n));break}}}(e),_i(e,n)}function Bi(t){let n=Di.get(t);if(void 0===n||(Di.delete(t),Vi(t,n.ssr,n.Ce),!n.Ce))return null;let r=e.Ce;return e.Ce=es,()=>{e.Ce=r,Hi()}}function Hi(){for(let e of Ri.values())Ui(e);Ri.clear()}function Ki(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Ji(e,t,n,r){let l=null;for(let r of e){let e=r[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===l||e.length>l[n].length)&&(l=r)}let i=l?.[r];if(null==i)return null;let s=l[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function Yi(e,t,n){if(di()){if(n instanceof Array){for(let e=n.length;e-- >0;)vt(n[e])&&n.splice(e,1);let e=t;if(n.some($t))$i.add(e);else if(e.localName.includes("-")&&!Li(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);vi.set(e,t)}return}if("string"==typeof n){if(wi.set(t,n),Ci(t.parentNode))return;let e=pi(`wcs-t:${encodeURIComponent(n)}`),r=pi("wcs-/t");return t.before(e),void t.after(r)}let r=yi.get(e);void 0===r&&yi.set(e,r=new Map),r.set(t,n);let l=t.getRootNode(),i=bi.get(l);return void 0===i&&bi.set(l,i=new Set),void i.add(e)}if("string"!=typeof n&&Ri.size>0){let e=Ri.get(n);void 0!==e&&(Ri.delete(n),Ri.set(t,e))}}var Gi=e=>null!==e&&8===e.nodeType&&[le.commentIfPrefix,le.commentElseIfPrefix,le.commentElsePrefix].includes(e.data),Xi=e=>3===e.nodeType&&""===e.data.trim(),Qi=e=>(Ri.get(e)?.q??e).nextSibling;function Zi(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.On;for(let r=0;r<n.length;r++){let l=n[r],i=e.ln,s=t[l[0]];for(let e=0;;){if(i=i.childNodes[l[e]],s?.nodeName!==i.nodeName)return!1;if(++e===l.length)break;s=s.firstChild;for(let t=l[e];t>0&&null!==s;t--)s=Qi(s)}e.So[r]=s}return!0}function es(e,t,n){if(0===Ri.size)return null;let r=t,l=0;if(!n){let e=le.commentIfPrefix;if(!mi(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Gi(n)&&l++,!mi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ri.has(r)&&null!==n&&!mi(n,e)&&1!==n.nodeType;n=n.nextSibling)Gi(n)&&(r=n)}let i=Ri.get(r);if(void 0===i)return null;if(!n&&i.branch!==l)return Ri.delete(r),Ui(i),null;let s=i.f.shift();if(0===i.f.length&&Ri.delete(r),i.q?.replaceWith(...Ai(t,r)),i.q=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=Ri.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.q;)e++}if(!Zi(e,o)){let n=(e.In?e.root:e.ln).cloneNode(!0);o=e.In?[n]:[...n.childNodes],Zi(e,o),(s[0]??i.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var ts={name:"ssr",install(){e.Dn=Yi,e.hr=Bi;let n=e.element;e.element=(t,r)=>{"mounting"===r&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||di())return;let r=n.previousElementSibling,l=r?.localName===fi(),i=l?r.getAttribute("version"):null,s=null===i||ai(i)===ai(oi);if(s){let e=t,n=e.Ee;e.Ee=(e,r)=>"$connectedCallback"===e?void 0:n.call(t,e,r)}if(!l)return;let o=!s&&parseInt(i)<4,a=/^3\.(\d+)\.(\d+)$/.exec(i),u=null!==a&&(+a[1]-5||+a[2]-3)>=0;s||console.warn(`[@wcstack/state] <${fi()} version="${i}"> does not match ${oi}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!u?" 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 c=s?r.querySelector('script[type="application/json"]'):null;if(null!==c){let e=JSON.parse(c.textContent||"{}"),n=t.target;for(let t of Object.keys(e)){let r=Object.getOwnPropertyDescriptor(n,t);void 0!==r&&(void 0!==r.get||void 0!==r.set||"function"==typeof r.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${ji}]`)))e.textContent=e.getAttribute(ji),e.removeAttribute(ji);let h=9===f.nodeType?f.body:f;o?function(e,t,n){let r=new Map,l=e=>{let t=e.parentElement;for(;null!==t&&!Li(t);)t=t.parentElement;if(null===t)return null;let n=r.get(t);if(void 0===n){let e=l(t),i=t.querySelector(`:scope > ${le.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of ce(t.getAttribute(le.bindAttributeName)??"")){let t=r.Ze;r.xe[0]===i&&n.push([e?Ji(e,t,1,0):t,r.xe.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let r=l(e);if(null===r)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:Ji(r,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return r.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:Ji(r,i[2],2,1)??i[2]};for(let t of Ki(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!mi(r,`@@wcs-${e[1]}-end:${e[2]}`);)r=r.nextSibling;if(null!==r){for(;t.nextSibling!==r;)t.nextSibling.remove();r.remove(),t.replaceWith(..."text"===e[1]?[pi(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let r of Ki(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(r.data)?.[1],l=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===l)continue;let o=document.importNode(l,!0),a=le.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,l)=>t+i(n??r,l))),s(o.content,n??r);let u=o.content.firstChild;r.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")}(h,r,u):Vi(h,r,s),r.remove(),s&&(e.Ce=es,queueMicrotask(()=>{Hi(),e.Ce=null}))}(t),n?.(t,r)},function(){let e=globalThis;e[Ii]={build:Wi,reset(){Pi=0}},void 0===e[hi]&&(e[hi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Ii].build(t),reset:()=>e[Ii].reset()})}(),e.Ao=t(e.Ao,ci);for(let e of nn())ci(e)}},ns="__WCSTACK_DEVTOOLS_HOOK__",rs=null,ls=new Set,is=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),ss=new WeakMap,os=0;var as=new WeakMap;function us(e){if(null===rs)return;let t=as.get(e),n=ls.has(e)?function(e,t){let n=new Map,r=new Set,l=(r,l,i,s,o,a)=>{if(5===r)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(r,l),c=0===s.n?null:o,f=`${(e=>{let t=ss.get(e);return void 0===t&&ss.set(e,t=++os),t})(i)}|${u}|${s.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:s.t,bindingType:a,node:i,replaceNode:i},absoluteAddress:is(e,s,c)})},i=e=>l(e.i,e.name,e.a,e.o,e.r,e.on()),s=e=>{if(!r.has(e)){if(r.add(e),null!==e.ye)for(let t of e.ye)i(t);if(e instanceof et&&null!==e.pe){let t=e.F.Xe;for(let n=0;n<t.length;n++){let r=e.V?.[n];void 0!==r?i(r):l(t[n].i,t[n].name,e.pe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.c)for(let t of e.c)o(t)}},o=e=>{if(!r.has(e))if(r.add(e),e instanceof ct){l(-1,"for",e.S,e.l.o,e.l.ae,"for");for(let t of e.Te)s(t)}else null!==e.O&&s(e.O)};for(let t of e.ue.values())for(let e of t)i(e),null!==e.D&&o(e.D);for(let t of e.oe.values())if(null!==t.$&&o(t.$),null!==t.L)for(let e of t.L)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,r]of t)n.has(e)||rs({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&rs({type:"state:binding-added",...r});as.set(e,n)}function cs(e){let t=Lt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function fs(e){let t=new Set,n=new Set,r=new Set,l=new Set;for(let i of e.I.all()){for(let e=1;e<=i.n;e++)t.add(i.h[e].t);"*"===i.s&&n.add(i.t),null!==i.getter&&r.add(i.t),null!==i.ie&&l.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:r,setter:l},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.ce.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==i.$watch&&"object"==typeof i.$watch?new Set(Object.keys(i.$watch)):null,keyedListPaths:null!==i.$listKeys&&"object"==typeof i.$listKeys?new Set(Object.keys(i.$listKeys)):null}}var hs=new WeakSet,ds=new WeakMap;function ps(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(hs.has(t))return;hs.add(t);let r=t.emit;t.emit=(...l)=>(null!==rs&&rs({type:"state:token-emit",kind:n,tokenName:t.name,args:l,subscriberCount:t.size,stateElement:e.element}),r.apply(t,l))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.ce.values())t(n,"event")}(e),"connected"===t){if(ls.has(e))return;ls.add(e),rs?.({type:"state:element-registered",rootNode:e.root,element:e.element}),us(e)}else"disconnected"===t&&(ls.delete(e),us(e),rs?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function ms(e,t,n,r,l,i){if(null===rs)return;let s=is(e,t,0===t.n?null:n),o=ds.get(e);void 0===o&&ds.set(e,o=new Set),o.add(s),i&&rs({type:"state:write",absoluteAddress:s,value:l,oldValue:r,hasOldValue:!0})}function gs(e){if(null===rs)return;let t=ds.get(e);ds.delete(e),void 0!==t&&rs({type:"state:update-batch",addresses:t}),us(e)}function ys(e,t,n){rs?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var bs={"*":["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 vs(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...bs["*"],...Object.hasOwn(bs,e)?bs[e]:[]])(n);return r.includes(t)||w(1205,[n,t,r.join(", ")],t,r),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var $s=[Sn,lr,jr,Dr,Bl,si,ts,{name:"devtools",install(){e.element=t(e.element,ps),e.Se=t(e.Se,ms),e.Oe=t(e.Oe,gs),e.qe=t(e.qe,ys),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let t=globalThis,n=t[ns]??(t[ns]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let r of t)r.onEvent?.(e.id,n)})};return{version:2,sources:e,register(r){if(!e.has(r.id)){e.set(r.id,r),n(r);for(let e of t)e.onSourceRegistered?.(r)}},unregister(n){let r=e.get(n);if(void 0!==r){r._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(r){t.add(r);for(let t of e.values())n(t),r.onSourceRegistered?.(t);return()=>{if(t.delete(r))for(let t of e.values())n(t)}}}}());2!==n.version&&console.warn(`[@wcstack/state] devtools hook registry version ${n.version}, expected 2: keeping the existing one.`),n.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:oi,getStateElements:()=>[...ls].map(fs),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.I.all()){let r=n.W,l=n.De?.length??0;if((null===r||0===r.size)&&0===l)continue;let i,s=0;if(null!==r)for(let e of r.values())s+=e.size;try{i=0===n.n?e.v(n,null):void 0}catch{i=void 0}t.push({path:n.t,tracked:!1,rows:s,keys:null===r?0:r.size,lists:l,lastValue:i})}return t}(cs(e)),keys(e){let t=cs(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return cs(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){cs(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(t){let n=null===rs&&null!==t;rs=t,null===t&&(as=new WeakMap),e.at=t&&((e,t)=>rs?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of ls)us(e)})}})}()}},{name:"native-commands",install(){e.or=vs}}];function ws(e){return e}var As=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],ks={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"真偽性を反転(falsy → true)",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},add:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},sub:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},abs:{description:"絶対値",hasArgs:!1,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:0},clamp:{description:"範囲内に丸める (min,max)",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:2,maxArgs:2,argTypes:["number","number"]},toFixed:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},upper:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lower:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},capitalize:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},padStart:{description:"先頭を埋める (length[,char]。char の既定は 0 — JS の既定は空白なので注意)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},padEnd:{description:"末尾を埋める (length[,char]。char の既定は空白 — JS と同じ)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},repeat:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},reverse:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},truncate:{description:"切り詰めて省略記号 (length[,suffix]。suffix の既定は … — U+2026 の 1 文字)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},join:{description:"配列を連結 ([separator]。既定はカンマ + 空白)",hasArgs:!0,resultType:"string",acceptTypes:["array"],minArgs:0,maxArgs:1,argTypes:["string"]},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},unit:{description:"単位(接尾辞)を付加",hasArgs:!0,resultType:"string",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["string"]},date:{description:"ロケール形式の日付 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},ymd:{description:"YYYY-MM-DD 形式 ([separator]。既定は -)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},hms:{description:"HH:MM:SS 形式 ([separator]。既定は :)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},coalesce:{description:"null / undefined の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},nullIfEmpty:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0},currency:{description:"通貨の書式 (code[, locale]。code は ISO 4217 — JPY / USD / EUR、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:1,maxArgs:2,argTypes:["string","string"]}},xs=2,Ss=Object.freeze({}),Ts=Object.freeze({}),Ns=Object.freeze({}),Os=Object.freeze(["prevent","stop","ro","direct"]),js=Object.freeze(["init","sync"]),Cs=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function Ms(){return{version:2,syntax:{bindAttribute:le.bindAttributeName,tagName:le.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(oe),modifiers:{flags:Os,keyValue:js,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:N,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:j,class:C,attr:M,style:P}}},filters:[...Object.keys(Se),...Object.keys(kn)],filterMeta:ks,filterAliases:Ss,declarationAliases:Ts,apiAliases:Ns,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(Cs.map(e=>[e,{type:"boolean",default:!0}])),features:[...As],nativeCommands:Object.fromEntries(Object.entries(bs).map(([e,t])=>[e,[...t]]))}}var Ps=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),Es=Object.freeze([]);function Ws(e){if(!le.enableContractAnalyzer)return Es;let t=[],n=rs,r=e=>{t.push(e),n?.(e)},l=e.manifestExtensions;if(null===l||"object"!=typeof l)return t;for(let e of Object.keys(l))Ps.has(e)||r({type:"contract:unsupported-extension",namespace:e});let i=l["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=Is(e);if(r({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){r({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let l=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(l.observables??{})){let l=n.ce.get(t);if(void 0===l){r({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==l&&r({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:l})}for(let t of Object.keys(l.inputs??{}))n.inputs.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(l.commands??{}))n.commands.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function Is(e){let t=customElements.get(e)?.wcBindable;if(null===t||"object"!=typeof t||"wc-bindable"!==t.protocol)return null;let n=e=>Array.isArray(e)?e:[],r=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&r.set(e.name,e.event);let l=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{ce:r,inputs:l(t.inputs),commands:l(t.commands)}}function Rs(e,t){(function(e){for(let t of e)s.has(t.name)||(s.add(t.name),t.install())})($s),rn(e,t)}export{ui as Ssr,je as TRUSTED_TYPES_POLICY_SLOT,oi as VERSION,xs as WCS_MANIFEST_VERSION,Ws as analyzeContract,Rs as bootstrapState,sn as buildBindings,Ss as builtinFilterAliases,ks as builtinFilterMeta,ws as defineState,Qt as getBindingsReady,ie as getConfig,Ce as getTrustedTypesPolicy,Ms as getWcsManifest,Me as setTrustedTypesPolicy};
1
+ var e={};function t(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function n(e,t,n){return null==t?n:(...l)=>{let r=t(...l);return e(r)?r:n(...l)}}var l=e=>!0===e,r=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.Ct&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.Ct(t)}}function a(e,t){if(!s.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}var u=class{constructor(e,t,n){this.c=[],this.getter=null,this.ie=null,this.se=!1,this._=[],this.Q=[],this.pt=null,this.F=-1,this.Y=c,this.Me=null,this.It=null,this.Dt=null,this.W=null,this.pn=!1,this.mn=!1,this._n=!1,this.Z=0,this.mt=new Set,this.t=e,this.d=n,this.s=t;let l=null===n?[null]:n.h.slice(),r="*"===t;r&&l.push(n),this.n=l.length-1,this.z=r?[]:null===n?[t]:[...n.z,t],this.h=l}Wn(e){this.mt.has(e)||(this.mt.add(e),this._.push(e),e.Q.push(this))}Io(e){this.mt.delete(e);let t=this._;t.splice(t.indexOf(e),1)}Do(){this.getter=null,this.ie=null,this.F=-1,this.Y=c,this._.length=0,this.mt.clear(),this.Q.length=0,this.pt=null,this.Me=null,this.It=null,this.Dt=null,this.W=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.d}return!1}},c=Symbol("unset"),f=Symbol("dirty"),h=Symbol("failed"),d=class{constructor(e=null){this.ht=new Map,this.Vn=e}Mt(e){return this.ht.get(e)}get(e){let t=this.ht.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),l=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),l),this.Vn?.(t),this.ht.set(e,t),l&&l.c.push(t),t}all(){return this.ht.values()}jt(e){this.ht.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,l=e.split("."),r=[];for(let e=0;e<l.length;e++){let t=l[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,r.push(Number(t)),l[e]="*"):"*"===t&&r.push(-1)}if(!n)return{o:l.join("."),indexes:r};let i={o:e,indexes:null};return p.size>4095&&p.clear(),p.set(e,i),i}var g=class{constructor(e,t,n){this.yt=null,this.x=null,this.ye=null,this.W=null,this.c=null,this.b=!0,this.l=e,this.y=t,this.$=n}},y=class{constructor(e,t){this.T=null,this.f=[],this.x=null,this.L=null,this.te=!1,this.Lt=!1,this.bt=!1,this.o=e,this.ae=t,this.n=e.n+1}},b=[];function v(t,n,l){throw new Error(`[@wcstack/state] ${t}${e.jo?.(t,n,l)??""}`)}function $(t,n=[]){return e.Lo?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function w(e,t,n,l){v($(e,t),n,l)}var A=class{constructor(e){this.wt=new Set,this.name=e}get size(){return this.wt.size}subscribe(e){return this.wt.add(e),()=>{this.wt.delete(e)}}unsubscribe(e){return this.wt.delete(e)}emit(...e){let t=[];for(let n of this.wt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${$(17,[this.name])}`,e)}return t}};function k(e,t,n){if(void 0===e)return[];Array.isArray(e)||w(18,[t]);let l=new Set;for(let r of e)("string"!=typeof r||""===r)&&w(19,[t]),r===n&&w(20,[t,r,n]),l.has(r)&&w(21,[t,r]),l.add(r);return e}var x=Symbol.for("wcstack.transition-runner");function S(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function T(e,t,n){let l=S(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var N="else",O="eventToken",j="command",C="class",M="attr",P="style",E=/^\$[1-9]\d{0,2}$/,W=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function I(e){let t=[],n=[],l="",r=null,i=!1,s=-1,o=-1,a=e=>{let r=function(e,t,n){let l=-1===t?e.length:t,r=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,r+e.slice(r).trimEnd().length)}(l,s,o);(!e||r||i)&&(t.push(r),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:W.test(e)?Number(e):e)}(r,i))),l="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];r?n===r?r=null:(-1===s&&(s=l.length),l+=n,o=l.length):'"'===n||"'"===n?(r=n,i=!0):","===n?a():l+=n}return null!==r&&w(107,[r,e]),a(!0),{args:t,literals:n}}var R=e=>e.trim();function D(e,t){let n=[],l=null;for(let r=0;r<e.length;r++){let i=e[r];null!==l?i===l&&(l=null):"'"===i||'"'===i?l=i:i===t&&n.push(r)}return n}var L=(e,t)=>D(e,t)[0]??-1;function q(e,t){let n=[],l=0;for(let r of D(e,t))n.push(e.slice(l,r)),l=r+1;return n.push(e.slice(l)),n}function z(e,t,n){let l=L(e,"|");if(-1===l)return[e.trim(),[]];let r=e.slice(l+1).trim(),i=n.get(r);return void 0===i&&(i=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=L(e,"("),r=(e=>D(e,")").pop()??-1)(e);if(-1===r&&(r=e.lastIndexOf(")")),-1!==n&&-1===r&&w(108,[e]),-1!==r&&-1===n&&w(109,[e]),-1!==r&&r<n&&w(110,[e]),-1!==r&&e.slice(r+1).trim().length>0){let t=e.slice(r+1).trim();w(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&w(112,[l]),i.includes("#")){let[,e]=i.split("#");w("input"===t?113:114,[i,e])}return-1===n?{Hn:i,args:[],literals:[]}:{Hn:i,...I(e.substring(n+1,r))}})}(q(r,"|").map(R),t,e),n.set(r,i)),[e.slice(0,l).trim(),i]}var U=new Map;function F(e){w(1101,[e])}function V(e){let[t,n]=z(e,"output",U);t.includes("@")&&w(32,[t]);let l=t,r=l.startsWith("."),i=r?l.slice(1):l;return(i.length>0&&i.split(".").some(e=>0===e.length)||!r&&0===i.length)&&w(119,[e]),function(e){e.includes("**")&&F(e);let t=e.split(".").length;t>512&&w(117,[e,t])}(l),{Qe:l,Ze:n}}var _=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&F(e),e}var K=0;function J(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var Y=()=>new Set,G=()=>[],X=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Z(e,t){return e===t||e!=e&&t!=t}function ee(e,t,n){let l=e.W?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e.W.delete(t)}function te(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ne(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ae;return null!==e&&e.l.n===t?e:null}function le(e,t,n){let l=ne(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var re=class{constructor(e,t){this.je=0,this.u=null,this.Le=0,this.vt=new Set,this.et=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.St=[],this.Be=null,this.Un=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this._e=[],this.We=[],this.Ve=[],this.kt=!1,this.hn=!1,this.Kt=new WeakMap,this.D=0,this.Ut=0,this.gn=!1,this.qt=!1,this.zt=!1,this.Fe=0,this.qn=()=>{this.D=0,this.gn=!1},this.zn=()=>{this.Fe--},this.rp=null,this.rr=null,this.Bo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.tt=[],this.Wo={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=ne(this.u,t);null===n&&w(7,[e]);let l=this.o(e);if(null!==l.getter||l.se)return this.watchIndex(t),n.y===this.read(l,null);let r=this.X;if(null!==r){let e=r.getter,n=l.Me??(l.Me=[]);if(!n.some(n=>n.getter===e&&n.Xn===t)){n.push({getter:e,Xn:t});let r=e.h[t];(r.It??(r.It=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,ne(this.u,n.n)))},$dependOn:e=>{this.resolve(H(e),this.u),null!==this.X&&0===this.X.be&&this.Gn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.yn(e,t,n,l),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],l=this.o(t,!0);this.bn("$resolve",t,l,n,!0);let r=this.Jn(l,n,null);if(e.length<3)return this.read(l,r);this.P(l,r,e[2])},$postUpdate:e=>{this.resolve(H(e),this.u);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.T[n.y],X.delete(n.l.T),this.A.Xt(n)),this.wn(t,n),null!==n&&this.Qn(n,t,void 0,n.$,!1),0===t.n&&this.Zn(t,void 0,void 0,!0),this.Gt(t,n,void 0,void 0,!1)}},this.A=t,this.I=new d(e=>{this.tt.push(e),this.nt(e)}),this.eo(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let r=n.target;if("symbol"==typeof t)return Reflect.get(r,t);if(36===t.charCodeAt(0))return n.ot(t);if(t.indexOf(".")<0){let e=n.I.Mt(t);if(void 0===e||null===e.getter){let e=r[t];if("function"==typeof e)return l===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.u),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(H(t),n.u),n.P(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.I.get(e);return t||(n.pn=!0),n}to(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let l=Object.getOwnPropertyDescriptor(n,e);if(void 0===l.get&&void 0===l.set)continue;let r=this.o(e);r.getter=l.get??null,r.ie=l.set??null,null!==r.getter&&r.n>0&&(r.F=this.je++)}for(let e of this.I.all())this.nt(e)}nt(e){e.t.includes("**")&&F(e.t),("__proto__"===e.s||"prototype"===e.s)&&w(120,[e.t]);let t=e.d;e.se=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.se),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(E.test(n))e.getter=function(){return this[n]};else{let l=t.split("."),r=l.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(r<0||l.indexOf("*",r)>=0)return;e.getter=()=>(this.resolve(t,this.u),this.rp!==e?this.read(this.rp,this.rr):this.read(e.d,this.u)?.[n]),e.ie=l=>{if(this.resolve(t,this.u),this.rp!==e)return this.P(this.rp,this.rr,l);let r=this.read(e.d,this.u);null==r&&w(4,[t,r]),r[n]=l}}e._n=!0,e.n>0&&(e.F=this.je++)}He(e,t){let n=null===e?this.oe:e.c??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new y(t,e)),t.pn=!0,this.G(l),l}no(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.x?.S??null,"for")}}G(t){let n=this.v(t.o,t.ae);if(n===t.T)return;this.oo(t);let l=function(e,t,n){let l=Array.isArray(t)?t:b;if(l===e.T)return null;let r=e.f,i=l.length,s=r.length,o=new Array(i),a=0;for(;a<i&&a<s&&r[a].$===l[a];)o[a]=r[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&r[u].$===l[c];)o[c]=r[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,l[t]);else if(a>c)for(let e=a;e<=u;e++)n.Bt(r[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)r[e].$===l[e]&&(o[e]=r[e]);let i=new Map;for(let e=u;e>=a;e--){let n=r[e];if(e<=t&&o[e]===n)continue;let l=i.get(n.$);void 0===l?i.set(n.$,n):Array.isArray(l)?l.push(n):i.set(n.$,[l,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,r=l[t],s=i.get(r);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(r)):(n=s,i.delete(r))),o[t]=n??new g(e,t,r)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Bt(t);else n.Bt(e)}for(let e=a;e<i;e++){let t=o[e];t.y!==e&&(t.y=e,n.Mo(t))}return e.f=o,e.T=l,r}(t,n,this);if(null===l)return;if(t.T===n){let e=J(this.Kt,n,G);if(e.push(t),e.length>1)for(let t of e)t.bt=!0}e.Qt?.(this,t,l),(null!==t.x||null!==t.L)&&!t.te&&(t.te=!0,this.We.push(t),this.we());let r=t.o.It;if(null!==r)for(let{source:e,getter:n}of r){let r=this.v(e,null),i=l[r],s=t.f[r];i!==s&&(void 0!==i&&i.b&&this.vn(n,i),void 0!==s&&this.vn(n,s))}}Mo(e){this.A.Ho(this,e)}Bt(e){e.b=!1;let t=e.W;if(null!==t){for(let e of t)ee(e.source,e.key,e.sub);e.W=null}if(null!==e.c)for(let t of e.c.values()){this.oo(t);for(let e of t.f)this.Bt(e)}}oo(e){let t=this.Kt.get(e.T);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.bt=!1,1===t.length&&(t[0].bt=!1))}resolve(e,t){let n=m(e),l=this.rp=this.o(n.o,!0),r=n.indexes;this.rr=0===l.n?null:null===r?le(t,l,l.n):this.Jn(l,r,t,e)}Jn(e,t,n,l){let r=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.He(r,a),c=t[o++];if(c<0)c=le(n,e,s)?.y??-1;else if(l&&u.T===b&&Object(i=this.v(a,r))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=l.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(r=u.f[c]??null,null===r)break}return this.rp=e,r}rt(e,t){return 0===e.n?te(this.target,e.z):null===t?void 0:te(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Gn(e,t,n),null!==e.getter)return this.A.Ko(this,e,t);if(e.se){let n=this.read(e.d,t);return n?.[e.s]}return null===e.d&&!(e.s in this.target)&&!this.vt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&w(301,[e.t],e.s,Object.keys(this.target)),this.rt(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Gn(e,t,n){let l=n.getter;e.Wn(l),0===l.n?e.Z!==n.de&&(e.Z=n.de,n.Sn.push(e)):e.n>0&&ne(t,Math.min(e.n,l.n))!==ne(n.r,Math.min(e.n,l.n))&&(l.pt??(l.pt=new Set)).add(e)}Uo(e,t){for(let n=0;n<this.Ht;n++){let l=this.Un[n];l.getter===e&&l.r===t&&w(701,[e.t])}this.Ht>=128&&w(801,[e.t]);let n=this.Ht++;this.Le++;let l=this.Un[n]??={getter:e,r:t,be:0,de:0,Sn:[]};l.getter=e,l.r=t,l.be=0,l.de=++K,l.Sn.length=0;let r=this.X;this.X=l;let i=this.u;this.u=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.qo(e,l),t}finally{this.Le--,this.Ht--,this.X=r,this.u=i,l.r=null}}qo(e,t){let n=t.de;for(let e of t.Sn)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.se&&Array.isArray(null!==t.getter?t.Y:this.rt(t,null))||this.io(t,e))}io(e,t){return e.Io(t),this.tt.push(e),!1}zo(){for(let e=this.tt;e.length>0;e=this.tt){this.tt=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.d||n.c.length>0||n._.length>0)&&(null===n.getter||n._n&&n.F<0)&&null===n.W){n.mn=!0,this.I.jt(n),t.add(n.d);for(let e of n.Q)this.io(e,n)}for(let e of t)(e.c=e.c.filter(e=>!e.mn)).length||this.tt.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.be){let n=t.getter,l=n.h[e];if(l){let e=l.Dt??(l.Dt=[]);e.includes(n)||e.push(n)}}}ot(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:E.test(t)?+t.slice(1):0;return(e<1||e>128)&&w(1001,[t]),this.watchIndex(e),ne(this.u,e)?.y}let l=this.Wo[t];if(void 0!==l)return l;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.ot?.(this,t)}eq(e,t){this.resolve(e,this.u);let n=this.rp,l=this.rr;if(null!==n.getter||n.se||n.n>0)return Z(this.read(n,l),t);let r=this.X;return null!==r&&0===r.be&&this.Yo(n,t,r),Z(this.v(n,null),t)}Yo(e,t,n){let l=n.getter,r=n.r,i=null===r?this.Yn:r.W??(r.W=[]);for(let r=0;r<i.length;r++){let s=i[r];if(s.sub.getter===l&&s.source===e){if(Z(s.key,t))return void(s.de=n.de);s.de!==n.de&&(ee(e,s.key,s.sub),i.splice(r--,1))}}let s={getter:l,r};J(e.W??=new Map,t,Y).add(s),i.push({source:e,key:t,sub:s,de:n.de})}Zn(e,t,n,l){this.Zt(e,r=>{let i=r.W;if(null===i&&null===r.Me)return;let s=r===e?[]:r.t.slice(e.t.length+1).split("."),o=te(t,s),a=te(n,s);if(null!==r.Me&&this.Xo(r,o,a,l),null!==i)for(let e of l?i.keys():[o,a]){let t=i.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.b?this.A.ve(this,n.getter,n.r):ee(r,e,n)}})}P(t,n,l,r=!1,i=!1){if(this.Le>0&&w(8),i||this.Fe>0?this.qt=!0:this.zt=!0,e.Oe?.(this,t,n,l,i))return;if(null!==t.ie){try{this.kn(t.ie,n,[l])}finally{this.Gt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&w(2,[t.t]),t.n>0&&null===n&&w(3,[t.t]);let s=t.se?this.v(t,n):this.rt(t,n);if(r||!this.Wt||!Object.is(s,l)||Object(l)===l){if("*"===t.s){let e=n;e.l.T[e.y]=l,X.delete(e.l.T),e.$=l,this.A.Xt(e)}else{let e=1===t.z.length?0===t.n?this.target:n.$:this.v(t.d,n);null==e&&w(4,[t.t,e]),e[t.s]=l}this.En(t,n),null!==n&&this.Qn(n,t,s,l),0===t.n&&this.Zn(t,s,l),this.Gt(t,n,s,l,!0,i)}}so(e){return(this.Kt.get(e.T)??[]).filter(t=>t.T===e.T&&(null===t.ae||t.ae.b))}Qn(e,t,n,l,r=!0){let i=e.l,s=t.t.slice(i.o.t.length+2),o=""!==s&&function(e){let t=X.get(e);if(void 0===t){let n=new Set;X.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(i.T);if(!o&&!i.bt&&null===i.o.getter&&!i.o._.length)return;let a=e.$,u=(t,i)=>{if(void 0===i||i===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(i.$=l,this.A.Xt(i)),r?this.En(o,i):this.wn(o,i),this.Gt(o,i,n,l,r)};for(let t of this.so(i))if(u(t,t.f[e.y]),o)for(let n of t.f)n.$===a&&n.y!==e.y&&u(t,n);if(""===s)return;let c=new Set([i.T]),h=e=>Array.isArray(e)&&e.includes(a),d=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.Kt.get(e)??[])for(let e of t.f)e.$===a&&u(t,e);for(let n of t){let t=n.Y,l=t===f;l&&(t=this.oe.get(n)?.T),(l||h(t))&&!c.has(n._)&&c.add(n._)&&(!l&&t!==e&&this.A.ve(this,n,null),d(t,n._))}},p=e=>{for(let t of e.Q)if(!c.has(t)&&c.add(t))if(null!==t.getter)p(t);else if(!t.se){let e=this.rt(t,null);h(e)&&d(e,t._)}};null!==i.o.getter?p(i.o):d(i.T,i.o._)}wn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.bt?this.so(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.Et(e,n),this.wn(e,n)}})}En(e,t){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let l=null===t?this.oe:t.c;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Xo(e,t,n,l){for(let{getter:r,Xn:i}of e.Me)this.lo(r.h[i],e=>{for(let i of l?e.f.keys():[t,n]){let t="number"==typeof i?e.f[i]:void 0;void 0!==t&&this.vn(r,t)}})}vn(e,t){t.l.n===e.n?this.A.ve(this,e,t):this.en(t,e,t=>this.A.ve(this,e,t))}Gt(t,n,l,r,i,s){e.Se?.(this,t,n,l,r,i,s),this.Ke(t,n)}Ke(e,t){this.A.Jo(this,e,t),this.we()}ao(e){let t=this.et.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.et.set(e,n);let l=this.root,r=this.Kn;return l.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==l;i=i.parentNode){let l=i[n];if(void 0!==l&&(l(t),t.cancelBubble))return;let s=i[r];if(void 0!==s&&s.b&&s.Qo(e,t))return}}),n}reset(t){let n=this.target,l=this.vt;for(let e of this.I.all())null===e.d&&null!==e.getter&&l.add(e.s);this.eo(t);for(let e in n)"$"!==e[0]&&l.add(e);for(let e of l)e in t&&l.delete(e);for(let e of this.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.co(e);this.Be=null;try{this.Yt()}finally{this.$n()}e.element?.(this,"reset")}eo(t){for(let[e,n]of _)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||w(46);for(let e of n)a(e,"$features")}let l=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof l||!l||Array.isArray(l))&&w(44,["state","$behavior"]);for(let e in l)(!B.includes(e)||"boolean"!=typeof l[e])&&w(44,["$behavior",e]);let[r,i,s]=B.map(e=>l[e]??!0);void 0!==this.target&&(r!==this._t||i!==this.Wt||s!==this.Vt)&&w(45);let o=function(e,t){let n={};for(let l of k(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new A(l);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new A(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&w(22);for(let[e,r]of Object.entries(l)){let l=n.get(e);void 0===l&&w(23,[e]),"function"!=typeof r&&w(24,[e]),l.subscribe((...e)=>t(r,e))}return n}(t,this._o);this._t=r,this.Wt=i,this.Vt=s,e.fe?.(this,t),this.target=t,this.je=0;for(let e of this.I.all())e.Do();this.Yn.length=0,this.to(t),this.commands=o,this.ce=u}co(e){this.no(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.yt=null,n.W=null,this.Et(t,n),null!==n.c)for(let e of n.c.values())this.co(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ae)t.unshift(n.y);return t}Zo(e,t,n){let l=this.ce.get(e);void 0===l&&w(1301,[e],e,this.ce.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&w(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&w(5,[e]),this.kn(l,n,[t,...this.H(n)])}kn(e,t,n){let l=this.u;this.u=t;try{return e.apply(this.proxy,n)}finally{this.u=l}}Et(e,t){if(null!==e.getter){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.ye;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let l=t.x;null!==l&&null!==l.pe&&l.uo(this,e);let r=t.l.L;if(null!==r)for(let n of r){let l=n.map.get(t);void 0!==l&&null!==l.pe&&l.uo(this,e)}}xn(e,t,n){this.Zt(e,e=>{let l=e._;for(let r=0;r<l.length;r++){let i=l[r];if(0===i.n)this.it(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.pt&&i.pt.has(e))this.nn(i.h[i.n],e=>this.it(i,e,n));else if(i.n<=e.n){let e=ne(t,i.n);null!==e&&this.it(i,e,n)}else this.en(t,i,e=>this.it(i,e,n))}})}it(t,n,l){l(t,n)&&(e.ke?.(this,t,n),this.Et(t,n),this.xn(t,n,l))}Zt(e,t){t(e);let n=e.c;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.lo(e,e=>{for(let n of e.f)t(n)})}lo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let l=n.c?.get(e);void 0!==l&&t(l)})}en(e,t,n){if(e.l.n===t.n)return n(e);let l=e.c?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.en(e,t,n)}nr(e){let t=e.r;null===t?J(this.ue,e.o,Y).add(e):(t.ye??(t.ye=[])).push(e)}Nn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.ye;t.b&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this._e.push(e),this.we())}we(){this.kt||(this.kt=!0,queueMicrotask(this.Bo))}Rn(){for(let e of this._e)e.te=!1;for(let e of this.We)e.te=!1;for(let e of this.Ve)e.Lt=!1;this._e=[],this.We=[],this.Ve=[],this.A.vt(this)}fo(t,n){let l=[...new Set([...this._e,...this.We,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${$(t)}`,l),e.st?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:l}),this.Rn()}Yt(){this.kt=!1;let t=this.Ut;this.Ut=0;let n=0;if(!this.qt||this.zt?this.qn():t>0?n=t:1===(n=++this.D)&&setTimeout(this.qn,0),this.qt=this.zt=!1,n>100)101===n?this.fo(41,100):this.Rn();else{this.hn=!0;try{for(let e=0;this._e.length>0||this.We.length>0||this.Ve.length>0;e++){if(e>=32){this.gn?this.Rn():this.fo(11,32),this.gn=!0;break}let t=this.Ve;if(t.length>0){this.Ve=[];for(let e of t)e.Lt=!1,this.no(e)}let l=this.We,r=this._e;this.We=[],this._e=[];let i=()=>{for(let e of l){e.te=!1;for(let t of[e.x,...e.L??[]])if(null!==t&&t.b)try{t.$t()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<r.length;t++){let n=r[t];!n.te||null===n.D==(0===e)||(n.te=!1,(null===n.Tn||n.Tn.b)&&this.Ue(n))}this.hn||(this.qe(),this.kt&&(this.Ut=n+1))},s=l.length>0||r.some(e=>null!==e.D)?T("state",i):i();void 0!==s&&s.then(void 0,e=>console.error(e))}}finally{this.hn=!1}this.qt=this.zt=!1,this.qe(),e.Ce?.(this),this.zo(),t>0&&this.kt&&(this.Ut=n+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,l){this.xt(e,{o:{t},a:n,on:()=>l})}Ue(e){try{e.apply()}catch(t){return void this.St.push([t,e])}null!==this.Be&&this.po(e.o,e.r)}po(e,t){let n=J(this.Be,e.t,G);null!==t&&n.push(this.H(t))}$n(){this.Be="function"==typeof this.target.$renderedCallback?new Map:null}qe(){let t=this.Be;if(null!==t&&t.size>0){this.Be=new Map;let e,n=[...t.keys()],l={};for(let[e,n]of t)n.length>0&&(l[e]=n);this.Fe++;try{e=this.Ee("$renderedCallback",[n,l])}catch(e){console.error(e)}Q(e)?e.then(this.zn,e=>{this.zn(),console.error(e)}):this.Fe--}if(0===this.St.length)return;let n=this.St;this.St=[];let l=this.target.$errorCallback;for(let[t,r]of n){e.ze?.(this,t,r);let n=r.o.t,i=r.on();if("function"==typeof l)try{let e=this.Ee("$errorCallback",[t,{path:n,bindingType:i,node:r.a}]);Q(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${$(12,r.name?[i,n,r.name,r.i]:[i,n])}`,t,r.a)}}Ee(e,t=[]){let n=this.target[e];return"function"==typeof n?this.kn(n,null,t):void 0}mo(e,t,n){if(0===e.n)return void n(null,[]);let l=[],r=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.He(s,o),u=t=>{l.push(t.y),i===e.n?n(t,l):r(i+1,t),l.pop()};for(let e of i-1<t.length?[a.f[t[i-1]]]:a.f)void 0!==e&&u(e)};r(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.bn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.u;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let r=le(t,n,e);if(null===r)break;l.push(r.y)}0===l.length&&w(6,[e])}}let r=[];return this.mo(n,l,e=>r.push(this.read(n,e))),r}yn(e,t,n,l){Array.isArray(t)||w(9,[e]),this.Le>0&&w(8);let r=this.o(e,!0);this.bn("$setAll",e,r,t,!1);let i=[];this.mo(r,t,(e,t)=>i.push([e,t.slice()]));let s=!0===l?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&w(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,l]=i[e],a="function"==typeof n?n(this.v(r,t),...l):s?n[e]:n;void 0!==a&&(this.P(r,t,a),o++)}return o}bn(e,t,n,l,r){let i=l.length;(i>n.n||r&&i<n.n)&&w(r?901:902,[e,t,n.n,i])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},se=()=>ie,oe=new Map,ae=new Set(["if","elseif","else","for"]),ue=new Set([N,"if","elseif","for","..."]),ce=new Set([C,M,P,j,O,"state"]);function fe(e){let t=function(e){return q(e,";")}(e).map(R).filter(e=>e.length>0).map(e=>{let t=L(e,":");-1===t&&w(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),r=n.split("#")[0].split("|")[0].trim();if(ue.has(r)){let t;return r!==n&&w(102,[e,r]),r===N?(l.length>0&&w(103,[e]),t={Qe:"#else",Ze:[]}):"..."===r?(0===l.length&&w(104,[e]),t=V(l),t.Ze.length>0&&w(105,[e])):(t=V(l),"for"===r&&t.Ze.length>0&&w(121,[e])),{$e:r,xe:[r],rn:[],M:[],...t,w:"..."===r?"spread":r}}(r===C||r===M)&&w(122,[e,r]);let i=V(l),s=function(e){let[t,n]=z(e,"input",oe),l=t.split("#").map(R);l.length>2&&w(115,[t]);let[r,i]=l,s=r.split(".").map(R);return!(s.length>1&&""===s[0])&&(0===r.length||s.some(e=>0===e.length))&&w(116,[e]),{$e:r,xe:s,rn:i?i.split(",").map(R):[],M:n}}(n),[o]=s.xe;if(""===o&&s.xe.length>1){let e=s.xe.slice(1);return(e.includes("")||ce.has(e[0]))&&w(106,[n]),{...s,$e:e.join("."),xe:e,...i,w:"prop"}}return{...s,...i,w:"radio"===r||"checkbox"===r?r:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ae.has(e.w))&&w(201,[e]),t}var he=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],de=new Map,pe=new Map;function me(e){for(let t of Object.keys(e))de.set(t,{...e[t]});pe.clear()}function ge(e){return de.has(e)}function ye(e){w(26,[e])}function be(e){w(27,[e])}function ve(e,t){w(28,[e,t])}function $e(e,t){w(29,[e,t])}function we(e){return!(!e||isNaN(Number(e)))}function Ae(e,t){return we(e)||be(t),Number(e)}function ke(e,t,n){return Ae(e?.[t]??ye(n),n)}function xe(e,t){return void 0!==t&&t.length>0?t[0]:e}var Se=(e,t)=>({factory:n=>{let l=ke(n,0,e);return n=>("number"!=typeof n&&ve(e,n),t(n,l))},arity:[1,1]}),Te={eq:{factory:(e,t)=>{let n=e?.[0]??ye("eq"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(we(n)||be("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??ye("ne"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(we(n)||be("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Se("lt",(e,t)=>e<t),le:Se("le",(e,t)=>e<=t),gt:Se("gt",(e,t)=>e>t),ge:Se("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ne=!1;function Oe(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function je(e){return 0===e.length?null:(Ne||(Ne=!0,me(Te)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,r=pe.get(l);if(typeof r<"u")return r;let i=de.get(e);void 0===i&&function(e,t){he.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),w(501,[e],e,t)}(e,de.keys());let[s,o]=i.arity;t.length<s&&w(601,[e,s,t.length]),t.length>o&&w(602,[e,o,t.length]);let a=i.factory(t,n);return pe.set(l,a),a}(e.Hn,e.args,e.literals)))}var Ce=Symbol.for("wcstack.trustedTypes.policy");function Me(){let e=globalThis[Ce];return null!==e&&"object"==typeof e?e:null}function Pe(e){globalThis[Ce]=e}function Ee(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function We(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Me(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Ie=Symbol.for("wcstack.state.view-transition-naming"),Re=new WeakSet;function De(){let e=S("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Le=new WeakMap,qe=e=>e.customElementRegistry??customElements;function ze(e,t,n,l,r,i=!1){let s=n.localName;if(!s.includes("-"))return r(null);let o=qe(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>ze(e,t,n,l,r,!0));let a=()=>{let e=o.get(s);o.upgrade(n),r(e?function(e){if(Le.has(e))return Le.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,ho:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Le.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==l&&!l.b||function(e,t,n){let l=n;null!==t&&(t.Nt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(o.whenDefined(s),l,()=>{try{a()}catch(l){He(e,l,t,n)}e.we()})}function Ue(t,n,l,r,i=n.o,s,o,a){let u=a.properties.get(r)??null,c=a.inputs.has(r),f=t.Vt;f&&null===u&&!c&&w(38,[r]);let h=n.K;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&w(39,[h,r]),"connect"===n.G&&null===u&&w(40,[r]);let d=f&&null!==u&&!c,p=new Ye(t,_e,l,r,i,s,o,n.N,void 0);p.M=n.M,lt(t,p,!d),null!==u&&!n.ro&&l.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.ho||e.detail?.(l,r,i)),(!p.An||!Object.is(i,p.value))&&(i=Oe(p.M,i),null===p.N&&(p.value=i),t.P(p.o,p.r,i,u.ho,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.Ue(p);else if("element"===m||"auto"===m){let e=()=>{if(null!==o&&!o.b)return;if("auto"===m&&void 0!==t.v(p.o,p.r))return void(d||t.Ue(p));let e=l[r];null===p.N&&(p.value=e),t.P(p.o,p.r,e,!1,!0)};"connect"!==n.G||l.isConnected?e():Promise.resolve().then(e)}return p}function Fe(e,t,n){w(e,[t.localName,n])}var Ve=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),_e=11,Be=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],He=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Rt,l,Be[n.i]),Ke=Symbol();function Je(e,t,n){let l=t.K;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.U:Ke}var Ye=class{constructor(e,t,n,l,r,i,s,o,a,u=null){this.te=!1,this.M=null,this.An=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=r,this.r=i,this.Tn=s,this.N=o,this.value=a,this.D=u}on(){return Be[this.i]}apply(){if(null!==this.D)return void this.D.$t();let e=Oe(this.N,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===_e||8===this.i||Ee(this.name)))return;if(this.value===Ke)return void(this.value=e);let t=this.a;if(this.i!==_e)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Xe(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Oe(this.M,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),r=n.v(this.o,this.r),i=Array.isArray(r)?r:[],s=i.includes(l);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==l):[...i,l]}else e=Oe(this.M,t[this.name]),this.value=NaN;n.P(this.o,this.r,e,!1,!0)}},Ge=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Xe(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ge(n)?t[n]="innerHTML"===n?We(l):null==l?"":String(l):Ee(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=We(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Qe]=[n,l])));case 8:return void(t.innerHTML=We(l));case 2:return null!=l&&"boolean"!=typeof l&&w(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Qe=Symbol();function Ze(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Qe];void 0!==n&&(t[n[0]]=n[1])}var et=class{constructor(e,t,n,l){this.b=!0,this.ye=null,this.c=null,this.Nt=null,this.Fn=null,this.r=e,this.at=t,this.j=n,this.O=l}Qo(e,t){let n=t.target,l=this.O,r=[],i=null;for(let t of l.ce){if(t.name!==e)continue;let s=l.On[t.a],o=ht(null===this.j?this.at:this.j[s[0]],s,1);o.contains(n)&&(o!==i&&r.unshift([]),r[0].push(t),i=o)}for(let e of r){for(let n of e)n.Pn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.j?this.at:this.j[this.j.length-1]}Re(){let e=this.Fn;return(null===e?null:e.Cn(this.at))??this.at}insertBefore(e,t){let n=this.s;for(let l=this.Re();;){let r=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=r}}bo(){null===this.j?this.at.remove():dt(this.Re(),this.s)}Te(e){if(this.b=!1,null!==this.Nt)for(let e of this.Nt)e();let t=this.ye;if(null!==t)for(let n=0;n<t.length;n++)e.Nn(t[n]);if(null!==this.c)for(let e of this.c)e.Te()}},tt=class extends et{constructor(e,t,n,l){super(e,t,n,l),this.wo=0,this.V=null,this.pe=0===l.Ye.length?null:new Array(2*l.Ye.length)}vo(e,t){let n=this.V??=new Array(this.O.Ye.length),l=n[t];if(void 0===l){let r=this.O.Ye[t],i=this.pe;l=n[t]=new Ye(e,r.i,i[2*t],r.name,r.o,this.r,this,r.N,i[2*t+1])}return l}uo(e,t){let n=this.O.Ye;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.vo(e,l))}Te(e){let t=this.r;t.x===this&&(t.x=null),super.Te(e)}};function nt(e,t,n,l){let r=ne(n,t.n);try{return e.He(r,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===r?e.oe.get(t):r.c.get(t)}}function lt(e,t,n){n&&e.nr(t);let l=t.Tn;null!==l&&(l.ye??=[]).push(t)}var rt=null;function it(){let e=rt;return rt=null,e}var st=-1;function ot(t,n,l,r,i=null){let s,o=n.On,a=n.build,u=n.So,c=null,f=e.Ie?.(n,null===r?i:r.S,null!==r),h=!f&&n.In,d=f?document.createDocumentFragment():(h?n.root:n.ln).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=ht(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==r?(p=m=new tt(l,s,c,n),null===r.map?l.x=m:r.map.set(l,m)):p=new et(l,s,c,n),st>=0&&function(e,t,n,l){let r=null;if(null===t)r=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===r;e++)1===t[e].nodeType&&(r=t[e]);let i=r?.style;if(null===r||void 0===i||Re.has(r))return;let s=globalThis[Ie]??={counter:0,assigned:0,warned:!1};s.assigned>=l?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${$(25,[l])}`)):(Re.add(r),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==r?"row":"branch",st),n.ce.length>0){let e=t.Kn;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.sr,y=t.Be,b=n.lr?u.slice(0,o.length):u,v=null===m?null:m.pe;if(null!==v){let e=n.Ye;for(let t=0;t<e.length;t++)v[2*t]=b[e[t].a],v[2*t+1]=e[t].U}for(let e=0;e<g.length;e++){let n=g[e],r=b[n.a],i=n.F;if(i>=0&&null!==v){let e=m.V?.[i];if(void 0!==e){e.te=!1,t.Ue(e);continue}try{let e=Oe(n.N,t.read(n.o,l));e!==n.U&&(Xe(n.i,r,n.name,e),v[2*i+1]=e),null!==y&&t.po(n.o,l)}catch(e){t.xt(e,m.vo(t,i))}continue}switch(n.i){case 6:{let e=new ft(t,n.O,nt(t,n.o,l,r),r);(p.c??=[]).push(e),r===s&&(p.Fn=e),e.$t();break}case 7:{let e=ut(t,n.q.map(e=>({O:e.O,o:e.o,N:e.N,S:b[e.a]})),l,p);(p.c??=[]).push(e),r===s&&(p.Fn=e);break}default:try{at(t,n,r,l,p)}catch(e){He(t,e,n,r)}}}return rt=p,d}function at(t,n,l,r,i){let s=l;switch(n.i){case 5:return void function(e,t,n,l,r){let i=n.Pn,s=e=>i(e,l);if(n.et){let l=e.ao(n.name),r=t[l];t[l]=void 0===r?s:e=>{r(e),s(e)},n.Ne&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.yo&&null!==r&&(r.Nt??=[]).push(()=>t.removeEventListener(n.name,s))}(t,l,n,r,i);case 12:return void ze(t,n,s,i,l=>function(t,n,l,r,i){let s=n.name,o=t.command(n.Rt.slice(9)),a=null===i?e.or?.(l,s):null;a||(null===i&&Fe(1202,l,`command.${s}`),i.commands.has(s)||w(1203,[l.localName,s]));let u=new WeakRef(l),c=o.subscribe((...e)=>{let t=u.deref();if(void 0!==t)return t.isConnected?a?a(t,e):t[s](...e):void 0;c()});null!==r&&(r.Nt??=[]).push(c)}(t,n,s,i,l));case 13:return void ze(t,n,s,i,e=>function(e,t,n,l,r){let i=t.name;null===r&&Fe(1202,n,`eventToken.${i}`);let s=r.properties.get(i);void 0===s&&w(1204,[n.localName,i]);let o=t.Rt;n.addEventListener(s.event,n=>{t.Tt&&n.preventDefault(),t.At&&n.stopPropagation();try{e.Zo(o,n,l)}catch(e){console.error(e)}})}(t,n,s,r,e))}let o=n.o,a=ne(r,o.n);if(14===n.i)return void ze(t,n,s,i,e=>function(e,t,n,l,r,i){null===i&&Fe(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.go?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:l;Ue(e,{...t,K:null,G:null},n,o,s,a,r,i)}}(t,n,s,a,i,e));if(n.Ne&&1===n.i)return void ze(t,n,s,i,l=>function(t,n,l,r,i,s){if(null!==s)return void Ue(t,n,l,n.name,n.o,r,i,s);let o=new Ye(t,1,l,n.name,n.o,r,i,n.N,Je(t,n,r));o.M=n.M,!e.ar?.(o,n.ro)&&(lt(t,o,!0),t.Ue(o))}(t,n,s,a,i,l));let u=new Ye(t,n.i,l,n.name,o,a,i,n.N,Je(t,n,a));u.M=n.M,lt(t,u,!0),t.Ue(u),null!==n.Pt&&l.addEventListener(n.Pt,()=>u.ir())}function ut(e,t,n,l){let r=new ct(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Ye(e,7,s.S,"if",t,ne(n,t.n),l,null,void 0,r);lt(e,o,!0),null===l&&r.ue.push(o),i??=o}return e.Ue(i),r}var ct=class{constructor(e,t,n){this.b=!0,this.C=null,this.y=-1,this.ue=[],this.engine=e,this.q=t,this.r=n}Cn(e){return null!==this.C&&this.q[this.y].S===e?this.C.Re():null}$t(){let e=this.engine,t=-1;for(let n=0;n<this.q.length;n++){let l=this.q[n];if(null===l.o||Oe(l.N,e.read(l.o,ne(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(st=De(),null!==this.C&&(this.C.bo(),this.C.Te(e),this.C=null),this.y=t,t>=0)){let n=this.q[t],l=ot(e,n.O,this.r,null,n.S);this.C=it();let r=n.S.parentNode;r.insertBefore(l,n.S),Ze(r)}}Te(){this.b=!1;for(let e of this.ue)this.engine.Nn(e);null!==this.C&&this.C.Te(this.engine)}},ft=class{constructor(e,t,n,l){this.b=!0,this.Ae=[],this.engine=e,this.O=t,this.l=n,this.S=l,null===n.x?(n.x=this,this.map=null):((n.L??=[]).push(this),this.map=new Map)}Cn(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ft(e){return null===this.map?e.x:this.map.get(e)??null}jt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Te(this.engine)}$t(){let e=this.engine,t=this.l.f,n=this.Ae;st=De();let l=t.length,r=n.length,i=this.S,s=i.parentNode;if(0===l){if(r>0){let e=n[0].Re(),t=n[r-1].s,l=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){l=null;break}l.push(n)}null!==l?s.replaceChildren(...l):dt(e,t);for(let e=0;e<r;e++)this.jt(n[e])}return void(this.Ae=[])}let o=new Array(l),a=0;for(;a<l&&a<r&&this.Ft(t[a])===n[a];)o[a]=n[a],a++;let u=r-1,c=l-1;for(;u>=a&&c>=a&&this.Ft(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],l=t.r;l.b&&this.Ft(l)===t?t.wo=e:(t.bo(),this.jt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(r>0)for(let e=0;e<n;e++){let n=this.Ft(t[a+e]);null!==n&&n.b?(u[e]=n.wo,f=!0):u[e]=-1}let h=c+1<l?o[c+1].Re():i;if(f){let l=function(e){let t=e.length,n=new Uint8Array(t),l=new Int32Array(t).fill(-1),r=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=r.length;for(;i<s;){let n=i+s>>1;e[r[n]]<t?i=n+1:s=n}i>0&&(l[n]=r[i-1]),r[i]=n}let i=r.length>0?r[r.length-1]:-1;for(;i>=0;)n[i]=1,i=l[i];return n}(u),r=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Ft(n);null!==u&&u.b?0===l[i]&&u.insertBefore(s,r):(s.insertBefore(ot(e,this.O,n,this),r),u=it()),o[a+i]=u,r=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(ot(e,this.O,t[l],this)),o[l]=it();s.insertBefore(n,h)}}this.Ae=o,Ze(s)}Te(){this.b=!1;let e=this.l;if(e.x===this)e.x=null;else if(null!==e.L){let t=e.L.indexOf(this);t>=0&&e.L.splice(t,1),0===e.L.length&&(e.L=null)}for(let e of this.Ae)e.Te(this.engine);this.map?.clear()}};function ht(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let l=t[n];l>0;l--)e=e.nextSibling}return e}function dt(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var pt=()=>ie.bindAttributeName;function mt(){return{a:0,i:1,name:"",o:null,N:null,U:c,Pn:null,O:null,q:null,M:null,Pt:null,Ne:!1,K:null,G:null,ro:!1,Tt:!1,At:!1,Rt:null,go:null,F:-1,et:!1,yo:!1}}var gt=["state","element","auto","none"],yt=["call","connect"],bt="$command.";function vt(t,n,l){E.test(n)&&(null===l&&w(1401,[n,Number(n.slice(1))]),n=`${l.t}.*.${n}`);let r=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&w(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,l)),i=null===l?0:l.n+1;r.n>i&&w(1401,[r.t,r.n,i]);for(let e=1;e<=r.n;e++){let t=e===i?l:l.h[e];r.h[e]!==t&&w(1403,[r.t,r.h[e].t,t.t])}return e.ko?.(t,r),r}var $t=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),wt=e=>8===e.i||$t(e)||1===e.i&&Ge(e.name);function At(e){w(202,[e])}function kt(e,t,n,l,r){let i=fe(t).map(t=>function(e,t,n,l,r){let i=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,r=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||w(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&w(33,[i,n]),null!==(o?l:r)&&w(34,[i]),(o?gt:yt).includes(s)||w(35,[i,s]),o?l=s:r=s}return{ro:t.includes("ro"),Tt:t.includes("prevent"),At:t.includes("stop"),event:n?n.slice(2):null,K:l,G:r}}(e,t.rn),s=l.localName.includes("-"),o=t.xe,a=t.Qe;if("event"===t.w){if(null!==i.K&&"none"!==i.K&&w(36),"eventToken"===o[0])return{...mt(),a:r,i:13,name:o.slice(1).join("."),Rt:a,Ne:s,Tt:i.Tt,At:i.At};let n=a.startsWith(bt)?a.slice(9):null,{Tt:l,At:u}=i,c=t.$e.slice(2),f=t.rn.includes("direct"),h=!f&&Ve.has(c);return h&&e.ao(c),{...mt(),a:r,i:5,name:c,et:h,Ne:s,yo:f,Pn(t,r){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.er(n,t,r);else{let n=e.tr(a,t,r);Q(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.w)return{...mt(),a:r,i:14,o:vt(e,a,n),Ne:s};if("command"===o[0]&&o.length>1)return a.startsWith(bt)||w(1201,[t.$e,a]),{...mt(),a:r,i:12,name:o.slice(1).join("."),Rt:a,Ne:s};let u=vt(e,a,n),c={...mt(),a:r,i:1,name:t.$e,o:u,N:je(t.Ze),M:je(t.M),ro:i.ro,K:i.K,G:i.G};if("radio"===t.w||"checkbox"===t.w)return("element"===i.K||"auto"===i.K)&&w(37,[t.w,i.K]),c.i="radio"===t.w?9:10,i.ro||(c.Pt=i.event??"input"),c;if(o.length>1){let e=o.slice(1).join("."),t=o[0];if("class"===t||"attr"===t||"style"===t)return c.K=null,c.name=e,"class"===t?(c.i=2,c.U=l.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,c}return"html"===t.$e?(c.i=8,c):(c.name="text"===t.$e?"textContent":t.$e,c.Ne=s&&!Ee(c.name),!s&&!i.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(l,c.name)&&(c.Pt=i.event??("select"===l.localName?"change":"input")),c)}(e,t,n,l,r));for(let e=0;e<i.length;e++)14===i[e].i&&(i[e].go=i.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return i}var xt=/\{\{([\s\S]+?)\}\}/g;function St(e){let t=e.data,n=[],l=0;xt.lastIndex=0;for(let r=xt.exec(t);null!==r;r=xt.exec(t)){let i=xt.lastIndex-r[0].length;i>l&&e.before(t.slice(l,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({a:s,cr:r[1].trim()}),l=xt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function Tt(e,t,n,l){let r=function(e){return{$e:"textContent",xe:["textContent"],rn:[],M:[],...V(e),w:"text"}}(t);return{...mt(),a:l,i:0,o:vt(e,r.Qe,n),N:je(r.Ze),U:""}}function Nt(e){let t=e.getAttribute(pt());if(null===t)return null;let n=fe(t)[0];return void 0===n||"for"!==n.w&&"if"!==n.w&&"elseif"!==n.w&&"else"!==n.w?null:n}var Ot=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function jt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.w?null:vt(e,l.Qe,n),N:"else"===l.w?null:je(l.Ze)}),r=[l(t,Nt(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=Nt(e);if(null===t||"elseif"!==t.w&&"else"!==t.w||(r.push(l(e,t)),"else"===t.w))break}return r}var Ct=new WeakSet;function Mt(t,n,l,r,i,s,o,a){let u=(n,l)=>{let i=document.createComment(l);return n.replaceWith(i),r&&e.Dn?.(t,i,n),i},c=n=>{for(let f=0;f<n.length;f++){let h=n[f];if(null!==h.parentNode)if(1===h.nodeType){let n=h,a=n.localName;if(n.hasAttribute(pt()+"-ignore"))continue;if(r){if("script"===a||"style"===a||Ct.has(n))continue;if(Ct.add(n),a===ie.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?Nt(n):null;if(null!==f){if("for"===f.w){let e=vt(t,f.Qe,l),r=Wt(t,n,e,!0);i(u(n,ie.commentForPrefix),e,r)}else"if"===f.w?s(jt(t,n,l).map((e,n)=>({O:Wt(t,e.el,l,!1),o:e.o,N:e.N,S:u(e.el,Ot(n,e))}))):At(f.w);continue}let d=n.getAttribute(pt()),p=null===d?null:kt(t,d,l,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some(wt)&&!e.Eo?.(n);try{r&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!r&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t._t&&h.data.includes("{{")&&!Ct.has(h))for(let{a:e,cr:t}of St(h))a(e,t);else if(8===h.nodeType){let e=Pt.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),a(t,e[1])}}}};c(n)}var Pt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Et=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Wt(e,t,n,l){let r=document.importNode(Et(t),!0),i=[],s=[],o=e=>i.push(e)-1;Mt(e,[...r.childNodes],n,!1,(e,t,n)=>{s.push({...mt(),a:o(e),i:6,o:t,O:n})},e=>{let t=e.map(e=>({a:o(e.S),O:e.O,o:e.o,N:e.N}));s.push({...mt(),a:t[0].a,i:7,q:t})},(e,t)=>{let n=o(e);for(let e of t)$t(e)&&w(203,[e.name]),e.a=n;s.push(...t),e.removeAttribute(pt())},(t,l)=>{s.push(Tt(e,l,n,o(t)))}),Lt(r,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let l=t;l!==e;l=l.parentNode){let e=0;for(let t=l.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(r,e)),u=1===r.childNodes.length&&8!==r.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of s){if(5===e.i&&e.et&&!e.Ne&&!It(i[e.a],r)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Rt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.q)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:r,root:u?r.firstChild:null,On:a,build:g,ce:d,sr:p,In:u,lr:c,So:[],Ye:f}}function It(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function Rt(e){if(null!==e.K)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.Ne&&null===e.Pt;default:return!1}}var Dt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Lt(e,t,n){for(let l=e.firstChild;null!==l;){let e=l.nextSibling;3===l.nodeType?n&&!t.has(l)&&""===l.data.trim()&&l.remove():1===l.nodeType&&Lt(l,t,Dt.has(l.localName)),l=e}}var qt=new WeakMap;function zt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,qt.set(t,e),Ft(e,[...n.childNodes]),e.qe()}function Ut(e,t,n){try{let l="template"===t.localName?Nt(t):null;null!==l&&!n&&w(204,[l.w]),Ft(e,[t])}catch(e){console.error(e)}e.qe()}function Ft(t,n){Mt(t,n,null,!0,(e,n,l)=>{new ft(t,l,nt(t,n,null,e),e).$t()},e=>{ut(t,e,null,null)},(n,l)=>{e.Dn?.(t,n,l);for(let e of l)at(t,e,n,null,null)},(n,l)=>{e.Dn?.(t,n,l),at(t,Tt(t,l,null,0),n,null,null)})}var Vt=Symbol.for("wcstack.binder"),_t=Symbol.for("wcstack.binder.pending"),Bt=Symbol.for("wcstack.binder.taken");var Ht=new Map;function Kt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=qt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ht.set(e,t):Ut(n,e,t?.range)}function Jt(){let e=[...Ht];Ht.clear();for(let[t,n]of e)Kt(t,n);!function(){let e=function(){let e=globalThis[Vt];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;let t=function(){let e=globalThis,t=e[_t];return void 0===t&&(t=[],e[_t]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Bt];return void 0===t&&(t=new WeakSet,e[Bt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Yt=class{constructor(){this.name="dirty",this.Z=(e,t)=>{if(0===e.n){let t=e.Y;return t!==c&&t!==f&&(e.Y=f,!0)}let n=null===t?null:t.yt;if(null===n)return!1;let l=n[e.F];return l!==c&&l!==f&&(n[e.F]=f,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.Et(t,n),e.xn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Dt;if(null!==n)for(let l of n)l.n===t.l.n?e.it(l,t,this.Z):e.en(t,l,t=>e.it(l,t,this.Z))}ve(t,n,l){this.Z(n,l),e.ke?.(t,n,l),t.Et(n,l),t.xn(n,l,this.Z)}Ko(e,t,n){let l=0===t.n;if(!l&&null===n)return;let r=l?null:n.yt??=new Array(e.je).fill(c),i=null===r?t.Y:r[t.F];if(i!==c&&i!==f&&i!==h&&(null===r||t.F in r))return i;i=h;try{return i=e.Uo(t,null===r?null:n)}finally{null===r?t.Y=i:r[t.F]=i}}Xt(e){e.yt=null}vt(e){for(let t of e.I.all())null!==t.getter&&(0===t.n?t.Y===f&&(t.Y=h):e.nn(t.h[t.n],e=>{let n=e.yt;null!==n&&n[t.F]===f&&(n[t.F]=h)}))}},Gt=0,Xt=new WeakMap;function Qt(e,t=e.getRootNode()){Xt.set(t,[...Xt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Zt(e){let t=Xt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Xt.get(e)!==t?Zt(e):Promise.reject(l.errors[0]):void 0)}var en=typeof HTMLElement>"u"?class{}:HTMLElement,tn=class extends en{constructor(){super(),this.engine=null,this.Mn=!1,this.ze=!1,this.U=null,this.Xe=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.$o=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Zt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Mn){if(null!==this.Xe)return void this.Xe.Ge();Qt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!qt.has(n)&&qt.set(n,t),Jt(),e.element?.(t,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.Mn=!0;let t=this.getRootNode(),n=e.ct?.(this,t);if(n)return this.Xe=n,!n.No&&this.parentNode instanceof ShadowRoot&&Qt(this),void(void 0===n.Ct?this.Ro():n.Ct()).then(e=>(this.loaded=!0,n.start(e,()=>this.To()))).then(()=>{this.an(),this.cn()},e=>this.xt(e,n.No));this.start(t),Qt(this)}disconnectedCallback(){if(null!==this.Xe)return void this.Xe.jn();let t=this.engine;if(null===t)return;let n=t.root;qt.get(n)===t&&qt.delete(n),Qt(this,n),this.xo("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.ze&&w(14),this.loaded)this.Xe.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.U=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&w(15),"readonly"===e&&n.Le++;try{t(n.proxy)}finally{"readonly"===e&&n.Le--}}async createStateAsync(e,t){let n=this.engine;null===n&&w(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let l=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&w(8),l(...e)):l},set(){w(8)}}))}async Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${$(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||w(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let l=this.querySelector('script[type="module"]');return null!==l?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let l="function"==typeof URL.createObjectURL,r=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Gt}`);try{return(await(import(r))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?$(42):$(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(r)}}(l):null!==this.U?Promise.resolve(this.U):new Promise(e=>{this.un=e})}async start(t){try{let n=t.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||n?.hasAttribute("data-wc-definition"))&&a("scopes","<wcs-state>");let l=await this.Ro(),r=o(l);if(r&&await r,this.getRootNode()!==t)return this.U=l,this.Mn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=qt.get(t)?.element;i?.isConnected&&(i.V||i.Xe)&&w(47);let s=new re(l,new Yt);s.element=this,this.engine=s,e.element?.(s,"mounting"),zt(s,t),Jt(),s.$n(),this.To(),await s.Ee("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.cn()}catch(e){this.ze=!this.V,this.xt(e)}}To(){this.V=!0,this.an()}xt(e,t){this.qe(this.V?50:49,e),this.an(),t?this.cn():this.$o(e)}qe(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${$(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.qe(t,e))}},nn=[];function ln(){return(nn=nn.filter(e=>e.deref())).map(e=>e.deref())}function rn(t,n){t&&function(e){let t=ie,n=ie.tagNames,l=Object.entries(e).filter(([,e])=>void 0!==e),r=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of l){let l=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof l||Array.isArray(n)!==Array.isArray(l))&&w(44,["bootstrapState",e])}for(let[e,t]of r)(!Object.hasOwn(n,e)||"string"!=typeof t)&&w(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of l)"tagNames"!==e&&(t[e]=n);for(let[e,t]of r)n[e]=t}(t),function(t=customElements){(function(){let e=globalThis;void 0===e[Vt]&&(e[Vt]={protocol:"wcs-binder",version:1,bind:Kt})})(),ln().includes(t)||nn.push(new WeakRef(t));let n=ie.tagNames.state;void 0===t.get(n)&&t.define(n,class extends tn{}),e.Ao?.(t)}(n)}var sn,on=e=>Zt(e),an=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},un="en";function cn(){if(ie.locale!==sn){sn=ie.locale;try{un=Intl.getCanonicalLocales(sn)[0]}catch{console.warn(`[@wcstack/state] ${$(48,[sn])}`),un="en"}}return un}var fn=["full","long","medium","short"];function hn(e,t){let[n,l]=e??[];return void 0===l&&void 0!==n&&fn.includes(n)&&([n,l]=[void 0,n]),void 0!==l&&!fn.includes(l)&&function(e,t){w(52,[e,t])}(t,l),[n,l]}var{eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,falsy:$n,truthy:wn,boolean:An}=Te,kn={toFixed:{factory:e=>{let t=Ae(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ve("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ve("locale",e),e.toLocaleString(t??cn()))},arity:[0,1]},upper:{factory:an(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:an(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:an(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:an(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:an(e=>{let t=[ke(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(Ae(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:an(e=>{let t=ke(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:an(e=>{let t=ke(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:an(e=>{let t=ke(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:an(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:an(e=>{let t=ke(e,0,"truncate"),n=e?.[1]??"…";return e=>{let l=String(e);return l.length<=t?l:l.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||w(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ve("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ve("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ve("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=Ae(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ve("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:an(e=>{let t=e?.[0]??ye("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=hn(e,"date"),l=n&&{dateStyle:n};return e=>(e instanceof Date||$e("date",e),e.toLocaleDateString(t??cn(),l))},arity:[0,2]},time:{factory:e=>{let[t,n]=hn(e,"time"),l=n&&{timeStyle:n};return e=>(e instanceof Date||$e("time",e),e.toLocaleTimeString(t??cn(),l))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=hn(e,"datetime"),l=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||$e("datetime",e),e.toLocaleString(t??cn(),l))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||$e("ymd",e);let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),r=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||$e("hms",e);let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),r=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,add:Se("add",(e,t)=>e+t),sub:Se("sub",(e,t)=>e-t),mul:Se("mul",(e,t)=>e*t),div:Se("div",(e,t)=>e/t),mod:Se("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ve("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ke(e,0,"clamp"),n=ke(e,1,"clamp");return e=>("number"!=typeof e&&ve("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:$n,truthy:wn,defaults:{factory:(e,t)=>{let n=xe(e?.[0]??ye("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=xe(e?.[0]??ye("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:An,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??ye("currency"),n=e?.[1],l={style:"currency",currency:t};try{new Intl.NumberFormat("en",l);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){w(53,[e])}(t)}return e=>("number"!=typeof e&&ve("currency",e),e.toLocaleString(n??cn(),l))},arity:[1,2]}},xn=Object.fromEntries(Object.entries(kn).filter(([e])=>!(e in Te))),Sn=!1,Tn={name:"formats",install:function(){Sn||(Sn=!0,me(kn))}};function Nn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let l=new Array(t.length+1),r=new Array(t.length+1);for(let e=0;e<=t.length;e++)l[e]=e;for(let n=1;n<=e.length;n++){r[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;r[i]=Math.min(l[i]+1,r[i-1]+1,l[i-1]+s)}for(let e=0;e<=t.length;e++)l[e]=r[e]}return l[t.length]}function On(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,r=3;for(let e of t){let t=Nn(n,e.toLowerCase(),2);t<r&&(l=e,r=t)}return null!==l?` Did you mean "${l}"?`:""}var jn=" Validate statically: npx @wcstack/lint <file>.",Cn=["","binding-syntax","template-syntax","binding-path-missing","binding-type-expectation","filter-unknown","filter-arity","getter-cycle","getter-depth-exceeded","index-arity","index-param-range","recursion-unsupported","token-misconfigured","token-undeclared","wildcard-rank","spread-no-bindable","declaration-alias","name-alias"],Mn=e=>{let t=Cn[e/100|0];return t?`[wcs/${t}] `:""},Pn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],En=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Wn=["","","class.","attr.","style."],In=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Rn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Dn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,l)=>`binding "${n?(Wn[l]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Rn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Rn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${En(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${En(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&Pn.includes(t)?" 4.0 moved it to the state's $behavior.":""}`,45:()=>"a re-set state may not change $behavior: create the element again.",47:()=>'a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount="path"> (v1\'s name="…" is gone: read the mounted state by its path).',48:e=>`the locale "${e}" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use "en".`,46:()=>'$features must be an array of add-on names (["temporal", "formats"]).',49:(e,...t)=>`${In(e,t)} failed to initialize.`,50:(e,...t)=>`${In(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${In(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,l)=>`${e}("${t}") takes ${n} index(es), got ${l}.`,902:(e,t,n,l)=>`${e}("${t}") takes at most ${n} index(es), got ${l}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function Ln(e,t){let n=Dn[e];return void 0===n?`${Mn(e)}#${e} ${t.join(" ")}`:Mn(e)+n(...t)}var qn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),zn=[[/no loop level in common with the context/,"; pass indexes ([] for all)."],[/"([^"#]+)#([^"]*)" is not a filter name: a modifier list .* comes before the input filters/,' — write "<property>#$2|$1".'],[/\[wcs\/recursion-unsupported\]/," It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll — and only when the state declares a $recursion anchor."],[/must be single binding/,' Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).'],[/\[wcs\/wildcard-rank\] .* needs \d+ enclosing/,' Wrap it in that many "for" templates, or use $resolve(path, indexes) to name the row explicitly.'],[/\[wcs\/wildcard-rank\] .* ranges over the rows of/,' A "*" in a binding is the row of the loop around it: read a row of another list in a getter, with $resolve(path, indexes).'],[/\[wcs\/binding-type-expectation\] class\.([^ ]+)/,' Write "class.$1: path|truthy" to toggle on truthiness.'],[/path segments — the limit/," Every prefix of a path is interned, so the cost grows with the square of the depth."],[/\[wcs\/index-arity\] \$resolve/,' $resolve takes one index per "*"; $getAll / $setAll take at most that many (fewer expands the rest).'],[/"([^"#]+)#[^"]*" is not a filter name: "#" cannot appear in one/,' Modifiers belong on the left side of the binding, before the ":" — write "$1" here.']],Un={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Fn(e,t,n){let l=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(Un,e)?Un[e]:null;return null===t?null:` "${e}" was renamed "${t}" in 3.2 and removed in 4.0 — write "${t}".`}(t):null)??(void 0!==t&&void 0!==n?On(t,n):"");for(let[t,n]of zn){let r=t.exec(e);null!==r&&(l+=n.replace(/\$(\d)/g,(e,t)=>r[Number(t)]))}let r=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==r&&(l+=` — write "${r[1]}#${r[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?l+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':he.some(ge)||(l+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&qn.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=jn),l}var Vn=new WeakMap,_n=new WeakMap,Bn=new WeakSet,Hn=new WeakSet;function Kn(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 Jn(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"$"!==e[0]&&"constructor"!==e&&t.add(e);return[...t]}function Yn(e,t){let n=[];for(let e=t;null!==e;e=e.d)n.unshift(e);let l=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==Kn(e.target,t.t)?.get?t:e.I.Mt(m(t.t).o)}(e,t);return n.some(e=>null!=l(e)?.getter)?null:Gn(e,n,0,e.target,l)}function Gn(e,t,n,l,r){for(;n<t.length;n++){let i=t[n];if(null===l||"object"!=typeof l)return null;if("*"===i.s){if(!Array.isArray(l)||0===l.length)return null;let i=null;for(let s of l){let l=Gn(e,t,n+1,s,r);if(null===l)return null;if(null===i)i=l;else if(l.seg===i.seg)for(let e of l.names)i.names.includes(e)||i.names.push(e)}return i}if(Array.isArray(l)&&/^\d+$/.test(i.s)){if(Number(i.s)>=l.length)return null;l=l[Number(i.s)];continue}let s=Kn(l,i.s);if(void 0===s&&null===i.d&&e.vt.has(i.s))return null;if(void 0===s){let t=Jn(l),n=r(i.d);for(let l of e.I.all())l.d===n&&null!==l.getter&&t.push(l.s);return{seg:i.s,names:t}}if(void 0!==s.get||void 0!==s.set)return null;l=s.value}return null}function Xn(t){Bn.has(t)||(Bn.add(t),setTimeout(()=>function(t){Bn.delete(t);let n=Vn.get(t);if(void 0===n)return;let l=_n.get(t);void 0===l&&_n.set(t,l=new Set);for(let[r,i]of n){if(l.has(r))continue;l.add(r);let n=Yn(t,r);if(null===n)continue;let s=[...t.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Hn.has(e)&&(r.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==s){l.delete(r),s.initializePromise.then(()=>{Hn.add(s),Xn(t)});continue}let[o,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];e.st?.(t,{type:"state:path-unresolved",source:i?"watch":"binding",path:r.t,missingSegment:n.seg});let u=t.I.Mt(m(r.t).o),c="";if(void 0!==u&&u!==r&&null!==u.getter){let e=u.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.h[t].t.length+2)}`);c=` The getter "${u.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}console.warn(`[@wcstack/state] [wcs/${o}] ${a} "${r.t}" does not resolve on the state tree: "${n.seg}" is not declared.${On(n.seg,n.names)}${c} Updates to this path will be silently dropped.${jn}`)}}(t),0))}function Qn(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.d)return;let l=Vn.get(e);void 0===l&&Vn.set(e,l=new Map),l.has(t)||l.set(t,n),Xn(e)}var Zn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),el=!1;function tl(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(el||!(t instanceof TypeError)||!Ee(l)||!("trustedTypes"in globalThis))return;el=!0;let r="function"==typeof Me()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${l}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${r}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:l})}var nl=new WeakMap;function ll(e,t,n){let l=e[t],r=void 0===n?void 0===l?null:`the event carried no detail (undefined) while element.${t} is ${typeof l}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==l&&"object"==typeof l?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof l}`;if(null===r)return;let i=nl.get(e);void 0===i&&nl.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${r}. With no getter, state receives e.detail as-is. Dispatch the value itself as detail, or declare getter (e.g. (e) => e.detail.${t}, or (e) => e.target.${t}) on that wcBindable property.`))}var rl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],il={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},sl={name:"diagnostics",install(){e.jo=Fn,e.Lo=Ln,e.ko=Qn,e.detail=ll,e.ze=t(e.ze,tl);let l=e.fe;e.fe=(e,t)=>{(function(e){void 0!==e.$scan&&w(1);for(let[t,n]of rl)void 0!==e[t]&&w(1601,[t,n])})(t),l?.(e,t),function(e){let t=e.$recursion;if(null===t||"object"!=typeof t)return;let n=Object.entries(t);if(1!==n.length||"string"!=typeof n[0][1])return;let[l,r]=n[0];if(!l.endsWith(".*")||!r.endsWith(".*"))return;let i=l.slice(0,-2),s=r.slice(0,-2),o=`.${r}`,a=`${i}.**`,u=Jn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>v(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${s}`||e.startsWith(`.${s}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${s}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${Zn(o)})+$`).test(t.slice(0,t.length-e.length))&&f(`"${a}${e}" and "${a}${t}" expand to the same concrete path at different depths (they differ by whole repetitions of "${r}"). Rename one of them.`);let t=new RegExp(`^${Zn(l)}(?:${Zn(o)})*${Zn(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&f(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(t),function(e){_n.delete(e),Vn.has(e)&&Xn(e)}(e)},e.ot=n(r,e.ot,(e,t)=>Object.hasOwn(il,t)?w(1701,[t,il[t]]):void 0)}},ol={},al=/\.\d/,ul=new Set(Object.getOwnPropertyNames(Object.prototype)),cl=0,fl=!1,hl=null,dl=()=>{fl=!1,cl++};function pl(){if(null===hl)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=dl,e.port1.unref?.(),hl=()=>e.port2.postMessage(0)}else hl=()=>setTimeout(dl,0);return fl||(fl=!0,hl()),cl}function ml(e,t){let n=new Set,l=[e];for(;l.length>0;){let e=l.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let l of t)if(n.ee(l)&&(n.n===l.n||!(l.n<e.n&&e.h[l.n+1].ee(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var gl=class{constructor(e,t){this.active=!1,this.Pe=new Map,this.early=[],this.n=0,this.Po=-1,this.Ln=new Set,this.Ke=null,this.engine=e,this.De=t}ur(){let e=this.engine;this.Pe.clear();let t=this.early;this.early=[];for(let t of this.De)t.getter=null!==t.p.getter||t.p.se,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(ol,e.v(t.p,null)):this.Bn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[l,r,i,s]of t)if((null===r||r.b)&&Object.is(e.v(l,r),s)){n.add(l);for(let e of this.De)e.p===l&&this.ut(e,r,i,!0)}for(let e of this.De)e.getter&&0===e.p.n&&!this.Pe.has(e)&&ml(yl(e.p),n)&&this.ut(e,null,void 0,!0);this.Pe.size>0&&e.we()}prime(t,n){try{n()}catch(n){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,n),e.st?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}Fo(){this.active=!1,this.Pe.clear(),this.early=[]}Bn(e,t,n,l){let r=this.engine.He(n,e.h[t]);for(let n of r.f)t===e.n?l(n):this.Bn(e,t+1,n,l)}ut(e,t,n,l){let r=this.Pe.get(e);void 0===r&&this.Pe.set(e,r=new Map);let i=r.get(t);void 0===i?r.set(t,[n,this.n,l]):(i[1]<this.n&&(i[1]=this.n),i[2]||=l)}Se(e,t,n,l,r,i){if(this.active){(this.Ke??=new Set).add(e);for(let i of this.De){let s=i.p;s.n!==e.n||!s.ee(e)||this.ut(i,t,i.getter?i.s.get(t??ol):s===e&&r&&this.engine.Wt&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}else i&&this.early.push([e,t,n,l])}ke(e,t){if(this.active)for(let n of this.De)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===e.n&&n.p.ee(e)&&this.ut(n,t,n.s.get(t??ol),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.De){let r=l.p;if(!(r.n<e.n||r.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(r.n===e.n?this.ut(l,t,void 0,!0):this.Bn(r,e.n+1,t,e=>this.ut(l,e,void 0,!0)))}}}Ce(){let t=this.Ke;if(this.Ke=null,!this.active||0===this.Pe.size)return;let n=this.Pe;this.Pe=new Map;let l=this.engine,r=[];for(let i of this.De){let s=n.get(i);if(void 0===s)continue;let o,a=[...s].filter(([e])=>null===e||e.b);a.length>1&&a.sort((e,t)=>bl(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=l.u;this.n=u+1,l.Fe++;try{if(a=l.v(i.p,n),i.getter&&(i.s.set(n??ol,a),Object.is(a,s)&&(al.test(i.t)||null!==n&&!c&&!(o??=null!==t&&ml(yl(i.p),t)))))continue;if(u>32){r.includes(i.t)||r.push(i.t);continue}l.u=n,e.st?.(l,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(l.proxy,a,s,...l.H(n))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),e.st?.(l,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{l.u=h,this.n=0,l.Fe--}}}r.length>0&&this.Oo(r)}Oo(t){let n=pl();n!==this.Po&&(this.Po=n,this.Ln.clear());let l=t.filter(e=>!this.Ln.has(e));if(0!==l.length){for(let e of l)this.Ln.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.st?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:l})}}};function yl(e){for(;null===e.getter&&null!==e.d;)e=e.d;return e}function bl(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ae)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ae)l.unshift(e.y);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var vl="$streamStatus",$l="$streamError",wl=new Set(Object.getOwnPropertyNames(Object.prototype)),Al=!1;function kl(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 void 0!==e.get||void 0!==e.set||"function"==typeof e.value}return!1}var xl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.B=n}set(e,t,n){Al=!0;try{this.engine.P(this.engine.o(`${e}.${t}`),null,n)}finally{Al=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.dt=!1,e.J?.abort(),e.J=null}pr(){for(let e of this.entries)e.dt=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(vl,e.name,"idle")}ke(e){let t=this.B.n;for(let n of this.entries)n.g===e&&(n.n=n.dt?Math.max(n.n,t):t,n.dt=!0)}Ce(){let e=this.engine,t=this.B,n=[];for(let l of this.entries){if(!l.dt)continue;let r=l.n;if(l.dt=!1,r>32)n.push(l.name),l.g.Y=h;else{t.n=r+1,e.Fe++;try{this.start(l,!1)}finally{e.Fe--,t.n=0}}}n.length>0&&t.Oo(n)}start(e,t){let n,l=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let r=e.g;r.getter=e.args;let i=r.Q.slice();Sl(r);try{n=l.read(r,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&v(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${vl}.${e}`||n.t===`${$l}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Sl(r);for(let e of i)e.Wn(r);if(r.Y=h,t)throw n;return this.set($l,e.name,n),void this.set(vl,e.name,"error")}}let r=new AbortController;e.J=r,l.P(l.o(e.name),null,e.U),this.set($l,e.name,null),this.set(vl,e.name,"active"),this.mr(e,r,n)}async mr(e,t,n){let l=this.engine,r=t.signal,i=()=>!r.aborted&&e.J===t,s=l.o(e.name),o=this.B.n,a=pl(),u=e=>{pl()===a&&(this.B.n=o);try{e()}finally{this.B.n=0}},c=e.U;try{let t=await e.source(n,r);if(!i())return;let o=t=>{c=void 0!==e.Co?e.Co(c,t):t,u(()=>l.P(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(r.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!i())return;if(t.done)break;o(t.value)}}else{if(null===t||"function"!=typeof t?.[Symbol.asyncIterator])throw new TypeError(`$stream "${e.name}": source must return an async iterable or a ReadableStream`);{let e=t[Symbol.asyncIterator]();for(r.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.J=null,u(()=>this.set(vl,e.name,"done"))}catch(n){if(!i())return;e.J=null,t.abort(),u(()=>{this.set($l,e.name,n),this.set(vl,e.name,"error")})}}};function Sl(e){for(let t of e.Q){let n=t._.indexOf(e);n>=0&&t._.splice(n,1),t.mt.delete(e)}e.Q.length=0,e.Y=c}var Tl=new WeakMap;function Nl(e){let t=Tl.get(e);return t?.target===e.target?t:void 0}function Ol(t,n){let l=new gl(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$watch must be an object mapping paths to handler functions.");let l=[];for(let r of Object.keys(n)){let i=n[r];(""===r||"$"===r[0]||r.includes("@")||ul.has(r))&&v(`$watch path "${r}" is not a path of the state tree.`),"function"!=typeof i&&v(`$watch entry "${r}" must be a function.`);let s=t.o(r);e.ko?.(t,s,!0),l.push({t:r,p:s,handler:i,getter:!1,s:new WeakMap})}return l}(t,n.$watch)),r=new xl(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$stream must be an object mapping stream names to definitions.");let l=[],r={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||wl.has(s))&&v(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&v(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&v(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&v(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${s}": args must be a function.`),kl(t,s)&&v(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),r[s]="idle",i[s]=null,l.push({name:s,source:a,Co:u,U:f,J:null,dt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[vl]=r,t[$l]=i,l}(t,n),l),i=Tl.get(t);void 0!==i&&(i.B.Fo(),i.Ot.fr()),Tl.set(t,{B:l,Ot:r,Ge:i?.Ge??!1,target:n})}function jl(e,t){let n=Tl.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Ge="connected"===t),n.target===e.target)){if("disconnected"===t)return n.B.Fo(),void n.Ot.pr();n.Ge&&(n.B.ur(),n.Ot.dr())}}var Cl=["$streamStatus","$streamError"],Ml={name:"temporal",install(){e.fe=t(e.fe,Ol),e.element=t(e.element,jl),e.Se=t(e.Se,(e,t,n,l,r,i,s)=>Nl(e)?.B.Se(t,n,l,r,i,s)),e.ke=t(e.ke,(e,t,n)=>{let l=Nl(e);void 0!==l&&(l.B.ke(t,n),l.Ot.ke(t))}),e.Qt=t(e.Qt,(e,t,n)=>Nl(e)?.B.Qt(t,n)),e.Ce=t(e.Ce,e=>{let t=Nl(e);void 0!==t&&(t.B.Ce(),t.Ot.Ce())}),e.ot=n(r,e.ot,(e,t)=>{let n=t.split(".",1)[0];if(Cl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Oe=n(l,e.Oe,(e,t)=>(!Al&&36===t.t.charCodeAt(0)&&Cl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Pl=new WeakMap,El=!1,Wl=/^(?!prototype$)[^\d.*$][^.*]*$/;function Il(e,t){let n=t.$listKeys,l=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let r=n[t];"string"==typeof r?l.set(e.o(t),e=>e[r]):"function"==typeof r?l.set(e.o(t),r):v(`$listKeys "${t}" must be a field name or a function.`)}}Pl.set(t,l)}function Rl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Dl(e,t,n){let l=new Map;for(let r of t){Rl(r)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(r);null==t&&v(`$listKeys "${e}": a row has no key.`),l.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),l.set(t,r)}return l}function Ll(e,t,n,l){if(El||!Array.isArray(l))return!1;let r=Pl.get(e.target)?.get(t);if(void 0===r)return!1;let i=e.rt(t,n);if(!Array.isArray(i)||i===l)return!1;let s=Dl(t.t,i,r);Dl(t.t,l,r);let o=[],a=[],u=i.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=s.get(r(t));o.push(n??t),void 0!==n&&a.push([e,n,t]),o[e]!==i[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let l of Object.keys(n))Object.is(t[l],n[l])||c.push([e,l,n[l]]);for(let l of Object.keys(t))!(l in n)&&null!==t[l]&&c.push([e,l,null])}if(u&&0===c.length)return!0;if(!u){El=!0;try{e.P(t,n,o)}finally{El=!1}}if(c.length>0){let l=e.He(0===t.n?null:n,t);for(let[n,r,i]of c){if("__proto__"===r)continue;let s=l.f[n],o=Wl.test(r)?e.o(`${t.t}.*.${r}`):null;null===o?.getter?e.P(o,s,i):(s.$[r]=i,e.P(e.o(`${t.t}.*`),s,s.$,!0))}}return!0}var ql={name:"list-keys",install(){e.fe=t(e.fe,Il),e.Oe=n(l,e.Oe,Ll)}},zl=new WeakMap,Ul=new WeakMap,Fl="will not graft: the root state failed to initialize.",Vl=new WeakSet,_l=new WeakMap,Bl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Hl=["$commandTokens","$eventTokens","$on","$errorCallback"],Kl=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,Jl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Yl=e=>e?.element?.isConnected?e:void 0;function Gl(e){let t=Ul.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function Xl(e,t){let n=Ul.get(t);if(Ul.delete(t),Array.isArray(n))for(let t of n)tr(t,e)}function Ql(e){let t=zl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function Zl(e,t){console.error(`${Kl(e.t)} ${t}`),Ql(e),e.Je?.(),e.Je=null}function er(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 tr(e,t){if(Vl.has(t))return Zl(e,"will not graft: its component is wired to its host.");let n=e.state,l=t.target,r=e.t.split("."),i=l;for(let e of r)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return Zl(e,`will not graft: the root state already has "${e.t}".`);let s=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,l){if("symbol"==typeof l)return;if(36!==l.charCodeAt(0))return e.proxy[n(l)];let r=e.proxy[l];return"$eqPath"===l?(e,t)=>r(n(e),n(t)):Jl.has(l)&&"function"==typeof r?(e,...t)=>r(n(e),...t):r},set:(t,l,r)=>"symbol"!=typeof l&&(e.proxy[n(l)]=r,!0)})}(t,e.t);e.chroot=s;let o={},a={},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:l,set:r,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==l||void 0!==r)a[`${e.t}.${n}`]={get:l&&function(){return l.call(s)},set:r&&function(e){r.call(s,e)}};else{if("$"===n[0])continue;if("function"==typeof i){let t=i.bind(s);a[`${e.t}.${n}`]={get:()=>t}}else o[n]=i}}if(void 0===i){for(let e=1;e<r.length;e++){let n=t.o(r.slice(0,e).join("."));null==t.rt(n,null)&&t.P(n,null,{})}t.P(t.o(e.t),null,o)}t.to(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=_l.get(t);void 0===c&&_l.set(t,c=[]),c.push(e),e.el.isConnected&&er(e,"$connectedCallback"),e.Je?.(),e.Je=null}function nr(e,t){let n=Ul.get(e);if(Array.isArray(n))for(let e of n)Zl(e,Fl);Ul.set(e,t)}var lr=new WeakMap;function rr(e,t){let n=e.getAttribute("mount");if(null===n)return null;let l={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(ie.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=zl.get(t);void 0===e&&zl.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==l&&(null===i.engine?i.el.isConnected:Yl(i.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=Ul.get(t);Array.isArray(e)&&Ul.set(t,e.filter(e=>e!==i)),i.Je?.(),i.Je=null}e.set(n,l)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{No:!0,start(e){if(null!==r)return Zl(l,r);if(zl.get(t).get(n)===l){for(let t of Bl)if(void 0!==e[t])return Zl(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of Hl)void 0!==e[t]&&console.warn(`${Kl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Je=e;let n=Yl(qt.get(t)),r=Ul.get(t);void 0!==n?tr(l,n):Gl(t)?Zl(l,Fl):Ul.set(t,[...Array.isArray(r)?r:[],l])})}},Ge(){null!==l.engine&&er(l,"$connectedCallback")},jn(){null!==l.engine&&er(l,"$disconnectedCallback")},reset(){v(`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 ir=new WeakMap,sr=new WeakMap;function or(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||v(`${t} must be an array of state member names.`);let l=new Set;for(let e of n)("string"!=typeof e||""===e)&&v(`${t} entries must be non-empty strings.`),"$"===e[0]&&v(`${t} entry "${e}": internal ($) members are never exposed.`),l.has(e)&&v(`${t} entry "${e}" is duplicated.`),l.add(e);return n}function ar(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let l=document.createDocumentFragment();for(let e of[...t.childNodes])l.appendChild(e.cloneNode(!0));let r=t.mode;return{start(t){e.hasAttribute("bind-component")&&v("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,l){e.includes("-")||v(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&v(`DCC: <${e}> is already defined.`);let r=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}(l),i=or(l,"$bindables"),s=or(l,"$commands");for(let e of i){let t=r.get(e);void 0===t&&v(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&v(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of s){let t=r.get(e);void 0===t&&v(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&v(`$commands entry "${e}" is not a method: list it in $bindables.`)}let o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=l=>{if(a.has(l))return a.get(l);if(l.hasAttribute("data-wc-definition"))return null;let r=l.attachShadow({mode:n});r.appendChild(t.cloneNode(!0));let s=r.querySelector(ie.tagNames.state);return a.set(l,s),ir.set(l,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.tagNames.state}>: no change events.`),s},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,l]of t)n.proxy[e]=l});class d extends HTMLElement{static{this.wcBindable=0===i.length&&0===s.length?null:{protocol:"wc-bindable",version:1,properties:i.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:i.map(e=>({name:e})),...0===s.length?{}:{commands:s.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of r)"function"==typeof t.value?Object.defineProperty(d.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(d.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=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,l,r,t)},Ge(){},jn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var ur=new WeakMap,cr=new WeakSet,fr=new WeakMap,hr=new WeakMap,dr="data-wcs-wired",pr=new WeakMap,mr=new WeakMap,gr=new WeakMap,yr=0,br=new Set,vr={},$r=["$watch","$stream","$renderedCallback"],wr=e=>e.split(".",1)[0];function Ar(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function kr(e,t){let n=e.a,l=wr(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(dr);else if(!Sr(n,l)){let e=n.getAttribute(dr)?.split(" ")??[];e.includes(l)||n.setAttribute(dr,[...e,l].join(" "))}pr.get(n)?.me===l&&v(`<${n.localName}>.${l} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let r=ur.get(n);void 0===r&&ur.set(n,r=[]),r.push(e),t&&cr.add(e);let i=fr.get(n);return void 0===i&&fr.set(n,i=new Map),i.has(l)||i.set(l,n[l]),hr.get(n)?.(),!1}function xr(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Sr(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Tr(e){let t=e.parentElement;for(;null!==t&&!xr(t);)t=t.parentElement;let n=qt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Kt(e):Ut(n,e))}var Nr=new Set;function Or(e,t){Nr.has(e)||(Nr.add(e),console.warn(`[@wcstack/state] ${t}`))}var jr=(e,t)=>t in e.state;function Cr(e,t){let n=Mr(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Mr(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 Pr(e,t,n){if(null!==n.getter)return;let l,r=e.host,i=r.engine,s=wr(n.t),o=r.entries.find(e=>e.E===n.t);if(void 0===o&&null!==n.d)return function(e,t){let n,l=t.d;for(;null!==l&&void 0===(n=e.ft.get(l));)l=l.d;if(null===l||void 0===n)return;let r=e.R,i=e.host.engine,s=i.o(n.p.t+t.t.slice(l.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=Er(e,o.r);return 0===t.n?n:(i.resolve(Ar(s.t,[...i.H(n),...r.H(ne(r.u,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.ie&&(t.ie=n=>{let l=a();Wr(e,o.e,()=>i.P(s,l,n)),e.dn=t}),t.n>0&&(t.F=r.je++),e.ft.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.E!==s?jr(r,s):Cr(r,s))return;l=o.he}else{if(null===t||null!==n.d||"$"===s[0]||jr(r,s))return;o=t,l=i.o(`${t.he.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(l,Er(e,a)),n.ie=t=>{Wr(e,u,()=>i.P(l,a,t)),e.dn=n},e.ft.set(n,{e:o,p:l,r:a})}function Er(e,t){return null!==t&&!t.b&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Wr(e,t,n){let l=br.has(e.R);br.add(e.R),e.from=t;try{n()}finally{l||br.delete(e.R),e.from=null}}var Ir=(e,t)=>t||!br.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Rr(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,yr+=t?1:-1;let n=e.host.engine,l=gr.get(n);void 0===l&&gr.set(n,l=new Map);for(let n of e.pe){let e=l.get(n.e.he);void 0===e&&l.set(n.e.he,e=new Map);let r=e.get(n.e.r);void 0===r&&e.set(n.e.r,r=new Set),t?r.add(n):(r.delete(n),0===r.size&&e.delete(n.e.r))}let r=e.host.entries.find(e=>""===e.E);if(void 0!==r){null===e.re&&function(e,t){let n=e.host,l=n.engine;e.re=new Map;let r=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(r.has(s))continue;r.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=wr(s);if(s!==a&&!jr(n,a))continue;let u=l.o(`${t.he.t}.${s}`);if(null===u.getter)qr(l,u,t.he);else if(!Dr.has(u.getter))continue;e.re.set(u,e.R.o(s))}}(e,r);for(let l of e.re.keys())t&&null===l.getter&&qr(n,l,r.he),n.A.ve(n,l,r.r);e.re.size>0&&n.we(),t&&function(e,t){let n=e.host.engine;for(let[l,r]of e.re){let i=n.v(l.d,t.r);if(null===i||"object"!=typeof i||!(l.s in i))continue;let s=e.host.el.localName;Or(`${s}|${l.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.me}.${r.t} is exported at "${l.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,r)}}var Dr=new WeakSet;function Lr(e,t,n,l){let r=gr.get(e)?.get(t)?.get(n);if(void 0===r)return null;let i=null;for(let e of r)""!==e.e.E||!0!==e.m.re?.has(l)||e.m===i||(null!==i&&v(`[wcs/mount-export-ambiguous] "${l.t}" is exported by two mounted components on the same instance: <${i.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.`),i=e.m);return i}function qr(e,t,n){let l=t.d,r=t.s,i=()=>{let t=e.read(l,e.u);return null!==t&&"object"==typeof t&&r in t?t:null};t.getter=()=>{let l=i();if(null!==l)return l[r];let s=Lr(e,n,e.u,t);return null===s?void 0:s.R.read(s.re.get(t),null)},Dr.add(t.getter),t.ie=s=>{let o=null===i()?Lr(e,n,e.u,t):null;if(null===o){let t=e.read(l,e.u);return void(null!==t&&"object"==typeof t&&(t[r]=s))}let a=o.re.get(t);void 0===Mr(o.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${o.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),o.R.P(a,null,s)},t.n>0&&(t.F=e.je++)}function zr(t,n,l,r,i,s){if(null!==n.getter)return t.A.ve(t,n,l),void t.we();if("*"===n.s){if(null===l)return;if(l.$=l.l.T[l.y],t.A.Xt(l),null!==l.c)for(let e of l.c.values())t.G(e)}else t.En(n,l);e.Se?.(t,n,l,r,i,s),t.Ke(n,l)}function Ur(e){let t=e.m.R;for(let[n,l]of e.m.ft)l.e===e.e&&(0===n.n?t.A.ve(t,n,null):t.nn(n.h[n.n],e=>t.A.ve(t,n,e)));t.we()}function Fr(e,t,n,l,r,i,s){let o=n.t.slice(t.t.length);if(""===o)return Ur(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=o.slice(1);let e=wr(a);if("$"===e[0]||jr(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ne(l,e).y);c.resolve(Ar(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||zr(c,h,d,r,i,s)}function Vr(e,t,n,l,r,i,s){if(0===yr)return;let o=br.has(e);br.add(e);try{let o=mr.get(e);!s&&void 0!==o&&o.fn&&!br.has(o.host.engine)&&function(e,t,n,l,r,i){let s,o=t;for(;null!==o&&void 0===(s=e.ft.get(o));)o=o.d;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.dn===t)return void(e.dn=null);if(null!==s.r&&!s.r.b)return;let u=[...a.H(s.r),...e.R.H(n)];a.resolve(Ar(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Wr(e,s.e,()=>zr(a,c,f,l,r,i))}(o,t,n,l,r,i),s&&void 0!==o&&o.fn&&null!==o.re&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[r,i]of e.re)i===t&&(l.A.ve(l,r,n.r),l.we())}(o,t);let a=gr.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.ee(e)){let a=o.get(0===e.n?null:ne(n,e.n));if(void 0!==a)for(let o of[...a])Ir(o,s)&&Fr(o,e,t,n,l,r,i)}else if(e.ee(t))for(let[e,l]of[...o])if(0===t.n||ne(e,t.n)===n)for(let e of[...l])Ir(e,s)&&Ur(e)}finally{o||br.delete(e)}}async function _r(t,n,l,r,i){if(r===vr)return;let s=o(r);s&&await s;let a=pr.get(n);a.engine&&r.$recursion&&v(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.C;if(null!==u&&u.el!==t&&u.el.isConnected&&v(`<${n.localName}> already has a connected <${ie.tagNames.state} bind-component="${a.me}">.`),null!==u&&Rr(u,!1),null!==u&&function(e,t,n){let l=e.R,r=`[${ie.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(r)||null!==e.querySelector(r)),s=new Set,o=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&s.add(e)},a=(e,t)=>{for(let n=e.Cn(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of l.ue.values())for(let t of e)if(null===t.D)o(t.a);else for(let e of t.D.q)a(t.D,e.S);for(let e of l.oe.values())for(let t of[e.x,...e.L??[]])null!==t&&a(t,t.S);for(let t of e.j)t.parentNode===n&&i(t)&&s.add(t);if(0===s.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!s.has(n)&&!e.j.includes(n)&&(i(n)||l._t&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(u,t,l))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.R.element=t,t.engine=e.R,e.j=e.j.filter(e=>e.parentNode===n),t.isConnected?await Br(e,l):l()}(u,t,l,i);let c=new re(r,new Yt);c.element=t,t.engine=c,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 l=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof l&&"constructor"!==t&&n.set(l,null)}let l=(t,n,l)=>Reflect.apply(t,e.proxy,l);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:l})),t}}(c,r);let f={el:t,j:[],R:c,host:a,pe:[],ft:new Map,fn:!1,dn:null,from:null,re:null};for(let e of a.entries)f.pe.push({m:f,e});a.C=f,mr.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.R,n=e.host,l=n.engine,r=n.el.localName,i=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=wr(e.E);jr(n,t)&&(e.E!==t||Cr(n,t))&&Or(`${r}.${e.E}`,`[wcs/mount-own-key-shadow] <${r}>: "${n.me}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=l.v(i.he,i.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.E===t)&&Or(`${r}.${t}`,`[wcs/mount-own-key-shadow] <${r}>: its own "${t}" hides "${i.he.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=$r.filter(e=>void 0!==n.state[e]);s.length>0&&Or(`${r}.${n.me}$`,`[wcs/mount-dollar-declaration] <${r}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.nt;t.nt=n=>{Pr(e,i,n),o.call(t,n)};let a=[...t.I.all()];for(let t of a)Pr(e,i,t);for(let e of a)o.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=mr.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.b))return!1;return!0})(e)&&u.call(t)}}(f),Rr(f,!0),Vl.add(c),Xl(c,l));let d=e.hr?.(l);zt(c,l),d?.(),f.j=[...l.childNodes],Jt(),h&&c.$n(),Object.defineProperty(n,a.me,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.me);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),t.isConnected?(await c.Ee("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):Rr(f,!1)}async function Br(t,n){Rr(t,!0);for(let e of t.pe)Ur(e);n?.(),!t.broken&&(await t.R.Ee("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.R,"connected"))}function Hr(t,n){let l=t.getAttribute("bind-component");if(null===l)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=qt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){nr(t,e);for(let e of lr.get(t)??[])e()}}),null}(t,n);let r=t.parentNode,i=r instanceof ShadowRoot,s=i?r.host:r instanceof Element?r:null,o=()=>{let e=null===s?void 0:pr.get(s)?.C;return e?.el===t?e:null},a=e=>{throw i&&nr(r,t),e},u=!1;return{Ct:()=>(null!==s&&s.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"]'))&&v(`<${ie.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await qe(n).whenDefined(r);let i=pr.get(n);if(void 0!==i)return i.me!==t&&v(`<${r}> already has a <${ie.tagNames.state} bind-component="${i.me}">.`),i.state;let s=()=>(ur.get(n)??[]).filter(e=>wr(e.name)===t),o=Sr(n,t);if(o&&0===s().length&&Tr(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(dr)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,i)=>{hr.set(n,l),e=function(e,t){Gl(e)&&t();let n=lr.get(e)??new Set;return lr.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}hr.delete(n);let a=s(),u=fr.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.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 (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),vr}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===l)&&v(`<${r}> maps "${e.name}" twice.`);let i=l.split(".").indexOf("*");if(i>=0){let n=l.split(".").slice(0,i).join(".");v(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}f.push({E:l,he:e.o,r:e.r,ro:cr.has(e)}),e.engine.Nn(e),""!==l&&delete n[e.name]}let h=0===a.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}(c):c;return pr.set(n,i={el:n,me:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,C:null}),h}(t,l,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await _r(t,s,i?r:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Ge(){let e=o();null!==e?Br(e).catch(e=>console.error(e)):u?Promise.resolve().then(()=>{if(t.parentNode===r)return _r(t,s,i?r:s,pr.get(s).state,()=>{})}).catch(e=>console.error(e)):hr.has(s)&&Tr(s)},jn(){let t=o();null!==t&&(Rr(t,!1),!t.broken&&(t.R.Ee("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.R,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${s?.localName}>.${l} instead.`)}}}var Kr={name:"scopes",install(){e.ct=n(i,e.ct,rr),e.ct=n(i,e.ct,ar),e.ct=n(i,e.ct,Hr),e.ar=kr,e.Eo=xr,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=_l.get(e)??[];if("disconnected"===t)for(let e of n)Ql(e);else if("reset"!==t&&Yl(qt.get(e.root))===e){Xl(e,e.root);for(let e of n)zl.get(e.root).has(e.t)||zl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();Xl(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:ir.get(n);void 0!==l&&sr.set(e,{host:n,def:l})}(e,n)}),e.Se=t(e.Se,(e,t,n,l,r,i)=>{(function(e,t,n,l){let r=sr.get(e);if(void 0===r)return;let i=t.t.split(".",1)[0];if(!r.def.bindables.includes(i))return;let s=l&&t.t===i;r.host.dispatchEvent(new CustomEvent(`${r.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,r,i),Vr(e,t,n,l,r,i,!1)}),e.ke=t(e.ke,(e,t,n)=>Vr(e,t,n,void 0,void 0,!1,!0)),e.Oe=n(l,e.Oe,(e,t,n,l,r)=>(function(e,t){let n=_l.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let l,r=mr.get(e);if(void 0===r)return!1;for(let e=t;null!==e&&void 0===l;e=e.d)l=r.ft.get(e);if(void 0===l)return!1;let i=l.e;return!((null===i.r||i.r.b)&&!i.ro)&&(!!n||(Er(r,i.r),void v(`[wcs/mount-readonly] <${r.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${r.host.me}${""===i.E?"":`.${i.E}`}#ro: ${i.he.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,r)));let r=e.fe;e.fe=(e,t)=>{let n=_l.get(e);void 0!==n&&n.length>0&&v(`re-setting a root state with grafted volumes (${n.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=gr.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&v("re-setting a root state with mounted components is not supported: they read its data."),r?.(e,t)}}},Jr="$recursion",Yr=new WeakMap,Gr=new WeakSet,Xr=new WeakSet,Qr=0,Zr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ei=e=>`[wcs/recursion-${e}]`;function ti(e,t){let n=n=>v(`${ei("declaration-invalid")} ${Jr} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${ei("declaration-invalid")} ${Jr} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var ni=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function li(e,t){let n=`${e.l}.**`,l=t.slice(n.length);return(!t.startsWith(n)||""!==l&&"."!==l[0]||l.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function ri(e,t,n){let l=li(e,t),r=function(e,t){for(let n=t;null!==n;n=n.l.ae){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===r&&v(`[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.`),ni(e,r.k)+l}function ii(e,t,n){let l=new Set,r=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${ei("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),r.has(e)&&v(`${ei("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),i+1>128&&v(`${ei("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${i+1} (the limit is 128).`),r.add(e),0)),s=(r,o)=>{for(let a of r){n(o,a);let r=e.o(`${ni(t,o)}.${t.key}`),u=e.read(r,a);i(u,r.t,o+1)&&(l.add(u),s(e.He(a,r).f,o+1),l.delete(u))}},o=e.o(t.l),a=e.read(o,null);i(a,t.l,0)&&(l.add(a),s(e.He(null,o).f,0))}function si(e,t){let n=function(e){let t=e[Jr],n=[],l=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!l.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),l.add(e);if(void 0===t)return n.length>0&&F(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${ei("declaration-invalid")} ${Jr} must be an object mapping one anchor path to its repeating sub-path.`);let r=Object.entries(t);1!==r.length&&v(`${ei("declaration-invalid")} ${Jr} must declare exactly one anchor (it declares ${r.length}).`);let i=ti("anchor",r[0][0]),s=ti("repeat",r[0][1]),o=i.slice(0,-2),a=s.slice(0,-2),u=`.${s}`,c=new Map,f=[],h=`${o}.**`;for(let[e,t]of n){let n=e.slice(h.length);(!e.startsWith(h)||""!==n&&"."!==n[0]||n.includes("**"))&&v(`[wcs/recursion-anchor] "${e}": a recursive key is "${h}" followed by a path (the anchor is "${i}").`),(""===n||n.split(".").slice(1).some(e=>""===e))&&v(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&v(`${ei("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${Zr(i)}((?:${Zr(u)})*)${Zr(n)}$`),n])}return{l:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${Zr(o)}((?:${Zr(`.*.${a}`)})*)$`)}}(t),l=Yr.has(e);null!==n?(l||Qr++,Yr.set(e,n),Xr.add(e),Gr.has(e)||function(e){Gr.add(e);let t=e,n=t.nt;t.nt=l=>{let r=Yr.get(e);if(l.t.includes("**")){let t=e.I.Mt(l.t)===l;return void(Xr.has(e)||void 0===r&&t?l.getter=()=>F(l.t):t||n.call(e,l))}if(void 0!==r&&null===l.getter)for(let[e,n]of r.matchers)if(e.test(l.t)){l.getter=r.families.get(n),l.n>0&&(l.F=t.je++),r.owners.set(l,r.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let r=Yr.get(e);return l.call(e,void 0!==r&&t.includes("**")?ri(r,t,n):t,n)};let r=t.getAll;t.getAll=(n,l)=>{let i=Yr.get(e);if(void 0===i||!n.includes("**"))return r.call(e,n,l);if(void 0===l)return r.call(e,ri(i,n,t.u));(!Array.isArray(l)||l.length>0)&&v(`${ei("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=li(i,n),o=[];return ii(e,i,(t,n)=>{for(let l of r.call(e,ni(i,t)+s,e.H(n)))o.push(l)}),o};let i=t.yn;t.yn=(n,l,r,s)=>{let o=Yr.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,l,r,s);Array.isArray(l)||w(9,[n]),l.length>0&&v(`${ei("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof r||!0===s?.spread)&&v(`${ei("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Le>0&&w(8);let a=li(o,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(o.step);)u=u.slice(o.step.length);let c=o.key.split(".");(""===u||u===`.${o.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${ei("structural-write")} "${n}" writes the recursion structure itself (a node, its "${o.key}" list or that list's length, or an object on the way to it).`);for(let e of o.families.keys()){let t=e;for(;t.startsWith(o.step);)t=t.slice(o.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${ei("readonly")} "${n}" writes into the recursive getter "${o.l}.**${e}".`)}let f=[];ii(e,o,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=i.call(e,ni(o,t)+a,e.H(n),r);return h}}(e)):l&&(Yr.delete(e),Qr--)}function oi(e,t){if(0===Qr)return!1;let n=Yr.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.d){let l=n.owners.get(e);void 0!==l&&v(`${ei("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var ai={name:"recursion",install(){e.fe=t(e.fe,si),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){Xr.delete(e)}(e)}),e.Oe=n(l,e.Oe,oi)}},ui="4.3.0",ci=e=>e.split(".").slice(0,2).join("."),fi=class extends en{static find(e){return e.querySelector?.(ie.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 ci(this.version)===ci(ui)}};function hi(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends fi{})}var di=()=>ie.tagNames.ssr,pi=Symbol.for("wcstack.ssr.snapshotBuilder"),mi=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),gi=e=>document.createComment(e),yi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,bi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),vi=new WeakMap,$i=new WeakMap,wi=new WeakMap,Ai=new WeakSet,ki=new WeakMap;function xi(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Si(e,t,...n){for(let n of Array.from(e.attributes))t.setAttribute(n.name,n.value);return(t.content??t).append(...n),t}var Ti=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Ni(e,t,n,l){let r=gi(null===l?"wcs-[":`wcs-[:${l}`),i=gi("wcs-]");n.length>0&&n[0].Re().before(...xi(e,t)),t.after(r);for(let e of n)null===l&&e.Re().before(gi("wcs-|"));let s=n.length>0?(e=>null===e.j?e.at:e.j[e.j.length-1])(n[n.length-1]):r;(Ti(s)??s).after(i);for(let e of xi(r,i))Ai.add(e)}function Oi(e){if(e instanceof ft){Ni(e.S,e.S,e.Ae,null);for(let t of e.Ae)ji(t);return}let t=e.C;null!==t&&(Ni(e.q[e.y].S,e.q[e.q.length-1].S,[t],e.y),ji(t))}function ji(e){if(null!==e.c)for(let t of e.c)Oi(t)}var Ci=new Set(["script","style","template","textarea","title"]),Mi="data-wcs-raw",Pi=e=>Ci.has(e.localName)||e.localName===di();function Ei(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(gi("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(gi("wcs-s")):1===t.nodeType&&!Pi(t)&&Ei(t)}var Wi=0;function Ii(e,t){let n=e.getRootNode(),l=[t];for(let e of $i.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let r=new Map;for(let e of l){let t=vi.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.x&&n.set(t.x.S,t.x),null!==t.L)for(let e of t.L)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.D)for(let t of e.D.q)n.set(t.S,e.D);let l=new Set;for(let[e,i]of t){r.set(e,i);let t=n.get(e);void 0!==t&&!l.has(t)&&e.isConnected&&(l.add(t),Oi(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=wi.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ai.has(e)||1===e.nodeType&&t.has(e)&&zi(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Pi(e.parentNode)?ki.has(e):t.has(n)&&bi(n,"wcs-t:"))&&(ki.has(e)||t.get(e)!==e.data):!t.has(e))&&l.push(e)}for(let e of l)e.remove()}let n=Array.from(e.childNodes);Pi(e)&&n.some(e=>ki.has(e))&&e.setAttribute(Mi,n.map(e=>ki.has(e)?`{{ ${ki.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Ei(9===n.nodeType?n.body:n);let i=document.createElement(di());i.setAttribute("version",ui);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 n of Object.keys(e)){if("$"===n[0])continue;let l=Object.getOwnPropertyDescriptor(e,n);void 0!==l.get||void 0!==l.set||"function"==typeof l.value||(t[n]=l.value)}return t}(t.target)),i.append(s);for(let[e,t]of r){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let l="svg"===n?.localName,r=`wcs-${l?"s":"t"}${Wi++}`;e.replaceWith(gi(`wcs-p:${r}`));let s=document.importNode(Et(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Si(e,document.createElement("template"),...e.childNodes));if(l){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=r,i.append(Si(t,o,s))}e.before(i)}function Ri(e){!function(e){if(null!==e.querySelector(ie.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=>ki.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(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===di())continue;let e=t.engine;null!=e&&Ii(t,e)}}var Di=Symbol.for("wcstack.state.ssr.impl"),Li=new Map,qi=new WeakMap,zi=t=>!0===e.Eo?.(t),Ui=e=>1===e.nodeType&&!Pi(e)&&!zi(e),Fi=e=>e.f.flat().concat(e.z??[]),Vi=e=>{for(let t of Fi(e))t.remove()};function _i(e,t,n){let l=/^wcs-\[(?::(\d+))?/.exec(e.data),r=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!yi(o,"wcs-]");){let e=o.nextSibling;if(yi(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];bi(o,"wcs-[")?e=_i(o,t,n):(n.push(o),Ui(o)&&Bi(o,t))}o=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:s,z:o??i.appendChild(gi("wcs-]"))},u=Fi(a);o=a.z.nextSibling;for(let e of u)n?.push(e),t&&Ct.add(e);return t&&null!==r?Li.set(r,a):Vi(a),o}function Bi(e,t){for(let n=e.firstChild;null!==n;)bi(n,"wcs-[")?n=_i(n,t):(Ui(n)&&Bi(n,t),n=n.nextSibling)}function Hi(e,t,n){let l=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=gi(`@@:${decodeURIComponent(e.slice(6))}`),n=r.nextSibling;for(;null!==n&&!yi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),r.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=r.parentNode,l="s"===e[10]?Si(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);l.removeAttribute("id"),t.replaceChild(l,r)}}}catch{}}else 1===r.nodeType&&!Pi(r)&&(zi(r)?qi.set(r,{ssr:t,Ie:n}):l(r))};l(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||Zi(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{bi(e,"wcs-[")?l++:yi(e,"wcs-]")&&--l<0&&(l=0,n=t+1)}),0===l)continue;let r=0;for(let l=t.firstChild;null!==l;l=l.nextSibling)if(bi(l,"wcs-["))r++;else if(yi(l,"wcs-]")&&0===r--){t.prepend(...e.slice(n));break}}}(e),Bi(e,n)}function Ki(t){let n=qi.get(t);if(void 0===n||(qi.delete(t),Hi(t,n.ssr,n.Ie),!n.Ie))return null;let l=e.Ie;return e.Ie=ns,()=>{e.Ie=l,Ji()}}function Ji(){for(let e of Li.values())Vi(e);Li.clear()}function Yi(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Gi(e,t,n,l){let r=null;for(let l of e){let e=l[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===r||e.length>r[n].length)&&(r=l)}let i=r?.[l];if(null==i)return null;let s=r[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function Xi(e,t,n){if(mi()){if(n instanceof Array){for(let e=n.length;e-- >0;)$t(n[e])&&n.splice(e,1);let e=t;if(n.some(wt))Ai.add(e);else if(e.localName.includes("-")&&!zi(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);wi.set(e,t)}return}if("string"==typeof n){if(ki.set(t,n),Pi(t.parentNode))return;let e=gi(`wcs-t:${encodeURIComponent(n)}`),l=gi("wcs-/t");return t.before(e),void t.after(l)}let l=vi.get(e);void 0===l&&vi.set(e,l=new Map),l.set(t,n);let r=t.getRootNode(),i=$i.get(r);return void 0===i&&$i.set(r,i=new Set),void i.add(e)}if("string"!=typeof n&&Li.size>0){let e=Li.get(n);void 0!==e&&(Li.delete(n),Li.set(t,e))}}var Qi=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),Zi=e=>3===e.nodeType&&""===e.data.trim(),es=e=>{let t=Li.get(e)?.z??e;return(Ti(t)??t).nextSibling};function ts(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.On;for(let l=0;l<n.length;l++){let r=n[l],i=e.ln,s=t[r[0]];for(let e=0;;){if(i=i.childNodes[r[e]],s?.nodeName!==i.nodeName)return!1;if(++e===r.length)break;s=(Ti(s)??s).firstChild;for(let t=r[e];t>0&&null!==s;t--)s=es(s)}e.So[l]=s}return!0}function ns(e,t,n){if(0===Li.size)return null;let l=t,r=0;if(!n){let e=ie.commentIfPrefix;if(!yi(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Qi(n)&&r++,!yi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Li.has(l)&&null!==n&&!yi(n,e)&&1!==n.nodeType;n=n.nextSibling)Qi(n)&&(l=n)}let i=Li.get(l);if(void 0===i)return null;if(!n&&i.branch!==r)return Li.delete(l),Vi(i),null;let s=i.f.shift();if(0===i.f.length&&Li.delete(l),i.z?.replaceWith(...xi(t,l)),i.z=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=Li.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.z;)e++;else Ti(s[e])===s[e+1]&&e++}if(!ts(e,o)){let n=(e.In?e.root:e.ln).cloneNode(!0);o=e.In?[n]:[...n.childNodes],ts(e,o),(s[0]??i.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var ls={name:"ssr",install(){e.Dn=Xi,e.hr=Ki;let n=e.element;e.element=(t,l)=>{"mounting"===l&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||mi())return;let l=n.previousElementSibling,r=l?.localName===di(),i=r?l.getAttribute("version"):null,s=null===i||ci(i)===ci(ui);if(s){let e=t,n=e.Ee;e.Ee=(e,l)=>"$connectedCallback"===e?void 0:n.call(t,e,l)}if(!r)return;let o=!s&&parseInt(i)<4,a=/^3\.(\d+)\.(\d+)$/.exec(i),u=null!==a&&(+a[1]-5||+a[2]-3)>=0;s||console.warn(`[@wcstack/state] <${di()} version="${i}"> does not match ${ui}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!u?" 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 c=s?l.querySelector('script[type="application/json"]'):null;if(null!==c){let e=JSON.parse(c.textContent||"{}"),n=t.target;for(let t of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(n,t);void 0!==l&&(void 0!==l.get||void 0!==l.set||"function"==typeof l.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${Mi}]`)))e.textContent=e.getAttribute(Mi),e.removeAttribute(Mi);let h=9===f.nodeType?f.body:f;queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),l=e.map(e=>e.selected),r=e.map(e=>e.hasAttribute("selected")),i=r.lastIndexOf(!0);i<0&&(i=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>l[t]!==r[t]):n.selectedIndex!==i)&&t.push([n,()=>e.forEach((e,t)=>e.selected=l[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),o?function(e,t,n){let l=new Map,r=e=>{let t=e.parentElement;for(;null!==t&&!zi(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=r(t),i=t.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of fe(t.getAttribute(ie.bindAttributeName)??"")){let t=l.Qe;l.xe[0]===i&&n.push([e?Gi(e,t,1,0):t,l.xe.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let l=r(e);if(null===l)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:Gi(l,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return l.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:Gi(l,i[2],2,1)??i[2]};for(let t of Yi(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!yi(l,`@@wcs-${e[1]}-end:${e[2]}`);)l=l.nextSibling;if(null!==l){for(;t.nextSibling!==l;)t.nextSibling.remove();l.remove(),t.replaceWith(..."text"===e[1]?[gi(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let l of Yi(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.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=ie.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,r)=>t+i(n??l,r))),s(o.content,n??l);let u=o.content.firstChild;l.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")}(h,l,u):Hi(h,l,s),l.remove(),s&&(e.Ie=ns,queueMicrotask(()=>{Ji(),e.Ie=null}))}(t),n?.(t,l)},function(){let e=globalThis;e[Di]={build:Ri,reset(){Wi=0}},void 0===e[pi]&&(e[pi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Di].build(t),reset:()=>e[Di].reset()})}(),e.Ao=t(e.Ao,hi);for(let e of ln())hi(e)}},rs="__WCSTACK_DEVTOOLS_HOOK__",is=null,ss=new Set,os=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),as=new WeakMap,us=0;var cs=new WeakMap;function fs(e){if(null===is)return;let t=cs.get(e),n=ss.has(e)?function(e,t){let n=new Map,l=new Set,r=(l,r,i,s,o,a)=>{if(5===l)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(l,r),c=0===s.n?null:o,f=`${(e=>{let t=as.get(e);return void 0===t&&as.set(e,t=++us),t})(i)}|${u}|${s.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:s.t,bindingType:a,node:i,replaceNode:i},absoluteAddress:os(e,s,c)})},i=e=>r(e.i,e.name,e.a,e.o,e.r,e.on()),s=e=>{if(!l.has(e)){if(l.add(e),null!==e.ye)for(let t of e.ye)i(t);if(e instanceof tt&&null!==e.pe){let t=e.O.Ye;for(let n=0;n<t.length;n++){let l=e.V?.[n];void 0!==l?i(l):r(t[n].i,t[n].name,e.pe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.c)for(let t of e.c)o(t)}},o=e=>{if(!l.has(e))if(l.add(e),e instanceof ft){r(-1,"for",e.S,e.l.o,e.l.ae,"for");for(let t of e.Ae)s(t)}else null!==e.C&&s(e.C)};for(let t of e.ue.values())for(let e of t)i(e),null!==e.D&&o(e.D);for(let t of e.oe.values())if(null!==t.x&&o(t.x),null!==t.L)for(let e of t.L)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||is({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&is({type:"state:binding-added",...l});cs.set(e,n)}function hs(e){let t=qt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function ds(e){let t=new Set,n=new Set,l=new Set,r=new Set;for(let i of e.I.all()){for(let e=1;e<=i.n;e++)t.add(i.h[e].t);"*"===i.s&&n.add(i.t),null!==i.getter&&l.add(i.t),null!==i.ie&&r.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:l,setter:r},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.ce.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==i.$watch&&"object"==typeof i.$watch?new Set(Object.keys(i.$watch)):null,keyedListPaths:null!==i.$listKeys&&"object"==typeof i.$listKeys?new Set(Object.keys(i.$listKeys)):null}}var ps=new WeakSet,ms=new WeakMap;function gs(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(ps.has(t))return;ps.add(t);let l=t.emit;t.emit=(...r)=>(null!==is&&is({type:"state:token-emit",kind:n,tokenName:t.name,args:r,subscriberCount:t.size,stateElement:e.element}),l.apply(t,r))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.ce.values())t(n,"event")}(e),"connected"===t){if(ss.has(e))return;ss.add(e),is?.({type:"state:element-registered",rootNode:e.root,element:e.element}),fs(e)}else"disconnected"===t&&(ss.delete(e),fs(e),is?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function ys(e,t,n,l,r,i){if(null===is)return;let s=os(e,t,0===t.n?null:n),o=ms.get(e);void 0===o&&ms.set(e,o=new Set),o.add(s),i&&is({type:"state:write",absoluteAddress:s,value:r,oldValue:l,hasOldValue:!0})}function bs(e){if(null===is)return;let t=ms.get(e);ms.delete(e),void 0!==t&&is({type:"state:update-batch",addresses:t}),fs(e)}function vs(e,t,n){is?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var $s={"*":["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 ws(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...$s["*"],...Object.hasOwn($s,e)?$s[e]:[]])(n);return l.includes(t)||w(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var As=[Tn,sl,Ml,ql,Kr,ai,ls,{name:"devtools",install(){e.element=t(e.element,gs),e.Se=t(e.Se,ys),e.Ce=t(e.Ce,bs),e.ze=t(e.ze,vs),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let t=globalThis,n=t[rs]??(t[rs]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let l of t)l.onEvent?.(e.id,n)})};return{version:2,sources:e,register(l){if(!e.has(l.id)){e.set(l.id,l),n(l);for(let e of t)e.onSourceRegistered?.(l)}},unregister(n){let l=e.get(n);if(void 0!==l){l._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(l){t.add(l);for(let t of e.values())n(t),l.onSourceRegistered?.(t);return()=>{if(t.delete(l))for(let t of e.values())n(t)}}}}());2!==n.version&&console.warn(`[@wcstack/state] devtools hook registry version ${n.version}, expected 2: keeping the existing one.`),n.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:ui,getStateElements:()=>[...ss].map(ds),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.I.all()){let l=n.W,r=n.Me?.length??0;if((null===l||0===l.size)&&0===r)continue;let i,s=0;if(null!==l)for(let e of l.values())s+=e.size;try{i=0===n.n?e.v(n,null):void 0}catch{i=void 0}t.push({path:n.t,tracked:!1,rows:s,keys:null===l?0:l.size,lists:r,lastValue:i})}return t}(hs(e)),keys(e){let t=hs(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let l;return hs(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){hs(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(t){let n=null===is&&null!==t;is=t,null===t&&(cs=new WeakMap),e.st=t&&((e,t)=>is?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of ss)fs(e)})}})}()}},{name:"native-commands",install(){e.or=ws}}];function ks(e){return e}var xs=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],Ss={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"真偽性を反転(falsy → true)",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},add:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},sub:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},abs:{description:"絶対値",hasArgs:!1,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:0},clamp:{description:"範囲内に丸める (min,max)",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:2,maxArgs:2,argTypes:["number","number"]},toFixed:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},upper:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lower:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},capitalize:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},padStart:{description:"先頭を埋める (length[,char]。char の既定は 0 — JS の既定は空白なので注意)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},padEnd:{description:"末尾を埋める (length[,char]。char の既定は空白 — JS と同じ)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},repeat:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},reverse:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},truncate:{description:"切り詰めて省略記号 (length[,suffix]。suffix の既定は … — U+2026 の 1 文字)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},join:{description:"配列を連結 ([separator]。既定はカンマ + 空白)",hasArgs:!0,resultType:"string",acceptTypes:["array"],minArgs:0,maxArgs:1,argTypes:["string"]},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},unit:{description:"単位(接尾辞)を付加",hasArgs:!0,resultType:"string",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["string"]},date:{description:"ロケール形式の日付 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},ymd:{description:"YYYY-MM-DD 形式 ([separator]。既定は -)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},hms:{description:"HH:MM:SS 形式 ([separator]。既定は :)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},coalesce:{description:"null / undefined の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},nullIfEmpty:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0},currency:{description:"通貨の書式 (code[, locale]。code は ISO 4217 — JPY / USD / EUR、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:1,maxArgs:2,argTypes:["string","string"]}},Ts=2,Ns=Object.freeze({}),Os=Object.freeze({}),js=Object.freeze({}),Cs=Object.freeze(["prevent","stop","ro","direct"]),Ms=Object.freeze(["init","sync"]),Ps=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function Es(){return{version:2,syntax:{bindAttribute:ie.bindAttributeName,tagName:ie.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(ae),modifiers:{flags:Cs,keyValue:Ms,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:N,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:j,class:C,attr:M,style:P}}},filters:[...Object.keys(Te),...Object.keys(xn)],filterMeta:Ss,filterAliases:Ns,declarationAliases:Os,apiAliases:js,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(Ps.map(e=>[e,{type:"boolean",default:!0}])),features:[...xs],nativeCommands:Object.fromEntries(Object.entries($s).map(([e,t])=>[e,[...t]]))}}var Ws=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),Is=Object.freeze([]);function Rs(e){if(!ie.enableContractAnalyzer)return Is;let t=[],n=is,l=e=>{t.push(e),n?.(e)},r=e.manifestExtensions;if(null===r||"object"!=typeof r)return t;for(let e of Object.keys(r))Ws.has(e)||l({type:"contract:unsupported-extension",namespace:e});let i=r["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=Ds(e);if(l({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){l({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let r=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(r.observables??{})){let r=n.ce.get(t);if(void 0===r){l({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==r&&l({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:r})}for(let t of Object.keys(r.inputs??{}))n.inputs.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(r.commands??{}))n.commands.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function Ds(e){let t=customElements.get(e)?.wcBindable;if(null===t||"object"!=typeof t||"wc-bindable"!==t.protocol)return null;let n=e=>Array.isArray(e)?e:[],l=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&l.set(e.name,e.event);let r=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{ce:l,inputs:r(t.inputs),commands:r(t.commands)}}function Ls(e,t){(function(e){for(let t of e)s.has(t.name)||(s.add(t.name),t.install())})(As),rn(e,t)}export{fi as Ssr,Ce as TRUSTED_TYPES_POLICY_SLOT,ui as VERSION,Ts as WCS_MANIFEST_VERSION,Rs as analyzeContract,Ls as bootstrapState,on as buildBindings,Ns as builtinFilterAliases,Ss as builtinFilterMeta,ks as defineState,Zt as getBindingsReady,se as getConfig,Me as getTrustedTypesPolicy,Es as getWcsManifest,Pe as setTrustedTypesPolicy};
2
2
  //# sourceMappingURL=index.esm.js.map