@wcstack/state 4.0.0-rc.9 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +8 -6
- package/README.md +8 -6
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/parser.esm.js +4 -0
- package/dist/split/auto.js +1 -1
- package/dist/split/chunks/{chunk-M5SODAAE.js → chunk-6MACFEK7.js} +2 -2
- package/dist/split/chunks/chunk-BMGEWHCR.js +2 -0
- package/dist/split/chunks/chunk-BMGEWHCR.js.map +1 -0
- package/dist/split/chunks/{chunk-UD3AYVP2.js → chunk-DFXQ7MFW.js} +2 -2
- package/dist/split/chunks/{chunk-7AYOQHZH.js → chunk-EM3Y3SJS.js} +2 -2
- package/dist/split/chunks/chunk-LAUWEM6K.js +2 -0
- package/dist/split/chunks/chunk-LAUWEM6K.js.map +1 -0
- package/dist/split/chunks/{chunk-EIMTT5I3.js → chunk-M656SMUU.js} +1 -1
- package/dist/split/chunks/{chunk-EIMTT5I3.js.map → chunk-M656SMUU.js.map} +1 -1
- package/dist/split/chunks/{chunk-W4KOY6GT.js → chunk-PHAN6L23.js} +2 -2
- package/dist/split/chunks/{chunk-NOPTR2L3.js → chunk-TUQ3OPZQ.js} +2 -2
- package/dist/split/chunks/{chunk-55J45X6H.js → chunk-V6VVL4F3.js} +2 -2
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/diagnostics.js.map +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/native-commands.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/package.json +1 -1
- package/dist/split/chunks/chunk-L3PFEJP7.js +0 -2
- package/dist/split/chunks/chunk-L3PFEJP7.js.map +0 -1
- package/dist/split/chunks/chunk-SAUVGHSB.js +0 -2
- package/dist/split/chunks/chunk-SAUVGHSB.js.map +0 -1
- /package/dist/split/chunks/{chunk-M5SODAAE.js.map → chunk-6MACFEK7.js.map} +0 -0
- /package/dist/split/chunks/{chunk-UD3AYVP2.js.map → chunk-DFXQ7MFW.js.map} +0 -0
- /package/dist/split/chunks/{chunk-7AYOQHZH.js.map → chunk-EM3Y3SJS.js.map} +0 -0
- /package/dist/split/chunks/{chunk-W4KOY6GT.js.map → chunk-PHAN6L23.js.map} +0 -0
- /package/dist/split/chunks/{chunk-NOPTR2L3.js.map → chunk-TUQ3OPZQ.js.map} +0 -0
- /package/dist/split/chunks/{chunk-55J45X6H.js.map → chunk-V6VVL4F3.js.map} +0 -0
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class{constructor(e,n,l){this.c=[],this.getter=null,this.ie=null,this.se=!1,this.M=[],this.J=[],this.ft=null,this.A=-1,this.z=t,this.Ce=null,this.Ot=null,this.Ct=null,this._=null,this.pn=!1,this.mn=!1,this._n=!1,this.Z=0,this.pt=new Set,this.t=e,this.d=l,this.s=n;let i=null===l?[null]:l.h.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this.K=r?[]:null===l?[n]:[...l.K,n],this.h=i}Wn(e){this.pt.has(e)||(this.pt.add(e),this.M.push(e),e.J.push(this))}Io(e){this.pt.delete(e);let t=this.M;t.splice(t.indexOf(e),1)}jo(){this.getter=null,this.ie=null,this.A=-1,this.z=t,this.M.length=0,this.pt.clear(),this.J.length=0,this.ft=null,this.Ce=null,this.Ot=null,this.Ct=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.d}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.mt=new Map,this.Vn=e}It(e){return this.mt.get(e)}get(t){let n=this.mt.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.mt.set(t,n),i&&i.c.push(n),n}all(){return this.mt.values()}jt(e){this.mt.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.ht=null,this.$=null,this.he=null,this._=null,this.c=null,this.y=!0,this.l=e,this.b=t,this.R=n}},a=class{constructor(e,t){this.C=null,this.f=[],this.$=null,this.B=null,this.te=!1,this.Lt=!1,this.yt=!1,this.o=e,this.ae=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.Dt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Dt(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.Do?.(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.wt=new Set,this.name=e}get size(){return this.wt.size}subscribe(e){return this.wt.add(e),()=>{this.wt.delete(e)}}unsubscribe(e){return this.wt.delete(e)}emit(...e){let t=[];for(let n of this.wt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${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=/^\$[1-9]\d{0,2}$/,M=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function T(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:M.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 P=e=>e.trim();function E(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 W=(e,t)=>E(e,t)[0]??-1;function I(e,t){let n=[],l=0;for(let i of E(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function R(e,t,n){let l=W(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=W(e,"("),i=(e=>E(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,...T(e.substring(n+1,i))}})}(I(i,"|").map(P),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var L=new Map;function q(e){b(1101,[e])}function D(e){let[t,n]=R(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("**")&&q(e);let t=e.split(".").length;t>512&&b(117,[e,t])}(l),{Je:l,Ze:n}}var z=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],F=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function U(e){return e.includes("**")&&q(e),e}var B=0;function _(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var V=()=>new Set,H=()=>[];function K(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function J(e,t){return e===t||e!=e&&t!=t}function G(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function X(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function Y(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ae;return null!==e&&e.l.n===t?e:null}function Q(e,t,n){let l=Y(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var Z=class{constructor(e,t){this.Ie=0,this.u=null,this.je=0,this.bt=new Set,this.et=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.vt=[],this.Le=null,this.qn=[],this.Vt=0,this.X=null,this.oe=new Map,this.ce=new Map,this.Be=[],this.De=[],this.Me=[],this.kt=!1,this.hn=!1,this.Ht=new WeakMap,this.W=0,this.Ut=0,this.gn=!1,this.qt=!1,this.Kt=!1,this.Pe=0,this.Kn=()=>{this.W=0,this.gn=!1},this.zn=()=>{this.Pe--},this.rp=null,this.rr=null,this.Mo=()=>this.zt(),this._o=(e,t)=>e(this.proxy,...t),this.Xn=[],this.tt=[],this.Wo={$untracked:e=>{let t=this.X;if(null===t)return e();t.ye++;try{return e()}finally{t.ye--}},$eqIndex:(e,t=1)=>{let n=Y(this.u,t);null===n&&b(7,[e]);let l=this.o(e);if(null!==l.getter||l.se)return this.watchIndex(t),n.b===this.read(l,null);let i=this.X;if(null!==i){let e=i.getter,n=l.Ce??(l.Ce=[]);if(!n.some(n=>n.getter===e&&n.Yn===t)){n.push({getter:e,Yn:t});let i=e.h[t];(i.Ot??(i.Ot=[])).push({source:l,getter:e})}}return n.b===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,Y(this.u,n.n)))},$dependOn:e=>{this.resolve(U(e),this.u),null!==this.X&&0===this.X.ye&&this.Gn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.yn(e,t,n,l),$resolve:(...e)=>{let t=U(e[0]),n=e[1]??[],l=this.o(t,!0);this.wn("$resolve",t,l,n,!0);let i=this.Qn(l,n,null);if(e.length<3)return this.read(l,i);this.T(l,i,e[2])},$postUpdate:e=>{this.resolve(U(e),this.u);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.R=n.l.C[n.b],this.P.Xt(n)),this.bn(t,n),null!==n&&this.Jn(n,t,void 0,n.R,!1),0===t.n&&this.Zn(t,void 0,void 0,!0),this.Yt(t,n,void 0,void 0,!1)}},this.P=t,this.I=new i(e=>{this.tt.push(e),this.nt(e)}),this.eo(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.ot(t);if(t.indexOf(".")<0){let e=n.I.It(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.u),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(U(t),n.u),n.T(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.I.get(e);return t||(n.pn=!0),n}to(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let l=Object.getOwnPropertyDescriptor(n,e);if(void 0===l.get&&void 0===l.set)continue;let i=this.o(e);i.getter=l.get??null,i.ie=l.set??null,null!==i.getter&&i.n>0&&(i.A=this.Ie++)}for(let e of this.I.all())this.nt(e)}nt(e){e.t.includes("**")&&q(e.t),("__proto__"===e.s||"prototype"===e.s)&&b(120,[e.t]);let t=e.d;e.se=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.se),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(C.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.u),this.rp!==e?this.read(this.rp,this.rr):this.read(e.d,this.u)?.[n]),e.ie=l=>{if(this.resolve(t,this.u),this.rp!==e)return this.T(this.rp,this.rr,l);let i=this.read(e.d,this.u);null==i&&b(4,[t,i]),i[n]=l}}e._n=!0,e.n>0&&(e.A=this.Ie++)}_e(e,t){let n=null===e?this.oe:e.c??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new a(t,e)),t.pn=!0,this.Y(l),l}no(e){try{this.Y(e)}catch(t){this.Gt(t,e.o.t,e.$?.S??null,"for")}}Y(e){let t=this.v(e.o,e.ae);if(t===e.C)return;this.oo(e);let n=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.C)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].R===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].R===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].R===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.R);void 0===l?r.set(n.R,n):Array.isArray(l)?l.push(n):r.set(n.R,[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.b!==e&&(t.b=e,n.Lo(t))}return e.f=a,e.C=l,i}(e,t,this);if(null===n)return;if(e.C===t){let n=_(this.Ht,t,H);if(n.push(e),n.length>1)for(let e of n)e.yt=!0}c.Qt?.(this,e,n),(null!==e.$||null!==e.B)&&!e.te&&(e.te=!0,this.De.push(e),this.Te());let l=e.o.Ot;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.y&&this.vn(i,r),void 0!==o&&this.vn(i,o))}}Lo(e){this.P.Ho(this,e)}Bt(e){e.y=!1;let t=e._;if(null!==t){for(let e of t)G(e.source,e.key,e.sub);e._=null}if(null!==e.c)for(let t of e.c.values()){this.oo(t);for(let e of t.f)this.Bt(e)}}oo(e){let t=this.Ht.get(e.C);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.yt=!1,1===t.length&&(t[0].yt=!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?Q(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._e(i,a),f=t[s++];if(f<0)f=Q(n,e,o)?.b??-1;else if(l&&c.C===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}rt(e,t){return 0===e.n?X(this.target,e.K):null===t?void 0:X(t.R,e.K)}read(e,t){let n=this.X;if(null!==n&&0===n.ye&&this.Gn(e,t,n),null!==e.getter)return this.P.Uo(this,e,t);if(e.se){let n=this.read(e.d,t);return n?.[e.s]}return null===e.d&&!(e.s in this.target)&&!this.bt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&b(301,[e.t],e.s,Object.keys(this.target)),this.rt(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.ye++;try{return this.read(e,t)}finally{n.ye--}}Gn(e,t,n){let l=n.getter;e.Wn(l),0===l.n?e.Z!==n.ue&&(e.Z=n.ue,n.kn.push(e)):e.n>0&&Y(t,Math.min(e.n,l.n))!==Y(n.r,Math.min(e.n,l.n))&&(l.ft??(l.ft=new Set)).add(e)}qo(e,t){for(let n=0;n<this.Vt;n++){let l=this.qn[n];l.getter===e&&l.r===t&&b(701,[e.t])}this.Vt>=128&&b(801,[e.t]);let n=this.Vt++;this.je++;let l=this.qn[n]??={getter:e,r:t,ye:0,ue:0,kn:[]};l.getter=e,l.r=t,l.ye=0,l.ue=++B,l.kn.length=0;let i=this.X;this.X=l;let r=this.u;this.u=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Ko(e,l),t}finally{this.je--,this.Vt--,this.X=i,this.u=r,l.r=null}}Ko(e,t){let n=t.ue;for(let e of t.kn)e.Z=n;e.J=e.J.filter(t=>t.Z===n||t.n>0||!t.se&&Array.isArray(null!==t.getter?t.z:this.rt(t,null))||this.io(t,e))}io(e,t){return e.Io(t),this.tt.push(e),!1}zo(){for(let e=this.tt;e.length>0;e=this.tt){this.tt=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.d||n.c.length>0||n.M.length>0)&&(null===n.getter||n._n&&n.A<0)&&null===n._){n.mn=!0,this.I.jt(n),t.add(n.d);for(let e of n.J)this.io(e,n)}for(let e of t)(e.c=e.c.filter(e=>!e.mn)).length||this.tt.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.ye){let n=t.getter,l=n.h[e];if(l){let e=l.Ct??(l.Ct=[]);e.includes(n)||e.push(n)}}}ot(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:C.test(e)?+e.slice(1):0;return(n<1||n>128)&&b(1001,[e]),this.watchIndex(n),Y(this.u,n)?.b}let n=this.Wo[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.ot?.(this,e)}eq(e,t){this.resolve(e,this.u);let n=this.rp,l=this.rr;if(null!==n.getter||n.se||n.n>0)return J(this.read(n,l),t);let i=this.X;return null!==i&&0===i.ye&&this.Xo(n,t,i),J(this.v(n,null),t)}Xo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Xn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(J(o.key,t))return void(o.ue=n.ue);o.ue!==n.ue&&(G(e,o.key,o.sub),r.splice(i--,1))}}let o={getter:l,r:i};_(e._??=new Map,t,V).add(o),r.push({source:e,key:t,sub:o,ue:n.ue})}Zn(e,t,n,l){this.Jt(e,i=>{let r=i._;if(null===r&&null===i.Ce)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=X(t,o),a=X(n,o);if(null!==i.Ce&&this.Yo(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.y?this.P.we(this,n.getter,n.r):G(i,e,n)}})}T(e,t,n,l=!1,i=!1){if(this.je>0&&b(8),i||this.Pe>0?this.qt=!0:this.Kt=!0,c.Ae?.(this,e,t,n,i))return;if(null!==e.ie){try{this.Sn(e.ie,t,[n])}finally{this.Yt(e,t,void 0,void 0,!1)}return}null!==e.getter&&b(2,[e.t]),e.n>0&&null===t&&b(3,[e.t]);let r=e.se?this.v(e,t):this.rt(e,t);if(l||!this._t||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.C[e.b]=n,e.R=n,this.P.Xt(e)}else{let l=1===e.K.length?0===e.n?this.target:t.R:this.v(e.d,t);null==l&&b(4,[e.t,l]),l[e.s]=n}this.En(e,t),null!==t&&this.Jn(t,e,r,n),0===e.n&&this.Zn(e,r,n),this.Yt(e,t,r,n,!0)}}so(e){return(this.Ht.get(e.C)??[]).filter(t=>t.C===e.C&&(null===t.ae||t.ae.y))}Jn(e,t,l,i,r=!0){let o=e.l;if(!o.yt&&null===o.o.getter&&!o.o.M.length)return;let s=e.R,a=t.t.slice(o.o.t.length+2),u=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${a}`,!0);""===a&&(n.R=i,this.P.Xt(n)),r?this.En(o,n):this.bn(o,n),this.Yt(o,n,l,i,r)};for(let t of this.so(o))u(t,t.f[e.b]);if(""===a)return;let c=new Set([o.C]),f=e=>Array.isArray(e)&&e.includes(s),h=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.Ht.get(e)??[])for(let e of t.f)e.R===s&&u(t,e);for(let l of t){let t=l.z,i=t===n;i&&(t=this.oe.get(l)?.C),(i||f(t))&&!c.has(l.M)&&c.add(l.M)&&(!i&&t!==e&&this.P.we(this,l,null),h(t,l.M))}},d=e=>{for(let t of e.J)if(!c.has(t)&&c.add(t))if(null!==t.getter)d(t);else if(!t.se){let e=this.rt(t,null);f(e)&&h(e,t.M)}};null!==o.o.getter?d(o.o):h(o.C,o.o.M)}bn(e,t){this.Go(e,t,e=>{this.Y(e);for(let t of e.yt?this.so(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.St(e,n),this.bn(e,n)}})}En(e,t){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.Y(t)}Go(e,t,n){let l=null===t?this.oe:t.c;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Yo(e,t,n,l){for(let{getter:i,Yn:r}of e.Ce)this.lo(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.vn(i,t)}})}vn(e,t){t.l.n===e.n?this.P.we(this,e,t):this.Zt(t,e,t=>this.P.we(this,e,t))}Yt(e,t,n,l,i){c.be?.(this,e,t,n,l,i),this.We(e,t)}We(e,t){this.P.Qo(this,e,t),this.Te()}ao(e){let t=this.et.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.et.set(e,n);let l=this.root,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.y&&o.Jo(e,t))return}}),n}reset(e){let t=this.target,n=this.bt;for(let e of this.I.all())null===e.d&&null!==e.getter&&n.add(e.s);this.eo(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.ce.values())for(let t of e)this.en(t);for(let e of this.oe.values())this.co(e);this.Le=null;try{this.zt()}finally{this.$n()}c.element?.(this,"reset")}eo(e){for(let[t,n]of z)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)(!F.includes(e)||"boolean"!=typeof n[e])&&b(44,["$behavior",e]);let[l,i,r]=F.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.Mt||i!==this._t||r!==this.Wt)&&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.Mt=l,this._t=i,this.Wt=r,c.de?.(this,e),this.target=e,this.Ie=0;for(let e of this.I.all())e.jo();this.Xn.length=0,this.to(e),this.commands=o,this.Re=s}co(e){this.no(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.ht=null,n._=null,this.St(t,n),null!==n.c)for(let e of n.c.values())this.co(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ae)t.unshift(n.b);return t}Zo(e,t,n){let l=this.Re.get(e);void 0===l&&b(1301,[e],e,this.Re.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.Sn(l,n,[t,...this.H(n)])}Sn(e,t,n){let l=this.u;this.u=t;try{return e.apply(this.proxy,n)}finally{this.u=l}}St(e,t){if(null!==e.getter){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Me.push(t))}if(null===t)return void this.Jt(e,e=>{let t=this.ce.get(e);if(void 0!==t)for(let e of t)this.en(e)});let n=t.he;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.en(n[t]);let l=t.$;null!==l&&null!==l.fe&&l.uo(this,e);let i=t.l.B;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.fe&&l.uo(this,e)}}Nn(e,t,n){this.Jt(e,e=>{let l=e.M;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.it(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.ft&&r.ft.has(e))this.tn(r.h[r.n],e=>this.it(r,e,n));else if(r.n<=e.n){let e=Y(t,r.n);null!==e&&this.it(r,e,n)}else this.Zt(t,r,e=>this.it(r,e,n))}})}it(e,t,n){n(e,t)&&(c.ve?.(this,e,t),this.St(e,t),this.Nn(e,t,n))}Jt(e,t){t(e);let n=e.c;for(let e=0;e<n.length;e++)this.Jt(n[e],t)}tn(e,t){this.lo(e,e=>{for(let n of e.f)t(n)})}lo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.tn(e.h[e.n],n=>{let l=n.c?.get(e);void 0!==l&&t(l)})}Zt(e,t,n){if(e.l.n===t.n)return n(e);let l=e.c?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.Zt(e,t,n)}nr(e){let t=e.r;null===t?_(this.ce,e.o,V).add(e):(t.he??(t.he=[])).push(e)}xn(e){let t=e.r;if(null===t)return void this.ce.get(e.o)?.delete(e);let n=t.he;t.y&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}en(e){e.te||(e.te=!0,this.Be.push(e),this.Te())}Te(){this.kt||(this.kt=!0,queueMicrotask(this.Mo))}Rn(){for(let e of this.Be)e.te=!1;for(let e of this.De)e.te=!1;for(let e of this.Me)e.Lt=!1;this.Be=[],this.De=[],this.Me=[],this.P.bt(this)}fo(e,t){let n=[...new Set([...this.Be,...this.De,...this.Me].map(e=>e.o.t))];console.error(`[@wcstack/state] ${w(e)}`,n),c.st?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Rn()}zt(){this.kt=!1;let e=this.Ut;this.Ut=0;let t=0;if(!this.qt||this.Kt?this.Kn():e>0?t=e:1===(t=++this.W)&&setTimeout(this.Kn,0),this.qt=this.Kt=!1,t>100)101===t?this.fo(41,100):this.Rn();else{this.hn=!0;try{for(let e=0;this.Be.length>0||this.De.length>0||this.Me.length>0;e++){if(e>=32){this.gn?this.Rn():this.fo(11,32),this.gn=!0;break}let n=this.Me;if(n.length>0){this.Me=[];for(let e of n)e.Lt=!1,this.no(e)}let l=this.De,i=this.Be;this.De=[],this.Be=[];let r=N("state",()=>{for(let e of l){e.te=!1;for(let t of[e.$,...e.B??[]])if(null!==t&&t.y)try{t.Et()}catch(n){this.Gt(n,e.o.t,t.S,"for")}}for(let e=0;e<i.length;e++){let t=i[e];t.te&&(t.te=!1,(null===t.Pn||t.Pn.y)&&this.Ve(t))}this.hn||(this.He(),this.kt&&(this.Ut=t+1))});void 0!==r&&r.then(void 0,e=>console.error(e))}}finally{this.hn=!1}this.qt=this.Kt=!1,this.He(),c.Fe?.(this),this.zo(),e>0&&this.kt&&(this.Ut=t+1)}}$t(e,t){this.vt.push([e,t])}Gt(e,t,n,l){this.$t(e,{o:{t},a:n,nn:()=>l})}Ve(e){try{e.apply()}catch(t){return void this.vt.push([t,e])}null!==this.Le&&this.po(e.o,e.r)}po(e,t){let n=_(this.Le,e.t,H);null!==t&&n.push(this.H(t))}$n(){this.Le="function"==typeof this.target.$renderedCallback?new Map:null}He(){let e=this.Le;if(null!==e&&e.size>0){this.Le=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Pe++;try{t=this.ke("$renderedCallback",[n,l])}catch(e){console.error(e)}K(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Pe--}if(0===this.vt.length)return;let t=this.vt;this.vt=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ue?.(this,e,l);let t=l.o.t,i=l.nn();if("function"==typeof n)try{let n=this.ke("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);K(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${w(12,[i,t])}`,e)}}ke(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Sn(n,null,t):void 0}mo(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._e(o,s),u=t=>{l.push(t.b),r===e.n?n(t,l):i(r+1,t),l.pop()};for(let e of r-1<t.length?[a.f[t[r-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.wn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.u;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=Q(t,n,e);if(null===i)break;l.push(i.b)}0===l.length&&b(6,[e])}}let i=[];return this.mo(n,l,e=>i.push(this.read(n,e))),i}yn(e,t,n,l){Array.isArray(t)||b(9,[e]),this.je>0&&b(8);let i=this.o(e,!0);this.wn("$setAll",e,i,t,!1);let r=[];this.mo(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.T(i,t,a),s++)}return s}wn(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])}},ee={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},te=new Map,ne=new Set(["if","elseif","else","for"]),le=new Set([j,"if","elseif","for","..."]),ie=new Set(["class","attr","style","command",O,"state"]);function re(e){let t=function(e){return I(e,";")}(e).map(P).filter(e=>e.length>0).map(e=>{let t=W(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(le.has(i)){let t;return i!==n&&b(102,[e,i]),i===j?(l.length>0&&b(103,[e]),t={Je:"#else",Ze:[]}):"..."===i?(0===l.length&&b(104,[e]),t=D(l),t.Ze.length>0&&b(105,[e])):(t=D(l),"for"===i&&t.Ze.length>0&&b(121,[e])),{Se:i,Ee:[i],on:[],j:[],...t,w:"..."===i?"spread":i}}let r=D(l),o=function(e){let[t,n]=R(e,"input",te),l=t.split("#").map(P);l.length>2&&b(115,[t]);let[i,r]=l,o=i.split(".").map(P);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&b(116,[e]),{Se:i,Ee:o,on:r?r.split(",").map(P):[],j:n}}(n),[s]=o.Ee;if(""===s&&o.Ee.length>1){let e=o.Ee.slice(1);return(e.includes("")||ie.has(e[0]))&&b(106,[n]),{...o,Se:e.join("."),Ee:e,...r,w:"prop"}}return{...o,...r,w:"radio"===i||"checkbox"===i?i:s===O||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ne.has(e.w))&&b(201,[e]),t}var oe=["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"],se=new Map,ae=new Map;function ue(e){for(let t of Object.keys(e))se.set(t,{...e[t]});ae.clear()}function ce(e){return se.has(e)}function fe(e){b(26,[e])}function he(e){b(27,[e])}function de(e){b(28,[e])}function pe(e){b(29,[e])}function me(e){return!(!e||isNaN(Number(e)))}function ge(e,t){return me(e)||he(t),Number(e)}function ye(e,t,n){return ge(e?.[t]??fe(n),n)}function $e(e,t){return void 0!==t&&t.length>0?t[0]:e}var ve=(e,t)=>({factory:n=>{let l=ye(n,0,e);return n=>("number"!=typeof n&&de(e),t(n,l))},arity:[1,1]}),we={eq:{factory:(e,t)=>{let n=e?.[0]??fe("eq"),l=$e(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(me(n)||he("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??fe("ne"),l=$e(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(me(n)||he("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ve("lt",(e,t)=>e<t),le:ve("le",(e,t)=>e<=t),gt:ve("gt",(e,t)=>e>t),ge:ve("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]}},be=!1;function ke(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Se(e){return 0===e.length?null:(be||(be=!0,ue(we)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=ae.get(l);if(typeof i<"u")return i;let r=se.get(e);void 0===r&&function(e,t){oe.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,se.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 ae.set(l,a),a}(e.Hn,e.args,e.literals)))}var xe=Symbol.for("wcstack.trustedTypes.policy");function Ae(){let e=globalThis[xe];return null!==e&&"object"==typeof e?e:null}function Ne(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function je(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ae(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Oe=Symbol.for("wcstack.state.view-transition-naming"),Ce=new WeakSet;function Me(){let e=A("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Te=new WeakMap,Pe=e=>e.customElementRegistry??customElements;function Ee(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=Pe(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Ee(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(Te.has(e))return Te.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,ho:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Te.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.y||function(e,t,n){let l=n;null!==t&&(t.Nt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){De(e,l,t,n)}e.Te()})}function We(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Wt;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.Y&&null===a&&b(40,[l]);let d=f&&null!==a&&!u,p=new Ue(e,Le,n,l,i,r,o,t.N,void 0);p.j=t.j,Xe(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.ho||c.detail?.(n,l,i)),(!p.Tn||!Object.is(i,p.value))&&(i=ke(p.j,i),null===p.N&&(p.value=i),e.T(p.o,p.r,i,a.ho,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.Ve(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.y)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.Ve(p));let t=n[l];null===p.N&&(p.value=t),e.T(p.o,p.r,t,!1,!0)};"connect"!==t.Y||n.isConnected?i():Promise.resolve().then(i)}return p}function Ie(e,t,n){b(e,[t.localName,n])}var Re=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Le=11,qe=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],De=(e,t,n,l)=>e.Gt(t,n.o?.t??n.xt,l,qe[n.i]),ze=Symbol();function Fe(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:ze}var Ue=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.j=null,this.Tn=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.Pn=o,this.N=s,this.value=a,this.W=u}nn(){return qe[this.i]}apply(){if(null!==this.W)return void this.W.Et();let e=ke(this.N,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Le||8===this.i||Ne(this.name)))return;if(this.value===ze)return void(this.value=e);let t=this.a;if(this.i!==Le)9===this.i?t.checked=void 0!==e&&this.rn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.rn()):_e(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.Tn=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.Tn=!1}}}rn(){return ke(this.j,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.rn()}else if(10===this.i){let l=this.rn(),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=ke(this.j,t[this.name]),this.value=NaN;n.T(this.o,this.r,e,!1,!0)}},Be=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function _e(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Be(n)?t[n]="innerHTML"===n?je(l):null==l?"":String(l):Ne(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=je(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ve]=[n,l])));case 8:return void(t.innerHTML=je(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 Ve=Symbol();function He(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ve];void 0!==n&&(t[n[0]]=n[1])}var Ke=class{constructor(e,t,n,l){this.y=!0,this.he=null,this.c=null,this.Nt=null,this.Fn=null,this.r=e,this.qe=t,this.L=n,this.F=l}Jo(e,t){let n=t.target,l=this.F,i=[],r=null;for(let t of l.Re){if(t.name!==e)continue;let o=l.On[t.a],s=rt(null===this.L?this.qe: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.An(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.qe:this.L[this.L.length-1]}Ke(){let e=this.Fn;return(null===e?null:e.Cn(this.qe))??this.qe}insertBefore(e,t){let n=this.s;for(let l=this.Ke();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}wo(){null===this.L?this.qe.remove():ot(this.Ke(),this.s)}Ne(e){if(this.y=!1,null!==this.Nt)for(let e of this.Nt)e();let t=this.he;if(null!==t)for(let n=0;n<t.length;n++)e.xn(t[n]);if(null!==this.c)for(let e of this.c)e.Ne()}},Je=class extends Ke{constructor(e,t,n,l){super(e,t,n,l),this.bo=0,this.V=null,this.fe=0===l.ze.length?null:new Array(2*l.ze.length)}vo(e,t){let n=this.V??=new Array(this.F.ze.length),l=n[t];if(void 0===l){let i=this.F.ze[t],r=this.fe;l=n[t]=new Ue(e,i.i,r[2*t],i.name,i.o,this.r,this,i.N,r[2*t+1])}return l}uo(e,t){let n=this.F.ze;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.en(this.vo(e,l))}Ne(e){let t=this.r;t.$===this&&(t.$=null),super.Ne(e)}};function Ge(e,t,n,l){let i=Y(n,t.n);try{return e._e(i,t)}catch(n){return e.Gt(n,t.t,l,"for"),null===i?e.oe.get(t):i.c.get(t)}}function Xe(e,t,n){n&&e.nr(t);let l=t.Pn;null!==l&&(l.he??=[]).push(t)}var Ye=null;function Qe(){let e=Ye;return Ye=null,e}var Ze=-1;function et(e,t,n,l,i=null){let r,o=t.On,s=t.build,a=t.ko,u=null,f=c.Oe?.(t,null===l?i:l.S,null!==l),h=!f&&t.In,d=f?document.createDocumentFragment():(h?t.root:t.sn).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=rt(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 Je(n,r,u,t),null===l.map?n.$=m:l.map.set(n,m)):p=new Ke(n,r,u,t),Ze>=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||Ce.has(i))return;let o=globalThis[Oe]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${w(25,[l])}`)):(Ce.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",Ze),t.Re.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.Le,$=t.lr?a.slice(0,o.length):a,v=null===m?null:m.fe;if(null!==v){let e=t.ze;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.A;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.Ve(t);continue}try{let t=ke(l.N,e.read(l.o,n));t!==l.q&&(_e(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.po(l.o,n)}catch(t){e.$t(t,m.vo(e,o))}continue}switch(l.i){case 6:{let t=new it(e,l.F,Ge(e,l.o,n,i),i);(p.c??=[]).push(t),i===r&&(p.Fn=t),t.Et();break}case 7:{let t=nt(e,l.G.map(e=>({F:e.F,o:e.o,N:e.N,S:$[e.a]})),n,p);(p.c??=[]).push(t),i===r&&(p.Fn=t);break}default:try{tt(e,l,i,n,p)}catch(t){De(e,t,l,i)}}}return Ye=p,d}function tt(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.An,o=e=>r(e,l);if(n.et){let l=e.ao(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.$e&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.yo&&null!==i&&(i.Nt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Ee(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.xt.slice(9)),s=null===i?c.or?.(n,r):null;s||(null===i&&Ie(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.Nt??=[]).push(u)}(e,t,r,i,n));case 13:return void Ee(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&Ie(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&b(1204,[n.localName,r]);let s=t.xt;n.addEventListener(o.event,n=>{t.Rt&&n.preventDefault(),t.Pt&&n.stopPropagation();try{e.Zo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=Y(l,o.n);if(14===t.i)return void Ee(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&Ie(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.go?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;We(e,{...t,U:null,Y:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.$e&&1===t.i)return void Ee(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void We(e,t,n,t.name,t.o,l,i,r);let o=new Ue(e,1,n,t.name,t.o,l,i,t.N,Fe(e,t,l));o.j=t.j,!c.ar?.(o,t.ro)&&(Xe(e,o,!0),e.Ve(o))}(e,t,r,s,i,n));let a=new Ue(e,t.i,n,t.name,o,s,i,t.N,Fe(e,t,s));a.j=t.j,Xe(e,a,!0),e.Ve(a),null!==t.Tt&&n.addEventListener(t.Tt,()=>a.ir())}function nt(e,t,n,l){let i=new lt(e,t,n),r=null;for(let o of t){if(null===o.o)continue;let t=o.o,s=new Ue(e,7,o.S,"if",t,Y(n,t.n),l,null,void 0,i);Xe(e,s,!0),null===l&&i.ce.push(s),r??=s}return e.Ve(r),i}var lt=class{constructor(e,t,n){this.y=!0,this.O=null,this.b=-1,this.ce=[],this.engine=e,this.G=t,this.r=n}Cn(e){return null!==this.O&&this.G[this.b].S===e?this.O.Ke():null}Et(){let e=this.engine,t=-1;for(let n=0;n<this.G.length;n++){let l=this.G[n];if(null===l.o||ke(l.N,e.read(l.o,Y(this.r,l.o.n)))){t=n;break}}if(t!==this.b&&(Ze=Me(),null!==this.O&&(this.O.wo(),this.O.Ne(e),this.O=null),this.b=t,t>=0)){let n=this.G[t],l=et(e,n.F,this.r,null,n.S);this.O=Qe();let i=n.S.parentNode;i.insertBefore(l,n.S),He(i)}}Ne(){this.y=!1;for(let e of this.ce)this.engine.xn(e);null!==this.O&&this.O.Ne(this.engine)}},it=class{constructor(e,t,n,l){this.y=!0,this.xe=[],this.engine=e,this.F=t,this.l=n,this.S=l,null===n.$?(n.$=this,this.map=null):((n.B??=[]).push(this),this.map=new Map)}Cn(e){return 0===this.xe.length?null:this.xe[0].Ke()}At(e){return null===this.map?e.$:this.map.get(e)??null}jt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ne(this.engine)}Et(){let e=this.engine,t=this.l.f,n=this.xe;Ze=Me();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){let e=n[0].Ke(),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):ot(e,t);for(let e=0;e<i;e++)this.jt(n[e])}return void(this.xe=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.At(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.At(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.y&&this.At(l)===t?t.bo=e:(t.wo(),this.jt(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.At(t[a+e]);null!==n&&n.y?(u[e]=n.bo,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Ke():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.At(n);null!==u&&u.y?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(et(e,this.F,n,this),i),u=Qe()),s[a+r]=u,i=u.Ke()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(et(e,this.F,t[l],this)),s[l]=Qe();o.insertBefore(n,h)}}this.xe=s,He(o)}Ne(){this.y=!1;let e=this.l;if(e.$===this)e.$=null;else if(null!==e.B){let t=e.B.indexOf(this);t>=0&&e.B.splice(t,1),0===e.B.length&&(e.B=null)}for(let e of this.xe)e.Ne(this.engine);this.map?.clear()}};function rt(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 ot(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var st=()=>ee.bindAttributeName;function at(){return{a:0,i:1,name:"",o:null,N:null,q:t,An:null,F:null,G:null,j:null,Tt:null,$e:!1,U:null,Y:null,ro:!1,Rt:!1,Pt:!1,xt:null,go:null,A:-1,et:!1,yo:!1}}var ut=["state","element","auto","none"],ct=["call","connect"],ft="$command.";function ht(e,t,n){C.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.So?.(e,l),l}var dt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),pt=e=>8===e.i||dt(e)||1===e.i&&Be(e.name);function mt(e){b(202,[e])}function gt(e,t,n,l,i){let r=re(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.Wt||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?ut:ct).includes(o)||b(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),Rt:t.includes("prevent"),Pt:t.includes("stop"),event:n?n.slice(2):null,U:l,Y:i}}(e,t.on),o=l.localName.includes("-"),s=t.Ee,a=t.Je;if("event"===t.w){if(null!==r.U&&"none"!==r.U&&b(36),"eventToken"===s[0])return{...at(),a:i,i:13,name:s.slice(1).join("."),xt:a,$e:o,Rt:r.Rt,Pt:r.Pt};let n=a.startsWith(ft)?a.slice(9):null,{Rt:l,Pt:u}=r,c=t.Se.slice(2),f=t.on.includes("direct"),h=!f&&Re.has(c);return h&&e.ao(c),{...at(),a:i,i:5,name:c,et:h,$e:o,yo:f,An(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);K(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.w)return{...at(),a:i,i:14,o:ht(e,a,n),$e:o};if("command"===s[0]&&s.length>1)return a.startsWith(ft)||b(1201,[t.Se,a]),{...at(),a:i,i:12,name:s.slice(1).join("."),xt:a,$e:o};let u=ht(e,a,n),c={...at(),a:i,i:1,name:t.Se,o:u,N:Se(t.Ze),j:Se(t.j),ro:r.ro,U:r.U,Y:r.Y};if("radio"===t.w||"checkbox"===t.w)return("element"===r.U||"auto"===r.U)&&b(37,[t.w,r.U]),c.i="radio"===t.w?9:10,r.ro||(c.Tt=r.event??"input"),c;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return c.U=null,c.name=e,"class"===t?(c.i=2,c.q=l.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,c}return"html"===t.Se?(c.i=8,c):(c.name="text"===t.Se?"textContent":t.Se,c.$e=o&&!Ne(c.name),!o&&!r.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(l,c.name)&&(c.Tt=r.event??("select"===l.localName?"change":"input")),c)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].go=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var yt=/\{\{([\s\S]+?)\}\}/g;function $t(e){let t=e.data,n=[],l=0;yt.lastIndex=0;for(let i=yt.exec(t);null!==i;i=yt.exec(t)){let r=yt.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=yt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function vt(e,t,n,l){let i=function(e){return{Se:"textContent",Ee:["textContent"],on:[],j:[],...D(e),w:"text"}}(t);return{...at(),a:l,i:0,o:ht(e,i.Je,n),N:Se(i.Ze),q:""}}function wt(e){let t=e.getAttribute(st());if(null===t)return null;let n=re(t)[0];return void 0===n||"for"!==n.w&&"if"!==n.w&&"elseif"!==n.w&&"else"!==n.w?null:n}var bt=(e,t)=>0===e?ee.commentIfPrefix:null===t.o?ee.commentElsePrefix:ee.commentElseIfPrefix;function kt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.w?null:ht(e,l.Je,n),N:"else"===l.w?null:Se(l.Ze)}),i=[l(t,wt(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=wt(e);if(null===t||"elseif"!==t.w&&"else"!==t.w||(i.push(l(e,t)),"else"===t.w))break}return i}var St=new WeakSet;function xt(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.jn?.(e,i,t),i},u=t=>{for(let f=0;f<t.length;f++){let h=t[f];if(null!==h.parentNode)if(1===h.nodeType){let t=h,s=t.localName;if(l){if("script"===s||"style"===s||St.has(t))continue;if(St.add(t),s===ee.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?wt(t):null;if(null!==f){if("for"===f.w){let l=ht(e,f.Je,n),r=jt(e,t,l,!0);i(a(t,ee.commentForPrefix),l,r)}else"if"===f.w?r(kt(e,t,n).map((t,l)=>({F:jt(e,t.el,n,!1),o:t.o,N:t.N,S:a(t.el,bt(l,t))}))):mt(f.w);continue}let d=t.getAttribute(st()),p=null===d?null:gt(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(pt)&&!c.Eo?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.Mt&&h.data.includes("{{")&&!St.has(h))for(let{a:e,cr:t}of $t(h))s(e,t);else if(8===h.nodeType){let e=At.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 At=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Nt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function jt(e,t,n,l){let i=document.importNode(Nt(t),!0),r=[],o=[],s=e=>r.push(e)-1;xt(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...at(),a:s(e),i:6,o:t,F:n})},e=>{let t=e.map(e=>({a:s(e.S),F:e.F,o:e.o,N:e.N}));o.push({...at(),a:t[0].a,i:7,G:t})},(e,t)=>{let n=s(e);for(let e of t)dt(e)&&b(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(st())},(t,l)=>{o.push(vt(e,l,n,s(t)))}),Tt(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.et&&!e.$e&&!Ot(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&&Ct(e)&&(e.A=f.push(e)-1),7===e.i)for(let t of e.G)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{sn:i,root:u?i.firstChild:null,On:a,build:g,Re:d,sr:p,In:u,lr:c,ko:[],ze:f}}function Ot(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 Ct(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.$e&&null===e.Tt;default:return!1}}var Mt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Tt(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&&Tt(l,t,Mt.has(l.localName)),l=e}}var Pt=new WeakMap;function Et(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Pt.set(t,e),It(e,[...n.childNodes]),e.He()}function Wt(e,t,n){try{let l="template"===t.localName?wt(t):null;null!==l&&!n&&b(204,[l.w]),It(e,[t])}catch(e){console.error(e)}e.He()}function It(e,t){xt(e,t,null,!0,(t,n,l)=>{new it(e,l,Ge(e,n,null,t),t).Et()},t=>{nt(e,t,null,null)},(t,n)=>{c.jn?.(e,t,n);for(let l of n)tt(e,l,t,null,null)},(t,n)=>{c.jn?.(e,t,n),tt(e,vt(e,n,null,0),t,null,null)})}var Rt=Symbol.for("wcstack.binder"),Lt=Symbol.for("wcstack.binder.pending"),qt=Symbol.for("wcstack.binder.taken");var Dt=new Map;function zt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Pt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Dt.set(e,t):Wt(n,e,t?.range)}function Ft(){let e=[...Dt];Dt.clear();for(let[t,n]of e)zt(t,n);!function(){let e=function(){let e=globalThis[Rt];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[Lt];return void 0===t&&(t=[],e[Lt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[qt];return void 0===t&&(t=new WeakSet,e[qt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Ut=class{constructor(){this.name="dirty",this.Z=(e,l)=>{if(0===e.n){let l=e.z;return l!==t&&l!==n&&(e.z=n,!0)}let i=null===l?null:l.ht;if(null===i)return!1;let r=i[e.A];return r!==t&&r!==n&&(i[e.A]=n,!0)}}Qo(e,t,n){null!==t.getter&&this.Z(t,n),e.St(t,n),e.Nn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Ct;if(null!==n)for(let l of n)l.n===t.l.n?e.it(l,t,this.Z):e.Zt(t,l,t=>e.it(l,t,this.Z))}we(e,t,n){this.Z(t,n),c.ve?.(e,t,n),e.St(t,n),e.Nn(t,n,this.Z)}Uo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.ht??=new Array(e.Ie).fill(t),a=null===s?i.z:s[i.A];if(a!==t&&a!==n&&a!==l&&(null===s||i.A in s))return a;a=l;try{return a=e.qo(i,null===s?null:r)}finally{null===s?i.z=a:s[i.A]=a}}Xt(e){e.ht=null}bt(e){for(let t of e.I.all())null!==t.getter&&(0===t.n?t.z===n&&(t.z=l):e.tn(t.h[t.n],e=>{let i=e.ht;null!==i&&i[t.A]===n&&(i[t.A]=l)}))}},Bt=0,_t=new WeakMap;function Vt(e,t=e.getRootNode()){_t.set(t,[..._t.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Ht(e){let t=_t.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?_t.get(e)!==t?Ht(e):Promise.reject(l.errors[0]):void 0)}var Kt=typeof HTMLElement>"u"?class{}:HTMLElement,Jt=class extends Kt{constructor(){super(),this.engine=null,this.Ln=!1,this.Ue=!1,this.q=null,this.Xe=null,this.loaded=!1,this.cn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.an=e,this.$o=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.ln=e})}static{this.getBindingsReady=Ht}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Xe)return void this.Xe.Ye();Vt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!Pt.has(t)&&Pt.set(t,e),Ft(),c.element?.(e,"back"),this.No("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),t=c.at?.(this,e);if(t)return this.Xe=t,!t.xo&&this.parentNode instanceof ShadowRoot&&Vt(this),void(void 0===t.Dt?this.Ro():t.Dt()).then(e=>(this.loaded=!0,t.start(e,()=>this.Po()))).then(()=>{this.ln(),this.an()},e=>this.$t(e,t.xo));this.start(e),Vt(this)}disconnectedCallback(){if(null!==this.Xe)return void this.Xe.Bn();let e=this.engine;if(null===e)return;let t=e.root;Pt.get(t)===e&&Pt.delete(t),Vt(this,t),this.No("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ue&&b(14),this.loaded)this.Xe.reset(e);else if(null===this.engine)if(null!==this.cn){let t=this.cn;this.cn=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.je++;try{t(n.proxy)}finally{"readonly"===e&&n.je--}}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 Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${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(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//${++Bt}`);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.cn=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.Ro(),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=Pt.get(e)?.element;i?.isConnected&&(i.V||i.Xe)&&b(47);let r=new Z(n,new Ut);r.element=this,this.engine=r,c.element?.(r,"mounting"),Et(r,e),Ft(),r.$n(),this.Po(),await r.ke("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.an()}catch(e){this.Ue=!this.V,this.$t(e)}}Po(){this.V=!0,this.ln()}$t(e,t){this.He(this.V?50:49,e),this.ln(),t?this.an():this.$o(e)}He(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)}No(e,t,n){(async()=>this.engine.ke(e))().then(n,e=>this.He(t,e))}},Gt=[];function Xt(){return(Gt=Gt.filter(e=>e.deref())).map(e=>e.deref())}var Yt,Qt=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},Zt="en";function en(){if(ee.locale!==Yt){Yt=ee.locale;try{Zt=Intl.getCanonicalLocales(Yt)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[Yt])}`),Zt="en"}}return Zt}var{eq:tn,ne:nn,not:ln,lt:rn,le:on,gt:sn,ge:an,falsy:un,truthy:cn,boolean:fn}=we,hn={toFixed:{factory:e=>{let t=ge(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&de("toFixed"),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&de("locale"),e.toLocaleString(t??en()))},arity:[0,1]},upper:{factory:Qt(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:Qt(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:Qt(()=>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:Qt(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:Qt(e=>{let t=[ye(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ge(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:Qt(e=>{let t=ye(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:Qt(e=>{let t=ye(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:Qt(e=>{let t=ye(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:Qt(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:Qt(e=>{let t=ye(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,ge(e?.[0]??"0","round"));return e=>("number"!=typeof e&&de("round"),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ge(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&de("floor"),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ge(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&de("ceil"),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ge(e?.[0]??"0","percent");return e=>("number"!=typeof e&&de("percent"),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:Qt(e=>{let t=e?.[0]??fe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||pe("date"),e.toLocaleDateString(t??en()))},arity:[0,1]},time:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||pe("time"),e.toLocaleTimeString(t??en()))},arity:[0,1]},datetime:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||pe("datetime"),e.toLocaleString(t??en()))},arity:[0,1]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||pe("ymd");let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||pe("hms");let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},eq:tn,ne:nn,not:ln,lt:rn,le:on,gt:sn,ge:an,add:ve("add",(e,t)=>e+t),sub:ve("sub",(e,t)=>e-t),mul:ve("mul",(e,t)=>e*t),div:ve("div",(e,t)=>e/t),mod:ve("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&de("abs"),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ye(e,0,"clamp"),n=ye(e,1,"clamp");return e=>("number"!=typeof e&&de("clamp"),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:un,truthy:cn,defaults:{factory:(e,t)=>{let n=$e(e?.[0]??fe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=$e(e?.[0]??fe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:fn,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]}},dn=!1,pn={name:"formats",install:function(){dn||(dn=!0,ue(hn))}};function mn(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 gn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=mn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var yn=" Validate statically: npx @wcstack/lint <file>.",$n=["","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"],vn=e=>{let t=$n[e/100|0];return t?`[wcs/${t}] `:""},wn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],bn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,kn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Sn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t)=>`binding "${e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${kn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${kn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:e=>`filter ${e} requires a number value`,29:e=>`filter ${e} requires a date value`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&wn.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)=>`${bn(e,t)} failed to initialize.`,50:(e,...t)=>`${bn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${bn(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>").`,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 xn(e,t){let n=Sn[e];return void 0===n?`${vn(e)}#${e} ${t.join(" ")}`:vn(e)+n(...t)}var An=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Nn=[[/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.']],jn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function On(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(jn,e)?jn[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?gn(t,n):"");for(let[t,n]of Nn){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"].':oe.some(ce)||(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&&An.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=yn),l}var Cn=new WeakMap,Mn=new WeakMap,Tn=new WeakSet,Pn=new WeakSet;function En(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 Wn(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 In(e,t){let n=[];for(let e=t;null!==e;e=e.d)n.unshift(e);let l=e.target,i=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==En(e.target,t.t)?.get?t:e.I.It(o(t.t).o)}(e,t);for(let t of n){if(null!=i(t)?.getter||null===l||"object"!=typeof l)return null;if("*"===t.s){if(!Array.isArray(l)||0===l.length)return null;l=l[0];continue}if(Array.isArray(l)&&/^\d+$/.test(t.s)){if(Number(t.s)>=l.length)return null;l=l[Number(t.s)];continue}let n=En(l,t.s);if(void 0===n&&null===t.d&&e.bt.has(t.s))return null;if(void 0===n){let n=Wn(l),r=i(t.d);for(let t of e.I.all())t.d===r&&null!==t.getter&&n.push(t.s);return{seg:t.s,names:n}}if(void 0!==n.get||void 0!==n.set)return null;l=n.value}return null}function Rn(e){Tn.has(e)||(Tn.add(e),setTimeout(()=>function(e){Tn.delete(e);let t=Cn.get(e);if(void 0===t)return;let n=Mn.get(e);void 0===n&&Mn.set(e,n=new Set);for(let[l,i]of t){if(n.has(l))continue;n.add(l);let t=In(e,l);if(null===t)continue;let r=[...e.root?.querySelectorAll(`${ee.tagNames.state}[mount]`)??[]].find(e=>!Pn.has(e)&&(l.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==r){n.delete(l),r.initializePromise.then(()=>{Pn.add(r),Rn(e)});continue}let[s,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];c.st?.(e,{type:"state:path-unresolved",source:i?"watch":"binding",path:l.t,missingSegment:t.seg});let u=e.I.It(o(l.t).o),f="";if(void 0!==u&&u!==l&&null!==u.getter){let e=u.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.h[t].t.length+2)}`);f=` The getter "${u.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}console.warn(`[@wcstack/state] [wcs/${s}] ${a} "${l.t}" does not resolve on the state tree: "${t.seg}" is not declared.${gn(t.seg,t.names)}${f} Updates to this path will be silently dropped.${yn}`)}}(e),0))}function Ln(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.d)return;let l=Cn.get(e);void 0===l&&Cn.set(e,l=new Map),l.has(t)||l.set(t,n),Rn(e)}var qn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Dn=!1;function zn(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(Dn||!(t instanceof TypeError)||!Ne(l)||!("trustedTypes"in globalThis))return;Dn=!0;let i="function"==typeof Ae()?.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 Fn=new WeakMap;function Un(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=Fn.get(e);void 0===r&&Fn.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 Bn=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],_n={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},Vn={name:"diagnostics",install(){c.Bo=On,c.Do=xn,c.So=Ln,c.detail=Un,c.Ue=f(c.Ue,zn);let e=c.de;c.de=(t,n)=>{(function(e){void 0!==e.$scan&&b(1);for(let[t,n]of Bn)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=Wn(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(`^(?:${qn(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(`^${qn(l)}(?:${qn(s)})*${qn(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){Mn.delete(e),Cn.has(e)&&Rn(e)}(t)},c.ot=h(p,c.ot,(e,t)=>Object.hasOwn(_n,t)?b(1701,[t,_n[t]]):void 0)}},Hn={},Kn=/\.\d/,Jn=new Set(Object.getOwnPropertyNames(Object.prototype)),Gn=0,Xn=!1,Yn=null,Qn=()=>{Xn=!1,Gn++};function Zn(){if(null===Yn)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=Qn,e.port1.unref?.(),Yn=()=>e.port2.postMessage(0)}else Yn=()=>setTimeout(Qn,0);return Xn||(Xn=!0,Yn()),Gn}function el(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.J){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 tl=class{constructor(e,t){this.active=!1,this.Ge=new Map,this.n=0,this.Ao=-1,this.Dn=new Set,this.We=null,this.engine=e,this.ct=t}ur(){let e=this.engine;this.Ge.clear();for(let t of this.ct)t.getter=null!==t.p.getter||t.p.se,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(Hn,e.v(t.p,null)):this.Mn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.st?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Fo(){this.active=!1,this.Ge.clear()}Mn(e,t,n,l){let i=this.engine._e(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Mn(e,t+1,n,l)}un(e,t,n,l){let i=this.Ge.get(e);void 0===i&&this.Ge.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)}be(e,t,n,l,i){if(this.active){(this.We??=new Set).add(e);for(let r of this.ct){let o=r.p;o.n!==e.n||!o.ee(e)||this.un(r,t,r.getter?r.s.get(t??Hn):o===e&&i&&this.engine._t&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}}ve(e,t){if(this.active)for(let n of this.ct)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===e.n&&n.p.ee(e)&&this.un(n,t,n.s.get(t??Hn),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.ct){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.un(l,t,void 0,!0):this.Mn(i,e.n+1,t,e=>this.un(l,e,void 0,!0)))}}}Fe(){let e=this.We;if(this.We=null,!this.active||0===this.Ge.size)return;let t=this.Ge;this.Ge=new Map;let n=this.engine,l=[];for(let i of this.ct){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.y);s.length>1&&s.sort((e,t)=>ll(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.u;this.n=a+1,n.Pe++;try{if(s=n.v(i.p,t),i.getter&&(i.s.set(t??Hn,s),Object.is(s,r)&&(Kn.test(i.t)||null!==t&&!u&&!(o??=null!==e&&el(nl(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.u=t,c.st?.(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.st?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.u=h,this.n=0,n.Pe--}}}l.length>0&&this.Oo(l)}Oo(e){let t=Zn();t!==this.Ao&&(this.Ao=t,this.Dn.clear());let n=e.filter(e=>!this.Dn.has(e));if(0!==n.length){for(let e of n)this.Dn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.st?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function nl(e){for(;null===e.getter&&null!==e.d;)e=e.d;return e}function ll(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ae)n.unshift(t.b);for(let e=t;null!==e;e=e.l.ae)l.unshift(e.b);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var il="$streamStatus",rl="$streamError",ol=new Set(Object.getOwnPropertyNames(Object.prototype)),sl=!1;function al(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 ul=class{constructor(e,t,n){this.engine=e,this.entries=t,this.D=n}set(e,t,n){sl=!0;try{this.engine.T(this.engine.o(`${e}.${t}`),null,n)}finally{sl=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.ut=!1,e.Q?.abort(),e.Q=null}pr(){for(let e of this.entries)e.ut=!1,null!==e.Q&&(e.Q.abort(),e.Q=null),this.set(il,e.name,"idle")}ve(e){let t=this.D.n;for(let n of this.entries)n.g===e&&(n.n=n.ut?Math.max(n.n,t):t,n.ut=!0)}Fe(){let e=this.engine,t=this.D,n=[];for(let i of this.entries){if(!i.ut)continue;let r=i.n;if(i.ut=!1,r>32)n.push(i.name),i.g.z=l;else{t.n=r+1,e.Pe++;try{this.start(i,!1)}finally{e.Pe--,t.n=0}}}n.length>0&&t.Oo(n)}start(e,t){let n,i=this.engine;if(null!==e.Q&&e.Q.abort(),e.Q=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.J.slice();cl(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.J)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${il}.${e}`||n.t===`${rl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){cl(r);for(let e of o)e.Wn(r);if(r.z=l,t)throw n;return this.set(rl,e.name,n),void this.set(il,e.name,"error")}}let r=new AbortController;e.Q=r,i.T(i.o(e.name),null,e.q),this.set(rl,e.name,null),this.set(il,e.name,"active"),this.mr(e,r,n)}async mr(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.Q===t,o=l.o(e.name),s=this.D.n,a=Zn(),u=e=>{Zn()===a&&(this.D.n=s);try{e()}finally{this.D.n=0}},c=e.q;try{let t=await e.source(n,i);if(!r())return;let s=t=>{c=void 0!==e.Co?e.Co(c,t):t,u(()=>l.T(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.Q=null,u(()=>this.set(il,e.name,"done"))}catch(n){if(!r())return;e.Q=null,t.abort(),u(()=>{this.set(rl,e.name,n),this.set(il,e.name,"error")})}}};function cl(e){for(let t of e.J){let n=t.M.indexOf(e);n>=0&&t.M.splice(n,1),t.pt.delete(e)}e.J.length=0,e.z=t}var fl=new WeakMap;function hl(e){let t=fl.get(e);return t?.target===e.target?t:void 0}function dl(e,t){let n=new tl(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("@")||Jn.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.So?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new ul(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)||ol.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.`),al(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,Co:u,q:f,Q:null,ut:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[il]=i,t[rl]=r,l}(e,t),n),i=fl.get(e);void 0!==i&&(i.D.Fo(),i.Ft.fr()),fl.set(e,{D:n,Ft:l,Ye:i?.Ye??!1,target:t})}function pl(e,t){let n=fl.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Ye="connected"===t),n.target===e.target)){if("disconnected"===t)return n.D.Fo(),void n.Ft.pr();n.Ye&&(n.D.ur(),n.Ft.dr())}}var ml=["$streamStatus","$streamError"],gl={name:"temporal",install(){c.de=f(c.de,dl),c.element=f(c.element,pl),c.be=f(c.be,(e,t,n,l,i,r)=>hl(e)?.D.be(t,n,l,i,r)),c.ve=f(c.ve,(e,t,n)=>{let l=hl(e);void 0!==l&&(l.D.ve(t,n),l.Ft.ve(t))}),c.Qt=f(c.Qt,(e,t,n)=>hl(e)?.D.Qt(t,n)),c.Fe=f(c.Fe,e=>{let t=hl(e);void 0!==t&&(t.D.Fe(),t.Ft.Fe())}),c.ot=h(p,c.ot,(e,t)=>{let n=t.split(".",1)[0];if(ml.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ae=h(d,c.Ae,(e,t)=>(!sl&&36===t.t.charCodeAt(0)&&ml.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},yl=new WeakMap,$l=!1,vl=/^(?!prototype$)[^\d.*$][^.*]*$/;function wl(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.`)}}yl.set(t,l)}function bl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function kl(e,t,n){let l=new Map;for(let i of t){bl(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 Sl(e,t,n,l){if($l||!Array.isArray(l))return!1;let i=yl.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.rt(t,n);if(!Array.isArray(r)||r===l)return!1;let o=kl(t.t,r,i);kl(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){$l=!0;try{e.T(t,n,s)}finally{$l=!1}}if(c.length>0){let l=e._e(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=vl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.T(s,o,r):(o.R[i]=r,e.T(e.o(`${t.t}.*`),o,o.R,!0))}}return!0}var xl={name:"list-keys",install(){c.de=f(c.de,wl),c.Ae=h(d,c.Ae,Sl)}},Al=new WeakMap,Nl=new WeakMap,jl="will not graft: the root state failed to initialize.",Ol=new WeakSet,Cl=new WeakMap,Ml=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Tl=["$commandTokens","$eventTokens","$on","$errorCallback"],Pl=e=>`[@wcstack/state] <${ee.tagNames.state} mount="${e}">`,El=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Wl=e=>e?.element?.isConnected?e:void 0;function Il(e){let t=Nl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function Rl(e,t){let n=Nl.get(t);if(Nl.delete(t),Array.isArray(n))for(let t of n)zl(t,e)}function Ll(e){let t=Al.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ql(e,t){console.error(`${Pl(e.t)} ${t}`),Ll(e),e.Qe?.(),e.Qe=null}function Dl(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 zl(e,t){if(Ol.has(t))return ql(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 ql(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)):El.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.rt(n,null)&&t.T(n,null,{})}t.T(t.o(e.t),null,s)}t.to(Object.defineProperties({},a));for(let e in a)t.We(t.o(e),null);e.engine=t;let c=Cl.get(t);void 0===c&&Cl.set(t,c=[]),c.push(e),e.el.isConnected&&Dl(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function Fl(e,t){let n=Nl.get(e);if(Array.isArray(n))for(let e of n)ql(e,jl);Nl.set(e,t)}var Ul=new WeakMap;function Bl(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(ee.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Al.get(t);void 0===e&&Al.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Wl(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Nl.get(t);Array.isArray(e)&&Nl.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{xo:!0,start(e){if(null!==i)return ql(l,i);if(Al.get(t).get(n)===l){for(let t of Ml)if(void 0!==e[t])return ql(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of Tl)void 0!==e[t]&&console.warn(`${Pl(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=Wl(Pt.get(t)),i=Nl.get(t);void 0!==n?zl(l,n):Il(t)?ql(l,jl):Nl.set(t,[...Array.isArray(i)?i:[],l])})}},Ye(){null!==l.engine&&Dl(l,"$connectedCallback")},Bn(){null!==l.engine&&Dl(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 _l=new WeakMap,Vl=new WeakMap;function Hl(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 Kl(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=Hl(l,"$bindables"),o=Hl(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(ee.tagNames.state);return a.set(l,o),_l.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ee.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)},Ye(){},Bn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Jl=new WeakMap,Gl=new WeakSet,Xl=new WeakMap,Yl=new WeakMap,Ql="data-wcs-wired",Zl=new WeakMap,ei=new WeakMap,ti=new WeakMap,ni=0,li=new Set,ii={},ri=["$watch","$stream","$renderedCallback"],oi=e=>e.split(".",1)[0];function si(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ai(e,t){let n=e.a,l=oi(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(Ql);else if(!ci(n,l)){let e=n.getAttribute(Ql)?.split(" ")??[];e.includes(l)||n.setAttribute(Ql,[...e,l].join(" "))}Zl.get(n)?.pe===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=Jl.get(n);void 0===i&&Jl.set(n,i=[]),i.push(e),t&&Gl.add(e);let r=Xl.get(n);return void 0===r&&Xl.set(n,r=new Map),r.has(l)||r.set(l,n[l]),Yl.get(n)?.(),!1}function ui(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ee.tagNames.state}[bind-component]`)}function ci(e,t){let n=e.getAttribute(ee.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function fi(e){let t=e.parentElement;for(;null!==t&&!ui(t);)t=t.parentElement;let n=Pt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?zt(e):Wt(n,e))}var hi=new Set;function di(e,t){hi.has(e)||(hi.add(e),console.warn(`[@wcstack/state] ${t}`))}var pi=(e,t)=>t in e.state;function mi(e,t){let n=gi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function gi(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 yi(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=oi(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.d)return function(e,t){let n,l=t.d;for(;null!==l&&void 0===(n=e.dt.get(l));)l=l.d;if(null===l||void 0===n)return;let i=e.x,r=e.host.engine,o=r.o(n.p.t+t.t.slice(l.t.length));if(null===o.getter)return;let s=n,a=()=>{let n=$i(e,s.r);return 0===t.n?n:(r.resolve(si(o.t,[...r.H(n),...i.H(Y(i.u,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.ie&&(t.ie=n=>{let l=a();vi(e,s.e,()=>r.T(o,l,n)),e.dn=t}),t.n>0&&(t.A=i.Ie++),e.dt.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):mi(i,o))return;l=s.me}else{if(null===t||null!==n.d||"$"===o[0]||pi(i,o))return;s=t,l=r.o(`${t.me.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,$i(e,a)),n.ie=t=>{vi(e,u,()=>r.T(l,a,t)),e.dn=n},e.dt.set(n,{e:s,p:l,r:a})}function $i(e,t){return null!==t&&!t.y&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function vi(e,t,n){let l=li.has(e.x);li.add(e.x),e.from=t;try{n()}finally{l||li.delete(e.x),e.from=null}}var wi=(e,t)=>t||!li.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function bi(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,ni+=t?1:-1;let n=e.host.engine,l=ti.get(n);void 0===l&&ti.set(n,l=new Map);for(let n of e.fe){let e=l.get(n.e.me);void 0===e&&l.set(n.e.me,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.re&&function(e,t){let n=e.host,l=n.engine;e.re=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=oi(o);if(o!==a&&!pi(n,a))continue;let u=l.o(`${t.me.t}.${o}`);if(null===u.getter)xi(l,u,t.me);else if(!ki.has(u.getter))continue;e.re.set(u,e.x.o(o))}}(e,i);for(let l of e.re.keys())t&&null===l.getter&&xi(n,l,i.me),n.P.we(n,l,i.r);e.re.size>0&&n.Te(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.re){let r=n.v(l.d,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;di(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.pe}.${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 ki=new WeakSet;function Si(e,t,n,l){let i=ti.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.re?.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 xi(e,t,n){let l=t.d,i=t.s,r=()=>{let t=e.read(l,e.u);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=Si(e,n,e.u,t);return null===o?void 0:o.x.read(o.re.get(t),null)},ki.add(t.getter),t.ie=o=>{let s=null===r()?Si(e,n,e.u,t):null;if(null===s){let t=e.read(l,e.u);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.re.get(t);void 0===gi(s.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${s.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),s.x.T(a,null,o)},t.n>0&&(t.A=e.Ie++)}function Ai(e,t,n,l,i,r){if(null!==t.getter)return e.P.we(e,t,n),void e.Te();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Xt(n),null!==n.c)for(let t of n.c.values())e.Y(t)}else e.En(t,n);c.be?.(e,t,n,l,i,r),e.We(t,n)}function Ni(e){let t=e.m.x;for(let[n,l]of e.m.dt)l.e===e.e&&(0===n.n?t.P.we(t,n,null):t.tn(n.h[n.n],e=>t.P.we(t,n,e)));t.Te()}function ji(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Ni(e);let a,u=e.m,c=u.x;if(""===e.e.E){a=s.slice(1);let e=oi(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(Y(l,e).b);c.resolve(si(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Ai(c,h,d,i,r,o)}function Oi(e,t,n,l,i,r,o){if(0===ni)return;let s=li.has(e);li.add(e);try{let s=ei.get(e);!o&&void 0!==s&&s.fn&&!li.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.dt.get(s));)s=s.d;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.y)return;let u=[...a.H(o.r),...e.x.H(n)];a.resolve(si(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||vi(e,o.e,()=>Ai(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.fn&&null!==s.re&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[i,r]of e.re)r===t&&(l.P.we(l,i,n.r),l.Te())}(s,t);let a=ti.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:Y(n,e.n));if(void 0!==a)for(let s of[...a])wi(s,o)&&ji(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||Y(e,t.n)===n)for(let e of[...l])wi(e,o)&&Ni(e)}finally{s||li.delete(e)}}async function Ci(e,t,n,l,i){if(l===ii)return;let r=y(l);r&&await r;let o=Zl.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.O;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${ee.tagNames.state} bind-component="${o.pe}">.`),null!==s&&bi(s,!1),null!==s&&function(e,t,n){let l=e.x,i=`[${ee.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.Cn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.ce.values())for(let t of e)if(null===t.W)s(t.a);else for(let e of t.W.G)a(t.W,e.S);for(let e of l.oe.values())for(let t of[e.$,...e.B??[]])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.Mt&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await Mi(e,l):l()}(s,e,n,i);let a=new Z(l,new Ut);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:[],x:a,host:o,fe:[],dt:new Map,fn:!1,dn:null,from:null,re:null};for(let e of o.entries)u.fe.push({m:u,e});o.O=u,ei.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.x,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=oi(e.E);pi(n,t)&&(e.E!==t||mi(n,t))&&di(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.pe}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.me,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.E===t)&&di(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.me.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=ri.filter(e=>void 0!==n.state[e]);o.length>0&&di(`${i}.${n.pe}$`,`[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.nt;t.nt=n=>{yi(e,r,n),s.call(t,n)};let a=[...t.I.all()];for(let t of a)yi(e,r,t);for(let e of a)s.call(t,e);let u=t.zt;t.zt=()=>{(function(e){for(;void 0!==e;e=ei.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}(u),bi(u,!0),Ol.add(a),Rl(a,n));let h=c.hr?.(n);Et(a,n),h?.(),u.L=[...n.childNodes],Ft(),f&&a.$n(),Object.defineProperty(t,o.pe,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.pe);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.ke("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):bi(u,!1)}async function Mi(e,t){bi(e,!0);for(let t of e.fe)Ni(t);t?.(),!e.broken&&(await e.x.ke("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function Ti(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Pt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){Fl(t,e);for(let e of Ul.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:Zl.get(r)?.O;return t?.el===e?t:null},s=t=>{throw i&&Fl(l,e),t},a=!1;return{Dt:()=>(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(`<${ee.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Pe(n).whenDefined(i);let r=Zl.get(n);if(void 0!==r)return r.pe!==t&&v(`<${i}> already has a <${ee.tagNames.state} bind-component="${r.pe}">.`),r.state;let o=()=>(Jl.get(n)??[]).filter(e=>oi(e.name)===t),s=ci(n,t);if(s&&0===o().length&&fi(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(Ql)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{Yl.set(n,l),e=function(e,t){Il(e)&&t();let n=Ul.get(e)??new Set;return Ul.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())}Yl.delete(n);let a=o(),u=Xl.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 (${ee.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),ii}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,me:e.o,r:e.r,ro:Gl.has(e)}),e.engine.xn(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 Zl.set(n,r={el:n,pe:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,O:null}),h}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ee.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await Ci(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Ye(){let t=o();null!==t?Mi(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===l)return Ci(e,r,i?l:r,Zl.get(r).state,()=>{})}).catch(e=>console.error(e)):Yl.has(r)&&fi(r)},Bn(){let e=o();null!==e&&(bi(e,!1),!e.broken&&(e.x.ke("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var Pi={name:"scopes",install(){c.at=h(m,c.at,Bl),c.at=h(m,c.at,Kl),c.at=h(m,c.at,Ti),c.ar=ai,c.Eo=ui,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Cl.get(e)??[];if("disconnected"===t)for(let e of n)Ll(e);else if("reset"!==t&&Wl(Pt.get(e.root))===e){Rl(e,e.root);for(let e of n)Al.get(e.root).has(e.t)||Al.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();Rl(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:_l.get(n);void 0!==l&&Vl.set(e,{host:n,def:l})}(e,n)}),c.be=f(c.be,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=Vl.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),Oi(e,t,n,l,i,r,!1)}),c.ve=f(c.ve,(e,t,n)=>Oi(e,t,n,void 0,void 0,!1,!0)),c.Ae=h(d,c.Ae,(e,t,n,l,i)=>(function(e,t){let n=Cl.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=ei.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.d)l=i.dt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.y)&&!r.ro)&&(!!n||($i(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.pe}${""===r.E?"":`.${r.E}`}#ro: ${r.me.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.de;c.de=(t,n)=>{let l=Cl.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=ti.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)}}},Ei="$recursion",Wi=new WeakMap,Ii=new WeakSet,Ri=new WeakSet,Li=0,qi=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Di=e=>`[wcs/recursion-${e}]`;function zi(e,t){let n=n=>v(`${Di("declaration-invalid")} ${Ei} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${Di("declaration-invalid")} ${Ei} ${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 Fi=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function Ui(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 Bi(e,t,n){let l=Ui(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ae){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===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.`),Fi(e,i.k)+l}function _i(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${Di("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${Di("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(`${Di("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(`${Fi(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e._e(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._e(null,s).f,0))}function Vi(e,t){let n=function(e){let t=e[Ei],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&&q(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${Di("declaration-invalid")} ${Ei} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${Di("declaration-invalid")} ${Ei} must declare exactly one anchor (it declares ${i.length}).`);let r=zi("anchor",i[0][0]),o=zi("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(`${Di("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${qi(r)}((?:${qi(u)})*)${qi(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${qi(s)}((?:${qi(`.*.${a}`)})*)$`)}}(t),l=Wi.has(e);null!==n?(l||Li++,Wi.set(e,n),Ri.add(e),Ii.has(e)||function(e){Ii.add(e);let t=e,n=t.nt;t.nt=l=>{let i=Wi.get(e);if(l.t.includes("**")){let t=e.I.It(l.t)===l;return void(Ri.has(e)||void 0===i&&t?l.getter=()=>q(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.A=t.Ie++),i.owners.set(l,i.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=Wi.get(e);return l.call(e,void 0!==i&&t.includes("**")?Bi(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=Wi.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,Bi(r,n,t.u));(!Array.isArray(l)||l.length>0)&&v(`${Di("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=Ui(r,n),s=[];return _i(e,r,(t,n)=>{for(let l of i.call(e,Fi(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.yn;t.yn=(n,l,i,o)=>{let s=Wi.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(`${Di("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${Di("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.je>0&&b(8);let a=Ui(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(`${Di("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(`${Di("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];_i(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,Fi(s,t)+a,e.H(n),i);return h}}(e)):l&&(Wi.delete(e),Li--)}function Hi(e,t){if(0===Li)return!1;let n=Wi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.d){let l=n.owners.get(e);void 0!==l&&v(`${Di("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var Ki={name:"recursion",install(){c.de=f(c.de,Vi),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){Ri.delete(e)}(e)}),c.Ae=h(d,c.Ae,Hi)}},Ji="4.0.0-rc.9",Gi=e=>e.split(".").slice(0,2).join("."),Xi=class extends Kt{static find(e){return e.querySelector?.(ee.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 Gi(this.version)===Gi(Ji)}};function Yi(e){let t=ee.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Xi{})}var Qi=()=>ee.tagNames.ssr,Zi=Symbol.for("wcstack.ssr.snapshotBuilder"),er=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),tr=e=>document.createComment(e),nr=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,lr=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),ir=new WeakMap,rr=new WeakMap,or=new WeakMap,sr=new WeakSet,ar=new WeakMap;function ur(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function cr(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 fr=e=>null===e.L?e.qe:e.L[e.L.length-1];function hr(e,t,n){let l=[tr(null===n?"wcs-[":`wcs-[:${n}`)];for(let e of t)null===n&&l.push(tr("wcs-|")),l.push(...ur(e.qe,fr(e)));l.push(tr("wcs-]")),e.after(...l);for(let e of l)sr.add(e)}function dr(e){if(e instanceof it){hr(e.S,e.xe,null);for(let t of e.xe)pr(t);return}let t=e.O;null!==t&&(hr(e.G[e.G.length-1].S,[t],e.b),pr(t))}function pr(e){if(null!==e.c)for(let t of e.c)dr(t)}var mr=new Set(["script","style","template","textarea","title"]),gr="data-wcs-raw",yr=e=>mr.has(e.localName)||e.localName===Qi();function $r(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(tr("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(tr("wcs-s")):1===t.nodeType&&!yr(t)&&$r(t)}var vr=0;function wr(e,t){let n=e.getRootNode(),l=[t];for(let e of rr.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let i=new Map;for(let e of l){let t=ir.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.$&&n.set(t.$.S,t.$),null!==t.B)for(let e of t.B)n.set(e.S,e);for(let t of e.ce.values())for(let e of t)if(null!==e.W)for(let t of e.W.G)n.set(t.S,e.W);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),dr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=or.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>sr.has(e)||1===e.nodeType&&t.has(e)&&Ar(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(yr(e.parentNode)?ar.has(e):t.has(n)&&lr(n,"wcs-t:"))&&(ar.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);yr(e)&&n.some(e=>ar.has(e))&&e.setAttribute(gr,n.map(e=>ar.has(e)?`{{ ${ar.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}$r(9===n.nodeType?n.body:n);let r=document.createElement(Qi());r.setAttribute("version",Ji);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"}${vr++}`;e.replaceWith(tr(`wcs-p:${i}`));let o=document.importNode(Nt(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(cr(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(cr(t,s,o))}e.before(r)}function br(e){!function(e){if(null!==e.querySelector(ee.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=>ar.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(`${ee.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===Qi())continue;let e=t.engine;null!=e&&wr(t,e)}}var kr=Symbol.for("wcstack.state.ssr.impl"),Sr=new Map,xr=new WeakMap,Ar=e=>!0===c.Eo?.(e),Nr=e=>1===e.nodeType&&!yr(e)&&!Ar(e),jr=e=>e.f.flat().concat(e.K??[]),Or=e=>{for(let t of jr(e))t.remove()};function Cr(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&&!nr(s,"wcs-]");){let e=s.nextSibling;if(nr(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];lr(s,"wcs-[")?e=Cr(s,t,n):(n.push(s),Nr(s)&&Mr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,K:s??r.appendChild(tr("wcs-]"))},u=jr(a);s=a.K.nextSibling;for(let e of u)n?.push(e),t&&St.add(e);return t&&null!==i?Sr.set(i,a):Or(a),s}function Mr(e,t){for(let n=e.firstChild;null!==n;)lr(n,"wcs-[")?n=Cr(n,t):(Nr(n)&&Mr(n,t),n=n.nextSibling)}function Tr(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=tr(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!nr(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]?cr(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&&!yr(i)&&(Ar(i)?xr.set(i,{ssr:t,Oe: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||qr(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{lr(e,"wcs-[")?l++:nr(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(lr(l,"wcs-["))i++;else if(nr(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Mr(e,n)}function Pr(e){let t=xr.get(e);if(void 0===t||(xr.delete(e),Tr(e,t.ssr,t.Oe),!t.Oe))return null;let n=c.Oe;return c.Oe=Fr,()=>{c.Oe=n,Er()}}function Er(){for(let e of Sr.values())Or(e);Sr.clear()}function Wr(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Ir(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 Rr(e,t,n){if(er()){if(n instanceof Array){for(let e=n.length;e-- >0;)dt(n[e])&&n.splice(e,1);let e=t;if(n.some(pt))sr.add(e);else if(e.localName.includes("-")&&!Ar(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);or.set(e,t)}return}if("string"==typeof n){if(ar.set(t,n),yr(t.parentNode))return;let e=tr(`wcs-t:${encodeURIComponent(n)}`),l=tr("wcs-/t");return t.before(e),void t.after(l)}let l=ir.get(e);void 0===l&&ir.set(e,l=new Map),l.set(t,n);let i=t.getRootNode(),r=rr.get(i);return void 0===r&&rr.set(i,r=new Set),void r.add(e)}if("string"!=typeof n&&Sr.size>0){let e=Sr.get(n);void 0!==e&&(Sr.delete(n),Sr.set(t,e))}}var Lr=e=>null!==e&&8===e.nodeType&&[ee.commentIfPrefix,ee.commentElseIfPrefix,ee.commentElsePrefix].includes(e.data),qr=e=>3===e.nodeType&&""===e.data.trim(),Dr=e=>(Sr.get(e)?.K??e).nextSibling;function zr(e,t){if(t.length!==e.sn.childNodes.length)return!1;let n=e.On;for(let l=0;l<n.length;l++){let i=n[l],r=e.sn,o=t[i[0]];for(let e=0;;){if(r=r.childNodes[i[e]],o?.nodeName!==r.nodeName)return!1;if(++e===i.length)break;o=o.firstChild;for(let t=i[e];t>0&&null!==o;t--)o=Dr(o)}e.ko[l]=o}return!0}function Fr(e,t,n){if(0===Sr.size)return null;let l=t,i=0;if(!n){let e=ee.commentIfPrefix;if(!nr(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Lr(n)&&i++,!nr(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Sr.has(l)&&null!==n&&!nr(n,e)&&1!==n.nodeType;n=n.nextSibling)Lr(n)&&(l=n)}let r=Sr.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Sr.delete(l),Or(r),null;let o=r.f.shift();if(0===r.f.length&&Sr.delete(l),r.K?.replaceWith(...ur(t,l)),r.K=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Sr.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.K;)e++}if(!zr(e,s)){let n=(e.In?e.root:e.sn).cloneNode(!0);s=e.In?[n]:[...n.childNodes],zr(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 Ur={name:"ssr",install(){c.jn=Rr,c.hr=Pr;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||er())return;let n=t.previousElementSibling,l=n?.localName===Qi(),i=l?n.getAttribute("version"):null,r=null===i||Gi(i)===Gi(Ji);if(r){let t=e,n=t.ke;t.ke=(t,l)=>"$connectedCallback"===t?void 0:n.call(e,t,l)}if(!l)return;let o=!r&&parseInt(i)<4,s=/^3\.(\d+)\.(\d+)$/.exec(i),a=null!==s&&(+s[1]-5||+s[2]-3)>=0;r||console.warn(`[@wcstack/state] <${Qi()} version="${i}"> does not match ${Ji}: 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(`[${gr}]`)))e.textContent=e.getAttribute(gr),e.removeAttribute(gr);let h=9===f.nodeType?f.body:f;o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!Ar(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 > ${ee.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of re(t.getAttribute(ee.bindAttributeName)??"")){let t=l.Je;l.Ee[0]===r&&n.push([e?Ir(e,t,1,0):t,l.Ee.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:Ir(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]:Ir(l,r[2],2,1)??r[2]};for(let t of Wr(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!nr(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]?[tr(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of Wr(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=ee.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(h,n,a):Tr(h,n,r),n.remove(),r&&(c.Oe=Fr,queueMicrotask(()=>{Er(),c.Oe=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[kr]={build:br,reset(){vr=0}},void 0===e[Zi]&&(e[Zi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[kr].build(t),reset:()=>e[kr].reset()})}(),c.To=f(c.To,Yi);for(let e of Xt())Yi(e)}},Br="__WCSTACK_DEVTOOLS_HOOK__",_r=null,Vr=new Set,Hr=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),Kr=new WeakMap,Jr=0;var Gr=new WeakMap;function Xr(e){if(null===_r)return;let t=Gr.get(e),n=Vr.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=Kr.get(e);return void 0===t&&Kr.set(e,t=++Jr),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:Hr(e,o,c)})},r=e=>i(e.i,e.name,e.a,e.o,e.r,e.nn()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.he)for(let t of e.he)r(t);if(e instanceof Je&&null!==e.fe){let t=e.F.ze;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.fe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.c)for(let t of e.c)s(t)}},s=e=>{if(!l.has(e))if(l.add(e),e instanceof it){i(-1,"for",e.S,e.l.o,e.l.ae,"for");for(let t of e.xe)o(t)}else null!==e.O&&o(e.O)};for(let t of e.ce.values())for(let e of t)r(e),null!==e.W&&s(e.W);for(let t of e.oe.values())if(null!==t.$&&s(t.$),null!==t.B)for(let e of t.B)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||_r({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&_r({type:"state:binding-added",...l});Gr.set(e,n)}function Yr(e){let t=Pt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function Qr(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.I.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.ie&&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.Re.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 Zr=new WeakSet,eo=new WeakMap;function to(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Zr.has(t))return;Zr.add(t);let l=t.emit;t.emit=(...i)=>(null!==_r&&_r({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.Re.values())t(n,"event")}(e),"connected"===t){if(Vr.has(e))return;Vr.add(e),_r?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Xr(e)}else"disconnected"===t&&(Vr.delete(e),Xr(e),_r?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function no(e,t,n,l,i,r){if(null===_r)return;let o=Hr(e,t,0===t.n?null:n),s=eo.get(e);void 0===s&&eo.set(e,s=new Set),s.add(o),r&&_r({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function lo(e){if(null===_r)return;let t=eo.get(e);eo.delete(e),void 0!==t&&_r({type:"state:update-batch",addresses:t}),Xr(e)}function io(e,t,n){_r?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.nn(),error:t})}var ro={"*":["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 oo(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...ro["*"],...Object.hasOwn(ro,e)?ro[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())}([pn,Vn,gl,xl,Pi,Ki,Ur,{name:"devtools",install(){c.element=f(c.element,to),c.be=f(c.be,no),c.Fe=f(c.Fe,lo),c.Ue=f(c.Ue,io),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[Br]??(e[Br]=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:Ji,getStateElements:()=>[...Vr].map(Qr),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.I.all()){let l=n._,i=n.Ce?.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}(Yr(e)),keys(e){let t=Yr(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 Yr(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){Yr(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===_r&&null!==e;_r=e,null===e&&(Gr=new WeakMap),c.st=e&&((e,t)=>_r?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of Vr)Xr(e)})}})}()}},{name:"native-commands",install(){c.or=oo}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Rt]&&(e[Rt]={protocol:"wcs-binder",version:1,bind:zt})})(),Xt().includes(e)||Gt.push(new WeakRef(e));let t=ee.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Jt{}),c.To?.(e)}();
|
|
1
|
+
var e=class{constructor(e,n,l){this.c=[],this.getter=null,this.ie=null,this.se=!1,this.M=[],this.J=[],this.ft=null,this.A=-1,this.z=t,this.Ce=null,this.Ot=null,this.Ct=null,this._=null,this.pn=!1,this.mn=!1,this._n=!1,this.Z=0,this.pt=new Set,this.t=e,this.d=l,this.s=n;let i=null===l?[null]:l.h.slice(),r="*"===n;r&&i.push(l),this.n=i.length-1,this.K=r?[]:null===l?[n]:[...l.K,n],this.h=i}Wn(e){this.pt.has(e)||(this.pt.add(e),this.M.push(e),e.J.push(this))}Io(e){this.pt.delete(e);let t=this.M;t.splice(t.indexOf(e),1)}jo(){this.getter=null,this.ie=null,this.A=-1,this.z=t,this.M.length=0,this.pt.clear(),this.J.length=0,this.ft=null,this.Ce=null,this.Ot=null,this.Ct=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.d}return!1}},t=Symbol("unset"),n=Symbol("dirty"),l=Symbol("failed"),i=class{constructor(e=null){this.mt=new Map,this.Vn=e}It(e){return this.mt.get(e)}get(t){let n=this.mt.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.mt.set(t,n),i&&i.c.push(n),n}all(){return this.mt.values()}jt(e){this.mt.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.ht=null,this.$=null,this.he=null,this._=null,this.c=null,this.y=!0,this.l=e,this.b=t,this.R=n}},a=class{constructor(e,t){this.C=null,this.f=[],this.$=null,this.B=null,this.te=!1,this.Lt=!1,this.yt=!1,this.o=e,this.ae=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.Dt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Dt(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 b(e,t=[]){return c.Do?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function w(e,t,n,l){v(b(e,t),n,l)}var k=class{constructor(e){this.wt=new Set,this.name=e}get size(){return this.wt.size}subscribe(e){return this.wt.add(e),()=>{this.wt.delete(e)}}unsubscribe(e){return this.wt.delete(e)}emit(...e){let t=[];for(let n of this.wt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${b(17,[this.name])}`,e)}return t}};function S(e,t,n){if(void 0===e)return[];Array.isArray(e)||w(18,[t]);let l=new Set;for(let i of e)("string"!=typeof i||""===i)&&w(19,[t]),i===n&&w(20,[t,i,n]),l.has(i)&&w(21,[t,i]),l.add(i);return e}var x=Symbol.for("wcstack.transition-runner");function N(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 A(e,t,n){let l=N(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&&w(107,[i,e]),a(!0),{args:t,literals:n}}var W=e=>e.trim();function I(e,t){let n=[],l=null;for(let i=0;i<e.length;i++){let r=e[i];null!==l?r===l&&(l=null):"'"===r||'"'===r?l=r:r===t&&n.push(i)}return n}var R=(e,t)=>I(e,t)[0]??-1;function L(e,t){let n=[],l=0;for(let i of I(e,t))n.push(e.slice(l,i)),l=i+1;return n.push(e.slice(l)),n}function q(e,t,n){let l=R(e,"|");if(-1===l)return[e.trim(),[]];let i=e.slice(l+1).trim(),r=n.get(i);return void 0===r&&(r=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>I(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&w(108,[e]),-1!==i&&-1===n&&w(109,[e]),-1!==i&&i<n&&w(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();w(111,[e,t])}let r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&w(112,[l]),r.includes("#")){let[,e]=r.split("#");w("input"===t?113:114,[r,e])}return-1===n?{Hn:r,args:[],literals:[]}:{Hn:r,...E(e.substring(n+1,i))}})}(L(i,"|").map(W),t,e),n.set(i,r)),[e.slice(0,l).trim(),r]}var D=new Map;function z(e){w(1101,[e])}function F(e){let[t,n]=q(e,"output",D);t.includes("@")&&w(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)&&w(119,[e]),function(e){e.includes("**")&&z(e);let t=e.split(".").length;t>512&&w(117,[e,t])}(l),{Je:l,Ze:n}}var U=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function _(e){return e.includes("**")&&z(e),e}var V=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=()=>[];function G(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Y(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function Q(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function Z(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ae;return null!==e&&e.l.n===t?e:null}function ee(e,t,n){let l=Z(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var te=class{constructor(e,t){this.Ie=0,this.u=null,this.je=0,this.bt=new Set,this.et=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.vt=[],this.Le=null,this.qn=[],this.Vt=0,this.X=null,this.oe=new Map,this.ce=new Map,this.Be=[],this.De=[],this.Me=[],this.kt=!1,this.hn=!1,this.Ht=new WeakMap,this.W=0,this.Ut=0,this.gn=!1,this.qt=!1,this.Kt=!1,this.Pe=0,this.Kn=()=>{this.W=0,this.gn=!1},this.zn=()=>{this.Pe--},this.rp=null,this.rr=null,this.Mo=()=>this.zt(),this._o=(e,t)=>e(this.proxy,...t),this.Xn=[],this.tt=[],this.Wo={$untracked:e=>{let t=this.X;if(null===t)return e();t.ye++;try{return e()}finally{t.ye--}},$eqIndex:(e,t=1)=>{let n=Z(this.u,t);null===n&&w(7,[e]);let l=this.o(e);if(null!==l.getter||l.se)return this.watchIndex(t),n.b===this.read(l,null);let i=this.X;if(null!==i){let e=i.getter,n=l.Ce??(l.Ce=[]);if(!n.some(n=>n.getter===e&&n.Yn===t)){n.push({getter:e,Yn:t});let i=e.h[t];(i.Ot??(i.Ot=[])).push({source:l,getter:e})}}return n.b===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,Z(this.u,n.n)))},$dependOn:e=>{this.resolve(_(e),this.u),null!==this.X&&0===this.X.ye&&this.Gn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.yn(e,t,n,l),$resolve:(...e)=>{let t=_(e[0]),n=e[1]??[],l=this.o(t,!0);this.wn("$resolve",t,l,n,!0);let i=this.Qn(l,n,null);if(e.length<3)return this.read(l,i);this.T(l,i,e[2])},$postUpdate:e=>{this.resolve(_(e),this.u);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.R=n.l.C[n.b],this.P.Xt(n)),this.bn(t,n),null!==n&&this.Jn(n,t,void 0,n.R,!1),0===t.n&&this.Zn(t,void 0,void 0,!0),this.Yt(t,n,void 0,void 0,!1)}},this.P=t,this.I=new i(e=>{this.tt.push(e),this.nt(e)}),this.eo(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.ot(t);if(t.indexOf(".")<0){let e=n.I.It(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.u),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(_(t),n.u),n.T(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.I.get(e);return t||(n.pn=!0),n}to(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let l=Object.getOwnPropertyDescriptor(n,e);if(void 0===l.get&&void 0===l.set)continue;let i=this.o(e);i.getter=l.get??null,i.ie=l.set??null,null!==i.getter&&i.n>0&&(i.A=this.Ie++)}for(let e of this.I.all())this.nt(e)}nt(e){e.t.includes("**")&&z(e.t),("__proto__"===e.s||"prototype"===e.s)&&w(120,[e.t]);let t=e.d;e.se=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.se),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(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.u),this.rp!==e?this.read(this.rp,this.rr):this.read(e.d,this.u)?.[n]),e.ie=l=>{if(this.resolve(t,this.u),this.rp!==e)return this.T(this.rp,this.rr,l);let i=this.read(e.d,this.u);null==i&&w(4,[t,i]),i[n]=l}}e._n=!0,e.n>0&&(e.A=this.Ie++)}_e(e,t){let n=null===e?this.oe:e.c??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new a(t,e)),t.pn=!0,this.Y(l),l}no(e){try{this.Y(e)}catch(t){this.Gt(t,e.o.t,e.$?.S??null,"for")}}Y(e){let t=this.v(e.o,e.ae);if(t===e.C)return;this.oo(e);let n=function(e,t,n){let l=Array.isArray(t)?t:u;if(l===e.C)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].R===l[c];)a[c]=i[c],c++;let f=o-1,h=r-1;for(;f>=c&&h>=c&&i[f].R===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].R===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.R);void 0===l?r.set(n.R,n):Array.isArray(l)?l.push(n):r.set(n.R,[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.b!==e&&(t.b=e,n.Lo(t))}return e.f=a,e.C=l,i}(e,t,this);if(null===n)return;if(e.C===t){let n=H(this.Ht,t,J);if(n.push(e),n.length>1)for(let e of n)e.yt=!0}c.Qt?.(this,e,n),(null!==e.$||null!==e.B)&&!e.te&&(e.te=!0,this.De.push(e),this.Te());let l=e.o.Ot;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.y&&this.vn(i,r),void 0!==o&&this.vn(i,o))}}Lo(e){this.P.Ho(this,e)}Bt(e){e.y=!1;let t=e._;if(null!==t){for(let e of t)Y(e.source,e.key,e.sub);e._=null}if(null!==e.c)for(let t of e.c.values()){this.oo(t);for(let e of t.f)this.Bt(e)}}oo(e){let t=this.Ht.get(e.C);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.yt=!1,1===t.length&&(t[0].yt=!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?ee(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._e(i,a),f=t[s++];if(f<0)f=ee(n,e,o)?.b??-1;else if(l&&c.C===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}rt(e,t){return 0===e.n?Q(this.target,e.K):null===t?void 0:Q(t.R,e.K)}read(e,t){let n=this.X;if(null!==n&&0===n.ye&&this.Gn(e,t,n),null!==e.getter)return this.P.Uo(this,e,t);if(e.se){let n=this.read(e.d,t);return n?.[e.s]}return null===e.d&&!(e.s in this.target)&&!this.bt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&w(301,[e.t],e.s,Object.keys(this.target)),this.rt(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.ye++;try{return this.read(e,t)}finally{n.ye--}}Gn(e,t,n){let l=n.getter;e.Wn(l),0===l.n?e.Z!==n.ue&&(e.Z=n.ue,n.kn.push(e)):e.n>0&&Z(t,Math.min(e.n,l.n))!==Z(n.r,Math.min(e.n,l.n))&&(l.ft??(l.ft=new Set)).add(e)}qo(e,t){for(let n=0;n<this.Vt;n++){let l=this.qn[n];l.getter===e&&l.r===t&&w(701,[e.t])}this.Vt>=128&&w(801,[e.t]);let n=this.Vt++;this.je++;let l=this.qn[n]??={getter:e,r:t,ye:0,ue:0,kn:[]};l.getter=e,l.r=t,l.ye=0,l.ue=++V,l.kn.length=0;let i=this.X;this.X=l;let r=this.u;this.u=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Ko(e,l),t}finally{this.je--,this.Vt--,this.X=i,this.u=r,l.r=null}}Ko(e,t){let n=t.ue;for(let e of t.kn)e.Z=n;e.J=e.J.filter(t=>t.Z===n||t.n>0||!t.se&&Array.isArray(null!==t.getter?t.z:this.rt(t,null))||this.io(t,e))}io(e,t){return e.Io(t),this.tt.push(e),!1}zo(){for(let e=this.tt;e.length>0;e=this.tt){this.tt=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.d||n.c.length>0||n.M.length>0)&&(null===n.getter||n._n&&n.A<0)&&null===n._){n.mn=!0,this.I.jt(n),t.add(n.d);for(let e of n.J)this.io(e,n)}for(let e of t)(e.c=e.c.filter(e=>!e.mn)).length||this.tt.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.ye){let n=t.getter,l=n.h[e];if(l){let e=l.Ct??(l.Ct=[]);e.includes(n)||e.push(n)}}}ot(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)&&w(1001,[e]),this.watchIndex(n),Z(this.u,n)?.b}let n=this.Wo[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.ot?.(this,e)}eq(e,t){this.resolve(e,this.u);let n=this.rp,l=this.rr;if(null!==n.getter||n.se||n.n>0)return X(this.read(n,l),t);let i=this.X;return null!==i&&0===i.ye&&this.Xo(n,t,i),X(this.v(n,null),t)}Xo(e,t,n){let l=n.getter,i=n.r,r=null===i?this.Xn:i._??(i._=[]);for(let i=0;i<r.length;i++){let o=r[i];if(o.sub.getter===l&&o.source===e){if(X(o.key,t))return void(o.ue=n.ue);o.ue!==n.ue&&(Y(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,ue:n.ue})}Zn(e,t,n,l){this.Jt(e,i=>{let r=i._;if(null===r&&null===i.Ce)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),s=Q(t,o),a=Q(n,o);if(null!==i.Ce&&this.Yo(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.y?this.P.we(this,n.getter,n.r):Y(i,e,n)}})}T(e,t,n,l=!1,i=!1){if(this.je>0&&w(8),i||this.Pe>0?this.qt=!0:this.Kt=!0,c.Ae?.(this,e,t,n,i))return;if(null!==e.ie){try{this.Sn(e.ie,t,[n])}finally{this.Yt(e,t,void 0,void 0,!1)}return}null!==e.getter&&w(2,[e.t]),e.n>0&&null===t&&w(3,[e.t]);let r=e.se?this.v(e,t):this.rt(e,t);if(l||!this._t||!Object.is(r,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.C[e.b]=n,e.R=n,this.P.Xt(e)}else{let l=1===e.K.length?0===e.n?this.target:t.R:this.v(e.d,t);null==l&&w(4,[e.t,l]),l[e.s]=n}this.En(e,t),null!==t&&this.Jn(t,e,r,n),0===e.n&&this.Zn(e,r,n),this.Yt(e,t,r,n,!0)}}so(e){return(this.Ht.get(e.C)??[]).filter(t=>t.C===e.C&&(null===t.ae||t.ae.y))}Jn(e,t,l,i,r=!0){let o=e.l;if(!o.yt&&null===o.o.getter&&!o.o.M.length)return;let s=e.R,a=t.t.slice(o.o.t.length+2),u=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${a}`,!0);""===a&&(n.R=i,this.P.Xt(n)),r?this.En(o,n):this.bn(o,n),this.Yt(o,n,l,i,r)};for(let t of this.so(o))u(t,t.f[e.b]);if(""===a)return;let c=new Set([o.C]),f=e=>Array.isArray(e)&&e.includes(s),h=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.Ht.get(e)??[])for(let e of t.f)e.R===s&&u(t,e);for(let l of t){let t=l.z,i=t===n;i&&(t=this.oe.get(l)?.C),(i||f(t))&&!c.has(l.M)&&c.add(l.M)&&(!i&&t!==e&&this.P.we(this,l,null),h(t,l.M))}},d=e=>{for(let t of e.J)if(!c.has(t)&&c.add(t))if(null!==t.getter)d(t);else if(!t.se){let e=this.rt(t,null);f(e)&&h(e,t.M)}};null!==o.o.getter?d(o.o):h(o.C,o.o.M)}bn(e,t){this.Go(e,t,e=>{this.Y(e);for(let t of e.yt?this.so(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.St(e,n),this.bn(e,n)}})}En(e,t){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.Y(t)}Go(e,t,n){let l=null===t?this.oe:t.c;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Yo(e,t,n,l){for(let{getter:i,Yn:r}of e.Ce)this.lo(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.vn(i,t)}})}vn(e,t){t.l.n===e.n?this.P.we(this,e,t):this.Zt(t,e,t=>this.P.we(this,e,t))}Yt(e,t,n,l,i){c.be?.(this,e,t,n,l,i),this.We(e,t)}We(e,t){this.P.Qo(this,e,t),this.Te()}ao(e){let t=this.et.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.et.set(e,n);let l=this.root,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.y&&o.Jo(e,t))return}}),n}reset(e){let t=this.target,n=this.bt;for(let e of this.I.all())null===e.d&&null!==e.getter&&n.add(e.s);this.eo(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.ce.values())for(let t of e)this.en(t);for(let e of this.oe.values())this.co(e);this.Le=null;try{this.zt()}finally{this.$n()}c.element?.(this,"reset")}eo(e){for(let[t,n]of U)void 0!==e[t]&&$(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||w(46);for(let e of t)$(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&w(44,["state","$behavior"]);for(let e in n)(!B.includes(e)||"boolean"!=typeof n[e])&&w(44,["$behavior",e]);let[l,i,r]=B.map(e=>n[e]??!0);void 0!==this.target&&(l!==this.Mt||i!==this._t||r!==this.Wt)&&w(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)&&w(22);for(let[e,i]of Object.entries(l)){let l=n.get(e);void 0===l&&w(23,[e]),"function"!=typeof i&&w(24,[e]),l.subscribe((...e)=>t(i,e))}return n}(e,this._o);this.Mt=l,this._t=i,this.Wt=r,c.de?.(this,e),this.target=e,this.Ie=0;for(let e of this.I.all())e.jo();this.Xn.length=0,this.to(e),this.commands=o,this.Re=s}co(e){this.no(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.ht=null,n._=null,this.St(t,n),null!==n.c)for(let e of n.c.values())this.co(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ae)t.unshift(n.b);return t}Zo(e,t,n){let l=this.Re.get(e);void 0===l&&w(1301,[e],e,this.Re.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&w(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&w(5,[e]),this.Sn(l,n,[t,...this.H(n)])}Sn(e,t,n){let l=this.u;this.u=t;try{return e.apply(this.proxy,n)}finally{this.u=l}}St(e,t){if(null!==e.getter){let n=null===t?this.oe:t.c;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Me.push(t))}if(null===t)return void this.Jt(e,e=>{let t=this.ce.get(e);if(void 0!==t)for(let e of t)this.en(e)});let n=t.he;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.en(n[t]);let l=t.$;null!==l&&null!==l.fe&&l.uo(this,e);let i=t.l.B;if(null!==i)for(let n of i){let l=n.map.get(t);void 0!==l&&null!==l.fe&&l.uo(this,e)}}Nn(e,t,n){this.Jt(e,e=>{let l=e.M;for(let i=0;i<l.length;i++){let r=l[i];if(0===r.n)this.it(r,null,n);else if(null===t||0===e.n||r.h[1]!==e.h[1]||null!==r.ft&&r.ft.has(e))this.tn(r.h[r.n],e=>this.it(r,e,n));else if(r.n<=e.n){let e=Z(t,r.n);null!==e&&this.it(r,e,n)}else this.Zt(t,r,e=>this.it(r,e,n))}})}it(e,t,n){n(e,t)&&(c.ve?.(this,e,t),this.St(e,t),this.Nn(e,t,n))}Jt(e,t){t(e);let n=e.c;for(let e=0;e<n.length;e++)this.Jt(n[e],t)}tn(e,t){this.lo(e,e=>{for(let n of e.f)t(n)})}lo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.tn(e.h[e.n],n=>{let l=n.c?.get(e);void 0!==l&&t(l)})}Zt(e,t,n){if(e.l.n===t.n)return n(e);let l=e.c?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.Zt(e,t,n)}nr(e){let t=e.r;null===t?H(this.ce,e.o,K).add(e):(t.he??(t.he=[])).push(e)}xn(e){let t=e.r;if(null===t)return void this.ce.get(e.o)?.delete(e);let n=t.he;t.y&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}en(e){e.te||(e.te=!0,this.Be.push(e),this.Te())}Te(){this.kt||(this.kt=!0,queueMicrotask(this.Mo))}Rn(){for(let e of this.Be)e.te=!1;for(let e of this.De)e.te=!1;for(let e of this.Me)e.Lt=!1;this.Be=[],this.De=[],this.Me=[],this.P.bt(this)}fo(e,t){let n=[...new Set([...this.Be,...this.De,...this.Me].map(e=>e.o.t))];console.error(`[@wcstack/state] ${b(e)}`,n),c.st?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Rn()}zt(){this.kt=!1;let e=this.Ut;this.Ut=0;let t=0;if(!this.qt||this.Kt?this.Kn():e>0?t=e:1===(t=++this.W)&&setTimeout(this.Kn,0),this.qt=this.Kt=!1,t>100)101===t?this.fo(41,100):this.Rn();else{this.hn=!0;try{for(let e=0;this.Be.length>0||this.De.length>0||this.Me.length>0;e++){if(e>=32){this.gn?this.Rn():this.fo(11,32),this.gn=!0;break}let n=this.Me;if(n.length>0){this.Me=[];for(let e of n)e.Lt=!1,this.no(e)}let l=this.De,i=this.Be;this.De=[],this.Be=[];let r=A("state",()=>{for(let e of l){e.te=!1;for(let t of[e.$,...e.B??[]])if(null!==t&&t.y)try{t.Et()}catch(n){this.Gt(n,e.o.t,t.S,"for")}}for(let e=0;e<i.length;e++){let t=i[e];t.te&&(t.te=!1,(null===t.Pn||t.Pn.y)&&this.Ve(t))}this.hn||(this.He(),this.kt&&(this.Ut=t+1))});void 0!==r&&r.then(void 0,e=>console.error(e))}}finally{this.hn=!1}this.qt=this.Kt=!1,this.He(),c.Fe?.(this),this.zo(),e>0&&this.kt&&(this.Ut=t+1)}}$t(e,t){this.vt.push([e,t])}Gt(e,t,n,l){this.$t(e,{o:{t},a:n,nn:()=>l})}Ve(e){try{e.apply()}catch(t){return void this.vt.push([t,e])}null!==this.Le&&this.po(e.o,e.r)}po(e,t){let n=H(this.Le,e.t,J);null!==t&&n.push(this.H(t))}$n(){this.Le="function"==typeof this.target.$renderedCallback?new Map:null}He(){let e=this.Le;if(null!==e&&e.size>0){this.Le=new Map;let t,n=[...e.keys()],l={};for(let[t,n]of e)n.length>0&&(l[t]=n);this.Pe++;try{t=this.ke("$renderedCallback",[n,l])}catch(e){console.error(e)}G(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Pe--}if(0===this.vt.length)return;let t=this.vt;this.vt=[];let n=this.target.$errorCallback;for(let[e,l]of t){c.Ue?.(this,e,l);let t=l.o.t,i=l.nn();if("function"==typeof n)try{let n=this.ke("$errorCallback",[e,{path:t,bindingType:i,node:l.a}]);G(n)&&n.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${b(12,[i,t])}`,e)}}ke(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Sn(n,null,t):void 0}mo(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._e(o,s),u=t=>{l.push(t.b),r===e.n?n(t,l):i(r+1,t),l.pop()};for(let e of r-1<t.length?[a.f[t[r-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.wn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.u;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=ee(t,n,e);if(null===i)break;l.push(i.b)}0===l.length&&w(6,[e])}}let i=[];return this.mo(n,l,e=>i.push(this.read(n,e))),i}yn(e,t,n,l){Array.isArray(t)||w(9,[e]),this.je>0&&w(8);let i=this.o(e,!0);this.wn("$setAll",e,i,t,!1);let r=[];this.mo(i,t,(e,t)=>r.push([e,t.slice()]));let o=!0===l?.spread;o&&(!Array.isArray(n)||n.length!==r.length)&&w(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.T(i,t,a),s++)}return s}wn(e,t,n,l,i){let r=l.length;(r>n.n||i&&r<n.n)&&w(i?901:902,[e,t,n.n,r])}},ne={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},le=new Map,ie=new Set(["if","elseif","else","for"]),re=new Set([j,"if","elseif","for","..."]),oe=new Set([C,M,"style","command",O,"state"]);function se(e){let t=function(e){return L(e,";")}(e).map(W).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&w(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(re.has(i)){let t;return i!==n&&w(102,[e,i]),i===j?(l.length>0&&w(103,[e]),t={Je:"#else",Ze:[]}):"..."===i?(0===l.length&&w(104,[e]),t=F(l),t.Ze.length>0&&w(105,[e])):(t=F(l),"for"===i&&t.Ze.length>0&&w(121,[e])),{Se:i,Ee:[i],on:[],j:[],...t,w:"..."===i?"spread":i}}(i===C||i===M)&&w(122,[e,i]);let r=F(l),o=function(e){let[t,n]=q(e,"input",le),l=t.split("#").map(W);l.length>2&&w(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))&&w(116,[e]),{Se:i,Ee:o,on:r?r.split(",").map(W):[],j:n}}(n),[s]=o.Ee;if(""===s&&o.Ee.length>1){let e=o.Ee.slice(1);return(e.includes("")||oe.has(e[0]))&&w(106,[n]),{...o,Se:e.join("."),Ee:e,...r,w:"prop"}}return{...o,...r,w:"radio"===i||"checkbox"===i?i:s===O||s.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ie.has(e.w))&&w(201,[e]),t}var ae=["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"],ue=new Map,ce=new Map;function fe(e){for(let t of Object.keys(e))ue.set(t,{...e[t]});ce.clear()}function he(e){return ue.has(e)}function de(e){w(26,[e])}function pe(e){w(27,[e])}function me(e){w(28,[e])}function ge(e){w(29,[e])}function ye(e){return!(!e||isNaN(Number(e)))}function $e(e,t){return ye(e)||pe(t),Number(e)}function ve(e,t,n){return $e(e?.[t]??de(n),n)}function be(e,t){return void 0!==t&&t.length>0?t[0]:e}var we=(e,t)=>({factory:n=>{let l=ve(n,0,e);return n=>("number"!=typeof n&&me(e),t(n,l))},arity:[1,1]}),ke={eq:{factory:(e,t)=>{let n=e?.[0]??de("eq"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(ye(n)||pe("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??de("ne"),l=be(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(ye(n)||pe("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:we("lt",(e,t)=>e<t),le:we("le",(e,t)=>e<=t),gt:we("gt",(e,t)=>e>t),ge:we("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]}},Se=!1;function xe(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:(Se||(Se=!0,fe(ke)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=ce.get(l);if(typeof i<"u")return i;let r=ue.get(e);void 0===r&&function(e,t){ae.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),w(501,[e],e,t)}(e,ue.keys());let[o,s]=r.arity;t.length<o&&w(601,[e,o,t.length]),t.length>s&&w(602,[e,s,t.length]);let a=r.factory(t,n);return ce.set(l,a),a}(e.Hn,e.args,e.literals)))}var Ae=Symbol.for("wcstack.trustedTypes.policy");function je(){let e=globalThis[Ae];return null!==e&&"object"==typeof e?e:null}function Oe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ce(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=je(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Me=Symbol.for("wcstack.state.view-transition-naming"),Te=new WeakSet;function Pe(){let e=N("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Ee=new WeakMap,We=e=>e.customElementRegistry??customElements;function Ie(e,t,n,l,i,r=!1){let o=n.localName;if(!o.includes("-"))return i(null);let s=We(n);if(!r&&!n.isConnected&&void 0===s.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Ie(e,t,n,l,i,!0));let a=()=>{let e=s.get(o);s.upgrade(n),i(e?function(e){if(Ee.has(e))return Ee.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,ho:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Ee.set(e,n),n}(e):null)};if(!r&&void 0!==s.get(o))return a();null!==l&&!l.y||function(e,t,n){let l=n;null!==t&&(t.Nt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(s.whenDefined(o),l,()=>{try{a()}catch(l){Fe(e,l,t,n)}e.Te()})}function Re(e,t,n,l,i=t.o,r,o,s){let a=s.properties.get(l)??null,u=s.inputs.has(l),f=e.Wt;f&&null===a&&!u&&w(38,[l]);let h=t.U;(null===a?"element"===h||"auto"===h:!u&&("state"===h||"auto"===h))&&w(39,[h,l]),"connect"===t.Y&&null===a&&w(40,[l]);let d=f&&null!==a&&!u,p=new _e(e,De,n,l,i,r,o,t.N,void 0);p.j=t.j,Qe(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.ho||c.detail?.(n,l,i)),(!p.Tn||!Object.is(i,p.value))&&(i=xe(p.j,i),null===p.N&&(p.value=i),e.T(p.o,p.r,i,a.ho,!0))});let m=h??(d?"element":"state");if("state"===m)d||e.Ve(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.y)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(d||e.Ve(p));let t=n[l];null===p.N&&(p.value=t),e.T(p.o,p.r,t,!1,!0)};"connect"!==t.Y||n.isConnected?i():Promise.resolve().then(i)}return p}function Le(e,t,n){w(e,[t.localName,n])}var qe=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),De=11,ze=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,l)=>e.Gt(t,n.o?.t??n.xt,l,ze[n.i]),Ue=Symbol();function Be(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.q:Ue}var _e=class{constructor(e,t,n,l,i,r,o,s,a,u=null){this.te=!1,this.j=null,this.Tn=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=i,this.r=r,this.Pn=o,this.N=s,this.value=a,this.W=u}nn(){return ze[this.i]}apply(){if(null!==this.W)return void this.W.Et();let e=xe(this.N,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===De||8===this.i||Oe(this.name)))return;if(this.value===Ue)return void(this.value=e);let t=this.a;if(this.i!==De)9===this.i?t.checked=void 0!==e&&this.rn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.rn()):He(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.Tn=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.Tn=!1}}}rn(){return xe(this.j,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.rn()}else if(10===this.i){let l=this.rn(),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=xe(this.j,t[this.name]),this.value=NaN;n.T(this.o,this.r,e,!1,!0)}},Ve=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function He(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ve(n)?t[n]="innerHTML"===n?Ce(l):null==l?"":String(l):Oe(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=Ce(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ke]=[n,l])));case 8:return void(t.innerHTML=Ce(l));case 2:return null!=l&&"boolean"!=typeof l&&w(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Ke=Symbol();function Je(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ke];void 0!==n&&(t[n[0]]=n[1])}var Ge=class{constructor(e,t,n,l){this.y=!0,this.he=null,this.c=null,this.Nt=null,this.Fn=null,this.r=e,this.qe=t,this.L=n,this.F=l}Jo(e,t){let n=t.target,l=this.F,i=[],r=null;for(let t of l.Re){if(t.name!==e)continue;let o=l.On[t.a],s=st(null===this.L?this.qe: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.An(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.qe:this.L[this.L.length-1]}Ke(){let e=this.Fn;return(null===e?null:e.Cn(this.qe))??this.qe}insertBefore(e,t){let n=this.s;for(let l=this.Ke();;){let i=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=i}}wo(){null===this.L?this.qe.remove():at(this.Ke(),this.s)}Ne(e){if(this.y=!1,null!==this.Nt)for(let e of this.Nt)e();let t=this.he;if(null!==t)for(let n=0;n<t.length;n++)e.xn(t[n]);if(null!==this.c)for(let e of this.c)e.Ne()}},Xe=class extends Ge{constructor(e,t,n,l){super(e,t,n,l),this.bo=0,this.V=null,this.fe=0===l.ze.length?null:new Array(2*l.ze.length)}vo(e,t){let n=this.V??=new Array(this.F.ze.length),l=n[t];if(void 0===l){let i=this.F.ze[t],r=this.fe;l=n[t]=new _e(e,i.i,r[2*t],i.name,i.o,this.r,this,i.N,r[2*t+1])}return l}uo(e,t){let n=this.F.ze;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.en(this.vo(e,l))}Ne(e){let t=this.r;t.$===this&&(t.$=null),super.Ne(e)}};function Ye(e,t,n,l){let i=Z(n,t.n);try{return e._e(i,t)}catch(n){return e.Gt(n,t.t,l,"for"),null===i?e.oe.get(t):i.c.get(t)}}function Qe(e,t,n){n&&e.nr(t);let l=t.Pn;null!==l&&(l.he??=[]).push(t)}var Ze=null;function et(){let e=Ze;return Ze=null,e}var tt=-1;function nt(e,t,n,l,i=null){let r,o=t.On,s=t.build,a=t.ko,u=null,f=c.Oe?.(t,null===l?i:l.S,null!==l),h=!f&&t.In,d=f?document.createDocumentFragment():(h?t.root:t.sn).cloneNode(!0);if(!f)for(let e=0;e<s.length;e++){let t=s[e];a[t]=st(d,o[t],h?1:0)}h?r=d:(u=f||[...d.childNodes],r=u[0]);let p,m=null;if(null!==l?(p=m=new Xe(n,r,u,t),null===l.map?n.$=m:l.map.set(n,m)):p=new Ge(n,r,u,t),tt>=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||Te.has(i))return;let o=globalThis[Me]??={counter:0,assigned:0,warned:!1};o.assigned>=l?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${b(25,[l])}`)):(Te.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",tt),t.Re.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.Le,$=t.lr?a.slice(0,o.length):a,v=null===m?null:m.fe;if(null!==v){let e=t.ze;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.A;if(o>=0&&null!==v){let t=m.V?.[o];if(void 0!==t){t.te=!1,e.Ve(t);continue}try{let t=xe(l.N,e.read(l.o,n));t!==l.q&&(He(l.i,i,l.name,t),v[2*o+1]=t),null!==y&&e.po(l.o,n)}catch(t){e.$t(t,m.vo(e,o))}continue}switch(l.i){case 6:{let t=new ot(e,l.F,Ye(e,l.o,n,i),i);(p.c??=[]).push(t),i===r&&(p.Fn=t),t.Et();break}case 7:{let t=it(e,l.G.map(e=>({F:e.F,o:e.o,N:e.N,S:$[e.a]})),n,p);(p.c??=[]).push(t),i===r&&(p.Fn=t);break}default:try{lt(e,l,i,n,p)}catch(t){Fe(e,t,l,i)}}}return Ze=p,d}function lt(e,t,n,l,i){let r=n;switch(t.i){case 5:return void function(e,t,n,l,i){let r=n.An,o=e=>r(e,l);if(n.et){let l=e.ao(n.name),i=t[l];t[l]=void 0===i?o:e=>{i(e),o(e)},n.$e&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.yo&&null!==i&&(i.Nt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,l,i);case 12:return void Ie(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name,o=e.command(t.xt.slice(9)),s=null===i?c.or?.(n,r):null;s||(null===i&&Le(1202,n,`command.${r}`),i.commands.has(r)||w(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.Nt??=[]).push(u)}(e,t,r,i,n));case 13:return void Ie(e,t,r,i,n=>function(e,t,n,l,i){let r=t.name;null===i&&Le(1202,n,`eventToken.${r}`);let o=i.properties.get(r);void 0===o&&w(1204,[n.localName,r]);let s=t.xt;n.addEventListener(o.event,n=>{t.Rt&&n.preventDefault(),t.Pt&&n.stopPropagation();try{e.Zo(s,n,l)}catch(e){console.error(e)}})}(e,t,r,l,n))}let o=t.o,s=Z(l,o.n);if(14===t.i)return void Ie(e,t,r,i,n=>function(e,t,n,l,i,r){null===r&&Le(1501,n,`"...: ${t.o.t}"`);let o=new Set([...r.properties.keys(),...r.inputs]);for(let s of o){if(t.go?.includes(s))continue;let o=e.o(`${t.o.t}.${s}`),a=0===o.n?null:l;Re(e,{...t,U:null,Y:null},n,s,o,a,i,r)}}(e,t,r,s,i,n));if(t.$e&&1===t.i)return void Ie(e,t,r,i,n=>function(e,t,n,l,i,r){if(null!==r)return void Re(e,t,n,t.name,t.o,l,i,r);let o=new _e(e,1,n,t.name,t.o,l,i,t.N,Be(e,t,l));o.j=t.j,!c.ar?.(o,t.ro)&&(Qe(e,o,!0),e.Ve(o))}(e,t,r,s,i,n));let a=new _e(e,t.i,n,t.name,o,s,i,t.N,Be(e,t,s));a.j=t.j,Qe(e,a,!0),e.Ve(a),null!==t.Tt&&n.addEventListener(t.Tt,()=>a.ir())}function it(e,t,n,l){let i=new rt(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,Z(n,t.n),l,null,void 0,i);Qe(e,s,!0),null===l&&i.ce.push(s),r??=s}return e.Ve(r),i}var rt=class{constructor(e,t,n){this.y=!0,this.O=null,this.b=-1,this.ce=[],this.engine=e,this.G=t,this.r=n}Cn(e){return null!==this.O&&this.G[this.b].S===e?this.O.Ke():null}Et(){let e=this.engine,t=-1;for(let n=0;n<this.G.length;n++){let l=this.G[n];if(null===l.o||xe(l.N,e.read(l.o,Z(this.r,l.o.n)))){t=n;break}}if(t!==this.b&&(tt=Pe(),null!==this.O&&(this.O.wo(),this.O.Ne(e),this.O=null),this.b=t,t>=0)){let n=this.G[t],l=nt(e,n.F,this.r,null,n.S);this.O=et();let i=n.S.parentNode;i.insertBefore(l,n.S),Je(i)}}Ne(){this.y=!1;for(let e of this.ce)this.engine.xn(e);null!==this.O&&this.O.Ne(this.engine)}},ot=class{constructor(e,t,n,l){this.y=!0,this.xe=[],this.engine=e,this.F=t,this.l=n,this.S=l,null===n.$?(n.$=this,this.map=null):((n.B??=[]).push(this),this.map=new Map)}Cn(e){return 0===this.xe.length?null:this.xe[0].Ke()}At(e){return null===this.map?e.$:this.map.get(e)??null}jt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ne(this.engine)}Et(){let e=this.engine,t=this.l.f,n=this.xe;tt=Pe();let l=t.length,i=n.length,r=this.S,o=r.parentNode;if(0===l){if(i>0){let e=n[0].Ke(),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):at(e,t);for(let e=0;e<i;e++)this.jt(n[e])}return void(this.xe=[])}let s=new Array(l),a=0;for(;a<l&&a<i&&this.At(t[a])===n[a];)s[a]=n[a],a++;let u=i-1,c=l-1;for(;u>=a&&c>=a&&this.At(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.y&&this.At(l)===t?t.bo=e:(t.wo(),this.jt(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.At(t[a+e]);null!==n&&n.y?(u[e]=n.bo,f=!0):u[e]=-1}let h=c+1<l?s[c+1].Ke():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.At(n);null!==u&&u.y?0===l[r]&&u.insertBefore(o,i):(o.insertBefore(nt(e,this.F,n,this),i),u=et()),s[a+r]=u,i=u.Ke()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(nt(e,this.F,t[l],this)),s[l]=et();o.insertBefore(n,h)}}this.xe=s,Je(o)}Ne(){this.y=!1;let e=this.l;if(e.$===this)e.$=null;else if(null!==e.B){let t=e.B.indexOf(this);t>=0&&e.B.splice(t,1),0===e.B.length&&(e.B=null)}for(let e of this.xe)e.Ne(this.engine);this.map?.clear()}};function st(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 at(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var ut=()=>ne.bindAttributeName;function ct(){return{a:0,i:1,name:"",o:null,N:null,q:t,An:null,F:null,G:null,j:null,Tt:null,$e:!1,U:null,Y:null,ro:!1,Rt:!1,Pt:!1,xt:null,go:null,A:-1,et:!1,yo:!1}}var ft=["state","element","auto","none"],ht=["call","connect"],dt="$command.";function pt(e,t,n){T.test(t)&&(null===n&&w(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&&w(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;l.n>i&&w(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&&w(1403,[l.t,l.h[e].t,t.t])}return c.So?.(e,l),l}var mt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),gt=e=>8===e.i||mt(e)||1===e.i&&Ve(e.name);function yt(e){w(202,[e])}function $t(e,t,n,l,i){let r=se(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.Wt||w(31);let r=n.slice(0,t).trim(),o=n.slice(t+1).trim(),s="init"===r;!s&&"sync"!==r&&w(33,[r,n]),null!==(s?l:i)&&w(34,[r]),(s?ft:ht).includes(o)||w(35,[r,o]),s?l=o:i=o}return{ro:t.includes("ro"),Rt:t.includes("prevent"),Pt:t.includes("stop"),event:n?n.slice(2):null,U:l,Y:i}}(e,t.on),o=l.localName.includes("-"),s=t.Ee,a=t.Je;if("event"===t.w){if(null!==r.U&&"none"!==r.U&&w(36),"eventToken"===s[0])return{...ct(),a:i,i:13,name:s.slice(1).join("."),xt:a,$e:o,Rt:r.Rt,Pt:r.Pt};let n=a.startsWith(dt)?a.slice(9):null,{Rt:l,Pt:u}=r,c=t.Se.slice(2),f=t.on.includes("direct"),h=!f&&qe.has(c);return h&&e.ao(c),{...ct(),a:i,i:5,name:c,et:h,$e:o,yo:f,An(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);G(n)&&n.then(void 0,e=>console.error(e))}}catch(e){console.error(e)}}}}if("spread"===t.w)return{...ct(),a:i,i:14,o:pt(e,a,n),$e:o};if("command"===s[0]&&s.length>1)return a.startsWith(dt)||w(1201,[t.Se,a]),{...ct(),a:i,i:12,name:s.slice(1).join("."),xt:a,$e:o};let u=pt(e,a,n),c={...ct(),a:i,i:1,name:t.Se,o:u,N:Ne(t.Ze),j:Ne(t.j),ro:r.ro,U:r.U,Y:r.Y};if("radio"===t.w||"checkbox"===t.w)return("element"===r.U||"auto"===r.U)&&w(37,[t.w,r.U]),c.i="radio"===t.w?9:10,r.ro||(c.Tt=r.event??"input"),c;if(s.length>1){let e=s.slice(1).join("."),t=s[0];if("class"===t||"attr"===t||"style"===t)return c.U=null,c.name=e,"class"===t?(c.i=2,c.q=l.classList.contains(e)):c.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,c}return"html"===t.Se?(c.i=8,c):(c.name="text"===t.Se?"textContent":t.Se,c.$e=o&&!Oe(c.name),!o&&!r.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(l,c.name)&&(c.Tt=r.event??("select"===l.localName?"change":"input")),c)}(e,t,n,l,i));for(let e=0;e<r.length;e++)14===r[e].i&&(r[e].go=r.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return r}var vt=/\{\{([\s\S]+?)\}\}/g;function bt(e){let t=e.data,n=[],l=0;vt.lastIndex=0;for(let i=vt.exec(t);null!==i;i=vt.exec(t)){let r=vt.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=vt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function wt(e,t,n,l){let i=function(e){return{Se:"textContent",Ee:["textContent"],on:[],j:[],...F(e),w:"text"}}(t);return{...ct(),a:l,i:0,o:pt(e,i.Je,n),N:Ne(i.Ze),q:""}}function kt(e){let t=e.getAttribute(ut());if(null===t)return null;let n=se(t)[0];return void 0===n||"for"!==n.w&&"if"!==n.w&&"elseif"!==n.w&&"else"!==n.w?null:n}var St=(e,t)=>0===e?ne.commentIfPrefix:null===t.o?ne.commentElsePrefix:ne.commentElseIfPrefix;function xt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.w?null:pt(e,l.Je,n),N:"else"===l.w?null:Ne(l.Ze)}),i=[l(t,kt(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=kt(e);if(null===t||"elseif"!==t.w&&"else"!==t.w||(i.push(l(e,t)),"else"===t.w))break}return i}var Nt=new WeakSet;function At(e,t,n,l,i,r,o,s){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),l&&c.jn?.(e,i,t),i},u=t=>{for(let f=0;f<t.length;f++){let h=t[f];if(null!==h.parentNode)if(1===h.nodeType){let t=h,s=t.localName;if(l){if("script"===s||"style"===s||Nt.has(t))continue;if(Nt.add(t),s===ne.tagNames.state){u([...t.childNodes]);continue}}let f="template"===s?kt(t):null;if(null!==f){if("for"===f.w){let l=pt(e,f.Je,n),r=Ct(e,t,l,!0);i(a(t,ne.commentForPrefix),l,r)}else"if"===f.w?r(xt(e,t,n).map((t,l)=>({F:Ct(e,t.el,n,!1),o:t.o,N:t.N,S:a(t.el,St(l,t))}))):yt(f.w);continue}let d=t.getAttribute(ut()),p=null===d?null:$t(e,d,n,t,0),m="noscript"!==s&&"iframe"!==s&&!p?.some(gt)&&!c.Eo?.(t);try{l&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!l&&m&&u([...t.childNodes])}else if(3===h.nodeType&&e.Mt&&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=jt.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 jt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Ot=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Ct(e,t,n,l){let i=document.importNode(Ot(t),!0),r=[],o=[],s=e=>r.push(e)-1;At(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ct(),a:s(e),i:6,o:t,F:n})},e=>{let t=e.map(e=>({a:s(e.S),F:e.F,o:e.o,N:e.N}));o.push({...ct(),a:t[0].a,i:7,G:t})},(e,t)=>{let n=s(e);for(let e of t)mt(e)&&w(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ut())},(t,l)=>{o.push(wt(e,l,n,s(t)))}),Et(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.et&&!e.$e&&!Mt(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&&Tt(e)&&(e.A=f.push(e)-1),7===e.i)for(let t of e.G)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{sn:i,root:u?i.firstChild:null,On:a,build:g,Re:d,sr:p,In:u,lr:c,ko:[],ze:f}}function Mt(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 Tt(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.$e&&null===e.Tt;default:return!1}}var Pt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Et(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&&Et(l,t,Pt.has(l.localName)),l=e}}var Wt=new WeakMap;function It(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Wt.set(t,e),Lt(e,[...n.childNodes]),e.He()}function Rt(e,t,n){try{let l="template"===t.localName?kt(t):null;null!==l&&!n&&w(204,[l.w]),Lt(e,[t])}catch(e){console.error(e)}e.He()}function Lt(e,t){At(e,t,null,!0,(t,n,l)=>{new ot(e,l,Ye(e,n,null,t),t).Et()},t=>{it(e,t,null,null)},(t,n)=>{c.jn?.(e,t,n);for(let l of n)lt(e,l,t,null,null)},(t,n)=>{c.jn?.(e,t,n),lt(e,wt(e,n,null,0),t,null,null)})}var qt=Symbol.for("wcstack.binder"),Dt=Symbol.for("wcstack.binder.pending"),zt=Symbol.for("wcstack.binder.taken");var Ft=new Map;function Ut(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Wt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ft.set(e,t):Rt(n,e,t?.range)}function Bt(){let e=[...Ft];Ft.clear();for(let[t,n]of e)Ut(t,n);!function(){let e=function(){let e=globalThis[qt];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;let t=function(){let e=globalThis,t=e[Dt];return void 0===t&&(t=[],e[Dt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[zt];return void 0===t&&(t=new WeakSet,e[zt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var _t=class{constructor(){this.name="dirty",this.Z=(e,l)=>{if(0===e.n){let l=e.z;return l!==t&&l!==n&&(e.z=n,!0)}let i=null===l?null:l.ht;if(null===i)return!1;let r=i[e.A];return r!==t&&r!==n&&(i[e.A]=n,!0)}}Qo(e,t,n){null!==t.getter&&this.Z(t,n),e.St(t,n),e.Nn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Ct;if(null!==n)for(let l of n)l.n===t.l.n?e.it(l,t,this.Z):e.Zt(t,l,t=>e.it(l,t,this.Z))}we(e,t,n){this.Z(t,n),c.ve?.(e,t,n),e.St(t,n),e.Nn(t,n,this.Z)}Uo(e,i,r){let o=0===i.n;if(!o&&null===r)return;let s=o?null:r.ht??=new Array(e.Ie).fill(t),a=null===s?i.z:s[i.A];if(a!==t&&a!==n&&a!==l&&(null===s||i.A in s))return a;a=l;try{return a=e.qo(i,null===s?null:r)}finally{null===s?i.z=a:s[i.A]=a}}Xt(e){e.ht=null}bt(e){for(let t of e.I.all())null!==t.getter&&(0===t.n?t.z===n&&(t.z=l):e.tn(t.h[t.n],e=>{let i=e.ht;null!==i&&i[t.A]===n&&(i[t.A]=l)}))}},Vt=0,Ht=new WeakMap;function Kt(e,t=e.getRootNode()){Ht.set(t,[...Ht.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Jt(e){let t=Ht.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?Ht.get(e)!==t?Jt(e):Promise.reject(l.errors[0]):void 0)}var Gt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Gt{constructor(){super(),this.engine=null,this.Ln=!1,this.Ue=!1,this.q=null,this.Xe=null,this.loaded=!1,this.cn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.an=e,this.$o=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.ln=e})}static{this.getBindingsReady=Jt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Xe)return void this.Xe.Ye();Kt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!Wt.has(t)&&Wt.set(t,e),Bt(),c.element?.(e,"back"),this.No("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),t=c.at?.(this,e);if(t)return this.Xe=t,!t.xo&&this.parentNode instanceof ShadowRoot&&Kt(this),void(void 0===t.Dt?this.Ro():t.Dt()).then(e=>(this.loaded=!0,t.start(e,()=>this.Po()))).then(()=>{this.ln(),this.an()},e=>this.$t(e,t.xo));this.start(e),Kt(this)}disconnectedCallback(){if(null!==this.Xe)return void this.Xe.Bn();let e=this.engine;if(null===e)return;let t=e.root;Wt.get(t)===e&&Wt.delete(t),Kt(this,t),this.No("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ue&&w(14),this.loaded)this.Xe.reset(e);else if(null===this.engine)if(null!==this.cn){let t=this.cn;this.cn=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&w(15),"readonly"===e&&n.je++;try{t(n.proxy)}finally{"readonly"===e&&n.je--}}async createStateAsync(e,t){let n=this.engine;null===n&&w(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let l=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&w(8),l(...e)):l},set(){w(8)}}))}async Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${b(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||w(13,[e,n.status]),await n.json()}return(await(import(t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let 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//${++Vt}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?b(42):b(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(i)}}(l):null!==this.q?Promise.resolve(this.q):new Promise(e=>{this.cn=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.Ro(),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=Wt.get(e)?.element;i?.isConnected&&(i.V||i.Xe)&&w(47);let r=new te(n,new _t);r.element=this,this.engine=r,c.element?.(r,"mounting"),It(r,e),Bt(),r.$n(),this.Po(),await r.ke("$connectedCallback"),this.isConnected&&c.element?.(r,"connected"),this.an()}catch(e){this.Ue=!this.V,this.$t(e)}}Po(){this.V=!0,this.ln()}$t(e,t){this.He(this.V?50:49,e),this.ln(),t?this.an():this.$o(e)}He(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${b(e,[this.localName,...n])}`,t)}No(e,t,n){(async()=>this.engine.ke(e))().then(n,e=>this.He(t,e))}},Yt=[];function Qt(){return(Yt=Yt.filter(e=>e.deref())).map(e=>e.deref())}var Zt,en=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},tn="en";function nn(){if(ne.locale!==Zt){Zt=ne.locale;try{tn=Intl.getCanonicalLocales(Zt)[0]}catch{console.warn(`[@wcstack/state] ${b(48,[Zt])}`),tn="en"}}return tn}var{eq:ln,ne:rn,not:on,lt:sn,le:an,gt:un,ge:cn,falsy:fn,truthy:hn,boolean:dn}=ke,pn={toFixed:{factory:e=>{let t=$e(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&me("toFixed"),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&me("locale"),e.toLocaleString(t??nn()))},arity:[0,1]},upper:{factory:en(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:en(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:en(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:en(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:en(e=>{let t=[ve(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push($e(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:en(e=>{let t=ve(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:en(e=>{let t=ve(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:en(e=>{let t=ve(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:en(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:en(e=>{let t=ve(e,0,"truncate"),n=e?.[1]??"…";return e=>{let l=String(e);return l.length<=t?l:l.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||w(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,$e(e?.[0]??"0","round"));return e=>("number"!=typeof e&&me("round"),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,$e(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&me("floor"),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,$e(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&me("ceil"),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=$e(e?.[0]??"0","percent");return e=>("number"!=typeof e&&me("percent"),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:en(e=>{let t=e?.[0]??de("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ge("date"),e.toLocaleDateString(t??nn()))},arity:[0,1]},time:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ge("time"),e.toLocaleTimeString(t??nn()))},arity:[0,1]},datetime:{factory:e=>{let t=e?.[0];return e=>(e instanceof Date||ge("datetime"),e.toLocaleString(t??nn()))},arity:[0,1]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ge("ymd");let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ge("hms");let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${i}`}},arity:[0,1]},eq:ln,ne:rn,not:on,lt:sn,le:an,gt:un,ge:cn,add:we("add",(e,t)=>e+t),sub:we("sub",(e,t)=>e-t),mul:we("mul",(e,t)=>e*t),div:we("div",(e,t)=>e/t),mod:we("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&me("abs"),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ve(e,0,"clamp"),n=ve(e,1,"clamp");return e=>("number"!=typeof e&&me("clamp"),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:fn,truthy:hn,defaults:{factory:(e,t)=>{let n=be(e?.[0]??de("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=be(e?.[0]??de("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:dn,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]}},mn=!1,gn={name:"formats",install:function(){mn||(mn=!0,fe(pn))}};function yn(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 $n(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,i=3;for(let e of t){let t=yn(n,e.toLowerCase(),2);t<i&&(l=e,i=t)}return null!==l?` Did you mean "${l}"?`:""}var vn=" Validate statically: npx @wcstack/lint <file>.",bn=["","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"],wn=e=>{let t=bn[e/100|0];return t?`[wcs/${t}] `:""},kn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Sn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,xn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Nn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t)=>`binding "${e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${xn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${xn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:e=>`filter ${e} requires a number value`,29:e=>`filter ${e} requires a date value`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&kn.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)=>`${Sn(e,t)} failed to initialize.`,50:(e,...t)=>`${Sn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Sn(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 An(e,t){let n=Nn[e];return void 0===n?`${wn(e)}#${e} ${t.join(" ")}`:wn(e)+n(...t)}var jn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),On=[[/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.']],Cn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Mn(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(Cn,e)?Cn[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?$n(t,n):"");for(let[t,n]of On){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"].':ae.some(he)||(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&&jn.has(r[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=vn),l}var Tn=new WeakMap,Pn=new WeakMap,En=new WeakSet,Wn=new WeakSet;function In(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 Rn(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 Ln(e,t){let n=[];for(let e=t;null!==e;e=e.d)n.unshift(e);let l=e.target,i=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==In(e.target,t.t)?.get?t:e.I.It(o(t.t).o)}(e,t);for(let t of n){if(null!=i(t)?.getter||null===l||"object"!=typeof l)return null;if("*"===t.s){if(!Array.isArray(l)||0===l.length)return null;l=l[0];continue}if(Array.isArray(l)&&/^\d+$/.test(t.s)){if(Number(t.s)>=l.length)return null;l=l[Number(t.s)];continue}let n=In(l,t.s);if(void 0===n&&null===t.d&&e.bt.has(t.s))return null;if(void 0===n){let n=Rn(l),r=i(t.d);for(let t of e.I.all())t.d===r&&null!==t.getter&&n.push(t.s);return{seg:t.s,names:n}}if(void 0!==n.get||void 0!==n.set)return null;l=n.value}return null}function qn(e){En.has(e)||(En.add(e),setTimeout(()=>function(e){En.delete(e);let t=Tn.get(e);if(void 0===t)return;let n=Pn.get(e);void 0===n&&Pn.set(e,n=new Set);for(let[l,i]of t){if(n.has(l))continue;n.add(l);let t=Ln(e,l);if(null===t)continue;let r=[...e.root?.querySelectorAll(`${ne.tagNames.state}[mount]`)??[]].find(e=>!Wn.has(e)&&(l.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==r){n.delete(l),r.initializePromise.then(()=>{Wn.add(r),qn(e)});continue}let[s,a]=i?["watch-path-missing","$watch path"]:["binding-path-missing","Bound path"];c.st?.(e,{type:"state:path-unresolved",source:i?"watch":"binding",path:l.t,missingSegment:t.seg});let u=e.I.It(o(l.t).o),f="";if(void 0!==u&&u!==l&&null!==u.getter){let e=u.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(u.h[t].t.length+2)}`);f=` The getter "${u.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}console.warn(`[@wcstack/state] [wcs/${s}] ${a} "${l.t}" does not resolve on the state tree: "${t.seg}" is not declared.${$n(t.seg,t.names)}${f} Updates to this path will be silently dropped.${vn}`)}}(e),0))}function Dn(e,t,n=!1){if("$"===t.t[0]||t.t.includes("#")||!n&&null===t.d)return;let l=Tn.get(e);void 0===l&&Tn.set(e,l=new Map),l.has(t)||l.set(t,n),qn(e)}var zn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Fn=!1;function Un(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(Fn||!(t instanceof TypeError)||!Oe(l)||!("trustedTypes"in globalThis))return;Fn=!0;let i="function"==typeof je()?.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 Bn=new WeakMap;function _n(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=Bn.get(e);void 0===r&&Bn.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 Vn=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],Hn={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},Kn={name:"diagnostics",install(){c.Bo=Mn,c.Do=An,c.So=Dn,c.detail=_n,c.Ue=f(c.Ue,Un);let e=c.de;c.de=(t,n)=>{(function(e){void 0!==e.$scan&&w(1);for(let[t,n]of Vn)void 0!==e[t]&&w(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=Rn(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(`^(?:${zn(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(`^${zn(l)}(?:${zn(s)})*${zn(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&f(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(n),function(e){Pn.delete(e),Tn.has(e)&&qn(e)}(t)},c.ot=h(p,c.ot,(e,t)=>Object.hasOwn(Hn,t)?w(1701,[t,Hn[t]]):void 0)}},Jn={},Gn=/\.\d/,Xn=new Set(Object.getOwnPropertyNames(Object.prototype)),Yn=0,Qn=!1,Zn=null,el=()=>{Qn=!1,Yn++};function tl(){if(null===Zn)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=el,e.port1.unref?.(),Zn=()=>e.port2.postMessage(0)}else Zn=()=>setTimeout(el,0);return Qn||(Qn=!0,Zn()),Yn}function nl(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.J){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 ll=class{constructor(e,t){this.active=!1,this.Ge=new Map,this.n=0,this.Ao=-1,this.Dn=new Set,this.We=null,this.engine=e,this.ct=t}ur(){let e=this.engine;this.Ge.clear();for(let t of this.ct)t.getter=null!==t.p.getter||t.p.se,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(Jn,e.v(t.p,null)):this.Mn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.st?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Fo(){this.active=!1,this.Ge.clear()}Mn(e,t,n,l){let i=this.engine._e(n,e.h[t]);for(let n of i.f)t===e.n?l(n):this.Mn(e,t+1,n,l)}un(e,t,n,l){let i=this.Ge.get(e);void 0===i&&this.Ge.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)}be(e,t,n,l,i){if(this.active){(this.We??=new Set).add(e);for(let r of this.ct){let o=r.p;o.n!==e.n||!o.ee(e)||this.un(r,t,r.getter?r.s.get(t??Jn):o===e&&i&&this.engine._t&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}}ve(e,t){if(this.active)for(let n of this.ct)(n.getter||=null!==n.p.getter||n.p.se)&&n.p.n===e.n&&n.p.ee(e)&&this.un(n,t,n.s.get(t??Jn),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.ct){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.un(l,t,void 0,!0):this.Mn(i,e.n+1,t,e=>this.un(l,e,void 0,!0)))}}}Fe(){let e=this.We;if(this.We=null,!this.active||0===this.Ge.size)return;let t=this.Ge;this.Ge=new Map;let n=this.engine,l=[];for(let i of this.ct){let r=t.get(i);if(void 0===r)continue;let o,s=[...r].filter(([e])=>null===e||e.y);s.length>1&&s.sort((e,t)=>rl(e[0],t[0]));for(let[t,[r,a,u]]of s){let s,f="evaluate",h=n.u;this.n=a+1,n.Pe++;try{if(s=n.v(i.p,t),i.getter&&(i.s.set(t??Jn,s),Object.is(s,r)&&(Gn.test(i.t)||null!==t&&!u&&!(o??=null!==e&&nl(il(i.p),e)))))continue;if(a>32){l.includes(i.t)||l.push(i.t);continue}n.u=t,c.st?.(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.st?.(n,{type:"state:watch-error",phase:f,path:i.t,error:e})}finally{n.u=h,this.n=0,n.Pe--}}}l.length>0&&this.Oo(l)}Oo(e){let t=tl();t!==this.Ao&&(this.Ao=t,this.Dn.clear());let n=e.filter(e=>!this.Dn.has(e));if(0!==n.length){for(let e of n)this.Dn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.st?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function il(e){for(;null===e.getter&&null!==e.d;)e=e.d;return e}function rl(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ae)n.unshift(t.b);for(let e=t;null!==e;e=e.l.ae)l.unshift(e.b);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var ol="$streamStatus",sl="$streamError",al=new Set(Object.getOwnPropertyNames(Object.prototype)),ul=!1;function cl(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 fl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.D=n}set(e,t,n){ul=!0;try{this.engine.T(this.engine.o(`${e}.${t}`),null,n)}finally{ul=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.ut=!1,e.Q?.abort(),e.Q=null}pr(){for(let e of this.entries)e.ut=!1,null!==e.Q&&(e.Q.abort(),e.Q=null),this.set(ol,e.name,"idle")}ve(e){let t=this.D.n;for(let n of this.entries)n.g===e&&(n.n=n.ut?Math.max(n.n,t):t,n.ut=!0)}Fe(){let e=this.engine,t=this.D,n=[];for(let i of this.entries){if(!i.ut)continue;let r=i.n;if(i.ut=!1,r>32)n.push(i.name),i.g.z=l;else{t.n=r+1,e.Pe++;try{this.start(i,!1)}finally{e.Pe--,t.n=0}}}n.length>0&&t.Oo(n)}start(e,t){let n,i=this.engine;if(null!==e.Q&&e.Q.abort(),e.Q=null,null!==e.g){let r=e.g;r.getter=e.args;let o=r.J.slice();hl(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.J)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${ol}.${e}`||n.t===`${sl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){hl(r);for(let e of o)e.Wn(r);if(r.z=l,t)throw n;return this.set(sl,e.name,n),void this.set(ol,e.name,"error")}}let r=new AbortController;e.Q=r,i.T(i.o(e.name),null,e.q),this.set(sl,e.name,null),this.set(ol,e.name,"active"),this.mr(e,r,n)}async mr(e,t,n){let l=this.engine,i=t.signal,r=()=>!i.aborted&&e.Q===t,o=l.o(e.name),s=this.D.n,a=tl(),u=e=>{tl()===a&&(this.D.n=s);try{e()}finally{this.D.n=0}},c=e.q;try{let t=await e.source(n,i);if(!r())return;let s=t=>{c=void 0!==e.Co?e.Co(c,t):t,u(()=>l.T(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.Q=null,u(()=>this.set(ol,e.name,"done"))}catch(n){if(!r())return;e.Q=null,t.abort(),u(()=>{this.set(sl,e.name,n),this.set(ol,e.name,"error")})}}};function hl(e){for(let t of e.J){let n=t.M.indexOf(e);n>=0&&t.M.splice(n,1),t.pt.delete(e)}e.J.length=0,e.z=t}var dl=new WeakMap;function pl(e){let t=dl.get(e);return t?.target===e.target?t:void 0}function ml(e,t){let n=new ll(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("@")||Xn.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.So?.(e,r,!0),n.push({t:l,p:r,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),l=new fl(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)||al.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.`),cl(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,Co:u,q:f,Q:null,ut:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[ol]=i,t[sl]=r,l}(e,t),n),i=dl.get(e);void 0!==i&&(i.D.Fo(),i.Ft.fr()),dl.set(e,{D:n,Ft:l,Ye:i?.Ye??!1,target:t})}function gl(e,t){let n=dl.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Ye="connected"===t),n.target===e.target)){if("disconnected"===t)return n.D.Fo(),void n.Ft.pr();n.Ye&&(n.D.ur(),n.Ft.dr())}}var yl=["$streamStatus","$streamError"],$l={name:"temporal",install(){c.de=f(c.de,ml),c.element=f(c.element,gl),c.be=f(c.be,(e,t,n,l,i,r)=>pl(e)?.D.be(t,n,l,i,r)),c.ve=f(c.ve,(e,t,n)=>{let l=pl(e);void 0!==l&&(l.D.ve(t,n),l.Ft.ve(t))}),c.Qt=f(c.Qt,(e,t,n)=>pl(e)?.D.Qt(t,n)),c.Fe=f(c.Fe,e=>{let t=pl(e);void 0!==t&&(t.D.Fe(),t.Ft.Fe())}),c.ot=h(p,c.ot,(e,t)=>{let n=t.split(".",1)[0];if(yl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ae=h(d,c.Ae,(e,t)=>(!ul&&36===t.t.charCodeAt(0)&&yl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},vl=new WeakMap,bl=!1,wl=/^(?!prototype$)[^\d.*$][^.*]*$/;function kl(e,t){let n=t.$listKeys,l=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let i=n[t];"string"==typeof i?l.set(e.o(t),e=>e[i]):"function"==typeof i?l.set(e.o(t),i):v(`$listKeys "${t}" must be a field name or a function.`)}}vl.set(t,l)}function Sl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function xl(e,t,n){let l=new Map;for(let i of t){Sl(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 Nl(e,t,n,l){if(bl||!Array.isArray(l))return!1;let i=vl.get(e.target)?.get(t);if(void 0===i)return!1;let r=e.rt(t,n);if(!Array.isArray(r)||r===l)return!1;let o=xl(t.t,r,i);xl(t.t,l,i);let s=[],a=[],u=r.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=o.get(i(t));s.push(n??t),void 0!==n&&a.push([e,n,t]),s[e]!==r[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let l of Object.keys(n))Object.is(t[l],n[l])||c.push([e,l,n[l]]);for(let l of Object.keys(t))!(l in n)&&null!==t[l]&&c.push([e,l,null])}if(u&&0===c.length)return!0;if(!u){bl=!0;try{e.T(t,n,s)}finally{bl=!1}}if(c.length>0){let l=e._e(0===t.n?null:n,t);for(let[n,i,r]of c){if("__proto__"===i)continue;let o=l.f[n],s=wl.test(i)?e.o(`${t.t}.*.${i}`):null;null===s?.getter?e.T(s,o,r):(o.R[i]=r,e.T(e.o(`${t.t}.*`),o,o.R,!0))}}return!0}var Al={name:"list-keys",install(){c.de=f(c.de,kl),c.Ae=h(d,c.Ae,Nl)}},jl=new WeakMap,Ol=new WeakMap,Cl="will not graft: the root state failed to initialize.",Ml=new WeakSet,Tl=new WeakMap,Pl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],El=["$commandTokens","$eventTokens","$on","$errorCallback"],Wl=e=>`[@wcstack/state] <${ne.tagNames.state} mount="${e}">`,Il=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Rl=e=>e?.element?.isConnected?e:void 0;function Ll(e){let t=Ol.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ql(e,t){let n=Ol.get(t);if(Ol.delete(t),Array.isArray(n))for(let t of n)Ul(t,e)}function Dl(e){let t=jl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function zl(e,t){console.error(`${Wl(e.t)} ${t}`),Dl(e),e.Qe?.(),e.Qe=null}function Fl(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 Ul(e,t){if(Ml.has(t))return zl(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 zl(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)):Il.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.rt(n,null)&&t.T(n,null,{})}t.T(t.o(e.t),null,s)}t.to(Object.defineProperties({},a));for(let e in a)t.We(t.o(e),null);e.engine=t;let c=Tl.get(t);void 0===c&&Tl.set(t,c=[]),c.push(e),e.el.isConnected&&Fl(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function Bl(e,t){let n=Ol.get(e);if(Array.isArray(n))for(let e of n)zl(e,Cl);Ol.set(e,t)}var _l=new WeakMap;function Vl(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(ne.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=jl.get(t);void 0===e&&jl.set(t,e=new Map);let r=e.get(n);if(void 0!==r&&r!==l&&(null===r.engine?r.el.isConnected:Rl(r.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===r?.engine){let e=Ol.get(t);Array.isArray(e)&&Ol.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{xo:!0,start(e){if(null!==i)return zl(l,i);if(jl.get(t).get(n)===l){for(let t of Pl)if(void 0!==e[t])return zl(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of El)void 0!==e[t]&&console.warn(`${Wl(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Qe=e;let n=Rl(Wt.get(t)),i=Ol.get(t);void 0!==n?Ul(l,n):Ll(t)?zl(l,Cl):Ol.set(t,[...Array.isArray(i)?i:[],l])})}},Ye(){null!==l.engine&&Fl(l,"$connectedCallback")},Bn(){null!==l.engine&&Fl(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 Hl=new WeakMap,Kl=new WeakMap;function Jl(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 Gl(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=Jl(l,"$bindables"),o=Jl(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(ne.tagNames.state);return a.set(l,o),Hl.set(l,s),null===o&&r.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ne.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)},Ye(){},Bn(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Xl=new WeakMap,Yl=new WeakSet,Ql=new WeakMap,Zl=new WeakMap,ei="data-wcs-wired",ti=new WeakMap,ni=new WeakMap,li=new WeakMap,ii=0,ri=new Set,oi={},si=["$watch","$stream","$renderedCallback"],ai=e=>e.split(".",1)[0];function ui(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function ci(e,t){let n=e.a,l=ai(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(ei);else if(!hi(n,l)){let e=n.getAttribute(ei)?.split(" ")??[];e.includes(l)||n.setAttribute(ei,[...e,l].join(" "))}ti.get(n)?.pe===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=Xl.get(n);void 0===i&&Xl.set(n,i=[]),i.push(e),t&&Yl.add(e);let r=Ql.get(n);return void 0===r&&Ql.set(n,r=new Map),r.has(l)||r.set(l,n[l]),Zl.get(n)?.(),!1}function fi(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ne.tagNames.state}[bind-component]`)}function hi(e,t){let n=e.getAttribute(ne.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function di(e){let t=e.parentElement;for(;null!==t&&!fi(t);)t=t.parentElement;let n=Wt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Ut(e):Rt(n,e))}var pi=new Set;function mi(e,t){pi.has(e)||(pi.add(e),console.warn(`[@wcstack/state] ${t}`))}var gi=(e,t)=>t in e.state;function yi(e,t){let n=$i(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function $i(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 vi(e,t,n){if(null!==n.getter)return;let l,i=e.host,r=i.engine,o=ai(n.t),s=i.entries.find(e=>e.E===n.t);if(void 0===s&&null!==n.d)return function(e,t){let n,l=t.d;for(;null!==l&&void 0===(n=e.dt.get(l));)l=l.d;if(null===l||void 0===n)return;let i=e.x,r=e.host.engine,o=r.o(n.p.t+t.t.slice(l.t.length));if(null===o.getter)return;let s=n,a=()=>{let n=bi(e,s.r);return 0===t.n?n:(r.resolve(ui(o.t,[...r.H(n),...i.H(Z(i.u,t.n))]),null),r.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:r.v(o,e)},null!==o.ie&&(t.ie=n=>{let l=a();wi(e,s.e,()=>r.T(o,l,n)),e.dn=t}),t.n>0&&(t.A=i.Ie++),e.dt.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?gi(i,o):yi(i,o))return;l=s.me}else{if(null===t||null!==n.d||"$"===o[0]||gi(i,o))return;s=t,l=r.o(`${t.me.t}.${o}`)}let a=s.r,u=s;n.getter=()=>r.v(l,bi(e,a)),n.ie=t=>{wi(e,u,()=>r.T(l,a,t)),e.dn=n},e.dt.set(n,{e:s,p:l,r:a})}function bi(e,t){return null!==t&&!t.y&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function wi(e,t,n){let l=ri.has(e.x);ri.add(e.x),e.from=t;try{n()}finally{l||ri.delete(e.x),e.from=null}}var ki=(e,t)=>t||!ri.has(e.m.x)||null!==e.m.from&&e.m.from!==e.e;function Si(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,ii+=t?1:-1;let n=e.host.engine,l=li.get(n);void 0===l&&li.set(n,l=new Map);for(let n of e.fe){let e=l.get(n.e.me);void 0===e&&l.set(n.e.me,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.re&&function(e,t){let n=e.host,l=n.engine;e.re=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=ai(o);if(o!==a&&!gi(n,a))continue;let u=l.o(`${t.me.t}.${o}`);if(null===u.getter)Ai(l,u,t.me);else if(!xi.has(u.getter))continue;e.re.set(u,e.x.o(o))}}(e,i);for(let l of e.re.keys())t&&null===l.getter&&Ai(n,l,i.me),n.P.we(n,l,i.r);e.re.size>0&&n.Te(),t&&function(e,t){let n=e.host.engine;for(let[l,i]of e.re){let r=n.v(l.d,t.r);if(null===r||"object"!=typeof r||!(l.s in r))continue;let o=e.host.el.localName;mi(`${o}|${l.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.pe}.${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 xi=new WeakSet;function Ni(e,t,n,l){let i=li.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.re?.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 Ai(e,t,n){let l=t.d,i=t.s,r=()=>{let t=e.read(l,e.u);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let l=r();if(null!==l)return l[i];let o=Ni(e,n,e.u,t);return null===o?void 0:o.x.read(o.re.get(t),null)},xi.add(t.getter),t.ie=o=>{let s=null===r()?Ni(e,n,e.u,t):null;if(null===s){let t=e.read(l,e.u);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=s.re.get(t);void 0===$i(s.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${s.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),s.x.T(a,null,o)},t.n>0&&(t.A=e.Ie++)}function ji(e,t,n,l,i,r){if(null!==t.getter)return e.P.we(e,t,n),void e.Te();if("*"===t.s){if(null===n)return;if(n.R=n.l.C[n.b],e.P.Xt(n),null!==n.c)for(let t of n.c.values())e.Y(t)}else e.En(t,n);c.be?.(e,t,n,l,i,r),e.We(t,n)}function Oi(e){let t=e.m.x;for(let[n,l]of e.m.dt)l.e===e.e&&(0===n.n?t.P.we(t,n,null):t.tn(n.h[n.n],e=>t.P.we(t,n,e)));t.Te()}function Ci(e,t,n,l,i,r,o){let s=n.t.slice(t.t.length);if(""===s)return Oi(e);let a,u=e.m,c=u.x;if(""===e.e.E){a=s.slice(1);let e=ai(a);if("$"===e[0]||gi(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(Z(l,e).b);c.resolve(ui(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||ji(c,h,d,i,r,o)}function Mi(e,t,n,l,i,r,o){if(0===ii)return;let s=ri.has(e);ri.add(e);try{let s=ni.get(e);!o&&void 0!==s&&s.fn&&!ri.has(s.host.engine)&&function(e,t,n,l,i,r){let o,s=t;for(;null!==s&&void 0===(o=e.dt.get(s));)s=s.d;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.y)return;let u=[...a.H(o.r),...e.x.H(n)];a.resolve(ui(o.p.t+t.t.slice(s.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||wi(e,o.e,()=>ji(a,c,f,l,i,r))}(s,t,n,l,i,r),o&&void 0!==s&&s.fn&&null!==s.re&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[i,r]of e.re)r===t&&(l.P.we(l,i,n.r),l.Te())}(s,t);let a=li.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:Z(n,e.n));if(void 0!==a)for(let s of[...a])ki(s,o)&&Ci(s,e,t,n,l,i,r)}else if(e.ee(t))for(let[e,l]of[...s])if(0===t.n||Z(e,t.n)===n)for(let e of[...l])ki(e,o)&&Oi(e)}finally{s||ri.delete(e)}}async function Ti(e,t,n,l,i){if(l===oi)return;let r=y(l);r&&await r;let o=ti.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.O;if(null!==s&&s.el!==e&&s.el.isConnected&&v(`<${t.localName}> already has a connected <${ne.tagNames.state} bind-component="${o.pe}">.`),null!==s&&Si(s,!1),null!==s&&function(e,t,n){let l=e.x,i=`[${ne.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.Cn(t);null!==n&&n!==t;n=n.nextSibling)s(n);s(t)};for(let e of l.ce.values())for(let t of e)if(null===t.W)s(t.a);else for(let e of t.W.G)a(t.W,e.S);for(let e of l.oe.values())for(let t of[e.$,...e.B??[]])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.Mt&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(s,e,n))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.x.element=t,t.engine=e.x,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await Pi(e,l):l()}(s,e,n,i);let a=new te(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:[],x:a,host:o,fe:[],dt:new Map,fn:!1,dn:null,from:null,re:null};for(let e of o.entries)u.fe.push({m:u,e});o.O=u,ni.set(a,u);let f=null===o.engine;f?c.element?.(a,"mounting"):(function(e){let t=e.x,n=e.host,l=n.engine,i=n.el.localName,r=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=ai(e.E);gi(n,t)&&(e.E!==t||yi(n,t))&&mi(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.pe}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==r){let e=l.v(r.me,r.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.E===t)&&mi(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${r.me.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&&mi(`${i}.${n.pe}$`,`[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.nt;t.nt=n=>{vi(e,r,n),s.call(t,n)};let a=[...t.I.all()];for(let t of a)vi(e,r,t);for(let e of a)s.call(t,e);let u=t.zt;t.zt=()=>{(function(e){for(;void 0!==e;e=ni.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.y))return!1;return!0})(e)&&u.call(t)}}(u),Si(u,!0),Ml.add(a),ql(a,n));let h=c.hr?.(n);It(a,n),h?.(),u.L=[...n.childNodes],Bt(),f&&a.$n(),Object.defineProperty(t,o.pe,{configurable:!0,enumerable:!0,get:()=>a.proxy});let d=t.$stateReadyCallback;if("function"==typeof d)try{let e=d.call(t,o.pe);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.ke("$connectedCallback"),f&&e.isConnected&&c.element?.(a,"connected")):Si(u,!1)}async function Pi(e,t){Si(e,!0);for(let t of e.fe)Oi(t);t?.(),!e.broken&&(await e.x.ke("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.x,"connected"))}function Ei(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Wt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){Bl(t,e);for(let e of _l.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:ti.get(r)?.O;return t?.el===e?t:null},s=t=>{throw i&&Bl(l,e),t},a=!1;return{Dt:()=>(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(`<${ne.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await We(n).whenDefined(i);let r=ti.get(n);if(void 0!==r)return r.pe!==t&&v(`<${i}> already has a <${ne.tagNames.state} bind-component="${r.pe}">.`),r.state;let o=()=>(Xl.get(n)??[]).filter(e=>ai(e.name)===t),s=hi(n,t);if(s&&0===o().length&&di(n),0===o().length&&(s||((e,t)=>!0===e.getAttribute(ei)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,r)=>{Zl.set(n,l),e=function(e,t){Ll(e)&&t();let n=_l.get(e)??new Set;return _l.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())}Zl.delete(n);let a=o(),u=Ql.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 (${ne.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),oi}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,me:e.o,r:e.r,ro:Yl.has(e)}),e.engine.xn(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 ti.set(n,r={el:n,pe:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,O:null}),h}(e,n,r,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ne.tagNames.state}> to be a direct child of a custom element.`))).catch(s),async start(t,n){await Ti(e,r,i?l:r,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),s(e)})},Ye(){let t=o();null!==t?Pi(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===l)return Ti(e,r,i?l:r,ti.get(r).state,()=>{})}).catch(e=>console.error(e)):Zl.has(r)&&di(r)},Bn(){let e=o();null!==e&&(Si(e,!1),!e.broken&&(e.x.ke("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.x,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${r?.localName}>.${n} instead.`)}}}var Wi={name:"scopes",install(){c.at=h(m,c.at,Vl),c.at=h(m,c.at,Gl),c.at=h(m,c.at,Ei),c.ar=ci,c.Eo=fi,c.element=f(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Tl.get(e)??[];if("disconnected"===t)for(let e of n)Dl(e);else if("reset"!==t&&Rl(Wt.get(e.root))===e){ql(e,e.root);for(let e of n)jl.get(e.root).has(e.t)||jl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ql(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:Hl.get(n);void 0!==l&&Kl.set(e,{host:n,def:l})}(e,n)}),c.be=f(c.be,(e,t,n,l,i,r)=>{(function(e,t,n,l){let i=Kl.get(e);if(void 0===i)return;let r=t.t.split(".",1)[0];if(!i.def.bindables.includes(r))return;let o=l&&t.t===r;i.host.dispatchEvent(new CustomEvent(`${i.def.tag}:${r}-changed`,{detail:o?n:void 0,bubbles:!0}))})(e,t,i,r),Mi(e,t,n,l,i,r,!1)}),c.ve=f(c.ve,(e,t,n)=>Mi(e,t,n,void 0,void 0,!1,!0)),c.Ae=h(d,c.Ae,(e,t,n,l,i)=>(function(e,t){let n=Tl.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=ni.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===l;e=e.d)l=i.dt.get(e);if(void 0===l)return!1;let r=l.e;return!((null===r.r||r.r.y)&&!r.ro)&&(!!n||(bi(i,r.r),void v(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.pe}${""===r.E?"":`.${r.E}`}#ro: ${r.me.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.de;c.de=(t,n)=>{let l=Tl.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=li.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)}}},Ii="$recursion",Ri=new WeakMap,Li=new WeakSet,qi=new WeakSet,Di=0,zi=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Fi=e=>`[wcs/recursion-${e}]`;function Ui(e,t){let n=n=>v(`${Fi("declaration-invalid")} ${Ii} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${Fi("declaration-invalid")} ${Ii} ${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 Bi=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function _i(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 Vi(e,t,n){let l=_i(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ae){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===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.`),Bi(e,i.k)+l}function Hi(e,t,n){let l=new Set,i=new Set,r=(e,n,r)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${Fi("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${Fi("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(`${Fi("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(`${Bi(t,s)}.${t.key}`),u=e.read(i,a);r(u,i.t,s+1)&&(l.add(u),o(e._e(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._e(null,s).f,0))}function Ki(e,t){let n=function(e){let t=e[Ii],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(`${Fi("declaration-invalid")} ${Ii} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${Fi("declaration-invalid")} ${Ii} must declare exactly one anchor (it declares ${i.length}).`);let r=Ui("anchor",i[0][0]),o=Ui("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(`${Fi("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${zi(r)}((?:${zi(u)})*)${zi(n)}$`),n])}return{l:s,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${zi(s)}((?:${zi(`.*.${a}`)})*)$`)}}(t),l=Ri.has(e);null!==n?(l||Di++,Ri.set(e,n),qi.add(e),Li.has(e)||function(e){Li.add(e);let t=e,n=t.nt;t.nt=l=>{let i=Ri.get(e);if(l.t.includes("**")){let t=e.I.It(l.t)===l;return void(qi.has(e)||void 0===i&&t?l.getter=()=>z(l.t):t||n.call(e,l))}if(void 0!==i&&null===l.getter)for(let[e,n]of i.matchers)if(e.test(l.t)){l.getter=i.families.get(n),l.n>0&&(l.A=t.Ie++),i.owners.set(l,i.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let i=Ri.get(e);return l.call(e,void 0!==i&&t.includes("**")?Vi(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,l)=>{let r=Ri.get(e);if(void 0===r||!n.includes("**"))return i.call(e,n,l);if(void 0===l)return i.call(e,Vi(r,n,t.u));(!Array.isArray(l)||l.length>0)&&v(`${Fi("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=_i(r,n),s=[];return Hi(e,r,(t,n)=>{for(let l of i.call(e,Bi(r,t)+o,e.H(n)))s.push(l)}),s};let r=t.yn;t.yn=(n,l,i,o)=>{let s=Ri.get(e);if(void 0===s||!n.includes("**"))return r.call(e,n,l,i,o);Array.isArray(l)||w(9,[n]),l.length>0&&v(`${Fi("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${Fi("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.je>0&&w(8);let a=_i(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(`${Fi("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(`${Fi("readonly")} "${n}" writes into the recursive getter "${s.l}.**${e}".`)}let f=[];Hi(e,s,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=r.call(e,Bi(s,t)+a,e.H(n),i);return h}}(e)):l&&(Ri.delete(e),Di--)}function Ji(e,t){if(0===Di)return!1;let n=Ri.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.d){let l=n.owners.get(e);void 0!==l&&v(`${Fi("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var Gi={name:"recursion",install(){c.de=f(c.de,Ki),c.element=f(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){qi.delete(e)}(e)}),c.Ae=h(d,c.Ae,Ji)}},Xi="4.0.1",Yi=e=>e.split(".").slice(0,2).join("."),Qi=class extends Gt{static find(e){return e.querySelector?.(ne.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 Yi(this.version)===Yi(Xi)}};function Zi(e){let t=ne.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Qi{})}var er=()=>ne.tagNames.ssr,tr=Symbol.for("wcstack.ssr.snapshotBuilder"),nr=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),lr=e=>document.createComment(e),ir=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,rr=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),or=new WeakMap,sr=new WeakMap,ar=new WeakMap,ur=new WeakSet,cr=new WeakMap;function fr(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function hr(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 dr=e=>null===e.L?e.qe:e.L[e.L.length-1];function pr(e,t,n){let l=[lr(null===n?"wcs-[":`wcs-[:${n}`)];for(let e of t)null===n&&l.push(lr("wcs-|")),l.push(...fr(e.qe,dr(e)));l.push(lr("wcs-]")),e.after(...l);for(let e of l)ur.add(e)}function mr(e){if(e instanceof ot){pr(e.S,e.xe,null);for(let t of e.xe)gr(t);return}let t=e.O;null!==t&&(pr(e.G[e.G.length-1].S,[t],e.b),gr(t))}function gr(e){if(null!==e.c)for(let t of e.c)mr(t)}var yr=new Set(["script","style","template","textarea","title"]),$r="data-wcs-raw",vr=e=>yr.has(e.localName)||e.localName===er();function br(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(lr("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(lr("wcs-s")):1===t.nodeType&&!vr(t)&&br(t)}var wr=0;function kr(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=or.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.$&&n.set(t.$.S,t.$),null!==t.B)for(let e of t.B)n.set(e.S,e);for(let t of e.ce.values())for(let e of t)if(null!==e.W)for(let t of e.W.G)n.set(t.S,e.W);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),mr(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=ar.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>ur.has(e)||1===e.nodeType&&t.has(e)&&jr(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(vr(e.parentNode)?cr.has(e):t.has(n)&&rr(n,"wcs-t:"))&&(cr.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);vr(e)&&n.some(e=>cr.has(e))&&e.setAttribute($r,n.map(e=>cr.has(e)?`{{ ${cr.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}br(9===n.nodeType?n.body:n);let r=document.createElement(er());r.setAttribute("version",Xi);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"}${wr++}`;e.replaceWith(lr(`wcs-p:${i}`));let o=document.importNode(Ot(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(hr(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(hr(t,s,o))}e.before(r)}function Sr(e){!function(e){if(null!==e.querySelector(ne.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=>cr.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(`${ne.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===er())continue;let e=t.engine;null!=e&&kr(t,e)}}var xr=Symbol.for("wcstack.state.ssr.impl"),Nr=new Map,Ar=new WeakMap,jr=e=>!0===c.Eo?.(e),Or=e=>1===e.nodeType&&!vr(e)&&!jr(e),Cr=e=>e.f.flat().concat(e.K??[]),Mr=e=>{for(let t of Cr(e))t.remove()};function Tr(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&&!ir(s,"wcs-]");){let e=s.nextSibling;if(ir(s,"wcs-|"))o.push([]),s.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];rr(s,"wcs-[")?e=Tr(s,t,n):(n.push(s),Or(s)&&Pr(s,t))}s=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:o,K:s??r.appendChild(lr("wcs-]"))},u=Cr(a);s=a.K.nextSibling;for(let e of u)n?.push(e),t&&Nt.add(e);return t&&null!==i?Nr.set(i,a):Mr(a),s}function Pr(e,t){for(let n=e.firstChild;null!==n;)rr(n,"wcs-[")?n=Tr(n,t):(Or(n)&&Pr(n,t),n=n.nextSibling)}function Er(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=lr(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!ir(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]?hr(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&&!vr(i)&&(jr(i)?Ar.set(i,{ssr:t,Oe: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||zr(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{rr(e,"wcs-[")?l++:ir(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(rr(l,"wcs-["))i++;else if(ir(l,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Pr(e,n)}function Wr(e){let t=Ar.get(e);if(void 0===t||(Ar.delete(e),Er(e,t.ssr,t.Oe),!t.Oe))return null;let n=c.Oe;return c.Oe=Br,()=>{c.Oe=n,Ir()}}function Ir(){for(let e of Nr.values())Mr(e);Nr.clear()}function Rr(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Lr(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 qr(e,t,n){if(nr()){if(n instanceof Array){for(let e=n.length;e-- >0;)mt(n[e])&&n.splice(e,1);let e=t;if(n.some(gt))ur.add(e);else if(e.localName.includes("-")&&!jr(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);ar.set(e,t)}return}if("string"==typeof n){if(cr.set(t,n),vr(t.parentNode))return;let e=lr(`wcs-t:${encodeURIComponent(n)}`),l=lr("wcs-/t");return t.before(e),void t.after(l)}let l=or.get(e);void 0===l&&or.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&&Nr.size>0){let e=Nr.get(n);void 0!==e&&(Nr.delete(n),Nr.set(t,e))}}var Dr=e=>null!==e&&8===e.nodeType&&[ne.commentIfPrefix,ne.commentElseIfPrefix,ne.commentElsePrefix].includes(e.data),zr=e=>3===e.nodeType&&""===e.data.trim(),Fr=e=>(Nr.get(e)?.K??e).nextSibling;function Ur(e,t){if(t.length!==e.sn.childNodes.length)return!1;let n=e.On;for(let l=0;l<n.length;l++){let i=n[l],r=e.sn,o=t[i[0]];for(let e=0;;){if(r=r.childNodes[i[e]],o?.nodeName!==r.nodeName)return!1;if(++e===i.length)break;o=o.firstChild;for(let t=i[e];t>0&&null!==o;t--)o=Fr(o)}e.ko[l]=o}return!0}function Br(e,t,n){if(0===Nr.size)return null;let l=t,i=0;if(!n){let e=ne.commentIfPrefix;if(!ir(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Dr(n)&&i++,!ir(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Nr.has(l)&&null!==n&&!ir(n,e)&&1!==n.nodeType;n=n.nextSibling)Dr(n)&&(l=n)}let r=Nr.get(l);if(void 0===r)return null;if(!n&&r.branch!==i)return Nr.delete(l),Mr(r),null;let o=r.f.shift();if(0===r.f.length&&Nr.delete(l),r.K?.replaceWith(...fr(t,l)),r.K=null,void 0===o)return null;let s=[];for(let e=0;e<o.length;e++){let t=Nr.get(o[e]);if(s.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.K;)e++}if(!Ur(e,s)){let n=(e.In?e.root:e.sn).cloneNode(!0);s=e.In?[n]:[...n.childNodes],Ur(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 _r={name:"ssr",install(){c.jn=qr,c.hr=Wr;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||nr())return;let n=t.previousElementSibling,l=n?.localName===er(),i=l?n.getAttribute("version"):null,r=null===i||Yi(i)===Yi(Xi);if(r){let t=e,n=t.ke;t.ke=(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] <${er()} version="${i}"> does not match ${Xi}: 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(`[${$r}]`)))e.textContent=e.getAttribute($r),e.removeAttribute($r);let h=9===f.nodeType?f.body:f;o?function(e,t,n){let l=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!jr(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 > ${ne.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of se(t.getAttribute(ne.bindAttributeName)??"")){let t=l.Je;l.Ee[0]===r&&n.push([e?Lr(e,t,1,0):t,l.Ee.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:Lr(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]:Lr(l,r[2],2,1)??r[2]};for(let t of Rr(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!ir(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]?[lr(`@@:${r(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let l of Rr(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=ne.bindAttributeName;s.removeAttribute("id"),s.setAttribute(a,s.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+r(n??l,i))),o(s.content,n??l);let u=s.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?s.content.childNodes:[s])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(h,n,a):Er(h,n,r),n.remove(),r&&(c.Oe=Br,queueMicrotask(()=>{Ir(),c.Oe=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[xr]={build:Sr,reset(){wr=0}},void 0===e[tr]&&(e[tr]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[xr].build(t),reset:()=>e[xr].reset()})}(),c.To=f(c.To,Zi);for(let e of Qt())Zi(e)}},Vr="__WCSTACK_DEVTOOLS_HOOK__",Hr=null,Kr=new Set,Jr=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),Gr=new WeakMap,Xr=0;var Yr=new WeakMap;function Qr(e){if(null===Hr)return;let t=Yr.get(e),n=Kr.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=Gr.get(e);return void 0===t&&Gr.set(e,t=++Xr),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:Jr(e,o,c)})},r=e=>i(e.i,e.name,e.a,e.o,e.r,e.nn()),o=e=>{if(!l.has(e)){if(l.add(e),null!==e.he)for(let t of e.he)r(t);if(e instanceof Xe&&null!==e.fe){let t=e.F.ze;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.fe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.c)for(let t of e.c)s(t)}},s=e=>{if(!l.has(e))if(l.add(e),e instanceof ot){i(-1,"for",e.S,e.l.o,e.l.ae,"for");for(let t of e.xe)o(t)}else null!==e.O&&o(e.O)};for(let t of e.ce.values())for(let e of t)r(e),null!==e.W&&s(e.W);for(let t of e.oe.values())if(null!==t.$&&s(t.$),null!==t.B)for(let e of t.B)s(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||Hr({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&Hr({type:"state:binding-added",...l});Yr.set(e,n)}function Zr(e){let t=Wt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function eo(e){let t=new Set,n=new Set,l=new Set,i=new Set;for(let r of e.I.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.ie&&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.Re.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 to=new WeakSet,no=new WeakMap;function lo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(to.has(t))return;to.add(t);let l=t.emit;t.emit=(...i)=>(null!==Hr&&Hr({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.Re.values())t(n,"event")}(e),"connected"===t){if(Kr.has(e))return;Kr.add(e),Hr?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Qr(e)}else"disconnected"===t&&(Kr.delete(e),Qr(e),Hr?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function io(e,t,n,l,i,r){if(null===Hr)return;let o=Jr(e,t,0===t.n?null:n),s=no.get(e);void 0===s&&no.set(e,s=new Set),s.add(o),r&&Hr({type:"state:write",absoluteAddress:o,value:i,oldValue:l,hasOldValue:!0})}function ro(e){if(null===Hr)return;let t=no.get(e);no.delete(e),void 0!==t&&Hr({type:"state:update-batch",addresses:t}),Qr(e)}function oo(e,t,n){Hr?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.nn(),error:t})}var so={"*":["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 ao(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...so["*"],...Object.hasOwn(so,e)?so[e]:[]])(n);return l.includes(t)||w(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())}([gn,Kn,$l,Al,Wi,Gi,_r,{name:"devtools",install(){c.element=f(c.element,lo),c.be=f(c.be,io),c.Fe=f(c.Fe,ro),c.Ue=f(c.Ue,oo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[Vr]??(e[Vr]=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:Xi,getStateElements:()=>[...Kr].map(eo),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.I.all()){let l=n._,i=n.Ce?.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}(Zr(e)),keys(e){let t=Zr(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 Zr(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){Zr(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(e){let t=null===Hr&&null!==e;Hr=e,null===e&&(Yr=new WeakMap),c.st=e&&((e,t)=>Hr?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of Kr)Qr(e)})}})}()}},{name:"native-commands",install(){c.or=ao}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[qt]&&(e[qt]={protocol:"wcs-binder",version:1,bind:Ut})})(),Qt().includes(e)||Yt.push(new WeakRef(e));let t=ne.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),c.To?.(e)}();
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|