@wcstack/state 4.0.0-rc.1 → 4.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +4 -4
- package/README.md +4 -4
- package/dist/auto.min.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/split/chunks/chunk-WEL3YSG7.js +1 -0
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/package.json +1 -1
- package/dist/split/chunks/chunk-WTD5TVPZ.js +0 -1
package/dist/auto.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=class{constructor(e,n,l){this.u=[],this.getter=null,this.Z=null,this.ke=!1,this.at=[],this.Ae=[],this.ct=null,this.A=-1,this.ee=t,this.Fe=null,this.xt=null,this.Rt=null,this.H=null,this.Pt=new Set,this.t=e,this.w=l,this.l=n;let i=null===l?[null]:l.c.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this._=r?[]:null===l?[n]:[...l._,n],this.c=i}Ln(e){this.Pt.has(e)||(this.Pt.add(e),this.at.push(e),e.Ae.push(this))}Po(){this.getter=null,this.Z=null,this.A=-1,this.ee=t,this.at.length=0,this.Pt.clear(),this.Ae.length=0,this.ct=null,this.Fe=null,this.xt=null,this.Rt=null,this.H=null}G(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.w}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.Tt=new Map,this.Bn=e}At(e){return this.Tt.get(e)}get(t){let n=this.Tt.get(t);if(void 0!==n)return n;let l=t.lastIndexOf("."),i=l<0?null:this.get(t.slice(0,l));return n=new e(t,t.slice(l+1),i),this.Bn?.(n),this.Tt.set(t,n),i&&i.u.push(n),n}all(){return this.Tt.values()}},r=new Map;function o(e){let t=r.get(e);if(void 0!==t)return t;let n=!0,l=e.split("."),i=[];for(let e=0;e<l.length;e++){let t=l[e],r=t.charCodeAt(0);e>0&&r>=48&&r<=57?(n=!1,i.push(Number(t)),l[e]="*"):"*"===t&&i.push(-1)}if(!n)return{o:l.join("."),indexes:i};let o={o:e,indexes:null};return r.set(e,o),o}var s=class{constructor(e,t,n){this.ut=null,this.$=null,this.de=null,this.H=null,this.u=null,this.d=!0,this.s=e,this.b=t,this.O=n}},a=class{constructor(e,t){this.Y=null,this.was=null,this.f=[],this.$=null,this.j=null,this.J=!1,this.Ft=!1,this.Ge=!1,this.o=e,this.te=t,this.n=e.n+1}},u=[],c={};function f(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function h(e,t,n){return null==t?n:(...l)=>{let i=t(...l);return e(i)?i:n(...l)}}var d=e=>!0===e,p=e=>void 0!==e,m=e=>null!=e,g=new Set;function y(e){let t=e.$features;if(null!=c.Ct&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Ct(e)}}function $(e,t){if(!g.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}function v(e,t,n){throw new Error(`[@wcstack/state] ${e}${c.Ao?.(e,t,n)??""}`)}var b=["","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"],w=e=>{let t=b[e/100|0];return t?`[wcs/${t}] `:""};function k(e,t=[]){return c.Fo?.(e,t)??`${w(e)}#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function S(e,t,n,l){v(k(e,t),n,l)}var x=class{constructor(e){this.dt=new Set,this.name=e}get size(){return this.dt.size}subscribe(e){return this.dt.add(e),()=>{this.dt.delete(e)}}unsubscribe(e){return this.dt.delete(e)}emit(...e){let t=[];for(let n of this.dt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${k(17,[this.name])}`,e)}return t}};function A(e,t,n){if(void 0===e)return[];Array.isArray(e)||S(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&S(19,[t]),i===n&&S(20,[t,i,n]),l.has(i)&&S(21,[t,i]),l.add(i);return e}var N=Symbol.for("wcstack.transition-runner");function j(e){let t=globalThis[N];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 O(e,t,n){let l=j(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var M="else",C="eventToken",T=/^\$[1-9]\d{0,2}$/,P=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function E(e){let t=[],n=[],l="",i=null,r=!1,o=-1,s=-1,a=e=>{let i=function(e,t,n){let l=-1===t?e.length:t,i=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,i+e.slice(i).trimEnd().length)}(l,o,s);(!e||i||r)&&(t.push(i),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:P.test(e)?Number(e):e)}(i,r))),l="",r=!1,o=-1,s=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=l.length),l+=n,s=l.length):'"'===n||"'"===n?(i=n,r=!0):","===n?a():l+=n}return null!==i&&S(107,[i,e]),a(!0),{args:t,literals:n}}var W=e=>e.trim();function I(e,t){let n=[],l=null;for(let i=0;i<e.length;i++){let r=e[i];null!==l?r===l&&(l=null):"'"===r||'"'===r?l=r:r===t&&n.push(i)}return n}var R=(e,t)=>I(e,t)[0]??-1;function L(e,t){let n=[],l=0;for(let i of I(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function q(e,t,n){let l=R(e,"|");if(-1===l)return[e.trim(),[]];let i=e.slice(l+1).trim(),r=n.get(i);return void 0===r&&(r=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>I(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&S(108,[e]),-1!==i&&-1===n&&S(109,[e]),-1!==i&&i<n&&S(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();S(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&S(112,[l]),r.includes("#")){let[,e]=r.split("#");S("input"===t?113:114,[r,e])}return-1===n?{Dn:r,args:[],literals:[]}:{Dn:r,...E(e.substring(n+1,i))}})}(L(i,"|").map(W),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var D=new Map;function z(e){S(1101,[e])}function U(e){let[t,n]=q(e,"output",D);t.includes("@")&&S(32,[t]);let l=t,i=l.startsWith("."),r=i?l.slice(1):l;return(r.length>0&&r.split(".").some(e=>0===e.length)||!i&&0===r.length)&&S(119,[e]),function(e){e.includes("**")&&z(e);let t=e.split(".").length;t>512&&S(117,[e,t])}(l),{Ye:l,Je:n}}var F=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],B=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],_=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&z(e),e}var K=0;function V(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var J=()=>new Set,X=()=>[];function G(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Y(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e.H?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e.H.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.s.n>t;)e=e.s.te;return null!==e&&e.s.n===t?e:null}function te(e,t,n){let l=ee(e,n);return null!==l&&l.s.o===t.c[n]?l:null}var ne=class{constructor(e,t){this.Oe=0,this.h=null,this.Ce=0,this.ft=new Set,this.root=null,this.Qe=new Map,this.Mn=Symbol("wcs.block"),this.element=null,this.pt=[],this.Ie=null,this.Wn=[],this.Bt=0,this.V=null,this.oe=new Map,this.re=new Map,this.je=[],this.Le=[],this.Be=[],this.mt=!1,this.un=!1,this.dn=new WeakMap,this.B=0,this.Dt=0,this.fn=!1,this.Mt=!1,this.Wt=!1,this.Ee=0,this._n=()=>{this.B=0,this.fn=!1},this.Hn=()=>{this.Ee--},this.rp=null,this.rr=null,this.Oo=()=>this._t(),this.Co=(e,t)=>e(this.proxy,...t),this.Vn=[],this.Io={$untracked:e=>{let t=this.V;if(null===t)return e();t.fe++;try{return e()}finally{t.fe--}},$eqIndex:(e,t=1)=>{let n=ee(this.h,t);null===n&&S(7,[e]);let l=this.o(e);if(null!==l.getter||l.ke)return this.watchIndex(t),n.b===this.read(l,null);let i=this.V;if(null!==i){let e=i.getter,n=l.Fe??(l.Fe=[]);if(!n.some(n=>n.getter===e&&n.Un===t)){n.push({getter:e,Un:t});let i=e.c[t];(i.xt??(i.xt=[])).push({source:l,getter:e})}}return n.b===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,ee(this.h,n.n)))},$dependOn:e=>{this.resolve(H(e),this.h),null!==this.V&&0===this.V.fe&&this.qn(this.rp,this.rr,this.V)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.pn(e,t,n,l),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],l=this.o(t);this.mn("$resolve",t,l,n,!0);let i=this.Kn(l,n,null);if(e.length<3)return this.read(l,i);this.P(l,i,e[2])},$postUpdate:e=>{this.resolve(H(e),this.h);let t=this.rp,n=this.rr;"*"===t.l&&null!==n&&(n.O=n.s.Y[n.b],this.R.Ht(n)),this.hn(t,n),null!==n&&n.s.Ge&&this.zn(n,t,void 0,n.O,!1),0===t.n&&this.Xn(t,void 0,void 0,!0),this.Vt(t,n,void 0,void 0,!1)}},this.R=t,this.L=new i(e=>this.Ze(e)),this.Gn(e);let n=this;this.proxy=new Proxy(e,{get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.Ut(t);if(t.indexOf(".")<0){let e=n.L.At(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return l===n.proxy&&n.U?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.h),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(H(t),n.h),n.P(n.rp,n.rr,l),!0)})}o(e){return this.L.get(e)}Yn(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 i=this.o(e);i.getter=l.get??null,i.Z=l.set??null,null!==i.getter&&i.n>0&&(i.A=this.Oe++)}for(let e of this.L.all())this.Ze(e)}Ze(e){e.t.includes("**")&&z(e.t),("__proto__"===e.l||"prototype"===e.l)&&S(120,[e.t]);let t=e.w;e.ke=null!==t&&"*"!==e.l&&t.n===e.n&&(null!==t.getter||t.ke),null===e.getter&&this.jo(e)}jo(e){let t=e.t,n=e.l;if(T.test(n))e.getter=function(){return this[n]};else{let n=t.split("."),l=n.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(l<0||n.indexOf("*",l)>=0)return;let i=n.slice(0,l).join("."),r=n.slice(l);e.getter=function(){let e=this[t];return void 0!==e?e:Z(this[i],r)},e.Z=function(e){this[t]=e}}e.n>0&&(e.A=this.Oe++)}De(e,t){let n=null===e?this.oe:e.u??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new a(t,e)),this.q(l),l}Jn(e){try{this.q(e)}catch(t){this.qt(t,e.o.t,e.$?.S??null,"for")}}q(e){let t=this.v(e.o,e.te),n=e.Y;if(t===n)return;e.was=n,this.Qn(e);let l=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.Y)return null;let i=e.f,r=l.length,o=i.length,a=new Array(r),c=0;for(;c<r&&c<o&&i[c].O===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].O===l[h];)a[h]=i[f],f--,h--;if(c>f)for(let t=c;t<=h;t++)a[t]=new s(e,t,l[t]);else if(c>h)for(let e=c;e<=f;e++)n.Ot(i[e]);else{let t=new Map;for(let e=c;e<=f;e++){let n=i[e],l=t.get(n.O);void 0===l?t.set(n.O,n):Array.isArray(l)?l.push(n):t.set(n.O,[l,n])}for(let n=c;n<=h;n++){let i,r=l[n],o=t.get(r);void 0!==o&&(Array.isArray(o)?(i=o.shift(),0===o.length&&t.delete(r)):(i=o,t.delete(r))),a[n]=i??new s(e,n,r)}for(let e of t.values())if(Array.isArray(e))for(let t of e)n.Ot(t);else n.Ot(e)}for(let e=c;e<r;e++){let t=a[e];t.b!==e&&(t.b=e,n.To(t))}return e.f=a,e.Y=l,i}(e,t,this);if(null===l)return;if(e.Y===t){let i=V(this.dn,t,X);if(i.push(e),i.length>1){for(let e of i)e.Ge=!0;if(i.some(e=>e.was!==n)){let t=this.o(`${e.o.t}.*`);for(let e of l)e.d&&this.$e(t,e)}}}c.Kt?.(this,e,l),(null!==e.$||null!==e.j)&&!e.J&&(e.J=!0,this.Le.push(e),this.Ne());let i=e.o.xt;if(null!==i)for(let{source:t,getter:n}of i){let i=this.v(t,null),r=l[i],o=e.f[i];r!==o&&(void 0!==r&&r.d&&this.gn(n,r),void 0!==o&&this.gn(n,o))}}To(e){this.R.Lo(this,e)}Ot(e){e.d=!1;let t=e.H;if(null!==t){for(let e of t)Q(e.source,e.key,e.sub);e.H=null}if(null!==e.u)for(let t of e.u.values()){this.Qn(t);for(let e of t.f)this.Ot(e)}}Qn(e){let t=this.dn.get(e.Y);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.Ge=!1,1===t.length&&(t[0].Ge=!1))}resolve(e,t){let n=o(e),l=this.o(n.o),i=n.indexes;this.rr=0===l.n?null:null===i?te(t,l,l.n):this.Kn(l,i,t),this.rp=l}Kn(e,t,n){let l=null;for(let i=1;i<=e.n;i++){let r=e.c[i],o=this.De(l,r),s=t[i-1];if(-1===s&&(s=te(n,e,i)?.b??-1),l=o.f[s]??null,null===l)break}return l}zt(e,t){return 0===e.n?Z(this.target,e._):null===t?void 0:Z(t.O,e._)}read(e,t){let n=this.V;if(null!==n&&0===n.fe&&this.qn(e,t,n),null!==e.getter)return this.R.Bo(this,e,t);if(e.ke){let n=this.read(e.w,t);return n?.[e.l]}return null===e.w&&!(e.l in this.target)&&!this.ft.has(e.l)&&"then"!==e.l&&"toJSON"!==e.l&&S(301,[e.t],e.l,Object.keys(this.target)),this.zt(e,t)}v(e,t){let n=this.V;if(null===n)return this.read(e,t);n.fe++;try{return this.read(e,t)}finally{n.fe--}}qn(e,t,n){let l=n.getter;e.Ln(l),e.n>0&&l.n>0&&ee(t,Math.min(e.n,l.n))!==ee(n.r,Math.min(e.n,l.n))&&(l.ct??(l.ct=new Set)).add(e)}Do(e,t){for(let n=0;n<this.Bt;n++){let l=this.Wn[n];l.getter===e&&l.r===t&&S(701,[e.t])}this.Bt>=128&&S(801,[e.t]);let n=this.Bt++;this.Ce++;let l=this.Wn[n]??={getter:e,r:t,fe:0,Me:0};l.getter=e,l.r=t,l.fe=0,l.Me=++K;let i=this.V;this.V=l;let r=this.h;this.h=t;try{return e.getter.call(this.proxy)}finally{this.Ce--,this.Bt--,this.V=i,this.h=r,l.r=null}}watchIndex(e){let t=this.V;if(null!==t&&0===t.fe){let n=t.getter,l=n.c[e];if(l){let e=l.Rt??(l.Rt=[]);e.includes(n)||e.push(n)}}}Ut(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:T.test(e)?+e.slice(1):0;return(n<1||n>128)&&S(1001,[e]),this.watchIndex(n),ee(this.h,n)?.b}let n=this.Io[e];if(void 0!==n)return n;switch(e){case"$trackDependency":return S(1701,[e,"$dependOn"]);case"$untrackDependency":return S(1701,[e,"$untracked"]);case"$stateElement":return this.element;case"$command":return this.commands}return c.Ut?.(this,e)}eq(e,t){this.resolve(e,this.h);let n=this.rp,l=this.rr;if(null!==n.getter||n.ke||n.n>0)return Y(this.read(n,l),t);let i=this.V;return null!==i&&0===i.fe&&this.Mo(n,t,i),Y(this.v(n,null),t)}Mo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Vn:i.H??(i.H=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(Y(o.key,t))return void(o.Me=n.Me);o.Me!==n.Me&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};V(e.H??=new Map,t,J).add(o),r.push({source:e,key:t,sub:o,Me:n.Me})}Xn(e,t,n,l){this.Xt(e,i=>{let r=i.H;if(null===r&&null===i.Fe)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=Z(t,o),a=Z(n,o);if(null!==i.Fe&&this.Wo(i,s,a,l),null!==r)for(let e of l?r.keys():[s,a]){let t=r.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.d?this.R.xe(this,n.getter,n.r):Q(i,e,n)}})}P(e,t,n,l=!1,i=!1){if(this.Ce>0&&S(8),i||this.Ee>0?this.Mt=!0:this.Wt=!0,c.Re?.(this,e,t,n,i))return;if(null!==e.Z){try{this.yn(e.Z,t,[n])}finally{this.Vt(e,t,void 0,void 0,!1)}return}null!==e.getter&&S(2,[e.t]),e.n>0&&null===t&&S(3,[e.t]);let r=e.ke?this.v(e,t):this.zt(e,t);if(l||!this.jt||!Object.is(r,n)||Object(n)===n){if("*"===e.l){let e=t;e.s.Y[e.b]=n,e.O=n,this.R.Ht(e)}else{let l=1===e._.length?0===e.n?this.target:t.O:this.v(e.w,t);null==l&&S(4,[e.t,l]),l[e.l]=n}this.wn(e,t),null!==t&&t.s.Ge&&this.zn(t,e,r,n),0===e.n&&this.Xn(e,r,n),this.Vt(e,t,r,n,!0)}}Zn(e){return(this.dn.get(e.Y)??[]).filter(t=>t.Y===e.Y&&(null===t.te||t.te.d))}zn(e,t,n,l,i=!0){let r=e.s,o=t.t.slice(r.o.t.length+2);for(let t of this.Zn(r)){if(t===r)continue;let s=t.f[e.b];if(void 0===s)continue;let a=this.o(`${t.o.t}.*${o}`);""===o&&(s.O=l,this.R.Ht(s)),i?this.wn(a,s):this.hn(a,s),this.Vt(a,s,n,l,i)}}hn(e,t){this._o(e,t,e=>{this.q(e);for(let t of e.Ge?this.Zn(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.ht(e,n),this.hn(e,n)}})}wn(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.G(e)&&this.q(t)}_o(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.G(e)&&n(t)}Wo(e,t,n,l){for(let{getter:i,Un:r}of e.Fe)this.eo(i.c[r],e=>{for(let r of l?e.f.keys():[t,n]){let t="number"==typeof r?e.f[r]:void 0;void 0!==t&&this.gn(i,t)}})}gn(e,t){t.s.n===e.n?this.R.xe(this,e,t):this.Gt(t,e,t=>this.R.xe(this,e,t))}Vt(e,t,n,l,i){c.pe?.(this,e,t,n,l,i),this.$e(e,t)}$e(e,t){this.R.Ho(this,e,t),this.Ne()}to(e){let t=this.Qe.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.Qe.set(e,n);let l=this.root,i=this.Mn;return l.addEventListener(e,t=>{for(let r=t.target;null!==r&&r!==l;r=r.parentNode){let l=r[n];if(void 0!==l&&(l(t),t.cancelBubble))return;let o=r[i];if(void 0!==o&&o.d&&o.Vo(e,t))return}}),n}reset(e){let t=this.target;this.Gn(e);let n=this.ft;for(let e in t)"$"!==e[0]&&n.add(e);for(let t of n)t in e&&n.delete(t);for(let e of this.re.values())for(let t of e)this.Yt(t);for(let e of this.oe.values())this.no(e);this.Ie=null;try{this._t()}finally{this.bn()}c.element?.(this,"reset")}Gn(e){for(let[t,n]of B)void 0!==e[t]&&$(n,t);void 0!==e.$scan&&S(1);for(let[t,n]of F)void 0!==e[t]&&S(1601,[t,n]);let t=e.$features;if(void 0!==t){Array.isArray(t)||S(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&S(44,["state","$behavior"]);for(let e in n)(!_.includes(e)||"boolean"!=typeof n[e])&&S(44,["$behavior",e]);let[l,i,r]=_.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.It||i!==this.jt||r!==this.Lt)&&S(45);let o=function(e,t){let n={};for(let l of A(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new x(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of A(e.$eventTokens,"$eventTokens"))n.set(t,new x(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&S(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&S(23,[e]),"function"!=typeof i&&S(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this.Co);this.It=l,this.jt=i,this.Lt=r,c.ie?.(this,e),this.target=e,this.Oe=0;for(let e of this.L.all())e.Po();this.Vn.length=0,this.Yn(e),this.commands=o,this.Se=s}no(e){this.Jn(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.ut=null,n.H=null,this.ht(t,n),null!==n.u)for(let e of n.u.values())this.no(e)}D(e){let t=[];for(let n=e;null!==n;n=n.s.te)t.unshift(n.b);return t}Uo(e,t,n){let l=this.Se.get(e);void 0===l&&S(1301,[e],e,this.Se.keys()),l.emit(t,...this.D(n))}command(e){let t=this.commands[e];return void 0===t&&S(1302,[e],e,Object.keys(this.commands)),t}qo(e,t,n){this.command(e).emit(t,...this.D(n))}Ko(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&S(5,[e]),this.yn(l,n,[t,...this.D(n)])}yn(e,t,n){let l=this.h;this.h=t;try{return e.apply(this.proxy,n)}finally{this.h=l}}ht(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Ft&&t.o.G(e)&&(t.Ft=!0,this.Be.push(t))}if(null===t)return void this.Xt(e,e=>{let t=this.re.get(e);if(void 0!==t)for(let e of t)this.Yt(e)});let n=t.de;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.G(e)&&this.Yt(n[t]);let l=t.$;null!==l&&null!==l.se&&l.oo(this,e);let i=t.s.j;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.se&&l.oo(this,e)}}vn(e,t,n){this.Xt(e,e=>{let l=e.at;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.et(r,null,n);else if(null===t||0===e.n||r.c[1]!==e.c[1]||null!==r.ct&&r.ct.has(e))this.Jt(r.c[r.n],e=>this.et(r,e,n));else if(r.n<=e.n){let e=ee(t,r.n);null!==e&&this.et(r,e,n)}else this.Gt(t,r,e=>this.et(r,e,n))}})}et(e,t,n){n(e,t)&&(c.me?.(this,e,t),this.ht(e,t),this.vn(e,t,n))}Xt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Xt(n[e],t)}Jt(e,t){this.eo(e,e=>{for(let n of e.f)t(n)})}eo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.Jt(e.c[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}Gt(e,t,n){if(e.s.n===t.n)return n(e);let l=e.u?.get(t.c[e.s.n+1]);if(void 0!==l)for(let e of l.f)this.Gt(e,t,n)}zo(e){let t=e.r;null===t?V(this.re,e.o,J).add(e):(t.de??(t.de=[])).push(e)}kn(e){let t=e.r;if(null===t)return void this.re.get(e.o)?.delete(e);let n=t.de;t.d&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}Yt(e){e.J||(e.J=!0,this.je.push(e),this.Ne())}Ne(){this.mt||(this.mt=!0,queueMicrotask(this.Oo))}Sn(){for(let e of this.je)e.J=!1;for(let e of this.Le)e.J=!1;for(let e of this.Be)e.Ft=!1;this.je=[],this.Le=[],this.Be=[],this.R.ft(this)}io(e,t){let n=[...new Set([...this.je,...this.Le,...this.Be].map(e=>e.o.t))];console.error(`[@wcstack/state] ${k(e)}`,n),c.tt?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Sn()}_t(){this.mt=!1;let e=this.Dt;this.Dt=0;let t=0;if(!this.Mt||this.Wt?this._n():e>0?t=e:1===(t=++this.B)&&setTimeout(this._n,0),this.Mt=this.Wt=!1,t>100)101===t?this.io(41,100):this.Sn();else{this.un=!0;try{for(let e=0;this.je.length>0||this.Le.length>0||this.Be.length>0;e++){if(e>=32){this.fn?this.Sn():this.io(11,32),this.fn=!0;break}let n=this.Be;if(n.length>0){this.Be=[];for(let e of n)e.Ft=!1,this.Jn(e)}let l=this.Le,i=this.je;this.Le=[],this.je=[];let r=O("state",()=>{for(let e of l){e.J=!1;for(let t of[e.$,...e.j??[]])if(null!==t&&t.d)try{t.yt()}catch(n){this.qt(n,e.o.t,t.S,"for")}}for(let e=0;e<i.length;e++){let t=i[e];t.J&&(t.J=!1,(null===t.En||t.En.d)&&this.We(t))}this.un||(this.Qt(),this.mt&&(this.Dt=t+1))});void 0!==r&&r.then(void 0,e=>console.error(e))}}finally{this.un=!1}this.Mt=this.Wt=!1,this.Qt(),c.Pe?.(this),e>0&&this.mt&&(this.Dt=t+1)}}wt(e,t){this.pt.push([e,t])}qt(e,t,n,l){this.wt(e,{o:{t},a:n,Zt:()=>l})}We(e){try{e.apply()}catch(t){return void this.pt.push([t,e])}null!==this.Ie&&this.so(e.o,e.r)}so(e,t){let n=V(this.Ie,e.t,X);null!==t&&n.push(this.D(t))}bn(){this.Ie="function"==typeof this.target.$renderedCallback?new Map:null}Qt(){let e=this.Ie;if(null!==e&&e.size>0){this.Ie=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Ee++;try{t=this.ae("$renderedCallback",[n,l])}catch(e){console.error(e)}G(t)?t.then(this.Hn,e=>{this.Hn(),console.error(e)}):this.Ee--}if(0===this.pt.length)return;let t=this.pt;this.pt=[];let n=this.target.$errorCallback;for(let[e,l]of t){c._e?.(this,e,l);let t=l.o.t,i=l.Zt();if("function"==typeof n)try{let n=this.ae("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);G(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${k(12,[i,t])}`,e)}}ae(e,t=[]){let n=this.target[e];return"function"==typeof n?this.yn(n,null,t):void 0}lo(e,t,n){if(0===e.n)return void n(null,[]);let l=[],i=(r,o)=>{let s=e.c[r];this.read(s,o);let a=this.De(o,s),u=t=>{l.push(t.b),r===e.n?n(t,l):i(r+1,t),l.pop()};for(let e of r-1<t.length?[a.f[t[r-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e);void 0!==t&&this.mn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.h;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=te(t,n,e);if(null===i)break;l.push(i.b)}0===l.length&&S(6,[e])}}let i=[];return this.lo(n,l,e=>i.push(this.read(n,e))),i}pn(e,t,n,l){Array.isArray(t)||S(9,[e]),this.Ce>0&&S(8);let i=this.o(e);this.mn("$setAll",e,i,t,!1);let r=[];this.lo(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&S(10,[e,r.length]);let s=0;for(let e=0;e<r.length;e++){let[t,l]=r[e],a="function"==typeof n?n(this.v(i,t),...l):o?n[e]:n;void 0!==a&&(this.P(i,t,a),s++)}return s}mn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&S(i?901:902,[e,t,n.n,r])}},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=new Map,re=new Set(["if","elseif","else","for"]),oe=new Set([M,"if","elseif","for","..."]),se=new Set(["class","attr","style","command",C,"state"]);function ae(e){let t=function(e){return L(e,";")}(e).map(W).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&S(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(oe.has(i)){let t;return i!==n&&S(102,[e,i]),i===M?(l.length>0&&S(103,[e]),t={Ye:"#else",Je:[]}):"..."===i?(0===l.length&&S(104,[e]),t=U(l),t.Je.length>0&&S(105,[e])):(t=U(l),"for"===i&&t.Je.length>0&&S(121,[e])),{he:i,ye:[i],en:[],C:[],...t,y:"..."===i?"spread":i}}let r=U(l),o=function(e){let[t,n]=q(e,"input",ie),l=t.split("#").map(W);l.length>2&&S(115,[t]);let[i,r]=l,o=i.split(".").map(W);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&S(116,[e]),{he:i,ye:o,en:r?r.split(",").map(W):[],C:n}}(n),[s]=o.ye;if(""===s&&o.ye.length>1){let e=o.ye.slice(1);return(e.includes("")||se.has(e[0]))&&S(106,[n]),{...o,he:e.join("."),ye:e,...r,y:"prop"}}return{...o,...r,y:"radio"===i||"checkbox"===i?i:s===C||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>re.has(e.y))&&S(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms"],ce=new Map,fe=new Map;function he(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});fe.clear()}function de(e){return ce.has(e)}function pe(e){S(26,[e])}function me(e){S(27,[e])}function ge(e){S(28,[e])}function ye(e){S(29,[e])}function $e(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return $e(e)||me(t),Number(e)}function be(e,t,n){return ve(e?.[t]??pe(n),n)}function we(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let l=be(n,0,e);return n=>("number"!=typeof n&&ge(e),t(n,l))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),l=we(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:($e(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),l=we(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:($e(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs"),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=be(e,0,"clamp"),n=be(e,1,"clamp");return e=>("number"!=typeof e&&ge("clamp"),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:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},defaults:{factory:(e,t)=>{let n=we(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=we(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:{factory:()=>e=>!!e,arity:[0,0]},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]}},xe=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ne(e){return 0===e.length?null:(xe||(xe=!0,he(Se)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=fe.get(l);if(typeof i<"u")return i;let r=ce.get(e);void 0===r&&function(e,t){ue.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),S(501,[e],e,t)}(e,ce.keys());let[o,s]=r.arity;t.length<o&&S(601,[e,o,t.length]),t.length>s&&S(602,[e,s,t.length]);let a=r.factory(t,n);return fe.set(l,a),a}(e.Dn,e.args,e.literals)))}var je=Symbol.for("wcstack.trustedTypes.policy");function Oe(){let e=globalThis[je];return null!==e&&"object"==typeof e?e:null}function Me(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ce(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Oe(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Te=Symbol.for("wcstack.state.view-transition-naming"),Pe=new WeakSet;function Ee(){let e=j("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var We=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function Re(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Ie(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(We.has(e))return We.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 Map,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,ao:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.set(e.name,{attribute:"string"==typeof e.attribute?e.attribute:null});for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return We.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.d||function(e,t,n){let l=n;null!==t&&(t.bt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Fe(e,l,t,n)}e.Ne()})}function Le(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.get(l),f=e.Lt;f&&null===a&&void 0===u&&S(38,[l]);let h=t.M;(null===a?"element"===h||"auto"===h:void 0===u&&("state"===h||"auto"===h))&&S(39,[h,l]),"connect"===t.q&&null===a&&S(40,[l]);let d=f&&null!==a&&void 0===u,p=new He(e,ze,n,l,i,r,o,t.N,void 0);p.C=t.C,p.attribute=u?.attribute??null,Ze(e,p,!d),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.ao||c.detail?.(n,l,i)),(!p.$n||!Object.is(i,p.value))&&(i=Ae(p.C,i),null===p.N&&(p.value=i),e.P(p.o,p.r,i,a.ao,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.We(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.d)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.We(p));let t=n[l];null===p.N&&(p.value=t),e.P(p.o,p.r,t,!1,!0)};"connect"!==t.q||n.isConnected?i():Promise.resolve().then(i)}return p}function qe(e,t,n){S(e,[t.localName,n])}var De=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),ze=11,Ue=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,l)=>e.qt(t,n.o?.t??n.vt,l,Ue[n.i]),Be=Symbol();function _e(e,t,n){let l=t.M;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.W:Be}var He=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.J=!1,this.C=null,this.attribute=null,this.$n=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.En=o,this.N=s,this.value=a,this.B=u}Zt(){return Ue[this.i]}apply(){if(null!==this.B)return void this.B.yt();let e=Ae(this.N,this.engine.read(this.o,this.r));if(e===this.value&&("object"!=typeof e||null===e||this.i===ze||8===this.i||Me(this.name)))return;if(this.value===Be)return void(this.value=e);let t=this.a;if(this.i!==ze)9===this.i?t.checked=void 0!==e&&this.tn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.tn()):Ve(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.$n=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.$n=!1}null!==this.attribute&&function(e,t,n){try{if(null==n)e.removeAttribute(t);else{let l=n;if("object"==typeof n)try{l=JSON.stringify(n)}catch{}e.setAttribute(t,String(l))}}catch{}}(t,this.attribute,e)}}tn(){return Ae(this.C,this.a.value)}Xo(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.tn()}else if(10===this.i){let l=this.tn(),i=n.v(this.o,this.r),r=Array.isArray(i)?i:[],o=r.includes(l);if(t.checked?o:!o)return;e=o?r.filter(e=>e!==l):[...r,l]}else e=Ae(this.C,t[this.name]);n.P(this.o,this.r,e,!1,!0)}},Ke=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ve(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ke(n)?t[n]="innerHTML"===n?Ce(l):null==l?"":String(l):Me(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Ce(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,l])));case 8:return void(t.innerHTML=Ce(l));case 2:return null!=l&&"boolean"!=typeof l&&S(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(null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)))}}var Je=Symbol();function Xe(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Ge=class{constructor(e,t,n,l){this.d=!0,this.de=null,this.u=null,this.bt=null,this.xn=null,this.r=e,this.He=t,this.I=n,this.T=l}Vo(e,t){let n=t.target,l=this.T,i=[],r=null;for(let t of l.Se){if(t.name!==e)continue;let o=l.Rn[t.a],s=at(null===this.I?this.He:this.I[o[0]],o,1);s.contains(n)&&(s!==r&&i.unshift([]),i[0].push(t),r=s)}for(let e of i){for(let n of e)n.Nn(t,this.r);if(t.cancelBubble)return!0}return!1}get l(){return null===this.I?this.He:this.I[this.I.length-1]}Ve(){let e=this.xn;return(null===e?null:e.Pn(this.He))??this.He}insertBefore(e,t){let n=this.l;for(let l=this.Ve();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}fo(){null===this.I?this.He.remove():ut(this.Ve(),this.l)}be(e){if(this.d=!1,null!==this.bt)for(let e of this.bt)e();let t=this.de;if(null!==t)for(let n=0;n<t.length;n++)e.kn(t[n]);if(null!==this.u)for(let e of this.u)e.be()}},Ye=class extends Ge{constructor(e,t,n,l){super(e,t,n,l),this.po=0,this.U=null,this.se=0===l.Ue.length?null:new Array(2*l.Ue.length)}mo(e,t){let n=this.U??=new Array(this.T.Ue.length),l=n[t];if(void 0===l){let i=this.T.Ue[t],r=this.se;l=n[t]=new He(e,i.i,r[2*t],i.name,i.o,this.r,this,i.N,r[2*t+1])}return l}oo(e,t){let n=this.T.Ue;for(let l=0;l<n.length;l++)n[l].o.G(t)&&e.Yt(this.mo(e,l))}be(e){let t=this.r;t.$===this&&(t.$=null),super.be(e)}};function Qe(e,t,n,l){let i=ee(n,t.n);try{return e.De(i,t)}catch(n){return e.qt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function Ze(e,t,n){n&&e.zo(t);let l=t.En;null!==l&&(l.de??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function lt(e,t,n,l,i=null){let r,o=t.Rn,s=t.build,a=t.ho,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.Tn,d=f?document.createDocumentFragment():(h?t.root:t.nn).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=at(d,o[t],h?1:0)}h?r=d:(u=f||[...d.childNodes],r=u[0]);let p,m=null;if(null!==l?(p=m=new Ye(n,r,u,t),null===l.map?n.$=m:l.map.set(n,m)):p=new Ge(n,r,u,t),nt>=0&&function(e,t,n,l){let i=null;if(null===t)i=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===i;e++)1===t[e].nodeType&&(i=t[e]);let r=i?.style;if(null===i||void 0===r||Pe.has(i))return;let o=globalThis[Te]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${k(25,[l])}`)):(Pe.add(i),o.assigned++,r.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),r.setProperty("view-transition-class",`wcs-${n}`))}(r,u,null!==l?"row":"branch",nt),t.Se.length>0){let t=e.Mn;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.Go,y=e.Ie,$=t.Yo?a.slice(0,o.length):a,v=null===m?null:m.se;if(null!==v){let e=t.Ue;for(let t=0;t<e.length;t++)v[2*t]=$[e[t].a],v[2*t+1]=e[t].W}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.a],o=l.A;if(o>=0&&null!==v){let t=m.U?.[o];if(void 0!==t){t.J=!1,e.We(t);continue}try{let t=Ae(l.N,e.read(l.o,n));t!==l.W&&(Ve(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.so(l.o,n)}catch(t){e.wt(t,m.mo(e,o))}continue}switch(l.i){case 6:{let t=new st(e,l.T,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.xn=t),t.yt();break}case 7:{let t=rt(e,l.K.map(e=>({T:e.T,o:e.o,N:e.N,S:$[e.a]})),n,p);(p.u??=[]).push(t),i===r&&(p.xn=t);break}default:try{it(e,l,i,n,p)}catch(t){Fe(e,t,l,i)}}}return et=p,d}function it(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Nn,o=e=>r(e,l);if(n.Qe){let l=e.to(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.we&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.uo&&null!==i&&(i.bt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.vt.slice(9));null===i&&qe(1202,n,`command.${r}`),i.commands.has(r)||S(1203,[n.localName,r]);let s=new WeakRef(n),a=o.subscribe((...e)=>{let t=s.deref();if(void 0!==t)return t.isConnected?t[r](...e):void 0;a()});null!==l&&(l.bt??=[]).push(a)}(e,t,r,i,n));case 13:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&qe(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&S(1204,[n.localName,r]);let s=t.vt;n.addEventListener(o.event,n=>{t.kt&&n.preventDefault(),t.St&&n.stopPropagation();try{e.Uo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=ee(l,o.n);if(14===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&qe(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs.keys()]);for(let s of o){if(t.co?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;Le(e,{...t,M:null,q:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.we&&1===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void Le(e,t,n,t.name,t.o,l,i,r);let o=new He(e,1,n,t.name,t.o,l,i,t.N,_e(e,t,l));o.C=t.C,!c.Jo?.(o,t.ro)&&(Ze(e,o,!0),e.We(o))}(e,t,r,s,i,n));let a=new He(e,t.i,n,t.name,o,s,i,t.N,_e(e,t,s));a.C=t.C,Ze(e,a,!0),e.We(a),null!==t.Et&&n.addEventListener(t.Et,()=>a.Xo())}function rt(e,t,n,l){let i=new ot(e,t,n),r=null;for(let o of t){if(null===o.o)continue;let t=o.o,s=new He(e,7,o.S,"if",t,ee(n,t.n),l,null,void 0,i);Ze(e,s,!0),null===l&&i.re.push(s),r??=s}return e.We(r),i}var ot=class{constructor(e,t,n){this.d=!0,this.F=null,this.b=-1,this.re=[],this.engine=e,this.K=t,this.r=n}Pn(e){return null!==this.F&&this.K[this.b].S===e?this.F.Ve():null}yt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ae(l.N,e.read(l.o,ee(this.r,l.o.n)))){t=n;break}}if(t!==this.b&&(nt=Ee(),null!==this.F&&(this.F.fo(),this.F.be(e),this.F=null),this.b=t,t>=0)){let n=this.K[t],l=lt(e,n.T,this.r,null,n.S);this.F=tt();let i=n.S.parentNode;i.insertBefore(l,n.S),Xe(i)}}be(){this.d=!1;for(let e of this.re)this.engine.kn(e);null!==this.F&&this.F.be(this.engine)}},st=class{constructor(e,t,n,l){this.d=!0,this.ve=[],this.engine=e,this.T=t,this.s=n,this.S=l,null===n.$?(n.$=this,this.map=null):((n.j??=[]).push(this),this.map=new Map)}Pn(e){return 0===this.ve.length?null:this.ve[0].Ve()}$t(e){return null===this.map?e.$:this.map.get(e)??null}go(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.be(this.engine)}yt(){let e=this.engine,t=this.s.f,n=this.ve;nt=Ee();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){ut(n[0].Ve(),n[i-1].l);for(let e=0;e<i;e++)this.go(n[e])}return void(this.ve=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.$t(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.$t(t[c])===n[u];)s[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],l=t.r;l.d&&this.$t(l)===t?t.po=e:(t.fo(),this.go(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(i>0)for(let e=0;e<n;e++){let n=this.$t(t[a+e]);null!==n&&n.d?(u[e]=n.po,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Ve():r;if(f){let l=function(e){let t=e.length,n=new Uint8Array(t),l=new Int32Array(t).fill(-1),i=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let r=0,o=i.length;for(;r<o;){let n=r+o>>1;e[i[n]]<t?r=n+1:o=n}r>0&&(l[n]=i[r-1]),i[r]=n}let r=i.length>0?i[i.length-1]:-1;for(;r>=0;)n[r]=1,r=l[r];return n}(u),i=h;for(let r=n-1;r>=0;r--){let n=t[a+r],u=this.$t(n);null!==u&&u.d?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(lt(e,this.T,n,this),i),u=tt()),s[a+r]=u,i=u.Ve()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(lt(e,this.T,t[l],this)),s[l]=tt();o.insertBefore(n,h)}}this.ve=s,Xe(o)}be(){this.d=!1;let e=this.s;if(e.$===this)e.$=null;else if(null!==e.j){let t=e.j.indexOf(this);t>=0&&e.j.splice(t,1),0===e.j.length&&(e.j=null)}for(let e of this.ve)e.be(this.engine);this.map?.clear()}};function at(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 ut(e,t){let n=document.createRange();n.setStartBefore(e),n.setEndAfter(t),n.deleteContents()}var ct=()=>le.bindAttributeName;function ft(){return{a:0,i:1,name:"",o:null,N:null,W:t,Nn:null,T:null,K:null,C:null,Et:null,we:!1,M:null,q:null,ro:!1,kt:!1,St:!1,vt:null,co:null,A:-1,Qe:!1,uo:!1}}var ht=["state","element","auto","none"],dt=["call","connect"],pt="$command.";function mt(e,t,n){T.test(t)&&(null===n&&S(1401,[t,Number(t.slice(1))]),t=`${n.t}.*.${t}`);let l=e.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&S(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&S(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?n:n.c[e];l.c[e]!==t&&S(1403,[l.t,l.c[e].t,t.t])}return c.yo?.(e,l),l}var gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&Ke(e.name);function $t(e){S(202,[e])}function vt(e,t,n,l,i){let r=ae(t).map(t=>function(e,t,n,l,i){let r=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Lt||S(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&S(33,[r,n]),null!==(s?l:i)&&S(34,[r]),(s?ht:dt).includes(o)||S(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),kt:t.includes("prevent"),St:t.includes("stop"),event:n?n.slice(2):null,M:l,q:i}}(e,t.en),o=l.localName.includes("-"),s=t.ye,a=t.Ye;if("event"===t.y){if(null!==r.M&&"none"!==r.M&&S(36),"eventToken"===s[0])return{...ft(),a:i,i:13,name:s.slice(1).join("."),vt:a,we:o,kt:r.kt,St:r.St};let n=a.startsWith(pt)?a.slice(9):null,{kt:l,St:u}=r,c=t.he.slice(2),f=t.en.includes("direct"),h=!f&&De.has(c);return h&&e.to(c),{...ft(),a:i,i:5,name:c,Qe:h,we:o,uo:f,Nn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.qo(n,t,i);else{let n=e.Ko(a,t,i);G(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.y)return{...ft(),a:i,i:14,o:mt(e,a,n),we:o};if("command"===s[0]&&s.length>1)return a.startsWith(pt)||S(1201,[t.he,a]),{...ft(),a:i,i:12,name:s.slice(1).join("."),vt:a,we:o};let u=mt(e,a,n),c={...ft(),a:i,i:1,name:t.he,o:u,N:Ne(t.Je),C:Ne(t.C),ro:r.ro,M:r.M,q:r.q};if("radio"===t.y||"checkbox"===t.y)return("element"===r.M||"auto"===r.M)&&S(37,[t.y,r.M]),c.i="radio"===t.y?9:10,r.ro||(c.Et=r.event??"input"),c;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return c.M=null,c.name=e,"class"===t?(c.i=2,c.W=l.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,c}return"html"===t.he?(c.i=8,c):(c.name="text"===t.he?"textContent":t.he,c.we=o&&!Me(c.name),!o&&!r.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.Et=r.event??("select"===l.localName?"change":"input")),c)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].co=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var bt=/\{\{([\s\S]+?)\}\}/g;function wt(e){let t=e.data,n=[],l=0;bt.lastIndex=0;for(let i=bt.exec(t);null!==i;i=bt.exec(t)){let r=bt.lastIndex-i[0].length;r>l&&e.before(t.slice(l,r));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({a:o,Qo:i[1].trim()}),l=bt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function kt(e,t,n,l){let i=function(e){return{he:"textContent",ye:["textContent"],en:[],C:[],...U(e),y:"text"}}(t);return{...ft(),a:l,i:0,o:mt(e,i.Ye,n),N:Ne(i.Je),W:""}}function St(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.y&&"if"!==n.y&&"elseif"!==n.y&&"else"!==n.y?null:n}var xt=(e,t)=>0===e?le.commentIfPrefix:null===t.o?le.commentElsePrefix:le.commentElseIfPrefix;function At(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.y?null:mt(e,l.Ye,n),N:"else"===l.y?null:Ne(l.Je)}),i=[l(t,St(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=St(e);if(null===t||"elseif"!==t.y&&"else"!==t.y||(i.push(l(e,t)),"else"===t.y))break}return i}var Nt=new WeakSet;function jt(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.An?.(e,i,t),i},u=t=>{for(let f=0;f<t.length;f++){let h=t[f];if(null!==h.parentNode)if(1===h.nodeType){let t=h,s=t.localName;if(l){if("script"===s||"style"===s||Nt.has(t))continue;if(Nt.add(t),s===le.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?St(t):null;if(null!==f){if("for"===f.y){let l=mt(e,f.Ye,n),r=Ct(e,t,l,!0);i(a(t,le.commentForPrefix),l,r)}else"if"===f.y?r(At(e,t,n).map((t,l)=>({T:Ct(e,t.el,n,!1),o:t.o,N:t.N,S:a(t.el,xt(l,t))}))):$t(f.y);continue}let d=t.getAttribute(ct()),p=null===d?null:vt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(yt)&&!c.wo?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.It&&h.data.includes("{{")&&!Nt.has(h))for(let{a:e,Qo:t}of wt(h))s(e,t);else if(8===h.nodeType){let e=Ot.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),s(t,e[1])}}}};u(t)}var Ot=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Mt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Ct(e,t,n,l){let i=document.importNode(Mt(t),!0),r=[],o=[],s=e=>r.push(e)-1;jt(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ft(),a:s(e),i:6,o:t,T:n})},e=>{let t=e.map(e=>({a:s(e.S),T:e.T,o:e.o,N:e.N}));o.push({...ft(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)gt(e)&&S(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,l)=>{o.push(kt(e,l,n,s(t)))}),Wt(i,new Set(r),!0);let a=r.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}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of o){if(5===e.i&&e.Qe&&!e.we&&!Tt(r[e.a],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.c[m]===n&&Pt(e)&&(e.A=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{nn:i,root:u?i.firstChild:null,Rn:a,build:g,Se:d,Go:p,Tn:u,Yo:c,ho:[],Ue:f}}function Tt(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 Pt(e){if(null!==e.M)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.we&&null===e.Et;default:return!1}}var Et=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Wt(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&&Wt(l,t,Et.has(l.localName)),l=e}}var It=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),Lt(e,[...n.childNodes]),e.Qt()}function Lt(e,t){jt(e,t,null,!0,(t,n,l)=>{new st(e,l,Qe(e,n,null,t),t).yt()},t=>{rt(e,t,null,null)},(t,n)=>{c.An?.(e,t,n);for(let l of n)it(e,l,t,null,null)},(t,n)=>{c.An?.(e,t,n),it(e,kt(e,n,null,0),t,null,null)})}var qt=Symbol.for("wcstack.binder"),Dt=Symbol.for("wcstack.binder.pending"),zt=Symbol.for("wcstack.binder.taken");var Ut=new Set;function Ft(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ut.add(e):function(e,t,n){try{let l="template"===t.localName?St(t):null;null!==l&&!n&&S(204,[l.y]),Lt(e,[t])}catch(e){console.error(e)}e.Qt()}(n,e,t?.range)}function Bt(){let e=[...Ut];Ut.clear();for(let t of e)Ft(t);!function(){let e=function(){let e=globalThis[qt];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[Dt];return void 0===t&&(t=[],e[Dt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[zt];return void 0===t&&(t=new WeakSet,e[zt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var _t=class{constructor(){this.name="dirty",this.nt=(e,l)=>{if(0===e.n){let l=e.ee;return l!==t&&l!==n&&(e.ee=n,!0)}let i=null===l?null:l.ut;if(null===i)return!1;let r=i[e.A];return r!==t&&r!==n&&(i[e.A]=n,!0)}}Ho(e,t,n){null!==t.getter&&this.nt(t,n),e.ht(t,n),e.vn(t,n,this.nt)}Lo(e,t){let n=t.s.o.Rt;if(null!==n)for(let l of n)l.n===t.s.n?e.et(l,t,this.nt):e.Gt(t,l,t=>e.et(l,t,this.nt))}xe(e,t,n){this.nt(t,n),c.me?.(e,t,n),e.ht(t,n),e.vn(t,n,this.nt)}Bo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.ut??=new Array(e.Oe).fill(t),a=null===s?i.ee:s[i.A];if(a!==t&&a!==n&&a!==l&&(null===s||i.A in s))return a;a=l;try{return a=e.Do(i,null===s?null:r)}finally{null===s?i.ee=a:s[i.A]=a}}Ht(e){e.ut=null}ft(e){for(let t of e.L.all())null!==t.getter&&(0===t.n?t.ee===n&&(t.ee=l):e.Jt(t.c[t.n],e=>{let i=e.ut;null!==i&&i[t.A]===n&&(i[t.A]=l)}))}},Ht=0,Kt=new WeakMap;function Vt(e){let t=e.getRootNode();Kt.set(t,[...(Kt.get(t)??[]).filter(t=>t.isConnected&&t!==e),e])}function Jt(e){let t=Kt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.U||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Kt.get(e)!==t?Jt(e):Promise.reject(l.errors[0]):void 0)}var Xt=typeof HTMLElement>"u"?class{}:HTMLElement,Gt=class extends Xt{constructor(){super(),this.engine=null,this.Fn=!1,this._e=!1,this.W=null,this.qe=null,this.loaded=!1,this.sn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.rn=e,this.bo=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.on=e})}static{this.getBindingsReady=Jt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Fn){if(null!==this.qe)return void this.qe.Ke();Vt(this);let e=this.engine;return void(null!==e&&Promise.resolve(e.ae("$connectedCallback")).then(()=>{this.isConnected&&c.element?.(e,"connected")},e=>console.error(e)))}this.Fn=!0;let e=this.getRootNode(),t=c.ot?.(this,e);if(t)return this.qe=t,!t.vo&&this.parentNode instanceof ShadowRoot&&Vt(this),void(void 0===t.Ct?this.ko():t.Ct()).then(e=>(this.loaded=!0,t.start(e,()=>this.So()))).then(()=>{this.on(),this.rn()},e=>this.wt(e,t.vo));this.start(e),Vt(this)}disconnectedCallback(){if(null!==this.qe)return void this.qe.On();let e=this.engine;null!==e&&(e.ae("$disconnectedCallback"),c.element?.(e,"disconnected"))}setInitialState(e){if(this._e&&S(14),this.loaded)this.qe.reset(e);else if(null===this.engine)if(null!==this.sn){let t=this.sn;this.sn=null,t(e)}else this.W=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&S(15),"readonly"===e&&n.Ce++;try{t(n.proxy)}finally{"readonly"===e&&n.Ce--}}async createStateAsync(e,t){let n=this.engine;null===n&&S(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&&S(8),l(...e)):l},set(){S(8)}}))}async ko(){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] ${k(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||S(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 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,i=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Ht}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?k(42):k(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(i)}}(l):null!==this.W?Promise.resolve(this.W):new Promise(e=>{this.sn=e})}async start(e){try{let t=e.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||t?.hasAttribute("data-wc-definition"))&&$("scopes","<wcs-state>");let n=await this.ko(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.W=n,this.Fn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=It.get(e)?.element;i?.isConnected&&(i.U||i.qe)&&S(47);let r=new ne(n,new _t);r.element=this,this.engine=r,c.element?.(r,"mounting"),Rt(r,e),Bt(),r.bn(),this.So(),await r.ae("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.rn()}catch(e){this._e=!this.U,this.wt(e)}}So(){this.U=!0,this.on()}wt(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${k(this.U?50:49,[this.localName,...n])}`,e),this.on(),t?this.rn():this.bo(e)}},Yt=[];function Qt(){return(Yt=Yt.filter(e=>e.deref())).map(e=>e.deref())}var Zt,en=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},tn="en";function nn(){if(le.locale!==Zt){Zt=le.locale;try{tn=Intl.getCanonicalLocales(Zt)[0]}catch{console.warn(`[@wcstack/state] ${k(48,[Zt])}`),tn="en"}}return tn}var ln={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed"),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale"),e.toLocaleString(t??nn()))},arity:[0,1]},upper:{factory:en(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:en(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:en(()=>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:en(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:en(e=>{let t=[be(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:en(e=>{let t=be(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:en(e=>{let t=be(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:en(e=>{let t=be(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:en(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:en(e=>{let t=be(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)||S(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ge("round"),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor"),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil"),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent"),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:en(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("date"),e.toLocaleDateString(t??nn()))},arity:[0,1]},time:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("time"),e.toLocaleTimeString(t??nn()))},arity:[0,1]},datetime:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("datetime"),e.toLocaleString(t??nn()))},arity:[0,1]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("ymd");let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("hms");let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]}},rn=!1,on={name:"formats",install:function(){rn||(rn=!0,he(ln))}};function sn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let l=new Array(t.length+1),i=new Array(t.length+1);for(let e=0;e<=t.length;e++)l[e]=e;for(let n=1;n<=e.length;n++){i[0]=n;for(let r=1;r<=t.length;r++){let o=e[n-1]===t[r-1]?0:1;i[r]=Math.min(l[r]+1,i[r-1]+1,l[r-1]+o)}for(let e=0;e<=t.length;e++)l[e]=i[e]}return l[t.length]}function an(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=sn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var un=" Validate statically: npx @wcstack/lint <file>.",cn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],fn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,hn="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)=>`binding "${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 ${hn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${hn}`,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=>`filter ${e} requires a number value`,29:e=>`filter ${e} requires a date value`,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&&cn.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)=>`${fn(e,t)} failed to initialize.`,50:(e,...t)=>`${fn(e,t)} $connectedCallback 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>").`,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}).`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,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 pn(e,t){let n=dn[e];return void 0===n?`${w(e)}#${e} ${t.join(" ")}`:w(e)+n(...t)}var mn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),gn=[[/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.']],yn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function $n(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(yn,e)?yn[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?an(t,n):"");for(let[t,n]of gn){let i=t.exec(e);null!==i&&(l+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(l+=` — write "${i[1]}#${i[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"].':ue.some(de)||(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 r=/\[wcs\/([\w-]+)\]/.exec(e);return null!==r&&mn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=un),l}var vn=new WeakMap,bn=new WeakMap,wn=new WeakSet,kn=new WeakSet;function Sn(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 xn(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 An(e,t){let n=[];for(let e=t;null!==e;e=e.w)n.unshift(e);let l=e.target,i=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!==Sn(e.target,t.t)?.get?t:e.L.At(o(t.t).o)}(e,t);for(let t of n){if(null!=i(t)?.getter||null===l||"object"!=typeof l)return null;if("*"===t.l){if(!Array.isArray(l)||0===l.length)return null;l=l[0];continue}if(Array.isArray(l)&&/^\d+$/.test(t.l)){if(Number(t.l)>=l.length)return null;l=l[Number(t.l)];continue}let n=Sn(l,t.l);if(void 0===n&&null===t.w&&e.ft.has(t.l))return null;if(void 0===n){let n=xn(l),r=i(t.w);for(let t of e.L.all())t.w===r&&null!==t.getter&&n.push(t.l);return{seg:t.l,names:n}}if(void 0!==n.get||void 0!==n.set)return null;l=n.value}return null}function Nn(e){wn.has(e)||(wn.add(e),setTimeout(()=>function(e){wn.delete(e);let t=vn.get(e);if(void 0===t)return;let n=bn.get(e);void 0===n&&bn.set(e,n=new Set);for(let[l,i]of t){if(n.has(l))continue;n.add(l);let t=An(e,l);if(null===t)continue;let r=[...e.root?.querySelectorAll(`${le.tagNames.state}[mount]`)??[]].find(e=>!kn.has(e)&&(l.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==r){n.delete(l),r.initializePromise.then(()=>{kn.add(r),Nn(e)});continue}let[s,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];c.tt?.(e,{type:"state:path-unresolved",source:i?"watch":"binding",path:l.t,missingSegment:t.seg});let u=e.L.At(o(l.t).o),f="";if(void 0!==u&&u!==l&&null!==u.getter){let e=u.c.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.c[t].t.length+2)}`);f=` 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/${s}] ${a} "${l.t}" does not resolve on the state tree: "${t.seg}" is not declared.${an(t.seg,t.names)}${f} Updates to this path will be silently dropped.${un}`)}}(e),0))}function jn(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.w)return;let l=vn.get(e);void 0===l&&vn.set(e,l=new Map),l.has(t)||l.set(t,n),Nn(e)}var On=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Mn=!1;function Cn(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(Mn||!(t instanceof TypeError)||!Me(l)||!("trustedTypes"in globalThis))return;Mn=!0;let i="function"==typeof Oe()?.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'). ${i}\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 Tn=new WeakMap;function Pn(e,t,n){let l=e[t],i=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===i)return;let r=Tn.get(e);void 0===r&&Tn.set(e,r=new Set),!r.has(t)&&(r.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${i}. 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 En={name:"diagnostics",install(){c.Ao=$n,c.Fo=pn,c.yo=jn,c.detail=Pn,c._e=f(c._e,Cn),c.ie=f(c.ie,(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,i]=n[0];if(!l.endsWith(".*")||!i.endsWith(".*"))return;let r=l.slice(0,-2),o=i.slice(0,-2),s=`.${i}`,a=`${r}.**`,u=xn(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===`.${o}`||e.startsWith(`.${o}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${o}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${On(s)})+$`).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 "${i}"). Rename one of them.`);let t=new RegExp(`^${On(l)}(?:${On(s)})*${On(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){bn.delete(e),vn.has(e)&&Nn(e)}(e)})}},Wn={},In=/\.\d/,Rn=new Set(Object.getOwnPropertyNames(Object.prototype)),Ln=0,qn=!1,Dn=null,zn=()=>{qn=!1,Ln++};function Un(){if(null===Dn)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=zn,e.port1.unref?.(),Dn=()=>e.port2.postMessage(0)}else Dn=()=>setTimeout(zn,0);return qn||(qn=!0,Dn()),Ln}function Fn(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.Ae){for(let l of t)if(n.G(l)&&(n.n===l.n||!(l.n<e.n&&e.c[l.n+1].G(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Bn=class{constructor(e,t){this.active=!1,this.ze=new Map,this.n=0,this.$o=-1,this.Cn=new Set,this.$e=null,this.engine=e,this.rt=t}Zo(){let e=this.engine;this.ze.clear();for(let t of this.rt)t.getter=null!==t.p.getter||t.p.ke,t.l=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.l.set(Wn,e.v(t.p,null)):this.In(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.l.set(n,e.v(t.p,n)))})});this.active=!0}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.tt?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}No(){this.active=!1,this.ze.clear()}In(e,t,n,l){let i=this.engine.De(n,e.c[t]);for(let n of i.f)t===e.n?l(n):this.In(e,t+1,n,l)}ln(e,t,n,l){let i=this.ze.get(e);void 0===i&&this.ze.set(e,i=new Map);let r=i.get(t);void 0===r?i.set(t,[n,this.n,l]):(r[1]<this.n&&(r[1]=this.n),r[2]||=l)}pe(e,t,n,l,i){if(this.active){(this.$e??=new Set).add(e);for(let r of this.rt){let o=r.p;o.n!==e.n||!o.G(e)||this.ln(r,t,r.getter?r.l.get(t??Wn):o===e&&i&&this.engine.jt&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}}me(e,t){if(this.active)for(let n of this.rt)(n.getter||=null!==n.p.getter||n.p.ke)&&n.p.n===e.n&&n.p.G(e)&&this.ln(n,t,n.l.get(t??Wn),!1)}Kt(e,t){if(!this.active)return;let n=null;for(let l of this.rt){let i=l.p;if(!(i.n<e.n||i.c[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.ln(l,t,void 0,!0):this.In(i,e.n+1,t,e=>this.ln(l,e,void 0,!0)))}}}Pe(){let e=this.$e;if(this.$e=null,!this.active||0===this.ze.size)return;let t=this.ze;this.ze=new Map;let n=this.engine,l=[];for(let i of this.rt){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.d);s.length>1&&s.sort((e,t)=>Hn(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.h;this.n=a+1,n.Ee++;try{if(s=n.v(i.p,t),i.getter&&(i.l.set(t??Wn,s),Object.is(s,r)&&(In.test(i.t)||null!==t&&!u&&!(o??=null!==e&&Fn(_n(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.h=t,c.tt?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.D(t))}catch(e){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),c.tt?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.h=h,this.n=0,n.Ee--}}}l.length>0&&this.xo(l)}xo(e){let t=Un();t!==this.$o&&(this.$o=t,this.Cn.clear());let n=e.filter(e=>!this.Cn.has(e));if(0!==n.length){for(let e of n)this.Cn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.tt?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function _n(e){for(;null===e.getter&&null!==e.w;)e=e.w;return e}function Hn(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.s.te)n.unshift(t.b);for(let e=t;null!==e;e=e.s.te)l.unshift(e.b);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 Kn="$streamStatus",Vn="$streamError",Jn=new Set(Object.getOwnPropertyNames(Object.prototype)),Xn=!1;function Gn(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 Yn=class{constructor(e,t,n){this.jn=0,this.engine=e,this.entries=t,this.X=n}set(e,t,n){Xn=!0;try{this.engine.P(this.engine.o(`${e}.${t}`),null,n)}finally{Xn=!1}}er(){for(let e of this.entries)this.start(e,!0)}tr(){for(let e of this.entries)e.it=!1,e.z?.abort(),e.z=null}nr(){for(let e of this.entries)e.it=!1,null!==e.z&&(e.z.abort(),e.z=null),this.set(Kn,e.name,"idle")}me(e){let t=Math.max(this.X.n,this.jn);for(let n of this.entries)n.g===e&&(n.n=n.it?Math.max(n.n,t):t,n.it=!0)}Pe(){let e=this.engine,t=this.X,n=[];for(let i of this.entries){if(!i.it)continue;let r=i.n;if(i.it=!1,r>32)n.push(i.name),i.g.ee=l;else{t.n=r+1,e.Ee++;try{this.start(i,!1)}finally{e.Ee--,t.n=0}}}n.length>0&&t.xo(n)}start(e,t){let n,i=this.engine;if(null!==e.z&&e.z.abort(),e.z=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.Ae.slice();Qn(r);try{n=i.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.Ae)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Kn}.${e}`||n.t===`${Vn}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Qn(r);for(let e of o)e.Ln(r);if(r.ee=l,t)throw n;return this.set(Vn,e.name,n),void this.set(Kn,e.name,"error")}}let r=new AbortController;e.z=r,i.P(i.o(e.name),null,e.W),this.set(Vn,e.name,null),this.set(Kn,e.name,"active"),this.or(e,r,n)}async or(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.z===t,o=l.o(e.name),s=this.X.n,a=Un(),u=e.W;try{let t=await e.source(n,i);if(!r())return;let c=t=>{u=void 0!==e.Ro?e.Ro(u,t):t,this.jn=Un()===a?s:0;try{l.P(o,null,u)}finally{this.jn=0}};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(i.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!r())return;if(t.done)break;c(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(i.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!r())return;if(t.done)break;c(t.value)}}}if(!r())return;e.z=null,this.set(Kn,e.name,"done")}catch(n){if(!r())return;e.z=null,t.abort(),this.set(Vn,e.name,n),this.set(Kn,e.name,"error")}}};function Qn(e){for(let t of e.Ae){let n=t.at.indexOf(e);n>=0&&t.at.splice(n,1),t.Pt.delete(e)}e.Ae.length=0,e.ee=t}var Zn=new WeakMap;function el(e){let t=Zn.get(e);return t?.target===e.target?t:void 0}function tl(e,t){let n=new Bn(e,function(e,t){if(void 0===t)return[];(null===t||"object"!=typeof t)&&v("$watch must be an object mapping paths to handler functions.");let n=[];for(let l of Object.keys(t)){let i=t[l];(""===l||"$"===l[0]||l.includes("@")||Rn.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 r=e.o(l);c.yo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,l:new WeakMap})}return n}(e,t.$watch)),l=new Yn(e,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=[],i={},r={};for(let o of Object.keys(n)){let s=n[o];(""===o||"$"===o[0]||/[.*]/.test(o)||Jn.has(o))&&v(`$stream entry "${o}" must be a flat property name.`),(null===s||"object"!=typeof s)&&v(`$stream entry "${o}" must be an object.`);let a=s.source,u=s.fold,c=s.args,f=s.initial;"function"!=typeof a&&v(`$stream entry "${o}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${o}": fold must be a function.`),void 0!==u&&!("initial"in s)&&v(`$stream entry "${o}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${o}": args must be a function.`),Gn(t,o)&&v(`$stream entry "${o}" collides with a getter, setter or method of the state.`),void 0===t[o]&&(t[o]=f),i[o]="idle",r[o]=null,l.push({name:o,source:a,Ro:u,W:f,z:null,it:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[Kn]=i,t[Vn]=r,l}(e,t),n),i=Zn.get(e);void 0!==i&&(i.X.No(),i.Nt.tr()),Zn.set(e,{X:n,Nt:l,Ke:i?.Ke??!1,target:t})}function nl(e,t){let n=Zn.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Ke="connected"===t),n.target===e.target)){if("disconnected"===t)return n.X.No(),void n.Nt.nr();n.Ke&&(n.X.Zo(),n.Nt.er())}}var ll=["$streamStatus","$streamError"],il={name:"temporal",install(){c.ie=f(c.ie,tl),c.element=f(c.element,nl),c.pe=f(c.pe,(e,t,n,l,i,r)=>el(e)?.X.pe(t,n,l,i,r)),c.me=f(c.me,(e,t,n)=>{let l=el(e);void 0!==l&&(l.X.me(t,n),l.Nt.me(t))}),c.Kt=f(c.Kt,(e,t,n)=>el(e)?.X.Kt(t,n)),c.Pe=f(c.Pe,e=>{let t=el(e);void 0!==t&&(t.X.Pe(),t.Nt.Pe())}),c.Ut=h(p,c.Ut,(e,t)=>{let n=t.split(".",1)[0];if(ll.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Re=h(d,c.Re,(e,t)=>(!Xn&&36===t.t.charCodeAt(0)&&ll.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},rl=new WeakMap,ol=!1,sl=/^(?!prototype$)[^\d.*$][^.*]*$/;function al(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 i=n[t];"string"==typeof i?l.set(e.o(t),e=>e[i]):"function"==typeof i?l.set(e.o(t),i):v(`$listKeys "${t}" must be a field name or a function.`)}}rl.set(t,l)}function ul(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function cl(e,t,n){let l=new Map;for(let i of t){ul(i)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(i);null==t&&v(`$listKeys "${e}": a row has no key.`),l.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),l.set(t,i)}return l}function fl(e,t,n,l){if(ol||!Array.isArray(l))return!1;let i=rl.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.zt(t,n);if(!Array.isArray(r)||r===l)return!1;let o=cl(t.t,r,i);cl(t.t,l,i);let s=[],a=[],u=r.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=o.get(i(t));s.push(n??t),void 0!==n&&a.push([e,n,t]),s[e]!==r[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){ol=!0;try{e.P(t,n,s)}finally{ol=!1}}if(c.length>0){let l=e.De(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=sl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.P(s,o,r):(o.O[i]=r,e.P(e.o(`${t.t}.*`),o,o.O,!0))}}return!0}var hl={name:"list-keys",install(){c.ie=f(c.ie,al),c.Re=h(d,c.Re,fl)}},dl=new WeakMap,pl=new WeakMap,ml=new WeakMap,gl="will not graft: the root state failed to initialize.",yl=new WeakSet,$l=new WeakMap,vl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],bl=["$commandTokens","$eventTokens","$on","$errorCallback"],wl=e=>`[@wcstack/state] <${le.tagNames.state} mount="${e}">`,kl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Sl=e=>e?.element?.isConnected?e:void 0;function xl(e){let t=ml.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function Al(e,t){dl.set(t,e);let n=ml.get(t);if(ml.delete(t),Array.isArray(n))for(let t of n)Ol(t,e)}function Nl(e,t){console.error(`${wl(e.t)} ${t}`),function(e){let t=pl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}(e),e.Xe?.(),e.Xe=null}function jl(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 Ol(e,t){if(yl.has(t))return Nl(e,"will not graft: its component is wired to its host.");let n=e.state,l=t.target,i=e.t.split("."),r=l;for(let e of i)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return Nl(e,`will not graft: the root state already has "${e.t}".`);let o=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 i=e.proxy[l];return"$eqPath"===l?(e,t)=>i(n(e),n(t)):kl.has(l)&&"function"==typeof i?(e,...t)=>i(n(e),...t):i},set:(t,l,i)=>"symbol"!=typeof l&&(e.proxy[n(l)]=i,!0)})}(t,e.t);e.chroot=o;let s={},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:i,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==l||void 0!==i)a[`${e.t}.${n}`]={get:l&&function(){return l.call(o)},set:i&&function(e){i.call(o,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(o);a[`${e.t}.${n}`]={get:()=>t}}else s[n]=r}}if(void 0===r){for(let e=1;e<i.length;e++){let n=t.o(i.slice(0,e).join("."));null==t.zt(n,null)&&t.P(n,null,{})}t.P(t.o(e.t),null,s)}t.Yn(Object.defineProperties({},a));for(let e in a)t.$e(t.o(e),null);e.engine=t;let c=$l.get(t);void 0===c&&$l.set(t,c=[]),c.push(e.t),e.el.isConnected&&jl(e,"$connectedCallback"),e.Xe?.(),e.Xe=null}function Ml(e,t){let n=ml.get(e);if(Array.isArray(n))for(let e of n)Nl(e,gl);ml.set(e,t)}var Cl=new WeakMap;function Tl(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,Xe:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(le.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=pl.get(t);void 0===e&&pl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Sl(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=ml.get(t);Array.isArray(e)&&ml.set(t,e.filter(e=>e!==r)),r.Xe?.(),r.Xe=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{vo:!0,start(e){if(null!==i)return Nl(l,i);if(pl.get(t).get(n)===l){for(let t of vl)if(void 0!==e[t])return Nl(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of bl)void 0!==e[t]&&console.warn(`${wl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Xe=e;let n=Sl(dl.get(t))??Sl(It.get(t)),i=ml.get(t);void 0!==n?Ol(l,n):xl(t)?Nl(l,gl):ml.set(t,[...Array.isArray(i)?i:[],l])})}},Ke(){null!==l.engine&&jl(l,"$connectedCallback")},On(){null!==l.engine&&jl(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 Pl=new WeakMap,El=new WeakMap;function Wl(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 Il(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 i=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 i=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),r=Wl(l,"$bindables"),o=Wl(l,"$commands");for(let e of r){let t=i.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 o){let t=i.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 s={tag:e,bindables:r},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 i=l.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(le.tagNames.state);return a.set(l,o),Pl.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${le.tagNames.state}>: no change events.`),o},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===r.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"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,i,t)},Ke(){},On(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Rl=new WeakMap,Ll=new WeakSet,ql=new WeakMap,Dl=new WeakMap,zl="data-wcs-wired",Ul=new WeakMap,Fl=new WeakMap,Bl=new WeakMap,_l=0,Hl=new Set,Kl={},Vl=["$watch","$stream","$renderedCallback"],Jl=e=>e.split(".",1)[0];function Xl(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Gl(e,t){let n=e.a,l=Jl(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(zl);else if(!Ql(n,l)){let e=n.getAttribute(zl)?.split(" ")??[];e.includes(l)||n.setAttribute(zl,[...e,l].join(" "))}Ul.get(n)?.ce===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 i=Rl.get(n);void 0===i&&Rl.set(n,i=[]),i.push(e),t&&Ll.add(e);let r=ql.get(n);return void 0===r&&ql.set(n,r=new Map),r.has(l)||r.set(l,n[l]),Dl.get(n)?.(),!1}function Yl(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${le.tagNames.state}[bind-component]`)}function Ql(e,t){let n=e.getAttribute(le.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}var Zl=new Set;function ei(e,t){Zl.has(e)||(Zl.add(e),console.warn(`[@wcstack/state] ${t}`))}var ti=(e,t)=>t in e.state;function ni(e,t){let n=li(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function li(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 ii(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=Jl(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.w)return function(e,t){let n,l=t.w;for(;null!==l&&void 0===(n=e.st.get(l));)l=l.w;if(null===l||void 0===n)return;let i=e.x,r=e.host.engine,o=r.o(n.p.t+t.t.slice(l.t.length));if(null===o.getter)return;let s=n,a=()=>{let n=ri(e,s.r);return 0===t.n?n:(r.resolve(Xl(o.t,[...r.D(n),...i.D(ee(i.h,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.Z&&(t.Z=n=>{let l=a();oi(e,s.e,()=>r.P(o,l,n)),e.an=t}),t.n>0&&(t.A=i.Oe++),e.st.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.E!==o?ti(i,o):ni(i,o))return;l=s.ue}else{if(null===t||null!==n.w||"$"===o[0]||ti(i,o))return;s=t,l=r.o(`${t.ue.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,ri(e,a)),n.Z=t=>{oi(e,u,()=>r.P(l,a,t)),e.an=n},e.st.set(n,{e:s,p:l,r:a})}function ri(e,t){return null!==t&&!t.d&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function oi(e,t,n){let l=Hl.has(e.x);Hl.add(e.x),e.from=t;try{n()}finally{l||Hl.delete(e.x),e.from=null}}var si=(e,t)=>t||!Hl.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function ai(e,t){if(e.cn===t||null===e.host.engine)return;e.cn=t,_l+=t?1:-1;let n=e.host.engine,l=Bl.get(n);void 0===l&&Bl.set(n,l=new Map);for(let n of e.se){let e=l.get(n.e.ue);void 0===e&&l.set(n.e.ue,e=new Map);let i=e.get(n.e.r);void 0===i&&e.set(n.e.r,i=new Set),t?i.add(n):(i.delete(n),0===i.size&&e.delete(n.e.r))}let i=e.host.entries.find(e=>""===e.E);if(void 0!==i){null===e.Q&&function(e,t){let n=e.host,l=n.engine;e.Q=new Map;let i=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let o of Object.getOwnPropertyNames(r)){if(i.has(o))continue;i.add(o);let s=Object.getOwnPropertyDescriptor(r,o);if(void 0===s.get&&void 0===s.set||"$"===o[0]||o.includes("*"))continue;let a=Jl(o);if(o!==a&&!ti(n,a))continue;let u=l.o(`${t.ue.t}.${o}`);if(null===u.getter)fi(l,u,t.ue);else if(!ui.has(u.getter))continue;e.Q.set(u,e.x.o(o))}}(e,i);for(let l of e.Q.keys())t&&null===l.getter&&fi(n,l,i.ue),n.R.xe(n,l,i.r);e.Q.size>0&&n.Ne(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.Q){let r=n.v(l.w,t.r);if(null===r||"object"!=typeof r||!(l.l in r))continue;let o=e.host.el.localName;ei(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.ce}.${i.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,i)}}var ui=new WeakSet;function ci(e,t,n,l){let i=Bl.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.E||!0!==e.m.Q?.has(l)||e.m===r||(null!==r&&v(`[wcs/mount-export-ambiguous] "${l.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function fi(e,t,n){let l=t.w,i=t.l,r=()=>{let t=e.read(l,e.h);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=ci(e,n,e.h,t);return null===o?void 0:o.x.read(o.Q.get(t),null)},ui.add(t.getter),t.Z=o=>{let s=null===r()?ci(e,n,e.h,t):null;if(null===s){let t=e.read(l,e.h);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.Q.get(t);void 0===li(s.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${s.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),s.x.P(a,null,o)},t.n>0&&(t.A=e.Oe++)}function hi(e,t,n,l,i,r){if(null!==t.getter)return e.R.xe(e,t,n),void e.Ne();if("*"===t.l){if(null===n)return;if(n.O=n.s.Y[n.b],e.R.Ht(n),null!==n.u)for(let t of n.u.values())e.q(t)}else e.wn(t,n);c.pe?.(e,t,n,l,i,r),e.$e(t,n)}function di(e){let t=e.m.x;for(let[n,l]of e.m.st)l.e===e.e&&(0===n.n?t.R.xe(t,n,null):t.Jt(n.c[n.n],e=>t.R.xe(t,n,e)));t.Ne()}function pi(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return di(e);let a,u=e.m,c=u.x;if(""===e.e.E){a=s.slice(1);let e=Jl(a);if("$"===e[0]||ti(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ee(l,e).b);c.resolve(Xl(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||hi(c,h,d,i,r,o)}function mi(e,t,n,l,i,r,o){if(0===_l)return;let s=Hl.has(e);Hl.add(e);try{let s=Fl.get(e);!o&&void 0!==s&&s.cn&&!Hl.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.st.get(s));)s=s.w;if(null===s||void 0===o)return;let a=e.host.engine;if(s===t&&e.an===t)return void(e.an=null);if(null!==o.r&&!o.r.d)return;let u=[...a.D(o.r),...e.x.D(n)];a.resolve(Xl(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||oi(e,o.e,()=>hi(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.cn&&null!==s.Q&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[i,r]of e.Q)r===t&&(l.R.xe(l,i,n.r),l.Ne())}(s,t);let a=Bl.get(e);if(void 0===a)return;for(let[e,s]of a)if(t.G(e)){let a=s.get(0===e.n?null:ee(n,e.n));if(void 0!==a)for(let s of[...a])si(s,o)&&pi(s,e,t,n,l,i,r)}else if(e.G(t))for(let[e,l]of[...s])if(0===t.n||ee(e,t.n)===n)for(let e of[...l])si(e,o)&&di(e)}finally{s||Hl.delete(e)}}async function gi(e,t){ai(e,!0);for(let t of e.se)di(t);t?.(),!e.broken&&(await e.x.ae("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function yi(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.U||void 0!==n&&n!==e&&n.isConnected)){Ml(t,e);for(let e of Cl.get(t)??[])e()}}),null}(e,t);let l=e.parentNode,i=l instanceof ShadowRoot,r=i?l.host:l instanceof Element?l:null,o=()=>{let t=null===r?void 0:Ul.get(r)?.F;return t?.el===e?t:null},s=t=>{throw i&&Ml(l,e),t};return{Ct:()=>(null!==r&&r.localName.includes("-")?async function(e,t,n,l){let i=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 <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let r=Ul.get(n);if(void 0!==r)return r.ce!==t&&v(`<${i}> already has a <${le.tagNames.state} bind-component="${r.ce}">.`),r.state;let o=()=>(Rl.get(n)??[]).filter(e=>Jl(e.name)===t);if(0===o().length&&(Ql(n,t)||((e,t)=>!0===e.getAttribute(zl)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{Dl.set(n,l),e=function(e,t){xl(e)&&t();let n=Cl.get(e)??new Set;return Cl.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>r(new Error(`[@wcstack/state] <${i}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Dl.delete(n);let s=o(),a=ql.get(n),u=void 0!==a&&a.has(t)?a.get(t):n[t];if((null===u||"object"!=typeof u)&&v(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===u?"null":typeof u}.`),0===s.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${le.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Kl}let c=[];for(let e of s){let l=e.name===t?"":e.name.slice(t.length+1);c.some(e=>e.E===l)&&v(`<${i}> maps "${e.name}" twice.`);let r=l.split(".").indexOf("*");if(r>=0){let n=l.split(".").slice(0,r).join(".");v(`<${i}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}c.push({E:l,ue:e.o,r:e.r,ro:Ll.has(e)}),e.engine.kn(e),""!==l&&delete n[e.name]}let f=0===s.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}(u):u;return Ul.set(n,r={el:n,ce:t,state:f,engine:0===s.length?null:s[0].engine,entries:c,F:null}),f}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${le.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){let a=!1;await async function(e,t,n,l,i){if(l===Kl)return;let r=y(l);r&&await r;let o=Ul.get(t);o.engine&&l.$recursion&&v(`[wcs/mount-dollar-declaration] <${t.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let s=o.F;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${le.tagNames.state} bind-component="${o.ce}">.`),null!==s&&ai(s,!1),null!==s&&function(e,t,n){let l=e.x,i=`[${le.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,s=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.Pn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.re.values())for(let t of e)if(null===t.B)s(t.a);else for(let e of t.B.K)a(t.B,e.S);for(let e of l.oe.values())for(let t of[e.$,...e.j??[]])null!==t&&a(t,t.S);for(let t of e.I)t.parentNode===n&&r(t)&&o.add(t);if(0===o.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!o.has(n)&&!e.I.includes(n)&&(r(n)||l.It&&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}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.I=e.I.filter(e=>e.parentNode===n),t.isConnected?await gi(e,l):l()}(s,e,n,i);let a=new ne(l,new _t);a.element=e,e.engine=a,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.U=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:l})),t}}(a,l);let u={el:e,I:[],x:a,host:o,se:[],st:new Map,cn:!1,an:null,from:null,Q:null};for(let e of o.entries)u.se.push({m:u,e});o.F=u,Fl.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.x,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=Jl(e.E);ti(n,t)&&(e.E!==t||ni(n,t))&&ei(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.ce}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.ue,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.E===t)&&ei(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.ue.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Vl.filter(e=>void 0!==n.state[e]);o.length>0&&ei(`${i}.${n.ce}$`,`[wcs/mount-dollar-declaration] <${i}>: ${o.join(", ")} ${1===o.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let s=t.Ze;t.Ze=n=>{ii(e,r,n),s.call(t,n)};let a=[...t.L.all()];for(let t of a)ii(e,r,t);for(let e of a)s.call(t,e);let u=n.entries.filter(e=>null!==e.r);if(u.length>0){let e=t._t;t._t=()=>{u.every(e=>e.r.d)&&e.call(t)}}}(u),ai(u,!0),yl.add(a),Al(a,n));let h=c.ir?.(n);Rt(a,n),h?.(),u.I=[...n.childNodes],Bt(),f&&a.bn(),Object.defineProperty(t,o.ce,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.ce);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.ae("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):ai(u,!1)}(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Ke(){let e=o();null!==e&&gi(e).catch(e=>console.error(e))},On(){let e=o();null!==e&&(ai(e,!1),!e.broken&&(e.x.ae("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var $i={name:"scopes",install(){c.ot=h(m,c.ot,Tl),c.ot=h(m,c.ot,Il),c.ot=h(m,c.ot,yi),c.Jo=Gl,c.wo=Yl,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return;let n=e.element.getRootNode();Al(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:Pl.get(n);void 0!==l&&El.set(e,{host:n,def:l})}(e,n)}),c.pe=f(c.pe,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=El.get(e);if(void 0===i)return;let r=t.t.split(".",1)[0];if(!i.def.bindables.includes(r))return;let o=l&&t.t===r;i.host.dispatchEvent(new CustomEvent(`${i.def.tag}:${r}-changed`,{detail:o?n:void 0,bubbles:!0}))})(e,t,i,r),mi(e,t,n,l,i,r,!1)}),c.me=f(c.me,(e,t,n)=>mi(e,t,n,void 0,void 0,!1,!0)),c.Re=h(d,c.Re,(e,t,n,l,i)=>(function(e,t){let n=$l.get(e);if(void 0!==n&&0===t.n)for(let 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,i=Fl.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.w)l=i.st.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.d)&&!r.ro)&&(!!n||(ri(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.ce}${""===r.E?"":`.${r.E}`}#ro: ${r.ue.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.ie;c.ie=(t,n)=>{let l=$l.get(t);void 0!==l&&l.length>0&&v(`re-setting a root state with grafted volumes (${l.join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Bl.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&v("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},vi="$recursion",bi=new WeakMap,wi=new WeakSet,ki=new WeakSet,Si=0,xi=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ai=e=>`[wcs/recursion-${e}]`;function Ni(e,t){let n=n=>v(`${Ai("declaration-invalid")} ${vi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${Ai("declaration-invalid")} ${vi} ${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 ji=(e,t)=>`${e.s}.*${e.step.repeat(t)}`;function Oi(e,t){let n=`${e.s}.**`,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.s}.*".`),l}function Mi(e,t,n){let l=Oi(e,t),i=function(e,t){for(let n=t;null!==n;n=n.s.te){let t=e.nodeList.exec(n.s.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===i&&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.`),ji(e,i.k)+l}function Ci(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${Ai("cycle")} "${n}" is reachable from itself: the data under "${t.s}" must be a tree.`),i.has(e)&&v(`${Ai("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.s}" must be a tree.`),r+1>128&&v(`${Ai("depth-exceeded")} Recursion on "${t.s}.*" reached depth ${r+1} (the limit is 128).`),i.add(e),0)),o=(i,s)=>{for(let a of i){n(s,a);let i=e.o(`${ji(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.De(a,i).f,s+1),l.delete(u))}},s=e.o(t.s),a=e.read(s,null);r(a,t.s,0)&&(l.add(a),o(e.De(null,s).f,0))}function Ti(e,t){let n=function(e){let t=e[vi],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&&z(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${Ai("declaration-invalid")} ${vi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${Ai("declaration-invalid")} ${vi} must declare exactly one anchor (it declares ${i.length}).`);let r=Ni("anchor",i[0][0]),o=Ni("repeat",i[0][1]),s=r.slice(0,-2),a=o.slice(0,-2),u=`.${o}`,c=new Map,f=[],h=`${s}.**`;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 "${r}").`),(""===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(`${Ai("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${xi(r)}((?:${xi(u)})*)${xi(n)}$`),n])}return{s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${xi(s)}((?:${xi(`.*.${a}`)})*)$`)}}(t),l=bi.has(e);null!==n?(l||Si++,bi.set(e,n),ki.add(e),wi.has(e)||function(e){wi.add(e);let t=e,n=t.Ze;t.Ze=l=>{let i=bi.get(e);if(l.t.includes("**")){let t=e.L.At(l.t)===l;return void(ki.has(e)||void 0===i&&t?l.getter=()=>z(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.A=t.Oe++),i.owners.set(l,i.s+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=bi.get(e);return l.call(e,void 0!==i&&t.includes("**")?Mi(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=bi.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,Mi(r,n,t.h));(!Array.isArray(l)||l.length>0)&&v(`${Ai("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=Oi(r,n),s=[];return Ci(e,r,(t,n)=>{for(let l of i.call(e,ji(r,t)+o,e.D(n)))s.push(l)}),s};let r=t.pn;t.pn=(n,l,i,o)=>{let s=bi.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||S(9,[n]),l.length>0&&v(`${Ai("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${Ai("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Ce>0&&S(8);let a=Oi(s,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(s.step);)u=u.slice(s.step.length);let c=s.key.split(".");(""===u||u===`.${s.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${Ai("structural-write")} "${n}" writes the recursion structure itself (a node, its "${s.key}" list or that list's length, or an object on the way to it).`);for(let e of s.families.keys()){let t=e;for(;t.startsWith(s.step);)t=t.slice(s.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${Ai("readonly")} "${n}" writes into the recursive getter "${s.s}.**${e}".`)}let f=[];Ci(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,ji(s,t)+a,e.D(n),i);return h}}(e)):l&&(bi.delete(e),Si--)}function Pi(e,t){if(0===Si)return!1;let n=bi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.w){let l=n.owners.get(e);void 0!==l&&v(`${Ai("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var Ei={name:"recursion",install(){c.ie=f(c.ie,Ti),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ki.delete(e)}(e)}),c.Re=h(d,c.Re,Pi)}},Wi="4.0.0-rc.1",Ii=e=>e.split(".").slice(0,2).join("."),Ri=class extends Xt{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 Ii(this.version)===Ii(Wi)}};function Li(e){let t=le.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Ri{})}var qi=()=>le.tagNames.ssr,Di=Symbol.for("wcstack.ssr.snapshotBuilder"),zi=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Ui=e=>document.createComment(e),Fi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Bi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),_i=new WeakMap,Hi=new WeakMap,Ki=new WeakMap,Vi=new WeakSet,Ji=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 Gi(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 Yi=e=>null===e.I?e.He:e.I[e.I.length-1];function Qi(e,t,n){let l=[Ui(null===n?"wcs-[":`wcs-[:${n}`)];for(let e of t)null===n&&l.push(Ui("wcs-|")),l.push(...Xi(e.He,Yi(e)));l.push(Ui("wcs-]")),e.after(...l);for(let e of l)Vi.add(e)}function Zi(e){if(e instanceof st){Qi(e.S,e.ve,null);for(let t of e.ve)er(t);return}let t=e.F;null!==t&&(Qi(e.K[e.K.length-1].S,[t],e.b),er(t))}function er(e){if(null!==e.u)for(let t of e.u)Zi(t)}var tr=new Set(["script","style","template","textarea","title"]),nr="data-wcs-raw",lr=e=>tr.has(e.localName)||e.localName===qi();function ir(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Ui("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Ui("wcs-s")):1===t.nodeType&&!lr(t)&&ir(t)}var rr=0;function or(e,t){let n=e.getRootNode(),l=[t];for(let e of Hi.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=_i.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.j)for(let e of t.j)n.set(e.S,e);for(let t of e.re.values())for(let e of t)if(null!==e.B)for(let t of e.B.K)n.set(t.S,e.B);let l=new Set;for(let[e,r]of t){i.set(e,r);let t=n.get(e);void 0!==t&&!l.has(t)&&e.isConnected&&(l.add(t),Zi(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ki.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Vi.has(e)||1===e.nodeType&&t.has(e)&&fr(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(lr(e.parentNode)?Ji.has(e):t.has(n)&&Bi(n,"wcs-t:"))&&(Ji.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);lr(e)&&n.some(e=>Ji.has(e))&&e.setAttribute(nr,n.map(e=>Ji.has(e)?`{{ ${Ji.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}ir(9===n.nodeType?n.body:n);let r=document.createElement(qi());r.setAttribute("version",Wi);let o=document.createElement("script");o.type="application/json",o.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)),r.append(o);for(let[e,t]of i){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,i=`wcs-${l?"s":"t"}${rr++}`;e.replaceWith(Ui(`wcs-p:${i}`));let o=document.importNode(Mt(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Gi(e,document.createElement("template"),...e.childNodes));if(l){let e=document.createElementNS(n.namespaceURI,"svg");e.append(o),o=e}let s=document.createElement("template");s.id=i,r.append(Gi(t,s,o))}e.before(r)}function sr(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=>Ji.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===qi())continue;let e=t.engine;null!=e&&or(t,e)}}var ar=Symbol.for("wcstack.state.ssr.impl"),ur=new Map,cr=new WeakMap,fr=e=>!0===c.wo?.(e),hr=e=>1===e.nodeType&&!lr(e)&&!fr(e),dr=e=>e.f.flat().concat(e._??[]),pr=e=>{for(let t of dr(e))t.remove()};function mr(e,t,n){let l=/^wcs-\[(?::(\d+))?/.exec(e.data),i=e.previousSibling,r=e.parentNode,o=[],s=e.nextSibling;for(e.remove();null!==s&&!Fi(s,"wcs-]");){let e=s.nextSibling;if(Fi(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];Bi(s,"wcs-[")?e=mr(s,t,n):(n.push(s),hr(s)&&gr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,_:s??r.appendChild(Ui("wcs-]"))},u=dr(a);s=a._.nextSibling;for(let e of u)n?.push(e),t&&Nt.add(e);return t&&null!==i?ur.set(i,a):pr(a),s}function gr(e,t){for(let n=e.firstChild;null!==n;)Bi(n,"wcs-[")?n=mr(n,t):(hr(n)&&gr(n,t),n=n.nextSibling)}function yr(e,t,n){let l=e=>{for(let i of Array.from(e.childNodes))if(i.parentNode===e)if(8===i.nodeType){let e=i.data;try{if("wcs-s"===e)i.remove();else if("wcs-e"===e)i.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Ui(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!Fi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),i.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=i.parentNode,l="s"===e[10]?Gi(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);l.removeAttribute("id"),t.replaceChild(l,i)}}}catch{}}else 1===i.nodeType&&!lr(i)&&(fr(i)?cr.set(i,{ssr:t,Te:n}):l(i))};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||xr(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Bi(e,"wcs-[")?l++:Fi(e,"wcs-]")&&--l<0&&(l=0,n=t+1)}),0===l)continue;let i=0;for(let l=t.firstChild;null!==l;l=l.nextSibling)if(Bi(l,"wcs-["))i++;else if(Fi(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),gr(e,n)}function $r(e){let t=cr.get(e);if(void 0===t||(cr.delete(e),yr(e,t.ssr,t.Te),!t.Te))return null;let n=c.Te;return c.Te=jr,()=>{c.Te=n,vr()}}function vr(){for(let e of ur.values())pr(e);ur.clear()}function br(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function wr(e,t,n,l){let i=null;for(let l of e){let e=l[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===i||e.length>i[n].length)&&(i=l)}let r=i?.[l];if(null==r)return null;let o=i[n],s=""===o?t:t.slice(o.length+1);return""===r?s:""===s?r:`${r}.${s}`}function kr(e,t,n){if(zi()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Vi.add(e);else if(e.localName.includes("-")&&!fr(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ki.set(e,t)}return}if("string"==typeof n){if(Ji.set(t,n),lr(t.parentNode))return;let e=Ui(`wcs-t:${encodeURIComponent(n)}`),l=Ui("wcs-/t");return t.before(e),void t.after(l)}let l=_i.get(e);void 0===l&&_i.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Hi.get(i);return void 0===r&&Hi.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&ur.size>0){let e=ur.get(n);void 0!==e&&(ur.delete(n),ur.set(t,e))}}var Sr=e=>null!==e&&8===e.nodeType&&[le.commentIfPrefix,le.commentElseIfPrefix,le.commentElsePrefix].includes(e.data),xr=e=>3===e.nodeType&&""===e.data.trim(),Ar=e=>(ur.get(e)?._??e).nextSibling;function Nr(e,t){if(t.length!==e.nn.childNodes.length)return!1;let n=e.Rn;for(let l=0;l<n.length;l++){let i=n[l],r=e.nn,o=t[i[0]];for(let e=0;;){if(r=r.childNodes[i[e]],o?.nodeName!==r.nodeName)return!1;if(++e===i.length)break;o=o.firstChild;for(let t=i[e];t>0&&null!==o;t--)o=Ar(o)}e.ho[l]=o}return!0}function jr(e,t,n){if(0===ur.size)return null;let l=t,i=0;if(!n){let e=le.commentIfPrefix;if(!Fi(t,e))for(let n=t.previousSibling;null!==n&&(Sr(n)||xr(n))&&(Sr(n)&&i++,!Fi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!ur.has(l)&&null!==n&&!Fi(n,e)&&(Sr(n)||xr(n));n=n.nextSibling)Sr(n)&&(l=n)}let r=ur.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return ur.delete(l),pr(r),null;let o=r.f.shift();if(0===r.f.length&&ur.delete(l),r._?.replaceWith(...Xi(t,l)),r._=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=ur.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t._;)e++}if(!Nr(e,s)){let n=(e.Tn?e.root:e.nn).cloneNode(!0);s=e.Tn?[n]:[...n.childNodes],Nr(e,s),(o[0]??r.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of o)e.remove()}return s}var Or={name:"ssr",install(){c.An=kr,c.ir=$r;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||zi())return;let n=t.previousElementSibling,l=n?.localName===qi(),i=l?n.getAttribute("version"):null,r=null===i||Ii(i)===Ii(Wi);if(r){let t=e,n=t.ae;t.ae=(t,l)=>"$connectedCallback"===t?void 0:n.call(e,t,l)}if(!l)return;let o=!r&&parseInt(i)<4,s=/^3\.(\d+)\.(\d+)$/.exec(i),a=null!==s&&(+s[1]-5||+s[2]-3)>=0;r||console.warn(`[@wcstack/state] <${qi()} version="${i}"> does not match ${Wi}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!a?" 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 u=r?n.querySelector('script[type="application/json"]'):null;if(null!==u){let t=JSON.parse(u.textContent||"{}"),n=e.target;for(let e of Object.keys(t)){let l=Object.getOwnPropertyDescriptor(n,e);void 0!==l&&(void 0!==l.get||void 0!==l.set||"function"==typeof l.value)||(n[e]=t[e])}e.hydrated=!0}let f=t.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${nr}]`)))e.textContent=e.getAttribute(nr),e.removeAttribute(nr);let h=9===f.nodeType?f.body:f;o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!fr(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=i(t),r=t.querySelector(`:scope > ${le.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ae(t.getAttribute(le.bindAttributeName)??"")){let t=l.Ye;l.ye[0]===r&&n.push([e?wr(e,t,1,0):t,l.ye.slice(1).join("."),e&&t])}}return n},r=(e,t,n)=>{let l=i(e);if(null===l)return t;let r=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===r)return n?t:wr(l,t,0,1)??t;let o=r[1].replace(/#m\d+\./g,"").slice(0,-1);return l.some(e=>""===e[1]&&(e[0]===o||e[2]===o))?r[2]:wr(l,r[2],2,1)??r[2]};for(let t of br(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Fi(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]?[Ui(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of br(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let s=document.importNode(i,!0),a=le.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(h,n,a):yr(h,n,r),n.remove(),r&&(c.Te=jr,queueMicrotask(()=>{vr(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[ar]={build:sr,reset(){rr=0}},void 0===e[Di]&&(e[Di]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[ar].build(t),reset:()=>e[ar].reset()})}(),c.Eo=f(c.Eo,Li);for(let e of Qt())Li(e)}},Mr="__WCSTACK_DEVTOOLS_HOOK__",Cr=null,Tr=new Set,Pr=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.D(n)}}),Er=new WeakMap,Wr=0;var Ir=new WeakMap;function Rr(e){if(null===Cr)return;let t=Ir.get(e),n=Tr.has(e)?function(e,t){let n=new Map,l=new Set,i=(l,i,r,o,s,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,i),c=0===o.n?null:s,f=`${(e=>{let t=Er.get(e);return void 0===t&&Er.set(e,t=++Wr),t})(r)}|${u}|${o.t}|${null===c?"":e.D(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:o.t,bindingType:a,node:r,replaceNode:r},absoluteAddress:Pr(e,o,c)})},r=e=>i(e.i,e.name,e.a,e.o,e.r,e.Zt()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.de)for(let t of e.de)r(t);if(e instanceof Ye&&null!==e.se){let t=e.T.Ue;for(let n=0;n<t.length;n++){let l=e.U?.[n];void 0!==l?r(l):i(t[n].i,t[n].name,e.se[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)s(t)}},s=e=>{if(!l.has(e))if(l.add(e),e instanceof st){i(-1,"for",e.S,e.s.o,e.s.te,"for");for(let t of e.ve)o(t)}else null!==e.F&&o(e.F)};for(let t of e.re.values())for(let e of t)r(e),null!==e.B&&s(e.B);for(let t of e.oe.values())if(null!==t.$&&s(t.$),null!==t.j)for(let e of t.j)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||Cr({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&Cr({type:"state:binding-added",...l});Ir.set(e,n)}function Lr(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function qr(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.L.all()){for(let e=1;e<=r.n;e++)t.add(r.c[e].t);"*"===r.l&&n.add(r.t),null!==r.getter&&l.add(r.t),null!==r.Z&&i.add(r.t)}let r=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:l,setter:i},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.Se.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==r.$watch&&"object"==typeof r.$watch?new Set(Object.keys(r.$watch)):null,keyedListPaths:null!==r.$listKeys&&"object"==typeof r.$listKeys?new Set(Object.keys(r.$listKeys)):null}}var Dr=new WeakSet,zr=new WeakMap;function Ur(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Dr.has(t))return;Dr.add(t);let l=t.emit;t.emit=(...i)=>(null!==Cr&&Cr({type:"state:token-emit",kind:n,tokenName:t.name,args:i,subscriberCount:t.size,stateElement:e.element}),l.apply(t,i))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.Se.values())t(n,"event")}(e),"connected"===t){if(Tr.has(e))return;Tr.add(e),Cr?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Rr(e)}else"disconnected"===t&&(Tr.delete(e),Rr(e),Cr?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function Fr(e,t,n,l,i,r){if(null===Cr)return;let o=Pr(e,t,0===t.n?null:n),s=zr.get(e);void 0===s&&zr.set(e,s=new Set),s.add(o),r&&Cr({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function Br(e){if(null===Cr)return;let t=zr.get(e);zr.delete(e),void 0!==t&&Cr({type:"state:update-batch",addresses:t}),Rr(e)}function _r(e,t,n){Cr?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.Zt(),error:t})}!function(e){for(let t of e)g.has(t.name)||(g.add(t.name),t.install())}([on,En,il,hl,$i,Ei,Or,{name:"devtools",install(){c.element=f(c.element,Ur),c.pe=f(c.pe,Fr),c.Pe=f(c.Pe,Br),c._e=f(c._e,_r),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[Mr]??(e[Mr]=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!==t.version&&console.warn(`[@wcstack/state] devtools hook registry version ${t.version}, expected 2: keeping the existing one.`),t.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:Wi,getStateElements:()=>[...Tr].map(qr),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.L.all()){let l=n.H,i=n.Fe?.length??0;if((null===l||0===l.size)&&0===i)continue;let r,o=0;if(null!==l)for(let e of l.values())o+=e.size;try{r=0===n.n?e.v(n,null):void 0}catch{r=void 0}t.push({path:n.t,tracked:!1,rows:o,keys:null===l?0:l.size,lists:i,lastValue:r})}return t}(Lr(e)),keys(e){let t=Lr(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 Lr(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){Lr(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===Cr&&null!==e;Cr=e,null===e&&(Ir=new WeakMap),c.tt=e&&((e,t)=>Cr?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of Tr)Rr(e)})}})}()}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[qt]&&(e[qt]={protocol:"wcs-binder",version:1,bind:Ft})})(),Qt().includes(e)||Yt.push(new WeakRef(e));let t=le.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Gt{}),c.Eo?.(e)}();
|
|
1
|
+
var e=class{constructor(e,n,l){this.u=[],this.getter=null,this.Z=null,this.ke=!1,this.at=[],this.Ae=[],this.ct=null,this.A=-1,this.ee=t,this.Fe=null,this.xt=null,this.Rt=null,this.H=null,this.Pt=new Set,this.t=e,this.w=l,this.l=n;let i=null===l?[null]:l.c.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this._=r?[]:null===l?[n]:[...l._,n],this.c=i}Ln(e){this.Pt.has(e)||(this.Pt.add(e),this.at.push(e),e.Ae.push(this))}Po(){this.getter=null,this.Z=null,this.A=-1,this.ee=t,this.at.length=0,this.Pt.clear(),this.Ae.length=0,this.ct=null,this.Fe=null,this.xt=null,this.Rt=null,this.H=null}G(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.w}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.Tt=new Map,this.Bn=e}At(e){return this.Tt.get(e)}get(t){let n=this.Tt.get(t);if(void 0!==n)return n;let l=t.lastIndexOf("."),i=l<0?null:this.get(t.slice(0,l));return n=new e(t,t.slice(l+1),i),this.Bn?.(n),this.Tt.set(t,n),i&&i.u.push(n),n}all(){return this.Tt.values()}},r=new Map;function o(e){let t=r.get(e);if(void 0!==t)return t;let n=!0,l=e.split("."),i=[];for(let e=0;e<l.length;e++){let t=l[e],r=t.charCodeAt(0);e>0&&r>=48&&r<=57?(n=!1,i.push(Number(t)),l[e]="*"):"*"===t&&i.push(-1)}if(!n)return{o:l.join("."),indexes:i};let o={o:e,indexes:null};return r.set(e,o),o}var s=class{constructor(e,t,n){this.ut=null,this.$=null,this.de=null,this.H=null,this.u=null,this.d=!0,this.s=e,this.b=t,this.O=n}},a=class{constructor(e,t){this.Y=null,this.was=null,this.f=[],this.$=null,this.j=null,this.J=!1,this.Ft=!1,this.Ge=!1,this.o=e,this.te=t,this.n=e.n+1}},u=[],c={};function f(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function h(e,t,n){return null==t?n:(...l)=>{let i=t(...l);return e(i)?i:n(...l)}}var d=e=>!0===e,p=e=>void 0!==e,m=e=>null!=e,g=new Set;function y(e){let t=e.$features;if(null!=c.Ct&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Ct(e)}}function $(e,t){if(!g.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}function v(e,t,n){throw new Error(`[@wcstack/state] ${e}${c.Ao?.(e,t,n)??""}`)}var b=["","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"],w=e=>{let t=b[e/100|0];return t?`[wcs/${t}] `:""};function k(e,t=[]){return c.Fo?.(e,t)??`${w(e)}#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function S(e,t,n,l){v(k(e,t),n,l)}var x=class{constructor(e){this.dt=new Set,this.name=e}get size(){return this.dt.size}subscribe(e){return this.dt.add(e),()=>{this.dt.delete(e)}}unsubscribe(e){return this.dt.delete(e)}emit(...e){let t=[];for(let n of this.dt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${k(17,[this.name])}`,e)}return t}};function A(e,t,n){if(void 0===e)return[];Array.isArray(e)||S(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&S(19,[t]),i===n&&S(20,[t,i,n]),l.has(i)&&S(21,[t,i]),l.add(i);return e}var N=Symbol.for("wcstack.transition-runner");function j(e){let t=globalThis[N];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 O(e,t,n){let l=j(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var M="else",C="eventToken",T=/^\$[1-9]\d{0,2}$/,P=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function E(e){let t=[],n=[],l="",i=null,r=!1,o=-1,s=-1,a=e=>{let i=function(e,t,n){let l=-1===t?e.length:t,i=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,i+e.slice(i).trimEnd().length)}(l,o,s);(!e||i||r)&&(t.push(i),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:P.test(e)?Number(e):e)}(i,r))),l="",r=!1,o=-1,s=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=l.length),l+=n,s=l.length):'"'===n||"'"===n?(i=n,r=!0):","===n?a():l+=n}return null!==i&&S(107,[i,e]),a(!0),{args:t,literals:n}}var W=e=>e.trim();function I(e,t){let n=[],l=null;for(let i=0;i<e.length;i++){let r=e[i];null!==l?r===l&&(l=null):"'"===r||'"'===r?l=r:r===t&&n.push(i)}return n}var R=(e,t)=>I(e,t)[0]??-1;function L(e,t){let n=[],l=0;for(let i of I(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function q(e,t,n){let l=R(e,"|");if(-1===l)return[e.trim(),[]];let i=e.slice(l+1).trim(),r=n.get(i);return void 0===r&&(r=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>I(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&S(108,[e]),-1!==i&&-1===n&&S(109,[e]),-1!==i&&i<n&&S(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();S(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&S(112,[l]),r.includes("#")){let[,e]=r.split("#");S("input"===t?113:114,[r,e])}return-1===n?{Dn:r,args:[],literals:[]}:{Dn:r,...E(e.substring(n+1,i))}})}(L(i,"|").map(W),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var D=new Map;function z(e){S(1101,[e])}function U(e){let[t,n]=q(e,"output",D);t.includes("@")&&S(32,[t]);let l=t,i=l.startsWith("."),r=i?l.slice(1):l;return(r.length>0&&r.split(".").some(e=>0===e.length)||!i&&0===r.length)&&S(119,[e]),function(e){e.includes("**")&&z(e);let t=e.split(".").length;t>512&&S(117,[e,t])}(l),{Ye:l,Je:n}}var F=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],B=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],_=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&z(e),e}var K=0;function V(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var J=()=>new Set,X=()=>[];function G(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Y(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e.H?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e.H.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.s.n>t;)e=e.s.te;return null!==e&&e.s.n===t?e:null}function te(e,t,n){let l=ee(e,n);return null!==l&&l.s.o===t.c[n]?l:null}var ne=class{constructor(e,t){this.Oe=0,this.h=null,this.Ce=0,this.ft=new Set,this.root=null,this.Qe=new Map,this.Mn=Symbol("wcs.block"),this.element=null,this.pt=[],this.Ie=null,this.Wn=[],this.Bt=0,this.V=null,this.oe=new Map,this.re=new Map,this.je=[],this.Le=[],this.Be=[],this.mt=!1,this.un=!1,this.dn=new WeakMap,this.B=0,this.Dt=0,this.fn=!1,this.Mt=!1,this.Wt=!1,this.Ee=0,this._n=()=>{this.B=0,this.fn=!1},this.Hn=()=>{this.Ee--},this.rp=null,this.rr=null,this.Oo=()=>this._t(),this.Co=(e,t)=>e(this.proxy,...t),this.Vn=[],this.Io={$untracked:e=>{let t=this.V;if(null===t)return e();t.fe++;try{return e()}finally{t.fe--}},$eqIndex:(e,t=1)=>{let n=ee(this.h,t);null===n&&S(7,[e]);let l=this.o(e);if(null!==l.getter||l.ke)return this.watchIndex(t),n.b===this.read(l,null);let i=this.V;if(null!==i){let e=i.getter,n=l.Fe??(l.Fe=[]);if(!n.some(n=>n.getter===e&&n.Un===t)){n.push({getter:e,Un:t});let i=e.c[t];(i.xt??(i.xt=[])).push({source:l,getter:e})}}return n.b===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,ee(this.h,n.n)))},$dependOn:e=>{this.resolve(H(e),this.h),null!==this.V&&0===this.V.fe&&this.qn(this.rp,this.rr,this.V)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.pn(e,t,n,l),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],l=this.o(t);this.mn("$resolve",t,l,n,!0);let i=this.Kn(l,n,null);if(e.length<3)return this.read(l,i);this.P(l,i,e[2])},$postUpdate:e=>{this.resolve(H(e),this.h);let t=this.rp,n=this.rr;"*"===t.l&&null!==n&&(n.O=n.s.Y[n.b],this.R.Ht(n)),this.hn(t,n),null!==n&&n.s.Ge&&this.zn(n,t,void 0,n.O,!1),0===t.n&&this.Xn(t,void 0,void 0,!0),this.Vt(t,n,void 0,void 0,!1)}},this.R=t,this.L=new i(e=>this.Ze(e)),this.Gn(e);let n=this;this.proxy=new Proxy(e,{get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.Ut(t);if(t.indexOf(".")<0){let e=n.L.At(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return l===n.proxy&&n.U?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.h),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(H(t),n.h),n.P(n.rp,n.rr,l),!0)})}o(e){return this.L.get(e)}Yn(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 i=this.o(e);i.getter=l.get??null,i.Z=l.set??null,null!==i.getter&&i.n>0&&(i.A=this.Oe++)}for(let e of this.L.all())this.Ze(e)}Ze(e){e.t.includes("**")&&z(e.t),("__proto__"===e.l||"prototype"===e.l)&&S(120,[e.t]);let t=e.w;e.ke=null!==t&&"*"!==e.l&&t.n===e.n&&(null!==t.getter||t.ke),null===e.getter&&this.jo(e)}jo(e){let t=e.t,n=e.l;if(T.test(n))e.getter=function(){return this[n]};else{let n=t.split("."),l=n.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(l<0||n.indexOf("*",l)>=0)return;let i=n.slice(0,l).join("."),r=n.slice(l);e.getter=function(){let e=this[t];return void 0!==e?e:Z(this[i],r)},e.Z=function(e){this[t]=e}}e.n>0&&(e.A=this.Oe++)}De(e,t){let n=null===e?this.oe:e.u??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new a(t,e)),this.q(l),l}Jn(e){try{this.q(e)}catch(t){this.qt(t,e.o.t,e.$?.S??null,"for")}}q(e){let t=this.v(e.o,e.te),n=e.Y;if(t===n)return;e.was=n,this.Qn(e);let l=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.Y)return null;let i=e.f,r=l.length,o=i.length,a=new Array(r),c=0;for(;c<r&&c<o&&i[c].O===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].O===l[h];)a[h]=i[f],f--,h--;if(c>f)for(let t=c;t<=h;t++)a[t]=new s(e,t,l[t]);else if(c>h)for(let e=c;e<=f;e++)n.Ot(i[e]);else{let t=new Map;for(let e=c;e<=f;e++){let n=i[e],l=t.get(n.O);void 0===l?t.set(n.O,n):Array.isArray(l)?l.push(n):t.set(n.O,[l,n])}for(let n=c;n<=h;n++){let i,r=l[n],o=t.get(r);void 0!==o&&(Array.isArray(o)?(i=o.shift(),0===o.length&&t.delete(r)):(i=o,t.delete(r))),a[n]=i??new s(e,n,r)}for(let e of t.values())if(Array.isArray(e))for(let t of e)n.Ot(t);else n.Ot(e)}for(let e=c;e<r;e++){let t=a[e];t.b!==e&&(t.b=e,n.To(t))}return e.f=a,e.Y=l,i}(e,t,this);if(null===l)return;if(e.Y===t){let i=V(this.dn,t,X);if(i.push(e),i.length>1){for(let e of i)e.Ge=!0;if(i.some(e=>e.was!==n)){let t=this.o(`${e.o.t}.*`);for(let e of l)e.d&&this.$e(t,e)}}}c.Kt?.(this,e,l),(null!==e.$||null!==e.j)&&!e.J&&(e.J=!0,this.Le.push(e),this.Ne());let i=e.o.xt;if(null!==i)for(let{source:t,getter:n}of i){let i=this.v(t,null),r=l[i],o=e.f[i];r!==o&&(void 0!==r&&r.d&&this.gn(n,r),void 0!==o&&this.gn(n,o))}}To(e){this.R.Lo(this,e)}Ot(e){e.d=!1;let t=e.H;if(null!==t){for(let e of t)Q(e.source,e.key,e.sub);e.H=null}if(null!==e.u)for(let t of e.u.values()){this.Qn(t);for(let e of t.f)this.Ot(e)}}Qn(e){let t=this.dn.get(e.Y);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.Ge=!1,1===t.length&&(t[0].Ge=!1))}resolve(e,t){let n=o(e),l=this.o(n.o),i=n.indexes;this.rr=0===l.n?null:null===i?te(t,l,l.n):this.Kn(l,i,t),this.rp=l}Kn(e,t,n){let l=null;for(let i=1;i<=e.n;i++){let r=e.c[i],o=this.De(l,r),s=t[i-1];if(-1===s&&(s=te(n,e,i)?.b??-1),l=o.f[s]??null,null===l)break}return l}zt(e,t){return 0===e.n?Z(this.target,e._):null===t?void 0:Z(t.O,e._)}read(e,t){let n=this.V;if(null!==n&&0===n.fe&&this.qn(e,t,n),null!==e.getter)return this.R.Bo(this,e,t);if(e.ke){let n=this.read(e.w,t);return n?.[e.l]}return null===e.w&&!(e.l in this.target)&&!this.ft.has(e.l)&&"then"!==e.l&&"toJSON"!==e.l&&S(301,[e.t],e.l,Object.keys(this.target)),this.zt(e,t)}v(e,t){let n=this.V;if(null===n)return this.read(e,t);n.fe++;try{return this.read(e,t)}finally{n.fe--}}qn(e,t,n){let l=n.getter;e.Ln(l),e.n>0&&l.n>0&&ee(t,Math.min(e.n,l.n))!==ee(n.r,Math.min(e.n,l.n))&&(l.ct??(l.ct=new Set)).add(e)}Do(e,t){for(let n=0;n<this.Bt;n++){let l=this.Wn[n];l.getter===e&&l.r===t&&S(701,[e.t])}this.Bt>=128&&S(801,[e.t]);let n=this.Bt++;this.Ce++;let l=this.Wn[n]??={getter:e,r:t,fe:0,Me:0};l.getter=e,l.r=t,l.fe=0,l.Me=++K;let i=this.V;this.V=l;let r=this.h;this.h=t;try{return e.getter.call(this.proxy)}finally{this.Ce--,this.Bt--,this.V=i,this.h=r,l.r=null}}watchIndex(e){let t=this.V;if(null!==t&&0===t.fe){let n=t.getter,l=n.c[e];if(l){let e=l.Rt??(l.Rt=[]);e.includes(n)||e.push(n)}}}Ut(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:T.test(e)?+e.slice(1):0;return(n<1||n>128)&&S(1001,[e]),this.watchIndex(n),ee(this.h,n)?.b}let n=this.Io[e];if(void 0!==n)return n;switch(e){case"$trackDependency":return S(1701,[e,"$dependOn"]);case"$untrackDependency":return S(1701,[e,"$untracked"]);case"$stateElement":return this.element;case"$command":return this.commands}return c.Ut?.(this,e)}eq(e,t){this.resolve(e,this.h);let n=this.rp,l=this.rr;if(null!==n.getter||n.ke||n.n>0)return Y(this.read(n,l),t);let i=this.V;return null!==i&&0===i.fe&&this.Mo(n,t,i),Y(this.v(n,null),t)}Mo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Vn:i.H??(i.H=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(Y(o.key,t))return void(o.Me=n.Me);o.Me!==n.Me&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};V(e.H??=new Map,t,J).add(o),r.push({source:e,key:t,sub:o,Me:n.Me})}Xn(e,t,n,l){this.Xt(e,i=>{let r=i.H;if(null===r&&null===i.Fe)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=Z(t,o),a=Z(n,o);if(null!==i.Fe&&this.Wo(i,s,a,l),null!==r)for(let e of l?r.keys():[s,a]){let t=r.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.d?this.R.xe(this,n.getter,n.r):Q(i,e,n)}})}P(e,t,n,l=!1,i=!1){if(this.Ce>0&&S(8),i||this.Ee>0?this.Mt=!0:this.Wt=!0,c.Re?.(this,e,t,n,i))return;if(null!==e.Z){try{this.yn(e.Z,t,[n])}finally{this.Vt(e,t,void 0,void 0,!1)}return}null!==e.getter&&S(2,[e.t]),e.n>0&&null===t&&S(3,[e.t]);let r=e.ke?this.v(e,t):this.zt(e,t);if(l||!this.jt||!Object.is(r,n)||Object(n)===n){if("*"===e.l){let e=t;e.s.Y[e.b]=n,e.O=n,this.R.Ht(e)}else{let l=1===e._.length?0===e.n?this.target:t.O:this.v(e.w,t);null==l&&S(4,[e.t,l]),l[e.l]=n}this.wn(e,t),null!==t&&t.s.Ge&&this.zn(t,e,r,n),0===e.n&&this.Xn(e,r,n),this.Vt(e,t,r,n,!0)}}Zn(e){return(this.dn.get(e.Y)??[]).filter(t=>t.Y===e.Y&&(null===t.te||t.te.d))}zn(e,t,n,l,i=!0){let r=e.s,o=t.t.slice(r.o.t.length+2);for(let t of this.Zn(r)){if(t===r)continue;let s=t.f[e.b];if(void 0===s)continue;let a=this.o(`${t.o.t}.*${o}`);""===o&&(s.O=l,this.R.Ht(s)),i?this.wn(a,s):this.hn(a,s),this.Vt(a,s,n,l,i)}}hn(e,t){this._o(e,t,e=>{this.q(e);for(let t of e.Ge?this.Zn(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.ht(e,n),this.hn(e,n)}})}wn(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.G(e)&&this.q(t)}_o(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.G(e)&&n(t)}Wo(e,t,n,l){for(let{getter:i,Un:r}of e.Fe)this.eo(i.c[r],e=>{for(let r of l?e.f.keys():[t,n]){let t="number"==typeof r?e.f[r]:void 0;void 0!==t&&this.gn(i,t)}})}gn(e,t){t.s.n===e.n?this.R.xe(this,e,t):this.Gt(t,e,t=>this.R.xe(this,e,t))}Vt(e,t,n,l,i){c.pe?.(this,e,t,n,l,i),this.$e(e,t)}$e(e,t){this.R.Ho(this,e,t),this.Ne()}to(e){let t=this.Qe.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.Qe.set(e,n);let l=this.root,i=this.Mn;return l.addEventListener(e,t=>{for(let r=t.target;null!==r&&r!==l;r=r.parentNode){let l=r[n];if(void 0!==l&&(l(t),t.cancelBubble))return;let o=r[i];if(void 0!==o&&o.d&&o.Vo(e,t))return}}),n}reset(e){let t=this.target;this.Gn(e);let n=this.ft;for(let e in t)"$"!==e[0]&&n.add(e);for(let t of n)t in e&&n.delete(t);for(let e of this.re.values())for(let t of e)this.Yt(t);for(let e of this.oe.values())this.no(e);this.Ie=null;try{this._t()}finally{this.bn()}c.element?.(this,"reset")}Gn(e){for(let[t,n]of B)void 0!==e[t]&&$(n,t);void 0!==e.$scan&&S(1);for(let[t,n]of F)void 0!==e[t]&&S(1601,[t,n]);let t=e.$features;if(void 0!==t){Array.isArray(t)||S(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&S(44,["state","$behavior"]);for(let e in n)(!_.includes(e)||"boolean"!=typeof n[e])&&S(44,["$behavior",e]);let[l,i,r]=_.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.It||i!==this.jt||r!==this.Lt)&&S(45);let o=function(e,t){let n={};for(let l of A(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new x(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of A(e.$eventTokens,"$eventTokens"))n.set(t,new x(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&S(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&S(23,[e]),"function"!=typeof i&&S(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this.Co);this.It=l,this.jt=i,this.Lt=r,c.ie?.(this,e),this.target=e,this.Oe=0;for(let e of this.L.all())e.Po();this.Vn.length=0,this.Yn(e),this.commands=o,this.Se=s}no(e){this.Jn(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.ut=null,n.H=null,this.ht(t,n),null!==n.u)for(let e of n.u.values())this.no(e)}D(e){let t=[];for(let n=e;null!==n;n=n.s.te)t.unshift(n.b);return t}Uo(e,t,n){let l=this.Se.get(e);void 0===l&&S(1301,[e],e,this.Se.keys()),l.emit(t,...this.D(n))}command(e){let t=this.commands[e];return void 0===t&&S(1302,[e],e,Object.keys(this.commands)),t}qo(e,t,n){this.command(e).emit(t,...this.D(n))}Ko(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&S(5,[e]),this.yn(l,n,[t,...this.D(n)])}yn(e,t,n){let l=this.h;this.h=t;try{return e.apply(this.proxy,n)}finally{this.h=l}}ht(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Ft&&t.o.G(e)&&(t.Ft=!0,this.Be.push(t))}if(null===t)return void this.Xt(e,e=>{let t=this.re.get(e);if(void 0!==t)for(let e of t)this.Yt(e)});let n=t.de;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.G(e)&&this.Yt(n[t]);let l=t.$;null!==l&&null!==l.se&&l.oo(this,e);let i=t.s.j;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.se&&l.oo(this,e)}}vn(e,t,n){this.Xt(e,e=>{let l=e.at;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.et(r,null,n);else if(null===t||0===e.n||r.c[1]!==e.c[1]||null!==r.ct&&r.ct.has(e))this.Jt(r.c[r.n],e=>this.et(r,e,n));else if(r.n<=e.n){let e=ee(t,r.n);null!==e&&this.et(r,e,n)}else this.Gt(t,r,e=>this.et(r,e,n))}})}et(e,t,n){n(e,t)&&(c.me?.(this,e,t),this.ht(e,t),this.vn(e,t,n))}Xt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Xt(n[e],t)}Jt(e,t){this.eo(e,e=>{for(let n of e.f)t(n)})}eo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.Jt(e.c[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}Gt(e,t,n){if(e.s.n===t.n)return n(e);let l=e.u?.get(t.c[e.s.n+1]);if(void 0!==l)for(let e of l.f)this.Gt(e,t,n)}zo(e){let t=e.r;null===t?V(this.re,e.o,J).add(e):(t.de??(t.de=[])).push(e)}kn(e){let t=e.r;if(null===t)return void this.re.get(e.o)?.delete(e);let n=t.de;t.d&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}Yt(e){e.J||(e.J=!0,this.je.push(e),this.Ne())}Ne(){this.mt||(this.mt=!0,queueMicrotask(this.Oo))}Sn(){for(let e of this.je)e.J=!1;for(let e of this.Le)e.J=!1;for(let e of this.Be)e.Ft=!1;this.je=[],this.Le=[],this.Be=[],this.R.ft(this)}io(e,t){let n=[...new Set([...this.je,...this.Le,...this.Be].map(e=>e.o.t))];console.error(`[@wcstack/state] ${k(e)}`,n),c.tt?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Sn()}_t(){this.mt=!1;let e=this.Dt;this.Dt=0;let t=0;if(!this.Mt||this.Wt?this._n():e>0?t=e:1===(t=++this.B)&&setTimeout(this._n,0),this.Mt=this.Wt=!1,t>100)101===t?this.io(41,100):this.Sn();else{this.un=!0;try{for(let e=0;this.je.length>0||this.Le.length>0||this.Be.length>0;e++){if(e>=32){this.fn?this.Sn():this.io(11,32),this.fn=!0;break}let n=this.Be;if(n.length>0){this.Be=[];for(let e of n)e.Ft=!1,this.Jn(e)}let l=this.Le,i=this.je;this.Le=[],this.je=[];let r=O("state",()=>{for(let e of l){e.J=!1;for(let t of[e.$,...e.j??[]])if(null!==t&&t.d)try{t.yt()}catch(n){this.qt(n,e.o.t,t.S,"for")}}for(let e=0;e<i.length;e++){let t=i[e];t.J&&(t.J=!1,(null===t.En||t.En.d)&&this.We(t))}this.un||(this.Qt(),this.mt&&(this.Dt=t+1))});void 0!==r&&r.then(void 0,e=>console.error(e))}}finally{this.un=!1}this.Mt=this.Wt=!1,this.Qt(),c.Pe?.(this),e>0&&this.mt&&(this.Dt=t+1)}}wt(e,t){this.pt.push([e,t])}qt(e,t,n,l){this.wt(e,{o:{t},a:n,Zt:()=>l})}We(e){try{e.apply()}catch(t){return void this.pt.push([t,e])}null!==this.Ie&&this.so(e.o,e.r)}so(e,t){let n=V(this.Ie,e.t,X);null!==t&&n.push(this.D(t))}bn(){this.Ie="function"==typeof this.target.$renderedCallback?new Map:null}Qt(){let e=this.Ie;if(null!==e&&e.size>0){this.Ie=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Ee++;try{t=this.ae("$renderedCallback",[n,l])}catch(e){console.error(e)}G(t)?t.then(this.Hn,e=>{this.Hn(),console.error(e)}):this.Ee--}if(0===this.pt.length)return;let t=this.pt;this.pt=[];let n=this.target.$errorCallback;for(let[e,l]of t){c._e?.(this,e,l);let t=l.o.t,i=l.Zt();if("function"==typeof n)try{let n=this.ae("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);G(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${k(12,[i,t])}`,e)}}ae(e,t=[]){let n=this.target[e];return"function"==typeof n?this.yn(n,null,t):void 0}lo(e,t,n){if(0===e.n)return void n(null,[]);let l=[],i=(r,o)=>{let s=e.c[r];this.read(s,o);let a=this.De(o,s),u=t=>{l.push(t.b),r===e.n?n(t,l):i(r+1,t),l.pop()};for(let e of r-1<t.length?[a.f[t[r-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e);void 0!==t&&this.mn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.h;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=te(t,n,e);if(null===i)break;l.push(i.b)}0===l.length&&S(6,[e])}}let i=[];return this.lo(n,l,e=>i.push(this.read(n,e))),i}pn(e,t,n,l){Array.isArray(t)||S(9,[e]),this.Ce>0&&S(8);let i=this.o(e);this.mn("$setAll",e,i,t,!1);let r=[];this.lo(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&S(10,[e,r.length]);let s=0;for(let e=0;e<r.length;e++){let[t,l]=r[e],a="function"==typeof n?n(this.v(i,t),...l):o?n[e]:n;void 0!==a&&(this.P(i,t,a),s++)}return s}mn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&S(i?901:902,[e,t,n.n,r])}},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=new Map,re=new Set(["if","elseif","else","for"]),oe=new Set([M,"if","elseif","for","..."]),se=new Set(["class","attr","style","command",C,"state"]);function ae(e){let t=function(e){return L(e,";")}(e).map(W).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&S(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(oe.has(i)){let t;return i!==n&&S(102,[e,i]),i===M?(l.length>0&&S(103,[e]),t={Ye:"#else",Je:[]}):"..."===i?(0===l.length&&S(104,[e]),t=U(l),t.Je.length>0&&S(105,[e])):(t=U(l),"for"===i&&t.Je.length>0&&S(121,[e])),{he:i,ye:[i],en:[],C:[],...t,y:"..."===i?"spread":i}}let r=U(l),o=function(e){let[t,n]=q(e,"input",ie),l=t.split("#").map(W);l.length>2&&S(115,[t]);let[i,r]=l,o=i.split(".").map(W);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&S(116,[e]),{he:i,ye:o,en:r?r.split(",").map(W):[],C:n}}(n),[s]=o.ye;if(""===s&&o.ye.length>1){let e=o.ye.slice(1);return(e.includes("")||se.has(e[0]))&&S(106,[n]),{...o,he:e.join("."),ye:e,...r,y:"prop"}}return{...o,...r,y:"radio"===i||"checkbox"===i?i:s===C||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>re.has(e.y))&&S(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms"],ce=new Map,fe=new Map;function he(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});fe.clear()}function de(e){return ce.has(e)}function pe(e){S(26,[e])}function me(e){S(27,[e])}function ge(e){S(28,[e])}function ye(e){S(29,[e])}function $e(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return $e(e)||me(t),Number(e)}function be(e,t,n){return ve(e?.[t]??pe(n),n)}function we(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let l=be(n,0,e);return n=>("number"!=typeof n&&ge(e),t(n,l))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),l=we(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:($e(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),l=we(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:($e(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs"),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=be(e,0,"clamp"),n=be(e,1,"clamp");return e=>("number"!=typeof e&&ge("clamp"),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:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},defaults:{factory:(e,t)=>{let n=we(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=we(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:{factory:()=>e=>!!e,arity:[0,0]},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]}},xe=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ne(e){return 0===e.length?null:(xe||(xe=!0,he(Se)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=fe.get(l);if(typeof i<"u")return i;let r=ce.get(e);void 0===r&&function(e,t){ue.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),S(501,[e],e,t)}(e,ce.keys());let[o,s]=r.arity;t.length<o&&S(601,[e,o,t.length]),t.length>s&&S(602,[e,s,t.length]);let a=r.factory(t,n);return fe.set(l,a),a}(e.Dn,e.args,e.literals)))}var je=Symbol.for("wcstack.trustedTypes.policy");function Oe(){let e=globalThis[je];return null!==e&&"object"==typeof e?e:null}function Me(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ce(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Oe(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Te=Symbol.for("wcstack.state.view-transition-naming"),Pe=new WeakSet;function Ee(){let e=j("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var We=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function Re(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Ie(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(We.has(e))return We.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 Map,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,ao:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.set(e.name,{attribute:"string"==typeof e.attribute?e.attribute:null});for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return We.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.d||function(e,t,n){let l=n;null!==t&&(t.bt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Fe(e,l,t,n)}e.Ne()})}function Le(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.get(l),f=e.Lt;f&&null===a&&void 0===u&&S(38,[l]);let h=t.M;(null===a?"element"===h||"auto"===h:void 0===u&&("state"===h||"auto"===h))&&S(39,[h,l]),"connect"===t.q&&null===a&&S(40,[l]);let d=f&&null!==a&&void 0===u,p=new He(e,ze,n,l,i,r,o,t.N,void 0);p.C=t.C,p.attribute=u?.attribute??null,Ze(e,p,!d),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.ao||c.detail?.(n,l,i)),(!p.$n||!Object.is(i,p.value))&&(i=Ae(p.C,i),null===p.N&&(p.value=i),e.P(p.o,p.r,i,a.ao,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.We(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.d)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.We(p));let t=n[l];null===p.N&&(p.value=t),e.P(p.o,p.r,t,!1,!0)};"connect"!==t.q||n.isConnected?i():Promise.resolve().then(i)}return p}function qe(e,t,n){S(e,[t.localName,n])}var De=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),ze=11,Ue=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,l)=>e.qt(t,n.o?.t??n.vt,l,Ue[n.i]),Be=Symbol();function _e(e,t,n){let l=t.M;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.W:Be}var He=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.J=!1,this.C=null,this.attribute=null,this.$n=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.En=o,this.N=s,this.value=a,this.B=u}Zt(){return Ue[this.i]}apply(){if(null!==this.B)return void this.B.yt();let e=Ae(this.N,this.engine.read(this.o,this.r));if(e===this.value&&("object"!=typeof e||null===e||this.i===ze||8===this.i||Me(this.name)))return;if(this.value===Be)return void(this.value=e);let t=this.a;if(this.i!==ze)9===this.i?t.checked=void 0!==e&&this.tn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.tn()):Ve(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.$n=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.$n=!1}null!==this.attribute&&function(e,t,n){try{if(null==n)e.removeAttribute(t);else{let l=n;if("object"==typeof n)try{l=JSON.stringify(n)}catch{}e.setAttribute(t,String(l))}}catch{}}(t,this.attribute,e)}}tn(){return Ae(this.C,this.a.value)}Xo(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.tn()}else if(10===this.i){let l=this.tn(),i=n.v(this.o,this.r),r=Array.isArray(i)?i:[],o=r.includes(l);if(t.checked?o:!o)return;e=o?r.filter(e=>e!==l):[...r,l]}else e=Ae(this.C,t[this.name]);n.P(this.o,this.r,e,!1,!0)}},Ke=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ve(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ke(n)?t[n]="innerHTML"===n?Ce(l):null==l?"":String(l):Me(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Ce(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,l])));case 8:return void(t.innerHTML=Ce(l));case 2:return null!=l&&"boolean"!=typeof l&&S(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(null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)))}}var Je=Symbol();function Xe(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Ge=class{constructor(e,t,n,l){this.d=!0,this.de=null,this.u=null,this.bt=null,this.xn=null,this.r=e,this.He=t,this.I=n,this.T=l}Vo(e,t){let n=t.target,l=this.T,i=[],r=null;for(let t of l.Se){if(t.name!==e)continue;let o=l.Rn[t.a],s=at(null===this.I?this.He:this.I[o[0]],o,1);s.contains(n)&&(s!==r&&i.unshift([]),i[0].push(t),r=s)}for(let e of i){for(let n of e)n.Nn(t,this.r);if(t.cancelBubble)return!0}return!1}get l(){return null===this.I?this.He:this.I[this.I.length-1]}Ve(){let e=this.xn;return(null===e?null:e.Pn(this.He))??this.He}insertBefore(e,t){let n=this.l;for(let l=this.Ve();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}fo(){null===this.I?this.He.remove():ut(this.Ve(),this.l)}be(e){if(this.d=!1,null!==this.bt)for(let e of this.bt)e();let t=this.de;if(null!==t)for(let n=0;n<t.length;n++)e.kn(t[n]);if(null!==this.u)for(let e of this.u)e.be()}},Ye=class extends Ge{constructor(e,t,n,l){super(e,t,n,l),this.po=0,this.U=null,this.se=0===l.Ue.length?null:new Array(2*l.Ue.length)}mo(e,t){let n=this.U??=new Array(this.T.Ue.length),l=n[t];if(void 0===l){let i=this.T.Ue[t],r=this.se;l=n[t]=new He(e,i.i,r[2*t],i.name,i.o,this.r,this,i.N,r[2*t+1])}return l}oo(e,t){let n=this.T.Ue;for(let l=0;l<n.length;l++)n[l].o.G(t)&&e.Yt(this.mo(e,l))}be(e){let t=this.r;t.$===this&&(t.$=null),super.be(e)}};function Qe(e,t,n,l){let i=ee(n,t.n);try{return e.De(i,t)}catch(n){return e.qt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function Ze(e,t,n){n&&e.zo(t);let l=t.En;null!==l&&(l.de??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function lt(e,t,n,l,i=null){let r,o=t.Rn,s=t.build,a=t.ho,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.Tn,d=f?document.createDocumentFragment():(h?t.root:t.nn).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=at(d,o[t],h?1:0)}h?r=d:(u=f||[...d.childNodes],r=u[0]);let p,m=null;if(null!==l?(p=m=new Ye(n,r,u,t),null===l.map?n.$=m:l.map.set(n,m)):p=new Ge(n,r,u,t),nt>=0&&function(e,t,n,l){let i=null;if(null===t)i=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===i;e++)1===t[e].nodeType&&(i=t[e]);let r=i?.style;if(null===i||void 0===r||Pe.has(i))return;let o=globalThis[Te]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${k(25,[l])}`)):(Pe.add(i),o.assigned++,r.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),r.setProperty("view-transition-class",`wcs-${n}`))}(r,u,null!==l?"row":"branch",nt),t.Se.length>0){let t=e.Mn;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.Go,y=e.Ie,$=t.Yo?a.slice(0,o.length):a,v=null===m?null:m.se;if(null!==v){let e=t.Ue;for(let t=0;t<e.length;t++)v[2*t]=$[e[t].a],v[2*t+1]=e[t].W}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.a],o=l.A;if(o>=0&&null!==v){let t=m.U?.[o];if(void 0!==t){t.J=!1,e.We(t);continue}try{let t=Ae(l.N,e.read(l.o,n));t!==l.W&&(Ve(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.so(l.o,n)}catch(t){e.wt(t,m.mo(e,o))}continue}switch(l.i){case 6:{let t=new st(e,l.T,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.xn=t),t.yt();break}case 7:{let t=rt(e,l.K.map(e=>({T:e.T,o:e.o,N:e.N,S:$[e.a]})),n,p);(p.u??=[]).push(t),i===r&&(p.xn=t);break}default:try{it(e,l,i,n,p)}catch(t){Fe(e,t,l,i)}}}return et=p,d}function it(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Nn,o=e=>r(e,l);if(n.Qe){let l=e.to(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.we&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.uo&&null!==i&&(i.bt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.vt.slice(9));null===i&&qe(1202,n,`command.${r}`),i.commands.has(r)||S(1203,[n.localName,r]);let s=new WeakRef(n),a=o.subscribe((...e)=>{let t=s.deref();if(void 0!==t)return t.isConnected?t[r](...e):void 0;a()});null!==l&&(l.bt??=[]).push(a)}(e,t,r,i,n));case 13:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&qe(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&S(1204,[n.localName,r]);let s=t.vt;n.addEventListener(o.event,n=>{t.kt&&n.preventDefault(),t.St&&n.stopPropagation();try{e.Uo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=ee(l,o.n);if(14===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&qe(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs.keys()]);for(let s of o){if(t.co?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;Le(e,{...t,M:null,q:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.we&&1===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void Le(e,t,n,t.name,t.o,l,i,r);let o=new He(e,1,n,t.name,t.o,l,i,t.N,_e(e,t,l));o.C=t.C,!c.Jo?.(o,t.ro)&&(Ze(e,o,!0),e.We(o))}(e,t,r,s,i,n));let a=new He(e,t.i,n,t.name,o,s,i,t.N,_e(e,t,s));a.C=t.C,Ze(e,a,!0),e.We(a),null!==t.Et&&n.addEventListener(t.Et,()=>a.Xo())}function rt(e,t,n,l){let i=new ot(e,t,n),r=null;for(let o of t){if(null===o.o)continue;let t=o.o,s=new He(e,7,o.S,"if",t,ee(n,t.n),l,null,void 0,i);Ze(e,s,!0),null===l&&i.re.push(s),r??=s}return e.We(r),i}var ot=class{constructor(e,t,n){this.d=!0,this.F=null,this.b=-1,this.re=[],this.engine=e,this.K=t,this.r=n}Pn(e){return null!==this.F&&this.K[this.b].S===e?this.F.Ve():null}yt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ae(l.N,e.read(l.o,ee(this.r,l.o.n)))){t=n;break}}if(t!==this.b&&(nt=Ee(),null!==this.F&&(this.F.fo(),this.F.be(e),this.F=null),this.b=t,t>=0)){let n=this.K[t],l=lt(e,n.T,this.r,null,n.S);this.F=tt();let i=n.S.parentNode;i.insertBefore(l,n.S),Xe(i)}}be(){this.d=!1;for(let e of this.re)this.engine.kn(e);null!==this.F&&this.F.be(this.engine)}},st=class{constructor(e,t,n,l){this.d=!0,this.ve=[],this.engine=e,this.T=t,this.s=n,this.S=l,null===n.$?(n.$=this,this.map=null):((n.j??=[]).push(this),this.map=new Map)}Pn(e){return 0===this.ve.length?null:this.ve[0].Ve()}$t(e){return null===this.map?e.$:this.map.get(e)??null}go(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.be(this.engine)}yt(){let e=this.engine,t=this.s.f,n=this.ve;nt=Ee();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){ut(n[0].Ve(),n[i-1].l);for(let e=0;e<i;e++)this.go(n[e])}return void(this.ve=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.$t(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.$t(t[c])===n[u];)s[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],l=t.r;l.d&&this.$t(l)===t?t.po=e:(t.fo(),this.go(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(i>0)for(let e=0;e<n;e++){let n=this.$t(t[a+e]);null!==n&&n.d?(u[e]=n.po,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Ve():r;if(f){let l=function(e){let t=e.length,n=new Uint8Array(t),l=new Int32Array(t).fill(-1),i=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let r=0,o=i.length;for(;r<o;){let n=r+o>>1;e[i[n]]<t?r=n+1:o=n}r>0&&(l[n]=i[r-1]),i[r]=n}let r=i.length>0?i[i.length-1]:-1;for(;r>=0;)n[r]=1,r=l[r];return n}(u),i=h;for(let r=n-1;r>=0;r--){let n=t[a+r],u=this.$t(n);null!==u&&u.d?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(lt(e,this.T,n,this),i),u=tt()),s[a+r]=u,i=u.Ve()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(lt(e,this.T,t[l],this)),s[l]=tt();o.insertBefore(n,h)}}this.ve=s,Xe(o)}be(){this.d=!1;let e=this.s;if(e.$===this)e.$=null;else if(null!==e.j){let t=e.j.indexOf(this);t>=0&&e.j.splice(t,1),0===e.j.length&&(e.j=null)}for(let e of this.ve)e.be(this.engine);this.map?.clear()}};function at(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 ut(e,t){let n=document.createRange();n.setStartBefore(e),n.setEndAfter(t),n.deleteContents()}var ct=()=>le.bindAttributeName;function ft(){return{a:0,i:1,name:"",o:null,N:null,W:t,Nn:null,T:null,K:null,C:null,Et:null,we:!1,M:null,q:null,ro:!1,kt:!1,St:!1,vt:null,co:null,A:-1,Qe:!1,uo:!1}}var ht=["state","element","auto","none"],dt=["call","connect"],pt="$command.";function mt(e,t,n){T.test(t)&&(null===n&&S(1401,[t,Number(t.slice(1))]),t=`${n.t}.*.${t}`);let l=e.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&S(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&S(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?n:n.c[e];l.c[e]!==t&&S(1403,[l.t,l.c[e].t,t.t])}return c.yo?.(e,l),l}var gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&Ke(e.name);function $t(e){S(202,[e])}function vt(e,t,n,l,i){let r=ae(t).map(t=>function(e,t,n,l,i){let r=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Lt||S(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&S(33,[r,n]),null!==(s?l:i)&&S(34,[r]),(s?ht:dt).includes(o)||S(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),kt:t.includes("prevent"),St:t.includes("stop"),event:n?n.slice(2):null,M:l,q:i}}(e,t.en),o=l.localName.includes("-"),s=t.ye,a=t.Ye;if("event"===t.y){if(null!==r.M&&"none"!==r.M&&S(36),"eventToken"===s[0])return{...ft(),a:i,i:13,name:s.slice(1).join("."),vt:a,we:o,kt:r.kt,St:r.St};let n=a.startsWith(pt)?a.slice(9):null,{kt:l,St:u}=r,c=t.he.slice(2),f=t.en.includes("direct"),h=!f&&De.has(c);return h&&e.to(c),{...ft(),a:i,i:5,name:c,Qe:h,we:o,uo:f,Nn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.qo(n,t,i);else{let n=e.Ko(a,t,i);G(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.y)return{...ft(),a:i,i:14,o:mt(e,a,n),we:o};if("command"===s[0]&&s.length>1)return a.startsWith(pt)||S(1201,[t.he,a]),{...ft(),a:i,i:12,name:s.slice(1).join("."),vt:a,we:o};let u=mt(e,a,n),c={...ft(),a:i,i:1,name:t.he,o:u,N:Ne(t.Je),C:Ne(t.C),ro:r.ro,M:r.M,q:r.q};if("radio"===t.y||"checkbox"===t.y)return("element"===r.M||"auto"===r.M)&&S(37,[t.y,r.M]),c.i="radio"===t.y?9:10,r.ro||(c.Et=r.event??"input"),c;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return c.M=null,c.name=e,"class"===t?(c.i=2,c.W=l.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,c}return"html"===t.he?(c.i=8,c):(c.name="text"===t.he?"textContent":t.he,c.we=o&&!Me(c.name),!o&&!r.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.Et=r.event??("select"===l.localName?"change":"input")),c)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].co=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var bt=/\{\{([\s\S]+?)\}\}/g;function wt(e){let t=e.data,n=[],l=0;bt.lastIndex=0;for(let i=bt.exec(t);null!==i;i=bt.exec(t)){let r=bt.lastIndex-i[0].length;r>l&&e.before(t.slice(l,r));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({a:o,Qo:i[1].trim()}),l=bt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function kt(e,t,n,l){let i=function(e){return{he:"textContent",ye:["textContent"],en:[],C:[],...U(e),y:"text"}}(t);return{...ft(),a:l,i:0,o:mt(e,i.Ye,n),N:Ne(i.Je),W:""}}function St(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.y&&"if"!==n.y&&"elseif"!==n.y&&"else"!==n.y?null:n}var xt=(e,t)=>0===e?le.commentIfPrefix:null===t.o?le.commentElsePrefix:le.commentElseIfPrefix;function At(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.y?null:mt(e,l.Ye,n),N:"else"===l.y?null:Ne(l.Je)}),i=[l(t,St(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=St(e);if(null===t||"elseif"!==t.y&&"else"!==t.y||(i.push(l(e,t)),"else"===t.y))break}return i}var Nt=new WeakSet;function jt(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.An?.(e,i,t),i},u=t=>{for(let f=0;f<t.length;f++){let h=t[f];if(null!==h.parentNode)if(1===h.nodeType){let t=h,s=t.localName;if(l){if("script"===s||"style"===s||Nt.has(t))continue;if(Nt.add(t),s===le.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?St(t):null;if(null!==f){if("for"===f.y){let l=mt(e,f.Ye,n),r=Ct(e,t,l,!0);i(a(t,le.commentForPrefix),l,r)}else"if"===f.y?r(At(e,t,n).map((t,l)=>({T:Ct(e,t.el,n,!1),o:t.o,N:t.N,S:a(t.el,xt(l,t))}))):$t(f.y);continue}let d=t.getAttribute(ct()),p=null===d?null:vt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(yt)&&!c.wo?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.It&&h.data.includes("{{")&&!Nt.has(h))for(let{a:e,Qo:t}of wt(h))s(e,t);else if(8===h.nodeType){let e=Ot.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),s(t,e[1])}}}};u(t)}var Ot=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Mt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Ct(e,t,n,l){let i=document.importNode(Mt(t),!0),r=[],o=[],s=e=>r.push(e)-1;jt(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ft(),a:s(e),i:6,o:t,T:n})},e=>{let t=e.map(e=>({a:s(e.S),T:e.T,o:e.o,N:e.N}));o.push({...ft(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)gt(e)&&S(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,l)=>{o.push(kt(e,l,n,s(t)))}),Wt(i,new Set(r),!0);let a=r.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}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of o){if(5===e.i&&e.Qe&&!e.we&&!Tt(r[e.a],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.c[m]===n&&Pt(e)&&(e.A=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{nn:i,root:u?i.firstChild:null,Rn:a,build:g,Se:d,Go:p,Tn:u,Yo:c,ho:[],Ue:f}}function Tt(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 Pt(e){if(null!==e.M)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.we&&null===e.Et;default:return!1}}var Et=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Wt(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&&Wt(l,t,Et.has(l.localName)),l=e}}var It=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),Lt(e,[...n.childNodes]),e.Qt()}function Lt(e,t){jt(e,t,null,!0,(t,n,l)=>{new st(e,l,Qe(e,n,null,t),t).yt()},t=>{rt(e,t,null,null)},(t,n)=>{c.An?.(e,t,n);for(let l of n)it(e,l,t,null,null)},(t,n)=>{c.An?.(e,t,n),it(e,kt(e,n,null,0),t,null,null)})}var qt=Symbol.for("wcstack.binder"),Dt=Symbol.for("wcstack.binder.pending"),zt=Symbol.for("wcstack.binder.taken");var Ut=new Set;function Ft(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ut.add(e):function(e,t,n){try{let l="template"===t.localName?St(t):null;null!==l&&!n&&S(204,[l.y]),Lt(e,[t])}catch(e){console.error(e)}e.Qt()}(n,e,t?.range)}function Bt(){let e=[...Ut];Ut.clear();for(let t of e)Ft(t);!function(){let e=function(){let e=globalThis[qt];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[Dt];return void 0===t&&(t=[],e[Dt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[zt];return void 0===t&&(t=new WeakSet,e[zt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var _t=class{constructor(){this.name="dirty",this.nt=(e,l)=>{if(0===e.n){let l=e.ee;return l!==t&&l!==n&&(e.ee=n,!0)}let i=null===l?null:l.ut;if(null===i)return!1;let r=i[e.A];return r!==t&&r!==n&&(i[e.A]=n,!0)}}Ho(e,t,n){null!==t.getter&&this.nt(t,n),e.ht(t,n),e.vn(t,n,this.nt)}Lo(e,t){let n=t.s.o.Rt;if(null!==n)for(let l of n)l.n===t.s.n?e.et(l,t,this.nt):e.Gt(t,l,t=>e.et(l,t,this.nt))}xe(e,t,n){this.nt(t,n),c.me?.(e,t,n),e.ht(t,n),e.vn(t,n,this.nt)}Bo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.ut??=new Array(e.Oe).fill(t),a=null===s?i.ee:s[i.A];if(a!==t&&a!==n&&a!==l&&(null===s||i.A in s))return a;a=l;try{return a=e.Do(i,null===s?null:r)}finally{null===s?i.ee=a:s[i.A]=a}}Ht(e){e.ut=null}ft(e){for(let t of e.L.all())null!==t.getter&&(0===t.n?t.ee===n&&(t.ee=l):e.Jt(t.c[t.n],e=>{let i=e.ut;null!==i&&i[t.A]===n&&(i[t.A]=l)}))}},Ht=0,Kt=new WeakMap;function Vt(e){let t=e.getRootNode();Kt.set(t,[...(Kt.get(t)??[]).filter(t=>t.isConnected&&t!==e),e])}function Jt(e){let t=Kt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.U||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Kt.get(e)!==t?Jt(e):Promise.reject(l.errors[0]):void 0)}var Xt=typeof HTMLElement>"u"?class{}:HTMLElement,Gt=class extends Xt{constructor(){super(),this.engine=null,this.Fn=!1,this._e=!1,this.W=null,this.qe=null,this.loaded=!1,this.sn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.rn=e,this.bo=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.on=e})}static{this.getBindingsReady=Jt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Fn){if(null!==this.qe)return void this.qe.Ke();Vt(this);let e=this.engine;return void(null!==e&&Promise.resolve(e.ae("$connectedCallback")).then(()=>{this.isConnected&&c.element?.(e,"connected")},e=>console.error(e)))}this.Fn=!0;let e=this.getRootNode(),t=c.ot?.(this,e);if(t)return this.qe=t,!t.vo&&this.parentNode instanceof ShadowRoot&&Vt(this),void(void 0===t.Ct?this.ko():t.Ct()).then(e=>(this.loaded=!0,t.start(e,()=>this.So()))).then(()=>{this.on(),this.rn()},e=>this.wt(e,t.vo));this.start(e),Vt(this)}disconnectedCallback(){if(null!==this.qe)return void this.qe.On();let e=this.engine;null!==e&&(e.ae("$disconnectedCallback"),c.element?.(e,"disconnected"))}setInitialState(e){if(this._e&&S(14),this.loaded)this.qe.reset(e);else if(null===this.engine)if(null!==this.sn){let t=this.sn;this.sn=null,t(e)}else this.W=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&S(15),"readonly"===e&&n.Ce++;try{t(n.proxy)}finally{"readonly"===e&&n.Ce--}}async createStateAsync(e,t){let n=this.engine;null===n&&S(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&&S(8),l(...e)):l},set(){S(8)}}))}async ko(){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] ${k(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||S(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 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,i=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Ht}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?k(42):k(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(i)}}(l):null!==this.W?Promise.resolve(this.W):new Promise(e=>{this.sn=e})}async start(e){try{let t=e.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||t?.hasAttribute("data-wc-definition"))&&$("scopes","<wcs-state>");let n=await this.ko(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.W=n,this.Fn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=It.get(e)?.element;i?.isConnected&&(i.U||i.qe)&&S(47);let r=new ne(n,new _t);r.element=this,this.engine=r,c.element?.(r,"mounting"),Rt(r,e),Bt(),r.bn(),this.So(),await r.ae("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.rn()}catch(e){this._e=!this.U,this.wt(e)}}So(){this.U=!0,this.on()}wt(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${k(this.U?50:49,[this.localName,...n])}`,e),this.on(),t?this.rn():this.bo(e)}},Yt=[];function Qt(){return(Yt=Yt.filter(e=>e.deref())).map(e=>e.deref())}var Zt,en=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},tn="en";function nn(){if(le.locale!==Zt){Zt=le.locale;try{tn=Intl.getCanonicalLocales(Zt)[0]}catch{console.warn(`[@wcstack/state] ${k(48,[Zt])}`),tn="en"}}return tn}var ln={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed"),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale"),e.toLocaleString(t??nn()))},arity:[0,1]},upper:{factory:en(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:en(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:en(()=>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:en(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:en(e=>{let t=[be(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:en(e=>{let t=be(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:en(e=>{let t=be(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:en(e=>{let t=be(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:en(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:en(e=>{let t=be(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)||S(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ge("round"),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor"),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil"),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent"),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:en(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("date"),e.toLocaleDateString(t??nn()))},arity:[0,1]},time:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("time"),e.toLocaleTimeString(t??nn()))},arity:[0,1]},datetime:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ye("datetime"),e.toLocaleString(t??nn()))},arity:[0,1]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("ymd");let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("hms");let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]}},rn=!1,on={name:"formats",install:function(){rn||(rn=!0,he(ln))}};function sn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let l=new Array(t.length+1),i=new Array(t.length+1);for(let e=0;e<=t.length;e++)l[e]=e;for(let n=1;n<=e.length;n++){i[0]=n;for(let r=1;r<=t.length;r++){let o=e[n-1]===t[r-1]?0:1;i[r]=Math.min(l[r]+1,i[r-1]+1,l[r-1]+o)}for(let e=0;e<=t.length;e++)l[e]=i[e]}return l[t.length]}function an(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=sn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var un=" Validate statically: npx @wcstack/lint <file>.",cn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],fn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,hn="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)=>`binding "${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 ${hn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${hn}`,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=>`filter ${e} requires a number value`,29:e=>`filter ${e} requires a date value`,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&&cn.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)=>`${fn(e,t)} failed to initialize.`,50:(e,...t)=>`${fn(e,t)} $connectedCallback 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>").`,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}).`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,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 pn(e,t){let n=dn[e];return void 0===n?`${w(e)}#${e} ${t.join(" ")}`:w(e)+n(...t)}var mn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),gn=[[/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.']],yn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function $n(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(yn,e)?yn[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?an(t,n):"");for(let[t,n]of gn){let i=t.exec(e);null!==i&&(l+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(l+=` — write "${i[1]}#${i[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"].':ue.some(de)||(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 r=/\[wcs\/([\w-]+)\]/.exec(e);return null!==r&&mn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=un),l}var vn=new WeakMap,bn=new WeakMap,wn=new WeakSet,kn=new WeakSet;function Sn(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 xn(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 An(e,t){let n=[];for(let e=t;null!==e;e=e.w)n.unshift(e);let l=e.target,i=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!==Sn(e.target,t.t)?.get?t:e.L.At(o(t.t).o)}(e,t);for(let t of n){if(null!=i(t)?.getter||null===l||"object"!=typeof l)return null;if("*"===t.l){if(!Array.isArray(l)||0===l.length)return null;l=l[0];continue}if(Array.isArray(l)&&/^\d+$/.test(t.l)){if(Number(t.l)>=l.length)return null;l=l[Number(t.l)];continue}let n=Sn(l,t.l);if(void 0===n&&null===t.w&&e.ft.has(t.l))return null;if(void 0===n){let n=xn(l),r=i(t.w);for(let t of e.L.all())t.w===r&&null!==t.getter&&n.push(t.l);return{seg:t.l,names:n}}if(void 0!==n.get||void 0!==n.set)return null;l=n.value}return null}function Nn(e){wn.has(e)||(wn.add(e),setTimeout(()=>function(e){wn.delete(e);let t=vn.get(e);if(void 0===t)return;let n=bn.get(e);void 0===n&&bn.set(e,n=new Set);for(let[l,i]of t){if(n.has(l))continue;n.add(l);let t=An(e,l);if(null===t)continue;let r=[...e.root?.querySelectorAll(`${le.tagNames.state}[mount]`)??[]].find(e=>!kn.has(e)&&(l.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==r){n.delete(l),r.initializePromise.then(()=>{kn.add(r),Nn(e)});continue}let[s,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];c.tt?.(e,{type:"state:path-unresolved",source:i?"watch":"binding",path:l.t,missingSegment:t.seg});let u=e.L.At(o(l.t).o),f="";if(void 0!==u&&u!==l&&null!==u.getter){let e=u.c.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.c[t].t.length+2)}`);f=` 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/${s}] ${a} "${l.t}" does not resolve on the state tree: "${t.seg}" is not declared.${an(t.seg,t.names)}${f} Updates to this path will be silently dropped.${un}`)}}(e),0))}function jn(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.w)return;let l=vn.get(e);void 0===l&&vn.set(e,l=new Map),l.has(t)||l.set(t,n),Nn(e)}var On=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Mn=!1;function Cn(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(Mn||!(t instanceof TypeError)||!Me(l)||!("trustedTypes"in globalThis))return;Mn=!0;let i="function"==typeof Oe()?.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'). ${i}\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 Tn=new WeakMap;function Pn(e,t,n){let l=e[t],i=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===i)return;let r=Tn.get(e);void 0===r&&Tn.set(e,r=new Set),!r.has(t)&&(r.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${i}. 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 En={name:"diagnostics",install(){c.Ao=$n,c.Fo=pn,c.yo=jn,c.detail=Pn,c._e=f(c._e,Cn),c.ie=f(c.ie,(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,i]=n[0];if(!l.endsWith(".*")||!i.endsWith(".*"))return;let r=l.slice(0,-2),o=i.slice(0,-2),s=`.${i}`,a=`${r}.**`,u=xn(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===`.${o}`||e.startsWith(`.${o}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${o}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${On(s)})+$`).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 "${i}"). Rename one of them.`);let t=new RegExp(`^${On(l)}(?:${On(s)})*${On(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){bn.delete(e),vn.has(e)&&Nn(e)}(e)})}},Wn={},In=/\.\d/,Rn=new Set(Object.getOwnPropertyNames(Object.prototype)),Ln=0,qn=!1,Dn=null,zn=()=>{qn=!1,Ln++};function Un(){if(null===Dn)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=zn,e.port1.unref?.(),Dn=()=>e.port2.postMessage(0)}else Dn=()=>setTimeout(zn,0);return qn||(qn=!0,Dn()),Ln}function Fn(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.Ae){for(let l of t)if(n.G(l)&&(n.n===l.n||!(l.n<e.n&&e.c[l.n+1].G(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Bn=class{constructor(e,t){this.active=!1,this.ze=new Map,this.n=0,this.$o=-1,this.Cn=new Set,this.$e=null,this.engine=e,this.rt=t}Zo(){let e=this.engine;this.ze.clear();for(let t of this.rt)t.getter=null!==t.p.getter||t.p.ke,t.l=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.l.set(Wn,e.v(t.p,null)):this.In(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.l.set(n,e.v(t.p,n)))})});this.active=!0}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.tt?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}No(){this.active=!1,this.ze.clear()}In(e,t,n,l){let i=this.engine.De(n,e.c[t]);for(let n of i.f)t===e.n?l(n):this.In(e,t+1,n,l)}ln(e,t,n,l){let i=this.ze.get(e);void 0===i&&this.ze.set(e,i=new Map);let r=i.get(t);void 0===r?i.set(t,[n,this.n,l]):(r[1]<this.n&&(r[1]=this.n),r[2]||=l)}pe(e,t,n,l,i){if(this.active){(this.$e??=new Set).add(e);for(let r of this.rt){let o=r.p;o.n!==e.n||!o.G(e)||this.ln(r,t,r.getter?r.l.get(t??Wn):o===e&&i&&this.engine.jt&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}}me(e,t){if(this.active)for(let n of this.rt)(n.getter||=null!==n.p.getter||n.p.ke)&&n.p.n===e.n&&n.p.G(e)&&this.ln(n,t,n.l.get(t??Wn),!1)}Kt(e,t){if(!this.active)return;let n=null;for(let l of this.rt){let i=l.p;if(!(i.n<e.n||i.c[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.ln(l,t,void 0,!0):this.In(i,e.n+1,t,e=>this.ln(l,e,void 0,!0)))}}}Pe(){let e=this.$e;if(this.$e=null,!this.active||0===this.ze.size)return;let t=this.ze;this.ze=new Map;let n=this.engine,l=[];for(let i of this.rt){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.d);s.length>1&&s.sort((e,t)=>Hn(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.h;this.n=a+1,n.Ee++;try{if(s=n.v(i.p,t),i.getter&&(i.l.set(t??Wn,s),Object.is(s,r)&&(In.test(i.t)||null!==t&&!u&&!(o??=null!==e&&Fn(_n(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.h=t,c.tt?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.D(t))}catch(e){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),c.tt?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.h=h,this.n=0,n.Ee--}}}l.length>0&&this.xo(l)}xo(e){let t=Un();t!==this.$o&&(this.$o=t,this.Cn.clear());let n=e.filter(e=>!this.Cn.has(e));if(0!==n.length){for(let e of n)this.Cn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.tt?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function _n(e){for(;null===e.getter&&null!==e.w;)e=e.w;return e}function Hn(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.s.te)n.unshift(t.b);for(let e=t;null!==e;e=e.s.te)l.unshift(e.b);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 Kn="$streamStatus",Vn="$streamError",Jn=new Set(Object.getOwnPropertyNames(Object.prototype)),Xn=!1;function Gn(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 Yn=class{constructor(e,t,n){this.jn=0,this.engine=e,this.entries=t,this.X=n}set(e,t,n){Xn=!0;try{this.engine.P(this.engine.o(`${e}.${t}`),null,n)}finally{Xn=!1}}er(){for(let e of this.entries)this.start(e,!0)}tr(){for(let e of this.entries)e.it=!1,e.z?.abort(),e.z=null}nr(){for(let e of this.entries)e.it=!1,null!==e.z&&(e.z.abort(),e.z=null),this.set(Kn,e.name,"idle")}me(e){let t=Math.max(this.X.n,this.jn);for(let n of this.entries)n.g===e&&(n.n=n.it?Math.max(n.n,t):t,n.it=!0)}Pe(){let e=this.engine,t=this.X,n=[];for(let i of this.entries){if(!i.it)continue;let r=i.n;if(i.it=!1,r>32)n.push(i.name),i.g.ee=l;else{t.n=r+1,e.Ee++;try{this.start(i,!1)}finally{e.Ee--,t.n=0}}}n.length>0&&t.xo(n)}start(e,t){let n,i=this.engine;if(null!==e.z&&e.z.abort(),e.z=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.Ae.slice();Qn(r);try{n=i.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.Ae)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Kn}.${e}`||n.t===`${Vn}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Qn(r);for(let e of o)e.Ln(r);if(r.ee=l,t)throw n;return this.set(Vn,e.name,n),void this.set(Kn,e.name,"error")}}let r=new AbortController;e.z=r,i.P(i.o(e.name),null,e.W),this.set(Vn,e.name,null),this.set(Kn,e.name,"active"),this.or(e,r,n)}async or(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.z===t,o=l.o(e.name),s=this.X.n,a=Un(),u=e.W;try{let t=await e.source(n,i);if(!r())return;let c=t=>{u=void 0!==e.Ro?e.Ro(u,t):t,this.jn=Un()===a?s:0;try{l.P(o,null,u)}finally{this.jn=0}};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(i.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!r())return;if(t.done)break;c(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(i.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!r())return;if(t.done)break;c(t.value)}}}if(!r())return;e.z=null,this.set(Kn,e.name,"done")}catch(n){if(!r())return;e.z=null,t.abort(),this.set(Vn,e.name,n),this.set(Kn,e.name,"error")}}};function Qn(e){for(let t of e.Ae){let n=t.at.indexOf(e);n>=0&&t.at.splice(n,1),t.Pt.delete(e)}e.Ae.length=0,e.ee=t}var Zn=new WeakMap;function el(e){let t=Zn.get(e);return t?.target===e.target?t:void 0}function tl(e,t){let n=new Bn(e,function(e,t){if(void 0===t)return[];(null===t||"object"!=typeof t)&&v("$watch must be an object mapping paths to handler functions.");let n=[];for(let l of Object.keys(t)){let i=t[l];(""===l||"$"===l[0]||l.includes("@")||Rn.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 r=e.o(l);c.yo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,l:new WeakMap})}return n}(e,t.$watch)),l=new Yn(e,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=[],i={},r={};for(let o of Object.keys(n)){let s=n[o];(""===o||"$"===o[0]||/[.*]/.test(o)||Jn.has(o))&&v(`$stream entry "${o}" must be a flat property name.`),(null===s||"object"!=typeof s)&&v(`$stream entry "${o}" must be an object.`);let a=s.source,u=s.fold,c=s.args,f=s.initial;"function"!=typeof a&&v(`$stream entry "${o}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${o}": fold must be a function.`),void 0!==u&&!("initial"in s)&&v(`$stream entry "${o}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${o}": args must be a function.`),Gn(t,o)&&v(`$stream entry "${o}" collides with a getter, setter or method of the state.`),void 0===t[o]&&(t[o]=f),i[o]="idle",r[o]=null,l.push({name:o,source:a,Ro:u,W:f,z:null,it:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[Kn]=i,t[Vn]=r,l}(e,t),n),i=Zn.get(e);void 0!==i&&(i.X.No(),i.Nt.tr()),Zn.set(e,{X:n,Nt:l,Ke:i?.Ke??!1,target:t})}function nl(e,t){let n=Zn.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Ke="connected"===t),n.target===e.target)){if("disconnected"===t)return n.X.No(),void n.Nt.nr();n.Ke&&(n.X.Zo(),n.Nt.er())}}var ll=["$streamStatus","$streamError"],il={name:"temporal",install(){c.ie=f(c.ie,tl),c.element=f(c.element,nl),c.pe=f(c.pe,(e,t,n,l,i,r)=>el(e)?.X.pe(t,n,l,i,r)),c.me=f(c.me,(e,t,n)=>{let l=el(e);void 0!==l&&(l.X.me(t,n),l.Nt.me(t))}),c.Kt=f(c.Kt,(e,t,n)=>el(e)?.X.Kt(t,n)),c.Pe=f(c.Pe,e=>{let t=el(e);void 0!==t&&(t.X.Pe(),t.Nt.Pe())}),c.Ut=h(p,c.Ut,(e,t)=>{let n=t.split(".",1)[0];if(ll.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Re=h(d,c.Re,(e,t)=>(!Xn&&36===t.t.charCodeAt(0)&&ll.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},rl=new WeakMap,ol=!1,sl=/^(?!prototype$)[^\d.*$][^.*]*$/;function al(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 i=n[t];"string"==typeof i?l.set(e.o(t),e=>e[i]):"function"==typeof i?l.set(e.o(t),i):v(`$listKeys "${t}" must be a field name or a function.`)}}rl.set(t,l)}function ul(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function cl(e,t,n){let l=new Map;for(let i of t){ul(i)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(i);null==t&&v(`$listKeys "${e}": a row has no key.`),l.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),l.set(t,i)}return l}function fl(e,t,n,l){if(ol||!Array.isArray(l))return!1;let i=rl.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.zt(t,n);if(!Array.isArray(r)||r===l)return!1;let o=cl(t.t,r,i);cl(t.t,l,i);let s=[],a=[],u=r.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=o.get(i(t));s.push(n??t),void 0!==n&&a.push([e,n,t]),s[e]!==r[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){ol=!0;try{e.P(t,n,s)}finally{ol=!1}}if(c.length>0){let l=e.De(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=sl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.P(s,o,r):(o.O[i]=r,e.P(e.o(`${t.t}.*`),o,o.O,!0))}}return!0}var hl={name:"list-keys",install(){c.ie=f(c.ie,al),c.Re=h(d,c.Re,fl)}},dl=new WeakMap,pl=new WeakMap,ml=new WeakMap,gl="will not graft: the root state failed to initialize.",yl=new WeakSet,$l=new WeakMap,vl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],bl=["$commandTokens","$eventTokens","$on","$errorCallback"],wl=e=>`[@wcstack/state] <${le.tagNames.state} mount="${e}">`,kl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Sl=e=>e?.element?.isConnected?e:void 0;function xl(e){let t=ml.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function Al(e,t){dl.set(t,e);let n=ml.get(t);if(ml.delete(t),Array.isArray(n))for(let t of n)Ol(t,e)}function Nl(e,t){console.error(`${wl(e.t)} ${t}`),function(e){let t=pl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}(e),e.Xe?.(),e.Xe=null}function jl(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 Ol(e,t){if(yl.has(t))return Nl(e,"will not graft: its component is wired to its host.");let n=e.state,l=t.target,i=e.t.split("."),r=l;for(let e of i)r=r?.[e];if(void 0!==r&&!0!==t.hydrated)return Nl(e,`will not graft: the root state already has "${e.t}".`);let o=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 i=e.proxy[l];return"$eqPath"===l?(e,t)=>i(n(e),n(t)):kl.has(l)&&"function"==typeof i?(e,...t)=>i(n(e),...t):i},set:(t,l,i)=>"symbol"!=typeof l&&(e.proxy[n(l)]=i,!0)})}(t,e.t);e.chroot=o;let s={},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:i,value:r}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==l||void 0!==i)a[`${e.t}.${n}`]={get:l&&function(){return l.call(o)},set:i&&function(e){i.call(o,e)}};else{if("$"===n[0])continue;if("function"==typeof r){let t=r.bind(o);a[`${e.t}.${n}`]={get:()=>t}}else s[n]=r}}if(void 0===r){for(let e=1;e<i.length;e++){let n=t.o(i.slice(0,e).join("."));null==t.zt(n,null)&&t.P(n,null,{})}t.P(t.o(e.t),null,s)}t.Yn(Object.defineProperties({},a));for(let e in a)t.$e(t.o(e),null);e.engine=t;let c=$l.get(t);void 0===c&&$l.set(t,c=[]),c.push(e.t),e.el.isConnected&&jl(e,"$connectedCallback"),e.Xe?.(),e.Xe=null}function Ml(e,t){let n=ml.get(e);if(Array.isArray(n))for(let e of n)Nl(e,gl);ml.set(e,t)}var Cl=new WeakMap;function Tl(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,Xe:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(le.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=pl.get(t);void 0===e&&pl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Sl(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=ml.get(t);Array.isArray(e)&&ml.set(t,e.filter(e=>e!==r)),r.Xe?.(),r.Xe=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{vo:!0,start(e){if(null!==i)return Nl(l,i);if(pl.get(t).get(n)===l){for(let t of vl)if(void 0!==e[t])return Nl(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of bl)void 0!==e[t]&&console.warn(`${wl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Xe=e;let n=Sl(dl.get(t))??Sl(It.get(t)),i=ml.get(t);void 0!==n?Ol(l,n):xl(t)?Nl(l,gl):ml.set(t,[...Array.isArray(i)?i:[],l])})}},Ke(){null!==l.engine&&jl(l,"$connectedCallback")},On(){null!==l.engine&&jl(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 Pl=new WeakMap,El=new WeakMap;function Wl(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 Il(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 i=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 i=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),r=Wl(l,"$bindables"),o=Wl(l,"$commands");for(let e of r){let t=i.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 o){let t=i.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 s={tag:e,bindables:r},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 i=l.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(le.tagNames.state);return a.set(l,o),Pl.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${le.tagNames.state}>: no change events.`),o},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===r.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"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,i,t)},Ke(){},On(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Rl=new WeakMap,Ll=new WeakSet,ql=new WeakMap,Dl=new WeakMap,zl="data-wcs-wired",Ul=new WeakMap,Fl=new WeakMap,Bl=new WeakMap,_l=0,Hl=new Set,Kl={},Vl=["$watch","$stream","$renderedCallback"],Jl=e=>e.split(".",1)[0];function Xl(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Gl(e,t){let n=e.a,l=Jl(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(zl);else if(!Ql(n,l)){let e=n.getAttribute(zl)?.split(" ")??[];e.includes(l)||n.setAttribute(zl,[...e,l].join(" "))}Ul.get(n)?.ce===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 i=Rl.get(n);void 0===i&&Rl.set(n,i=[]),i.push(e),t&&Ll.add(e);let r=ql.get(n);return void 0===r&&ql.set(n,r=new Map),r.has(l)||r.set(l,n[l]),Dl.get(n)?.(),!1}function Yl(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${le.tagNames.state}[bind-component]`)}function Ql(e,t){let n=e.getAttribute(le.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}var Zl=new Set;function ei(e,t){Zl.has(e)||(Zl.add(e),console.warn(`[@wcstack/state] ${t}`))}var ti=(e,t)=>t in e.state;function ni(e,t){let n=li(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function li(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 ii(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=Jl(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.w)return function(e,t){let n,l=t.w;for(;null!==l&&void 0===(n=e.st.get(l));)l=l.w;if(null===l||void 0===n)return;let i=e.x,r=e.host.engine,o=r.o(n.p.t+t.t.slice(l.t.length));if(null===o.getter)return;let s=n,a=()=>{let n=ri(e,s.r);return 0===t.n?n:(r.resolve(Xl(o.t,[...r.D(n),...i.D(ee(i.h,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.Z&&(t.Z=n=>{let l=a();oi(e,s.e,()=>r.P(o,l,n)),e.an=t}),t.n>0&&(t.A=i.Oe++),e.st.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.E!==o?ti(i,o):ni(i,o))return;l=s.ue}else{if(null===t||null!==n.w||"$"===o[0]||ti(i,o))return;s=t,l=r.o(`${t.ue.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,ri(e,a)),n.Z=t=>{oi(e,u,()=>r.P(l,a,t)),e.an=n},e.st.set(n,{e:s,p:l,r:a})}function ri(e,t){return null!==t&&!t.d&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function oi(e,t,n){let l=Hl.has(e.x);Hl.add(e.x),e.from=t;try{n()}finally{l||Hl.delete(e.x),e.from=null}}var si=(e,t)=>t||!Hl.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function ai(e,t){if(e.cn===t||null===e.host.engine)return;e.cn=t,_l+=t?1:-1;let n=e.host.engine,l=Bl.get(n);void 0===l&&Bl.set(n,l=new Map);for(let n of e.se){let e=l.get(n.e.ue);void 0===e&&l.set(n.e.ue,e=new Map);let i=e.get(n.e.r);void 0===i&&e.set(n.e.r,i=new Set),t?i.add(n):(i.delete(n),0===i.size&&e.delete(n.e.r))}let i=e.host.entries.find(e=>""===e.E);if(void 0!==i){null===e.Q&&function(e,t){let n=e.host,l=n.engine;e.Q=new Map;let i=new Set;for(let r=n.state;null!==r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let o of Object.getOwnPropertyNames(r)){if(i.has(o))continue;i.add(o);let s=Object.getOwnPropertyDescriptor(r,o);if(void 0===s.get&&void 0===s.set||"$"===o[0]||o.includes("*"))continue;let a=Jl(o);if(o!==a&&!ti(n,a))continue;let u=l.o(`${t.ue.t}.${o}`);if(null===u.getter)fi(l,u,t.ue);else if(!ui.has(u.getter))continue;e.Q.set(u,e.x.o(o))}}(e,i);for(let l of e.Q.keys())t&&null===l.getter&&fi(n,l,i.ue),n.R.xe(n,l,i.r);e.Q.size>0&&n.Ne(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.Q){let r=n.v(l.w,t.r);if(null===r||"object"!=typeof r||!(l.l in r))continue;let o=e.host.el.localName;ei(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.ce}.${i.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,i)}}var ui=new WeakSet;function ci(e,t,n,l){let i=Bl.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.E||!0!==e.m.Q?.has(l)||e.m===r||(null!==r&&v(`[wcs/mount-export-ambiguous] "${l.t}" is exported by two mounted components on the same instance: <${r.host.el.localName}> and <${e.m.host.el.localName}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),r=e.m);return r}function fi(e,t,n){let l=t.w,i=t.l,r=()=>{let t=e.read(l,e.h);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=ci(e,n,e.h,t);return null===o?void 0:o.x.read(o.Q.get(t),null)},ui.add(t.getter),t.Z=o=>{let s=null===r()?ci(e,n,e.h,t):null;if(null===s){let t=e.read(l,e.h);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.Q.get(t);void 0===li(s.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${s.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),s.x.P(a,null,o)},t.n>0&&(t.A=e.Oe++)}function hi(e,t,n,l,i,r){if(null!==t.getter)return e.R.xe(e,t,n),void e.Ne();if("*"===t.l){if(null===n)return;if(n.O=n.s.Y[n.b],e.R.Ht(n),null!==n.u)for(let t of n.u.values())e.q(t)}else e.wn(t,n);c.pe?.(e,t,n,l,i,r),e.$e(t,n)}function di(e){let t=e.m.x;for(let[n,l]of e.m.st)l.e===e.e&&(0===n.n?t.R.xe(t,n,null):t.Jt(n.c[n.n],e=>t.R.xe(t,n,e)));t.Ne()}function pi(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return di(e);let a,u=e.m,c=u.x;if(""===e.e.E){a=s.slice(1);let e=Jl(a);if("$"===e[0]||ti(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ee(l,e).b);c.resolve(Xl(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||hi(c,h,d,i,r,o)}function mi(e,t,n,l,i,r,o){if(0===_l)return;let s=Hl.has(e);Hl.add(e);try{let s=Fl.get(e);!o&&void 0!==s&&s.cn&&!Hl.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.st.get(s));)s=s.w;if(null===s||void 0===o)return;let a=e.host.engine;if(s===t&&e.an===t)return void(e.an=null);if(null!==o.r&&!o.r.d)return;let u=[...a.D(o.r),...e.x.D(n)];a.resolve(Xl(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||oi(e,o.e,()=>hi(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.cn&&null!==s.Q&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[i,r]of e.Q)r===t&&(l.R.xe(l,i,n.r),l.Ne())}(s,t);let a=Bl.get(e);if(void 0===a)return;for(let[e,s]of a)if(t.G(e)){let a=s.get(0===e.n?null:ee(n,e.n));if(void 0!==a)for(let s of[...a])si(s,o)&&pi(s,e,t,n,l,i,r)}else if(e.G(t))for(let[e,l]of[...s])if(0===t.n||ee(e,t.n)===n)for(let e of[...l])si(e,o)&&di(e)}finally{s||Hl.delete(e)}}async function gi(e,t){ai(e,!0);for(let t of e.se)di(t);t?.(),!e.broken&&(await e.x.ae("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function yi(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.U||void 0!==n&&n!==e&&n.isConnected)){Ml(t,e);for(let e of Cl.get(t)??[])e()}}),null}(e,t);let l=e.parentNode,i=l instanceof ShadowRoot,r=i?l.host:l instanceof Element?l:null,o=()=>{let t=null===r?void 0:Ul.get(r)?.F;return t?.el===e?t:null},s=t=>{throw i&&Ml(l,e),t};return{Ct:()=>(null!==r&&r.localName.includes("-")?async function(e,t,n,l){let i=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 <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let r=Ul.get(n);if(void 0!==r)return r.ce!==t&&v(`<${i}> already has a <${le.tagNames.state} bind-component="${r.ce}">.`),r.state;let o=()=>(Rl.get(n)??[]).filter(e=>Jl(e.name)===t);if(0===o().length&&(Ql(n,t)||((e,t)=>!0===e.getAttribute(zl)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{Dl.set(n,l),e=function(e,t){xl(e)&&t();let n=Cl.get(e)??new Set;return Cl.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>r(new Error(`[@wcstack/state] <${i}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Dl.delete(n);let s=o(),a=ql.get(n),u=void 0!==a&&a.has(t)?a.get(t):n[t];if((null===u||"object"!=typeof u)&&v(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===u?"null":typeof u}.`),0===s.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${le.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Kl}let c=[];for(let e of s){let l=e.name===t?"":e.name.slice(t.length+1);c.some(e=>e.E===l)&&v(`<${i}> maps "${e.name}" twice.`);let r=l.split(".").indexOf("*");if(r>=0){let n=l.split(".").slice(0,r).join(".");v(`<${i}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}c.push({E:l,ue:e.o,r:e.r,ro:Ll.has(e)}),e.engine.kn(e),""!==l&&delete n[e.name]}let f=0===s.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}(u):u;return Ul.set(n,r={el:n,ce:t,state:f,engine:0===s.length?null:s[0].engine,entries:c,F:null}),f}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${le.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){let a=!1;await async function(e,t,n,l,i){if(l===Kl)return;let r=y(l);r&&await r;let o=Ul.get(t);o.engine&&l.$recursion&&v(`[wcs/mount-dollar-declaration] <${t.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let s=o.F;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${le.tagNames.state} bind-component="${o.ce}">.`),null!==s&&ai(s,!1),null!==s&&function(e,t,n){let l=e.x,i=`[${le.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,s=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.Pn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.re.values())for(let t of e)if(null===t.B)s(t.a);else for(let e of t.B.K)a(t.B,e.S);for(let e of l.oe.values())for(let t of[e.$,...e.j??[]])null!==t&&a(t,t.S);for(let t of e.I)t.parentNode===n&&r(t)&&o.add(t);if(0===o.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!o.has(n)&&!e.I.includes(n)&&(r(n)||l.It&&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}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.I=e.I.filter(e=>e.parentNode===n),t.isConnected?await gi(e,l):l()}(s,e,n,i);let a=new ne(l,new _t);a.element=e,e.engine=a,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.U=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:l})),t}}(a,l);let u={el:e,I:[],x:a,host:o,se:[],st:new Map,cn:!1,an:null,from:null,Q:null};for(let e of o.entries)u.se.push({m:u,e});o.F=u,Fl.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.x,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=Jl(e.E);ti(n,t)&&(e.E!==t||ni(n,t))&&ei(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.ce}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.ue,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.E===t)&&ei(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.ue.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Vl.filter(e=>void 0!==n.state[e]);o.length>0&&ei(`${i}.${n.ce}$`,`[wcs/mount-dollar-declaration] <${i}>: ${o.join(", ")} ${1===o.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let s=t.Ze;t.Ze=n=>{ii(e,r,n),s.call(t,n)};let a=[...t.L.all()];for(let t of a)ii(e,r,t);for(let e of a)s.call(t,e);let u=n.entries.filter(e=>null!==e.r);if(u.length>0){let e=t._t;t._t=()=>{u.every(e=>e.r.d)&&e.call(t)}}}(u),ai(u,!0),yl.add(a),Al(a,n));let h=c.ir?.(n);Rt(a,n),h?.(),u.I=[...n.childNodes],Bt(),f&&a.bn(),Object.defineProperty(t,o.ce,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.ce);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.ae("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):ai(u,!1)}(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Ke(){let e=o();null!==e&&gi(e).catch(e=>console.error(e))},On(){let e=o();null!==e&&(ai(e,!1),!e.broken&&(e.x.ae("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var $i={name:"scopes",install(){c.ot=h(m,c.ot,Tl),c.ot=h(m,c.ot,Il),c.ot=h(m,c.ot,yi),c.Jo=Gl,c.wo=Yl,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return;let n=e.element.getRootNode();Al(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:Pl.get(n);void 0!==l&&El.set(e,{host:n,def:l})}(e,n)}),c.pe=f(c.pe,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=El.get(e);if(void 0===i)return;let r=t.t.split(".",1)[0];if(!i.def.bindables.includes(r))return;let o=l&&t.t===r;i.host.dispatchEvent(new CustomEvent(`${i.def.tag}:${r}-changed`,{detail:o?n:void 0,bubbles:!0}))})(e,t,i,r),mi(e,t,n,l,i,r,!1)}),c.me=f(c.me,(e,t,n)=>mi(e,t,n,void 0,void 0,!1,!0)),c.Re=h(d,c.Re,(e,t,n,l,i)=>(function(e,t){let n=$l.get(e);if(void 0!==n&&0===t.n)for(let 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,i=Fl.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.w)l=i.st.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.d)&&!r.ro)&&(!!n||(ri(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.ce}${""===r.E?"":`.${r.E}`}#ro: ${r.ue.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.ie;c.ie=(t,n)=>{let l=$l.get(t);void 0!==l&&l.length>0&&v(`re-setting a root state with grafted volumes (${l.join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Bl.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&v("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},vi="$recursion",bi=new WeakMap,wi=new WeakSet,ki=new WeakSet,Si=0,xi=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ai=e=>`[wcs/recursion-${e}]`;function Ni(e,t){let n=n=>v(`${Ai("declaration-invalid")} ${vi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${Ai("declaration-invalid")} ${vi} ${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 ji=(e,t)=>`${e.s}.*${e.step.repeat(t)}`;function Oi(e,t){let n=`${e.s}.**`,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.s}.*".`),l}function Mi(e,t,n){let l=Oi(e,t),i=function(e,t){for(let n=t;null!==n;n=n.s.te){let t=e.nodeList.exec(n.s.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===i&&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.`),ji(e,i.k)+l}function Ci(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${Ai("cycle")} "${n}" is reachable from itself: the data under "${t.s}" must be a tree.`),i.has(e)&&v(`${Ai("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.s}" must be a tree.`),r+1>128&&v(`${Ai("depth-exceeded")} Recursion on "${t.s}.*" reached depth ${r+1} (the limit is 128).`),i.add(e),0)),o=(i,s)=>{for(let a of i){n(s,a);let i=e.o(`${ji(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.De(a,i).f,s+1),l.delete(u))}},s=e.o(t.s),a=e.read(s,null);r(a,t.s,0)&&(l.add(a),o(e.De(null,s).f,0))}function Ti(e,t){let n=function(e){let t=e[vi],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&&z(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${Ai("declaration-invalid")} ${vi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${Ai("declaration-invalid")} ${vi} must declare exactly one anchor (it declares ${i.length}).`);let r=Ni("anchor",i[0][0]),o=Ni("repeat",i[0][1]),s=r.slice(0,-2),a=o.slice(0,-2),u=`.${o}`,c=new Map,f=[],h=`${s}.**`;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 "${r}").`),(""===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(`${Ai("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${xi(r)}((?:${xi(u)})*)${xi(n)}$`),n])}return{s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${xi(s)}((?:${xi(`.*.${a}`)})*)$`)}}(t),l=bi.has(e);null!==n?(l||Si++,bi.set(e,n),ki.add(e),wi.has(e)||function(e){wi.add(e);let t=e,n=t.Ze;t.Ze=l=>{let i=bi.get(e);if(l.t.includes("**")){let t=e.L.At(l.t)===l;return void(ki.has(e)||void 0===i&&t?l.getter=()=>z(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.A=t.Oe++),i.owners.set(l,i.s+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=bi.get(e);return l.call(e,void 0!==i&&t.includes("**")?Mi(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=bi.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,Mi(r,n,t.h));(!Array.isArray(l)||l.length>0)&&v(`${Ai("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=Oi(r,n),s=[];return Ci(e,r,(t,n)=>{for(let l of i.call(e,ji(r,t)+o,e.D(n)))s.push(l)}),s};let r=t.pn;t.pn=(n,l,i,o)=>{let s=bi.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||S(9,[n]),l.length>0&&v(`${Ai("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${Ai("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Ce>0&&S(8);let a=Oi(s,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(s.step);)u=u.slice(s.step.length);let c=s.key.split(".");(""===u||u===`.${s.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${Ai("structural-write")} "${n}" writes the recursion structure itself (a node, its "${s.key}" list or that list's length, or an object on the way to it).`);for(let e of s.families.keys()){let t=e;for(;t.startsWith(s.step);)t=t.slice(s.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${Ai("readonly")} "${n}" writes into the recursive getter "${s.s}.**${e}".`)}let f=[];Ci(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,ji(s,t)+a,e.D(n),i);return h}}(e)):l&&(bi.delete(e),Si--)}function Pi(e,t){if(0===Si)return!1;let n=bi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.w){let l=n.owners.get(e);void 0!==l&&v(`${Ai("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var Ei={name:"recursion",install(){c.ie=f(c.ie,Ti),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ki.delete(e)}(e)}),c.Re=h(d,c.Re,Pi)}},Wi="4.0.0-rc.2",Ii=e=>e.split(".").slice(0,2).join("."),Ri=class extends Xt{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 Ii(this.version)===Ii(Wi)}};function Li(e){let t=le.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Ri{})}var qi=()=>le.tagNames.ssr,Di=Symbol.for("wcstack.ssr.snapshotBuilder"),zi=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Ui=e=>document.createComment(e),Fi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Bi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),_i=new WeakMap,Hi=new WeakMap,Ki=new WeakMap,Vi=new WeakSet,Ji=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 Gi(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 Yi=e=>null===e.I?e.He:e.I[e.I.length-1];function Qi(e,t,n){let l=[Ui(null===n?"wcs-[":`wcs-[:${n}`)];for(let e of t)null===n&&l.push(Ui("wcs-|")),l.push(...Xi(e.He,Yi(e)));l.push(Ui("wcs-]")),e.after(...l);for(let e of l)Vi.add(e)}function Zi(e){if(e instanceof st){Qi(e.S,e.ve,null);for(let t of e.ve)er(t);return}let t=e.F;null!==t&&(Qi(e.K[e.K.length-1].S,[t],e.b),er(t))}function er(e){if(null!==e.u)for(let t of e.u)Zi(t)}var tr=new Set(["script","style","template","textarea","title"]),nr="data-wcs-raw",lr=e=>tr.has(e.localName)||e.localName===qi();function ir(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Ui("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Ui("wcs-s")):1===t.nodeType&&!lr(t)&&ir(t)}var rr=0;function or(e,t){let n=e.getRootNode(),l=[t];for(let e of Hi.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=_i.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.j)for(let e of t.j)n.set(e.S,e);for(let t of e.re.values())for(let e of t)if(null!==e.B)for(let t of e.B.K)n.set(t.S,e.B);let l=new Set;for(let[e,r]of t){i.set(e,r);let t=n.get(e);void 0!==t&&!l.has(t)&&e.isConnected&&(l.add(t),Zi(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ki.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Vi.has(e)||1===e.nodeType&&t.has(e)&&fr(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(lr(e.parentNode)?Ji.has(e):t.has(n)&&Bi(n,"wcs-t:"))&&(Ji.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);lr(e)&&n.some(e=>Ji.has(e))&&e.setAttribute(nr,n.map(e=>Ji.has(e)?`{{ ${Ji.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}ir(9===n.nodeType?n.body:n);let r=document.createElement(qi());r.setAttribute("version",Wi);let o=document.createElement("script");o.type="application/json",o.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)),r.append(o);for(let[e,t]of i){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,i=`wcs-${l?"s":"t"}${rr++}`;e.replaceWith(Ui(`wcs-p:${i}`));let o=document.importNode(Mt(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Gi(e,document.createElement("template"),...e.childNodes));if(l){let e=document.createElementNS(n.namespaceURI,"svg");e.append(o),o=e}let s=document.createElement("template");s.id=i,r.append(Gi(t,s,o))}e.before(r)}function sr(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=>Ji.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===qi())continue;let e=t.engine;null!=e&&or(t,e)}}var ar=Symbol.for("wcstack.state.ssr.impl"),ur=new Map,cr=new WeakMap,fr=e=>!0===c.wo?.(e),hr=e=>1===e.nodeType&&!lr(e)&&!fr(e),dr=e=>e.f.flat().concat(e._??[]),pr=e=>{for(let t of dr(e))t.remove()};function mr(e,t,n){let l=/^wcs-\[(?::(\d+))?/.exec(e.data),i=e.previousSibling,r=e.parentNode,o=[],s=e.nextSibling;for(e.remove();null!==s&&!Fi(s,"wcs-]");){let e=s.nextSibling;if(Fi(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];Bi(s,"wcs-[")?e=mr(s,t,n):(n.push(s),hr(s)&&gr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,_:s??r.appendChild(Ui("wcs-]"))},u=dr(a);s=a._.nextSibling;for(let e of u)n?.push(e),t&&Nt.add(e);return t&&null!==i?ur.set(i,a):pr(a),s}function gr(e,t){for(let n=e.firstChild;null!==n;)Bi(n,"wcs-[")?n=mr(n,t):(hr(n)&&gr(n,t),n=n.nextSibling)}function yr(e,t,n){let l=e=>{for(let i of Array.from(e.childNodes))if(i.parentNode===e)if(8===i.nodeType){let e=i.data;try{if("wcs-s"===e)i.remove();else if("wcs-e"===e)i.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Ui(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!Fi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),i.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=i.parentNode,l="s"===e[10]?Gi(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);l.removeAttribute("id"),t.replaceChild(l,i)}}}catch{}}else 1===i.nodeType&&!lr(i)&&(fr(i)?cr.set(i,{ssr:t,Te:n}):l(i))};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||xr(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Bi(e,"wcs-[")?l++:Fi(e,"wcs-]")&&--l<0&&(l=0,n=t+1)}),0===l)continue;let i=0;for(let l=t.firstChild;null!==l;l=l.nextSibling)if(Bi(l,"wcs-["))i++;else if(Fi(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),gr(e,n)}function $r(e){let t=cr.get(e);if(void 0===t||(cr.delete(e),yr(e,t.ssr,t.Te),!t.Te))return null;let n=c.Te;return c.Te=jr,()=>{c.Te=n,vr()}}function vr(){for(let e of ur.values())pr(e);ur.clear()}function br(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function wr(e,t,n,l){let i=null;for(let l of e){let e=l[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===i||e.length>i[n].length)&&(i=l)}let r=i?.[l];if(null==r)return null;let o=i[n],s=""===o?t:t.slice(o.length+1);return""===r?s:""===s?r:`${r}.${s}`}function kr(e,t,n){if(zi()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Vi.add(e);else if(e.localName.includes("-")&&!fr(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ki.set(e,t)}return}if("string"==typeof n){if(Ji.set(t,n),lr(t.parentNode))return;let e=Ui(`wcs-t:${encodeURIComponent(n)}`),l=Ui("wcs-/t");return t.before(e),void t.after(l)}let l=_i.get(e);void 0===l&&_i.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Hi.get(i);return void 0===r&&Hi.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&ur.size>0){let e=ur.get(n);void 0!==e&&(ur.delete(n),ur.set(t,e))}}var Sr=e=>null!==e&&8===e.nodeType&&[le.commentIfPrefix,le.commentElseIfPrefix,le.commentElsePrefix].includes(e.data),xr=e=>3===e.nodeType&&""===e.data.trim(),Ar=e=>(ur.get(e)?._??e).nextSibling;function Nr(e,t){if(t.length!==e.nn.childNodes.length)return!1;let n=e.Rn;for(let l=0;l<n.length;l++){let i=n[l],r=e.nn,o=t[i[0]];for(let e=0;;){if(r=r.childNodes[i[e]],o?.nodeName!==r.nodeName)return!1;if(++e===i.length)break;o=o.firstChild;for(let t=i[e];t>0&&null!==o;t--)o=Ar(o)}e.ho[l]=o}return!0}function jr(e,t,n){if(0===ur.size)return null;let l=t,i=0;if(!n){let e=le.commentIfPrefix;if(!Fi(t,e))for(let n=t.previousSibling;null!==n&&(Sr(n)||xr(n))&&(Sr(n)&&i++,!Fi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!ur.has(l)&&null!==n&&!Fi(n,e)&&(Sr(n)||xr(n));n=n.nextSibling)Sr(n)&&(l=n)}let r=ur.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return ur.delete(l),pr(r),null;let o=r.f.shift();if(0===r.f.length&&ur.delete(l),r._?.replaceWith(...Xi(t,l)),r._=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=ur.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t._;)e++}if(!Nr(e,s)){let n=(e.Tn?e.root:e.nn).cloneNode(!0);s=e.Tn?[n]:[...n.childNodes],Nr(e,s),(o[0]??r.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of o)e.remove()}return s}var Or={name:"ssr",install(){c.An=kr,c.ir=$r;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||zi())return;let n=t.previousElementSibling,l=n?.localName===qi(),i=l?n.getAttribute("version"):null,r=null===i||Ii(i)===Ii(Wi);if(r){let t=e,n=t.ae;t.ae=(t,l)=>"$connectedCallback"===t?void 0:n.call(e,t,l)}if(!l)return;let o=!r&&parseInt(i)<4,s=/^3\.(\d+)\.(\d+)$/.exec(i),a=null!==s&&(+s[1]-5||+s[2]-3)>=0;r||console.warn(`[@wcstack/state] <${qi()} version="${i}"> does not match ${Wi}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!a?" 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 u=r?n.querySelector('script[type="application/json"]'):null;if(null!==u){let t=JSON.parse(u.textContent||"{}"),n=e.target;for(let e of Object.keys(t)){let l=Object.getOwnPropertyDescriptor(n,e);void 0!==l&&(void 0!==l.get||void 0!==l.set||"function"==typeof l.value)||(n[e]=t[e])}e.hydrated=!0}let f=t.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${nr}]`)))e.textContent=e.getAttribute(nr),e.removeAttribute(nr);let h=9===f.nodeType?f.body:f;o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!fr(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=i(t),r=t.querySelector(`:scope > ${le.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ae(t.getAttribute(le.bindAttributeName)??"")){let t=l.Ye;l.ye[0]===r&&n.push([e?wr(e,t,1,0):t,l.ye.slice(1).join("."),e&&t])}}return n},r=(e,t,n)=>{let l=i(e);if(null===l)return t;let r=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===r)return n?t:wr(l,t,0,1)??t;let o=r[1].replace(/#m\d+\./g,"").slice(0,-1);return l.some(e=>""===e[1]&&(e[0]===o||e[2]===o))?r[2]:wr(l,r[2],2,1)??r[2]};for(let t of br(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Fi(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]?[Ui(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of br(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let s=document.importNode(i,!0),a=le.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(h,n,a):yr(h,n,r),n.remove(),r&&(c.Te=jr,queueMicrotask(()=>{vr(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[ar]={build:sr,reset(){rr=0}},void 0===e[Di]&&(e[Di]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[ar].build(t),reset:()=>e[ar].reset()})}(),c.Eo=f(c.Eo,Li);for(let e of Qt())Li(e)}},Mr="__WCSTACK_DEVTOOLS_HOOK__",Cr=null,Tr=new Set,Pr=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.D(n)}}),Er=new WeakMap,Wr=0;var Ir=new WeakMap;function Rr(e){if(null===Cr)return;let t=Ir.get(e),n=Tr.has(e)?function(e,t){let n=new Map,l=new Set,i=(l,i,r,o,s,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,i),c=0===o.n?null:s,f=`${(e=>{let t=Er.get(e);return void 0===t&&Er.set(e,t=++Wr),t})(r)}|${u}|${o.t}|${null===c?"":e.D(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:o.t,bindingType:a,node:r,replaceNode:r},absoluteAddress:Pr(e,o,c)})},r=e=>i(e.i,e.name,e.a,e.o,e.r,e.Zt()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.de)for(let t of e.de)r(t);if(e instanceof Ye&&null!==e.se){let t=e.T.Ue;for(let n=0;n<t.length;n++){let l=e.U?.[n];void 0!==l?r(l):i(t[n].i,t[n].name,e.se[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)s(t)}},s=e=>{if(!l.has(e))if(l.add(e),e instanceof st){i(-1,"for",e.S,e.s.o,e.s.te,"for");for(let t of e.ve)o(t)}else null!==e.F&&o(e.F)};for(let t of e.re.values())for(let e of t)r(e),null!==e.B&&s(e.B);for(let t of e.oe.values())if(null!==t.$&&s(t.$),null!==t.j)for(let e of t.j)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||Cr({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&Cr({type:"state:binding-added",...l});Ir.set(e,n)}function Lr(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function qr(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.L.all()){for(let e=1;e<=r.n;e++)t.add(r.c[e].t);"*"===r.l&&n.add(r.t),null!==r.getter&&l.add(r.t),null!==r.Z&&i.add(r.t)}let r=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:l,setter:i},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.Se.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==r.$watch&&"object"==typeof r.$watch?new Set(Object.keys(r.$watch)):null,keyedListPaths:null!==r.$listKeys&&"object"==typeof r.$listKeys?new Set(Object.keys(r.$listKeys)):null}}var Dr=new WeakSet,zr=new WeakMap;function Ur(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Dr.has(t))return;Dr.add(t);let l=t.emit;t.emit=(...i)=>(null!==Cr&&Cr({type:"state:token-emit",kind:n,tokenName:t.name,args:i,subscriberCount:t.size,stateElement:e.element}),l.apply(t,i))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.Se.values())t(n,"event")}(e),"connected"===t){if(Tr.has(e))return;Tr.add(e),Cr?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Rr(e)}else"disconnected"===t&&(Tr.delete(e),Rr(e),Cr?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function Fr(e,t,n,l,i,r){if(null===Cr)return;let o=Pr(e,t,0===t.n?null:n),s=zr.get(e);void 0===s&&zr.set(e,s=new Set),s.add(o),r&&Cr({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function Br(e){if(null===Cr)return;let t=zr.get(e);zr.delete(e),void 0!==t&&Cr({type:"state:update-batch",addresses:t}),Rr(e)}function _r(e,t,n){Cr?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.Zt(),error:t})}!function(e){for(let t of e)g.has(t.name)||(g.add(t.name),t.install())}([on,En,il,hl,$i,Ei,Or,{name:"devtools",install(){c.element=f(c.element,Ur),c.pe=f(c.pe,Fr),c.Pe=f(c.Pe,Br),c._e=f(c._e,_r),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[Mr]??(e[Mr]=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!==t.version&&console.warn(`[@wcstack/state] devtools hook registry version ${t.version}, expected 2: keeping the existing one.`),t.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:Wi,getStateElements:()=>[...Tr].map(qr),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.L.all()){let l=n.H,i=n.Fe?.length??0;if((null===l||0===l.size)&&0===i)continue;let r,o=0;if(null!==l)for(let e of l.values())o+=e.size;try{r=0===n.n?e.v(n,null):void 0}catch{r=void 0}t.push({path:n.t,tracked:!1,rows:o,keys:null===l?0:l.size,lists:i,lastValue:r})}return t}(Lr(e)),keys(e){let t=Lr(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 Lr(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){Lr(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===Cr&&null!==e;Cr=e,null===e&&(Ir=new WeakMap),c.tt=e&&((e,t)=>Cr?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of Tr)Rr(e)})}})}()}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[qt]&&(e[qt]={protocol:"wcs-binder",version:1,bind:Ft})})(),Qt().includes(e)||Yt.push(new WeakRef(e));let t=le.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Gt{}),c.Eo?.(e)}();
|