@wcstack/state 4.6.0 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.mt=null,this.F=-1,this.Y=t,this.De=null,this.It=null,this.jt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=e,this.c=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}_n(e){this.ht.has(e)||(this.ht.add(e),this.B.push(e),e.Q.push(this))}jo(e){this.ht.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Do(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.De=null,this.It=null,this.jt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.c}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.yt=new Map,this.Vn=e}wt(e){return this.yt.get(e)}get(t){let n=this.yt.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.Vn?.(n),this.yt.set(t,n),i&&i.u.push(n),n}all(){return this.yt.values()}Dt(e){this.yt.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.bt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.$=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Lt=!1,this.vt=!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.Mt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Mt(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.Bo?.(e,t,n)??""}`)}function w(e,t=[]){return c.Mo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function b(e,t,n,l){v(w(e,t),n,l)}var k=class{constructor(e){this.kt=new Set,this.name=e}get size(){return this.kt.size}subscribe(e){return this.kt.add(e),()=>{this.kt.delete(e)}}unsubscribe(e){return this.kt.delete(e)}emit(...e){let t=[];for(let n of this.kt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${w(17,[this.name])}`,e)}return t}};function S(e,t,n){if(void 0===e)return[];Array.isArray(e)||b(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&b(19,[t]),i===n&&b(20,[t,i,n]),l.has(i)&&b(21,[t,i]),l.add(i);return e}var x=Symbol.for("wcstack.transition-runner");function A(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function N(e,t,n){let l=A(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var j="else",O="eventToken",C="class",M="attr",T=/^\$[1-9]\d{0,2}$/,P=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function E(e){let t=[],n=[],l="",i=null,r=!1,o=-1,s=-1,a=e=>{let i=function(e,t,n){let l=-1===t?e.length:t,i=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,i+e.slice(i).trimEnd().length)}(l,o,s);(!e||i||r)&&(t.push(i),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:P.test(e)?Number(e):e)}(i,r))),l="",r=!1,o=-1,s=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=l.length),l+=n,s=l.length):'"'===n||"'"===n?(i=n,r=!0):","===n?a():l+=n}return null!==i&&b(107,[i,e]),a(!0),{args:t,literals:n}}var W=e=>e.trim();function I(e,t){let n=[],l=null;for(let i=0;i<e.length;i++){let r=e[i];null!==l?r===l&&(l=null):"'"===r||'"'===r?l=r:r===t&&n.push(i)}return n}var R=(e,t)=>I(e,t)[0]??-1;function D(e,t){let n=[],l=0;for(let i of I(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function q(e,t,n){let l=R(e,"|");if(-1===l)return[e.trim(),[]];let i=e.slice(l+1).trim(),r=n.get(i);return void 0===r&&(r=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>I(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&b(108,[e]),-1!==i&&-1===n&&b(109,[e]),-1!==i&&i<n&&b(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();b(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&b(112,[l]),r.includes("#")){let[,e]=r.split("#");b("input"===t?113:114,[r,e])}return-1===n?{Hn:r,args:[],literals:[]}:{Hn:r,...E(e.substring(n+1,i))}})}(D(i,"|").map(W),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var L=new Map;function z(e){b(1101,[e])}function U(e){let[t,n]=q(e,"output",L);t.includes("@")&&b(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)&&b(119,[e]),function(e){e.includes("**")&&z(e);let t=e.split(".").length;t>512&&b(117,[e,t])}(l),{Ze:l,et:n}}var F=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function V(e){return e.includes("**")&&z(e),e}var _=0;function H(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var K=()=>new Set,J=()=>[],G=new WeakMap;function X(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Y(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function te(e,t,n){let l=ee(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var ne=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.St=[],this.Me=null,this.qn=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.j=0,this.qt=0,this.yn=!1,this.Kt=!1,this.zt=!1,this.Ce=0,this.Kn=()=>{this.j=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.He=[],this.Xn={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=ee(this.d,t);null===n&&b(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.X;if(null!==i){let e=i.getter,n=l.De??(l.De=[]);if(!n.some(n=>n.getter===e&&n.Gn===t)){n.push({getter:e,Gn:t});let i=e.h[t];(i.It??(i.It=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,ee(this.d,n.n)))},$dependOn:e=>{this.resolve(V(e),this.d),null!==this.X&&0===this.X.be&&this.Jn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.wn(e,t,n,l),$resolve:(...e)=>{let t=V(e[0]),n=e[1]??[],l=this.o(t,!0);this.bn("$resolve",t,l,n,!0);let i=this.Qn(l,n,null);if(e.length<3)return this.read(l,i);this.A(l,i,e[2])},$postUpdate:e=>{this.resolve(V(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.P[n.y],G.delete(n.l.P),this.T.Xt(n)),this.vn(t,n),null!==n&&this.Zn(n,t,void 0,n.$,!1),0===t.n&&this.eo(t,void 0,void 0,!0),this.Gt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.He.push(e),this.ot(e)}),this.to(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.rt(t);if(t.indexOf(".")<0){let e=n.O.wt(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(V(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}no(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.ot(e)}ot(e){e.t.includes("**")&&z(e.t),("__proto__"===e.s||"prototype"===e.s)&&b(120,[e.t]);let t=e.c;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(T.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.c,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.c,this.d);null==i&&b(4,[t,i]),i[n]=l}}e.hn=!0,e.n>0&&(e.F=this.Le++)}Ue(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.G(l),l}oo(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}G(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.io(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].$===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].$===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.Bt(i[e]);else{let t=f<h?f:h;for(let e=c;e<=t;e++)i[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.$);void 0===l?r.set(n.$,n):Array.isArray(l)?l.push(n):r.set(n.$,[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.Bt(t);else n.Bt(e)}for(let e=c;e<r;e++){let t=a[e];t.y!==e&&(t.y=e,n.Lo(t))}return e.f=a,e.P=l,i}(e,t,this);if(null===n)return;if(e.P===t){let n=H(this.Ut,t,J);if(n.push(e),n.length>1)for(let e of n)e.vt=!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.It;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.kn(i,r),void 0!==o&&this.kn(i,o))}}Lo(e){this.T.Ho(this,e)}Bt(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.io(t);for(let e of t.f)this.Bt(e)}}io(e){let t=this.Ut.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.vt=!1,1===t.length&&(t[0].vt=!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?te(t,l,l.n):this.Qn(l,i,t,e)}Qn(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.Ue(i,a),f=t[s++];if(f<0)f=te(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}it(e,t){return 0===e.n?Z(this.target,e.z):null===t?void 0:Z(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Jn(e,t,n),null!==e.getter)return this.T.Uo(this,e,t);if(e.ae){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.tt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&b(301,[e.t],e.s,Object.keys(this.target)),this.it(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Jn(e,t,n){let l=n.getter;e._n(l),0===l.n?e.Z!==n.de&&(e.Z=n.de,n.Sn.push(e)):e.n>0&&ee(t,Math.min(e.n,l.n))!==ee(n.r,Math.min(e.n,l.n))&&(l.mt??(l.mt=new Set)).add(e)}qo(e,t){for(let n=0;n<this.Ht;n++){let l=this.qn[n];l.getter===e&&l.r===t&&b(701,[e.t])}this.Ht>=128&&b(801,[e.t]);let n=this.Ht++;this.Be++;let l=this.qn[n]??={getter:e,r:t,be:0,de:0,Sn:[]};l.getter=e,l.r=t,l.be=0,l.de=++_,l.Sn.length=0;let i=this.X;this.X=l;let r=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Ko(e,l),t}finally{this.Be--,this.Ht--,this.X=i,this.d=r,l.r=null}}Ko(e,t){let n=t.de;for(let e of t.Sn)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.it(t,null))||this.so(t,e))}so(e,t){return e.jo(t),this.He.push(e),!1}zo(){for(let e=this.He;e.length>0;e=this.He){this.He=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.c||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Dt(n),t.add(n.c);for(let e of n.Q)this.so(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.He.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.be){let n=t.getter,l=n.h[e];if(l){let e=l.jt??(l.jt=[]);e.includes(n)||e.push(n)}}}rt(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:T.test(e)?+e.slice(1):0;return(n<1||n>128)&&b(1001,[e]),this.watchIndex(n),ee(this.d,n)?.y}let n=this.Xn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.rt?.(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 Y(this.read(n,l),t);let i=this.X;return null!==i&&0===i.be&&this.Yo(n,t,i),Y(this.v(n,null),t)}Yo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Yn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(Y(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};H(e._??=new Map,t,K).add(o),r.push({source:e,key:t,sub:o,de:n.de})}eo(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=Z(t,o),a=Z(n,o);if(null!==i.De&&this.Xo(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&&b(8),i||this.Ce>0?this.Kt=!0:this.zt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.En(e.se,t,[n])}finally{this.Gt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&b(2,[e.t]),e.n>0&&null===t&&b(3,[e.t]);let r=e.ae?this.v(e,t):this.it(e,t);if(l||!this._t||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,G.delete(e.l.P),e.$=n,this.T.Xt(e)}else{let l=1===e.z.length?0===e.n?this.target:t.$:this.v(e.c,t);null==l&&b(4,[e.t,l]),l[e.s]=n}this.$n(e,t),null!==t&&this.Zn(t,e,r,n),0===e.n&&this.eo(e,r,n),this.Gt(e,t,r,n,!0,i)}}lo(e){return(this.Ut.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}Zn(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=G.get(e);if(void 0===t){let n=new Set;G.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.vt&&null===o.o.getter&&!o.o.B.length)return;let u=e.$,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(n.$=i,this.T.Xt(n)),r?this.$n(o,n):this.vn(o,n),this.Gt(o,n,l,i,r)};for(let t of this.lo(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.$===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.Ut.get(e)??[])for(let e of t.f)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.it(t,null);h(e)&&d(e,t.B)}};null!==o.o.getter?p(o.o):d(o.P,o.o.B)}vn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.vt?this.lo(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.$t(e,n),this.vn(e,n)}})}$n(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Xo(e,t,n,l){for(let{getter:i,Gn:r}of e.De)this.ao(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.kn(i,t)}})}kn(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Gt(e,t,n,l,i,r){c.re?.(this,e,t,n,l,i,r),this.qe(e,t)}qe(e,t){this.T.Jo(this,e,t),this.ve()}co(e){let t=this.nt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.nt.set(e,n);let l=this.root,i=this.Un;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.Qo(e,t))return}}),n}reset(e){let t=this.target,n=this.tt;for(let e of this.O.all())null===e.c&&null!==e.getter&&n.add(e.s);this.to(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.uo(e);this.Me=null;try{this.Yt()}finally{this.Nn()}c.element?.(this,"reset")}to(e){for(let[t,n]of F)void 0!==e[t]&&$(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||b(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&b(44,["state","$behavior"]);for(let e in n)(!B.includes(e)||"boolean"!=typeof n[e])&&b(44,["$behavior",e]);let[l,i,r]=B.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.Wt||i!==this._t||r!==this.Vt)&&b(45);let o=function(e,t){let n={};for(let l of S(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new k(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of S(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&b(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&b(23,[e]),"function"!=typeof i&&b(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this._o);this.Wt=l,this._t=i,this.Vt=r,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Do();this.Yn.length=0,this.no(e),this.commands=o,this.Oe=s}uo(e){this.oo(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.bt=null,n._=null,this.$t(t,n),null!==n.u)for(let e of n.u.values())this.uo(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}Zo(e,t,n){let l=this.Oe.get(e);void 0===l&&b(1301,[e],e,this.Oe.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&b(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&b(5,[e]),this.En(l,n,[t,...this.H(n)])}En(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}$t(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.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.fo(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.fo(this,e)}}xn(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.st(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.mt&&r.mt.has(e))this.nn(r.h[r.n],e=>this.st(r,e,n));else if(r.n<=e.n){let e=ee(t,r.n);null!==e&&this.st(r,e,n)}else this.en(t,r,e=>this.st(r,e,n))}})}st(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.$t(e,t),this.xn(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.ao(e,e=>{for(let n of e.f)t(n)})}ao(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)}nr(e){let t=e.r;null===t?H(this.ue,e.o,K).add(e):(t.we??(t.we=[])).push(e)}Rn(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.Et||(this.Et=!0,queueMicrotask(this.Wo))}Pn(){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.Lt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${w(e)}`,n),c.at?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Pn()}Yt(){this.Et=!1;let e=this.qt;this.qt=0;let t=0;if(!this.Kt||this.zt?this.Kn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Kn,0),this.Kt=this.zt=!1,t>100)101===t?this.po(41,100):this.Pn();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.yn?this.Pn():this.po(11,32),this.yn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Lt=!1,this.oo(e)}let l=this._e,i=this.We;this._e=[],this.We=[];let r=()=>{for(let e of l){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.Nt()}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.Tn||n.Tn.w)&&this.Ke(n))}this.gn||(this.ze(),this.Et&&(this.qt=t+1))},o=l.length>0||i.some(e=>null!==e.j)?N("state",r):r();void 0!==o&&o.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.Kt=this.zt=!1,this.ze(),c.me?.(this),this.zo(),e>0&&this.Et&&(this.qt=t+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,l){this.xt(e,{o:{t},a:n,on:()=>l})}Ke(e){try{e.apply()}catch(t){return void this.St.push([t,e])}null!==this.Me&&this.mo(e.o,e.r)}mo(e,t){let n=H(this.Me,e.t,J);null!==t&&n.push(this.H(t))}Nn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}ze(){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.Ee("$renderedCallback",[n,l])}catch(e){console.error(e)}X(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.St.length)return;let t=this.St;this.St=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ye?.(this,e,l);let t=l.o.t,i=l.on();if("function"==typeof n)try{let n=this.Ee("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);X(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${w(12,l.name?[i,t,l.name,l.i]:[i,t])}`,e,l.a)}}Ee(e,t=[]){let n=this.target[e];return"function"==typeof n?this.En(n,null,t):void 0}ho(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.Ue(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.bn("$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=te(t,n,e);if(null===i)break;l.push(i.y)}0===l.length&&b(6,[e])}}let i=[];return this.ho(n,l,e=>i.push(this.read(n,e))),i}wn(e,t,n,l){Array.isArray(t)||b(9,[e]),this.Be>0&&b(8);let i=this.o(e,!0);this.bn("$setAll",e,i,t,!1);let r=[];this.ho(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&b(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}bn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&b(i?901:902,[e,t,n.n,r])}},le={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},ie=new Map,re=new Set(["if","elseif","else","for"]),oe=new Set([j,"if","elseif","for","..."]),se=new Set([C,M,"style","command",O,"state"]);function ae(e){let t=function(e){return D(e,";")}(e).map(W).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&b(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(oe.has(i)){let t;return i!==n&&b(102,[e,i]),i===j?(l.length>0&&b(103,[e]),t={Ze:"#else",et:[]}):"..."===i?(0===l.length&&b(104,[e]),t=U(l),t.et.length>0&&b(105,[e])):(t=U(l),"for"===i&&t.et.length>0&&b(121,[e])),{$e:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===C||i===M)&&b(122,[e,i]);let r=U(l),o=function(e){let[t,n]=q(e,"input",ie),l=t.split("#").map(W);l.length>2&&b(115,[t]);let[i,r]=l,o=i.split(".").map(W);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&b(116,[e]),{$e:i,Ne:o,rn:r?r.split(",").map(W):[],D:n}}(n),[s]=o.Ne;if(""===s&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||se.has(e[0]))&&b(106,[n]),{...o,$e:e.join("."),Ne:e,...r,b:"prop"}}return{...o,...r,b:"radio"===i||"checkbox"===i?i:s===O||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>re.has(e.b))&&b(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],ce=new Map,fe=new Map;function he(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});fe.clear()}function de(e){return ce.has(e)}function pe(e){b(26,[e])}function me(e){b(27,[e])}function ge(e,t){b(28,[e,t])}function ye(e,t){b(29,[e,t])}function $e(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return $e(e)||me(t),Number(e)}function we(e,t,n){return ve(e?.[t]??pe(n),n)}function be(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let l=we(n,0,e);return n=>("number"!=typeof n&&ge(e,n),t(n,l))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:($e(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:($e(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},xe=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ne(e){return 0===e.length?null:(xe||(xe=!0,he(Se)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=fe.get(l);if(typeof i<"u")return i;let r=ce.get(e);void 0===r&&function(e,t){ue.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),b(501,[e],e,t)}(e,ce.keys());let[o,s]=r.arity;t.length<o&&b(601,[e,o,t.length]),t.length>s&&b(602,[e,s,t.length]);let a=r.factory(t,n);return fe.set(l,a),a}(e.Hn,e.args,e.literals)))}var je=Symbol.for("wcstack.trustedTypes.policy");function Oe(){let e=globalThis[je];return null!==e&&"object"==typeof e?e:null}function Ce(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Me(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Oe(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Te=Symbol.for("wcstack.state.view-transition-naming"),Pe=new WeakSet;function Ee(){let e=A("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var We=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function Re(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Ie(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(We.has(e))return We.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new 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,go:"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 We.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.Rt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Fe(e,l,t,n)}e.ve()})}function De(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Vt;f&&null===a&&!u&&b(38,[l]);let h=t.U;(null===a?"element"===h||"auto"===h:!u&&("state"===h||"auto"===h))&&b(39,[h,l]),"connect"===t.G&&null===a&&b(40,[l]);let d=f&&null!==a&&!u,p=new _e(e,ze,n,l,i,r,o,t.x,void 0);p.D=t.D,Ze(e,p,!d),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.go||c.detail?.(n,l,i)),(!p.An||!Object.is(i,p.value))&&(i=Ae(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.go,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.Ke(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.Ke(p));let t=n[l];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.G||n.isConnected?i():Promise.resolve().then(i)}return p}function qe(e,t,n){b(e,[t.localName,n])}var Le=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),ze=11,Ue=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Pt,l,Ue[n.i]),Be=Symbol();function Ve(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:Be}var _e=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.D=null,this.An=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.Tn=o,this.x=s,this.value=a,this.j=u}on(){return Ue[this.i]}apply(){if(null!==this.j)return void this.j.Nt();let e=Ae(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===ze||8===this.i||Ce(this.name)))return;if(this.value===Be)return void(this.value=e);let t=this.a;if(this.i!==ze)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ke(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ae(this.D,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),i=n.v(this.o,this.r),r=Array.isArray(i)?i:[],o=r.includes(l);if(t.checked?o:!o)return;e=o?r.filter(e=>e!==l):[...r,l]}else e=Ae(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},He=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ke(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(He(n)?t[n]="innerHTML"===n?Me(l):null==l?"":String(l):Ce(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Me(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,l])));case 8:return void(t.innerHTML=Me(l));case 2:return null!=l&&"boolean"!=typeof l&&b(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 Je=Symbol();function Ge(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Xe=class{constructor(e,t,n,l){this.w=!0,this.we=null,this.u=null,this.Rt=null,this.On=null,this.r=e,this.ct=t,this.L=n,this.C=l}Qo(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.Cn[t.a],s=at(null===this.L?this.ct: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.Fn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ct:this.L[this.L.length-1]}Re(){let e=this.On;return(null===e?null:e.In(this.ct))??this.ct}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}}bo(){null===this.L?this.ct.remove():ut(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Rt)for(let e of this.Rt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Rn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Ye=class extends Xe{constructor(e,t,n,l){super(e,t,n,l),this.vo=0,this.V=null,this.pe=0===l.Xe.length?null:new Array(2*l.Xe.length)}ko(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 _e(e,i.i,r[2*t],i.name,i.o,this.r,this,i.x,r[2*t+1])}return l}fo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.ko(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=ee(n,t.n);try{return e.Ue(i,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function Ze(e,t,n){n&&e.nr(t);let l=t.Tn;null!==l&&(l.we??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function lt(e,t,n,l,i=null){let r,o=t.Cn,s=t.build,a=t.So,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.jn,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]=at(d,o[t],h?1:0)}h?r=d:(u=f||[...d.childNodes],r=u[0]);let p,m=null;if(null!==l?(p=m=new Ye(n,r,u,t),null===l.map?n.N=m:l.map.set(n,m)):p=new Xe(n,r,u,t),nt>=0&&function(e,t,n,l){let i=null;if(null===t)i=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===i;e++)1===t[e].nodeType&&(i=t[e]);let r=i?.style;if(null===i||void 0===r||Pe.has(i))return;let o=globalThis[Te]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${w(25,[l])}`)):(Pe.add(i),o.assigned++,r.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),r.setProperty("view-transition-class",`wcs-${n}`))}(r,u,null!==l?"row":"branch",nt),t.Oe.length>0){let t=e.Un;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.sr,y=e.Me,$=t.lr?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].a],v[2*t+1]=e[t].q}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.a],o=l.F;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.Ke(t);continue}try{let t=Ae(l.x,e.read(l.o,n));t!==l.q&&(Ke(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.mo(l.o,n)}catch(t){e.xt(t,m.ko(e,o))}continue}switch(l.i){case 6:{let t=new st(e,l.C,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.On=t),t.Nt();break}case 7:{let t=rt(e,l.K.map(e=>({C:e.C,o:e.o,x:e.x,S:$[e.a]})),n,p);(p.u??=[]).push(t),i===r&&(p.On=t);break}default:try{it(e,l,i,n,p)}catch(t){Fe(e,t,l,i)}}}return et=p,d}function it(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Fn,o=e=>r(e,l);if(n.nt){let l=e.co(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.wo&&null!==i&&(i.Rt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.Pt.slice(9)),s=null===i?c.or?.(n,r):null;s||(null===i&&qe(1202,n,`command.${r}`),i.commands.has(r)||b(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.Rt??=[]).push(u)}(e,t,r,i,n));case 13:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&qe(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&b(1204,[n.localName,r]);let s=t.Pt;n.addEventListener(o.event,n=>{t.Tt&&n.preventDefault(),t.At&&n.stopPropagation();try{e.Zo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=ee(l,o.n);if(14===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&qe(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.yo?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;De(e,{...t,U:null,G:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.xe&&1===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void De(e,t,n,t.name,t.o,l,i,r);let o=new _e(e,1,n,t.name,t.o,l,i,t.x,Ve(e,t,l));o.D=t.D,!c.ar?.(o,t.ro)&&(Ze(e,o,!0),e.Ke(o))}(e,t,r,s,i,n));let a=new _e(e,t.i,n,t.name,o,s,i,t.x,Ve(e,t,s));a.D=t.D,Ze(e,a,!0),e.Ke(a),null!==t.Ft&&n.addEventListener(t.Ft,()=>a.ir())}function rt(e,t,n,l){let i=new ot(e,t,n),r=null;for(let o of t){if(null===o.o)continue;let t=o.o,s=new _e(e,7,o.S,"if",t,ee(n,t.n),l,null,void 0,i);Ze(e,s,!0),null===l&&i.ue.push(s),r??=s}return e.Ke(r),i}var ot=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}In(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}Nt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ae(l.x,e.read(l.o,ee(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(nt=Ee(),null!==this.I&&(this.I.bo(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],l=lt(e,n.C,this.r,null,n.S);this.I=tt();let i=n.S.parentNode;i.insertBefore(l,n.S),Ge(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Rn(e);null!==this.I&&this.I.Pe(this.engine)}},st=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)}In(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ot(e){return null===this.map?e.N:this.map.get(e)??null}Dt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}Nt(){let e=this.engine,t=this.l.f,n=this.Ae;nt=Ee();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):ut(e,t);for(let e=0;e<i;e++)this.Dt(n[e])}return void(this.Ae=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.Ot(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.Ot(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.Ot(l)===t?t.vo=e:(t.bo(),this.Dt(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.Ot(t[a+e]);null!==n&&n.w?(u[e]=n.vo,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.Ot(n);null!==u&&u.w?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(lt(e,this.C,n,this),i),u=tt()),s[a+r]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(lt(e,this.C,t[l],this)),s[l]=tt();o.insertBefore(n,h)}}this.Ae=s,Ge(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 at(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let l=t[n];l>0;l--)e=e.nextSibling}return e}function ut(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var ct=()=>le.bindAttributeName;function ft(){return{a:0,i:1,name:"",o:null,x:null,q:t,Fn:null,C:null,K:null,D:null,Ft:null,xe:!1,U:null,G:null,ro:!1,Tt:!1,At:!1,Pt:null,yo:null,F:-1,nt:!1,wo:!1}}var ht=["state","element","auto","none"],dt=["call","connect"],pt="$command.";function mt(e,t,n){T.test(t)&&(null===n&&b(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&&b(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&b(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&&b(1403,[l.t,l.h[e].t,t.t])}return c.Eo?.(e,l),l}var gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&He(e.name);function $t(e){b(202,[e])}function vt(e,t,n,l,i){let r=ae(t).map(t=>function(e,t,n,l,i){let r=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||b(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&b(33,[r,n]),null!==(s?l:i)&&b(34,[r]),(s?ht:dt).includes(o)||b(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),Tt:t.includes("prevent"),At:t.includes("stop"),event:n?n.slice(2):null,U:l,G:i}}(e,t.rn),o=l.localName.includes("-"),s=t.Ne,a=t.Ze;if("event"===t.b){if(null!==r.U&&"none"!==r.U&&b(36),"eventToken"===s[0])return{...ft(),a:i,i:13,name:s.slice(1).join("."),Pt:a,xe:o,Tt:r.Tt,At:r.At};let n=a.startsWith(pt)?a.slice(9):null,{Tt:l,At:u}=r,f=t.$e.slice(2),h=t.rn.includes("direct"),d=!h&&Le.has(f);d&&e.co(f);let p=t=>{console.error(t),d&&c.handlerThrew?.(e,a,f)};return{...ft(),a:i,i:5,name:f,nt:d,xe:o,wo:h,Fn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.er(n,t,i);else{let n=e.tr(a,t,i);X(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ft(),a:i,i:14,o:mt(e,a,n),xe:o};if("command"===s[0]&&s.length>1)return a.startsWith(pt)||b(1201,[t.$e,a]),{...ft(),a:i,i:12,name:s.slice(1).join("."),Pt:a,xe:o};let u=mt(e,a,n),f={...ft(),a:i,i:1,name:t.$e,o:u,x:Ne(t.et),D:Ne(t.D),ro:r.ro,U:r.U,G:r.G};if("radio"===t.b||"checkbox"===t.b)return("element"===r.U||"auto"===r.U)&&b(37,[t.b,r.U]),f.i="radio"===t.b?9:10,r.ro||(f.Ft=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.$e?(f.i=8,f):(f.name="text"===t.$e?"textContent":t.$e,f.xe=o&&!Ce(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.Ft=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].yo=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var wt=/\{\{([\s\S]+?)\}\}/g;function bt(e){let t=e.data,n=[],l=0;wt.lastIndex=0;for(let i=wt.exec(t);null!==i;i=wt.exec(t)){let r=wt.lastIndex-i[0].length;r>l&&e.before(t.slice(l,r));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({a:o,cr:i[1].trim()}),l=wt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function kt(e,t,n,l){let i=function(e){return{$e:"textContent",Ne:["textContent"],rn:[],D:[],...U(e),b:"text"}}(t);return{...ft(),a:l,i:0,o:mt(e,i.Ze,n),x:Ne(i.et),q:""}}function St(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var xt=(e,t)=>0===e?le.commentIfPrefix:null===t.o?le.commentElsePrefix:le.commentElseIfPrefix;function At(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:mt(e,l.Ze,n),x:"else"===l.b?null:Ne(l.et)}),i=[l(t,St(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=St(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(l(e,t)),"else"===t.b))break}return i}var Nt=new WeakSet;function jt(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.Dn?.(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(ct()+"-ignore"))continue;if(l){if("script"===s||"style"===s||Nt.has(t))continue;if(Nt.add(t),s===le.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?St(t):null;if(null!==f){if("for"===f.b){let l=mt(e,f.Ze,n),r=Mt(e,t,l,!0);i(a(t,le.commentForPrefix),l,r)}else"if"===f.b?r(At(e,t,n).map((t,l)=>({C:Mt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,xt(l,t))}))):$t(f.b);continue}let d=t.getAttribute(ct()),p=null===d?null:vt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(yt)&&!c.$o?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.Wt&&h.data.includes("{{")&&!Nt.has(h))for(let{a:e,cr:t}of bt(h))s(e,t);else if(8===h.nodeType){let e=Ot.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),s(t,e[1])}}}};u(t)}var Ot=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Ct=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Mt(e,t,n,l){let i=document.importNode(Ct(t),!0),r=[],o=[],s=e=>r.push(e)-1;jt(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ft(),a:s(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({a:s(e.S),C:e.C,o:e.o,x:e.x}));o.push({...ft(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)gt(e)&&b(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,l)=>{o.push(kt(e,l,n,s(t)))}),Wt(i,new Set(r),!0);let a=r.map(e=>function(e,t){let n=[];for(let l=t;l!==e;l=l.parentNode){let e=0;for(let t=l.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of o){if(5===e.i&&e.nt&&!e.xe&&!Tt(r[e.a],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Pt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,Cn:a,build:g,Oe:d,sr:p,jn:u,lr:c,So:[],Xe:f}}function Tt(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function Pt(e){if(null!==e.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.Ft;default:return!1}}var Et=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Wt(e,t,n){for(let l=e.firstChild;null!==l;){let e=l.nextSibling;3===l.nodeType?n&&!t.has(l)&&""===l.data.trim()&&l.remove():1===l.nodeType&&Wt(l,t,Et.has(l.localName)),l=e}}var It=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),qt(e,[...n.childNodes]),e.ze()}function Dt(e,t,n){try{let l="template"===t.localName?St(t):null;null!==l&&!n&&b(204,[l.b]),qt(e,[t])}catch(e){console.error(e)}e.ze()}function qt(e,t){jt(e,t,null,!0,(t,n,l)=>{new st(e,l,Qe(e,n,null,t),t).Nt()},t=>{rt(e,t,null,null)},(t,n)=>{c.Dn?.(e,t,n);for(let l of n)it(e,l,t,null,null)},(t,n)=>{c.Dn?.(e,t,n),it(e,kt(e,n,null,0),t,null,null)})}var Lt=Symbol.for("wcstack.binder"),zt=Symbol.for("wcstack.binder.pending"),Ut=Symbol.for("wcstack.binder.taken");var Ft=new Map;function Bt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ft.set(e,t):Dt(n,e,t?.range)}function Vt(){let e=[...Ft];Ft.clear();for(let[t,n]of e)Bt(t,n);!function(){let e=function(){let e=globalThis[Lt];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[zt];return void 0===t&&(t=[],e[zt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Ut];return void 0===t&&(t=new WeakSet,e[Ut]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var _t=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.bt;if(null===i)return!1;let r=i[e.F];return r!==t&&r!==n&&(i[e.F]=n,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.$t(t,n),e.xn(t,n,this.Z)}Ho(e,t){let n=t.l.o.jt;if(null!==n)for(let l of n)l.n===t.l.n?e.st(l,t,this.Z):e.en(t,l,t=>e.st(l,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.$t(t,n),e.xn(t,n,this.Z)}Uo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.bt??=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.qo(i,null===s?null:r)}finally{null===s?i.Y=a:s[i.F]=a}}Xt(e){e.bt=null}tt(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.bt;null!==i&&i[t.F]===n&&(i[t.F]=l)}))}},Ht=0,Kt=new WeakMap;function Jt(e,t=e.getRootNode()){Kt.set(t,[...Kt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Gt(e){let t=Kt.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?Kt.get(e)!==t?Gt(e):Promise.reject(l.errors[0]):void 0)}var Xt=typeof HTMLElement>"u"?class{}:HTMLElement,Yt=class extends Xt{constructor(){super(),this.engine=null,this.Ln=!1,this.Ye=!1,this.q=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.No=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Gt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();Jt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!It.has(t)&&It.set(t,e),Vt(),c.element?.(e,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),t=c.ut?.(this,e);if(t)return this.Ge=t,!t.Ro&&this.parentNode instanceof ShadowRoot&&Jt(this),void(void 0===t.Mt?this.Po():t.Mt()).then(e=>(this.loaded=!0,t.start(e,()=>this.To()))).then(()=>{this.an(),this.cn()},e=>this.xt(e,t.Ro));this.start(e),Jt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let e=this.engine;if(null===e)return;let t=e.root;It.get(t)===e&&It.delete(t),Jt(this,t),this.xo("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ye&&b(14),this.loaded)this.Ge.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&b(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&b(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&&b(8),l(...e)):l},set(){b(8)}}))}async Po(){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] ${w(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||b(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//${++Ht}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?w(42):w(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.Po(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.q=n,this.Ln=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=It.get(e)?.element;i?.isConnected&&(i.V||i.Ge)&&b(47);let r=new ne(n,new _t);r.element=this,this.engine=r,c.element?.(r,"mounting"),Rt(r,e),Vt(),r.Nn(),this.To(),await r.Ee("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.cn()}catch(e){this.Ye=!this.V,this.xt(e)}}To(){this.V=!0,this.an()}xt(e,t){this.ze(this.V?50:49,e),this.an(),t?this.cn():this.No(e)}ze(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${w(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.ze(t,e))}},Qt=[];function Zt(){return(Qt=Qt.filter(e=>e.deref())).map(e=>e.deref())}var en,tn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},nn="en";function ln(){if(le.locale!==en){en=le.locale;try{nn=Intl.getCanonicalLocales(en)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[en])}`),nn="en"}}return nn}var rn=["full","long","medium","short"];function on(e,t){let[n,l]=e??[];return void 0===l&&void 0!==n&&rn.includes(n)&&([n,l]=[void 0,n]),void 0!==l&&!rn.includes(l)&&function(e,t){b(52,[e,t])}(t,l),[n,l]}var{eq:sn,ne:an,not:un,lt:cn,le:fn,gt:hn,ge:dn,falsy:pn,truthy:mn,boolean:gn}=Se,yn={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale",e),e.toLocaleString(t??ln()))},arity:[0,1]},upper:{factory:tn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:tn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:tn(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:tn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:tn(e=>{let t=[we(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:tn(e=>{let t=we(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:tn(e=>{let t=we(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:tn(e=>{let t=we(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:tn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:tn(e=>{let t=we(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)||b(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ge("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:tn(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=on(e,"date"),l=n&&{dateStyle:n};return e=>(e instanceof Date||ye("date",e),e.toLocaleDateString(t??ln(),l))},arity:[0,2]},time:{factory:e=>{let[t,n]=on(e,"time"),l=n&&{timeStyle:n};return e=>(e instanceof Date||ye("time",e),e.toLocaleTimeString(t??ln(),l))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=on(e,"datetime"),l=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||ye("datetime",e),e.toLocaleString(t??ln(),l))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("ymd",e);let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("hms",e);let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},eq:sn,ne:an,not:un,lt:cn,le:fn,gt:hn,ge:dn,add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=we(e,0,"clamp"),n=we(e,1,"clamp");return e=>("number"!=typeof e&&ge("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:pn,truthy:mn,defaults:{factory:(e,t)=>{let n=be(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=be(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:gn,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]??pe("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){b(53,[e])}(t)}return e=>("number"!=typeof e&&ge("currency",e),e.toLocaleString(n??ln(),l))},arity:[1,2]}},$n=!1,vn={name:"formats",install:function(){$n||($n=!0,he(yn))}};function wn(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 bn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=wn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var kn=" Validate statically: npx @wcstack/lint <file>.",Sn=["","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"],xn=e=>{let t=Sn[e/100|0];return t?`[wcs/${t}] `:""},An=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Nn=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)})`,jn=["","","class.","attr.","style."],On=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Cn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Mn={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?(jn[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 ${Cn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Cn}`,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 ${Nn(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 ${Nn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&An.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)=>`${On(e,t)} failed to initialize.`,50:(e,...t)=>`${On(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${On(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 Tn(e,t){let n=Mn[e];return void 0===n?`${xn(e)}#${e} ${t.join(" ")}`:xn(e)+n(...t)}var Pn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),En=[[/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.']],Wn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function In(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(Wn,e)?Wn[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?bn(t,n):"");for(let[t,n]of En){let i=t.exec(e);null!==i&&(l+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(l+=` — write "${i[1]}#${i[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?l+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':ue.some(de)||(l+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let r=/\[wcs\/([\w-]+)\]/.exec(e);return null!==r&&Pn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=kn),l}var Rn=new WeakMap,Dn=new WeakMap,qn=new WeakSet,Ln=new WeakSet;function zn(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 Un(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 Fn(e,t){let n=[];for(let e=t;null!==e;e=e.c)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!==zn(e.target,t.t)?.get?t:e.O.wt(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=zn(l,r.s);if(void 0===o&&null===r.c&&e.tt.has(r.s))return null;if(void 0===o){let o=Un(l),s=i(r.c);for(let t of e.O.all())t.c===s&&null!==t.getter&&o.push(t.s);return{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 Vn(e){qn.has(e)||(qn.add(e),setTimeout(()=>function(e){qn.delete(e);let t=Rn.get(e);if(void 0===t)return;let n=Dn.get(e);void 0===n&&Dn.set(e,n=new Set);let l=new Map(t),i=new Map;for(let r of e.O.all()){let e=null===r.c||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=Fn(e,t);if(null===l)continue;let s=[...e.root?.querySelectorAll(`${le.tagNames.state}[mount]`)??[]].find(e=>!Ln.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==s){n.delete(t),s.initializePromise.then(()=>{Ln.add(s),Vn(e)});continue}let a=e.O.wt(o(t.t).o),u="";if(void 0!==a&&a!==t&&null!==a.getter){let e=a.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(a.h[t].t.length+2)}`);u=` The getter "${a.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let f=bn(l.seg,l.names);if((l.r||3===r)&&""===f&&""===u)continue;let[h,d,p]=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.at?.(e,{type:"state:path-unresolved",source:p,path:t.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${h}] ${d} "${t.t}"${3===r?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${f}${u} ${2===r?"The call updates nothing.":3===r?"The getter reads undefined.":"Updates to this path will be silently dropped."}${kn}`)}}(e),0))}function _n(e,t,n=!1){Hn(e,t,n?1:0)}function Hn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let l=Rn.get(e);void 0===l&&Rn.set(e,l=new Map),l.has(t)||l.set(t,n),Vn(e)}var Kn=new WeakSet,Jn=!1,Gn=new WeakMap;function Xn(e,t){let n=Gn.get(e),l=t.s;if(null!==t.c||Jn||void 0===n||n.has(l)||"$"===l[0]||e.tt.has(l))return;let i=bn(l,[...n]);n.add(l),""!==i&&![...e.root?.querySelectorAll(`${le.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}${kn}`)}var Yn=new WeakSet;function Qn(e){if(Yn.has(e))return;Yn.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.${kn}`)),t.apply(e,l))}var Zn=new WeakMap;function el(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:zn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let i=Zn.get(e);void 0===i&&Zn.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(…).${kn}`))}function tl(e){Rn.has(e)&&e.He.length>0&&Vn(e)}var nl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ll=!1;function il(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(ll||!(t instanceof TypeError)||!Ce(l)||!("trustedTypes"in globalThis))return;ll=!0;let i="function"==typeof Oe()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${l}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${i}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:l})}var rl=new WeakMap;function ol(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=rl.get(e);void 0===r&&rl.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 sl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],al={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},ul={name:"diagnostics",install(){c.Bo=In,c.Mo=Tn,c.Eo=_n,c.detail=ol,c.Ye=f(c.Ye,il);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&b(1);for(let[t,n]of sl)void 0!==e[t]&&b(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=Un(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(`^(?:${nl(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(`^${nl(l)}(?:${nl(s)})*${nl(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){Dn.delete(e),Rn.has(e)&&Vn(e)}(t),function(e){if(Kn.has(e))return;Kn.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{Jn=!0;try{n(t)}finally{Jn=!1}let l=e.O.wt(o(t).o);void 0!==l&&Hn(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))Qn(t)}})}(t),Gn.set(t,new Set(Un(n)))},c.handlerThrew=el,c.re=f(c.re,Xn),c.me=f(c.me,tl),c.rt=h(p,c.rt,(e,t)=>Object.hasOwn(al,t)?b(1701,[t,al[t]]):void 0)}},cl={},fl=/\.\d/,hl=new Set(Object.getOwnPropertyNames(Object.prototype)),dl=0,pl=!1,ml=null,gl=()=>{pl=!1,dl++};function yl(){if(null===ml)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=gl,e.port1.unref?.(),ml=()=>e.port2.postMessage(0)}else ml=()=>setTimeout(gl,0);return pl||(pl=!0,ml()),dl}function $l(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 vl=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Fo=-1,this.Mn=new Set,this.qe=null,this.engine=e,this.je=t}ur(){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(cl,e.v(t.p,null)):this.Wn(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.dt(e,i,r,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&$l(wl(e.p),n)&&this.dt(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Oo(){this.active=!1,this.Fe.clear(),this.early=[]}Wn(e,t,n,l){let i=this.engine.Ue(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Wn(e,t+1,n,l)}dt(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.qe??=new Set).add(e);for(let r of this.je){let o=r.p;o.n!==e.n||!o.ee(e)||this.dt(r,t,r.getter?r.s.get(t??cl):o===e&&i&&this.engine._t&&(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.dt(n,t,n.s.get(t??cl),!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.dt(l,t,void 0,!0):this.Wn(i,e.n+1,t,e=>this.dt(l,e,void 0,!0)))}}}me(){let e=this.qe;if(this.qe=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)=>bl(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??cl,s),Object.is(s,r)&&(fl.test(i.t)||null!==t&&!u&&!(o??=null!==e&&$l(wl(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.d=t,c.at?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.H(t))}catch(e){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),c.at?.(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.Co(l)}Co(e){let t=yl();t!==this.Fo&&(this.Fo=t,this.Mn.clear());let n=e.filter(e=>!this.Mn.has(e));if(0!==n.length){for(let e of n)this.Mn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function wl(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function bl(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 kl="$streamStatus",Sl="$streamError",xl=new Set(Object.getOwnPropertyNames(Object.prototype)),Al=!1;function Nl(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 jl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Al=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Al=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.ft=!1,e.J?.abort(),e.J=null}pr(){for(let e of this.entries)e.ft=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(kl,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.ft?Math.max(n.n,t):t,n.ft=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.ft)continue;let r=i.n;if(i.ft=!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.Co(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();Ol(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===`${kl}.${e}`||n.t===`${Sl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Ol(r);for(let e of o)e._n(r);if(r.Y=l,t)throw n;return this.set(Sl,e.name,n),void this.set(kl,e.name,"error")}}let r=new AbortController;e.J=r,i.A(i.o(e.name),null,e.q),this.set(Sl,e.name,null),this.set(kl,e.name,"active"),this.mr(e,r,n)}async mr(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=yl(),u=e=>{yl()===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.Io?e.Io(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(kl,e.name,"done"))}catch(n){if(!r())return;e.J=null,t.abort(),u(()=>{this.set(Sl,e.name,n),this.set(kl,e.name,"error")})}}};function Ol(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.ht.delete(e)}e.Q.length=0,e.Y=t}var Cl=new WeakMap;function Ml(e){let t=Cl.get(e);return t?.target===e.target?t:void 0}function Tl(e,t){let n=new vl(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("@")||hl.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.Eo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new jl(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)||xl.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.`),Nl(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,Io:u,q:f,J:null,ft:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[kl]=i,t[Sl]=r,l}(e,t),n),i=Cl.get(e);void 0!==i&&(i.W.Oo(),i.Ct.fr()),Cl.set(e,{W:n,Ct:l,Je:i?.Je??!1,target:t})}function Pl(e,t){let n=Cl.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Je="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.Oo(),void n.Ct.pr();n.Je&&(n.W.ur(),n.Ct.dr())}}var El=["$streamStatus","$streamError"],Wl={name:"temporal",install(){c.fe=f(c.fe,Tl),c.element=f(c.element,Pl),c.re=f(c.re,(e,t,n,l,i,r,o)=>Ml(e)?.W.re(t,n,l,i,r,o)),c.Se=f(c.Se,(e,t,n)=>{let l=Ml(e);void 0!==l&&(l.W.Se(t,n),l.Ct.Se(t))}),c.Qt=f(c.Qt,(e,t,n)=>Ml(e)?.W.Qt(t,n)),c.me=f(c.me,e=>{let t=Ml(e);void 0!==t&&(t.W.me(),t.Ct.me())}),c.rt=h(p,c.rt,(e,t)=>{let n=t.split(".",1)[0];if(El.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=h(d,c.Ie,(e,t)=>(!Al&&36===t.t.charCodeAt(0)&&El.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Il=new WeakMap,Rl=!1,Dl=/^(?!prototype$)[^\d.*$][^.*]*$/;function ql(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.`)}}Il.set(t,l)}function Ll(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function zl(e,t,n){let l=new Map;for(let i of t){Ll(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 Ul(e,t,n,l){if(Rl||!Array.isArray(l))return!1;let i=Il.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.it(t,n);if(!Array.isArray(r)||r===l)return!1;let o=zl(t.t,r,i);zl(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){Rl=!0;try{e.A(t,n,s)}finally{Rl=!1}}if(c.length>0){let l=e.Ue(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=Dl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.A(s,o,r):(o.$[i]=r,e.A(e.o(`${t.t}.*`),o,o.$,!0))}}return!0}var Fl={name:"list-keys",install(){c.fe=f(c.fe,ql),c.Ie=h(d,c.Ie,Ul)}},Bl=new WeakMap,Vl=new WeakMap,_l="will not graft: the root state failed to initialize.",Hl=new WeakSet,Kl=new WeakMap,Jl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Gl=["$commandTokens","$eventTokens","$on","$errorCallback"],Xl=e=>`[@wcstack/state] <${le.tagNames.state} mount="${e}">`,Yl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Ql=e=>e?.element?.isConnected?e:void 0;function Zl(e){let t=Vl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ei(e,t){let n=Vl.get(t);if(Vl.delete(t),Array.isArray(n))for(let t of n)ii(t,e)}function ti(e){let t=Bl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ni(e,t){console.error(`${Xl(e.t)} ${t}`),ti(e),e.Qe?.(),e.Qe=null}function li(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function ii(e,t){if(Hl.has(t))return ni(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 ni(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)):Yl.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.it(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,s)}t.no(Object.defineProperties({},a));for(let e in a)t.qe(t.o(e),null);e.engine=t;let c=Kl.get(t);void 0===c&&Kl.set(t,c=[]),c.push(e),e.el.isConnected&&li(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function ri(e,t){let n=Vl.get(e);if(Array.isArray(n))for(let e of n)ni(e,_l);Vl.set(e,t)}var oi=new WeakMap;function si(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,Qe:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(le.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Bl.get(t);void 0===e&&Bl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Ql(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Vl.get(t);Array.isArray(e)&&Vl.set(t,e.filter(e=>e!==r)),r.Qe?.(),r.Qe=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ro:!0,start(e){if(null!==i)return ni(l,i);if(Bl.get(t).get(n)===l){for(let t of Jl)if(void 0!==e[t])return ni(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of Gl)void 0!==e[t]&&console.warn(`${Xl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Qe=e;let n=Ql(It.get(t)),i=Vl.get(t);void 0!==n?ii(l,n):Zl(t)?ni(l,_l):Vl.set(t,[...Array.isArray(i)?i:[],l])})}},Je(){null!==l.engine&&li(l,"$connectedCallback")},Bn(){null!==l.engine&&li(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 ai=new WeakMap,ui=new WeakMap;function ci(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 fi(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=ci(l,"$bindables"),o=ci(l,"$commands");for(let e of r){let t=i.get(e);void 0===t&&v(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&v(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of o){let t=i.get(e);void 0===t&&v(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&v(`$commands entry "${e}" is not a method: list it in $bindables.`)}let s={tag:e,bindables:r},a=new WeakMap,u=new WeakMap,c=l=>{if(a.has(l))return a.get(l);if(l.hasAttribute("data-wc-definition"))return null;let i=l.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(le.tagNames.state);return a.set(l,o),ai.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${le.tagNames.state}>: no change events.`),o},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,l]of t)n.proxy[e]=l});class d extends HTMLElement{static{this.wcBindable=0===r.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"function"==typeof t.value?Object.defineProperty(d.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(d.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,l,i,t)},Je(){},Bn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var hi=new WeakMap,di=new WeakSet,pi=new WeakMap,mi=new WeakMap,gi="data-wcs-wired",yi=new WeakMap,$i=new WeakMap,vi=new WeakMap,wi=0,bi=new Set,ki={},Si=["$watch","$stream","$renderedCallback"],xi=e=>e.split(".",1)[0];function Ai(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ni(e,t){let n=e.a,l=xi(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(gi);else if(!Oi(n,l)){let e=n.getAttribute(gi)?.split(" ")??[];e.includes(l)||n.setAttribute(gi,[...e,l].join(" "))}yi.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=hi.get(n);void 0===i&&hi.set(n,i=[]),i.push(e),t&&di.add(e);let r=pi.get(n);return void 0===r&&pi.set(n,r=new Map),r.has(l)||r.set(l,n[l]),mi.get(n)?.(),!1}function ji(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${le.tagNames.state}[bind-component]`)}function Oi(e,t){let n=e.getAttribute(le.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Ci(e){let t=e.parentElement;for(;null!==t&&!ji(t);)t=t.parentElement;let n=It.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Bt(e):Dt(n,e))}var Mi=new Set;function Ti(e,t){Mi.has(e)||(Mi.add(e),console.warn(`[@wcstack/state] ${t}`))}var Pi=(e,t)=>t in e.state;function Ei(e,t){let n=Wi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Wi(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function Ii(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=xi(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.c)return function(e,t){let n,l=t.c;for(;null!==l&&void 0===(n=e.pt.get(l));)l=l.c;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=Ri(e,s.r);return 0===t.n?n:(r.resolve(Ai(o.t,[...r.H(n),...i.H(ee(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();Di(e,s.e,()=>r.A(o,l,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.pt.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.E!==o?Pi(i,o):Ei(i,o))return;l=s.ye}else{if(null===t||null!==n.c||"$"===o[0]||Pi(i,o))return;s=t,l=r.o(`${t.ye.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,Ri(e,a)),n.se=t=>{Di(e,u,()=>r.A(l,a,t)),e.dn=n},e.pt.set(n,{e:s,p:l,r:a})}function Ri(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Di(e,t,n){let l=bi.has(e.R);bi.add(e.R),e.from=t;try{n()}finally{l||bi.delete(e.R),e.from=null}}var qi=(e,t)=>t||!bi.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Li(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,wi+=t?1:-1;let n=e.host.engine,l=vi.get(n);void 0===l&&vi.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.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=xi(o);if(o!==a&&!Pi(n,a))continue;let u=l.o(`${t.ye.t}.${o}`);if(null===u.getter)Fi(l,u,t.ye);else if(!zi.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&&Fi(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.c,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;Ti(`${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 zi=new WeakSet;function Ui(e,t,n,l){let i=vi.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.E||!0!==e.m.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 Fi(e,t,n){let l=t.c,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=Ui(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},zi.add(t.getter),t.se=o=>{let s=null===r()?Ui(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===Wi(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 Bi(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.$=n.l.P[n.y],e.T.Xt(n),null!==n.u)for(let t of n.u.values())e.G(t)}else e.$n(t,n);c.re?.(e,t,n,l,i,r),e.qe(t,n)}function Vi(e){let t=e.m.R;for(let[n,l]of e.m.pt)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 _i(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Vi(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=s.slice(1);let e=xi(a);if("$"===e[0]||Pi(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ee(l,e).y);c.resolve(Ai(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Bi(c,h,d,i,r,o)}function Hi(e,t,n,l,i,r,o){if(0===wi)return;let s=bi.has(e);bi.add(e);try{let s=$i.get(e);!o&&void 0!==s&&s.fn&&!bi.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.pt.get(s));)s=s.c;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(Ai(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Di(e,o.e,()=>Bi(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.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=vi.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:ee(n,e.n));if(void 0!==a)for(let s of[...a])qi(s,o)&&_i(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||ee(e,t.n)===n)for(let e of[...l])qi(e,o)&&Vi(e)}finally{s||bi.delete(e)}}async function Ki(e,t,n,l,i){if(l===ki)return;let r=y(l);r&&await r;let o=yi.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 <${le.tagNames.state} bind-component="${o.he}">.`),null!==s&&Li(s,!1),null!==s&&function(e,t,n){let l=e.R,i=`[${le.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,s=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.In(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.a);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.Wt&&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 Ji(e,l):l()}(s,e,n,i);let a=new ne(l,new _t);a.element=e,e.engine=a,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let l=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof l&&"constructor"!==t&&n.set(l,null)}let l=(t,n,l)=>Reflect.apply(t,e.proxy,l);e.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:[],pt: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,$i.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.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=xi(e.E);Pi(n,t)&&(e.E!==t||Ei(n,t))&&Ti(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.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.E===t)&&Ti(`${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=Si.filter(e=>void 0!==n.state[e]);o.length>0&&Ti(`${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.ot;t.ot=n=>{Ii(e,r,n),s.call(t,n)};let a=[...t.O.all()];for(let t of a)Ii(e,r,t);for(let e of a)s.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=$i.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Li(u,!0),Hl.add(a),ei(a,n));let h=c.hr?.(n,a);Rt(a,n),h?.(),u.L=[...n.childNodes],Vt(),f&&a.Nn(),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,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.Ee("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):Li(u,!1)}async function Ji(e,t){Li(e,!0);for(let t of e.pe)Vi(t);t?.(),!e.broken&&(await e.R.Ee("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function Gi(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){ri(t,e);for(let e of oi.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:yi.get(r)?.I;return t?.el===e?t:null},s=t=>{throw i&&ri(l,e),t},a=!1;return{Mt:()=>(null!==r&&r.localName.includes("-")?async function(e,t,n,l){let i=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&v(`<${le.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let r=yi.get(n);if(void 0!==r)return r.he!==t&&v(`<${i}> already has a <${le.tagNames.state} bind-component="${r.he}">.`),r.state;let o=()=>(hi.get(n)??[]).filter(e=>xi(e.name)===t),s=Oi(n,t);if(s&&0===o().length&&Ci(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(gi)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{mi.set(n,l),e=function(e,t){Zl(e)&&t();let n=oi.get(e)??new Set;return oi.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())}mi.delete(n);let a=o(),u=pi.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 (${le.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),ki}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===l)&&v(`<${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({E:l,ye:e.o,r:e.r,ro:di.has(e)}),e.engine.Rn(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 yi.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 <${le.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await Ki(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Je(){let t=o();null!==t?Ji(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===l)return Ki(e,r,i?l:r,yi.get(r).state,()=>{})}).catch(e=>console.error(e)):mi.has(r)&&Ci(r)},Bn(){let e=o();null!==e&&(Li(e,!1),!e.broken&&(e.R.Ee("$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 Xi={name:"scopes",install(){c.ut=h(m,c.ut,si),c.ut=h(m,c.ut,fi),c.ut=h(m,c.ut,Gi),c.ar=Ni,c.$o=ji,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Kl.get(e)??[];if("disconnected"===t)for(let e of n)ti(e);else if("reset"!==t&&Ql(It.get(e.root))===e){ei(e,e.root);for(let e of n)Bl.get(e.root).has(e.t)||Bl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ei(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:ai.get(n);void 0!==l&&ui.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=ui.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),Hi(e,t,n,l,i,r,!1)}),c.Se=f(c.Se,(e,t,n)=>Hi(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=Kl.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=$i.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.c)l=i.pt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.w)&&!r.ro)&&(!!n||(Ri(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===r.E?"":`.${r.E}`}#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=Kl.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=vi.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)}}},Yi="$recursion",Qi=new WeakMap,Zi=new WeakSet,er=new WeakSet,tr=0,nr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),lr=e=>`[wcs/recursion-${e}]`;function ir(e,t){let n=n=>v(`${lr("declaration-invalid")} ${Yi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${lr("declaration-invalid")} ${Yi} ${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 rr=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function or(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 sr(e,t,n){let l=or(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.`),rr(e,i.k)+l}function ar(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${lr("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${lr("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(`${lr("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(`${rr(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.Ue(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.Ue(null,s).f,0))}function ur(e,t){let n=function(e){let t=e[Yi],n=[],l=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!l.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),l.add(e);if(void 0===t)return n.length>0&&z(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${lr("declaration-invalid")} ${Yi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${lr("declaration-invalid")} ${Yi} must declare exactly one anchor (it declares ${i.length}).`);let r=ir("anchor",i[0][0]),o=ir("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(`${lr("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${nr(r)}((?:${nr(u)})*)${nr(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${nr(s)}((?:${nr(`.*.${a}`)})*)$`)}}(t),l=Qi.has(e);null!==n?(l||tr++,Qi.set(e,n),er.add(e),Zi.has(e)||function(e){Zi.add(e);let t=e,n=t.ot;t.ot=l=>{let i=Qi.get(e);if(l.t.includes("**")){let t=e.O.wt(l.t)===l;return void(er.has(e)||void 0===i&&t?l.getter=()=>z(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.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=Qi.get(e);return l.call(e,void 0!==i&&t.includes("**")?sr(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=Qi.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,sr(r,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${lr("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=or(r,n),s=[];return ar(e,r,(t,n)=>{for(let l of i.call(e,rr(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.wn;t.wn=(n,l,i,o)=>{let s=Qi.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||b(9,[n]),l.length>0&&v(`${lr("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${lr("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&b(8);let a=or(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(`${lr("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(`${lr("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];ar(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,rr(s,t)+a,e.H(n),i);return h}}(e)):l&&(Qi.delete(e),tr--)}function cr(e,t){if(0===tr)return!1;let n=Qi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let l=n.owners.get(e);void 0!==l&&v(`${lr("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var fr={name:"recursion",install(){c.fe=f(c.fe,ur),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){er.delete(e)}(e)}),c.Ie=h(d,c.Ie,cr)}},hr="4.6.0",dr=e=>e.split(".").slice(0,2).join("."),pr=class extends Xt{static find(e){return e.querySelector?.(le.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return dr(this.version)===dr(hr)}};function mr(e){let t=le.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends pr{})}var gr=()=>le.tagNames.ssr,yr=Symbol.for("wcstack.ssr.snapshotBuilder"),$r=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),vr=e=>document.createComment(e),wr=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,br=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),kr=new WeakMap,Sr=new WeakMap,xr=new WeakMap,Ar=new WeakSet,Nr=new WeakMap;function jr(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Or(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 Cr=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Mr(e,t,n,l){let i=vr(null===l?"wcs-[":`wcs-[:${l}`),r=vr("wcs-]");n.length>0&&n[0].Re().before(...jr(e,t)),t.after(i);for(let e of n)null===l&&e.Re().before(vr("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ct:e.L[e.L.length-1])(n[n.length-1]):i;(Cr(o)??o).after(r);for(let e of jr(i,r))Ar.add(e)}function Tr(e){if(e instanceof st){Mr(e.S,e.S,e.Ae,null);for(let t of e.Ae)Pr(t);return}let t=e.I;null!==t&&(Mr(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Pr(t))}function Pr(e){if(null!==e.u)for(let t of e.u)Tr(t)}var Er=new Set(["script","style","template","textarea","title"]),Wr="data-wcs-raw",Ir=e=>Er.has(e.localName)||e.localName===gr();function Rr(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(vr("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(vr("wcs-s")):1===t.nodeType&&!Ir(t)&&Rr(t)}var Dr=0;function qr(e,t){let n=e.getRootNode(),l=[t];for(let e of Sr.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=kr.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),Tr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=xr.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ar.has(e)||1===e.nodeType&&t.has(e)&&Br(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Ir(e.parentNode)?Nr.has(e):t.has(n)&&br(n,"wcs-t:"))&&(Nr.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);Ir(e)&&n.some(e=>Nr.has(e))&&e.setAttribute(Wr,n.map(e=>Nr.has(e)?`{{ ${Nr.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Rr(9===n.nodeType?n.body:n);let r=document.createElement(gr());r.setAttribute("version",hr);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"}${Dr++}`;e.replaceWith(vr(`wcs-p:${i}`));let o=document.importNode(Ct(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Or(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(Or(t,s,o))}e.before(r)}function Lr(e){!function(e){if(null!==e.querySelector(le.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Nr.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${le.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===gr())continue;let e=t.engine;null!=e&&qr(t,e)}}var zr=Symbol.for("wcstack.state.ssr.impl"),Ur=new Map,Fr=new WeakMap,Br=e=>!0===c.$o?.(e),Vr=e=>1===e.nodeType&&!Ir(e)&&!Br(e),_r=e=>e.f.flat().concat(e.z??[]),Hr=e=>{for(let t of _r(e))t.remove()};function Kr(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&&!wr(s,"wcs-]");){let e=s.nextSibling;if(wr(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];br(s,"wcs-[")?e=Kr(s,t,n):(n.push(s),Vr(s)&&Jr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,z:s??r.appendChild(vr("wcs-]"))},u=_r(a);s=a.z.nextSibling;for(let e of u)n?.push(e),t&&Nt.add(e);return t&&null!==i?Ur.set(i,a):Hr(a),s}function Jr(e,t){for(let n=e.firstChild;null!==n;)br(n,"wcs-[")?n=Kr(n,t):(Vr(n)&&Jr(n,t),n=n.nextSibling)}function Gr(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=vr(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!wr(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]?Or(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&&!Ir(i)&&(Br(i)?Fr.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||lo(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{br(e,"wcs-[")?l++:wr(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(br(l,"wcs-["))i++;else if(wr(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Jr(e,n)}function Xr(e,t){let n=Fr.get(e);if(void 0===n)return null;Fr.delete(e);let l=e=>Gr(e,n.ssr,n.Te);if(n.Te||eo(t,e,e,l),l(e),!n.Te)return null;let i=c.Te;return c.Te=oo,()=>{c.Te=i,Yr()}}function Yr(){for(let e of Ur.values())Hr(e);Ur.clear()}function Qr(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Zr(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 eo(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=()=>{};jt(e,[...i.childNodes],null,!0,r,r,r,(t,n)=>kt(e,n,null,0))}function to(e,t,n){if($r()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Ar.add(e);else if(e.localName.includes("-")&&!Br(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);xr.set(e,t)}return}if("string"==typeof n){if(Nr.set(t,n),Ir(t.parentNode))return;let e=vr(`wcs-t:${encodeURIComponent(n)}`),l=vr("wcs-/t");return t.before(e),void t.after(l)}let l=kr.get(e);void 0===l&&kr.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Sr.get(i);return void 0===r&&Sr.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&Ur.size>0){let e=Ur.get(n);void 0!==e&&(Ur.delete(n),Ur.set(t,e))}}var no=e=>null!==e&&8===e.nodeType&&[le.commentIfPrefix,le.commentElseIfPrefix,le.commentElsePrefix].includes(e.data),lo=e=>3===e.nodeType&&""===e.data.trim(),io=e=>{let t=Ur.get(e)?.z??e;return(Cr(t)??t).nextSibling};function ro(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.Cn;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=(Cr(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=io(o)}e.So[l]=o}return!0}function oo(e,t,n){if(0===Ur.size)return null;let l=t,i=0;if(!n){let e=le.commentIfPrefix;if(!wr(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(no(n)&&i++,!wr(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ur.has(l)&&null!==n&&!wr(n,e)&&1!==n.nodeType;n=n.nextSibling)no(n)&&(l=n)}let r=Ur.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Ur.delete(l),Hr(r),null;let o=r.f.shift();if(0===r.f.length&&Ur.delete(l),r.z?.replaceWith(...jr(t,l)),r.z=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Ur.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else Cr(o[e])===o[e+1]&&e++}if(!ro(e,s)){let n=(e.jn?e.root:e.ln).cloneNode(!0);s=e.jn?[n]:[...n.childNodes],ro(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 so={name:"ssr",install(){c.Dn=to,c.hr=Xr;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||$r())return;let n=t.previousElementSibling,l=n?.localName===gr(),i=l?n.getAttribute("version"):null,r=null===i||dr(i)===dr(hr);if(r){let t=e,n=t.Ee;t.Ee=(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] <${gr()} version="${i}"> does not match ${hr}: 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(`[${Wr}]`)))e.textContent=e.getAttribute(Wr),e.removeAttribute(Wr);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&&!Br(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=i(t),r=t.querySelector(`:scope > ${le.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ae(t.getAttribute(le.bindAttributeName)??"")){let t=l.Ze;l.Ne[0]===r&&n.push([e?Zr(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:Zr(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]:Zr(l,r[2],2,1)??r[2]};for(let t of Qr(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!wr(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]?[vr(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of Qr(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let s=document.importNode(i,!0),a=le.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,n,a):Gr(e,n,r);r||eo(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=oo,queueMicrotask(()=>{Yr(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[zr]={build:Lr,reset(){Dr=0}},void 0===e[yr]&&(e[yr]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[zr].build(t),reset:()=>e[zr].reset()})}(),c.Ao=f(c.Ao,mr);for(let e of Zt())mr(e)}},ao="__WCSTACK_DEVTOOLS_HOOK__",uo=null,co=new Set,fo=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),ho=new WeakMap,po=0;var mo=new WeakMap;function go(e){if(null===uo)return;let t=mo.get(e),n=co.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=ho.get(e);return void 0===t&&ho.set(e,t=++po),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:fo(e,o,c)})},r=e=>i(e.i,e.name,e.a,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 Ye&&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 st){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)||uo({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&uo({type:"state:binding-added",...l});mo.set(e,n)}function yo(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function $o(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 vo=new WeakSet,wo=new WeakMap;function bo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(vo.has(t))return;vo.add(t);let l=t.emit;t.emit=(...i)=>(null!==uo&&uo({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(co.has(e))return;co.add(e),uo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),go(e)}else"disconnected"===t&&(co.delete(e),go(e),uo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function ko(e,t,n,l,i,r){if(null===uo)return;let o=fo(e,t,0===t.n?null:n),s=wo.get(e);void 0===s&&wo.set(e,s=new Set),s.add(o),r&&uo({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function So(e){if(null===uo)return;let t=wo.get(e);wo.delete(e),void 0!==t&&uo({type:"state:update-batch",addresses:t}),go(e)}function xo(e,t,n){uo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Ao={"*":["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 No(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Ao["*"],...Object.hasOwn(Ao,e)?Ao[e]:[]])(n);return l.includes(t)||b(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)g.has(t.name)||(g.add(t.name),t.install())}([vn,ul,Wl,Fl,Xi,fr,so,{name:"devtools",install(){c.element=f(c.element,bo),c.re=f(c.re,ko),c.me=f(c.me,So),c.Ye=f(c.Ye,xo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[ao]??(e[ao]=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:hr,getStateElements:()=>[...co].map($o),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}(yo(e)),keys(e){let t=yo(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 yo(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){yo(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===uo&&null!==e;uo=e,null===e&&(mo=new WeakMap),c.at=e&&((e,t)=>uo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of co)go(e)})}})}()}},{name:"native-commands",install(){c.or=No}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Lt]&&(e[Lt]={protocol:"wcs-binder",version:1,bind:Bt})})(),Zt().includes(e)||Qt.push(new WeakRef(e));let t=le.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Yt{}),c.Ao?.(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.mt=null,this.F=-1,this.Y=t,this.De=null,this.It=null,this.jt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=e,this.c=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}_n(e){this.ht.has(e)||(this.ht.add(e),this.B.push(e),e.Q.push(this))}jo(e){this.ht.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Do(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.De=null,this.It=null,this.jt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.c}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.yt=new Map,this.Vn=e}wt(e){return this.yt.get(e)}get(t){let n=this.yt.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.Vn?.(n),this.yt.set(t,n),i&&i.u.push(n),n}all(){return this.yt.values()}Dt(e){this.yt.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.bt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.$=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Lt=!1,this.vt=!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.Mt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Mt(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.Bo?.(e,t,n)??""}`)}function w(e,t=[]){return c.Mo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function b(e,t,n,l){v(w(e,t),n,l)}var k=class{constructor(e){this.kt=new Set,this.name=e}get size(){return this.kt.size}subscribe(e){return this.kt.add(e),()=>{this.kt.delete(e)}}unsubscribe(e){return this.kt.delete(e)}emit(...e){let t=[];for(let n of this.kt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${w(17,[this.name])}`,e)}return t}};function S(e,t,n){if(void 0===e)return[];Array.isArray(e)||b(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&b(19,[t]),i===n&&b(20,[t,i,n]),l.has(i)&&b(21,[t,i]),l.add(i);return e}var x=Symbol.for("wcstack.transition-runner");function A(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function N(e,t,n){let l=A(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var j="else",O="eventToken",C="class",M="attr",T=/^\$[1-9]\d{0,2}$/,P=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function E(e){let t=[],n=[],l="",i=null,r=!1,o=-1,s=-1,a=e=>{let i=function(e,t,n){let l=-1===t?e.length:t,i=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,i+e.slice(i).trimEnd().length)}(l,o,s);(!e||i||r)&&(t.push(i),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:P.test(e)?Number(e):e)}(i,r))),l="",r=!1,o=-1,s=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=l.length),l+=n,s=l.length):'"'===n||"'"===n?(i=n,r=!0):","===n?a():l+=n}return null!==i&&b(107,[i,e]),a(!0),{args:t,literals:n}}var W=e=>e.trim();function I(e,t){let n=[],l=null;for(let i=0;i<e.length;i++){let r=e[i];null!==l?r===l&&(l=null):"'"===r||'"'===r?l=r:r===t&&n.push(i)}return n}var R=(e,t)=>I(e,t)[0]??-1;function D(e,t){let n=[],l=0;for(let i of I(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function q(e,t,n){let l=R(e,"|");if(-1===l)return[e.trim(),[]];let i=e.slice(l+1).trim(),r=n.get(i);return void 0===r&&(r=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>I(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&b(108,[e]),-1!==i&&-1===n&&b(109,[e]),-1!==i&&i<n&&b(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();b(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&b(112,[l]),r.includes("#")){let[,e]=r.split("#");b("input"===t?113:114,[r,e])}return-1===n?{Hn:r,args:[],literals:[]}:{Hn:r,...E(e.substring(n+1,i))}})}(D(i,"|").map(W),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var L=new Map;function z(e){b(1101,[e])}function U(e){let[t,n]=q(e,"output",L);t.includes("@")&&b(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)&&b(119,[e]),function(e){e.includes("**")&&z(e);let t=e.split(".").length;t>512&&b(117,[e,t])}(l),{Ze:l,et:n}}var F=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function V(e){return e.includes("**")&&z(e),e}var _=0;function H(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var K=()=>new Set,J=()=>[],G=new WeakMap;function X(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Y(e,t){return e===t||e!=e&&t!=t}function Q(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function te(e,t,n){let l=ee(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var ne=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.St=[],this.Me=null,this.qn=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.j=0,this.qt=0,this.yn=!1,this.Kt=!1,this.zt=!1,this.Ce=0,this.Kn=()=>{this.j=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.He=[],this.Xn={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=ee(this.d,t);null===n&&b(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.X;if(null!==i){let e=i.getter,n=l.De??(l.De=[]);if(!n.some(n=>n.getter===e&&n.Gn===t)){n.push({getter:e,Gn:t});let i=e.h[t];(i.It??(i.It=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,ee(this.d,n.n)))},$dependOn:e=>{this.resolve(V(e),this.d),null!==this.X&&0===this.X.be&&this.Jn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.wn(e,t,n,l),$resolve:(...e)=>{let t=V(e[0]),n=e[1]??[],l=this.o(t,!0);this.bn("$resolve",t,l,n,!0);let i=this.Qn(l,n,null);if(e.length<3)return this.read(l,i);this.A(l,i,e[2])},$postUpdate:e=>{this.resolve(V(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.P[n.y],G.delete(n.l.P),this.T.Xt(n)),this.vn(t,n),null!==n&&this.Zn(n,t,void 0,n.$,!1),0===t.n&&this.eo(t,void 0,void 0,!0),this.Gt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.He.push(e),this.ot(e)}),this.to(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.rt(t);if(t.indexOf(".")<0){let e=n.O.wt(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(V(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}no(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.ot(e)}ot(e){e.t.includes("**")&&z(e.t),("__proto__"===e.s||"prototype"===e.s)&&b(120,[e.t]);let t=e.c;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(T.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.c,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.c,this.d);null==i&&b(4,[t,i]),i[n]=l}}e.hn=!0,e.n>0&&(e.F=this.Le++)}Ue(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.G(l),l}oo(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}G(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.io(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].$===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].$===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.Bt(i[e]);else{let t=f<h?f:h;for(let e=c;e<=t;e++)i[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.$);void 0===l?r.set(n.$,n):Array.isArray(l)?l.push(n):r.set(n.$,[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.Bt(t);else n.Bt(e)}for(let e=c;e<r;e++){let t=a[e];t.y!==e&&(t.y=e,n.Lo(t))}return e.f=a,e.P=l,i}(e,t,this);if(null===n)return;if(e.P===t){let n=H(this.Ut,t,J);if(n.push(e),n.length>1)for(let e of n)e.vt=!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.It;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.kn(i,r),void 0!==o&&this.kn(i,o))}}Lo(e){this.T.Ho(this,e)}Bt(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.io(t);for(let e of t.f)this.Bt(e)}}io(e){let t=this.Ut.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.vt=!1,1===t.length&&(t[0].vt=!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?te(t,l,l.n):this.Qn(l,i,t,e)}Qn(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.Ue(i,a),f=t[s++];if(f<0)f=te(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}it(e,t){return 0===e.n?Z(this.target,e.z):null===t?void 0:Z(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Jn(e,t,n),null!==e.getter)return this.T.Uo(this,e,t);if(e.ae){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.tt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&b(301,[e.t],e.s,Object.keys(this.target)),this.it(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Jn(e,t,n){let l=n.getter;e._n(l),0===l.n?e.Z!==n.de&&(e.Z=n.de,n.Sn.push(e)):e.n>0&&ee(t,Math.min(e.n,l.n))!==ee(n.r,Math.min(e.n,l.n))&&(l.mt??(l.mt=new Set)).add(e)}qo(e,t){for(let n=0;n<this.Ht;n++){let l=this.qn[n];l.getter===e&&l.r===t&&b(701,[e.t])}this.Ht>=128&&b(801,[e.t]);let n=this.Ht++;this.Be++;let l=this.qn[n]??={getter:e,r:t,be:0,de:0,Sn:[]};l.getter=e,l.r=t,l.be=0,l.de=++_,l.Sn.length=0;let i=this.X;this.X=l;let r=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Ko(e,l),t}finally{this.Be--,this.Ht--,this.X=i,this.d=r,l.r=null}}Ko(e,t){let n=t.de;for(let e of t.Sn)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.it(t,null))||this.so(t,e))}so(e,t){return e.jo(t),this.He.push(e),!1}zo(){for(let e=this.He;e.length>0;e=this.He){this.He=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.c||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Dt(n),t.add(n.c);for(let e of n.Q)this.so(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.He.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.be){let n=t.getter,l=n.h[e];if(l){let e=l.jt??(l.jt=[]);e.includes(n)||e.push(n)}}}rt(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:T.test(e)?+e.slice(1):0;return(n<1||n>128)&&b(1001,[e]),this.watchIndex(n),ee(this.d,n)?.y}let n=this.Xn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.rt?.(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 Y(this.read(n,l),t);let i=this.X;return null!==i&&0===i.be&&this.Yo(n,t,i),Y(this.v(n,null),t)}Yo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Yn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(Y(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Q(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};H(e._??=new Map,t,K).add(o),r.push({source:e,key:t,sub:o,de:n.de})}eo(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=Z(t,o),a=Z(n,o);if(null!==i.De&&this.Xo(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&&b(8),i||this.Ce>0?this.Kt=!0:this.zt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.En(e.se,t,[n])}finally{this.Gt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&b(2,[e.t]),e.n>0&&null===t&&b(3,[e.t]);let r=e.ae?this.v(e,t):this.it(e,t);if(l||!this._t||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,G.delete(e.l.P),e.$=n,this.T.Xt(e)}else{let l=1===e.z.length?0===e.n?this.target:t.$:this.v(e.c,t);null==l&&b(4,[e.t,l]),l[e.s]=n}this.$n(e,t),null!==t&&this.Zn(t,e,r,n),0===e.n&&this.eo(e,r,n),this.Gt(e,t,r,n,!0,i)}}lo(e){return(this.Ut.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}Zn(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=G.get(e);if(void 0===t){let n=new Set;G.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.vt&&null===o.o.getter&&!o.o.B.length)return;let u=e.$,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(n.$=i,this.T.Xt(n)),r?this.$n(o,n):this.vn(o,n),this.Gt(o,n,l,i,r)};for(let t of this.lo(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.$===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.Ut.get(e)??[])for(let e of t.f)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.it(t,null);h(e)&&d(e,t.B)}};null!==o.o.getter?p(o.o):d(o.P,o.o.B)}vn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.vt?this.lo(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.$t(e,n),this.vn(e,n)}})}$n(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Xo(e,t,n,l){for(let{getter:i,Gn:r}of e.De)this.ao(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.kn(i,t)}})}kn(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Gt(e,t,n,l,i,r){c.re?.(this,e,t,n,l,i,r),this.qe(e,t)}qe(e,t){this.T.Jo(this,e,t),this.ve()}co(e){let t=this.nt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.nt.set(e,n);let l=this.root,i=this.Un;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.Qo(e,t))return}}),n}reset(e){let t=this.target,n=this.tt;for(let e of this.O.all())null===e.c&&null!==e.getter&&n.add(e.s);this.to(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.uo(e);this.Me=null;try{this.Yt()}finally{this.Nn()}c.element?.(this,"reset")}to(e){for(let[t,n]of F)void 0!==e[t]&&$(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||b(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&b(44,["state","$behavior"]);for(let e in n)(!B.includes(e)||"boolean"!=typeof n[e])&&b(44,["$behavior",e]);let[l,i,r]=B.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.Wt||i!==this._t||r!==this.Vt)&&b(45);let o=function(e,t){let n={};for(let l of S(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new k(l);return Object.freeze(n)}(e,this.commands),s=function(e,t){let n=new Map;for(let t of S(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&b(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&b(23,[e]),"function"!=typeof i&&b(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this._o);this.Wt=l,this._t=i,this.Vt=r,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Do();this.Yn.length=0,this.no(e),this.commands=o,this.Oe=s}uo(e){this.oo(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.bt=null,n._=null,this.$t(t,n),null!==n.u)for(let e of n.u.values())this.uo(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}Zo(e,t,n){let l=this.Oe.get(e);void 0===l&&b(1301,[e],e,this.Oe.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&b(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&b(5,[e]),this.En(l,n,[t,...this.H(n)])}En(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}$t(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.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.fo(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.fo(this,e)}}xn(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.st(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.mt&&r.mt.has(e))this.nn(r.h[r.n],e=>this.st(r,e,n));else if(r.n<=e.n){let e=ee(t,r.n);null!==e&&this.st(r,e,n)}else this.en(t,r,e=>this.st(r,e,n))}})}st(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.$t(e,t),this.xn(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.ao(e,e=>{for(let n of e.f)t(n)})}ao(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)}nr(e){let t=e.r;null===t?H(this.ue,e.o,K).add(e):(t.we??(t.we=[])).push(e)}Rn(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.Et||(this.Et=!0,queueMicrotask(this.Wo))}Pn(){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.Lt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${w(e)}`,n),c.at?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Pn()}Yt(){this.Et=!1;let e=this.qt;this.qt=0;let t=0;if(!this.Kt||this.zt?this.Kn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Kn,0),this.Kt=this.zt=!1,t>100)101===t?this.po(41,100):this.Pn();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.yn?this.Pn():this.po(11,32),this.yn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Lt=!1,this.oo(e)}let l=this._e,i=this.We;this._e=[],this.We=[];let r=()=>{for(let e of l){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.Nt()}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.Tn||n.Tn.w)&&this.Ke(n))}this.gn||(this.ze(),this.Et&&(this.qt=t+1))},o=l.length>0||i.some(e=>null!==e.j)?N("state",r):r();void 0!==o&&o.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.Kt=this.zt=!1,this.ze(),c.me?.(this),this.zo(),e>0&&this.Et&&(this.qt=t+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,l){this.xt(e,{o:{t},a:n,on:()=>l})}Ke(e){try{e.apply()}catch(t){return void this.St.push([t,e])}null!==this.Me&&this.mo(e.o,e.r)}mo(e,t){let n=H(this.Me,e.t,J);null!==t&&n.push(this.H(t))}Nn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}ze(){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.Ee("$renderedCallback",[n,l])}catch(e){console.error(e)}X(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.St.length)return;let t=this.St;this.St=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ye?.(this,e,l);let t=l.o.t,i=l.on();if("function"==typeof n)try{let n=this.Ee("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);X(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${w(12,l.name?[i,t,l.name,l.i]:[i,t])}`,e,l.a)}}Ee(e,t=[]){let n=this.target[e];return"function"==typeof n?this.En(n,null,t):void 0}ho(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.Ue(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.bn("$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=te(t,n,e);if(null===i)break;l.push(i.y)}0===l.length&&b(6,[e])}}let i=[];return this.ho(n,l,e=>i.push(this.read(n,e))),i}wn(e,t,n,l){Array.isArray(t)||b(9,[e]),this.Be>0&&b(8);let i=this.o(e,!0);this.bn("$setAll",e,i,t,!1);let r=[];this.ho(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&b(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}bn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&b(i?901:902,[e,t,n.n,r])}},le={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},ie=new Map,re=new Set(["if","elseif","else","for"]),oe=new Set([j,"if","elseif","for","..."]),se=new Set([C,M,"style","command",O,"state"]);function ae(e){let t=function(e){return D(e,";")}(e).map(W).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&b(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(oe.has(i)){let t;return i!==n&&b(102,[e,i]),i===j?(l.length>0&&b(103,[e]),t={Ze:"#else",et:[]}):"..."===i?(0===l.length&&b(104,[e]),t=U(l),t.et.length>0&&b(105,[e])):(t=U(l),"for"===i&&t.et.length>0&&b(121,[e])),{$e:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===C||i===M)&&b(122,[e,i]);let r=U(l),o=function(e){let[t,n]=q(e,"input",ie),l=t.split("#").map(W);l.length>2&&b(115,[t]);let[i,r]=l,o=i.split(".").map(W);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&b(116,[e]),{$e:i,Ne:o,rn:r?r.split(",").map(W):[],D:n}}(n),[s]=o.Ne;if(""===s&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||se.has(e[0]))&&b(106,[n]),{...o,$e:e.join("."),Ne:e,...r,b:"prop"}}return{...o,...r,b:"radio"===i||"checkbox"===i?i:s===O||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>re.has(e.b))&&b(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],ce=new Map,fe=new Map;function he(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});fe.clear()}function de(e){return ce.has(e)}function pe(e){b(26,[e])}function me(e){b(27,[e])}function ge(e,t){b(28,[e,t])}function ye(e,t){b(29,[e,t])}function $e(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return $e(e)||me(t),Number(e)}function we(e,t,n){return ve(e?.[t]??pe(n),n)}function be(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let l=we(n,0,e);return n=>("number"!=typeof n&&ge(e,n),t(n,l))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:($e(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:($e(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},xe=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ne(e){return 0===e.length?null:(xe||(xe=!0,he(Se)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=fe.get(l);if(typeof i<"u")return i;let r=ce.get(e);void 0===r&&function(e,t){ue.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),b(501,[e],e,t)}(e,ce.keys());let[o,s]=r.arity;t.length<o&&b(601,[e,o,t.length]),t.length>s&&b(602,[e,s,t.length]);let a=r.factory(t,n);return fe.set(l,a),a}(e.Hn,e.args,e.literals)))}var je=Symbol.for("wcstack.trustedTypes.policy");function Oe(){let e=globalThis[je];return null!==e&&"object"==typeof e?e:null}function Ce(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Me(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Oe(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Te=Symbol.for("wcstack.state.view-transition-naming"),Pe=new WeakSet;function Ee(){let e=A("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var We=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function Re(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Ie(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(We.has(e))return We.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new 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,go:"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 We.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.Rt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Fe(e,l,t,n)}e.ve()})}function De(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Vt;f&&null===a&&!u&&b(38,[l]);let h=t.U;(null===a?"element"===h||"auto"===h:!u&&("state"===h||"auto"===h))&&b(39,[h,l]),"connect"===t.G&&null===a&&b(40,[l]);let d=f&&null!==a&&!u,p=new _e(e,ze,n,l,i,r,o,t.x,void 0);p.D=t.D,Ze(e,p,!d),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.go||c.detail?.(n,l,i)),(!p.An||!Object.is(i,p.value))&&(i=Ae(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.go,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.Ke(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.Ke(p));let t=n[l];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.G||n.isConnected?i():Promise.resolve().then(i)}return p}function qe(e,t,n){b(e,[t.localName,n])}var Le=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),ze=11,Ue=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Pt,l,Ue[n.i]),Be=Symbol();function Ve(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:Be}var _e=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.D=null,this.An=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.Tn=o,this.x=s,this.value=a,this.j=u}on(){return Ue[this.i]}apply(){if(null!==this.j)return void this.j.Nt();let e=Ae(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===ze||8===this.i||Ce(this.name)))return;if(this.value===Be)return void(this.value=e);let t=this.a;if(this.i!==ze)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ke(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ae(this.D,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),i=n.v(this.o,this.r),r=Array.isArray(i)?i:[],o=r.includes(l);if(t.checked?o:!o)return;e=o?r.filter(e=>e!==l):[...r,l]}else e=Ae(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},He=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ke(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(He(n)?t[n]="innerHTML"===n?Me(l):null==l?"":String(l):Ce(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Me(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,l])));case 8:return void(t.innerHTML=Me(l));case 2:return null!=l&&"boolean"!=typeof l&&b(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 Je=Symbol();function Ge(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Xe=class{constructor(e,t,n,l){this.w=!0,this.we=null,this.u=null,this.Rt=null,this.On=null,this.r=e,this.ct=t,this.L=n,this.C=l}Qo(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.Cn[t.a],s=at(null===this.L?this.ct: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.Fn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ct:this.L[this.L.length-1]}Re(){let e=this.On;return(null===e?null:e.In(this.ct))??this.ct}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}}bo(){null===this.L?this.ct.remove():ut(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Rt)for(let e of this.Rt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Rn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Ye=class extends Xe{constructor(e,t,n,l){super(e,t,n,l),this.vo=0,this.V=null,this.pe=0===l.Xe.length?null:new Array(2*l.Xe.length)}ko(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 _e(e,i.i,r[2*t],i.name,i.o,this.r,this,i.x,r[2*t+1])}return l}fo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.ko(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=ee(n,t.n);try{return e.Ue(i,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===i?e.oe.get(t):i.u.get(t)}}function Ze(e,t,n){n&&e.nr(t);let l=t.Tn;null!==l&&(l.we??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function lt(e,t,n,l,i=null){let r,o=t.Cn,s=t.build,a=t.So,u=null,f=c.Te?.(t,null===l?i:l.S,null!==l),h=!f&&t.jn,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]=at(d,o[t],h?1:0)}h?r=d:(u=f||[...d.childNodes],r=u[0]);let p,m=null;if(null!==l?(p=m=new Ye(n,r,u,t),null===l.map?n.N=m:l.map.set(n,m)):p=new Xe(n,r,u,t),nt>=0&&function(e,t,n,l){let i=null;if(null===t)i=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===i;e++)1===t[e].nodeType&&(i=t[e]);let r=i?.style;if(null===i||void 0===r||Pe.has(i))return;let o=globalThis[Te]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${w(25,[l])}`)):(Pe.add(i),o.assigned++,r.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),r.setProperty("view-transition-class",`wcs-${n}`))}(r,u,null!==l?"row":"branch",nt),t.Oe.length>0){let t=e.Un;if(null===u)r[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.sr,y=e.Me,$=t.lr?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].a],v[2*t+1]=e[t].q}for(let t=0;t<g.length;t++){let l=g[t],i=$[l.a],o=l.F;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.Ke(t);continue}try{let t=Ae(l.x,e.read(l.o,n));t!==l.q&&(Ke(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.mo(l.o,n)}catch(t){e.xt(t,m.ko(e,o))}continue}switch(l.i){case 6:{let t=new st(e,l.C,Qe(e,l.o,n,i),i);(p.u??=[]).push(t),i===r&&(p.On=t),t.Nt();break}case 7:{let t=rt(e,l.K.map(e=>({C:e.C,o:e.o,x:e.x,S:$[e.a]})),n,p);(p.u??=[]).push(t),i===r&&(p.On=t);break}default:try{it(e,l,i,n,p)}catch(t){Fe(e,t,l,i)}}}return et=p,d}function it(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.Fn,o=e=>r(e,l);if(n.nt){let l=e.co(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.wo&&null!==i&&(i.Rt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.Pt.slice(9)),s=null===i?c.or?.(n,r):null;s||(null===i&&qe(1202,n,`command.${r}`),i.commands.has(r)||b(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.Rt??=[]).push(u)}(e,t,r,i,n));case 13:return void Re(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&qe(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&b(1204,[n.localName,r]);let s=t.Pt;n.addEventListener(o.event,n=>{t.Tt&&n.preventDefault(),t.At&&n.stopPropagation();try{e.Zo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=ee(l,o.n);if(14===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&qe(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.yo?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;De(e,{...t,U:null,G:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.xe&&1===t.i)return void Re(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void De(e,t,n,t.name,t.o,l,i,r);let o=new _e(e,1,n,t.name,t.o,l,i,t.x,Ve(e,t,l));o.D=t.D,!c.ar?.(o,t.ro)&&(Ze(e,o,!0),e.Ke(o))}(e,t,r,s,i,n));let a=new _e(e,t.i,n,t.name,o,s,i,t.x,Ve(e,t,s));a.D=t.D,Ze(e,a,!0),e.Ke(a),null!==t.Ft&&n.addEventListener(t.Ft,()=>a.ir())}function rt(e,t,n,l){let i=new ot(e,t,n),r=null;for(let o of t){if(null===o.o)continue;let t=o.o,s=new _e(e,7,o.S,"if",t,ee(n,t.n),l,null,void 0,i);Ze(e,s,!0),null===l&&i.ue.push(s),r??=s}return e.Ke(r),i}var ot=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}In(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}Nt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let l=this.K[n];if(null===l.o||Ae(l.x,e.read(l.o,ee(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(nt=Ee(),null!==this.I&&(this.I.bo(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],l=lt(e,n.C,this.r,null,n.S);this.I=tt();let i=n.S.parentNode;i.insertBefore(l,n.S),Ge(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Rn(e);null!==this.I&&this.I.Pe(this.engine)}},st=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)}In(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ot(e){return null===this.map?e.N:this.map.get(e)??null}Dt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}Nt(){let e=this.engine,t=this.l.f,n=this.Ae;nt=Ee();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):ut(e,t);for(let e=0;e<i;e++)this.Dt(n[e])}return void(this.Ae=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.Ot(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.Ot(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.Ot(l)===t?t.vo=e:(t.bo(),this.Dt(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.Ot(t[a+e]);null!==n&&n.w?(u[e]=n.vo,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.Ot(n);null!==u&&u.w?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(lt(e,this.C,n,this),i),u=tt()),s[a+r]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(lt(e,this.C,t[l],this)),s[l]=tt();o.insertBefore(n,h)}}this.Ae=s,Ge(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 at(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let l=t[n];l>0;l--)e=e.nextSibling}return e}function ut(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var ct=()=>le.bindAttributeName;function ft(){return{a:0,i:1,name:"",o:null,x:null,q:t,Fn:null,C:null,K:null,D:null,Ft:null,xe:!1,U:null,G:null,ro:!1,Tt:!1,At:!1,Pt:null,yo:null,F:-1,nt:!1,wo:!1}}var ht=["state","element","auto","none"],dt=["call","connect"],pt="$command.";function mt(e,t,n){T.test(t)&&(null===n&&b(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&&b(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&b(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&&b(1403,[l.t,l.h[e].t,t.t])}return c.Eo?.(e,l),l}var gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&He(e.name);function $t(e){b(202,[e])}function vt(e,t,n,l,i){let r=ae(t).map(t=>function(e,t,n,l,i){let r=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||b(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&b(33,[r,n]),null!==(s?l:i)&&b(34,[r]),(s?ht:dt).includes(o)||b(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),Tt:t.includes("prevent"),At:t.includes("stop"),event:n?n.slice(2):null,U:l,G:i}}(e,t.rn),o=l.localName.includes("-"),s=t.Ne,a=t.Ze;if("event"===t.b){if(null!==r.U&&"none"!==r.U&&b(36),"eventToken"===s[0])return{...ft(),a:i,i:13,name:s.slice(1).join("."),Pt:a,xe:o,Tt:r.Tt,At:r.At};let n=a.startsWith(pt)?a.slice(9):null,{Tt:l,At:u}=r,f=t.$e.slice(2),h=t.rn.includes("direct"),d=!h&&Le.has(f);d&&e.co(f);let p=t=>{console.error(t),d&&c.handlerThrew?.(e,a,f)};return{...ft(),a:i,i:5,name:f,nt:d,xe:o,wo:h,Fn(t,i){l&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.er(n,t,i);else{let n=e.tr(a,t,i);X(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ft(),a:i,i:14,o:mt(e,a,n),xe:o};if("command"===s[0]&&s.length>1)return a.startsWith(pt)||b(1201,[t.$e,a]),{...ft(),a:i,i:12,name:s.slice(1).join("."),Pt:a,xe:o};let u=mt(e,a,n),f={...ft(),a:i,i:1,name:t.$e,o:u,x:Ne(t.et),D:Ne(t.D),ro:r.ro,U:r.U,G:r.G};if("radio"===t.b||"checkbox"===t.b)return("element"===r.U||"auto"===r.U)&&b(37,[t.b,r.U]),f.i="radio"===t.b?9:10,r.ro||(f.Ft=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.$e?(f.i=8,f):(f.name="text"===t.$e?"textContent":t.$e,f.xe=o&&!Ce(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.Ft=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].yo=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var wt=/\{\{([\s\S]+?)\}\}/g;function bt(e){let t=e.data,n=[],l=0;wt.lastIndex=0;for(let i=wt.exec(t);null!==i;i=wt.exec(t)){let r=wt.lastIndex-i[0].length;r>l&&e.before(t.slice(l,r));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({a:o,cr:i[1].trim()}),l=wt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function kt(e,t,n,l){let i=function(e){return{$e:"textContent",Ne:["textContent"],rn:[],D:[],...U(e),b:"text"}}(t);return{...ft(),a:l,i:0,o:mt(e,i.Ze,n),x:Ne(i.et),q:""}}function St(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var xt=(e,t)=>0===e?le.commentIfPrefix:null===t.o?le.commentElsePrefix:le.commentElseIfPrefix;function At(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:mt(e,l.Ze,n),x:"else"===l.b?null:Ne(l.et)}),i=[l(t,St(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=St(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(l(e,t)),"else"===t.b))break}return i}var Nt=new WeakSet;function jt(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.Dn?.(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(ct()+"-ignore"))continue;if(l){if("script"===s||"style"===s||Nt.has(t))continue;if(Nt.add(t),s===le.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?St(t):null;if(null!==f){if("for"===f.b){let l=mt(e,f.Ze,n),r=Mt(e,t,l,!0);i(a(t,le.commentForPrefix),l,r)}else"if"===f.b?r(At(e,t,n).map((t,l)=>({C:Mt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,xt(l,t))}))):$t(f.b);continue}let d=t.getAttribute(ct()),p=null===d?null:vt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(yt)&&!c.$o?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.Wt&&h.data.includes("{{")&&!Nt.has(h))for(let{a:e,cr:t}of bt(h))s(e,t);else if(8===h.nodeType){let e=Ot.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),s(t,e[1])}}}};u(t)}var Ot=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Ct=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Mt(e,t,n,l){let i=document.importNode(Ct(t),!0),r=[],o=[],s=e=>r.push(e)-1;jt(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ft(),a:s(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({a:s(e.S),C:e.C,o:e.o,x:e.x}));o.push({...ft(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=s(e);for(let e of t)gt(e)&&b(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,l)=>{o.push(kt(e,l,n,s(t)))}),Wt(i,new Set(r),!0);let a=r.map(e=>function(e,t){let n=[];for(let l=t;l!==e;l=l.parentNode){let e=0;for(let t=l.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of o){if(5===e.i&&e.nt&&!e.xe&&!Tt(r[e.a],i)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Pt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.K)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,Cn:a,build:g,Oe:d,sr:p,jn:u,lr:c,So:[],Xe:f}}function Tt(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function Pt(e){if(null!==e.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.Ft;default:return!1}}var Et=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Wt(e,t,n){for(let l=e.firstChild;null!==l;){let e=l.nextSibling;3===l.nodeType?n&&!t.has(l)&&""===l.data.trim()&&l.remove():1===l.nodeType&&Wt(l,t,Et.has(l.localName)),l=e}}var It=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),qt(e,[...n.childNodes]),e.ze()}function Dt(e,t,n){try{let l="template"===t.localName?St(t):null;null!==l&&!n&&b(204,[l.b]),qt(e,[t])}catch(e){console.error(e)}e.ze()}function qt(e,t){jt(e,t,null,!0,(t,n,l)=>{new st(e,l,Qe(e,n,null,t),t).Nt()},t=>{rt(e,t,null,null)},(t,n)=>{c.Dn?.(e,t,n);for(let l of n)it(e,l,t,null,null)},(t,n)=>{c.Dn?.(e,t,n),it(e,kt(e,n,null,0),t,null,null)})}var Lt=Symbol.for("wcstack.binder"),zt=Symbol.for("wcstack.binder.pending"),Ut=Symbol.for("wcstack.binder.taken");var Ft=new Map;function Bt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ft.set(e,t):Dt(n,e,t?.range)}function Vt(){let e=[...Ft];Ft.clear();for(let[t,n]of e)Bt(t,n);!function(){let e=function(){let e=globalThis[Lt];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[zt];return void 0===t&&(t=[],e[zt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Ut];return void 0===t&&(t=new WeakSet,e[Ut]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var _t=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.bt;if(null===i)return!1;let r=i[e.F];return r!==t&&r!==n&&(i[e.F]=n,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.$t(t,n),e.xn(t,n,this.Z)}Ho(e,t){let n=t.l.o.jt;if(null!==n)for(let l of n)l.n===t.l.n?e.st(l,t,this.Z):e.en(t,l,t=>e.st(l,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.$t(t,n),e.xn(t,n,this.Z)}Uo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.bt??=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.qo(i,null===s?null:r)}finally{null===s?i.Y=a:s[i.F]=a}}Xt(e){e.bt=null}tt(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.bt;null!==i&&i[t.F]===n&&(i[t.F]=l)}))}},Ht=0,Kt=new WeakMap;function Jt(e,t=e.getRootNode()){Kt.set(t,[...Kt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Gt(e){let t=Kt.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?Kt.get(e)!==t?Gt(e):Promise.reject(l.errors[0]):void 0)}var Xt=typeof HTMLElement>"u"?class{}:HTMLElement,Yt=class extends Xt{constructor(){super(),this.engine=null,this.Ln=!1,this.Ye=!1,this.q=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.No=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Gt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();Jt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!It.has(t)&&It.set(t,e),Vt(),c.element?.(e,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),t=c.ut?.(this,e);if(t)return this.Ge=t,!t.Ro&&this.parentNode instanceof ShadowRoot&&Jt(this),void(void 0===t.Mt?this.Po():t.Mt()).then(e=>(this.loaded=!0,t.start(e,()=>this.To()))).then(()=>{this.an(),this.cn()},e=>this.xt(e,t.Ro));this.start(e),Jt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let e=this.engine;if(null===e)return;let t=e.root;It.get(t)===e&&It.delete(t),Jt(this,t),this.xo("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ye&&b(14),this.loaded)this.Ge.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&b(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&b(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&&b(8),l(...e)):l},set(){b(8)}}))}async Po(){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] ${w(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||b(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//${++Ht}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?w(42):w(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.Po(),l=y(n);if(l&&await l,this.getRootNode()!==e)return this.q=n,this.Ln=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&$("ssr","enable-ssr");let i=It.get(e)?.element;i?.isConnected&&(i.V||i.Ge)&&b(47);let r=new ne(n,new _t);r.element=this,this.engine=r,c.element?.(r,"mounting"),Rt(r,e),Vt(),r.Nn(),this.To(),await r.Ee("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.cn()}catch(e){this.Ye=!this.V,this.xt(e)}}To(){this.V=!0,this.an()}xt(e,t){this.ze(this.V?50:49,e),this.an(),t?this.cn():this.No(e)}ze(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${w(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.ze(t,e))}},Qt=[];function Zt(){return(Qt=Qt.filter(e=>e.deref())).map(e=>e.deref())}var en,tn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},nn="en";function ln(){if(le.locale!==en){en=le.locale;try{nn=Intl.getCanonicalLocales(en)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[en])}`),nn="en"}}return nn}var rn=["full","long","medium","short"];function on(e,t){let[n,l]=e??[];return void 0===l&&void 0!==n&&rn.includes(n)&&([n,l]=[void 0,n]),void 0!==l&&!rn.includes(l)&&function(e,t){b(52,[e,t])}(t,l),[n,l]}var{eq:sn,ne:an,not:un,lt:cn,le:fn,gt:hn,ge:dn,falsy:pn,truthy:mn,boolean:gn}=Se,yn={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale",e),e.toLocaleString(t??ln()))},arity:[0,1]},upper:{factory:tn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:tn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:tn(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:tn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:tn(e=>{let t=[we(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:tn(e=>{let t=we(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:tn(e=>{let t=we(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:tn(e=>{let t=we(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:tn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:tn(e=>{let t=we(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)||b(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ge("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:tn(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=on(e,"date"),l=n&&{dateStyle:n};return e=>(e instanceof Date||ye("date",e),e.toLocaleDateString(t??ln(),l))},arity:[0,2]},time:{factory:e=>{let[t,n]=on(e,"time"),l=n&&{timeStyle:n};return e=>(e instanceof Date||ye("time",e),e.toLocaleTimeString(t??ln(),l))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=on(e,"datetime"),l=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||ye("datetime",e),e.toLocaleString(t??ln(),l))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("ymd",e);let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("hms",e);let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},eq:sn,ne:an,not:un,lt:cn,le:fn,gt:hn,ge:dn,add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=we(e,0,"clamp"),n=we(e,1,"clamp");return e=>("number"!=typeof e&&ge("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:pn,truthy:mn,defaults:{factory:(e,t)=>{let n=be(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=be(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:gn,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]??pe("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){b(53,[e])}(t)}return e=>("number"!=typeof e&&ge("currency",e),e.toLocaleString(n??ln(),l))},arity:[1,2]}},$n=!1,vn={name:"formats",install:function(){$n||($n=!0,he(yn))}};function wn(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 bn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=wn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var kn=" Validate statically: npx @wcstack/lint <file>.",Sn=["","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"],xn=e=>{let t=Sn[e/100|0];return t?`[wcs/${t}] `:""},An=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Nn=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)})`,jn=["","","class.","attr.","style."],On=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Cn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Mn={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?(jn[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 ${Cn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Cn}`,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 ${Nn(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 ${Nn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&An.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)=>`${On(e,t)} failed to initialize.`,50:(e,...t)=>`${On(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${On(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 Tn(e,t){let n=Mn[e];return void 0===n?`${xn(e)}#${e} ${t.join(" ")}`:xn(e)+n(...t)}var Pn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),En=[[/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.']],Wn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function In(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(Wn,e)?Wn[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?bn(t,n):"");for(let[t,n]of En){let i=t.exec(e);null!==i&&(l+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(l+=` — write "${i[1]}#${i[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?l+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':ue.some(de)||(l+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let r=/\[wcs\/([\w-]+)\]/.exec(e);return null!==r&&Pn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=kn),l}var Rn=new WeakMap,Dn=new WeakMap,qn=new WeakSet,Ln=new WeakSet;function zn(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 Un(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 Fn(e,t){let n=[];for(let e=t;null!==e;e=e.c)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!==zn(e.target,t.t)?.get?t:e.O.wt(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=zn(l,r.s);if(void 0===o&&null===r.c&&e.tt.has(r.s))return null;if(void 0===o){let o=Un(l),s=i(r.c);for(let t of e.O.all())t.c===s&&null!==t.getter&&o.push(t.s);return{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 Vn(e){qn.has(e)||(qn.add(e),setTimeout(()=>function(e){qn.delete(e);let t=Rn.get(e);if(void 0===t)return;let n=Dn.get(e);void 0===n&&Dn.set(e,n=new Set);let l=new Map(t),i=new Map;for(let r of e.O.all()){let e=null===r.c||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=Fn(e,t);if(null===l)continue;let s=[...e.root?.querySelectorAll(`${le.tagNames.state}[mount]`)??[]].find(e=>!Ln.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==s){n.delete(t),s.initializePromise.then(()=>{Ln.add(s),Vn(e)});continue}let a=e.O.wt(o(t.t).o),u="";if(void 0!==a&&a!==t&&null!==a.getter){let e=a.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(a.h[t].t.length+2)}`);u=` The getter "${a.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let f=bn(l.seg,l.names);if((l.r||3===r)&&""===f&&""===u)continue;let[h,d,p]=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.at?.(e,{type:"state:path-unresolved",source:p,path:t.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${h}] ${d} "${t.t}"${3===r?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${f}${u} ${2===r?"The call updates nothing.":3===r?"The getter reads undefined.":"Updates to this path will be silently dropped."}${kn}`)}}(e),0))}function _n(e,t,n=!1){Hn(e,t,n?1:0)}function Hn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let l=Rn.get(e);void 0===l&&Rn.set(e,l=new Map),l.has(t)||l.set(t,n),Vn(e)}var Kn=new WeakSet,Jn=!1,Gn=new WeakMap;function Xn(e,t){let n=Gn.get(e),l=t.s;if(null!==t.c||Jn||void 0===n||n.has(l)||"$"===l[0]||e.tt.has(l))return;let i=bn(l,[...n]);n.add(l),""!==i&&![...e.root?.querySelectorAll(`${le.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}${kn}`)}var Yn=new WeakSet;function Qn(e){if(Yn.has(e))return;Yn.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.${kn}`)),t.apply(e,l))}var Zn=new WeakMap;function el(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:zn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let i=Zn.get(e);void 0===i&&Zn.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(…).${kn}`))}function tl(e){Rn.has(e)&&e.He.length>0&&Vn(e)}var nl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ll=!1;function il(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(ll||!(t instanceof TypeError)||!Ce(l)||!("trustedTypes"in globalThis))return;ll=!0;let i="function"==typeof Oe()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${l}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${i}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:l})}var rl=new WeakMap;function ol(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=rl.get(e);void 0===r&&rl.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 sl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],al={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},ul={name:"diagnostics",install(){c.Bo=In,c.Mo=Tn,c.Eo=_n,c.detail=ol,c.Ye=f(c.Ye,il);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&b(1);for(let[t,n]of sl)void 0!==e[t]&&b(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=Un(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(`^(?:${nl(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(`^${nl(l)}(?:${nl(s)})*${nl(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){Dn.delete(e),Rn.has(e)&&Vn(e)}(t),function(e){if(Kn.has(e))return;Kn.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{Jn=!0;try{n(t)}finally{Jn=!1}let l=e.O.wt(o(t).o);void 0!==l&&Hn(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))Qn(t)}})}(t),Gn.set(t,new Set(Un(n)))},c.handlerThrew=el,c.re=f(c.re,Xn),c.me=f(c.me,tl),c.rt=h(p,c.rt,(e,t)=>Object.hasOwn(al,t)?b(1701,[t,al[t]]):void 0)}},cl={},fl=/\.\d/,hl=new Set(Object.getOwnPropertyNames(Object.prototype)),dl=0,pl=!1,ml=null,gl=()=>{pl=!1,dl++};function yl(){if(null===ml)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=gl,e.port1.unref?.(),ml=()=>e.port2.postMessage(0)}else ml=()=>setTimeout(gl,0);return pl||(pl=!0,ml()),dl}function $l(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 vl=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Fo=-1,this.Mn=new Set,this.qe=null,this.engine=e,this.je=t}ur(){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(cl,e.v(t.p,null)):this.Wn(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.dt(e,i,r,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&$l(wl(e.p),n)&&this.dt(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Oo(){this.active=!1,this.Fe.clear(),this.early=[]}Wn(e,t,n,l){let i=this.engine.Ue(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Wn(e,t+1,n,l)}dt(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.qe??=new Set).add(e);for(let r of this.je){let o=r.p;o.n!==e.n||!o.ee(e)||this.dt(r,t,r.getter?r.s.get(t??cl):o===e&&i&&this.engine._t&&(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.dt(n,t,n.s.get(t??cl),!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.dt(l,t,void 0,!0):this.Wn(i,e.n+1,t,e=>this.dt(l,e,void 0,!0)))}}}me(){let e=this.qe;if(this.qe=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)=>bl(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??cl,s),Object.is(s,r)&&(fl.test(i.t)||null!==t&&!u&&!(o??=null!==e&&$l(wl(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.d=t,c.at?.(n,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(n.proxy,s,r,...n.H(t))}catch(e){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),c.at?.(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.Co(l)}Co(e){let t=yl();t!==this.Fo&&(this.Fo=t,this.Mn.clear());let n=e.filter(e=>!this.Mn.has(e));if(0!==n.length){for(let e of n)this.Mn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function wl(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function bl(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 kl="$streamStatus",Sl="$streamError",xl=new Set(Object.getOwnPropertyNames(Object.prototype)),Al=!1;function Nl(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 jl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Al=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Al=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.ft=!1,e.J?.abort(),e.J=null}pr(){for(let e of this.entries)e.ft=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(kl,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.ft?Math.max(n.n,t):t,n.ft=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.ft)continue;let r=i.n;if(i.ft=!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.Co(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();Ol(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===`${kl}.${e}`||n.t===`${Sl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Ol(r);for(let e of o)e._n(r);if(r.Y=l,t)throw n;return this.set(Sl,e.name,n),void this.set(kl,e.name,"error")}}let r=new AbortController;e.J=r,i.A(i.o(e.name),null,e.q),this.set(Sl,e.name,null),this.set(kl,e.name,"active"),this.mr(e,r,n)}async mr(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=yl(),u=e=>{yl()===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.Io?e.Io(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(kl,e.name,"done"))}catch(n){if(!r())return;e.J=null,t.abort(),u(()=>{this.set(Sl,e.name,n),this.set(kl,e.name,"error")})}}};function Ol(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.ht.delete(e)}e.Q.length=0,e.Y=t}var Cl=new WeakMap;function Ml(e){let t=Cl.get(e);return t?.target===e.target?t:void 0}function Tl(e,t){let n=new vl(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("@")||hl.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.Eo?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new jl(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)||xl.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.`),Nl(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,Io:u,q:f,J:null,ft:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[kl]=i,t[Sl]=r,l}(e,t),n),i=Cl.get(e);void 0!==i&&(i.W.Oo(),i.Ct.fr()),Cl.set(e,{W:n,Ct:l,Je:i?.Je??!1,target:t})}function Pl(e,t){let n=Cl.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Je="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.Oo(),void n.Ct.pr();n.Je&&(n.W.ur(),n.Ct.dr())}}var El=["$streamStatus","$streamError"],Wl={name:"temporal",install(){c.fe=f(c.fe,Tl),c.element=f(c.element,Pl),c.re=f(c.re,(e,t,n,l,i,r,o)=>Ml(e)?.W.re(t,n,l,i,r,o)),c.Se=f(c.Se,(e,t,n)=>{let l=Ml(e);void 0!==l&&(l.W.Se(t,n),l.Ct.Se(t))}),c.Qt=f(c.Qt,(e,t,n)=>Ml(e)?.W.Qt(t,n)),c.me=f(c.me,e=>{let t=Ml(e);void 0!==t&&(t.W.me(),t.Ct.me())}),c.rt=h(p,c.rt,(e,t)=>{let n=t.split(".",1)[0];if(El.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=h(d,c.Ie,(e,t)=>(!Al&&36===t.t.charCodeAt(0)&&El.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Il=new WeakMap,Rl=!1,Dl=/^(?!prototype$)[^\d.*$][^.*]*$/;function ql(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.`)}}Il.set(t,l)}function Ll(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function zl(e,t,n){let l=new Map;for(let i of t){Ll(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 Ul(e,t,n,l){if(Rl||!Array.isArray(l))return!1;let i=Il.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.it(t,n);if(!Array.isArray(r)||r===l)return!1;let o=zl(t.t,r,i);zl(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){Rl=!0;try{e.A(t,n,s)}finally{Rl=!1}}if(c.length>0){let l=e.Ue(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=Dl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.A(s,o,r):(o.$[i]=r,e.A(e.o(`${t.t}.*`),o,o.$,!0))}}return!0}var Fl={name:"list-keys",install(){c.fe=f(c.fe,ql),c.Ie=h(d,c.Ie,Ul)}},Bl=new WeakMap,Vl=new WeakMap,_l="will not graft: the root state failed to initialize.",Hl=new WeakSet,Kl=new WeakMap,Jl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Gl=["$commandTokens","$eventTokens","$on","$errorCallback"],Xl=e=>`[@wcstack/state] <${le.tagNames.state} mount="${e}">`,Yl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Ql=e=>e?.element?.isConnected?e:void 0;function Zl(e){let t=Vl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ei(e,t){let n=Vl.get(t);if(Vl.delete(t),Array.isArray(n))for(let t of n)ii(t,e)}function ti(e){let t=Bl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ni(e,t){console.error(`${Xl(e.t)} ${t}`),ti(e),e.Qe?.(),e.Qe=null}function li(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function ii(e,t){if(Hl.has(t))return ni(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 ni(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)):Yl.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.it(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,s)}t.no(Object.defineProperties({},a));for(let e in a)t.qe(t.o(e),null);e.engine=t;let c=Kl.get(t);void 0===c&&Kl.set(t,c=[]),c.push(e),e.el.isConnected&&li(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function ri(e,t){let n=Vl.get(e);if(Array.isArray(n))for(let e of n)ni(e,_l);Vl.set(e,t)}var oi=new WeakMap;function si(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,Qe:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(le.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Bl.get(t);void 0===e&&Bl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Ql(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Vl.get(t);Array.isArray(e)&&Vl.set(t,e.filter(e=>e!==r)),r.Qe?.(),r.Qe=null}e.set(n,l)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ro:!0,start(e){if(null!==i)return ni(l,i);if(Bl.get(t).get(n)===l){for(let t of Jl)if(void 0!==e[t])return ni(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of Gl)void 0!==e[t]&&console.warn(`${Xl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Qe=e;let n=Ql(It.get(t)),i=Vl.get(t);void 0!==n?ii(l,n):Zl(t)?ni(l,_l):Vl.set(t,[...Array.isArray(i)?i:[],l])})}},Je(){null!==l.engine&&li(l,"$connectedCallback")},Bn(){null!==l.engine&&li(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 ai=new WeakMap,ui=new WeakMap;function ci(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 fi(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=ci(l,"$bindables"),o=ci(l,"$commands");for(let e of r){let t=i.get(e);void 0===t&&v(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&v(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of o){let t=i.get(e);void 0===t&&v(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&v(`$commands entry "${e}" is not a method: list it in $bindables.`)}let s={tag:e,bindables:r},a=new WeakMap,u=new WeakMap,c=l=>{if(a.has(l))return a.get(l);if(l.hasAttribute("data-wc-definition"))return null;let i=l.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(le.tagNames.state);return a.set(l,o),ai.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${le.tagNames.state}>: no change events.`),o},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,l]of t)n.proxy[e]=l});class d extends HTMLElement{static{this.wcBindable=0===r.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:r.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:r.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"function"==typeof t.value?Object.defineProperty(d.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(d.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,l,i,t)},Je(){},Bn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var hi=new WeakMap,di=new WeakSet,pi=new WeakMap,mi=new WeakMap,gi="data-wcs-wired",yi=new WeakMap,$i=new WeakMap,vi=new WeakMap,wi=0,bi=new Set,ki={},Si=["$watch","$stream","$renderedCallback"],xi=e=>e.split(".",1)[0];function Ai(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ni(e,t){let n=e.a,l=xi(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(gi);else if(!Oi(n,l)){let e=n.getAttribute(gi)?.split(" ")??[];e.includes(l)||n.setAttribute(gi,[...e,l].join(" "))}yi.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=hi.get(n);void 0===i&&hi.set(n,i=[]),i.push(e),t&&di.add(e);let r=pi.get(n);return void 0===r&&pi.set(n,r=new Map),r.has(l)||r.set(l,n[l]),mi.get(n)?.(),!1}function ji(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${le.tagNames.state}[bind-component]`)}function Oi(e,t){let n=e.getAttribute(le.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Ci(e){let t=e.parentElement;for(;null!==t&&!ji(t);)t=t.parentElement;let n=It.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Bt(e):Dt(n,e))}var Mi=new Set;function Ti(e,t){Mi.has(e)||(Mi.add(e),console.warn(`[@wcstack/state] ${t}`))}var Pi=(e,t)=>t in e.state;function Ei(e,t){let n=Wi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Wi(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function Ii(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=xi(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.c)return function(e,t){let n,l=t.c;for(;null!==l&&void 0===(n=e.pt.get(l));)l=l.c;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=Ri(e,s.r);return 0===t.n?n:(r.resolve(Ai(o.t,[...r.H(n),...i.H(ee(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();Di(e,s.e,()=>r.A(o,l,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.pt.set(t,{e:s.e,p:o,r:s.r})}(e,n);if(0!==n.n)return;if(void 0!==s){if(s.E!==o?Pi(i,o):Ei(i,o))return;l=s.ye}else{if(null===t||null!==n.c||"$"===o[0]||Pi(i,o))return;s=t,l=r.o(`${t.ye.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,Ri(e,a)),n.se=t=>{Di(e,u,()=>r.A(l,a,t)),e.dn=n},e.pt.set(n,{e:s,p:l,r:a})}function Ri(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Di(e,t,n){let l=bi.has(e.R);bi.add(e.R),e.from=t;try{n()}finally{l||bi.delete(e.R),e.from=null}}var qi=(e,t)=>t||!bi.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Li(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,wi+=t?1:-1;let n=e.host.engine,l=vi.get(n);void 0===l&&vi.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.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=xi(o);if(o!==a&&!Pi(n,a))continue;let u=l.o(`${t.ye.t}.${o}`);if(null===u.getter)Fi(l,u,t.ye);else if(!zi.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&&Fi(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.c,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;Ti(`${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 zi=new WeakSet;function Ui(e,t,n,l){let i=vi.get(e)?.get(t)?.get(n);if(void 0===i)return null;let r=null;for(let e of i)""!==e.e.E||!0!==e.m.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 Fi(e,t,n){let l=t.c,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=Ui(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},zi.add(t.getter),t.se=o=>{let s=null===r()?Ui(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===Wi(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 Bi(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.$=n.l.P[n.y],e.T.Xt(n),null!==n.u)for(let t of n.u.values())e.G(t)}else e.$n(t,n);c.re?.(e,t,n,l,i,r),e.qe(t,n)}function Vi(e){let t=e.m.R;for(let[n,l]of e.m.pt)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 _i(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Vi(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=s.slice(1);let e=xi(a);if("$"===e[0]||Pi(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+s;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ee(l,e).y);c.resolve(Ai(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Bi(c,h,d,i,r,o)}function Hi(e,t,n,l,i,r,o){if(0===wi)return;let s=bi.has(e);bi.add(e);try{let s=$i.get(e);!o&&void 0!==s&&s.fn&&!bi.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.pt.get(s));)s=s.c;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(Ai(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||Di(e,o.e,()=>Bi(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.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=vi.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:ee(n,e.n));if(void 0!==a)for(let s of[...a])qi(s,o)&&_i(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||ee(e,t.n)===n)for(let e of[...l])qi(e,o)&&Vi(e)}finally{s||bi.delete(e)}}async function Ki(e,t,n,l,i){if(l===ki)return;let r=y(l);r&&await r;let o=yi.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 <${le.tagNames.state} bind-component="${o.he}">.`),null!==s&&Li(s,!1),null!==s&&function(e,t,n){let l=e.R,i=`[${le.bindAttributeName}]`,r=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,s=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.In(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.a);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.Wt&&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 Ji(e,l):l()}(s,e,n,i);let a=new ne(l,new _t);a.element=e,e.engine=a,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let l=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof l&&"constructor"!==t&&n.set(l,null)}let l=(t,n,l)=>Reflect.apply(t,e.proxy,l);e.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:[],pt: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,$i.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.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=xi(e.E);Pi(n,t)&&(e.E!==t||Ei(n,t))&&Ti(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.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.E===t)&&Ti(`${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=Si.filter(e=>void 0!==n.state[e]);o.length>0&&Ti(`${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.ot;t.ot=n=>{Ii(e,r,n),s.call(t,n)};let a=[...t.O.all()];for(let t of a)Ii(e,r,t);for(let e of a)s.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=$i.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Li(u,!0),Hl.add(a),ei(a,n));let h=c.hr?.(n,a);Rt(a,n),h?.(),u.L=[...n.childNodes],Vt(),f&&a.Nn(),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,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.Ee("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):Li(u,!1)}async function Ji(e,t){Li(e,!0);for(let t of e.pe)Vi(t);t?.(),!e.broken&&(await e.R.Ee("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function Gi(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){ri(t,e);for(let e of oi.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:yi.get(r)?.I;return t?.el===e?t:null},s=t=>{throw i&&ri(l,e),t},a=!1;return{Mt:()=>(null!==r&&r.localName.includes("-")?async function(e,t,n,l){let i=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&v(`<${le.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let r=yi.get(n);if(void 0!==r)return r.he!==t&&v(`<${i}> already has a <${le.tagNames.state} bind-component="${r.he}">.`),r.state;let o=()=>(hi.get(n)??[]).filter(e=>xi(e.name)===t),s=Oi(n,t);if(s&&0===o().length&&Ci(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(gi)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{mi.set(n,l),e=function(e,t){Zl(e)&&t();let n=oi.get(e)??new Set;return oi.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())}mi.delete(n);let a=o(),u=pi.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 (${le.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),ki}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===l)&&v(`<${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({E:l,ye:e.o,r:e.r,ro:di.has(e)}),e.engine.Rn(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 yi.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 <${le.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await Ki(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Je(){let t=o();null!==t?Ji(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===l)return Ki(e,r,i?l:r,yi.get(r).state,()=>{})}).catch(e=>console.error(e)):mi.has(r)&&Ci(r)},Bn(){let e=o();null!==e&&(Li(e,!1),!e.broken&&(e.R.Ee("$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 Xi={name:"scopes",install(){c.ut=h(m,c.ut,si),c.ut=h(m,c.ut,fi),c.ut=h(m,c.ut,Gi),c.ar=Ni,c.$o=ji,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Kl.get(e)??[];if("disconnected"===t)for(let e of n)ti(e);else if("reset"!==t&&Ql(It.get(e.root))===e){ei(e,e.root);for(let e of n)Bl.get(e.root).has(e.t)||Bl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ei(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:ai.get(n);void 0!==l&&ui.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=ui.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),Hi(e,t,n,l,i,r,!1)}),c.Se=f(c.Se,(e,t,n)=>Hi(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=Kl.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=$i.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.c)l=i.pt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.w)&&!r.ro)&&(!!n||(Ri(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===r.E?"":`.${r.E}`}#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=Kl.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=vi.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)}}},Yi="$recursion",Qi=new WeakMap,Zi=new WeakSet,er=new WeakSet,tr=0,nr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),lr=e=>`[wcs/recursion-${e}]`;function ir(e,t){let n=n=>v(`${lr("declaration-invalid")} ${Yi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${lr("declaration-invalid")} ${Yi} ${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 rr=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function or(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 sr(e,t,n){let l=or(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.`),rr(e,i.k)+l}function ar(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${lr("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${lr("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(`${lr("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(`${rr(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e.Ue(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.Ue(null,s).f,0))}function ur(e,t){let n=function(e){let t=e[Yi],n=[],l=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!l.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),l.add(e);if(void 0===t)return n.length>0&&z(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${lr("declaration-invalid")} ${Yi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${lr("declaration-invalid")} ${Yi} must declare exactly one anchor (it declares ${i.length}).`);let r=ir("anchor",i[0][0]),o=ir("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(`${lr("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${nr(r)}((?:${nr(u)})*)${nr(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${nr(s)}((?:${nr(`.*.${a}`)})*)$`)}}(t),l=Qi.has(e);null!==n?(l||tr++,Qi.set(e,n),er.add(e),Zi.has(e)||function(e){Zi.add(e);let t=e,n=t.ot;t.ot=l=>{let i=Qi.get(e);if(l.t.includes("**")){let t=e.O.wt(l.t)===l;return void(er.has(e)||void 0===i&&t?l.getter=()=>z(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.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=Qi.get(e);return l.call(e,void 0!==i&&t.includes("**")?sr(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=Qi.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,sr(r,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${lr("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=or(r,n),s=[];return ar(e,r,(t,n)=>{for(let l of i.call(e,rr(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.wn;t.wn=(n,l,i,o)=>{let s=Qi.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||b(9,[n]),l.length>0&&v(`${lr("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${lr("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&b(8);let a=or(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(`${lr("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(`${lr("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];ar(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,rr(s,t)+a,e.H(n),i);return h}}(e)):l&&(Qi.delete(e),tr--)}function cr(e,t){if(0===tr)return!1;let n=Qi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let l=n.owners.get(e);void 0!==l&&v(`${lr("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var fr={name:"recursion",install(){c.fe=f(c.fe,ur),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){er.delete(e)}(e)}),c.Ie=h(d,c.Ie,cr)}},hr="4.6.2",dr=e=>e.split(".").slice(0,2).join("."),pr=class extends Xt{static find(e){return e.querySelector?.(le.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return dr(this.version)===dr(hr)}};function mr(e){let t=le.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends pr{})}var gr=()=>le.tagNames.ssr,yr=Symbol.for("wcstack.ssr.snapshotBuilder"),$r=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),vr=e=>document.createComment(e),wr=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,br=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),kr=new WeakMap,Sr=new WeakMap,xr=new WeakMap,Ar=new WeakSet,Nr=new WeakMap;function jr(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Or(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 Cr=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Mr(e,t,n,l){let i=vr(null===l?"wcs-[":`wcs-[:${l}`),r=vr("wcs-]");n.length>0&&n[0].Re().before(...jr(e,t)),t.after(i);for(let e of n)null===l&&e.Re().before(vr("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ct:e.L[e.L.length-1])(n[n.length-1]):i;(Cr(o)??o).after(r);for(let e of jr(i,r))Ar.add(e)}function Tr(e){if(e instanceof st){Mr(e.S,e.S,e.Ae,null);for(let t of e.Ae)Pr(t);return}let t=e.I;null!==t&&(Mr(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Pr(t))}function Pr(e){if(null!==e.u)for(let t of e.u)Tr(t)}var Er=new Set(["script","style","template","textarea","title"]),Wr="data-wcs-raw",Ir=e=>Er.has(e.localName)||e.localName===gr();function Rr(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(vr("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(vr("wcs-s")):1===t.nodeType&&!Ir(t)&&Rr(t)}var Dr=0;function qr(e,t){let n=e.getRootNode(),l=[t];for(let e of Sr.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=kr.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),Tr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=xr.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ar.has(e)||1===e.nodeType&&t.has(e)&&Br(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Ir(e.parentNode)?Nr.has(e):t.has(n)&&br(n,"wcs-t:"))&&(Nr.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);Ir(e)&&n.some(e=>Nr.has(e))&&e.setAttribute(Wr,n.map(e=>Nr.has(e)?`{{ ${Nr.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Rr(9===n.nodeType?n.body:n);let r=document.createElement(gr());r.setAttribute("version",hr);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"}${Dr++}`;e.replaceWith(vr(`wcs-p:${i}`));let o=document.importNode(Ct(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Or(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(Or(t,s,o))}e.before(r)}function Lr(e){!function(e){if(null!==e.querySelector(le.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Nr.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${le.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===gr())continue;let e=t.engine;null!=e&&qr(t,e)}}var zr=Symbol.for("wcstack.state.ssr.impl"),Ur=new Map,Fr=new WeakMap,Br=e=>!0===c.$o?.(e),Vr=e=>1===e.nodeType&&!Ir(e)&&!Br(e),_r=e=>e.f.flat().concat(e.z??[]),Hr=e=>{for(let t of _r(e))t.remove()};function Kr(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&&!wr(s,"wcs-]");){let e=s.nextSibling;if(wr(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];br(s,"wcs-[")?e=Kr(s,t,n):(n.push(s),Vr(s)&&Jr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,z:s??r.appendChild(vr("wcs-]"))},u=_r(a);s=a.z.nextSibling;for(let e of u)n?.push(e),t&&Nt.add(e);return t&&null!==i?Ur.set(i,a):Hr(a),s}function Jr(e,t){for(let n=e.firstChild;null!==n;)br(n,"wcs-[")?n=Kr(n,t):(Vr(n)&&Jr(n,t),n=n.nextSibling)}function Gr(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=vr(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!wr(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]?Or(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&&!Ir(i)&&(Br(i)?Fr.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||lo(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{br(e,"wcs-[")?l++:wr(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(br(l,"wcs-["))i++;else if(wr(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Jr(e,n)}function Xr(e,t){let n=Fr.get(e);if(void 0===n)return null;Fr.delete(e);let l=e=>Gr(e,n.ssr,n.Te);if(n.Te||eo(t,e,e,l),l(e),!n.Te)return null;let i=c.Te;return c.Te=oo,()=>{c.Te=i,Yr()}}function Yr(){for(let e of Ur.values())Hr(e);Ur.clear()}function Qr(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Zr(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 eo(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=()=>{};jt(e,[...i.childNodes],null,!0,r,r,r,(t,n)=>kt(e,n,null,0))}function to(e,t,n){if($r()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Ar.add(e);else if(e.localName.includes("-")&&!Br(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);xr.set(e,t)}return}if("string"==typeof n){if(Nr.set(t,n),Ir(t.parentNode))return;let e=vr(`wcs-t:${encodeURIComponent(n)}`),l=vr("wcs-/t");return t.before(e),void t.after(l)}let l=kr.get(e);void 0===l&&kr.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=Sr.get(i);return void 0===r&&Sr.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&Ur.size>0){let e=Ur.get(n);void 0!==e&&(Ur.delete(n),Ur.set(t,e))}}var no=e=>null!==e&&8===e.nodeType&&[le.commentIfPrefix,le.commentElseIfPrefix,le.commentElsePrefix].includes(e.data),lo=e=>3===e.nodeType&&""===e.data.trim(),io=e=>{let t=Ur.get(e)?.z??e;return(Cr(t)??t).nextSibling};function ro(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.Cn;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=(Cr(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=io(o)}e.So[l]=o}return!0}function oo(e,t,n){if(0===Ur.size)return null;let l=t,i=0;if(!n){let e=le.commentIfPrefix;if(!wr(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(no(n)&&i++,!wr(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ur.has(l)&&null!==n&&!wr(n,e)&&1!==n.nodeType;n=n.nextSibling)no(n)&&(l=n)}let r=Ur.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Ur.delete(l),Hr(r),null;let o=r.f.shift();if(0===r.f.length&&Ur.delete(l),r.z?.replaceWith(...jr(t,l)),r.z=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Ur.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else Cr(o[e])===o[e+1]&&e++}if(!ro(e,s)){let n=(e.jn?e.root:e.ln).cloneNode(!0);s=e.jn?[n]:[...n.childNodes],ro(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 so={name:"ssr",install(){c.Dn=to,c.hr=Xr;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||$r())return;let n=t.previousElementSibling,l=n?.localName===gr(),i=l?n.getAttribute("version"):null,r=null===i||dr(i)===dr(hr);if(r){let t=e,n=t.Ee;t.Ee=(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] <${gr()} version="${i}"> does not match ${hr}: 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(`[${Wr}]`)))e.textContent=e.getAttribute(Wr),e.removeAttribute(Wr);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&&!Br(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=i(t),r=t.querySelector(`:scope > ${le.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of ae(t.getAttribute(le.bindAttributeName)??"")){let t=l.Ze;l.Ne[0]===r&&n.push([e?Zr(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:Zr(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]:Zr(l,r[2],2,1)??r[2]};for(let t of Qr(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!wr(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]?[vr(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of Qr(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let s=document.importNode(i,!0),a=le.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,n,a):Gr(e,n,r);r||eo(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=oo,queueMicrotask(()=>{Yr(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[zr]={build:Lr,reset(){Dr=0}},void 0===e[yr]&&(e[yr]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[zr].build(t),reset:()=>e[zr].reset()})}(),c.Ao=f(c.Ao,mr);for(let e of Zt())mr(e)}},ao="__WCSTACK_DEVTOOLS_HOOK__",uo=null,co=new Set,fo=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),ho=new WeakMap,po=0;var mo=new WeakMap;function go(e){if(null===uo)return;let t=mo.get(e),n=co.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=ho.get(e);return void 0===t&&ho.set(e,t=++po),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:fo(e,o,c)})},r=e=>i(e.i,e.name,e.a,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 Ye&&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 st){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)||uo({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&uo({type:"state:binding-added",...l});mo.set(e,n)}function yo(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function $o(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 vo=new WeakSet,wo=new WeakMap;function bo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(vo.has(t))return;vo.add(t);let l=t.emit;t.emit=(...i)=>(null!==uo&&uo({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(co.has(e))return;co.add(e),uo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),go(e)}else"disconnected"===t&&(co.delete(e),go(e),uo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function ko(e,t,n,l,i,r){if(null===uo)return;let o=fo(e,t,0===t.n?null:n),s=wo.get(e);void 0===s&&wo.set(e,s=new Set),s.add(o),r&&uo({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function So(e){if(null===uo)return;let t=wo.get(e);wo.delete(e),void 0!==t&&uo({type:"state:update-batch",addresses:t}),go(e)}function xo(e,t,n){uo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Ao={"*":["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 No(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Ao["*"],...Object.hasOwn(Ao,e)?Ao[e]:[]])(n);return l.includes(t)||b(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)g.has(t.name)||(g.add(t.name),t.install())}([vn,ul,Wl,Fl,Xi,fr,so,{name:"devtools",install(){c.element=f(c.element,bo),c.re=f(c.re,ko),c.me=f(c.me,So),c.Ye=f(c.Ye,xo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[ao]??(e[ao]=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:hr,getStateElements:()=>[...co].map($o),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}(yo(e)),keys(e){let t=yo(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 yo(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){yo(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===uo&&null!==e;uo=e,null===e&&(mo=new WeakMap),c.at=e&&((e,t)=>uo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of co)go(e)})}})}()}},{name:"native-commands",install(){c.or=No}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Lt]&&(e[Lt]={protocol:"wcs-binder",version:1,bind:Bt})})(),Zt().includes(e)||Qt.push(new WeakRef(e));let t=le.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Yt{}),c.Ao?.(e)}();
2
2
  //# sourceMappingURL=auto.min.js.map