@wcstack/state 4.10.0 → 4.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/auto.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=class{constructor(e,n,l){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.B=[],this.Q=[],this.ht=null,this.F=-1,this.Y=t,this.De=null,this.jt=null,this.Dt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.yt=new Set,this.t=e,this.a=l,this.s=n;let i=null===l?[null]:l.h.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this.z=r?[]:null===l?[n]:[...l.z,n],this.h=i}Hn(e){this.yt.has(e)||(this.yt.add(e),this.B.push(e),e.Q.push(this))}Bo(e){this.yt.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Mo(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.yt.clear(),this.Q.length=0,this.ht=null,this.De=null,this.jt=null,this.Dt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.a}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.wt=new Map,this.Un=e}bt(e){return this.wt.get(e)}get(t){let n=this.wt.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.Un?.(n),this.wt.set(t,n),i&&i.u.push(n),n}all(){return this.wt.values()}Lt(e){this.wt.delete(e.t)}},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.size>4095&&r.clear(),r.set(e,o),o}var s=class{constructor(e,t,n){this.vt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.E=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Bt=!1,this.kt=!1,this.o=e,this.ce=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.Wt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Wt(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._o?.(e,t,n)??""}`)}function w(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function b(e,t=[]){return c.Vo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function k(e,t,n,l){v(b(e,t),n,l)}var S=class{constructor(e){this.St=new Set,this.name=e}get size(){return this.St.size}subscribe(e){return this.St.add(e),()=>{this.St.delete(e)}}unsubscribe(e){return this.St.delete(e)}emit(...e){let t=[];for(let n of this.St)try{t.push(n(...e))}catch(e){t.push(void 0),w(e,`[@wcstack/state] ${b(17,[this.name])}`)}return t}};function x(e,t,n){if(void 0===e)return[];Array.isArray(e)||k(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&k(19,[t]),i===n&&k(20,[t,i,n]),l.has(i)&&k(21,[t,i]),l.add(i);return e}var A=Symbol.for("wcstack.transition-runner");function N(e){let t=globalThis[A];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 j(e,t,n){let l=N(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var O="else",C="eventToken",M="class",T="attr",P=/^\$[1-9]\d{0,2}$/,E=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function W(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:E.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&&k(107,[i,e]),a(!0),{args:t,literals:n}}var I=e=>e.trim();function R(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 D=(e,t)=>R(e,t)[0]??-1;function q(e,t){let n=[],l=0;for(let i of R(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function L(e,t,n){let l=D(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=D(e,"("),i=(e=>R(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&k(108,[e]),-1!==i&&-1===n&&k(109,[e]),-1!==i&&i<n&&k(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();k(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&k(112,[l]),r.includes("#")){let[,e]=r.split("#");k("input"===t?113:114,[r,e])}return-1===n?{qn:r,args:[],literals:[]}:{qn:r,...W(e.substring(n+1,i))}})}(q(i,"|").map(I),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var z=new Map;function U(e){k(1101,[e])}function F(e){let[t,n]=L(e,"output",z);t.includes("@")&&k(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)&&k(119,[e]),function(e){e.includes("**")&&U(e);let t=e.split(".").length;t>512&&k(117,[e,t])}(l),{et:l,tt:n}}var V=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],_=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function B(e){return e.includes("**")&&U(e),e}var H=0;function K(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var J=()=>new Set,G=()=>[],Y=new WeakMap;function Z(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function ee(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function te(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function ne(e,t,n){let l=te(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var le=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.nt=new Set,this.ot=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.$t=[],this.Me=null,this.zn=[],this.Ut=0,this.G=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.He=!1,this.gn=!1,this.qt=new WeakMap,this.j=0,this.Kt=0,this.yn=0,this.wn=0,this.bn=!1,this.zt=!1,this.Yt=!1,this.Ce=0,this.Yn=()=>{this.j=0,this.bn=!1},this.Gn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Ho=()=>{this.He&&this.Et()},this.Uo=(e,t)=>e(this.proxy,...t),this.Xn=[],this.Ue=[],this.Jn={$untracked:e=>{let t=this.G;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=te(this.d,t);null===n&&k(7,[e]);let l=this.o(e);if(null!==l.getter||l.ae)return this.watchIndex(t),n.y===this.read(l,null);let i=this.G;if(null!==i){let e=i.getter,n=l.De??(l.De=[]);if(!n.some(n=>n.getter===e&&n.Qn===t)){n.push({getter:e,Qn:t});let i=e.h[t];(i.jt??(i.jt=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,te(this.d,n.n)))},$dependOn:e=>{this.resolve(B(e),this.d),null!==this.G&&0===this.G.be&&this.Zn(this.rp,this.rr,this.G)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.vn(e,t,n,l),$resolve:(...e)=>{let t=B(e[0]),n=e[1]??[],l=this.o(t,!0);this.kn("$resolve",t,l,n,!0);let i=this.eo(l,n,null);if(e.length<3)return this.read(l,i);this.A(l,i,e[2])},$postUpdate:e=>{this.resolve(B(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.E=n.l.P[n.y],Y.delete(n.l.P),this.T.Gt(n)),this.Sn(t,n),null!==n&&this.to(n,t,void 0,n.E,!1),0===t.n&&this.no(t,void 0,void 0,!0),this.Xt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.Ue.push(e),this.rt(e)}),this.oo(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.it(t);if(t.indexOf(".")<0){let e=n.O.bt(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return l===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(B(t),n.d),n.A(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}io(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.se=l.set??null,null!==i.getter&&i.n>0&&(i.F=this.Le++)}for(let e of this.O.all())this.rt(e)}rt(e){e.t.includes("**")&&U(e.t),("__proto__"===e.s||"prototype"===e.s)&&k(120,[e.t]);let t=e.a;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.qo(e)}qo(e){let t=e.t,n=e.s;if(P.test(n))e.getter=function(){return this[n]};else{let l=t.split("."),i=l.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(i<0||l.indexOf("*",i)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.a,this.d)?.[n]),e.se=l=>{if(this.resolve(t,this.d),this.rp!==e)return this.A(this.rp,this.rr,l);let i=this.read(e.a,this.d);null==i&&k(4,[t,i]),i[n]=l}}e.hn=!0,e.n>0&&(e.F=this.Le++)}qe(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)),t.pn=!0,this.X(l),l}so(e){try{this.X(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}X(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.lo(e);let n=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.P)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].E===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].E===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.Mt(i[e]);else{let t=f<h?f:h;for(let e=c;e<=t;e++)i[e].E===l[e]&&(a[e]=i[e]);let r=new Map;for(let e=f;e>=c;e--){let n=i[e];if(e<=t&&a[e]===n)continue;let l=r.get(n.E);void 0===l?r.set(n.E,n):Array.isArray(l)?l.push(n):r.set(n.E,[l,n])}for(let t=c;t<=h;t++){if(void 0!==a[t])continue;let n,i=l[t],o=r.get(i);void 0!==o&&(Array.isArray(o)?(n=o.pop(),0===o.length&&r.delete(i)):(n=o,r.delete(i))),a[t]=n??new s(e,t,i)}for(let e of r.values())if(Array.isArray(e))for(let t of e)n.Mt(t);else n.Mt(e)}for(let e=c;e<r;e++){let t=a[e];t.y!==e&&(t.y=e,n.Wo(t))}return e.f=a,e.P=l,i}(e,t,this);if(null===n)return;if(e.P===t){let n=K(this.qt,t,G);if(n.push(e),n.length>1)for(let e of n)e.kt=!0}c.Qt?.(this,e,n),(null!==e.N||null!==e.M)&&!e.te&&(e.te=!0,this._e.push(e),this.ve());let l=e.o.jt;if(null!==l)for(let{source:t,getter:i}of l){let l=this.v(t,null),r=n[l],o=e.f[l];r!==o&&(void 0!==r&&r.w&&this.$n(i,r),void 0!==o&&this.$n(i,o))}}Wo(e){this.T.Ko(this,e)}Mt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)Q(e.source,e.key,e.sub);e._=null}if(null!==e.u)for(let t of e.u.values()){this.lo(t);for(let e of t.f)this.Mt(e)}}lo(e){let t=this.qt.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.kt=!1,1===t.length&&(t[0].kt=!1))}resolve(e,t){let n=o(e),l=this.rp=this.o(n.o,!0),i=n.indexes;this.rr=0===l.n?null:null===i?ne(t,l,l.n):this.eo(l,i,t,e)}eo(e,t,n,l){let i=null;for(let r,o=1,s=0;o<=e.n;o++){let a=e.h[o],c=this.qe(i,a),f=t[s++];if(f<0)f=ne(n,e,o)?.y??-1;else if(l&&c.P===u&&Object(r=this.v(a,i))===r){let t=e.t.split("."),n=a.t.split(".").length;t[n]=l.split(".")[n],e=this.o(t.join("."),!0),o--;continue}if(i=c.f[f]??null,null===i)break}return this.rp=e,i}st(e,t){return 0===e.n?ee(this.target,e.z):null===t?void 0:ee(t.E,e.z)}read(e,t){let n=this.G;if(null!==n&&0===n.be&&this.Zn(e,t,n),null!==e.getter)return this.T.zo(this,e,t);if(e.ae){let n=this.read(e.a,t);return n?.[e.s]}return null===e.a&&!(e.s in this.target)&&!this.nt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&k(301,[e.t],e.s,Object.keys(this.target)),this.st(e,t)}v(e,t){let n=this.G;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Zn(e,t,n){let l=n.getter;e.Hn(l),0===l.n?e.Z!==n.de&&(e.Z=n.de,n.En.push(e)):e.n>0&&te(t,Math.min(e.n,l.n))!==te(n.r,Math.min(e.n,l.n))&&(l.ht??(l.ht=new Set)).add(e)}Yo(e,t){for(let n=0;n<this.Ut;n++){let l=this.zn[n];l.getter===e&&l.r===t&&k(701,[e.t])}this.Ut>=128&&k(801,[e.t]);let n=this.Ut++;this.Be++;let l=this.zn[n]??={getter:e,r:t,be:0,de:0,En:[]};l.getter=e,l.r=t,l.be=0,l.de=++H,l.En.length=0;let i=this.G;this.G=l;let r=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Go(e,l),t}finally{this.Be--,this.Ut--,this.G=i,this.d=r,l.r=null}}Go(e,t){let n=t.de;for(let e of t.En)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.st(t,null))||this.ao(t,e))}ao(e,t){return e.Bo(t),this.Ue.push(e),!1}Xo(){for(let e=this.Ue;e.length>0;e=this.Ue){this.Ue=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.a||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Lt(n),t.add(n.a);for(let e of n.Q)this.ao(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.Ue.push(e)}}watchIndex(e){let t=this.G;if(null!==t&&0===t.be){let n=t.getter,l=n.h[e];if(l){let e=l.Dt??(l.Dt=[]);e.includes(n)||e.push(n)}}}it(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:P.test(e)?+e.slice(1):0;return(n<1||n>128)&&k(1001,[e]),this.watchIndex(n),te(this.d,n)?.y}let n=this.Jn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.it?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,l=this.rr;if(null!==n.getter||n.ae||n.n>0)return X(this.read(n,l),t);let i=this.G;return null!==i&&0===i.be&&this.Jo(n,t,i),X(this.v(n,null),t)}Jo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Xn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(X(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};K(e._??=new Map,t,J).add(o),r.push({source:e,key:t,sub:o,de:n.de})}no(e,t,n,l){this.Zt(e,i=>{let r=i._;if(null===r&&null===i.De)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=ee(t,o),a=ee(n,o);if(null!==i.De&&this.Qo(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.w?this.T.ke(this,n.getter,n.r):Q(i,e,n)}})}A(e,t,n,l=!1,i=!1){if(this.Be>0&&k(8),i||this.Ce>0?this.zt=!0:this.Yt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.Nn(e.se,t,[n])}finally{this.Xt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&k(2,[e.t]),e.n>0&&null===t&&k(3,[e.t]);let r=e.ae?this.v(e,t):this.st(e,t);if(l||!this.Vt||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,Y.delete(e.l.P),e.E=n,this.T.Gt(e)}else{let l=1===e.z.length?0===e.n?this.target:t.E:this.v(e.a,t);null==l&&k(4,[e.t,l]),l[e.s]=n}this.xn(e,t),null!==t&&this.to(t,e,r,n),0===e.n&&this.no(e,r,n),this.Xt(e,t,r,n,!0,i)}}co(e){return(this.qt.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}to(e,t,l,i,r=!0){let o=e.l,s=t.t.slice(o.o.t.length+2),a=""!==s&&function(e){let t=Y.get(e);if(void 0===t){let n=new Set;Y.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.kt&&null===o.o.getter&&!o.o.B.length)return;let u=e.E,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(n.E=i,this.T.Gt(n)),r?this.xn(o,n):this.Sn(o,n),this.Xt(o,n,l,i,r)};for(let t of this.co(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.E===u&&n.y!==e.y&&c(t,n);if(""===s)return;let f=new Set([o.P]),h=e=>Array.isArray(e)&&e.includes(u),d=(e,t)=>{if(!f.has(e)&&f.add(e))for(let t of this.qt.get(e)??[])for(let e of t.f)e.E===u&&c(t,e);for(let l of t){let t=l.Y,i=t===n;i&&(t=this.oe.get(l)?.P),(i||h(t))&&!f.has(l.B)&&f.add(l.B)&&(!i&&t!==e&&this.T.ke(this,l,null),d(t,l.B))}},p=e=>{for(let t of e.Q)if(!f.has(t)&&f.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.st(t,null);h(e)&&d(e,t.B)}};null!==o.o.getter?p(o.o):d(o.P,o.o.B)}Sn(e,t){this.Zo(e,t,e=>{this.X(e);for(let t of e.kt?this.co(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.Nt(e,n),this.Sn(e,n)}})}xn(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.X(t)}Zo(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Qo(e,t,n,l){for(let{getter:i,Qn:r}of e.De)this.uo(i.h[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.$n(i,t)}})}$n(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Xt(e,t,n,l,i,r){c.re?.(this,e,t,n,l,i,r),this.Ke(e,t)}Ke(e,t){this.T.er(this,e,t),this.ve()}fo(e){let t=this.ot.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.ot.set(e,n);let l=this.root,i=this.Kn;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.w&&o.tr(e,t))return}}),n}reset(e){let t=this.target,n=this.nt;for(let e of this.O.all())null===e.a&&null!==e.getter&&n.add(e.s);this.oo(e);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.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.po(e);this.Me=null;try{this.Et()}finally{this.Rn()}c.element?.(this,"reset")}oo(e){for(let[t,n]of V)void 0!==e[t]&&$(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||k(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&k(44,["state","$behavior"]);for(let e in n)(!_.includes(e)||"boolean"!=typeof n[e])&&k(44,["$behavior",e]);let[l,i,r]=_.map(e=>n[e]??!0);void 0!==this.target&&(l!==this._t||i!==this.Vt||r!==this.Ht)&&k(45);let o=function(e,t){let n={};for(let l of x(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new S(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of x(e.$eventTokens,"$eventTokens"))n.set(t,new S(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&k(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&k(23,[e]),"function"!=typeof i&&k(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this.Uo);this._t=l,this.Vt=i,this.Ht=r,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Mo();this.Xn.length=0,this.io(e),this.commands=o,this.Oe=s}po(e){this.so(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.vt=null,n._=null,this.Nt(t,n),null!==n.u)for(let e of n.u.values())this.po(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}nr(e,t,n){let l=this.Oe.get(e);void 0===l&&k(1301,[e],e,this.Oe.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&k(1302,[e],e,Object.keys(this.commands)),t}or(e,t,n){this.command(e).emit(t,...this.H(n))}ir(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&k(5,[e]),this.Nn(l,n,[t,...this.H(n)])}Nn(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}Nt(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Bt&&t.o.ee(e)&&(t.Bt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.we;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let l=t.N;null!==l&&null!==l.pe&&l.mo(this,e);let i=t.l.M;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.pe&&l.mo(this,e)}}Pn(e,t,n){this.Zt(e,e=>{let l=e.B;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.at(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.ht&&r.ht.has(e))this.nn(r.h[r.n],e=>this.at(r,e,n));else if(r.n<=e.n){let e=te(t,r.n);null!==e&&this.at(r,e,n)}else this.en(t,r,e=>this.at(r,e,n))}})}at(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.Nt(e,t),this.Pn(e,t,n))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.uo(e,e=>{for(let n of e.f)t(n)})}uo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}en(e,t,n){if(e.l.n===t.n)return n(e);let l=e.u?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.en(e,t,n)}sr(e){let t=e.r;null===t?K(this.ue,e.o,J).add(e):(t.we??(t.we=[])).push(e)}Tn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.He||(this.He=!0,queueMicrotask(this.Ho))}An(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Bt=!1;this.We=[],this._e=[],this.Ve=[],this.T.nt(this)}ho(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];w(n,`[@wcstack/state] ${b(e)}`),c.ct?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.An()}Et(){this.He=!1;let e=this.Kt;this.Kt=0;let t=0;if(!this.zt||this.Yt?this.Yn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Yn,0),this.zt=this.Yt=!1,t>100)101===t?this.ho(41,100):this.An();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.bn?this.An():this.ho(11,32),this.bn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Bt=!1,this.so(e)}let l=this._e,i=this.We;this._e=[],this.We=[];let r=!1,o=()=>{r=!0;for(let e of l){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.xt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<i.length;t++){let n=i[t];!n.te||null===n.j==(0===e)||(n.te=!1,(null===n.Fn||n.Fn.w)&&this.ze(n))}if(!this.gn&&(this.Ye(),0===--this.yn&&this.go(),this.He)){this.Kt=t+1,this.wn++;try{for(;this.He;)this.Et()}finally{this.wn--}}},s=(l.length>0||i.some(e=>null!==e.j))&&0===this.wn?j("state",o):o();r||this.yn++,void 0!==s&&s.then(void 0,w)}}finally{this.gn=!1}this.zt=this.Yt=!1,this.Ye(),0===this.yn&&this.go(),e>0&&this.He&&(this.Kt=t+1)}}go(){c.me?.(this),this.Xo()}Rt(e,t){this.$t.push([e,t])}Jt(e,t,n,l){this.Rt(e,{o:{t},c:n,on:()=>l})}ze(e){try{e.apply()}catch(t){return void this.$t.push([t,e])}null!==this.Me&&this.yo(e.o,e.r)}yo(e,t){let n=K(this.Me,e.t,G);null!==t&&n.push(this.H(t))}Rn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}Ye(){let e=this.Me;if(null!==e&&e.size>0){this.Me=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Ce++;try{t=this.$e("$renderedCallback",[n,l])}catch(e){w(e)}Z(t)?t.then(this.Gn,e=>{this.Gn(),w(e)}):this.Ce--}if(0===this.$t.length)return;let t=this.$t;this.$t=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ge?.(this,e,l);let t=l.o.t,i=l.on();if("function"==typeof n)try{let n=this.$e("$errorCallback",[e,{path:t,bindingType:i,node:l.c}]);Z(n)&&n.then(void 0,w)}catch(e){w(e)}else w(e,`[@wcstack/state] ${b(12,l.name?[i,t,l.name,l.i]:[i,t])}`,l.c)}}$e(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Nn(n,null,t):void 0}wo(e,t,n){if(0===e.n)return void n(null,[]);let l=[],i=(r,o)=>{let s=e.h[r];this.read(s,o);let a=this.qe(o,s),u=t=>{l.push(t.y),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,!0);void 0!==t&&this.kn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=ne(t,n,e);if(null===i)break;l.push(i.y)}0===l.length&&k(6,[e])}}let i=[];return this.wo(n,l,e=>i.push(this.read(n,e))),i}vn(e,t,n,l){Array.isArray(t)||k(9,[e]),this.Be>0&&k(8);let i=this.o(e,!0);this.kn("$setAll",e,i,t,!1);let r=[];this.wo(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&k(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.A(i,t,a),s++)}return s}kn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&k(i?901:902,[e,t,n.n,r])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},re=new Map,oe=new Set(["if","elseif","else","for"]),se=new Set([O,"if","elseif","for","..."]),ae=new Set([M,T,"style","command",C,"state"]);function ue(e){let t=function(e){return q(e,";")}(e).map(I).filter(e=>e.length>0).map(e=>{let t=D(e,":");-1===t&&k(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(se.has(i)){let t;return i!==n&&k(102,[e,i]),i===O?(l.length>0&&k(103,[e]),t={et:"#else",tt:[]}):"..."===i?(0===l.length&&k(104,[e]),t=F(l),t.tt.length>0&&k(105,[e])):(t=F(l),"for"===i&&t.tt.length>0&&k(121,[e])),{Ee:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===M||i===T)&&k(122,[e,i]);let r=F(l),o=function(e){let[t,n]=L(e,"input",re),l=t.split("#").map(I);l.length>2&&k(115,[t]);let[i,r]=l,o=i.split(".").map(I);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&k(116,[e]),{Ee:i,Ne:o,rn:r?r.split(",").map(I):[],D:n}}(n),[s]=o.Ne;if(""===s&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||ae.has(e[0]))&&k(106,[n]),{...o,Ee:e.join("."),Ne:e,...r,b:"prop"}}return{...o,...r,b:"radio"===i||"checkbox"===i?i:s===C||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>oe.has(e.b))&&k(201,[e]),t}var ce=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],fe=new Map,he=new Map;function de(e){for(let t of Object.keys(e))fe.set(t,{...e[t]});he.clear()}function pe(e){return fe.has(e)}function me(e){k(26,[e])}function ge(e){k(27,[e])}function ye(e,t){k(28,[e,t])}function $e(e,t){k(29,[e,t])}function ve(e){return!(!e||isNaN(Number(e)))}function we(e,t){return ve(e)||ge(t),Number(e)}function be(e,t,n){return we(e?.[t]??me(n),n)}function ke(e,t){return void 0!==t&&t.length>0?t[0]:e}var Se=(e,t)=>({factory:n=>{let l=be(n,0,e);return n=>("number"!=typeof n&&ye(e,n),t(n,l))},arity:[1,1]}),xe={eq:{factory:(e,t)=>{let n=e?.[0]??me("eq"),l=ke(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(ve(n)||ge("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??me("ne"),l=ke(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(ve(n)||ge("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Se("lt",(e,t)=>e<t),le:Se("le",(e,t)=>e<=t),gt:Se("gt",(e,t)=>e>t),ge:Se("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ae=!1;function Ne(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function je(e){return 0===e.length?null:(Ae||(Ae=!0,de(xe)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=he.get(l);if(typeof i<"u")return i;let r=fe.get(e);void 0===r&&function(e,t){ce.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),k(501,[e],e,t)}(e,fe.keys());let[o,s]=r.arity;t.length<o&&k(601,[e,o,t.length]),t.length>s&&k(602,[e,s,t.length]);let a=r.factory(t,n);return he.set(l,a),a}(e.qn,e.args,e.literals)))}var Oe=Symbol.for("wcstack.trustedTypes.policy");function Ce(){let e=globalThis[Oe];return null!==e&&"object"==typeof e?e:null}function Me(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Te(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ce(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Pe=Symbol.for("wcstack.state.view-transition-naming"),Ee=new WeakSet;function We(){let e=N("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Ie=new WeakMap,Re=e=>e.customElementRegistry??customElements;function De(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Re(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>De(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(Ie.has(e))return Ie.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,bo:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Ie.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.w||function(e,t,n){let l=n;null!==t&&(t.Pt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Ve(e,l,t,n)}e.ve()})}function qe(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Ht;f&&null===a&&!u&&k(38,[l]);let h=t.U;(null===a?"element"===h||"auto"===h:!u&&("state"===h||"auto"===h))&&k(39,[h,l]),"connect"===t.X&&null===a&&k(40,[l]);let d=f&&null!==a&&!u,p=new He(e,Ue,n,l,i,r,o,t.x,void 0);p.D=t.D,et(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.bo||c.detail?.(n,l,i)),(!p.On||!Object.is(i,p.value))&&(i=Ne(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.bo,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.ze(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.ze(p));let t=n[l];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.X||n.isConnected?i():Promise.resolve().then(i)}return p}function Le(e,t,n){k(e,[t.localName,n])}var ze=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Ue=11,Fe=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Ve=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Tt,l,Fe[n.i]),_e=Symbol();function Be(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:_e}var He=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.D=null,this.On=!1,this.engine=e,this.i=t,this.c=n,this.name=l,this.o=i,this.r=r,this.Fn=o,this.x=s,this.value=a,this.j=u}on(){return Fe[this.i]}apply(){if(null!==this.j)return void this.j.xt();let e=Ne(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Ue||8===this.i||Me(this.name)))return;if(this.value===_e)return void(this.value=e);let t=this.c;if(this.i!==Ue)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Je(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.On=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.On=!1}}}sn(){return Ne(this.D,this.c.value)}ar(){let e,t=this.c,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),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=Ne(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},Ke=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Je(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?Te(l):null==l?"":String(l):Me(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Te(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ge]=[n,l])));case 8:return void(t.innerHTML=Te(l));case 2:return null!=l&&"boolean"!=typeof l&&k(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Ge=Symbol();function Ye(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ge];void 0!==n&&(t[n[0]]=n[1])}var Ze=class{constructor(e,t,n,l){this.w=!0,this.we=null,this.u=null,this.Pt=null,this.In=null,this.r=e,this.ut=t,this.L=n,this.C=l}tr(e,t){let n=t.target,l=this.C,i=[],r=null;for(let t of l.Oe){if(t.name!==e)continue;let o=l.jn[t.c],s=ut(null===this.L?this.ut:this.L[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.Cn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ut:this.L[this.L.length-1]}Re(){let e=this.In;return(null===e?null:e.Dn(this.ut))??this.ut}insertBefore(e,t){let n=this.s;for(let l=this.Re();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}So(){null===this.L?this.ut.remove():ct(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Pt)for(let e of this.Pt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Tn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Xe=class extends Ze{constructor(e,t,n,l){super(e,t,n,l),this.$o=0,this.V=null,this.pe=0===l.Xe.length?null:new Array(2*l.Xe.length)}Eo(e,t){let n=this.V??=new Array(this.C.Xe.length),l=n[t];if(void 0===l){let i=this.C.Xe[t],r=this.pe;l=n[t]=new He(e,i.i,r[2*t],i.name,i.o,this.r,this,i.x,r[2*t+1])}return l}mo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.Eo(e,l))}Pe(e){let t=this.r;t.N===this&&(t.N=null),super.Pe(e)}};function Qe(e,t,n,l){let i=te(n,t.n);try{return e.qe(i,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function et(e,t,n){n&&e.sr(t);let l=t.Fn;null!==l&&(l.we??=[]).push(t)}var tt=null;function nt(){let e=tt;return tt=null,e}var lt=-1;function it(e,t,n,l,i=null){let r,o=t.jn,s=t.build,a=t.No,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.Ln,d=f?document.createDocumentFragment():(h?t.root:t.ln).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=ut(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 Xe(n,r,u,t),null===l.map?n.N=m:l.map.set(n,m)):p=new Ze(n,r,u,t),lt>=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||Ee.has(i))return;let o=globalThis[Pe]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${b(25,[l])}`)):(Ee.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",lt),t.Oe.length>0){let t=e.Kn;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.cr,y=e.Me,$=t.ur?a.slice(0,o.length):a,v=null===m?null:m.pe;if(null!==v){let e=t.Xe;for(let t=0;t<e.length;t++)v[2*t]=$[e[t].c],v[2*t+1]=e[t].q}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.c],o=l.F;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.ze(t);continue}try{let t=Ne(l.x,e.read(l.o,n));t!==l.q&&(Je(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.yo(l.o,n)}catch(t){e.Rt(t,m.Eo(e,o))}continue}switch(l.i){case 6:{let t=new at(e,l.C,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.In=t),t.xt();break}case 7:{let t=ot(e,l.K.map(e=>({C:e.C,o:e.o,x:e.x,S:$[e.c]})),n,p);(p.u??=[]).push(t),i===r&&(p.In=t);break}default:try{rt(e,l,i,n,p)}catch(t){Ve(e,t,l,i)}}}return tt=p,d}function rt(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Cn,o=e=>r(e,l);if(n.ot){let l=e.fo(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.xe&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.ko&&null!==i&&(i.Pt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void De(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.Tt.slice(9)),s=null===i?c.lr?.(n,r):null;s||(null===i&&Le(1202,n,`command.${r}`),i.commands.has(r)||k(1203,[n.localName,r]));let a=new WeakRef(n),u=o.subscribe((...e)=>{let t=a.deref();if(void 0!==t)return t.isConnected?s?s(t,e):t[r](...e):void 0;u()});null!==l&&(l.Pt??=[]).push(u)}(e,t,r,i,n));case 13:return void De(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&Le(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&k(1204,[n.localName,r]);let s=t.Tt;n.addEventListener(o.event,n=>{t.At&&n.preventDefault(),t.Ft&&n.stopPropagation();try{e.nr(s,n,l)}catch(e){w(e)}})}(e,t,r,l,n))}let o=t.o,s=te(l,o.n);if(14===t.i)return void De(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&Le(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.vo?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;qe(e,{...t,U:null,X:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.xe&&1===t.i)return void De(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void qe(e,t,n,t.name,t.o,l,i,r);let o=new He(e,1,n,t.name,t.o,l,i,t.x,Be(e,t,l));o.D=t.D,!c.dr?.(o,t.ro)&&(et(e,o,!0),e.ze(o))}(e,t,r,s,i,n));let a=new He(e,t.i,n,t.name,o,s,i,t.x,Be(e,t,s));a.D=t.D,et(e,a,!0),e.ze(a),null!==t.Ot&&n.addEventListener(t.Ot,()=>a.ar())}function ot(e,t,n,l){let i=new st(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,te(n,t.n),l,null,void 0,i);et(e,s,!0),null===l&&i.ue.push(s),r??=s}return e.ze(r),i}var st=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}Dn(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}xt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ne(l.x,e.read(l.o,te(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(lt=We(),null!==this.I&&(this.I.So(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],l=it(e,n.C,this.r,null,n.S);this.I=nt();let i=n.S.parentNode;i.insertBefore(l,n.S),Ye(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Tn(e);null!==this.I&&this.I.Pe(this.engine)}},at=class{constructor(e,t,n,l){this.w=!0,this.Ae=[],this.engine=e,this.C=t,this.l=n,this.S=l,null===n.N?(n.N=this,this.map=null):((n.M??=[]).push(this),this.map=new Map)}Dn(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ct(e){return null===this.map?e.N:this.map.get(e)??null}Lt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}xt(){let e=this.engine,t=this.l.f,n=this.Ae;lt=We();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){let e=n[0].Re(),t=n[i-1].s,l=[];for(let n=o.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==r&&3!==n.nodeType){l=null;break}l.push(n)}null!==l?o.replaceChildren(...l):ct(e,t);for(let e=0;e<i;e++)this.Lt(n[e])}return void(this.Ae=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.Ct(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.Ct(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.w&&this.Ct(l)===t?t.$o=e:(t.So(),this.Lt(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.Ct(t[a+e]);null!==n&&n.w?(u[e]=n.$o,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Re():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.Ct(n);null!==u&&u.w?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(it(e,this.C,n,this),i),u=nt()),s[a+r]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(it(e,this.C,t[l],this)),s[l]=nt();o.insertBefore(n,h)}}this.Ae=s,Ye(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function ut(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 ct(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var ft=()=>ie.bindAttributeName;function ht(){return{c:0,i:1,name:"",o:null,x:null,q:t,Cn:null,C:null,K:null,D:null,Ot:null,xe:!1,U:null,X:null,ro:!1,At:!1,Ft:!1,Tt:null,vo:null,F:-1,ot:!1,ko:!1}}var dt=["state","element","auto","none"],pt=["call","connect"],mt="$command.";function gt(e,t,n){P.test(t)&&(null===n&&k(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&&k(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&k(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?n:n.h[e];l.h[e]!==t&&k(1403,[l.t,l.h[e].t,t.t])}return c.xo?.(e,l),l}var yt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),$t=e=>8===e.i||yt(e)||1===e.i&&Ke(e.name);function vt(e){k(202,[e])}function wt(e,t,n,l,i){let r=ue(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.Ht||k(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&k(33,[r,n]),null!==(s?l:i)&&k(34,[r]),(s?dt:pt).includes(o)||k(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),At:t.includes("prevent"),Ft:t.includes("stop"),event:n?n.slice(2):null,U:l,X:i}}(e,t.rn),o=l.localName.includes("-"),s=t.Ne,a=t.et;if("event"===t.b){if(null!==r.U&&"none"!==r.U&&k(36),"eventToken"===s[0])return{...ht(),c:i,i:13,name:s.slice(1).join("."),Tt:a,xe:o,At:r.At,Ft:r.Ft};let n=a.startsWith(mt)?a.slice(9):null,{At:l,Ft:u}=r,f=t.Ee.slice(2),h=t.rn.includes("direct"),d=!h&&ze.has(f);d&&e.fo(f);let p=t=>{w(t),d&&c.handlerThrew?.(e,a,f)};return{...ht(),c:i,i:5,name:f,ot:d,xe:o,ko:h,Cn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.or(n,t,i);else{let n=e.ir(a,t,i);Z(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ht(),c:i,i:14,o:gt(e,a,n),xe:o};if("command"===s[0]&&s.length>1)return a.startsWith(mt)||k(1201,[t.Ee,a]),{...ht(),c:i,i:12,name:s.slice(1).join("."),Tt:a,xe:o};let u=gt(e,a,n),f={...ht(),c:i,i:1,name:t.Ee,o:u,x:je(t.tt),D:je(t.D),ro:r.ro,U:r.U,X:r.X};if("radio"===t.b||"checkbox"===t.b)return("element"===r.U||"auto"===r.U)&&k(37,[t.b,r.U]),f.i="radio"===t.b?9:10,r.ro||(f.Ot=r.event??"input"),f;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return f.U=null,f.name=e,"class"===t?(f.i=2,f.q=l.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,f}return"html"===t.Ee?(f.i=8,f):(f.name="text"===t.Ee?"textContent":t.Ee,f.xe=o&&!Me(f.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,f.name)&&(f.Ot=r.event??("select"===l.localName?"change":"input")),f)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].vo=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var bt=/\{\{([\s\S]+?)\}\}/g;function kt(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({c:o,fr:i[1].trim()}),l=bt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function St(e,t,n,l){let i=function(e){return{Ee:"textContent",Ne:["textContent"],rn:[],D:[],...F(e),b:"text"}}(t);return{...ht(),c:l,i:0,o:gt(e,i.et,n),x:je(i.tt),q:""}}function xt(e){let t=e.getAttribute(ft());if(null===t)return null;let n=ue(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var At=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function Nt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:gt(e,l.et,n),x:"else"===l.b?null:je(l.tt)}),i=[l(t,xt(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=xt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(l(e,t)),"else"===t.b))break}return i}var jt=new WeakSet;function Ot(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.Bn?.(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(t.hasAttribute(ft()+"-ignore"))continue;if(l){if("script"===s||"style"===s||jt.has(t))continue;if(jt.add(t),s===ie.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?xt(t):null;if(null!==f){if("for"===f.b){let l=gt(e,f.et,n),r=Tt(e,t,l,!0);i(a(t,ie.commentForPrefix),l,r)}else"if"===f.b?r(Nt(e,t,n).map((t,l)=>({C:Tt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,At(l,t))}))):vt(f.b);continue}let d=t.getAttribute(ft()),p=null===d?null:wt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some($t)&&!c.Ro?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e._t&&h.data.includes("{{")&&!jt.has(h))for(let{c:e,fr:t}of kt(h))s(e,t);else if(8===h.nodeType){let e=Ct.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 Ct=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Mt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Tt(e,t,n,l){let i=document.importNode(Mt(t),!0),r=[],o=[],s=e=>r.push(e)-1;Ot(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ht(),c:s(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({c:s(e.S),C:e.C,o:e.o,x:e.x}));o.push({...ht(),c:t[0].c,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)yt(e)&&k(203,[e.name]),e.c=n;o.push(...t),e.removeAttribute(ft())},(t,l)=>{o.push(St(e,l,n,s(t)))}),It(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.ot&&!e.xe&&!Pt(r[e.c],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Et(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.c);else h.add(e.c)}let g=[...h].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,jn:a,build:g,Oe:d,cr:p,Ln:u,ur:c,No:[],Xe:f}}function Pt(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 Et(e){if(null!==e.U)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.xe&&null===e.Ot;default:return!1}}var Wt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function It(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&&It(l,t,Wt.has(l.localName)),l=e}}var Rt=new WeakMap;function Dt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Rt.set(t,e),Lt(e,[...n.childNodes]),e.Ye()}function qt(e,t,n){try{let l="template"===t.localName?xt(t):null;null!==l&&!n&&k(204,[l.b]),Lt(e,[t])}catch(e){w(e)}e.Ye()}function Lt(e,t){Ot(e,t,null,!0,(t,n,l)=>{new at(e,l,Qe(e,n,null,t),t).xt()},t=>{ot(e,t,null,null)},(t,n)=>{c.Bn?.(e,t,n);for(let l of n)rt(e,l,t,null,null)},(t,n)=>{c.Bn?.(e,t,n),rt(e,St(e,n,null,0),t,null,null)})}var zt=Symbol.for("wcstack.binder"),Ut=Symbol.for("wcstack.binder.pending"),Ft=Symbol.for("wcstack.binder.taken");var Vt=new Map;function _t(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Rt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Vt.set(e,t):qt(n,e,t?.range)}function Bt(){let e=[...Vt];Vt.clear();for(let[t,n]of e)_t(t,n);!function(){let e=function(){let e=globalThis[zt];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[Ut];return void 0===t&&(t=[],e[Ut]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Ft];return void 0===t&&(t=new WeakSet,e[Ft]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Ht=class{constructor(){this.name="dirty",this.Z=(e,l)=>{if(0===e.n){let l=e.Y;return l!==t&&l!==n&&(e.Y=n,!0)}let i=null===l?null:l.vt;if(null===i)return!1;let r=i[e.F];return r!==t&&r!==n&&(i[e.F]=n,!0)}}er(e,t,n){null!==t.getter&&this.Z(t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}Ko(e,t){let n=t.l.o.Dt;if(null!==n)for(let l of n)l.n===t.l.n?e.at(l,t,this.Z):e.en(t,l,t=>e.at(l,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}zo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.vt??=new Array(e.Le).fill(t),a=null===s?i.Y:s[i.F];if(a!==t&&a!==n&&a!==l&&(null===s||i.F in s))return a;a=l;try{return a=e.Yo(i,null===s?null:r)}finally{null===s?i.Y=a:s[i.F]=a}}Gt(e){e.vt=null}nt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===n&&(t.Y=l):e.nn(t.h[t.n],e=>{let i=e.vt;null!==i&&i[t.F]===n&&(i[t.F]=l)}))}},Kt=0,Jt=new WeakMap;function Gt(e,t=e.getRootNode()){Jt.set(t,[...Jt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Yt(e){let t=Jt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Jt.get(e)!==t?Yt(e):Promise.reject(l.errors[0]):void 0)}var Zt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Zt{constructor(){super(),this.engine=null,this.Mn=!1,this.Ge=!1,this.q=null,this.Je=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.Po=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Yt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Mn){if(null!==this.Je)return void this.Je.Qe();Gt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!Rt.has(t)&&Rt.set(t,e),Bt(),c.element?.(e,"back"),this.To("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Mn=!0;let e=this.getRootNode(),t=c.dt?.(this,e);if(t)return this.Je=t,!t.Ao&&this.parentNode instanceof ShadowRoot&&Gt(this),void(void 0===t.Wt?this.Fo():t.Wt()).then(e=>(this.loaded=!0,t.start(e,()=>this.Oo()))).then(()=>{this.an(),this.cn()},e=>this.Rt(e,t.Ao));this.start(e),Gt(this)}disconnectedCallback(){if(null!==this.Je)return void this.Je.Wn();let e=this.engine;if(null===e)return;let t=e.root;Rt.get(t)===e&&Rt.delete(t),Gt(this,t),this.To("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ge&&k(14),this.loaded)this.Je.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&k(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&k(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&&k(8),l(...e)):l},set(){k(8)}}))}async Fo(){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] ${b(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||k(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let l=this.querySelector('script[type="module"]');return null!==l?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let l="function"==typeof URL.createObjectURL,i=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Kt}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?b(42):b(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(i)}}(l):null!==this.q?Promise.resolve(this.q):new Promise(e=>{this.un=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.Fo(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.q=n,this.Mn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=Rt.get(e)?.element;i?.isConnected&&(i.V||i.Je)&&k(47);let r=new le(n,new Ht);r.element=this,this.engine=r,c.element?.(r,"mounting"),Dt(r,e),Bt(),r.Rn(),this.Oo(),await r.$e("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.cn()}catch(e){this.Ge=!this.V,this.Rt(e)}}Oo(){this.V=!0,this.an()}Rt(e,t){this.Ye(this.V?50:49,e),this.an(),t?this.cn():this.Po(e)}Ye(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);w(t,`[@wcstack/state] ${b(e,[this.localName,...n])}`)}To(e,t,n){(async()=>this.engine.$e(e))().then(n,e=>this.Ye(t,e))}},Qt=[];function en(){return(Qt=Qt.filter(e=>e.deref())).map(e=>e.deref())}var tn,nn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},ln="en";function rn(){if(ie.locale!==tn){tn=ie.locale;try{ln=Intl.getCanonicalLocales(tn)[0]}catch{console.warn(`[@wcstack/state] ${b(48,[tn])}`),ln="en"}}return ln}var on=["full","long","medium","short"];function sn(e,t){let[n,l,i]=(e??[]).map(e=>e||void 0);!l&&on.includes(n)?[n,l]=[void 0,n]:!l&&!i&&/\/|^UTC$/.test(n)&&([n,i]=[void 0,n]),l&&!on.includes(l)&&function(e,t){k(52,[e,t])}(t,l);try{i&&new Intl.DateTimeFormat(void 0,{timeZone:i})}catch{k(54,[t,i])}return[n,l,i]}var an=e=>String(e).padStart(2,"0"),{eq:un,ne:cn,not:fn,lt:hn,le:dn,gt:pn,ge:mn,falsy:gn,truthy:yn,boolean:$n}=xe,vn={toFixed:{factory:e=>{let t=we(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ye("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ye("locale",e),e.toLocaleString(t??rn()))},arity:[0,1]},upper:{factory:nn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:nn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:nn(()=>e=>{let t=String(e);return t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:nn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:nn(e=>{let t=[be(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(we(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:nn(e=>{let t=be(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:nn(e=>{let t=be(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:nn(e=>{let t=be(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:nn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:nn(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)||k(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ye("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ye("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ye("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=we(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ye("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:nn(e=>{let t=e?.[0]??me("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:nn(e=>{let[t,n,l]=sn(e,"date"),i=(n||l)&&{dateStyle:n,timeZone:l};return e=>(e instanceof Date||$e("date",e),e.toLocaleDateString(t??rn(),i))}),arity:[0,3]},time:{factory:nn(e=>{let[t,n,l]=sn(e,"time"),i=(n||l)&&{timeStyle:n,timeZone:l};return e=>(e instanceof Date||$e("time",e),e.toLocaleTimeString(t??rn(),i))}),arity:[0,3]},datetime:{factory:nn(e=>{let[t,n,l]=sn(e,"datetime"),i=(n||l)&&{dateStyle:n,timeStyle:n,timeZone:l};return e=>(e instanceof Date||$e("datetime",e),e.toLocaleString(t??rn(),i))}),arity:[0,3]},ymd:{factory:nn(e=>{let t=e?.[0]??"-";return e=>(e instanceof Date||$e("ymd",e),`${e.getFullYear()}${t}${an(e.getMonth()+1)}${t}${an(e.getDate())}`)}),arity:[0,1]},hms:{factory:nn(e=>{let t=e?.[0]??":";return e=>(e instanceof Date||$e("hms",e),`${an(e.getHours())}${t}${an(e.getMinutes())}${t}${an(e.getSeconds())}`)}),arity:[0,1]},eq:un,ne:cn,not:fn,lt:hn,le:dn,gt:pn,ge:mn,add:Se("add",(e,t)=>e+t),sub:Se("sub",(e,t)=>e-t),mul:Se("mul",(e,t)=>e*t),div:Se("div",(e,t)=>e/t),mod:Se("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ye("abs",e),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&&ye("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:gn,truthy:yn,defaults:{factory:(e,t)=>{let n=ke(e?.[0]??me("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=ke(e?.[0]??me("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:$n,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??me("currency"),n=e?.[1],l={style:"currency",currency:t};try{new Intl.NumberFormat("en",l);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){k(53,[e])}(t)}return e=>("number"!=typeof e&&ye("currency",e),e.toLocaleString(n??rn(),l))},arity:[1,2]}},wn=!1,bn={name:"formats",hooks:c,install:function(){wn||(wn=!0,de(vn))}};function kn(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 Sn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=kn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var xn=" Validate statically: npx @wcstack/lint <file>.",An=["","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"],Nn=e=>{let t=An[e/100|0];return t?`[wcs/${t}] `:""},jn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],On=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Cn=["","","class.","attr.","style."],Mn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Tn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Pn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,l)=>`binding "${n?(Cn[l]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Tn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Tn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${On(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${On(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}${"string"==typeof t&&/^\d{4}-\d\d-\d\d$/.test(t)?`. A date-only string is a day, not a moment: new Date(${JSON.stringify(t)}) is midnight UTC, the day before west of Greenwich — new Date(y, m - 1, d) is that day where the page is`:""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"${/\/|^UTC$/.test(t)?` — a time zone is the third argument, after the locale and the style, and an empty argument keeps its default: ${e}(,,${t}), ${e}(en-US,long,${t})`:""}`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,54:(e,t)=>`filter ${e} takes an IANA time zone (Asia/Tokyo, America/New_York, UTC), not "${t}"`,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&&jn.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)=>`${Mn(e,t)} failed to initialize.`,50:(e,...t)=>`${Mn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Mn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,l)=>`${e}("${t}") takes ${n} index(es), got ${l}.`,902:(e,t,n,l)=>`${e}("${t}") takes at most ${n} index(es), got ${l}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function En(e,t){let n=Pn[e];return void 0===n?`${Nn(e)}#${e} ${t.join(" ")}`:Nn(e)+n(...t)}var Wn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),In=[[/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.']],Rn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Dn(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(Rn,e)?Rn[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?Sn(t,n):"");for(let[t,n]of In){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"].':ce.some(pe)||(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&&Wn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=xn),l}var qn=new WeakMap,Ln=new WeakMap,zn=new WeakSet,Un=new WeakSet;function Fn(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 Vn(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 _n(e,t){let n=[];for(let e=t;null!==e;e=e.a)n.unshift(e);let l=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==Fn(e.target,t.t)?.get?t:e.O.bt(o(t.t).o)}(e,t);return n.some(e=>null!=l(e)?.getter)?null:Bn(e,n,0,e.target,l)}function Bn(e,t,n,l,i){for(;n<t.length;n++){let r=t[n];if(null===l||"object"!=typeof l)return null;if("*"===r.s){if(!Array.isArray(l)||0===l.length)return null;let r=null;for(let o of l){let l=Bn(e,t,n+1,o,i);if(null===l)return null;if(null===r)r=l;else if(l.seg===r.seg)for(let e of l.names)r.names.includes(e)||r.names.push(e)}return r}if(Array.isArray(l)&&/^\d+$/.test(r.s)){if(Number(r.s)>=l.length)return null;l=l[Number(r.s)];continue}let o=Fn(l,r.s);if(void 0===o&&null===r.a&&e.nt.has(r.s))return null;if(void 0===o){let o=Vn(l),s=i(r.a);for(let t of e.O.all())t.a===s&&null!==t.getter&&o.push(t.s);return n>0&&0===o.length?null:{seg:r.s,names:o,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==o.get||void 0!==o.set)return null;l=o.value}return null}function Hn(e){zn.has(e)||(zn.add(e),setTimeout(()=>function(e){zn.delete(e);let t=qn.get(e);if(void 0===t)return;let n=Ln.get(e);void 0===n&&Ln.set(e,n=new Set);let l=new Map(t),i=new Map;for(let r of e.O.all()){let e=null===r.a||n.has(r)||t.has(r)?void 0:r.B.find(e=>!e.hn);void 0!==e&&(i.set(r,e),l.set(r,3))}for(let[t,r]of l){if(n.has(t))continue;n.add(t);let l=_n(e,t);if(null===l)continue;let s=Xn.get(e),a=t.a;for(;null!==a&&!s?.has(a);)a=a.a;if(null!==a)continue;let u=[...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Un.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==u){n.delete(t),u.initializePromise.then(()=>{Un.add(u),Hn(e)});continue}let f=e.O.bt(o(t.t).o),h="";if(void 0!==f&&f!==t&&null!==f.getter){let e=f.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(f.h[t].t.length+2)}`);h=` The getter "${f.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let d=Sn(l.seg,l.names);if((l.r||3===r)&&""===d&&""===h)continue;let[p,m,g]=1===r?["watch-path-missing","$watch path","watch"]:2===r?["post-update-path-missing","$postUpdate path","postUpdate"]:3===r?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];c.ct?.(e,{type:"state:path-unresolved",source:g,path:t.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${p}] ${m} "${t.t}"${3===r?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${d}${h} ${2===r?"The call updates nothing.":3===r?"The getter reads undefined.":"Updates to this path will be silently dropped."}${xn}`)}}(e),0))}function Kn(e,t,n=!1){Jn(e,t,n?1:0)}function Jn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.a)return;let l=qn.get(e);void 0===l&&qn.set(e,l=new Map),l.has(t)||l.set(t,n),Hn(e)}var Gn=new WeakSet,Yn=!1,Zn=new WeakMap,Xn=new WeakMap;function Qn(e,t,n,l,i,r,o){if(!o)return;let s=Xn.get(e);void 0===s&&Xn.set(e,s=new Set),s.add(t)}function el(e,t){let n=Zn.get(e),l=t.s;if(null!==t.a||Yn||void 0===n||n.has(l)||"$"===l[0]||e.nt.has(l))return;let i=Sn(l,[...n]);n.add(l),""!==i&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${l}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${l}" is not declared: writing it creates a new key.${i}${xn}`)}var tl=new WeakSet;function nl(e){if(tl.has(e))return;tl.add(e);let t=e.emit,n=!1;e.emit=(...l)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${xn}`)),t.apply(e,l))}var ll=new WeakMap;function il(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:Fn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let i=ll.get(e);void 0===i&&ll.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${xn}`))}var rl=new WeakSet,ol=/\bthis\s*[.[]|=\s*this\b/,sl=new WeakSet,al=e=>{for(let t of["src","state","json"])if(e.hasAttribute(t))return`<${e.localName} ${t}${"json"===t?"":`="${e.getAttribute(t)}"`}>`;return`<${e.localName}>`};function ul(e,t){let n=e.element;if("mounting"!==t||!n)return;let l=n.getRootNode();if(sl.has(l))return;let i=[...l.querySelectorAll(ie.tagNames.state)].filter(e=>e!==n&&!e.hasAttribute("mount")&&!e.hasAttribute("bind-component"));0!==i.length&&(sl.add(l),console.warn(`[@wcstack/state] [wcs/second-root] ${i.length+1} root <wcs-state> elements share one root, and there is one state tree per root: ${al(n)} takes it — its state was ready first, whatever the order in the document — and ${i.map(al).join(", ")} is refused (#47). Keep one, and graft the others with <wcs-state mount="path">.${xn}`))}function cl(e){qn.has(e)&&e.Ue.length>0&&Hn(e)}var fl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),hl=!1;function dl(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(hl||!(t instanceof TypeError)||!Me(l)||!("trustedTypes"in globalThis))return;hl=!0;let i="function"==typeof Ce()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${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.c,property:l})}var pl=new WeakMap;function ml(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=pl.get(e);void 0===r&&pl.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 gl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],yl={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},$l={name:"diagnostics",hooks:c,install(){c._o=Dn,c.Vo=En,c.xo=Kn,c.detail=ml,c.Ge=f(c.Ge,dl);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&k(1);for(let[t,n]of gl)void 0!==e[t]&&k(1601,[t,n])})(n),e?.(t,n),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=Vn(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(`^(?:${fl(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(`^${fl(l)}(?:${fl(s)})*${fl(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.`)}}(n),function(e){let t=Fn(e,"$on")?.value;if(null!==t&&"object"==typeof t)for(let e of Object.keys(t)){let n=t[e];"function"!=typeof n||rl.has(n)||!ol.test(String(n))||(rl.add(n),console.warn(`[@wcstack/state] [wcs/on-handler-this] The $on handler "${e}" uses this. A $on handler is called as ${e}(state, event): this is undefined there, so it throws when the event arrives — write ${e}(state, event) { state.x = … }.${xn}`))}}(n),function(e){Ln.delete(e),qn.has(e)&&Hn(e)}(t),function(e){if(Gn.has(e))return;Gn.add(e);let t=e.Jn,n=t.$postUpdate;t.$postUpdate=t=>{Yn=!0;try{n(t)}finally{Yn=!1}let l=e.O.bt(o(t).o);void 0!==l&&Jn(e,l,2)}}(t),function(e){if(void 0!==Object.getOwnPropertyDescriptor(e,"commands")?.set)return;let t=e.commands;Object.defineProperty(e,"commands",{configurable:!0,get:()=>t,set:e=>{t=e;for(let t of Object.values(e))nl(t)}})}(t),Zn.set(t,new Set(Vn(n)))},c.handlerThrew=il,c.element=f(c.element,ul),c.re=f(f(c.re,el),Qn),c.me=f(c.me,cl),c.it=h(p,c.it,(e,t)=>Object.hasOwn(yl,t)?k(1701,[t,yl[t]]):void 0)}},vl={},wl=/\.\d/,bl=new Set(Object.getOwnPropertyNames(Object.prototype)),kl=0,Sl=!1,xl=null,Al=()=>{Sl=!1,kl++};function Nl(){if(null===xl)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=Al,e.port1.unref?.(),xl=()=>e.port2.postMessage(0)}else xl=()=>setTimeout(Al,0);return Sl||(Sl=!0,xl()),kl}function jl(e,t){let n=new Set,l=[e];for(;l.length>0;){let e=l.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let l of t)if(n.ee(l)&&(n.n===l.n||!(l.n<e.n&&e.h[l.n+1].ee(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Ol=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Io=-1,this._n=new Set,this.Ke=null,this.engine=e,this.je=t}pr(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.je)t.getter=null!==t.p.getter||t.p.ae,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(vl,e.v(t.p,null)):this.Vn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[l,i,r,o]of t)if((null===i||i.w)&&Object.is(e.v(l,i),o)){n.add(l);for(let e of this.je)e.p===l&&this.ft(e,i,r,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&jl(Cl(e.p),n)&&this.ft(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){w(t,`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`),c.ct?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}jo(){this.active=!1,this.Fe.clear(),this.early=[]}Vn(e,t,n,l){let i=this.engine.qe(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Vn(e,t+1,n,l)}ft(e,t,n,l){let i=this.Fe.get(e);void 0===i&&this.Fe.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)}re(e,t,n,l,i,r){if(this.active){(this.Ke??=new Set).add(e);for(let r of this.je){let o=r.p;o.n!==e.n||!o.ee(e)||this.ft(r,t,r.getter?r.s.get(t??vl):o===e&&i&&this.engine.Vt&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}else r&&this.early.push([e,t,n,l])}Se(e,t){if(this.active)for(let n of this.je)(n.getter||=null!==n.p.getter||n.p.ae)&&n.p.n===e.n&&n.p.ee(e)&&this.ft(n,t,n.s.get(t??vl),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.je){let i=l.p;if(!(i.n<e.n||i.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.ft(l,t,void 0,!0):this.Vn(i,e.n+1,t,e=>this.ft(l,e,void 0,!0)))}}}me(){let e=this.Ke;if(this.Ke=null,!this.active||0===this.Fe.size)return;let t=this.Fe;this.Fe=new Map;let n=this.engine,l=[];for(let i of this.je){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.w);s.length>1&&s.sort((e,t)=>Ml(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.d;this.n=a+1,n.Ce++;try{if(s=n.v(i.p,t),i.getter&&(i.s.set(t??vl,s),Object.is(s,r)&&(wl.test(i.t)||null!==t&&!u&&!(o??=null!==e&&jl(Cl(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.d=t,c.ct?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.H(t))}catch(e){w(e,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),c.ct?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.d=h,this.n=0,n.Ce--}}}l.length>0&&this.Do(l)}Do(e){let t=Nl();t!==this.Io&&(this.Io=t,this._n.clear());let n=e.filter(e=>!this._n.has(e));if(0!==n.length){for(let e of n)this._n.add(e);w("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.ct?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function Cl(e){for(;null===e.getter&&null!==e.a;)e=e.a;return e}function Ml(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)l.unshift(e.y);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var Tl="$streamStatus",Pl="$streamError",El=new Set(Object.getOwnPropertyNames(Object.prototype)),Wl=!1;function Il(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 Rl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Wl=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Wl=!1}}mr(){for(let e of this.entries)this.start(e,!0)}hr(){for(let e of this.entries)e.pt=!1,e.J?.abort(),e.J=null}gr(){for(let e of this.entries)e.pt=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(Tl,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.pt?Math.max(n.n,t):t,n.pt=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.pt)continue;let r=i.n;if(i.pt=!1,r>32)n.push(i.name),i.g.Y=l;else{t.n=r+1,e.Ce++;try{this.start(i,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Do(n)}start(e,t){let n,i=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.Q.slice();Dl(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.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Tl}.${e}`||n.t===`${Pl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Dl(r);for(let e of o)e.Hn(r);if(r.Y=l,t)throw n;return this.set(Pl,e.name,n),void this.set(Tl,e.name,"error")}}let r=new AbortController;e.J=r,i.A(i.o(e.name),null,e.q),this.set(Pl,e.name,null),this.set(Tl,e.name,"active"),this.yr(e,r,n)}async yr(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.J===t,o=l.o(e.name),s=this.W.n,a=Nl(),u=e=>{Nl()===a&&(this.W.n=s);try{e()}finally{this.W.n=0}},c=e.q;try{let t=await e.source(n,i);if(!r())return;let s=t=>{c=void 0!==e.Lo?e.Lo(c,t):t,u(()=>l.A(o,null,c))};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;s(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;s(t.value)}}}if(!r())return;e.J=null,u(()=>this.set(Tl,e.name,"done"))}catch(n){if(!r())return;e.J=null,t.abort(),u(()=>{this.set(Pl,e.name,n),this.set(Tl,e.name,"error")})}}};function Dl(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.yt.delete(e)}e.Q.length=0,e.Y=t}var ql=new WeakMap;function Ll(e){let t=ql.get(e);return t?.target===e.target?t:void 0}function zl(e,t){let n=new Ol(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("@")||bl.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.xo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new Rl(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)||El.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.`),Il(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,Lo:u,q:f,J:null,pt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[Tl]=i,t[Pl]=r,l}(e,t),n),i=ql.get(e);void 0!==i&&(i.W.jo(),i.It.hr()),ql.set(e,{W:n,It:l,Qe:i?.Qe??!1,target:t})}function Ul(e,t){let n=ql.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Qe="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.jo(),void n.It.gr();n.Qe&&(n.W.pr(),n.It.mr())}}var Fl=["$streamStatus","$streamError"],Vl={name:"temporal",hooks:c,install(){c.fe=f(c.fe,zl),c.element=f(c.element,Ul),c.re=f(c.re,(e,t,n,l,i,r,o)=>Ll(e)?.W.re(t,n,l,i,r,o)),c.Se=f(c.Se,(e,t,n)=>{let l=Ll(e);void 0!==l&&(l.W.Se(t,n),l.It.Se(t))}),c.Qt=f(c.Qt,(e,t,n)=>Ll(e)?.W.Qt(t,n)),c.me=f(c.me,e=>{let t=Ll(e);void 0!==t&&(t.W.me(),t.It.me())}),c.it=h(p,c.it,(e,t)=>{let n=t.split(".",1)[0];if(Fl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=h(d,c.Ie,(e,t)=>(!Wl&&36===t.t.charCodeAt(0)&&Fl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},_l=new WeakMap,Bl=!1,Hl=/^(?!prototype$)[^\d.*$][^.*]*$/;function Kl(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.`)}}_l.set(t,l)}function Jl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Gl(e,t,n){let l=new Map;for(let i of t){Jl(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 Yl(e,t,n,l){if(Bl||!Array.isArray(l))return!1;let i=_l.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.st(t,n);if(!Array.isArray(r)||r===l)return!1;let o=Gl(t.t,r,i);Gl(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){Bl=!0;try{e.A(t,n,s)}finally{Bl=!1}}if(c.length>0){let l=e.qe(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=Hl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.A(s,o,r):(o.E[i]=r,e.A(e.o(`${t.t}.*`),o,o.E,!0))}}return!0}var Zl={name:"list-keys",hooks:c,install(){c.fe=f(c.fe,Kl),c.Ie=h(d,c.Ie,Yl)}},Xl=new WeakMap,Ql=new WeakMap,ei="will not graft: the root state failed to initialize.",ti=new WeakSet,ni=new WeakMap,li=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],ii=["$commandTokens","$eventTokens","$on","$errorCallback"],ri=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,oi=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),si=e=>e?.element?.isConnected?e:void 0;function ai(e){let t=Ql.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ui(e,t){let n=Ql.get(t);if(Ql.delete(t),Array.isArray(n))for(let t of n)di(t,e)}function ci(e){let t=Xl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function fi(e,t){w(`${ri(e.t)} ${t}`),ci(e),e.Ze?.(),e.Ze=null}function hi(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,w)}catch(e){w(e)}}function di(e,t){if(ti.has(t))return fi(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 fi(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)):oi.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.st(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,s)}t.io(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=ni.get(t);void 0===c&&ni.set(t,c=[]),c.push(e),e.el.isConnected&&hi(e,"$connectedCallback"),e.Ze?.(),e.Ze=null}function pi(e,t){let n=Ql.get(e);if(Array.isArray(n))for(let e of n)fi(e,ei);Ql.set(e,t)}var mi=new WeakMap;function gi(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,Ze:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Xl.get(t);void 0===e&&Xl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:si(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Ql.get(t);Array.isArray(e)&&Ql.set(t,e.filter(e=>e!==r)),r.Ze?.(),r.Ze=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ao:!0,start(e){if(null!==i)return fi(l,i);if(Xl.get(t).get(n)===l){for(let t of li)if(void 0!==e[t])return fi(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of ii)void 0!==e[t]&&console.warn(`${ri(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Ze=e;let n=si(Rt.get(t)),i=Ql.get(t);void 0!==n?di(l,n):ai(t)?fi(l,ei):Ql.set(t,[...Array.isArray(i)?i:[],l])})}},Qe(){null!==l.engine&&hi(l,"$connectedCallback")},Wn(){null!==l.engine&&hi(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 yi=new WeakMap,$i=new WeakMap;function vi(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 wi(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=vi(l,"$bindables"),o=vi(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(ie.tagNames.state);return a.set(l,o),yi.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.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)},Qe(){},Wn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var bi=new WeakMap,ki=new WeakSet,Si=new WeakMap,xi=new WeakMap,Ai="data-wcs-wired",Ni=new WeakMap,ji=new WeakMap,Oi=new WeakMap,Ci=0,Mi=new Set,Ti={},Pi=["$watch","$stream","$renderedCallback"],Ei=e=>e.split(".",1)[0];function Wi(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ii(e,t){let n=e.c,l=Ei(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(Ai);else if(!Di(n,l)){let e=n.getAttribute(Ai)?.split(" ")??[];e.includes(l)||n.setAttribute(Ai,[...e,l].join(" "))}Ni.get(n)?.he===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=bi.get(n);void 0===i&&bi.set(n,i=[]),i.push(e),t&&ki.add(e);let r=Si.get(n);return void 0===r&&Si.set(n,r=new Map),r.has(l)||r.set(l,n[l]),xi.get(n)?.(),!1}function Ri(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Di(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function qi(e){let t=e.parentElement;for(;null!==t&&!Ri(t);)t=t.parentElement;let n=Rt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?_t(e):qt(n,e))}var Li=new Set;function zi(e,t){Li.has(e)||(Li.add(e),console.warn(`[@wcstack/state] ${t}`))}var Ui=(e,t)=>t in e.state;function Fi(e,t){let n=Vi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Vi(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 _i(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=Ei(n.t),s=i.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.a)return function(e,t){let n,l=t.a;for(;null!==l&&void 0===(n=e.mt.get(l));)l=l.a;if(null===l||void 0===n)return;let i=e.R,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=Bi(e,s.r);return 0===t.n?n:(r.resolve(Wi(o.t,[...r.H(n),...i.H(te(i.d,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.se&&(t.se=n=>{let l=a();Hi(e,s.e,()=>r.A(o,l,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.mt.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==o?Ui(i,o):Fi(i,o))return;l=s.ye}else{if(null===t||null!==n.a||"$"===o[0]||Ui(i,o))return;s=t,l=r.o(`${t.ye.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,Bi(e,a)),n.se=t=>{Hi(e,u,()=>r.A(l,a,t)),e.dn=n},e.mt.set(n,{e:s,p:l,r:a})}function Bi(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Hi(e,t,n){let l=Mi.has(e.R);Mi.add(e.R),e.from=t;try{n()}finally{l||Mi.delete(e.R),e.from=null}}var Ki=(e,t)=>t||!Mi.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Ji(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,Ci+=t?1:-1;let n=e.host.engine,l=Oi.get(n);void 0===l&&Oi.set(n,l=new Map);for(let n of e.pe){let e=l.get(n.e.ye);void 0===e&&l.set(n.e.ye,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.$);if(void 0!==i){null===e.ie&&function(e,t){let n=e.host,l=n.engine;e.ie=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=Ei(o);if(o!==a&&!Ui(n,a))continue;let u=l.o(`${t.ye.t}.${o}`);if(null===u.getter)Zi(l,u,t.ye);else if(!Gi.has(u.getter))continue;e.ie.set(u,e.R.o(o))}}(e,i);for(let l of e.ie.keys())t&&null===l.getter&&Zi(n,l,i.ye),n.T.ke(n,l,i.r);e.ie.size>0&&n.ve(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.ie){let r=n.v(l.a,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;zi(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.he}.${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 Gi=new WeakSet;function Yi(e,t,n,l){let i=Oi.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.$||!0!==e.m.ie?.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 Zi(e,t,n){let l=t.a,i=t.s,r=()=>{let t=e.read(l,e.d);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=Yi(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Gi.add(t.getter),t.se=o=>{let s=null===r()?Yi(e,n,e.d,t):null;if(null===s){let t=e.read(l,e.d);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.ie.get(t);void 0===Vi(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.R.A(a,null,o)},t.n>0&&(t.F=e.Le++)}function Xi(e,t,n,l,i,r){if(null!==t.getter)return e.T.ke(e,t,n),void e.ve();if("*"===t.s){if(null===n)return;if(n.E=n.l.P[n.y],e.T.Gt(n),null!==n.u)for(let t of n.u.values())e.X(t)}else e.xn(t,n);c.re?.(e,t,n,l,i,r),e.Ke(t,n)}function Qi(e){let t=e.m.R;for(let[n,l]of e.m.mt)l.e===e.e&&(0===n.n?t.T.ke(t,n,null):t.nn(n.h[n.n],e=>t.T.ke(t,n,e)));t.ve()}function er(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Qi(e);let a,u=e.m,c=u.R;if(""===e.e.$){a=s.slice(1);let e=Ei(a);if("$"===e[0]||Ui(u.host,e)||u.host.entries.some(e=>""!==e.$&&(a===e.$||a.startsWith(`${e.$}.`))))return}else a=e.e.$+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(te(l,e).y);c.resolve(Wi(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Xi(c,h,d,i,r,o)}function tr(e,t,n,l,i,r,o){if(0===Ci)return;let s=Mi.has(e);Mi.add(e);try{let s=ji.get(e);!o&&void 0!==s&&s.fn&&!Mi.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.mt.get(s));)s=s.a;if(null===s||void 0===o)return;let a=e.host.engine;if(s===t&&e.dn===t)return void(e.dn=null);if(null!==o.r&&!o.r.w)return;let u=[...a.H(o.r),...e.R.H(n)];a.resolve(Wi(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Hi(e,o.e,()=>Xi(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.fn&&null!==s.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.$),l=e.host.engine;for(let[i,r]of e.ie)r===t&&(l.T.ke(l,i,n.r),l.ve())}(s,t);let a=Oi.get(e);if(void 0===a)return;for(let[e,s]of a)if(t.ee(e)){let a=s.get(0===e.n?null:te(n,e.n));if(void 0!==a)for(let s of[...a])Ki(s,o)&&er(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||te(e,t.n)===n)for(let e of[...l])Ki(e,o)&&Qi(e)}finally{s||Mi.delete(e)}}async function nr(e,t,n,l,i){if(l===Ti)return;let r=y(l);r&&await r;let o=Ni.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.I;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${ie.tagNames.state} bind-component="${o.he}">.`),null!==s&&Ji(s,!1),null!==s&&function(e,t,n){let l=e.R,i=`[${ie.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.Dn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.ue.values())for(let t of e)if(null===t.j)s(t.c);else for(let e of t.j.K)a(t.j,e.S);for(let e of l.oe.values())for(let t of[e.N,...e.M??[]])null!==t&&a(t,t.S);for(let t of e.L)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.L.includes(n)&&(r(n)||l._t&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.R.element=t,t.engine=e.R,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await lr(e,l):l()}(s,e,n,i);let a=new le(l,new Ht);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.V=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,L:[],R:a,host:o,pe:[],mt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of o.entries)u.pe.push({m:u,e});o.I=u,ji.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.R,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Ei(e.$);Ui(n,t)&&(e.$!==t||Fi(n,t))&&zi(`${i}.${e.$}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.ye,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&zi(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.ye.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Pi.filter(e=>void 0!==n.state[e]);o.length>0&&zi(`${i}.${n.he}$`,`[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.rt;t.rt=n=>{_i(e,r,n),s.call(t,n)};let a=[...t.O.all()];for(let t of a)_i(e,r,t);for(let e of a)s.call(t,e);let u=t.Et;t.Et=()=>{(function(e){for(;void 0!==e;e=ji.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Ji(u,!0),ti.add(a),ui(a,n));let h=c.wr?.(n,a);Dt(a,n),h?.(),u.L=[...n.childNodes],Bt(),f&&a.Rn(),Object.defineProperty(t,o.he,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.he);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,w)}catch(e){w(e)}i(),e.isConnected?(await a.$e("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):Ji(u,!1)}async function lr(e,t){Ji(e,!0);for(let t of e.pe)Qi(t);t?.(),!e.broken&&(await e.R.$e("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function ir(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Rt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){pi(t,e);for(let e of mi.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:Ni.get(r)?.I;return t?.el===e?t:null},s=t=>{throw i&&pi(l,e),t},a=!1;return{Wt:()=>(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(`<${ie.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Re(n).whenDefined(i);let r=Ni.get(n);if(void 0!==r)return r.he!==t&&v(`<${i}> already has a <${ie.tagNames.state} bind-component="${r.he}">.`),r.state;let o=()=>(bi.get(n)??[]).filter(e=>Ei(e.name)===t),s=Di(n,t);if(s&&0===o().length&&qi(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(Ai)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{xi.set(n,l),e=function(e,t){ai(e)&&t();let n=mi.get(e)??new Set;return mi.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())}xi.delete(n);let a=o(),u=Si.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Ti}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(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>")`}.`)}f.push({$:l,ye:e.o,r:e.r,ro:ki.has(e)}),e.engine.Tn(e),""!==l&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return Ni.set(n,r={el:n,he:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,I:null}),h}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await nr(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Qe(){let t=o();null!==t?lr(t).catch(w):a?Promise.resolve().then(()=>{if(e.parentNode===l)return nr(e,r,i?l:r,Ni.get(r).state,()=>{})}).catch(w):xi.has(r)&&qi(r)},Wn(){let e=o();null!==e&&(Ji(e,!1),!e.broken&&(e.R.$e("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.R,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var rr={name:"scopes",hooks:c,install(){c.dt=h(m,c.dt,gi),c.dt=h(m,c.dt,wi),c.dt=h(m,c.dt,ir),c.dr=Ii,c.Ro=Ri,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=ni.get(e)??[];if("disconnected"===t)for(let e of n)ci(e);else if("reset"!==t&&si(Rt.get(e.root))===e){ui(e,e.root);for(let e of n)Xl.get(e.root).has(e.t)||Xl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ui(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:yi.get(n);void 0!==l&&$i.set(e,{host:n,def:l})}(e,n)}),c.re=f(c.re,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=$i.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),tr(e,t,n,l,i,r,!1)}),c.Se=f(c.Se,(e,t,n)=>tr(e,t,n,void 0,void 0,!1,!0)),c.Ie=h(d,c.Ie,(e,t,n,l,i)=>(function(e,t){let n=ni.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let l,i=ji.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.a)l=i.mt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.w)&&!r.ro)&&(!!n||(Bi(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===r.$?"":`.${r.$}`}#ro: ${r.ye.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.fe;c.fe=(t,n)=>{let l=ni.get(t);void 0!==l&&l.length>0&&v(`re-setting a root state with grafted volumes (${l.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Oi.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)}}},or="$recursion",sr=new WeakMap,ar=new WeakSet,ur=new WeakSet,cr=0,fr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),hr=e=>`[wcs/recursion-${e}]`;function dr(e,t){let n=n=>v(`${hr("declaration-invalid")} ${or} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${hr("declaration-invalid")} ${or} ${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 pr=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function mr(e,t){let n=`${e.l}.**`,l=t.slice(n.length);return(!t.startsWith(n)||""!==l&&"."!==l[0]||l.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function gr(e,t,n){let l=mr(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ce){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===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.`),pr(e,i.k)+l}function yr(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${hr("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${hr("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),r+1>128&&v(`${hr("depth-exceeded")} Recursion on "${t.l}.*" 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(`${pr(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.qe(a,i).f,s+1),l.delete(u))}},s=e.o(t.l),a=e.read(s,null);r(a,t.l,0)&&(l.add(a),o(e.qe(null,s).f,0))}function $r(e,t){let n=function(e){let t=e[or],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&&U(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${hr("declaration-invalid")} ${or} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${hr("declaration-invalid")} ${or} must declare exactly one anchor (it declares ${i.length}).`);let r=dr("anchor",i[0][0]),o=dr("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(`${hr("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${fr(r)}((?:${fr(u)})*)${fr(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${fr(s)}((?:${fr(`.*.${a}`)})*)$`)}}(t),l=sr.has(e);null!==n?(l||cr++,sr.set(e,n),ur.add(e),ar.has(e)||function(e){ar.add(e);let t=e,n=t.rt;t.rt=l=>{let i=sr.get(e);if(l.t.includes("**")){let t=e.O.bt(l.t)===l;return void(ur.has(e)||void 0===i&&t?l.getter=()=>U(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.F=t.Le++),i.owners.set(l,i.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=sr.get(e);return l.call(e,void 0!==i&&t.includes("**")?gr(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=sr.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,gr(r,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${hr("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=mr(r,n),s=[];return yr(e,r,(t,n)=>{for(let l of i.call(e,pr(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.vn;t.vn=(n,l,i,o)=>{let s=sr.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||k(9,[n]),l.length>0&&v(`${hr("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${hr("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&k(8);let a=mr(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(`${hr("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(`${hr("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];yr(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,pr(s,t)+a,e.H(n),i);return h}}(e)):l&&(sr.delete(e),cr--)}function vr(e,t){if(0===cr)return!1;let n=sr.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.a){let l=n.owners.get(e);void 0!==l&&v(`${hr("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var wr={name:"recursion",hooks:c,install(){c.fe=f(c.fe,$r),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ur.delete(e)}(e)}),c.Ie=h(d,c.Ie,vr)}},br="4.10.0",kr=e=>e.split(".").slice(0,2).join("."),Sr=class extends Zt{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return kr(this.version)===kr(br)}};function xr(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Sr{})}var Ar=()=>ie.tagNames.ssr,Nr=Symbol.for("wcstack.ssr.snapshotBuilder"),jr=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Or=e=>document.createComment(e),Cr=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Mr=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),Tr=new WeakMap,Pr=new WeakMap,Er=new WeakMap,Wr=new WeakSet,Ir=new WeakMap;function Rr(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Dr(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 qr=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Lr(e,t,n,l){let i=Or(null===l?"wcs-[":`wcs-[:${l}`),r=Or("wcs-]");n.length>0&&n[0].Re().before(...Rr(e,t)),t.after(i);for(let e of n)null===l&&e.Re().before(Or("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ut:e.L[e.L.length-1])(n[n.length-1]):i;(qr(o)??o).after(r);for(let e of Rr(i,r))Wr.add(e)}function zr(e){if(e instanceof at){Lr(e.S,e.S,e.Ae,null);for(let t of e.Ae)Ur(t);return}let t=e.I;null!==t&&(Lr(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Ur(t))}function Ur(e){if(null!==e.u)for(let t of e.u)zr(t)}var Fr=new Set(["script","style","template","textarea","title"]),Vr="data-wcs-raw",_r=e=>Fr.has(e.localName)||e.localName===Ar();function Br(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Or("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Or("wcs-s")):1===t.nodeType&&!_r(t)&&Br(t)}var Hr=0;function Kr(e,t){let n=e.getRootNode(),l=[t];for(let e of Pr.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=Tr.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.N&&n.set(t.N.S,t.N),null!==t.M)for(let e of t.M)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.j)for(let t of e.j.K)n.set(t.S,e.j);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),zr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Er.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Wr.has(e)||1===e.nodeType&&t.has(e)&&Xr(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(_r(e.parentNode)?Ir.has(e):t.has(n)&&Mr(n,"wcs-t:"))&&(Ir.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);_r(e)&&n.some(e=>Ir.has(e))&&e.setAttribute(Vr,n.map(e=>Ir.has(e)?`{{ ${Ir.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Br(9===n.nodeType?n.body:n);let r=document.createElement(Ar());r.setAttribute("version",br);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"}${Hr++}`;e.replaceWith(Or(`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(Dr(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(Dr(t,s,o))}e.before(r)}function Jr(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Ir.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===Ar())continue;let e=t.engine;null!=e&&Kr(t,e)}}var Gr=Symbol.for("wcstack.state.ssr.impl"),Yr=new Map,Zr=new WeakMap,Xr=e=>!0===c.Ro?.(e),Qr=e=>1===e.nodeType&&!_r(e)&&!Xr(e),eo=e=>e.f.flat().concat(e.z??[]),to=e=>{for(let t of eo(e))t.remove()};function no(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&&!Cr(s,"wcs-]");){let e=s.nextSibling;if(Cr(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];Mr(s,"wcs-[")?e=no(s,t,n):(n.push(s),Qr(s)&&lo(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,z:s??r.appendChild(Or("wcs-]"))},u=eo(a);s=a.z.nextSibling;for(let e of u)n?.push(e),t&&jt.add(e);return t&&null!==i?Yr.set(i,a):to(a),s}function lo(e,t){for(let n=e.firstChild;null!==n;)Mr(n,"wcs-[")?n=no(n,t):(Qr(n)&&lo(n,t),n=n.nextSibling)}function io(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=Or(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!Cr(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]?Dr(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&&!_r(i)&&(Xr(i)?Zr.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||ho(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Mr(e,"wcs-[")?l++:Cr(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(Mr(l,"wcs-["))i++;else if(Cr(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),lo(e,n)}function ro(e,t){let n=Zr.get(e);if(void 0===n)return null;Zr.delete(e);let l=e=>io(e,n.ssr,n.Te);if(n.Te||uo(t,e,e,l),l(e),!n.Te)return null;let i=c.Te;return c.Te=go,()=>{c.Te=i,oo()}}function oo(){for(let e of Yr.values())to(e);Yr.clear()}function so(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function ao(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 uo(e,t,n,l){let i=document.createElement("template").content;for(let e of n.childNodes)i.appendChild(i.ownerDocument.importNode(e,!0));l(i),e.root=t;let r=()=>{};Ot(e,[...i.childNodes],null,!0,r,r,r,(t,n)=>St(e,n,null,0))}function co(e,t,n){if(jr()){if(n instanceof Array){for(let e=n.length;e-- >0;)yt(n[e])&&n.splice(e,1);let e=t;if(n.some($t))Wr.add(e);else if(e.localName.includes("-")&&!Xr(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Er.set(e,t)}return}if("string"==typeof n){if(Ir.set(t,n),_r(t.parentNode))return;let e=Or(`wcs-t:${encodeURIComponent(n)}`),l=Or("wcs-/t");return t.before(e),void t.after(l)}let l=Tr.get(e);void 0===l&&Tr.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Pr.get(i);return void 0===r&&Pr.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&Yr.size>0){let e=Yr.get(n);void 0!==e&&(Yr.delete(n),Yr.set(t,e))}}var fo=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),ho=e=>3===e.nodeType&&""===e.data.trim(),po=e=>{let t=Yr.get(e)?.z??e;return(qr(t)??t).nextSibling};function mo(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.jn;for(let l=0;l<n.length;l++){let i=n[l],r=e.ln,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=(qr(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=po(o)}e.No[l]=o}return!0}function go(e,t,n){if(0===Yr.size)return null;let l=t,i=0;if(!n){let e=ie.commentIfPrefix;if(!Cr(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(fo(n)&&i++,!Cr(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Yr.has(l)&&null!==n&&!Cr(n,e)&&1!==n.nodeType;n=n.nextSibling)fo(n)&&(l=n)}let r=Yr.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Yr.delete(l),to(r),null;let o=r.f.shift();if(0===r.f.length&&Yr.delete(l),r.z?.replaceWith(...Rr(t,l)),r.z=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Yr.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else qr(o[e])===o[e+1]&&e++}if(!mo(e,s)){let n=(e.Ln?e.root:e.ln).cloneNode(!0);s=e.Ln?[n]:[...n.childNodes],mo(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 yo={name:"ssr",hooks:c,install(){c.Bn=co,c.wr=ro;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||jr())return;let n=t.previousElementSibling,l=n?.localName===Ar(),i=l?n.getAttribute("version"):null,r=null===i||kr(i)===kr(br);if(r){let t=e,n=t.$e;t.$e=(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] <${Ar()} version="${i}"> does not match ${br}: 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(`[${Vr}]`)))e.textContent=e.getAttribute(Vr),e.removeAttribute(Vr);let h=9===f.nodeType?f.body:f;n.remove();let d=e=>o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!Xr(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 > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ue(t.getAttribute(ie.bindAttributeName)??"")){let t=l.et;l.Ne[0]===r&&n.push([e?ao(e,t,1,0):t,l.Ne.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:ao(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]:ao(l,r[2],2,1)??r[2]};for(let t of so(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Cr(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]?[Or(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of so(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=ie.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")}(e,n,a):io(e,n,r);r||uo(e,f,h,d),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),l=e.map(e=>e.selected),i=e.map(e=>e.hasAttribute("selected")),r=i.lastIndexOf(!0);r<0&&(r=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>l[t]!==i[t]):n.selectedIndex!==r)&&t.push([n,()=>e.forEach((e,t)=>e.selected=l[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),r&&(c.Te=go,queueMicrotask(()=>{oo(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Gr]={build:Jr,reset(){Hr=0}},void 0===e[Nr]&&(e[Nr]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Gr].build(t),reset:()=>e[Gr].reset()})}(),c.Co=f(c.Co,xr);for(let e of en())xr(e)}},$o="__WCSTACK_DEVTOOLS_HOOK__",vo=null,wo=new Set,bo=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),ko=new WeakMap,So=0;var xo=new WeakMap;function Ao(e){if(null===vo)return;let t=xo.get(e),n=wo.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=ko.get(e);return void 0===t&&ko.set(e,t=++So),t})(r)}|${u}|${o.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:o.t,bindingType:a,node:r,replaceNode:r},absoluteAddress:bo(e,o,c)})},r=e=>i(e.i,e.name,e.c,e.o,e.r,e.on()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.we)for(let t of e.we)r(t);if(e instanceof Xe&&null!==e.pe){let t=e.C.Xe;for(let n=0;n<t.length;n++){let l=e.V?.[n];void 0!==l?r(l):i(t[n].i,t[n].name,e.pe[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 at){i(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Ae)o(t)}else null!==e.I&&o(e.I)};for(let t of e.ue.values())for(let e of t)r(e),null!==e.j&&s(e.j);for(let t of e.oe.values())if(null!==t.N&&s(t.N),null!==t.M)for(let e of t.M)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||vo({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&vo({type:"state:binding-added",...l});xo.set(e,n)}function No(e){let t=Rt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function jo(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.O.all()){for(let e=1;e<=r.n;e++)t.add(r.h[e].t);"*"===r.s&&n.add(r.t),null!==r.getter&&l.add(r.t),null!==r.se&&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.Oe.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 Oo=new WeakSet,Co=new WeakMap;function Mo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Oo.has(t))return;Oo.add(t);let l=t.emit;t.emit=(...i)=>(null!==vo&&vo({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.Oe.values())t(n,"event")}(e),"connected"===t){if(wo.has(e))return;wo.add(e),vo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Ao(e)}else"disconnected"===t&&(wo.delete(e),Ao(e),vo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function To(e,t,n,l,i,r){if(null===vo)return;let o=bo(e,t,0===t.n?null:n),s=Co.get(e);void 0===s&&Co.set(e,s=new Set),s.add(o),r&&vo({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function Po(e){if(null===vo)return;let t=Co.get(e);Co.delete(e),void 0!==t&&vo({type:"state:update-batch",addresses:t}),Ao(e)}function Eo(e,t,n){vo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Wo={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Io(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Wo["*"],...Object.hasOwn(Wo,e)?Wo[e]:[]])(n);return l.includes(t)||k(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)if(!g.has(t.name)){if(t.hooks!==c)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${t.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);g.add(t.name),t.install()}}([bn,$l,Vl,Zl,rr,wr,yo,{name:"devtools",hooks:c,install(){c.element=f(c.element,Mo),c.re=f(c.re,To),c.me=f(c.me,Po),c.Ge=f(c.Ge,Eo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[$o]??(e[$o]=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:br,getStateElements:()=>[...wo].map(jo),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let l=n._,i=n.De?.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}(No(e)),keys(e){let t=No(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 No(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){No(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===vo&&null!==e;vo=e,null===e&&(xo=new WeakMap),c.ct=e&&((e,t)=>vo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of wo)Ao(e)})}})}()}},{name:"native-commands",hooks:c,install(){c.lr=Io}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[zt]&&(e[zt]={protocol:"wcs-binder",version:1,bind:_t})})(),en().includes(e)||Qt.push(new WeakRef(e));let t=ie.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),c.Co?.(e)}();
1
+ var e=class{constructor(e,n,l){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.B=[],this.Q=[],this.ht=null,this.F=-1,this.Y=t,this.De=null,this.jt=null,this.Dt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.yt=new Set,this.t=e,this.a=l,this.s=n;let i=null===l?[null]:l.h.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this.z=r?[]:null===l?[n]:[...l.z,n],this.h=i}Hn(e){this.yt.has(e)||(this.yt.add(e),this.B.push(e),e.Q.push(this))}Bo(e){this.yt.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Mo(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.yt.clear(),this.Q.length=0,this.ht=null,this.De=null,this.jt=null,this.Dt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.a}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.wt=new Map,this.Un=e}bt(e){return this.wt.get(e)}get(t){let n=this.wt.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.Un?.(n),this.wt.set(t,n),i&&i.u.push(n),n}all(){return this.wt.values()}Lt(e){this.wt.delete(e.t)}},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.size>4095&&r.clear(),r.set(e,o),o}var s=class{constructor(e,t,n){this.vt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.E=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Bt=!1,this.kt=!1,this.o=e,this.ce=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.Wt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Wt(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._o?.(e,t,n)??""}`)}function w(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function b(e,t=[]){return c.Vo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function k(e,t,n,l){v(b(e,t),n,l)}var S=class{constructor(e){this.St=new Set,this.name=e}get size(){return this.St.size}subscribe(e){return this.St.add(e),()=>{this.St.delete(e)}}unsubscribe(e){return this.St.delete(e)}emit(...e){let t=[];for(let n of this.St)try{t.push(n(...e))}catch(e){t.push(void 0),w(e,`[@wcstack/state] ${b(17,[this.name])}`)}return t}};function x(e,t,n){if(void 0===e)return[];Array.isArray(e)||k(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&k(19,[t]),i===n&&k(20,[t,i,n]),l.has(i)&&k(21,[t,i]),l.add(i);return e}var A=Symbol.for("wcstack.transition-runner");function N(e){let t=globalThis[A];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 j(e,t,n){let l=N(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var O="else",C="eventToken",M="class",T="attr",P=/^\$[1-9]\d{0,2}$/,E=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function W(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:E.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&&k(107,[i,e]),a(!0),{args:t,literals:n}}var I=e=>e.trim();function R(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 D=(e,t)=>R(e,t)[0]??-1;function q(e,t){let n=[],l=0;for(let i of R(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function L(e,t,n){let l=D(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=D(e,"("),i=(e=>R(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&k(108,[e]),-1!==i&&-1===n&&k(109,[e]),-1!==i&&i<n&&k(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();k(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&k(112,[l]),r.includes("#")){let[,e]=r.split("#");k("input"===t?113:114,[r,e])}return-1===n?{qn:r,args:[],literals:[]}:{qn:r,...W(e.substring(n+1,i))}})}(q(i,"|").map(I),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var z=new Map;function U(e){k(1101,[e])}function F(e){let[t,n]=L(e,"output",z);t.includes("@")&&k(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)&&k(119,[e]),function(e){e.includes("**")&&U(e);let t=e.split(".").length;t>512&&k(117,[e,t])}(l),{et:l,tt:n}}var V=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],_=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function B(e){return e.includes("**")&&U(e),e}var H=0;function K(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var J=()=>new Set,G=()=>[],Y=new WeakMap;function Z(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function ee(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function te(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function ne(e,t,n){let l=te(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var le=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.nt=new Set,this.ot=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.$t=[],this.Me=null,this.zn=[],this.Ut=0,this.G=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.He=!1,this.gn=!1,this.qt=new WeakMap,this.j=0,this.Kt=0,this.yn=0,this.wn=0,this.bn=!1,this.zt=!1,this.Yt=!1,this.Ce=0,this.Yn=()=>{this.j=0,this.bn=!1},this.Gn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Ho=()=>{this.He&&this.Et()},this.Uo=(e,t)=>e(this.proxy,...t),this.Xn=[],this.Ue=[],this.Jn={$untracked:e=>{let t=this.G;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=te(this.d,t);null===n&&k(7,[e]);let l=this.o(e);if(null!==l.getter||l.ae)return this.watchIndex(t),n.y===this.read(l,null);let i=this.G;if(null!==i){let e=i.getter,n=l.De??(l.De=[]);if(!n.some(n=>n.getter===e&&n.Qn===t)){n.push({getter:e,Qn:t});let i=e.h[t];(i.jt??(i.jt=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,te(this.d,n.n)))},$dependOn:e=>{this.resolve(B(e),this.d),null!==this.G&&0===this.G.be&&this.Zn(this.rp,this.rr,this.G)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.vn(e,t,n,l),$resolve:(...e)=>{let t=B(e[0]),n=e[1]??[],l=this.o(t,!0);this.kn("$resolve",t,l,n,!0);let i=this.eo(l,n,null);if(e.length<3)return this.read(l,i);this.A(l,i,e[2])},$postUpdate:e=>{this.resolve(B(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.E=n.l.P[n.y],Y.delete(n.l.P),this.T.Gt(n)),this.Sn(t,n),null!==n&&this.to(n,t,void 0,n.E,!1),0===t.n&&this.no(t,void 0,void 0,!0),this.Xt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.Ue.push(e),this.rt(e)}),this.oo(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.it(t);if(t.indexOf(".")<0){let e=n.O.bt(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return l===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(B(t),n.d),n.A(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}io(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.se=l.set??null,null!==i.getter&&i.n>0&&(i.F=this.Le++)}for(let e of this.O.all())this.rt(e)}rt(e){e.t.includes("**")&&U(e.t),("__proto__"===e.s||"prototype"===e.s)&&k(120,[e.t]);let t=e.a;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.qo(e)}qo(e){let t=e.t,n=e.s;if(P.test(n))e.getter=function(){return this[n]};else{let l=t.split("."),i=l.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(i<0||l.indexOf("*",i)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.a,this.d)?.[n]),e.se=l=>{if(this.resolve(t,this.d),this.rp!==e)return this.A(this.rp,this.rr,l);let i=this.read(e.a,this.d);null==i&&k(4,[t,i]),i[n]=l}}e.hn=!0,e.n>0&&(e.F=this.Le++)}qe(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)),t.pn=!0,this.X(l),l}so(e){try{this.X(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}X(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.lo(e);let n=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.P)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].E===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].E===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.Mt(i[e]);else{let t=f<h?f:h;for(let e=c;e<=t;e++)i[e].E===l[e]&&(a[e]=i[e]);let r=new Map;for(let e=f;e>=c;e--){let n=i[e];if(e<=t&&a[e]===n)continue;let l=r.get(n.E);void 0===l?r.set(n.E,n):Array.isArray(l)?l.push(n):r.set(n.E,[l,n])}for(let t=c;t<=h;t++){if(void 0!==a[t])continue;let n,i=l[t],o=r.get(i);void 0!==o&&(Array.isArray(o)?(n=o.pop(),0===o.length&&r.delete(i)):(n=o,r.delete(i))),a[t]=n??new s(e,t,i)}for(let e of r.values())if(Array.isArray(e))for(let t of e)n.Mt(t);else n.Mt(e)}for(let e=c;e<r;e++){let t=a[e];t.y!==e&&(t.y=e,n.Wo(t))}return e.f=a,e.P=l,i}(e,t,this);if(null===n)return;if(e.P===t){let n=K(this.qt,t,G);if(n.push(e),n.length>1)for(let e of n)e.kt=!0}c.Qt?.(this,e,n),(null!==e.N||null!==e.M)&&!e.te&&(e.te=!0,this._e.push(e),this.ve());let l=e.o.jt;if(null!==l)for(let{source:t,getter:i}of l){let l=this.v(t,null),r=n[l],o=e.f[l];r!==o&&(void 0!==r&&r.w&&this.$n(i,r),void 0!==o&&this.$n(i,o))}}Wo(e){this.T.Ko(this,e)}Mt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)Q(e.source,e.key,e.sub);e._=null}if(null!==e.u)for(let t of e.u.values()){this.lo(t);for(let e of t.f)this.Mt(e)}}lo(e){let t=this.qt.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.kt=!1,1===t.length&&(t[0].kt=!1))}resolve(e,t){let n=o(e),l=this.rp=this.o(n.o,!0),i=n.indexes;this.rr=0===l.n?null:null===i?ne(t,l,l.n):this.eo(l,i,t,e)}eo(e,t,n,l){let i=null;for(let r,o=1,s=0;o<=e.n;o++){let a=e.h[o],c=this.qe(i,a),f=t[s++];if(f<0)f=ne(n,e,o)?.y??-1;else if(l&&c.P===u&&Object(r=this.v(a,i))===r){let t=e.t.split("."),n=a.t.split(".").length;t[n]=l.split(".")[n],e=this.o(t.join("."),!0),o--;continue}if(i=c.f[f]??null,null===i)break}return this.rp=e,i}st(e,t){return 0===e.n?ee(this.target,e.z):null===t?void 0:ee(t.E,e.z)}read(e,t){let n=this.G;if(null!==n&&0===n.be&&this.Zn(e,t,n),null!==e.getter)return this.T.zo(this,e,t);if(e.ae){let n=this.read(e.a,t);return n?.[e.s]}return null===e.a&&!(e.s in this.target)&&!this.nt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&k(301,[e.t],e.s,Object.keys(this.target)),this.st(e,t)}v(e,t){let n=this.G;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Zn(e,t,n){let l=n.getter;e.Hn(l),0===l.n?e.Z!==n.de&&(e.Z=n.de,n.En.push(e)):e.n>0&&te(t,Math.min(e.n,l.n))!==te(n.r,Math.min(e.n,l.n))&&(l.ht??(l.ht=new Set)).add(e)}Yo(e,t){for(let n=0;n<this.Ut;n++){let l=this.zn[n];l.getter===e&&l.r===t&&k(701,[e.t])}this.Ut>=128&&k(801,[e.t]);let n=this.Ut++;this.Be++;let l=this.zn[n]??={getter:e,r:t,be:0,de:0,En:[]};l.getter=e,l.r=t,l.be=0,l.de=++H,l.En.length=0;let i=this.G;this.G=l;let r=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Go(e,l),t}finally{this.Be--,this.Ut--,this.G=i,this.d=r,l.r=null}}Go(e,t){let n=t.de;for(let e of t.En)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.st(t,null))||this.ao(t,e))}ao(e,t){return e.Bo(t),this.Ue.push(e),!1}Xo(){for(let e=this.Ue;e.length>0;e=this.Ue){this.Ue=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.a||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Lt(n),t.add(n.a);for(let e of n.Q)this.ao(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.Ue.push(e)}}watchIndex(e){let t=this.G;if(null!==t&&0===t.be){let n=t.getter,l=n.h[e];if(l){let e=l.Dt??(l.Dt=[]);e.includes(n)||e.push(n)}}}it(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:P.test(e)?+e.slice(1):0;return(n<1||n>128)&&k(1001,[e]),this.watchIndex(n),te(this.d,n)?.y}let n=this.Jn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.it?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,l=this.rr;if(null!==n.getter||n.ae||n.n>0)return X(this.read(n,l),t);let i=this.G;return null!==i&&0===i.be&&this.Jo(n,t,i),X(this.v(n,null),t)}Jo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Xn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(X(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};K(e._??=new Map,t,J).add(o),r.push({source:e,key:t,sub:o,de:n.de})}no(e,t,n,l){this.Zt(e,i=>{let r=i._;if(null===r&&null===i.De)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=ee(t,o),a=ee(n,o);if(null!==i.De&&this.Qo(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.w?this.T.ke(this,n.getter,n.r):Q(i,e,n)}})}A(e,t,n,l=!1,i=!1){if(this.Be>0&&k(8),i||this.Ce>0?this.zt=!0:this.Yt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.Nn(e.se,t,[n])}finally{this.Xt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&k(2,[e.t]),e.n>0&&null===t&&k(3,[e.t]);let r=e.ae?this.v(e,t):this.st(e,t);if(l||!this.Vt||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,Y.delete(e.l.P),e.E=n,this.T.Gt(e)}else{let l=1===e.z.length?0===e.n?this.target:t.E:this.v(e.a,t);null==l&&k(4,[e.t,l]),l[e.s]=n}this.xn(e,t),null!==t&&this.to(t,e,r,n),0===e.n&&this.no(e,r,n),this.Xt(e,t,r,n,!0,i)}}co(e){return(this.qt.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}to(e,t,l,i,r=!0){let o=e.l,s=t.t.slice(o.o.t.length+2),a=""!==s&&function(e){let t=Y.get(e);if(void 0===t){let n=new Set;Y.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.kt&&null===o.o.getter&&!o.o.B.length)return;let u=e.E,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(n.E=i,this.T.Gt(n)),r?this.xn(o,n):this.Sn(o,n),this.Xt(o,n,l,i,r)};for(let t of this.co(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.E===u&&n.y!==e.y&&c(t,n);if(""===s)return;let f=new Set([o.P]),h=e=>Array.isArray(e)&&e.includes(u),d=(e,t)=>{if(!f.has(e)&&f.add(e))for(let t of this.qt.get(e)??[])for(let e of t.f)e.E===u&&c(t,e);for(let l of t){let t=l.Y,i=t===n;i&&(t=this.oe.get(l)?.P),(i||h(t))&&!f.has(l.B)&&f.add(l.B)&&(!i&&t!==e&&this.T.ke(this,l,null),d(t,l.B))}},p=e=>{for(let t of e.Q)if(!f.has(t)&&f.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.st(t,null);h(e)&&d(e,t.B)}};null!==o.o.getter?p(o.o):d(o.P,o.o.B)}Sn(e,t){this.Zo(e,t,e=>{this.X(e);for(let t of e.kt?this.co(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.Nt(e,n),this.Sn(e,n)}})}xn(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.X(t)}Zo(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Qo(e,t,n,l){for(let{getter:i,Qn:r}of e.De)this.uo(i.h[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.$n(i,t)}})}$n(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Xt(e,t,n,l,i,r){c.re?.(this,e,t,n,l,i,r),this.Ke(e,t)}Ke(e,t){this.T.er(this,e,t),this.ve()}fo(e){let t=this.ot.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.ot.set(e,n);let l=this.root,i=this.Kn;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.w&&o.tr(e,t))return}}),n}reset(e){let t=this.target,n=this.nt;for(let e of this.O.all())null===e.a&&null!==e.getter&&n.add(e.s);this.oo(e);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.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.po(e);this.Me=null;try{this.Et()}finally{this.Rn()}c.element?.(this,"reset")}oo(e){for(let[t,n]of V)void 0!==e[t]&&$(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||k(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&k(44,["state","$behavior"]);for(let e in n)(!_.includes(e)||"boolean"!=typeof n[e])&&k(44,["$behavior",e]);let[l,i,r]=_.map(e=>n[e]??!0);void 0!==this.target&&(l!==this._t||i!==this.Vt||r!==this.Ht)&&k(45);let o=function(e,t){let n={};for(let l of x(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new S(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of x(e.$eventTokens,"$eventTokens"))n.set(t,new S(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&k(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&k(23,[e]),"function"!=typeof i&&k(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this.Uo);this._t=l,this.Vt=i,this.Ht=r,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Mo();this.Xn.length=0,this.io(e),this.commands=o,this.Oe=s}po(e){this.so(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.vt=null,n._=null,this.Nt(t,n),null!==n.u)for(let e of n.u.values())this.po(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}nr(e,t,n){let l=this.Oe.get(e);void 0===l&&k(1301,[e],e,this.Oe.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&k(1302,[e],e,Object.keys(this.commands)),t}or(e,t,n){this.command(e).emit(t,...this.H(n))}ir(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&k(5,[e]),this.Nn(l,n,[t,...this.H(n)])}Nn(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}Nt(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Bt&&t.o.ee(e)&&(t.Bt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.we;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let l=t.N;null!==l&&null!==l.pe&&l.mo(this,e);let i=t.l.M;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.pe&&l.mo(this,e)}}Pn(e,t,n){this.Zt(e,e=>{let l=e.B;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.at(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.ht&&r.ht.has(e))this.nn(r.h[r.n],e=>this.at(r,e,n));else if(r.n<=e.n){let e=te(t,r.n);null!==e&&this.at(r,e,n)}else this.en(t,r,e=>this.at(r,e,n))}})}at(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.Nt(e,t),this.Pn(e,t,n))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.uo(e,e=>{for(let n of e.f)t(n)})}uo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}en(e,t,n){if(e.l.n===t.n)return n(e);let l=e.u?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.en(e,t,n)}sr(e){let t=e.r;null===t?K(this.ue,e.o,J).add(e):(t.we??(t.we=[])).push(e)}Tn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.He||(this.He=!0,queueMicrotask(this.Ho))}An(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Bt=!1;this.We=[],this._e=[],this.Ve=[],this.T.nt(this)}ho(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];w(n,`[@wcstack/state] ${b(e)}`),c.ct?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.An()}Et(){this.He=!1;let e=this.Kt;this.Kt=0;let t=0;if(!this.zt||this.Yt?this.Yn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Yn,0),this.zt=this.Yt=!1,t>100)101===t?this.ho(41,100):this.An();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.bn?this.An():this.ho(11,32),this.bn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Bt=!1,this.so(e)}let l=this._e,i=this.We;this._e=[],this.We=[];let r=!1,o=()=>{r=!0;for(let e of l){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.xt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<i.length;t++){let n=i[t];!n.te||null===n.j==(0===e)||(n.te=!1,(null===n.Fn||n.Fn.w)&&this.ze(n))}if(!this.gn&&(this.Ye(),0===--this.yn&&this.go(),this.He)){this.Kt=t+1,this.wn++;try{for(;this.He;)this.Et()}finally{this.wn--}}},s=(l.length>0||i.some(e=>null!==e.j))&&0===this.wn?j("state",o):o();r||this.yn++,void 0!==s&&s.then(void 0,w)}}finally{this.gn=!1}this.zt=this.Yt=!1,this.Ye(),0===this.yn&&this.go(),e>0&&this.He&&(this.Kt=t+1)}}go(){c.me?.(this),this.Xo()}Rt(e,t){this.$t.push([e,t])}Jt(e,t,n,l){this.Rt(e,{o:{t},c:n,on:()=>l})}ze(e){try{e.apply()}catch(t){return void this.$t.push([t,e])}null!==this.Me&&this.yo(e.o,e.r)}yo(e,t){let n=K(this.Me,e.t,G);null!==t&&n.push(this.H(t))}Rn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}Ye(){let e=this.Me;if(null!==e&&e.size>0){this.Me=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Ce++;try{t=this.$e("$renderedCallback",[n,l])}catch(e){w(e)}Z(t)?t.then(this.Gn,e=>{this.Gn(),w(e)}):this.Ce--}if(0===this.$t.length)return;let t=this.$t;this.$t=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ge?.(this,e,l);let t=l.o.t,i=l.on();if("function"==typeof n)try{let n=this.$e("$errorCallback",[e,{path:t,bindingType:i,node:l.c}]);Z(n)&&n.then(void 0,w)}catch(e){w(e)}else w(e,`[@wcstack/state] ${b(12,l.name?[i,t,l.name,l.i]:[i,t])}`,l.c)}}$e(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Nn(n,null,t):void 0}wo(e,t,n){if(0===e.n)return void n(null,[]);let l=[],i=(r,o)=>{let s=e.h[r];this.read(s,o);let a=this.qe(o,s),u=t=>{l.push(t.y),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,!0);void 0!==t&&this.kn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=ne(t,n,e);if(null===i)break;l.push(i.y)}0===l.length&&k(6,[e])}}let i=[];return this.wo(n,l,e=>i.push(this.read(n,e))),i}vn(e,t,n,l){Array.isArray(t)||k(9,[e]),this.Be>0&&k(8);let i=this.o(e,!0);this.kn("$setAll",e,i,t,!1);let r=[];this.wo(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&k(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.A(i,t,a),s++)}return s}kn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&k(i?901:902,[e,t,n.n,r])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},re=new Map,oe=new Set(["if","elseif","else","for"]),se=new Set([O,"if","elseif","for","..."]),ae=new Set([M,T,"style","command",C,"state"]);function ue(e){let t=function(e){return q(e,";")}(e).map(I).filter(e=>e.length>0).map(e=>{let t=D(e,":");-1===t&&k(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(se.has(i)){let t;return i!==n&&k(102,[e,i]),i===O?(l.length>0&&k(103,[e]),t={et:"#else",tt:[]}):"..."===i?(0===l.length&&k(104,[e]),t=F(l),t.tt.length>0&&k(105,[e])):(t=F(l),"for"===i&&t.tt.length>0&&k(121,[e])),{Ee:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===M||i===T)&&k(122,[e,i]);let r=F(l),o=function(e){let[t,n]=L(e,"input",re),l=t.split("#").map(I);l.length>2&&k(115,[t]);let[i,r]=l,o=i.split(".").map(I);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&k(116,[e]),{Ee:i,Ne:o,rn:r?r.split(",").map(I):[],D:n}}(n),[s]=o.Ne;if(""===s&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||ae.has(e[0]))&&k(106,[n]),{...o,Ee:e.join("."),Ne:e,...r,b:"prop"}}return{...o,...r,b:"radio"===i||"checkbox"===i?i:s===C||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>oe.has(e.b))&&k(201,[e]),t}var ce=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],fe=new Map,he=new Map;function de(e){for(let t of Object.keys(e))fe.set(t,{...e[t]});he.clear()}function pe(e){return fe.has(e)}function me(e){k(26,[e])}function ge(e){k(27,[e])}function ye(e,t){k(28,[e,t])}function $e(e,t){k(29,[e,t])}function ve(e){return!(!e||isNaN(Number(e)))}function we(e,t){return ve(e)||ge(t),Number(e)}function be(e,t,n){return we(e?.[t]??me(n),n)}function ke(e,t){return void 0!==t&&t.length>0?t[0]:e}var Se=(e,t)=>({factory:n=>{let l=be(n,0,e);return n=>("number"!=typeof n&&ye(e,n),t(n,l))},arity:[1,1]}),xe={eq:{factory:(e,t)=>{let n=e?.[0]??me("eq"),l=ke(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(ve(n)||ge("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??me("ne"),l=ke(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(ve(n)||ge("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Se("lt",(e,t)=>e<t),le:Se("le",(e,t)=>e<=t),gt:Se("gt",(e,t)=>e>t),ge:Se("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ae=!1;function Ne(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function je(e){return 0===e.length?null:(Ae||(Ae=!0,de(xe)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=he.get(l);if(typeof i<"u")return i;let r=fe.get(e);void 0===r&&function(e,t){ce.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),k(501,[e],e,t)}(e,fe.keys());let[o,s]=r.arity;t.length<o&&k(601,[e,o,t.length]),t.length>s&&k(602,[e,s,t.length]);let a=r.factory(t,n);return he.set(l,a),a}(e.qn,e.args,e.literals)))}var Oe=Symbol.for("wcstack.trustedTypes.policy");function Ce(){let e=globalThis[Oe];return null!==e&&"object"==typeof e?e:null}function Me(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Te(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ce(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Pe=Symbol.for("wcstack.state.view-transition-naming"),Ee=new WeakSet;function We(){let e=N("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Ie=new WeakMap,Re=e=>e.customElementRegistry??customElements;function De(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Re(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>De(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(Ie.has(e))return Ie.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,bo:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Ie.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.w||function(e,t,n){let l=n;null!==t&&(t.Pt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Ve(e,l,t,n)}e.ve()})}function qe(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Ht;f&&null===a&&!u&&k(38,[l]);let h=t.U;(null===a?"element"===h||"auto"===h:!u&&("state"===h||"auto"===h))&&k(39,[h,l]),"connect"===t.X&&null===a&&k(40,[l]);let d=f&&null!==a&&!u,p=new He(e,Ue,n,l,i,r,o,t.x,void 0);p.D=t.D,et(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.bo||c.detail?.(n,l,i)),(!p.On||!Object.is(i,p.value))&&(i=Ne(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.bo,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.ze(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.ze(p));let t=n[l];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.X||n.isConnected?i():Promise.resolve().then(i)}return p}function Le(e,t,n){k(e,[t.localName,n])}var ze=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Ue=11,Fe=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Ve=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Tt,l,Fe[n.i]),_e=Symbol();function Be(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:_e}var He=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.D=null,this.On=!1,this.engine=e,this.i=t,this.c=n,this.name=l,this.o=i,this.r=r,this.Fn=o,this.x=s,this.value=a,this.j=u}on(){return Fe[this.i]}apply(){if(null!==this.j)return void this.j.xt();let e=Ne(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Ue||8===this.i||Me(this.name)))return;if(this.value===_e)return void(this.value=e);let t=this.c;if(this.i!==Ue)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Je(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.On=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.On=!1}}}sn(){return Ne(this.D,this.c.value)}ar(){let e,t=this.c,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),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=Ne(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},Ke=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Je(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?Te(l):null==l?"":String(l):Me(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Te(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ge]=[n,l])));case 8:return void(t.innerHTML=Te(l));case 2:return null!=l&&"boolean"!=typeof l&&k(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Ge=Symbol();function Ye(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ge];void 0!==n&&(t[n[0]]=n[1])}var Ze=class{constructor(e,t,n,l){this.w=!0,this.we=null,this.u=null,this.Pt=null,this.In=null,this.r=e,this.ut=t,this.L=n,this.C=l}tr(e,t){let n=t.target,l=this.C,i=[],r=null;for(let t of l.Oe){if(t.name!==e)continue;let o=l.jn[t.c],s=ut(null===this.L?this.ut:this.L[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.Cn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ut:this.L[this.L.length-1]}Re(){let e=this.In;return(null===e?null:e.Dn(this.ut))??this.ut}insertBefore(e,t){let n=this.s;for(let l=this.Re();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}So(){null===this.L?this.ut.remove():ct(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Pt)for(let e of this.Pt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Tn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Xe=class extends Ze{constructor(e,t,n,l){super(e,t,n,l),this.$o=0,this.V=null,this.pe=0===l.Xe.length?null:new Array(2*l.Xe.length)}Eo(e,t){let n=this.V??=new Array(this.C.Xe.length),l=n[t];if(void 0===l){let i=this.C.Xe[t],r=this.pe;l=n[t]=new He(e,i.i,r[2*t],i.name,i.o,this.r,this,i.x,r[2*t+1])}return l}mo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.Eo(e,l))}Pe(e){let t=this.r;t.N===this&&(t.N=null),super.Pe(e)}};function Qe(e,t,n,l){let i=te(n,t.n);try{return e.qe(i,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function et(e,t,n){n&&e.sr(t);let l=t.Fn;null!==l&&(l.we??=[]).push(t)}var tt=null;function nt(){let e=tt;return tt=null,e}var lt=-1;function it(e,t,n,l,i=null){let r,o=t.jn,s=t.build,a=t.No,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.Ln,d=f?document.createDocumentFragment():(h?t.root:t.ln).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=ut(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 Xe(n,r,u,t),null===l.map?n.N=m:l.map.set(n,m)):p=new Ze(n,r,u,t),lt>=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||Ee.has(i))return;let o=globalThis[Pe]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${b(25,[l])}`)):(Ee.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",lt),t.Oe.length>0){let t=e.Kn;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.cr,y=e.Me,$=t.ur?a.slice(0,o.length):a,v=null===m?null:m.pe;if(null!==v){let e=t.Xe;for(let t=0;t<e.length;t++)v[2*t]=$[e[t].c],v[2*t+1]=e[t].q}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.c],o=l.F;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.ze(t);continue}try{let t=Ne(l.x,e.read(l.o,n));t!==l.q&&(Je(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.yo(l.o,n)}catch(t){e.Rt(t,m.Eo(e,o))}continue}switch(l.i){case 6:{let t=new at(e,l.C,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.In=t),t.xt();break}case 7:{let t=ot(e,l.K.map(e=>({C:e.C,o:e.o,x:e.x,S:$[e.c]})),n,p);(p.u??=[]).push(t),i===r&&(p.In=t);break}default:try{rt(e,l,i,n,p)}catch(t){Ve(e,t,l,i)}}}return tt=p,d}function rt(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Cn,o=e=>r(e,l);if(n.ot){let l=e.fo(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.xe&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.ko&&null!==i&&(i.Pt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void De(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.Tt.slice(9)),s=null===i?c.lr?.(n,r):null;s||(null===i&&Le(1202,n,`command.${r}`),i.commands.has(r)||k(1203,[n.localName,r]));let a=new WeakRef(n),u=o.subscribe((...e)=>{let t=a.deref();if(void 0!==t)return t.isConnected?s?s(t,e):t[r](...e):void 0;u()});null!==l&&(l.Pt??=[]).push(u)}(e,t,r,i,n));case 13:return void De(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&Le(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&k(1204,[n.localName,r]);let s=t.Tt;n.addEventListener(o.event,n=>{t.At&&n.preventDefault(),t.Ft&&n.stopPropagation();try{e.nr(s,n,l)}catch(e){w(e)}})}(e,t,r,l,n))}let o=t.o,s=te(l,o.n);if(14===t.i)return void De(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&Le(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.vo?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;qe(e,{...t,U:null,X:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.xe&&1===t.i)return void De(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void qe(e,t,n,t.name,t.o,l,i,r);let o=new He(e,1,n,t.name,t.o,l,i,t.x,Be(e,t,l));o.D=t.D,!c.dr?.(o,t.ro)&&(et(e,o,!0),e.ze(o))}(e,t,r,s,i,n));let a=new He(e,t.i,n,t.name,o,s,i,t.x,Be(e,t,s));a.D=t.D,et(e,a,!0),e.ze(a),null!==t.Ot&&n.addEventListener(t.Ot,()=>a.ar())}function ot(e,t,n,l){let i=new st(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,te(n,t.n),l,null,void 0,i);et(e,s,!0),null===l&&i.ue.push(s),r??=s}return e.ze(r),i}var st=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}Dn(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}xt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ne(l.x,e.read(l.o,te(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(lt=We(),null!==this.I&&(this.I.So(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],l=it(e,n.C,this.r,null,n.S);this.I=nt();let i=n.S.parentNode;i.insertBefore(l,n.S),Ye(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Tn(e);null!==this.I&&this.I.Pe(this.engine)}},at=class{constructor(e,t,n,l){this.w=!0,this.Ae=[],this.engine=e,this.C=t,this.l=n,this.S=l,null===n.N?(n.N=this,this.map=null):((n.M??=[]).push(this),this.map=new Map)}Dn(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ct(e){return null===this.map?e.N:this.map.get(e)??null}Lt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}xt(){let e=this.engine,t=this.l.f,n=this.Ae;lt=We();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){let e=n[0].Re(),t=n[i-1].s,l=[];for(let n=o.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==r&&3!==n.nodeType){l=null;break}l.push(n)}null!==l?o.replaceChildren(...l):ct(e,t);for(let e=0;e<i;e++)this.Lt(n[e])}return void(this.Ae=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.Ct(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.Ct(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.w&&this.Ct(l)===t?t.$o=e:(t.So(),this.Lt(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.Ct(t[a+e]);null!==n&&n.w?(u[e]=n.$o,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Re():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.Ct(n);null!==u&&u.w?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(it(e,this.C,n,this),i),u=nt()),s[a+r]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(it(e,this.C,t[l],this)),s[l]=nt();o.insertBefore(n,h)}}this.Ae=s,Ye(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function ut(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 ct(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var ft=()=>ie.bindAttributeName;function ht(){return{c:0,i:1,name:"",o:null,x:null,q:t,Cn:null,C:null,K:null,D:null,Ot:null,xe:!1,U:null,X:null,ro:!1,At:!1,Ft:!1,Tt:null,vo:null,F:-1,ot:!1,ko:!1}}var dt=["state","element","auto","none"],pt=["call","connect"],mt="$command.";function gt(e,t,n){P.test(t)&&(null===n&&k(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&&k(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&k(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?n:n.h[e];l.h[e]!==t&&k(1403,[l.t,l.h[e].t,t.t])}return c.xo?.(e,l),l}var yt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),$t=e=>8===e.i||yt(e)||1===e.i&&Ke(e.name);function vt(e){k(202,[e])}function wt(e,t,n,l,i){let r=ue(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.Ht||k(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&k(33,[r,n]),null!==(s?l:i)&&k(34,[r]),(s?dt:pt).includes(o)||k(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),At:t.includes("prevent"),Ft:t.includes("stop"),event:n?n.slice(2):null,U:l,X:i}}(e,t.rn),o=l.localName.includes("-"),s=t.Ne,a=t.et;if("event"===t.b){if(null!==r.U&&"none"!==r.U&&k(36),"eventToken"===s[0])return{...ht(),c:i,i:13,name:s.slice(1).join("."),Tt:a,xe:o,At:r.At,Ft:r.Ft};let n=a.startsWith(mt)?a.slice(9):null,{At:l,Ft:u}=r,f=t.Ee.slice(2),h=t.rn.includes("direct"),d=!h&&ze.has(f);d&&e.fo(f);let p=t=>{w(t),d&&c.handlerThrew?.(e,a,f)};return{...ht(),c:i,i:5,name:f,ot:d,xe:o,ko:h,Cn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.or(n,t,i);else{let n=e.ir(a,t,i);Z(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ht(),c:i,i:14,o:gt(e,a,n),xe:o};if("command"===s[0]&&s.length>1)return a.startsWith(mt)||k(1201,[t.Ee,a]),{...ht(),c:i,i:12,name:s.slice(1).join("."),Tt:a,xe:o};let u=gt(e,a,n),f={...ht(),c:i,i:1,name:t.Ee,o:u,x:je(t.tt),D:je(t.D),ro:r.ro,U:r.U,X:r.X};if("radio"===t.b||"checkbox"===t.b)return("element"===r.U||"auto"===r.U)&&k(37,[t.b,r.U]),f.i="radio"===t.b?9:10,r.ro||(f.Ot=r.event??"input"),f;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return f.U=null,f.name=e,"class"===t?(f.i=2,f.q=l.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,f}return"html"===t.Ee?(f.i=8,f):(f.name="text"===t.Ee?"textContent":t.Ee,f.xe=o&&!Me(f.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,f.name)&&(f.Ot=r.event??("select"===l.localName?"change":"input")),f)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].vo=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var bt=/\{\{([\s\S]+?)\}\}/g;function kt(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({c:o,fr:i[1].trim()}),l=bt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function St(e,t,n,l){let i=function(e){return{Ee:"textContent",Ne:["textContent"],rn:[],D:[],...F(e),b:"text"}}(t);return{...ht(),c:l,i:0,o:gt(e,i.et,n),x:je(i.tt),q:""}}function xt(e){let t=e.getAttribute(ft());if(null===t)return null;let n=ue(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var At=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function Nt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:gt(e,l.et,n),x:"else"===l.b?null:je(l.tt)}),i=[l(t,xt(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=xt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(l(e,t)),"else"===t.b))break}return i}var jt=new WeakSet;function Ot(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.Bn?.(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(t.hasAttribute(ft()+"-ignore"))continue;if(l){if("script"===s||"style"===s||jt.has(t))continue;if(jt.add(t),s===ie.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?xt(t):null;if(null!==f){if("for"===f.b){let l=gt(e,f.et,n),r=Tt(e,t,l,!0);i(a(t,ie.commentForPrefix),l,r)}else"if"===f.b?r(Nt(e,t,n).map((t,l)=>({C:Tt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,At(l,t))}))):vt(f.b);continue}let d=t.getAttribute(ft()),p=null===d?null:wt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some($t)&&!c.Ro?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e._t&&h.data.includes("{{")&&!jt.has(h))for(let{c:e,fr:t}of kt(h))s(e,t);else if(8===h.nodeType){let e=Ct.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 Ct=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Mt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Tt(e,t,n,l){let i=document.importNode(Mt(t),!0),r=[],o=[],s=e=>r.push(e)-1;Ot(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ht(),c:s(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({c:s(e.S),C:e.C,o:e.o,x:e.x}));o.push({...ht(),c:t[0].c,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)yt(e)&&k(203,[e.name]),e.c=n;o.push(...t),e.removeAttribute(ft())},(t,l)=>{o.push(St(e,l,n,s(t)))}),It(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.ot&&!e.xe&&!Pt(r[e.c],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Et(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.c);else h.add(e.c)}let g=[...h].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,jn:a,build:g,Oe:d,cr:p,Ln:u,ur:c,No:[],Xe:f}}function Pt(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 Et(e){if(null!==e.U)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.xe&&null===e.Ot;default:return!1}}var Wt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function It(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&&It(l,t,Wt.has(l.localName)),l=e}}var Rt=new WeakMap;function Dt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Rt.set(t,e),Lt(e,[...n.childNodes]),e.Ye()}function qt(e,t,n){try{let l="template"===t.localName?xt(t):null;null!==l&&!n&&k(204,[l.b]),Lt(e,[t])}catch(e){w(e)}e.Ye()}function Lt(e,t){Ot(e,t,null,!0,(t,n,l)=>{new at(e,l,Qe(e,n,null,t),t).xt()},t=>{ot(e,t,null,null)},(t,n)=>{c.Bn?.(e,t,n);for(let l of n)rt(e,l,t,null,null)},(t,n)=>{c.Bn?.(e,t,n),rt(e,St(e,n,null,0),t,null,null)})}var zt=Symbol.for("wcstack.binder"),Ut=Symbol.for("wcstack.binder.pending"),Ft=Symbol.for("wcstack.binder.taken");var Vt=new Map;function _t(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Rt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Vt.set(e,t):qt(n,e,t?.range)}function Bt(){let e=[...Vt];Vt.clear();for(let[t,n]of e)_t(t,n);!function(){let e=function(){let e=globalThis[zt];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[Ut];return void 0===t&&(t=[],e[Ut]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Ft];return void 0===t&&(t=new WeakSet,e[Ft]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Ht=class{constructor(){this.name="dirty",this.Z=(e,l)=>{if(0===e.n){let l=e.Y;return l!==t&&l!==n&&(e.Y=n,!0)}let i=null===l?null:l.vt;if(null===i)return!1;let r=i[e.F];return r!==t&&r!==n&&(i[e.F]=n,!0)}}er(e,t,n){null!==t.getter&&this.Z(t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}Ko(e,t){let n=t.l.o.Dt;if(null!==n)for(let l of n)l.n===t.l.n?e.at(l,t,this.Z):e.en(t,l,t=>e.at(l,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}zo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.vt??=new Array(e.Le).fill(t),a=null===s?i.Y:s[i.F];if(a!==t&&a!==n&&a!==l&&(null===s||i.F in s))return a;a=l;try{return a=e.Yo(i,null===s?null:r)}finally{null===s?i.Y=a:s[i.F]=a}}Gt(e){e.vt=null}nt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===n&&(t.Y=l):e.nn(t.h[t.n],e=>{let i=e.vt;null!==i&&i[t.F]===n&&(i[t.F]=l)}))}},Kt=0,Jt=new WeakMap;function Gt(e,t=e.getRootNode()){Jt.set(t,[...Jt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Yt(e){let t=Jt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Jt.get(e)!==t?Yt(e):Promise.reject(l.errors[0]):void 0)}var Zt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Zt{constructor(){super(),this.engine=null,this.Mn=!1,this.Ge=!1,this.q=null,this.Je=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.Po=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Yt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Mn){if(null!==this.Je)return void this.Je.Qe();Gt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!Rt.has(t)&&Rt.set(t,e),Bt(),c.element?.(e,"back"),this.To("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Mn=!0;let e=this.getRootNode(),t=c.dt?.(this,e);if(t)return this.Je=t,!t.Ao&&this.parentNode instanceof ShadowRoot&&Gt(this),void(void 0===t.Wt?this.Fo():t.Wt()).then(e=>(this.loaded=!0,t.start(e,()=>this.Oo()))).then(()=>{this.an(),this.cn()},e=>this.Rt(e,t.Ao));this.start(e),Gt(this)}disconnectedCallback(){if(null!==this.Je)return void this.Je.Wn();let e=this.engine;if(null===e)return;let t=e.root;Rt.get(t)===e&&Rt.delete(t),Gt(this,t),this.To("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ge&&k(14),this.loaded)this.Je.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&k(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&k(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&&k(8),l(...e)):l},set(){k(8)}}))}async Fo(){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] ${b(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||k(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let l=this.querySelector('script[type="module"]');return null!==l?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let l="function"==typeof URL.createObjectURL,i=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Kt}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?b(42):b(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(i)}}(l):null!==this.q?Promise.resolve(this.q):new Promise(e=>{this.un=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.Fo(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.q=n,this.Mn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=Rt.get(e)?.element;i?.isConnected&&(i.V||i.Je)&&k(47);let r=new le(n,new Ht);r.element=this,this.engine=r,c.element?.(r,"mounting"),Dt(r,e),Bt(),r.Rn(),this.Oo(),await r.$e("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.cn()}catch(e){this.Ge=!this.V,this.Rt(e)}}Oo(){this.V=!0,this.an()}Rt(e,t){this.Ye(this.V?50:49,e),this.an(),t?this.cn():this.Po(e)}Ye(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);w(t,`[@wcstack/state] ${b(e,[this.localName,...n])}`)}To(e,t,n){(async()=>this.engine.$e(e))().then(n,e=>this.Ye(t,e))}},Qt=[];function en(){return(Qt=Qt.filter(e=>e.deref())).map(e=>e.deref())}var tn,nn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},ln="en";function rn(){if(ie.locale!==tn){tn=ie.locale;try{ln=Intl.getCanonicalLocales(tn)[0]}catch{console.warn(`[@wcstack/state] ${b(48,[tn])}`),ln="en"}}return ln}var on=["full","long","medium","short"];function sn(e,t){let[n,l,i]=(e??[]).map(e=>e||void 0);!l&&on.includes(n)?[n,l]=[void 0,n]:!l&&!i&&/\/|^UTC$/.test(n)&&([n,i]=[void 0,n]),l&&!on.includes(l)&&function(e,t){k(52,[e,t])}(t,l);try{i&&new Intl.DateTimeFormat(void 0,{timeZone:i})}catch{k(54,[t,i])}return[n,l,i]}var an=e=>String(e).padStart(2,"0"),{eq:un,ne:cn,not:fn,lt:hn,le:dn,gt:pn,ge:mn,falsy:gn,truthy:yn,boolean:$n}=xe,vn={toFixed:{factory:e=>{let t=we(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ye("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ye("locale",e),e.toLocaleString(t??rn()))},arity:[0,1]},upper:{factory:nn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:nn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:nn(()=>e=>{let t=String(e);return t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:nn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:nn(e=>{let t=[be(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(we(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:nn(e=>{let t=be(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:nn(e=>{let t=be(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:nn(e=>{let t=be(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:nn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:nn(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)||k(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ye("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ye("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ye("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=we(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ye("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:nn(e=>{let t=e?.[0]??me("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:nn(e=>{let[t,n,l]=sn(e,"date"),i=(n||l)&&{dateStyle:n,timeZone:l};return e=>(e instanceof Date||$e("date",e),e.toLocaleDateString(t??rn(),i))}),arity:[0,3]},time:{factory:nn(e=>{let[t,n,l]=sn(e,"time"),i=(n||l)&&{timeStyle:n,timeZone:l};return e=>(e instanceof Date||$e("time",e),e.toLocaleTimeString(t??rn(),i))}),arity:[0,3]},datetime:{factory:nn(e=>{let[t,n,l]=sn(e,"datetime"),i=(n||l)&&{dateStyle:n,timeStyle:n,timeZone:l};return e=>(e instanceof Date||$e("datetime",e),e.toLocaleString(t??rn(),i))}),arity:[0,3]},ymd:{factory:nn(e=>{let t=e?.[0]??"-";return e=>(e instanceof Date||$e("ymd",e),`${e.getFullYear()}${t}${an(e.getMonth()+1)}${t}${an(e.getDate())}`)}),arity:[0,1]},hms:{factory:nn(e=>{let t=e?.[0]??":";return e=>(e instanceof Date||$e("hms",e),`${an(e.getHours())}${t}${an(e.getMinutes())}${t}${an(e.getSeconds())}`)}),arity:[0,1]},eq:un,ne:cn,not:fn,lt:hn,le:dn,gt:pn,ge:mn,add:Se("add",(e,t)=>e+t),sub:Se("sub",(e,t)=>e-t),mul:Se("mul",(e,t)=>e*t),div:Se("div",(e,t)=>e/t),mod:Se("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ye("abs",e),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&&ye("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:gn,truthy:yn,defaults:{factory:(e,t)=>{let n=ke(e?.[0]??me("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=ke(e?.[0]??me("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:$n,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??me("currency"),n=e?.[1],l={style:"currency",currency:t};try{new Intl.NumberFormat("en",l);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){k(53,[e])}(t)}return e=>("number"!=typeof e&&ye("currency",e),e.toLocaleString(n??rn(),l))},arity:[1,2]}},wn=!1,bn={name:"formats",hooks:c,install:function(){wn||(wn=!0,de(vn))}};function kn(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 Sn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=kn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var xn=" Validate statically: npx @wcstack/lint <file>.",An=["","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"],Nn=e=>{let t=An[e/100|0];return t?`[wcs/${t}] `:""},jn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],On=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Cn=["","","class.","attr.","style."],Mn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Tn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Pn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,l)=>`binding "${n?(Cn[l]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Tn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Tn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${On(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${On(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}${"string"==typeof t&&/^\d{4}-\d\d-\d\d$/.test(t)?`. A date-only string is a day, not a moment: new Date(${JSON.stringify(t)}) is midnight UTC, the day before west of Greenwich — new Date(y, m - 1, d) is that day where the page is`:""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"${/\/|^UTC$/.test(t)?` — a time zone is the third argument, after the locale and the style, and an empty argument keeps its default: ${e}(,,${t}), ${e}(en-US,long,${t})`:""}`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,54:(e,t)=>`filter ${e} takes an IANA time zone (Asia/Tokyo, America/New_York, UTC), not "${t}"`,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&&jn.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)=>`${Mn(e,t)} failed to initialize.`,50:(e,...t)=>`${Mn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Mn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,l)=>`${e}("${t}") takes ${n} index(es), got ${l}.`,902:(e,t,n,l)=>`${e}("${t}") takes at most ${n} index(es), got ${l}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function En(e,t){let n=Pn[e];return void 0===n?`${Nn(e)}#${e} ${t.join(" ")}`:Nn(e)+n(...t)}var Wn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),In=[[/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.']],Rn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Dn(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(Rn,e)?Rn[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?Sn(t,n):"");for(let[t,n]of In){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"].':ce.some(pe)||(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&&Wn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=xn),l}var qn=new WeakMap,Ln=new WeakMap,zn=new WeakSet,Un=new WeakSet;function Fn(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 Vn(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 _n(e,t){let n=[];for(let e=t;null!==e;e=e.a)n.unshift(e);let l=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==Fn(e.target,t.t)?.get?t:e.O.bt(o(t.t).o)}(e,t);return n.some(e=>null!=l(e)?.getter)?null:Bn(e,n,0,e.target,l)}function Bn(e,t,n,l,i){for(;n<t.length;n++){let r=t[n];if(null===l||"object"!=typeof l)return null;if("*"===r.s){if(!Array.isArray(l)||0===l.length)return null;let r=null;for(let o of l){let l=Bn(e,t,n+1,o,i);if(null===l)return null;if(null===r)r=l;else if(l.seg===r.seg)for(let e of l.names)r.names.includes(e)||r.names.push(e)}return r}if(Array.isArray(l)&&/^\d+$/.test(r.s)){if(Number(r.s)>=l.length)return null;l=l[Number(r.s)];continue}let o=Fn(l,r.s);if(void 0===o&&null===r.a&&e.nt.has(r.s))return null;if(void 0===o){let o=Vn(l),s=i(r.a);for(let t of e.O.all())t.a===s&&null!==t.getter&&o.push(t.s);return n>0&&0===o.length?null:{seg:r.s,names:o,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==o.get||void 0!==o.set)return null;l=o.value}return null}function Hn(e){zn.has(e)||(zn.add(e),setTimeout(()=>function(e){zn.delete(e);let t=qn.get(e);if(void 0===t)return;let n=Ln.get(e);void 0===n&&Ln.set(e,n=new Set);let l=new Map(t),i=new Map;for(let r of e.O.all()){let e=null===r.a||n.has(r)||t.has(r)?void 0:r.B.find(e=>!e.hn);void 0!==e&&(i.set(r,e),l.set(r,3))}for(let[t,r]of l){if(n.has(t))continue;n.add(t);let l=_n(e,t);if(null===l)continue;let s=Xn.get(e),a=t.a;for(;null!==a&&!s?.has(a);)a=a.a;if(null!==a)continue;let u=[...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Un.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==u){n.delete(t),u.initializePromise.then(()=>{Un.add(u),Hn(e)});continue}let f=e.O.bt(o(t.t).o),h="";if(void 0!==f&&f!==t&&null!==f.getter){let e=f.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(f.h[t].t.length+2)}`);h=` The getter "${f.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let d=Sn(l.seg,l.names);if((l.r||3===r)&&""===d&&""===h)continue;let[p,m,g]=1===r?["watch-path-missing","$watch path","watch"]:2===r?["post-update-path-missing","$postUpdate path","postUpdate"]:3===r?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];c.ct?.(e,{type:"state:path-unresolved",source:g,path:t.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${p}] ${m} "${t.t}"${3===r?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${d}${h} ${2===r?"The call updates nothing.":3===r?"The getter reads undefined.":"Updates to this path will be silently dropped."}${xn}`)}}(e),0))}function Kn(e,t,n=!1){Jn(e,t,n?1:0)}function Jn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.a)return;let l=qn.get(e);void 0===l&&qn.set(e,l=new Map),l.has(t)||l.set(t,n),Hn(e)}var Gn=new WeakSet,Yn=!1,Zn=new WeakMap,Xn=new WeakMap;function Qn(e,t,n,l,i,r,o){if(!o)return;let s=Xn.get(e);void 0===s&&Xn.set(e,s=new Set),s.add(t)}function el(e,t){let n=Zn.get(e),l=t.s;if(null!==t.a||Yn||void 0===n||n.has(l)||"$"===l[0]||e.nt.has(l))return;let i=Sn(l,[...n]);n.add(l),""!==i&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${l}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${l}" is not declared: writing it creates a new key.${i}${xn}`)}var tl=new WeakSet;function nl(e){if(tl.has(e))return;tl.add(e);let t=e.emit,n=!1;e.emit=(...l)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${xn}`)),t.apply(e,l))}var ll=new WeakMap;function il(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:Fn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let i=ll.get(e);void 0===i&&ll.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${xn}`))}var rl=new WeakSet,ol=/\bthis\s*[.[]|=\s*this\b/,sl=new WeakSet,al=e=>{for(let t of["src","state","json"])if(e.hasAttribute(t))return`<${e.localName} ${t}${"json"===t?"":`="${e.getAttribute(t)}"`}>`;return`<${e.localName}>`};function ul(e,t){let n=e.element;if("mounting"!==t||!n)return;let l=n.getRootNode();if(sl.has(l))return;let i=[...l.querySelectorAll(ie.tagNames.state)].filter(e=>e!==n&&!e.hasAttribute("mount")&&!e.hasAttribute("bind-component"));0!==i.length&&(sl.add(l),console.warn(`[@wcstack/state] [wcs/second-root] ${i.length+1} root <wcs-state> elements share one root, and there is one state tree per root: ${al(n)} takes it — its state was ready first, whatever the order in the document — and ${i.map(al).join(", ")} is refused (#47). Keep one, and graft the others with <wcs-state mount="path">.${xn}`))}function cl(e){qn.has(e)&&e.Ue.length>0&&Hn(e)}var fl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),hl=!1;function dl(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(hl||!(t instanceof TypeError)||!Me(l)||!("trustedTypes"in globalThis))return;hl=!0;let i="function"==typeof Ce()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${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.c,property:l})}var pl=new WeakMap;function ml(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=pl.get(e);void 0===r&&pl.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 gl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],yl={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},$l={name:"diagnostics",hooks:c,install(){c._o=Dn,c.Vo=En,c.xo=Kn,c.detail=ml,c.Ge=f(c.Ge,dl);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&k(1);for(let[t,n]of gl)void 0!==e[t]&&k(1601,[t,n])})(n),e?.(t,n),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=Vn(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(`^(?:${fl(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(`^${fl(l)}(?:${fl(s)})*${fl(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.`)}}(n),function(e){let t=Fn(e,"$on")?.value;if(null!==t&&"object"==typeof t)for(let e of Object.keys(t)){let n=t[e];"function"!=typeof n||rl.has(n)||!ol.test(String(n))||(rl.add(n),console.warn(`[@wcstack/state] [wcs/on-handler-this] The $on handler "${e}" uses this. A $on handler is called as ${e}(state, event): this is undefined there, so it throws when the event arrives — write ${e}(state, event) { state.x = … }.${xn}`))}}(n),function(e){Ln.delete(e),qn.has(e)&&Hn(e)}(t),function(e){if(Gn.has(e))return;Gn.add(e);let t=e.Jn,n=t.$postUpdate;t.$postUpdate=t=>{Yn=!0;try{n(t)}finally{Yn=!1}let l=e.O.bt(o(t).o);void 0!==l&&Jn(e,l,2)}}(t),function(e){if(void 0!==Object.getOwnPropertyDescriptor(e,"commands")?.set)return;let t=e.commands;Object.defineProperty(e,"commands",{configurable:!0,get:()=>t,set:e=>{t=e;for(let t of Object.values(e))nl(t)}})}(t),Zn.set(t,new Set(Vn(n)))},c.handlerThrew=il,c.element=f(c.element,ul),c.re=f(f(c.re,el),Qn),c.me=f(c.me,cl),c.it=h(p,c.it,(e,t)=>Object.hasOwn(yl,t)?k(1701,[t,yl[t]]):void 0)}},vl={},wl=/\.\d/,bl=new Set(Object.getOwnPropertyNames(Object.prototype)),kl=0,Sl=!1,xl=null,Al=()=>{Sl=!1,kl++};function Nl(){if(null===xl)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=Al,e.port1.unref?.(),xl=()=>e.port2.postMessage(0)}else xl=()=>setTimeout(Al,0);return Sl||(Sl=!0,xl()),kl}function jl(e,t){let n=new Set,l=[e];for(;l.length>0;){let e=l.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let l of t)if(n.ee(l)&&(n.n===l.n||!(l.n<e.n&&e.h[l.n+1].ee(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Ol=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Io=-1,this._n=new Set,this.Ke=null,this.engine=e,this.je=t}pr(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.je)t.getter=null!==t.p.getter||t.p.ae,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(vl,e.v(t.p,null)):this.Vn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[l,i,r,o]of t)if((null===i||i.w)&&Object.is(e.v(l,i),o)){n.add(l);for(let e of this.je)e.p===l&&this.ft(e,i,r,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&jl(Cl(e.p),n)&&this.ft(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){w(t,`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`),c.ct?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}jo(){this.active=!1,this.Fe.clear(),this.early=[]}Vn(e,t,n,l){let i=this.engine.qe(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Vn(e,t+1,n,l)}ft(e,t,n,l){let i=this.Fe.get(e);void 0===i&&this.Fe.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)}re(e,t,n,l,i,r){if(this.active){(this.Ke??=new Set).add(e);for(let r of this.je){let o=r.p;o.n!==e.n||!o.ee(e)||this.ft(r,t,r.getter?r.s.get(t??vl):o===e&&i&&this.engine.Vt&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}else r&&this.early.push([e,t,n,l])}Se(e,t){if(this.active)for(let n of this.je)(n.getter||=null!==n.p.getter||n.p.ae)&&n.p.n===e.n&&n.p.ee(e)&&this.ft(n,t,n.s.get(t??vl),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.je){let i=l.p;if(!(i.n<e.n||i.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.ft(l,t,void 0,!0):this.Vn(i,e.n+1,t,e=>this.ft(l,e,void 0,!0)))}}}me(){let e=this.Ke;if(this.Ke=null,!this.active||0===this.Fe.size)return;let t=this.Fe;this.Fe=new Map;let n=this.engine,l=[];for(let i of this.je){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.w);s.length>1&&s.sort((e,t)=>Ml(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.d;this.n=a+1,n.Ce++;try{if(s=n.v(i.p,t),i.getter&&(i.s.set(t??vl,s),Object.is(s,r)&&(wl.test(i.t)||null!==t&&!u&&!(o??=null!==e&&jl(Cl(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.d=t,c.ct?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.H(t))}catch(e){w(e,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),c.ct?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.d=h,this.n=0,n.Ce--}}}l.length>0&&this.Do(l)}Do(e){let t=Nl();t!==this.Io&&(this.Io=t,this._n.clear());let n=e.filter(e=>!this._n.has(e));if(0!==n.length){for(let e of n)this._n.add(e);w("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.ct?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function Cl(e){for(;null===e.getter&&null!==e.a;)e=e.a;return e}function Ml(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)l.unshift(e.y);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var Tl="$streamStatus",Pl="$streamError",El=new Set(Object.getOwnPropertyNames(Object.prototype)),Wl=!1;function Il(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 Rl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Wl=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Wl=!1}}mr(){for(let e of this.entries)this.start(e,!0)}hr(){for(let e of this.entries)e.pt=!1,e.J?.abort(),e.J=null}gr(){for(let e of this.entries)e.pt=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(Tl,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.pt?Math.max(n.n,t):t,n.pt=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.pt)continue;let r=i.n;if(i.pt=!1,r>32)n.push(i.name),i.g.Y=l;else{t.n=r+1,e.Ce++;try{this.start(i,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Do(n)}start(e,t){let n,i=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.Q.slice();Dl(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.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Tl}.${e}`||n.t===`${Pl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Dl(r);for(let e of o)e.Hn(r);if(r.Y=l,t)throw n;return this.set(Pl,e.name,n),void this.set(Tl,e.name,"error")}}let r=new AbortController;e.J=r,i.A(i.o(e.name),null,e.q),this.set(Pl,e.name,null),this.set(Tl,e.name,"active"),this.yr(e,r,n)}async yr(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.J===t,o=l.o(e.name),s=this.W.n,a=Nl(),u=e=>{Nl()===a&&(this.W.n=s);try{e()}finally{this.W.n=0}},c=e.q;try{let t=await e.source(n,i);if(!r())return;let s=t=>{c=void 0!==e.Lo?e.Lo(c,t):t,u(()=>l.A(o,null,c))};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;s(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;s(t.value)}}}if(!r())return;e.J=null,u(()=>this.set(Tl,e.name,"done"))}catch(n){if(!r())return;e.J=null,t.abort(),u(()=>{this.set(Pl,e.name,n),this.set(Tl,e.name,"error")})}}};function Dl(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.yt.delete(e)}e.Q.length=0,e.Y=t}var ql=new WeakMap;function Ll(e){let t=ql.get(e);return t?.target===e.target?t:void 0}function zl(e,t){let n=new Ol(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("@")||bl.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.xo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new Rl(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)||El.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.`),Il(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,Lo:u,q:f,J:null,pt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[Tl]=i,t[Pl]=r,l}(e,t),n),i=ql.get(e);void 0!==i&&(i.W.jo(),i.It.hr()),ql.set(e,{W:n,It:l,Qe:i?.Qe??!1,target:t})}function Ul(e,t){let n=ql.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Qe="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.jo(),void n.It.gr();n.Qe&&(n.W.pr(),n.It.mr())}}var Fl=["$streamStatus","$streamError"],Vl={name:"temporal",hooks:c,install(){c.fe=f(c.fe,zl),c.element=f(c.element,Ul),c.re=f(c.re,(e,t,n,l,i,r,o)=>Ll(e)?.W.re(t,n,l,i,r,o)),c.Se=f(c.Se,(e,t,n)=>{let l=Ll(e);void 0!==l&&(l.W.Se(t,n),l.It.Se(t))}),c.Qt=f(c.Qt,(e,t,n)=>Ll(e)?.W.Qt(t,n)),c.me=f(c.me,e=>{let t=Ll(e);void 0!==t&&(t.W.me(),t.It.me())}),c.it=h(p,c.it,(e,t)=>{let n=t.split(".",1)[0];if(Fl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=h(d,c.Ie,(e,t)=>(!Wl&&36===t.t.charCodeAt(0)&&Fl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},_l=new WeakMap,Bl=!1,Hl=/^(?!prototype$)[^\d.*$][^.*]*$/;function Kl(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.`)}}_l.set(t,l)}function Jl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Gl(e,t,n){let l=new Map;for(let i of t){Jl(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 Yl(e,t,n,l){if(Bl||!Array.isArray(l))return!1;let i=_l.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.st(t,n);if(!Array.isArray(r)||r===l)return!1;let o=Gl(t.t,r,i);Gl(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){Bl=!0;try{e.A(t,n,s)}finally{Bl=!1}}if(c.length>0){let l=e.qe(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=Hl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.A(s,o,r):(o.E[i]=r,e.A(e.o(`${t.t}.*`),o,o.E,!0))}}return!0}var Zl={name:"list-keys",hooks:c,install(){c.fe=f(c.fe,Kl),c.Ie=h(d,c.Ie,Yl)}},Xl=new WeakMap,Ql=new WeakMap,ei="will not graft: the root state failed to initialize.",ti=new WeakSet,ni=new WeakMap,li=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],ii=["$commandTokens","$eventTokens","$on","$errorCallback"],ri=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,oi=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),si=e=>e?.element?.isConnected?e:void 0;function ai(e){let t=Ql.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ui(e,t){let n=Ql.get(t);if(Ql.delete(t),Array.isArray(n))for(let t of n)di(t,e)}function ci(e){let t=Xl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function fi(e,t){w(`${ri(e.t)} ${t}`),ci(e),e.Ze?.(),e.Ze=null}function hi(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,w)}catch(e){w(e)}}function di(e,t){if(ti.has(t))return fi(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 fi(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)):oi.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.st(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,s)}t.io(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=ni.get(t);void 0===c&&ni.set(t,c=[]),c.push(e),e.el.isConnected&&hi(e,"$connectedCallback"),e.Ze?.(),e.Ze=null}function pi(e,t){let n=Ql.get(e);if(Array.isArray(n))for(let e of n)fi(e,ei);Ql.set(e,t)}var mi=new WeakMap;function gi(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,Ze:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Xl.get(t);void 0===e&&Xl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:si(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Ql.get(t);Array.isArray(e)&&Ql.set(t,e.filter(e=>e!==r)),r.Ze?.(),r.Ze=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ao:!0,start(e){if(null!==i)return fi(l,i);if(Xl.get(t).get(n)===l){for(let t of li)if(void 0!==e[t])return fi(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of ii)void 0!==e[t]&&console.warn(`${ri(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Ze=e;let n=si(Rt.get(t)),i=Ql.get(t);void 0!==n?di(l,n):ai(t)?fi(l,ei):Ql.set(t,[...Array.isArray(i)?i:[],l])})}},Qe(){null!==l.engine&&hi(l,"$connectedCallback")},Wn(){null!==l.engine&&hi(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 yi=new WeakMap,$i=new WeakMap;function vi(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 wi(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=vi(l,"$bindables"),o=vi(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(ie.tagNames.state);return a.set(l,o),yi.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.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)},Qe(){},Wn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var bi=new WeakMap,ki=new WeakSet,Si=new WeakMap,xi=new WeakMap,Ai="data-wcs-wired",Ni=new WeakMap,ji=new WeakMap,Oi=new WeakMap,Ci=0,Mi=new Set,Ti={},Pi=["$watch","$stream","$renderedCallback"],Ei=e=>e.split(".",1)[0];function Wi(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ii(e,t){let n=e.c,l=Ei(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(Ai);else if(!Di(n,l)){let e=n.getAttribute(Ai)?.split(" ")??[];e.includes(l)||n.setAttribute(Ai,[...e,l].join(" "))}Ni.get(n)?.he===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=bi.get(n);void 0===i&&bi.set(n,i=[]),i.push(e),t&&ki.add(e);let r=Si.get(n);return void 0===r&&Si.set(n,r=new Map),r.has(l)||r.set(l,n[l]),xi.get(n)?.(),!1}function Ri(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Di(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function qi(e){let t=e.parentElement;for(;null!==t&&!Ri(t);)t=t.parentElement;let n=Rt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?_t(e):qt(n,e))}var Li=new Set;function zi(e,t){Li.has(e)||(Li.add(e),console.warn(`[@wcstack/state] ${t}`))}var Ui=(e,t)=>t in e.state;function Fi(e,t){let n=Vi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Vi(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 _i(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=Ei(n.t),s=i.entries.find(e=>e.$===n.t);if(void 0===s&&null!==n.a)return function(e,t){let n,l=t.a;for(;null!==l&&void 0===(n=e.mt.get(l));)l=l.a;if(null===l||void 0===n)return;let i=e.R,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=Bi(e,s.r);return 0===t.n?n:(r.resolve(Wi(o.t,[...r.H(n),...i.H(te(i.d,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.se&&(t.se=n=>{let l=a();Hi(e,s.e,()=>r.A(o,l,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.mt.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.$!==o?Ui(i,o):Fi(i,o))return;l=s.ye}else{if(null===t||null!==n.a||"$"===o[0]||Ui(i,o))return;s=t,l=r.o(`${t.ye.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,Bi(e,a)),n.se=t=>{Hi(e,u,()=>r.A(l,a,t)),e.dn=n},e.mt.set(n,{e:s,p:l,r:a})}function Bi(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Hi(e,t,n){let l=Mi.has(e.R);Mi.add(e.R),e.from=t;try{n()}finally{l||Mi.delete(e.R),e.from=null}}var Ki=(e,t)=>t||!Mi.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Ji(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,Ci+=t?1:-1;let n=e.host.engine,l=Oi.get(n);void 0===l&&Oi.set(n,l=new Map);for(let n of e.pe){let e=l.get(n.e.ye);void 0===e&&l.set(n.e.ye,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.$);if(void 0!==i){null===e.ie&&function(e,t){let n=e.host,l=n.engine;e.ie=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=Ei(o);if(o!==a&&!Ui(n,a))continue;let u=l.o(`${t.ye.t}.${o}`);if(null===u.getter)Zi(l,u,t.ye);else if(!Gi.has(u.getter))continue;e.ie.set(u,e.R.o(o))}}(e,i);for(let l of e.ie.keys())t&&null===l.getter&&Zi(n,l,i.ye),n.T.ke(n,l,i.r);e.ie.size>0&&n.ve(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.ie){let r=n.v(l.a,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;zi(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.he}.${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 Gi=new WeakSet;function Yi(e,t,n,l){let i=Oi.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.$||!0!==e.m.ie?.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 Zi(e,t,n){let l=t.a,i=t.s,r=()=>{let t=e.read(l,e.d);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=Yi(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Gi.add(t.getter),t.se=o=>{let s=null===r()?Yi(e,n,e.d,t):null;if(null===s){let t=e.read(l,e.d);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.ie.get(t);void 0===Vi(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.R.A(a,null,o)},t.n>0&&(t.F=e.Le++)}function Xi(e,t,n,l,i,r){if(null!==t.getter)return e.T.ke(e,t,n),void e.ve();if("*"===t.s){if(null===n)return;if(n.E=n.l.P[n.y],e.T.Gt(n),null!==n.u)for(let t of n.u.values())e.X(t)}else e.xn(t,n);c.re?.(e,t,n,l,i,r),e.Ke(t,n)}function Qi(e){let t=e.m.R;for(let[n,l]of e.m.mt)l.e===e.e&&(0===n.n?t.T.ke(t,n,null):t.nn(n.h[n.n],e=>t.T.ke(t,n,e)));t.ve()}function er(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Qi(e);let a,u=e.m,c=u.R;if(""===e.e.$){a=s.slice(1);let e=Ei(a);if("$"===e[0]||Ui(u.host,e)||u.host.entries.some(e=>""!==e.$&&(a===e.$||a.startsWith(`${e.$}.`))))return}else a=e.e.$+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(te(l,e).y);c.resolve(Wi(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Xi(c,h,d,i,r,o)}function tr(e,t,n,l,i,r,o){if(0===Ci)return;let s=Mi.has(e);Mi.add(e);try{let s=ji.get(e);!o&&void 0!==s&&s.fn&&!Mi.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.mt.get(s));)s=s.a;if(null===s||void 0===o)return;let a=e.host.engine;if(s===t&&e.dn===t)return void(e.dn=null);if(null!==o.r&&!o.r.w)return;let u=[...a.H(o.r),...e.R.H(n)];a.resolve(Wi(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Hi(e,o.e,()=>Xi(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.fn&&null!==s.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.$),l=e.host.engine;for(let[i,r]of e.ie)r===t&&(l.T.ke(l,i,n.r),l.ve())}(s,t);let a=Oi.get(e);if(void 0===a)return;for(let[e,s]of a)if(t.ee(e)){let a=s.get(0===e.n?null:te(n,e.n));if(void 0!==a)for(let s of[...a])Ki(s,o)&&er(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||te(e,t.n)===n)for(let e of[...l])Ki(e,o)&&Qi(e)}finally{s||Mi.delete(e)}}async function nr(e,t,n,l,i){if(l===Ti)return;let r=y(l);r&&await r;let o=Ni.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.I;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${ie.tagNames.state} bind-component="${o.he}">.`),null!==s&&Ji(s,!1),null!==s&&function(e,t,n){let l=e.R,i=`[${ie.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.Dn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.ue.values())for(let t of e)if(null===t.j)s(t.c);else for(let e of t.j.K)a(t.j,e.S);for(let e of l.oe.values())for(let t of[e.N,...e.M??[]])null!==t&&a(t,t.S);for(let t of e.L)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.L.includes(n)&&(r(n)||l._t&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.R.element=t,t.engine=e.R,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await lr(e,l):l()}(s,e,n,i);let a=new le(l,new Ht);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.V=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,L:[],R:a,host:o,pe:[],mt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of o.entries)u.pe.push({m:u,e});o.I=u,ji.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.R,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Ei(e.$);Ui(n,t)&&(e.$!==t||Fi(n,t))&&zi(`${i}.${e.$}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.ye,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&zi(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.ye.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Pi.filter(e=>void 0!==n.state[e]);o.length>0&&zi(`${i}.${n.he}$`,`[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.rt;t.rt=n=>{_i(e,r,n),s.call(t,n)};let a=[...t.O.all()];for(let t of a)_i(e,r,t);for(let e of a)s.call(t,e);let u=t.Et;t.Et=()=>{(function(e){for(;void 0!==e;e=ji.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Ji(u,!0),ti.add(a),ui(a,n));let h=c.wr?.(n,a);Dt(a,n),h?.(),u.L=[...n.childNodes],Bt(),f&&a.Rn(),Object.defineProperty(t,o.he,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.he);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,w)}catch(e){w(e)}i(),e.isConnected?(await a.$e("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):Ji(u,!1)}async function lr(e,t){Ji(e,!0);for(let t of e.pe)Qi(t);t?.(),!e.broken&&(await e.R.$e("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function ir(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Rt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){pi(t,e);for(let e of mi.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:Ni.get(r)?.I;return t?.el===e?t:null},s=t=>{throw i&&pi(l,e),t},a=!1;return{Wt:()=>(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(`<${ie.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Re(n).whenDefined(i);let r=Ni.get(n);if(void 0!==r)return r.he!==t&&v(`<${i}> already has a <${ie.tagNames.state} bind-component="${r.he}">.`),r.state;let o=()=>(bi.get(n)??[]).filter(e=>Ei(e.name)===t),s=Di(n,t);if(s&&0===o().length&&qi(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(Ai)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{xi.set(n,l),e=function(e,t){ai(e)&&t();let n=mi.get(e)??new Set;return mi.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())}xi.delete(n);let a=o(),u=Si.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Ti}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(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>")`}.`)}f.push({$:l,ye:e.o,r:e.r,ro:ki.has(e)}),e.engine.Tn(e),""!==l&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return Ni.set(n,r={el:n,he:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,I:null}),h}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await nr(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Qe(){let t=o();null!==t?lr(t).catch(w):a?Promise.resolve().then(()=>{if(e.parentNode===l)return nr(e,r,i?l:r,Ni.get(r).state,()=>{})}).catch(w):xi.has(r)&&qi(r)},Wn(){let e=o();null!==e&&(Ji(e,!1),!e.broken&&(e.R.$e("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.R,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var rr={name:"scopes",hooks:c,install(){c.dt=h(m,c.dt,gi),c.dt=h(m,c.dt,wi),c.dt=h(m,c.dt,ir),c.dr=Ii,c.Ro=Ri,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=ni.get(e)??[];if("disconnected"===t)for(let e of n)ci(e);else if("reset"!==t&&si(Rt.get(e.root))===e){ui(e,e.root);for(let e of n)Xl.get(e.root).has(e.t)||Xl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ui(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:yi.get(n);void 0!==l&&$i.set(e,{host:n,def:l})}(e,n)}),c.re=f(c.re,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=$i.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),tr(e,t,n,l,i,r,!1)}),c.Se=f(c.Se,(e,t,n)=>tr(e,t,n,void 0,void 0,!1,!0)),c.Ie=h(d,c.Ie,(e,t,n,l,i)=>(function(e,t){let n=ni.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let l,i=ji.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.a)l=i.mt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.w)&&!r.ro)&&(!!n||(Bi(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===r.$?"":`.${r.$}`}#ro: ${r.ye.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.fe;c.fe=(t,n)=>{let l=ni.get(t);void 0!==l&&l.length>0&&v(`re-setting a root state with grafted volumes (${l.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Oi.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)}}},or="$recursion",sr=new WeakMap,ar=new WeakSet,ur=new WeakSet,cr=0,fr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),hr=e=>`[wcs/recursion-${e}]`;function dr(e,t){let n=n=>v(`${hr("declaration-invalid")} ${or} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${hr("declaration-invalid")} ${or} ${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 pr=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function mr(e,t){let n=`${e.l}.**`,l=t.slice(n.length);return(!t.startsWith(n)||""!==l&&"."!==l[0]||l.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function gr(e,t,n){let l=mr(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ce){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===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.`),pr(e,i.k)+l}function yr(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${hr("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${hr("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),r+1>128&&v(`${hr("depth-exceeded")} Recursion on "${t.l}.*" 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(`${pr(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.qe(a,i).f,s+1),l.delete(u))}},s=e.o(t.l),a=e.read(s,null);r(a,t.l,0)&&(l.add(a),o(e.qe(null,s).f,0))}function $r(e,t){let n=function(e){let t=e[or],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&&U(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${hr("declaration-invalid")} ${or} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${hr("declaration-invalid")} ${or} must declare exactly one anchor (it declares ${i.length}).`);let r=dr("anchor",i[0][0]),o=dr("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(`${hr("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${fr(r)}((?:${fr(u)})*)${fr(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${fr(s)}((?:${fr(`.*.${a}`)})*)$`)}}(t),l=sr.has(e);null!==n?(l||cr++,sr.set(e,n),ur.add(e),ar.has(e)||function(e){ar.add(e);let t=e,n=t.rt;t.rt=l=>{let i=sr.get(e);if(l.t.includes("**")){let t=e.O.bt(l.t)===l;return void(ur.has(e)||void 0===i&&t?l.getter=()=>U(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.F=t.Le++),i.owners.set(l,i.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=sr.get(e);return l.call(e,void 0!==i&&t.includes("**")?gr(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=sr.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,gr(r,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${hr("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=mr(r,n),s=[];return yr(e,r,(t,n)=>{for(let l of i.call(e,pr(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.vn;t.vn=(n,l,i,o)=>{let s=sr.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||k(9,[n]),l.length>0&&v(`${hr("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${hr("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&k(8);let a=mr(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(`${hr("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(`${hr("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];yr(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,pr(s,t)+a,e.H(n),i);return h}}(e)):l&&(sr.delete(e),cr--)}function vr(e,t){if(0===cr)return!1;let n=sr.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.a){let l=n.owners.get(e);void 0!==l&&v(`${hr("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var wr={name:"recursion",hooks:c,install(){c.fe=f(c.fe,$r),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ur.delete(e)}(e)}),c.Ie=h(d,c.Ie,vr)}},br="4.10.1",kr=e=>e.split(".").slice(0,2).join("."),Sr=class extends Zt{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return kr(this.version)===kr(br)}};function xr(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Sr{})}var Ar=()=>ie.tagNames.ssr,Nr=Symbol.for("wcstack.ssr.snapshotBuilder"),jr=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Or=e=>document.createComment(e),Cr=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Mr=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),Tr=new WeakMap,Pr=new WeakMap,Er=new WeakMap,Wr=new WeakSet,Ir=new WeakMap;function Rr(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Dr(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 qr=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Lr(e,t,n,l){let i=Or(null===l?"wcs-[":`wcs-[:${l}`),r=Or("wcs-]");n.length>0&&n[0].Re().before(...Rr(e,t)),t.after(i);for(let e of n)null===l&&e.Re().before(Or("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ut:e.L[e.L.length-1])(n[n.length-1]):i;(qr(o)??o).after(r);for(let e of Rr(i,r))Wr.add(e)}function zr(e){if(e instanceof at){Lr(e.S,e.S,e.Ae,null);for(let t of e.Ae)Ur(t);return}let t=e.I;null!==t&&(Lr(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Ur(t))}function Ur(e){if(null!==e.u)for(let t of e.u)zr(t)}var Fr=new Set(["script","style","template","textarea","title"]),Vr="data-wcs-raw",_r=e=>Fr.has(e.localName)||e.localName===Ar();function Br(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Or("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Or("wcs-s")):1===t.nodeType&&!_r(t)&&Br(t)}var Hr=0;function Kr(e,t){let n=e.getRootNode(),l=[t];for(let e of Pr.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=Tr.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.N&&n.set(t.N.S,t.N),null!==t.M)for(let e of t.M)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.j)for(let t of e.j.K)n.set(t.S,e.j);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),zr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Er.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Wr.has(e)||1===e.nodeType&&t.has(e)&&Xr(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(_r(e.parentNode)?Ir.has(e):t.has(n)&&Mr(n,"wcs-t:"))&&(Ir.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);_r(e)&&n.some(e=>Ir.has(e))&&e.setAttribute(Vr,n.map(e=>Ir.has(e)?`{{ ${Ir.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Br(9===n.nodeType?n.body:n);let r=document.createElement(Ar());r.setAttribute("version",br);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"}${Hr++}`;e.replaceWith(Or(`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(Dr(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(Dr(t,s,o))}e.before(r)}function Jr(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Ir.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===Ar())continue;let e=t.engine;null!=e&&Kr(t,e)}}var Gr=Symbol.for("wcstack.state.ssr.impl"),Yr=new Map,Zr=new WeakMap,Xr=e=>!0===c.Ro?.(e),Qr=e=>1===e.nodeType&&!_r(e)&&!Xr(e),eo=e=>e.f.flat().concat(e.z??[]),to=e=>{for(let t of eo(e))t.remove()};function no(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&&!Cr(s,"wcs-]");){let e=s.nextSibling;if(Cr(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];Mr(s,"wcs-[")?e=no(s,t,n):(n.push(s),Qr(s)&&lo(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,z:s??r.appendChild(Or("wcs-]"))},u=eo(a);s=a.z.nextSibling;for(let e of u)n?.push(e),t&&jt.add(e);return t&&null!==i?Yr.set(i,a):to(a),s}function lo(e,t){for(let n=e.firstChild;null!==n;)Mr(n,"wcs-[")?n=no(n,t):(Qr(n)&&lo(n,t),n=n.nextSibling)}function io(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=Or(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!Cr(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]?Dr(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&&!_r(i)&&(Xr(i)?Zr.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||ho(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Mr(e,"wcs-[")?l++:Cr(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(Mr(l,"wcs-["))i++;else if(Cr(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),lo(e,n)}function ro(e,t){let n=Zr.get(e);if(void 0===n)return null;Zr.delete(e);let l=e=>io(e,n.ssr,n.Te);if(n.Te||uo(t,e,e,l),l(e),!n.Te)return null;let i=c.Te;return c.Te=go,()=>{c.Te=i,oo()}}function oo(){for(let e of Yr.values())to(e);Yr.clear()}function so(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function ao(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 uo(e,t,n,l){let i=document.createElement("template").content;for(let e of n.childNodes)i.appendChild(i.ownerDocument.importNode(e,!0));l(i),e.root=t;let r=()=>{};Ot(e,[...i.childNodes],null,!0,r,r,r,(t,n)=>St(e,n,null,0))}function co(e,t,n){if(jr()){if(n instanceof Array){for(let e=n.length;e-- >0;)yt(n[e])&&n.splice(e,1);let e=t;if(n.some($t))Wr.add(e);else if(e.localName.includes("-")&&!Xr(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Er.set(e,t)}return}if("string"==typeof n){if(Ir.set(t,n),_r(t.parentNode))return;let e=Or(`wcs-t:${encodeURIComponent(n)}`),l=Or("wcs-/t");return t.before(e),void t.after(l)}let l=Tr.get(e);void 0===l&&Tr.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Pr.get(i);return void 0===r&&Pr.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&Yr.size>0){let e=Yr.get(n);void 0!==e&&(Yr.delete(n),Yr.set(t,e))}}var fo=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),ho=e=>3===e.nodeType&&""===e.data.trim(),po=e=>{let t=Yr.get(e)?.z??e;return(qr(t)??t).nextSibling};function mo(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.jn;for(let l=0;l<n.length;l++){let i=n[l],r=e.ln,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=(qr(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=po(o)}e.No[l]=o}return!0}function go(e,t,n){if(0===Yr.size)return null;let l=t,i=0;if(!n){let e=ie.commentIfPrefix;if(!Cr(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(fo(n)&&i++,!Cr(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Yr.has(l)&&null!==n&&!Cr(n,e)&&1!==n.nodeType;n=n.nextSibling)fo(n)&&(l=n)}let r=Yr.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Yr.delete(l),to(r),null;let o=r.f.shift();if(0===r.f.length&&Yr.delete(l),r.z?.replaceWith(...Rr(t,l)),r.z=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Yr.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else qr(o[e])===o[e+1]&&e++}if(!mo(e,s)){let n=(e.Ln?e.root:e.ln).cloneNode(!0);s=e.Ln?[n]:[...n.childNodes],mo(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 yo={name:"ssr",hooks:c,install(){c.Bn=co,c.wr=ro;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||jr())return;let n=t.previousElementSibling,l=n?.localName===Ar(),i=l?n.getAttribute("version"):null,r=null===i||kr(i)===kr(br);if(r){let t=e,n=t.$e;t.$e=(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] <${Ar()} version="${i}"> does not match ${br}: 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(`[${Vr}]`)))e.textContent=e.getAttribute(Vr),e.removeAttribute(Vr);let h=9===f.nodeType?f.body:f;n.remove();let d=e=>o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!Xr(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 > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ue(t.getAttribute(ie.bindAttributeName)??"")){let t=l.et;l.Ne[0]===r&&n.push([e?ao(e,t,1,0):t,l.Ne.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:ao(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]:ao(l,r[2],2,1)??r[2]};for(let t of so(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Cr(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]?[Or(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of so(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=ie.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")}(e,n,a):io(e,n,r);r||uo(e,f,h,d),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),l=e.map(e=>e.selected),i=e.map(e=>e.hasAttribute("selected")),r=i.lastIndexOf(!0);r<0&&(r=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>l[t]!==i[t]):n.selectedIndex!==r)&&t.push([n,()=>e.forEach((e,t)=>e.selected=l[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),r&&(c.Te=go,queueMicrotask(()=>{oo(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Gr]={build:Jr,reset(){Hr=0}},void 0===e[Nr]&&(e[Nr]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Gr].build(t),reset:()=>e[Gr].reset()})}(),c.Co=f(c.Co,xr);for(let e of en())xr(e)}},$o="__WCSTACK_DEVTOOLS_HOOK__",vo=null,wo=new Set,bo=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),ko=new WeakMap,So=0;var xo=new WeakMap;function Ao(e){if(null===vo)return;let t=xo.get(e),n=wo.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=ko.get(e);return void 0===t&&ko.set(e,t=++So),t})(r)}|${u}|${o.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:o.t,bindingType:a,node:r,replaceNode:r},absoluteAddress:bo(e,o,c)})},r=e=>i(e.i,e.name,e.c,e.o,e.r,e.on()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.we)for(let t of e.we)r(t);if(e instanceof Xe&&null!==e.pe){let t=e.C.Xe;for(let n=0;n<t.length;n++){let l=e.V?.[n];void 0!==l?r(l):i(t[n].i,t[n].name,e.pe[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 at){i(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Ae)o(t)}else null!==e.I&&o(e.I)};for(let t of e.ue.values())for(let e of t)r(e),null!==e.j&&s(e.j);for(let t of e.oe.values())if(null!==t.N&&s(t.N),null!==t.M)for(let e of t.M)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||vo({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&vo({type:"state:binding-added",...l});xo.set(e,n)}function No(e){let t=Rt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function jo(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.O.all()){for(let e=1;e<=r.n;e++)t.add(r.h[e].t);"*"===r.s&&n.add(r.t),null!==r.getter&&l.add(r.t),null!==r.se&&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.Oe.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 Oo=new WeakSet,Co=new WeakMap;function Mo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Oo.has(t))return;Oo.add(t);let l=t.emit;t.emit=(...i)=>(null!==vo&&vo({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.Oe.values())t(n,"event")}(e),"connected"===t){if(wo.has(e))return;wo.add(e),vo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Ao(e)}else"disconnected"===t&&(wo.delete(e),Ao(e),vo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function To(e,t,n,l,i,r){if(null===vo)return;let o=bo(e,t,0===t.n?null:n),s=Co.get(e);void 0===s&&Co.set(e,s=new Set),s.add(o),r&&vo({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function Po(e){if(null===vo)return;let t=Co.get(e);Co.delete(e),void 0!==t&&vo({type:"state:update-batch",addresses:t}),Ao(e)}function Eo(e,t,n){vo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Wo={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Io(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Wo["*"],...Object.hasOwn(Wo,e)?Wo[e]:[]])(n);return l.includes(t)||k(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)if(!g.has(t.name)){if(t.hooks!==c)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${t.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);g.add(t.name),t.install()}}([bn,$l,Vl,Zl,rr,wr,yo,{name:"devtools",hooks:c,install(){c.element=f(c.element,Mo),c.re=f(c.re,To),c.me=f(c.me,Po),c.Ge=f(c.Ge,Eo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[$o]??(e[$o]=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:br,getStateElements:()=>[...wo].map(jo),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let l=n._,i=n.De?.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}(No(e)),keys(e){let t=No(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 No(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){No(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===vo&&null!==e;vo=e,null===e&&(xo=new WeakMap),c.ct=e&&((e,t)=>vo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of wo)Ao(e)})}})}()}},{name:"native-commands",hooks:c,install(){c.lr=Io}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[zt]&&(e[zt]={protocol:"wcs-binder",version:1,bind:_t})})(),en().includes(e)||Qt.push(new WeakRef(e));let t=ie.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),c.Co?.(e)}();
2
2
  //# sourceMappingURL=auto.min.js.map