wcstack 4.8.0 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/package.json +1 -1
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class{constructor(e,n,r){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.B=[],this.Q=[],this.mt=null,this.F=-1,this.Y=t,this.De=null,this.It=null,this.jt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=e,this.c=r,this.s=n;let i=null===r?[null]:r.h.slice(),s="*"===n;s&&i.push(r),this.n=i.length-1,this.z=s?[]:null===r?[n]:[...r.z,n],this.h=i}_n(e){this.ht.has(e)||(this.ht.add(e),this.B.push(e),e.Q.push(this))}jo(e){this.ht.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Do(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.De=null,this.It=null,this.jt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.c}return!1}},t=Symbol("unset"),n=Symbol("dirty"),r=Symbol("failed"),i=class{constructor(e=null){this.yt=new Map,this.Vn=e}wt(e){return this.yt.get(e)}get(t){let n=this.yt.get(t);if(void 0!==n)return n;let r=t.lastIndexOf("."),i=r<0?null:this.get(t.slice(0,r));return n=new e(t,t.slice(r+1),i),this.Vn?.(n),this.yt.set(t,n),i&&i.u.push(n),n}all(){return this.yt.values()}Dt(e){this.yt.delete(e.t)}},s=new Map;function o(e){let t=s.get(e);if(void 0!==t)return t;let n=!0,r=e.split("."),i=[];for(let e=0;e<r.length;e++){let t=r[e],s=t.charCodeAt(0);e>0&&s>=48&&s<=57?(n=!1,i.push(Number(t)),r[e]="*"):"*"===t&&i.push(-1)}if(!n)return{o:r.join("."),indexes:i};let o={o:e,indexes:null};return s.size>4095&&s.clear(),s.set(e,o),o}var l=class{constructor(e,t,n){this.bt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.$=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Lt=!1,this.vt=!1,this.o=e,this.ce=t,this.n=e.n+1}},u=[],c={};function h(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function d(e,t,n){return null==t?n:(...r)=>{let i=t(...r);return e(i)?i:n(...r)}}var f=e=>!0===e,p=e=>void 0!==e,m=e=>null!=e,g=new Set;function y(e){let t=e.$features;if(null!=c.Mt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Mt(e)}}function b(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 w(e,t,n){throw new Error(`[@wcstack/state] ${e}${c.Bo?.(e,t,n)??""}`)}function v(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function _(e,t=[]){return c.Mo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function $(e,t,n,r){w(_(e,t),n,r)}var k=class{constructor(e){this.kt=new Set,this.name=e}get size(){return this.kt.size}subscribe(e){return this.kt.add(e),()=>{this.kt.delete(e)}}unsubscribe(e){return this.kt.delete(e)}emit(...e){let t=[];for(let n of this.kt)try{t.push(n(...e))}catch(e){t.push(void 0),v(e,`[@wcstack/state] ${_(17,[this.name])}`)}return t}};function S(e,t,n){if(void 0===e)return[];Array.isArray(e)||$(18,[t]);let r=new Set;for(let i of e)("string"!=typeof i||""===i)&&$(19,[t]),i===n&&$(20,[t,i,n]),r.has(i)&&$(21,[t,i]),r.add(i);return e}var N=Symbol.for("wcstack.transition-runner");function A(e){let t=globalThis[N];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function C(e,t,n){let r=A(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var E="else",T="eventToken",x="class",P="attr",O=/^\$[1-9]\d{0,2}$/,M=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function L(e){let t=[],n=[],r="",i=null,s=!1,o=-1,l=-1,a=e=>{let i=function(e,t,n){let r=-1===t?e.length:t,i=-1===n?0:n;return e.slice(r-e.slice(0,r).trimStart().length,i+e.slice(i).trimEnd().length)}(r,o,l);(!e||i||s)&&(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,s))),r="",s=!1,o=-1,l=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=r.length),r+=n,l=r.length):'"'===n||"'"===n?(i=n,s=!0):","===n?a():r+=n}return null!==i&&$(107,[i,e]),a(!0),{args:t,literals:n}}var I=e=>e.trim();function j(e,t){let n=[],r=null;for(let i=0;i<e.length;i++){let s=e[i];null!==r?s===r&&(r=null):"'"===s||'"'===s?r=s:s===t&&n.push(i)}return n}var R=(e,t)=>j(e,t)[0]??-1;function H(e,t){let n=[],r=0;for(let i of j(e,t))n.push(e.slice(r,i)),r=i+1;return n.push(e.slice(r)),n}function W(e,t,n){let r=R(e,"|");if(-1===r)return[e.trim(),[]];let i=e.slice(r+1).trim(),s=n.get(i);return void 0===s&&(s=function(e,t,n){let r=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>j(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&$(108,[e]),-1!==i&&-1===n&&$(109,[e]),-1!==i&&i<n&&$(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();$(111,[e,t])}let s=(-1===n?e:e.substring(0,n)).trim();if(0===s.length&&$(112,[r]),s.includes("#")){let[,e]=s.split("#");$("input"===t?113:114,[s,e])}return-1===n?{Hn:s,args:[],literals:[]}:{Hn:s,...L(e.substring(n+1,i))}})}(H(i,"|").map(I),t,e),n.set(i,s)),[e.slice(0,r).trim(),s]}var U=new Map;function D(e){$(1101,[e])}function F(e){let[t,n]=W(e,"output",U);t.includes("@")&&$(32,[t]);let r=t,i=r.startsWith("."),s=i?r.slice(1):r;return(s.length>0&&s.split(".").some(e=>0===e.length)||!i&&0===s.length)&&$(119,[e]),function(e){e.includes("**")&&D(e);let t=e.split(".").length;t>512&&$(117,[e,t])}(r),{Ze:r,et:n}}var z=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],q=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function B(e){return e.includes("**")&&D(e),e}var G=0;function K(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var V=()=>new Set,J=()=>[],Q=new WeakMap;function X(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Y(e,t){return e===t||e!=e&&t!=t}function Z(e,t,n){let r=e._?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e._.delete(t)}function ee(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function te(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function ne(e,t,n){let r=te(e,n);return null!==r&&r.l.o===t.h[n]?r:null}var re=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.St=[],this.Me=null,this.qn=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.j=0,this.qt=0,this.yn=!1,this.Kt=!1,this.zt=!1,this.Ce=0,this.Kn=()=>{this.j=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.He=[],this.Xn={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=te(this.d,t);null===n&&$(7,[e]);let r=this.o(e);if(null!==r.getter||r.ae)return this.watchIndex(t),n.y===this.read(r,null);let i=this.X;if(null!==i){let e=i.getter,n=r.De??(r.De=[]);if(!n.some(n=>n.getter===e&&n.Gn===t)){n.push({getter:e,Gn:t});let i=e.h[t];(i.It??(i.It=[])).push({source:r,getter:e})}}return n.y===this.v(r,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,te(this.d,n.n)))},$dependOn:e=>{this.resolve(B(e),this.d),null!==this.X&&0===this.X.be&&this.Jn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,r)=>this.wn(e,t,n,r),$resolve:(...e)=>{let t=B(e[0]),n=e[1]??[],r=this.o(t,!0);this.bn("$resolve",t,r,n,!0);let i=this.Qn(r,n,null);if(e.length<3)return this.read(r,i);this.A(r,i,e[2])},$postUpdate:e=>{this.resolve(B(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.P[n.y],Q.delete(n.l.P),this.T.Xt(n)),this.vn(t,n),null!==n&&this.Zn(n,t,void 0,n.$,!1),0===t.n&&this.eo(t,void 0,void 0,!0),this.Gt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.He.push(e),this.ot(e)}),this.to(e);let n=this,r={getOwnPropertyDescriptor(e,t){let r=Reflect.getOwnPropertyDescriptor(n.target,t);return r&&(r.configurable=!0),r},get(e,t,r){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.rt(t);if(t.indexOf(".")<0){let e=n.O.wt(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return r===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,r)=>"symbol"==typeof t?Reflect.set(n.target,t,r):(n.resolve(B(t),n.d),n.A(n.rp,n.rr,r),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])r[e]=(t,...r)=>Reflect[e](n.target,...r);this.proxy=new Proxy({},r)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}no(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let r=Object.getOwnPropertyDescriptor(n,e);if(void 0===r.get&&void 0===r.set)continue;let i=this.o(e);i.getter=r.get??null,i.se=r.set??null,null!==i.getter&&i.n>0&&(i.F=this.Le++)}for(let e of this.O.all())this.ot(e)}ot(e){e.t.includes("**")&&D(e.t),("__proto__"===e.s||"prototype"===e.s)&&$(120,[e.t]);let t=e.c;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.Vo(e)}Vo(e){let t=e.t,n=e.s;if(O.test(n))e.getter=function(){return this[n]};else{let r=t.split("."),i=r.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(i<0||r.indexOf("*",i)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.c,this.d)?.[n]),e.se=r=>{if(this.resolve(t,this.d),this.rp!==e)return this.A(this.rp,this.rr,r);let i=this.read(e.c,this.d);null==i&&$(4,[t,i]),i[n]=r}}e.hn=!0,e.n>0&&(e.F=this.Le++)}Ue(e,t){let n=null===e?this.oe:e.u??=new Map,r=n.get(t);return void 0===r&&n.set(t,r=new a(t,e)),t.pn=!0,this.G(r),r}oo(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}G(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.io(e);let n=function(e,t,n){let r=Array.isArray(t)?t:u;if(r===e.P)return null;let i=e.f,s=r.length,o=i.length,a=new Array(s),c=0;for(;c<s&&c<o&&i[c].$===r[c];)a[c]=i[c],c++;let h=o-1,d=s-1;for(;h>=c&&d>=c&&i[h].$===r[d];)a[d]=i[h],h--,d--;if(c>h)for(let t=c;t<=d;t++)a[t]=new l(e,t,r[t]);else if(c>d)for(let e=c;e<=h;e++)n.Bt(i[e]);else{let t=h<d?h:d;for(let e=c;e<=t;e++)i[e].$===r[e]&&(a[e]=i[e]);let s=new Map;for(let e=h;e>=c;e--){let n=i[e];if(e<=t&&a[e]===n)continue;let r=s.get(n.$);void 0===r?s.set(n.$,n):Array.isArray(r)?r.push(n):s.set(n.$,[r,n])}for(let t=c;t<=d;t++){if(void 0!==a[t])continue;let n,i=r[t],o=s.get(i);void 0!==o&&(Array.isArray(o)?(n=o.pop(),0===o.length&&s.delete(i)):(n=o,s.delete(i))),a[t]=n??new l(e,t,i)}for(let e of s.values())if(Array.isArray(e))for(let t of e)n.Bt(t);else n.Bt(e)}for(let e=c;e<s;e++){let t=a[e];t.y!==e&&(t.y=e,n.Lo(t))}return e.f=a,e.P=r,i}(e,t,this);if(null===n)return;if(e.P===t){let n=K(this.Ut,t,J);if(n.push(e),n.length>1)for(let e of n)e.vt=!0}c.Qt?.(this,e,n),(null!==e.N||null!==e.M)&&!e.te&&(e.te=!0,this._e.push(e),this.ve());let r=e.o.It;if(null!==r)for(let{source:t,getter:i}of r){let r=this.v(t,null),s=n[r],o=e.f[r];s!==o&&(void 0!==s&&s.w&&this.kn(i,s),void 0!==o&&this.kn(i,o))}}Lo(e){this.T.Ho(this,e)}Bt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)Z(e.source,e.key,e.sub);e._=null}if(null!==e.u)for(let t of e.u.values()){this.io(t);for(let e of t.f)this.Bt(e)}}io(e){let t=this.Ut.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.vt=!1,1===t.length&&(t[0].vt=!1))}resolve(e,t){let n=o(e),r=this.rp=this.o(n.o,!0),i=n.indexes;this.rr=0===r.n?null:null===i?ne(t,r,r.n):this.Qn(r,i,t,e)}Qn(e,t,n,r){let i=null;for(let s,o=1,l=0;o<=e.n;o++){let a=e.h[o],c=this.Ue(i,a),h=t[l++];if(h<0)h=ne(n,e,o)?.y??-1;else if(r&&c.P===u&&Object(s=this.v(a,i))===s){let t=e.t.split("."),n=a.t.split(".").length;t[n]=r.split(".")[n],e=this.o(t.join("."),!0),o--;continue}if(i=c.f[h]??null,null===i)break}return this.rp=e,i}it(e,t){return 0===e.n?ee(this.target,e.z):null===t?void 0:ee(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Jn(e,t,n),null!==e.getter)return this.T.Uo(this,e,t);if(e.ae){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.tt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&$(301,[e.t],e.s,Object.keys(this.target)),this.it(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Jn(e,t,n){let r=n.getter;e._n(r),0===r.n?e.Z!==n.de&&(e.Z=n.de,n.Sn.push(e)):e.n>0&&te(t,Math.min(e.n,r.n))!==te(n.r,Math.min(e.n,r.n))&&(r.mt??(r.mt=new Set)).add(e)}qo(e,t){for(let n=0;n<this.Ht;n++){let r=this.qn[n];r.getter===e&&r.r===t&&$(701,[e.t])}this.Ht>=128&&$(801,[e.t]);let n=this.Ht++;this.Be++;let r=this.qn[n]??={getter:e,r:t,be:0,de:0,Sn:[]};r.getter=e,r.r=t,r.be=0,r.de=++G,r.Sn.length=0;let i=this.X;this.X=r;let s=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Ko(e,r),t}finally{this.Be--,this.Ht--,this.X=i,this.d=s,r.r=null}}Ko(e,t){let n=t.de;for(let e of t.Sn)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.it(t,null))||this.so(t,e))}so(e,t){return e.jo(t),this.He.push(e),!1}zo(){for(let e=this.He;e.length>0;e=this.He){this.He=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.c||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Dt(n),t.add(n.c);for(let e of n.Q)this.so(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.He.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.be){let n=t.getter,r=n.h[e];if(r){let e=r.jt??(r.jt=[]);e.includes(n)||e.push(n)}}}rt(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:O.test(e)?+e.slice(1):0;return(n<1||n>128)&&$(1001,[e]),this.watchIndex(n),te(this.d,n)?.y}let n=this.Xn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.rt?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,r=this.rr;if(null!==n.getter||n.ae||n.n>0)return Y(this.read(n,r),t);let i=this.X;return null!==i&&0===i.be&&this.Yo(n,t,i),Y(this.v(n,null),t)}Yo(e,t,n){let r=n.getter,i=n.r,s=null===i?this.Yn:i._??(i._=[]);for(let i=0;i<s.length;i++){let o=s[i];if(o.sub.getter===r&&o.source===e){if(Y(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Z(e,o.key,o.sub),s.splice(i--,1))}}let o={getter:r,r:i};K(e._??=new Map,t,V).add(o),s.push({source:e,key:t,sub:o,de:n.de})}eo(e,t,n,r){this.Zt(e,i=>{let s=i._;if(null===s&&null===i.De)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),l=ee(t,o),a=ee(n,o);if(null!==i.De&&this.Xo(i,l,a,r),null!==s)for(let e of r?s.keys():[l,a]){let t=s.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.w?this.T.ke(this,n.getter,n.r):Z(i,e,n)}})}A(e,t,n,r=!1,i=!1){if(this.Be>0&&$(8),i||this.Ce>0?this.Kt=!0:this.zt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.En(e.se,t,[n])}finally{this.Gt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&$(2,[e.t]),e.n>0&&null===t&&$(3,[e.t]);let s=e.ae?this.v(e,t):this.it(e,t);if(r||!this._t||!Object.is(s,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,Q.delete(e.l.P),e.$=n,this.T.Xt(e)}else{let r=1===e.z.length?0===e.n?this.target:t.$:this.v(e.c,t);null==r&&$(4,[e.t,r]),r[e.s]=n}this.$n(e,t),null!==t&&this.Zn(t,e,s,n),0===e.n&&this.eo(e,s,n),this.Gt(e,t,s,n,!0,i)}}lo(e){return(this.Ut.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}Zn(e,t,r,i,s=!0){let o=e.l,l=t.t.slice(o.o.t.length+2),a=""!==l&&function(e){let t=Q.get(e);if(void 0===t){let n=new Set;Q.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.vt&&null===o.o.getter&&!o.o.B.length)return;let u=e.$,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${l}`,!0);""===l&&(n.$=i,this.T.Xt(n)),s?this.$n(o,n):this.vn(o,n),this.Gt(o,n,r,i,s)};for(let t of this.lo(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.$===u&&n.y!==e.y&&c(t,n);if(""===l)return;let h=new Set([o.P]),d=e=>Array.isArray(e)&&e.includes(u),f=(e,t)=>{if(!h.has(e)&&h.add(e))for(let t of this.Ut.get(e)??[])for(let e of t.f)e.$===u&&c(t,e);for(let r of t){let t=r.Y,i=t===n;i&&(t=this.oe.get(r)?.P),(i||d(t))&&!h.has(r.B)&&h.add(r.B)&&(!i&&t!==e&&this.T.ke(this,r,null),f(t,r.B))}},p=e=>{for(let t of e.Q)if(!h.has(t)&&h.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.it(t,null);d(e)&&f(e,t.B)}};null!==o.o.getter?p(o.o):f(o.P,o.o.B)}vn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.vt?this.lo(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.$t(e,n),this.vn(e,n)}})}$n(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let r=null===t?this.oe:t.u;if(null!==r)for(let t of r.values())t.o.ee(e)&&n(t)}Xo(e,t,n,r){for(let{getter:i,Gn:s}of e.De)this.ao(i.h[s],e=>{for(let s of r?e.f.keys():[t,n]){let t="number"==typeof s?e.f[s]:void 0;void 0!==t&&this.kn(i,t)}})}kn(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Gt(e,t,n,r,i,s){c.re?.(this,e,t,n,r,i,s),this.qe(e,t)}qe(e,t){this.T.Jo(this,e,t),this.ve()}co(e){let t=this.nt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.nt.set(e,n);let r=this.root,i=this.Un;return r.addEventListener(e,t=>{for(let s=t.target;null!==s&&s!==r;s=s.parentNode){let r=s[n];if(void 0!==r&&(r(t),t.cancelBubble))return;let o=s[i];if(void 0!==o&&o.w&&o.Qo(e,t))return}}),n}reset(e){let t=this.target,n=this.tt;for(let e of this.O.all())null===e.c&&null!==e.getter&&n.add(e.s);this.to(e);for(let e in t)"$"!==e[0]&&n.add(e);for(let t of n)t in e&&n.delete(t);for(let e of this.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.uo(e);this.Me=null;try{this.Yt()}finally{this.Nn()}c.element?.(this,"reset")}to(e){for(let[t,n]of z)void 0!==e[t]&&b(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||$(46);for(let e of t)b(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&$(44,["state","$behavior"]);for(let e in n)(!q.includes(e)||"boolean"!=typeof n[e])&&$(44,["$behavior",e]);let[r,i,s]=q.map(e=>n[e]??!0);void 0!==this.target&&(r!==this.Wt||i!==this._t||s!==this.Vt)&&$(45);let o=function(e,t){let n={};for(let r of S(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new k(r);return Object.freeze(n)}(e,this.commands),l=function(e,t){let n=new Map;for(let t of S(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let r=e.$on;if(void 0===r)return n;(null===r||"object"!=typeof r)&&$(22);for(let[e,i]of Object.entries(r)){let r=n.get(e);void 0===r&&$(23,[e]),"function"!=typeof i&&$(24,[e]),r.subscribe((...e)=>t(i,e))}return n}(e,this._o);this.Wt=r,this._t=i,this.Vt=s,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Do();this.Yn.length=0,this.no(e),this.commands=o,this.Oe=l}uo(e){this.oo(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.bt=null,n._=null,this.$t(t,n),null!==n.u)for(let e of n.u.values())this.uo(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}Zo(e,t,n){let r=this.Oe.get(e);void 0===r&&$(1301,[e],e,this.Oe.keys()),r.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&$(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let r=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof r&&$(5,[e]),this.En(r,n,[t,...this.H(n)])}En(e,t,n){let r=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=r}}$t(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.we;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let r=t.N;null!==r&&null!==r.pe&&r.fo(this,e);let i=t.l.M;if(null!==i)for(let n of i){let r=n.map.get(t);void 0!==r&&null!==r.pe&&r.fo(this,e)}}xn(e,t,n){this.Zt(e,e=>{let r=e.B;for(let i=0;i<r.length;i++){let s=r[i];if(0===s.n)this.st(s,null,n);else if(null===t||0===e.n||s.h[1]!==e.h[1]||null!==s.mt&&s.mt.has(e))this.nn(s.h[s.n],e=>this.st(s,e,n));else if(s.n<=e.n){let e=te(t,s.n);null!==e&&this.st(s,e,n)}else this.en(t,s,e=>this.st(s,e,n))}})}st(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.$t(e,t),this.xn(e,t,n))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.ao(e,e=>{for(let n of e.f)t(n)})}ao(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let r=n.u?.get(e);void 0!==r&&t(r)})}en(e,t,n){if(e.l.n===t.n)return n(e);let r=e.u?.get(t.h[e.l.n+1]);if(void 0!==r)for(let e of r.f)this.en(e,t,n)}nr(e){let t=e.r;null===t?K(this.ue,e.o,V).add(e):(t.we??(t.we=[])).push(e)}Rn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Pn(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Lt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];v(n,`[@wcstack/state] ${_(e)}`),c.at?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Pn()}Yt(){this.Et=!1;let e=this.qt;this.qt=0;let t=0;if(!this.Kt||this.zt?this.Kn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Kn,0),this.Kt=this.zt=!1,t>100)101===t?this.po(41,100):this.Pn();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.yn?this.Pn():this.po(11,32),this.yn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Lt=!1,this.oo(e)}let r=this._e,i=this.We;this._e=[],this.We=[];let s=()=>{for(let e of r){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.Nt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<i.length;t++){let n=i[t];!n.te||null===n.j==(0===e)||(n.te=!1,(null===n.Tn||n.Tn.w)&&this.Ke(n))}this.gn||(this.ze(),this.Et&&(this.qt=t+1))},o=r.length>0||i.some(e=>null!==e.j)?C("state",s):s();void 0!==o&&o.then(void 0,v)}}finally{this.gn=!1}this.Kt=this.zt=!1,this.ze(),c.me?.(this),this.zo(),e>0&&this.Et&&(this.qt=t+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,r){this.xt(e,{o:{t:t},a:n,on:()=>r})}Ke(e){try{e.apply()}catch(t){return void this.St.push([t,e])}null!==this.Me&&this.mo(e.o,e.r)}mo(e,t){let n=K(this.Me,e.t,J);null!==t&&n.push(this.H(t))}Nn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}ze(){let e=this.Me;if(null!==e&&e.size>0){this.Me=new Map;let t,n=[...e.keys()],r={};for(let[t,n]of e)n.length>0&&(r[t]=n);this.Ce++;try{t=this.Ee("$renderedCallback",[n,r])}catch(e){v(e)}X(t)?t.then(this.zn,e=>{this.zn(),v(e)}):this.Ce--}if(0===this.St.length)return;let t=this.St;this.St=[];let n=this.target.$errorCallback;for(let[r,i]of t){c.Ye?.(this,r,i);let t=i.o.t,s=i.on();if("function"==typeof n)try{let e=this.Ee("$errorCallback",[r,{path:t,bindingType:s,node:i.a}]);X(e)&&e.then(void 0,v)}catch(e){v(e)}else v(r,`[@wcstack/state] ${_(12,i.name?[s,t,i.name,i.i]:[s,t])}`,i.a)}}Ee(e,t=[]){let n=this.target[e];return"function"==typeof n?this.En(n,null,t):void 0}ho(e,t,n){if(0===e.n)return void n(null,[]);let r=[],i=(s,o)=>{let l=e.h[s];this.read(l,o);let a=this.Ue(o,l),u=t=>{r.push(t.y),s===e.n?n(t,r):i(s+1,t),r.pop()};for(let e of s-1<t.length?[a.f[t[s-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.bn("$getAll",e,n,t,!1);let r=t;if(void 0===r){r=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=ne(t,n,e);if(null===i)break;r.push(i.y)}0===r.length&&$(6,[e])}}let i=[];return this.ho(n,r,e=>i.push(this.read(n,e))),i}wn(e,t,n,r){Array.isArray(t)||$(9,[e]),this.Be>0&&$(8);let i=this.o(e,!0);this.bn("$setAll",e,i,t,!1);let s=[];this.ho(i,t,(e,t)=>s.push([e,t.slice()]));let o=!0===r?.spread;o&&(!Array.isArray(n)||n.length!==s.length)&&$(10,[e,s.length]);let l=0;for(let e=0;e<s.length;e++){let[t,r]=s[e],a="function"==typeof n?n(this.v(i,t),...r):o?n[e]:n;void 0!==a&&(this.A(i,t,a),l++)}return l}bn(e,t,n,r,i){let s=r.length;(s>n.n||i&&s<n.n)&&$(i?901:902,[e,t,n.n,s])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en"},se=new Map,oe=new Set(["if","elseif","else","for"]),le=new Set([E,"if","elseif","for","..."]),ae=new Set([x,P,"style","command",T,"state"]);function ue(e){let t=function(e){return H(e,";")}(e).map(I).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&$(101,[e]);let n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(le.has(i)){let t;return i!==n&&$(102,[e,i]),i===E?(r.length>0&&$(103,[e]),t={Ze:"#else",et:[]}):"..."===i?(0===r.length&&$(104,[e]),t=F(r),t.et.length>0&&$(105,[e])):(t=F(r),"for"===i&&t.et.length>0&&$(121,[e])),{$e:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===x||i===P)&&$(122,[e,i]);let s=F(r),o=function(e){let[t,n]=W(e,"input",se),r=t.split("#").map(I);r.length>2&&$(115,[t]);let[i,s]=r,o=i.split(".").map(I);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&$(116,[e]),{$e:i,Ne:o,rn:s?s.split(",").map(I):[],D:n}}(n),[l]=o.Ne;if(""===l&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||ae.has(e[0]))&&$(106,[n]),{...o,$e:e.join("."),Ne:e,...s,b:"prop"}}return{...o,...s,b:"radio"===i||"checkbox"===i?i:l===T||l.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>oe.has(e.b))&&$(201,[e]),t}var ce=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],he=new Map,de=new Map;function fe(e){for(let t of Object.keys(e))he.set(t,{...e[t]});de.clear()}function pe(e){return he.has(e)}function me(e){$(26,[e])}function ge(e){$(27,[e])}function ye(e,t){$(28,[e,t])}function be(e,t){$(29,[e,t])}function we(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return we(e)||ge(t),Number(e)}function _e(e,t,n){return ve(e?.[t]??me(n),n)}function $e(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let r=_e(n,0,e);return n=>("number"!=typeof n&&ye(e,n),t(n,r))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??me("eq"),r=$e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(we(n)||ge("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??me("ne"),r=$e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(we(n)||ge("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ne=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ce(e){return 0===e.length?null:(Ne||(Ne=!0,fe(Se)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=de.get(r);if(typeof i<"u")return i;let s=he.get(e);void 0===s&&function(e,t){ce.includes(e)&&w(`[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),$(501,[e],e,t)}(e,he.keys());let[o,l]=s.arity;t.length<o&&$(601,[e,o,t.length]),t.length>l&&$(602,[e,l,t.length]);let a=s.factory(t,n);return de.set(r,a),a}(e.Hn,e.args,e.literals)))}var Ee=Symbol.for("wcstack.trustedTypes.policy");function Te(){let e=globalThis[Ee];return null!==e&&"object"==typeof e?e:null}function xe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Pe(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Te(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Oe=Symbol.for("wcstack.state.view-transition-naming"),Me=new WeakSet;function Le(){let e=A("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Ie=new WeakMap,je=e=>e.customElementRegistry??customElements;function Re(e,t,n,r,i,s=!1){let o=n.localName;if(!o.includes("-"))return i(null);let l=je(n);if(!s&&!n.isConnected&&void 0===l.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,r,i,!0));let a=()=>{let e=l.get(o);l.upgrade(n),i(e?function(e){if(Ie.has(e))return Ie.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,go:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Ie.set(e,n),n}(e):null)};if(!s&&void 0!==l.get(o))return a();null!==r&&!r.w||function(e,t,n){let r=n;null!==t&&(t.Rt??=[]).push(()=>{r=null}),e.then(()=>r?.())}(l.whenDefined(o),r,()=>{try{a()}catch(r){ze(e,r,t,n)}e.ve()})}function He(e,t,n,r,i=t.o,s,o,l){let a=l.properties.get(r)??null,u=l.inputs.has(r),h=e.Vt;h&&null===a&&!u&&$(38,[r]);let d=t.U;(null===a?"element"===d||"auto"===d:!u&&("state"===d||"auto"===d))&&$(39,[d,r]),"connect"===t.G&&null===a&&$(40,[r]);let f=h&&null!==a&&!u,p=new Ge(e,De,n,r,i,s,o,t.x,void 0);p.D=t.D,et(e,p,!f),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.go||c.detail?.(n,r,i)),(!p.An||!Object.is(i,p.value))&&(i=Ae(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.go,!0))});let m=d??(f?"element":"state");if("state"===m)f||e.Ke(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(f||e.Ke(p));let t=n[r];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.G||n.isConnected?i():Promise.resolve().then(i)}return p}function We(e,t,n){$(e,[t.localName,n])}var Ue=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),De=11,Fe=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],ze=(e,t,n,r)=>e.Jt(t,n.o?.t??n.Pt,r,Fe[n.i]),qe=Symbol();function Be(e,t,n){let r=t.U;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.q:qe}var Ge=class{constructor(e,t,n,r,i,s,o,l,a,u=null){this.te=!1,this.D=null,this.An=!1,this.engine=e,this.i=t,this.a=n,this.name=r,this.o=i,this.r=s,this.Tn=o,this.x=l,this.value=a,this.j=u}on(){return Fe[this.i]}apply(){if(null!==this.j)return void this.j.Nt();let e=Ae(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===De||8===this.i||xe(this.name)))return;if(this.value===qe)return void(this.value=e);let t=this.a;if(this.i!==De)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ve(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ae(this.D,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let r=this.sn(),i=n.v(this.o,this.r),s=Array.isArray(i)?i:[],o=s.includes(r);if(t.checked?o:!o)return;e=o?s.filter(e=>e!==r):[...s,r]}else e=Ae(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},Ke=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ve(e,t,n,r){switch(e){case 0:return void(t.data=null==r?"":String(r));case 1:return void(Ke(n)?t[n]="innerHTML"===n?Pe(r):null==r?"":String(r):xe(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Pe(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,r])));case 8:return void(t.innerHTML=Pe(r));case 2:return null!=r&&"boolean"!=typeof r&&$(401,[n,typeof r]),void t.classList.toggle(n,!0===r);case 3:return void(null==r?t.removeAttribute(n):t.setAttribute(n,String(r)));case 4:return void(n.includes("-")?null==r?t.style.removeProperty(n):t.style.setProperty(n,String(r)):t.style[n]=null==r?"":String(r))}}var Je=Symbol();function Qe(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Xe=class{constructor(e,t,n,r){this.w=!0,this.we=null,this.u=null,this.Rt=null,this.On=null,this.r=e,this.ct=t,this.L=n,this.C=r}Qo(e,t){let n=t.target,r=this.C,i=[],s=null;for(let t of r.Oe){if(t.name!==e)continue;let o=r.Cn[t.a],l=ut(null===this.L?this.ct:this.L[o[0]],o,1);l.contains(n)&&(l!==s&&i.unshift([]),i[0].push(t),s=l)}for(let e of i){for(let n of e)n.Fn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ct:this.L[this.L.length-1]}Re(){let e=this.On;return(null===e?null:e.In(this.ct))??this.ct}insertBefore(e,t){let n=this.s;for(let r=this.Re();;){let i=r.nextSibling;if(e.insertBefore(r,t),r===n)return;r=i}}bo(){null===this.L?this.ct.remove():ct(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Rt)for(let e of this.Rt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Rn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Ye=class extends Xe{constructor(e,t,n,r){super(e,t,n,r),this.vo=0,this.V=null,this.pe=0===r.Xe.length?null:new Array(2*r.Xe.length)}ko(e,t){let n=this.V??=new Array(this.C.Xe.length),r=n[t];if(void 0===r){let i=this.C.Xe[t],s=this.pe;r=n[t]=new Ge(e,i.i,s[2*t],i.name,i.o,this.r,this,i.x,s[2*t+1])}return r}fo(e,t){let n=this.C.Xe;for(let r=0;r<n.length;r++)n[r].o.ee(t)&&e.tn(this.ko(e,r))}Pe(e){let t=this.r;t.N===this&&(t.N=null),super.Pe(e)}};function Ze(e,t,n,r){let i=te(n,t.n);try{return e.Ue(i,t)}catch(n){return e.Jt(n,t.t,r,"for"),null===i?e.oe.get(t):i.u.get(t)}}function et(e,t,n){n&&e.nr(t);let r=t.Tn;null!==r&&(r.we??=[]).push(t)}var tt=null;function nt(){let e=tt;return tt=null,e}var rt=-1;function it(e,t,n,r,i=null){let s,o=t.Cn,l=t.build,a=t.So,u=null,h=c.Te?.(t,null===r?i:r.S,null!==r),d=!h&&t.jn,f=h?document.createDocumentFragment():(d?t.root:t.ln).cloneNode(!0);if(!h)for(let e=0;e<l.length;e++){let t=l[e];a[t]=ut(f,o[t],d?1:0)}d?s=f:(u=h||[...f.childNodes],s=u[0]);let p,m=null;if(null!==r?(p=m=new Ye(n,s,u,t),null===r.map?n.N=m:r.map.set(n,m)):p=new Xe(n,s,u,t),rt>=0&&function(e,t,n,r){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 s=i?.style;if(null===i||void 0===s||Me.has(i))return;let o=globalThis[Oe]??={counter:0,assigned:0,warned:!1};o.assigned>=r?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${_(25,[r])}`)):(Me.add(i),o.assigned++,s.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),s.setProperty("view-transition-class",`wcs-${n}`))}(s,u,null!==r?"row":"branch",rt),t.Oe.length>0){let t=e.Un;if(null===u)s[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.sr,y=e.Me,b=t.lr?a.slice(0,o.length):a,w=null===m?null:m.pe;if(null!==w){let e=t.Xe;for(let t=0;t<e.length;t++)w[2*t]=b[e[t].a],w[2*t+1]=e[t].q}for(let r=0;r<g.length;r++){let i=g[r],o=b[i.a],l=i.F;if(l>=0&&null!==w){let r=m.V?.[l];if(void 0!==r){r.te=!1,e.Ke(r);continue}try{let t=Ae(i.x,e.read(i.o,n));t!==i.q&&(Ve(i.i,o,i.name,t),w[2*l+1]=t),null!==y&&e.mo(i.o,n)}catch(t){e.xt(t,m.ko(e,l))}continue}switch(i.i){case 6:{let t=new at(e,i.C,Ze(e,i.o,n,o),o);(p.u??=[]).push(t),o===s&&(p.On=t),t.Nt();break}case 7:{let t=ot(e,i.K.map(e=>({C:e.C,o:e.o,x:e.x,S:b[e.a]})),n,p);(p.u??=[]).push(t),o===s&&(p.On=t);break}default:try{st(e,i,o,n,p)}catch(t){ze(e,t,i,o)}}}return tt=p,f}function st(e,t,n,r,i){let s=n;switch(t.i){case 5:return void function(e,t,n,r,i){let s=n.Fn,o=e=>s(e,r);if(n.nt){let r=e.co(n.name),i=t[r];t[r]=void 0===i?o:e=>{i(e),o(e)},n.xe&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.wo&&null!==i&&(i.Rt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,r,i);case 12:return void Re(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name,o=e.command(t.Pt.slice(9)),l=null===i?c.or?.(n,s):null;l||(null===i&&We(1202,n,`command.${s}`),i.commands.has(s)||$(1203,[n.localName,s]));let a=new WeakRef(n),u=o.subscribe((...e)=>{let t=a.deref();if(void 0!==t)return t.isConnected?l?l(t,e):t[s](...e):void 0;u()});null!==r&&(r.Rt??=[]).push(u)}(e,t,s,i,n));case 13:return void Re(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name;null===i&&We(1202,n,`eventToken.${s}`);let o=i.properties.get(s);void 0===o&&$(1204,[n.localName,s]);let l=t.Pt;n.addEventListener(o.event,n=>{t.Tt&&n.preventDefault(),t.At&&n.stopPropagation();try{e.Zo(l,n,r)}catch(e){v(e)}})}(e,t,s,r,n))}let o=t.o,l=te(r,o.n);if(14===t.i)return void Re(e,t,s,i,n=>function(e,t,n,r,i,s){null===s&&We(1501,n,`"...: ${t.o.t}"`);let o=new Set([...s.properties.keys(),...s.inputs]);for(let l of o){if(t.yo?.includes(l))continue;let o=e.o(`${t.o.t}.${l}`),a=0===o.n?null:r;He(e,{...t,U:null,G:null},n,l,o,a,i,s)}}(e,t,s,l,i,n));if(t.xe&&1===t.i)return void Re(e,t,s,i,n=>function(e,t,n,r,i,s){if(null!==s)return void He(e,t,n,t.name,t.o,r,i,s);let o=new Ge(e,1,n,t.name,t.o,r,i,t.x,Be(e,t,r));o.D=t.D,!c.ar?.(o,t.ro)&&(et(e,o,!0),e.Ke(o))}(e,t,s,l,i,n));let a=new Ge(e,t.i,n,t.name,o,l,i,t.x,Be(e,t,l));a.D=t.D,et(e,a,!0),e.Ke(a),null!==t.Ft&&n.addEventListener(t.Ft,()=>a.ir())}function ot(e,t,n,r){let i=new lt(e,t,n),s=null;for(let o of t){if(null===o.o)continue;let t=o.o,l=new Ge(e,7,o.S,"if",t,te(n,t.n),r,null,void 0,i);et(e,l,!0),null===r&&i.ue.push(l),s??=l}return e.Ke(s),i}var lt=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}In(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}Nt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let r=this.K[n];if(null===r.o||Ae(r.x,e.read(r.o,te(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(rt=Le(),null!==this.I&&(this.I.bo(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],r=it(e,n.C,this.r,null,n.S);this.I=nt();let i=n.S.parentNode;i.insertBefore(r,n.S),Qe(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Rn(e);null!==this.I&&this.I.Pe(this.engine)}},at=class{constructor(e,t,n,r){this.w=!0,this.Ae=[],this.engine=e,this.C=t,this.l=n,this.S=r,null===n.N?(n.N=this,this.map=null):((n.M??=[]).push(this),this.map=new Map)}In(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ot(e){return null===this.map?e.N:this.map.get(e)??null}Dt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}Nt(){let e=this.engine,t=this.l.f,n=this.Ae;rt=Le();let r=t.length,i=n.length,s=this.S,o=s.parentNode;if(0===r){if(i>0){let e=n[0].Re(),t=n[i-1].s,r=[];for(let n=o.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==s&&3!==n.nodeType){r=null;break}r.push(n)}null!==r?o.replaceChildren(...r):ct(e,t);for(let e=0;e<i;e++)this.Dt(n[e])}return void(this.Ae=[])}let l=new Array(r),a=0;for(;a<r&&a<i&&this.Ot(t[a])===n[a];)l[a]=n[a],a++;let u=i-1,c=r-1;for(;u>=a&&c>=a&&this.Ot(t[c])===n[u];)l[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],r=t.r;r.w&&this.Ot(r)===t?t.vo=e:(t.bo(),this.Dt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),h=!1;if(i>0)for(let e=0;e<n;e++){let n=this.Ot(t[a+e]);null!==n&&n.w?(u[e]=n.vo,h=!0):u[e]=-1}let d=c+1<r?l[c+1].Re():s;if(h){let r=function(e){let t=e.length,n=new Uint8Array(t),r=new Int32Array(t).fill(-1),i=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let s=0,o=i.length;for(;s<o;){let n=s+o>>1;e[i[n]]<t?s=n+1:o=n}s>0&&(r[n]=i[s-1]),i[s]=n}let s=i.length>0?i[i.length-1]:-1;for(;s>=0;)n[s]=1,s=r[s];return n}(u),i=d;for(let s=n-1;s>=0;s--){let n=t[a+s],u=this.Ot(n);null!==u&&u.w?0===r[s]&&u.insertBefore(o,i):(o.insertBefore(it(e,this.C,n,this),i),u=nt()),l[a+s]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(it(e,this.C,t[r],this)),l[r]=nt();o.insertBefore(n,d)}}this.Ae=l,Qe(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function ut(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function ct(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var ht=()=>ie.bindAttributeName;function dt(){return{a:0,i:1,name:"",o:null,x:null,q:t,Fn:null,C:null,K:null,D:null,Ft:null,xe:!1,U:null,G:null,ro:!1,Tt:!1,At:!1,Pt:null,yo:null,F:-1,nt:!1,wo:!1}}var ft=["state","element","auto","none"],pt=["call","connect"],mt="$command.";function gt(e,t,n){O.test(t)&&(null===n&&$(1401,[t,Number(t.slice(1))]),t=`${n.t}.*.${t}`);let r=e.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&$(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;r.n>i&&$(1401,[r.t,r.n,i]);for(let e=1;e<=r.n;e++){let t=e===i?n:n.h[e];r.h[e]!==t&&$(1403,[r.t,r.h[e].t,t.t])}return c.Eo?.(e,r),r}var yt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),bt=e=>8===e.i||yt(e)||1===e.i&&Ke(e.name);function wt(e){$(202,[e])}function vt(e,t,n,r,i){let s=ue(t).map(t=>function(e,t,n,r,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),r=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||$(31);let s=n.slice(0,t).trim(),o=n.slice(t+1).trim(),l="init"===s;!l&&"sync"!==s&&$(33,[s,n]),null!==(l?r:i)&&$(34,[s]),(l?ft:pt).includes(o)||$(35,[s,o]),l?r=o:i=o}return{ro:t.includes("ro"),Tt:t.includes("prevent"),At:t.includes("stop"),event:n?n.slice(2):null,U:r,G:i}}(e,t.rn),o=r.localName.includes("-"),l=t.Ne,a=t.Ze;if("event"===t.b){if(null!==s.U&&"none"!==s.U&&$(36),"eventToken"===l[0])return{...dt(),a:i,i:13,name:l.slice(1).join("."),Pt:a,xe:o,Tt:s.Tt,At:s.At};let n=a.startsWith(mt)?a.slice(9):null,{Tt:r,At:u}=s,h=t.$e.slice(2),d=t.rn.includes("direct"),f=!d&&Ue.has(h);f&&e.co(h);let p=t=>{v(t),f&&c.handlerThrew?.(e,a,h)};return{...dt(),a:i,i:5,name:h,nt:f,xe:o,wo:d,Fn(t,i){r&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.er(n,t,i);else{let n=e.tr(a,t,i);X(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...dt(),a:i,i:14,o:gt(e,a,n),xe:o};if("command"===l[0]&&l.length>1)return a.startsWith(mt)||$(1201,[t.$e,a]),{...dt(),a:i,i:12,name:l.slice(1).join("."),Pt:a,xe:o};let u=gt(e,a,n),h={...dt(),a:i,i:1,name:t.$e,o:u,x:Ce(t.et),D:Ce(t.D),ro:s.ro,U:s.U,G:s.G};if("radio"===t.b||"checkbox"===t.b)return("element"===s.U||"auto"===s.U)&&$(37,[t.b,s.U]),h.i="radio"===t.b?9:10,s.ro||(h.Ft=s.event??"input"),h;if(l.length>1){let e=l.slice(1).join("."),t=l[0];if("class"===t||"attr"===t||"style"===t)return h.U=null,h.name=e,"class"===t?(h.i=2,h.q=r.classList.contains(e)):h.i="attr"===t?"srcdoc"===e&&"iframe"===r.localName?1:3:4,h}return"html"===t.$e?(h.i=8,h):(h.name="text"===t.$e?"textContent":t.$e,h.xe=o&&!xe(h.name),!o&&!s.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(r,h.name)&&(h.Ft=s.event??("select"===r.localName?"change":"input")),h)}(e,t,n,r,i));for(let e=0;e<s.length;e++)14===s[e].i&&(s[e].yo=s.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return s}var _t=/\{\{([\s\S]+?)\}\}/g;function $t(e){let t=e.data,n=[],r=0;_t.lastIndex=0;for(let i=_t.exec(t);null!==i;i=_t.exec(t)){let s=_t.lastIndex-i[0].length;s>r&&e.before(t.slice(r,s));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({a:o,cr:i[1].trim()}),r=_t.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function kt(e,t,n,r){let i=function(e){return{$e:"textContent",Ne:["textContent"],rn:[],D:[],...F(e),b:"text"}}(t);return{...dt(),a:r,i:0,o:gt(e,i.Ze,n),x:Ce(i.et),q:""}}function St(e){let t=e.getAttribute(ht());if(null===t)return null;let n=ue(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var Nt=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function At(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:gt(e,r.Ze,n),x:"else"===r.b?null:Ce(r.et)}),i=[r(t,St(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=St(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(r(e,t)),"else"===t.b))break}return i}var Ct=new WeakSet;function Et(e,t,n,r,i,s,o,l){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),r&&c.Dn?.(e,i,t),i},u=t=>{for(let h=0;h<t.length;h++){let d=t[h];if(null!==d.parentNode)if(1===d.nodeType){let t=d,l=t.localName;if(t.hasAttribute(ht()+"-ignore"))continue;if(r){if("script"===l||"style"===l||Ct.has(t))continue;if(Ct.add(t),l===ie.tagNames.state){u([...t.childNodes]);continue}}let h="template"===l?St(t):null;if(null!==h){if("for"===h.b){let r=gt(e,h.Ze,n),s=Pt(e,t,r,!0);i(a(t,ie.commentForPrefix),r,s)}else"if"===h.b?s(At(e,t,n).map((t,r)=>({C:Pt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,Nt(r,t))}))):wt(h.b);continue}let f=t.getAttribute(ht()),p=null===f?null:vt(e,f,n,t,0),m="noscript"!==l&&"iframe"!==l&&!p?.some(bt)&&!c.$o?.(t);try{r&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!r&&m&&u([...t.childNodes])}else if(3===d.nodeType&&e.Wt&&d.data.includes("{{")&&!Ct.has(d))for(let{a:e,cr:t}of $t(d))l(e,t);else if(8===d.nodeType){let e=Tt.exec(d.data),t=e&&d.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");d.replaceWith(t),l(t,e[1])}}}};u(t)}var Tt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,xt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Pt(e,t,n,r){let i=document.importNode(xt(t),!0),s=[],o=[],l=e=>s.push(e)-1;Et(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...dt(),a:l(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({a:l(e.S),C:e.C,o:e.o,x:e.x}));o.push({...dt(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=l(e);for(let e of t)yt(e)&&$(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ht())},(t,r)=>{o.push(kt(e,r,n,l(t)))}),It(i,new Set(s),!0);let a=s.map(e=>function(e,t){let n=[];for(let r=t;r!==e;r=r.parentNode){let e=0;for(let t=r.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),h=[],d=new Set,f=[],p=[],m=r?n.n+1:-1;for(let e of o){if(5===e.i&&e.nt&&!e.xe&&!Ot(s[e.a],i)){f.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Mt(e)&&(e.F=h.push(e)-1),7===e.i)for(let t of e.K)d.add(t.a);else d.add(e.a)}let g=[...d].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,Cn:a,build:g,Oe:f,sr:p,jn:u,lr:c,So:[],Xe:h}}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 Mt(e){if(null!==e.U)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.xe&&null===e.Ft;default:return!1}}var Lt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function It(e,t,n){for(let r=e.firstChild;null!==r;){let e=r.nextSibling;3===r.nodeType?n&&!t.has(r)&&""===r.data.trim()&&r.remove():1===r.nodeType&&It(r,t,Lt.has(r.localName)),r=e}}var jt=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,jt.set(t,e),Wt(e,[...n.childNodes]),e.ze()}function Ht(e,t,n){try{let r="template"===t.localName?St(t):null;null!==r&&!n&&$(204,[r.b]),Wt(e,[t])}catch(e){v(e)}e.ze()}function Wt(e,t){Et(e,t,null,!0,(t,n,r)=>{new at(e,r,Ze(e,n,null,t),t).Nt()},t=>{ot(e,t,null,null)},(t,n)=>{c.Dn?.(e,t,n);for(let r of n)st(e,r,t,null,null)},(t,n)=>{c.Dn?.(e,t,n),st(e,kt(e,n,null,0),t,null,null)})}var Ut=Symbol.for("wcstack.binder"),Dt=Symbol.for("wcstack.binder.pending"),Ft=Symbol.for("wcstack.binder.taken"),zt=new Map;function qt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=jt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?zt.set(e,t):Ht(n,e,t?.range)}function Bt(){let e=[...zt];zt.clear();for(let[t,n]of e)qt(t,n);!function(){let e=function(){let e=globalThis[Ut];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),r=function(){let e=globalThis,t=e[Ft];return void 0===t&&(t=new WeakSet,e[Ft]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Gt=class{constructor(){this.name="dirty",this.Z=(e,r)=>{if(0===e.n){let r=e.Y;return r!==t&&r!==n&&(e.Y=n,!0)}let i=null===r?null:r.bt;if(null===i)return!1;let s=i[e.F];return s!==t&&s!==n&&(i[e.F]=n,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.$t(t,n),e.xn(t,n,this.Z)}Ho(e,t){let n=t.l.o.jt;if(null!==n)for(let r of n)r.n===t.l.n?e.st(r,t,this.Z):e.en(t,r,t=>e.st(r,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.$t(t,n),e.xn(t,n,this.Z)}Uo(e,i,s){let o=0===i.n;if(!o&&null===s)return;let l=o?null:s.bt??=new Array(e.Le).fill(t),a=null===l?i.Y:l[i.F];if(a!==t&&a!==n&&a!==r&&(null===l||i.F in l))return a;a=r;try{return a=e.qo(i,null===l?null:s)}finally{null===l?i.Y=a:l[i.F]=a}}Xt(e){e.bt=null}tt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===n&&(t.Y=r):e.nn(t.h[t.n],e=>{let i=e.bt;null!==i&&i[t.F]===n&&(i[t.F]=r)}))}},Kt=0,Vt=new WeakMap;function Jt(e,t=e.getRootNode()){Vt.set(t,[...Vt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Qt(e){let t=Vt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Vt.get(e)!==t?Qt(e):Promise.reject(r.errors[0]):void 0)}var Xt=typeof HTMLElement>"u"?class{}:HTMLElement,Yt=class extends Xt{constructor(){super(),this.engine=null,this.Ln=!1,this.Ye=!1,this.q=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.No=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Qt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();Jt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!jt.has(t)&&jt.set(t,e),Bt(),c.element?.(e,"back"),this.xo("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Ln=!0;let e=this.getRootNode(),t=c.ut?.(this,e);if(t)return this.Ge=t,!t.Ro&&this.parentNode instanceof ShadowRoot&&Jt(this),void(void 0===t.Mt?this.Po():t.Mt()).then(e=>(this.loaded=!0,t.start(e,()=>this.To()))).then(()=>{this.an(),this.cn()},e=>this.xt(e,t.Ro));this.start(e),Jt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let e=this.engine;if(null===e)return;let t=e.root;jt.get(t)===e&&jt.delete(t),Jt(this,t),this.xo("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ye&&$(14),this.loaded)this.Ge.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&$(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&$(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let r=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&$(8),r(...e)):r},set(){$(8)}}))}async Po(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${_(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||$(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let r=this.querySelector('script[type="module"]');return null!==r?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let r="function"==typeof URL.createObjectURL,i=r?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Kt}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?_(42):_(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),r&&URL.revokeObjectURL(i)}}(r):null!==this.q?Promise.resolve(this.q):new Promise(e=>{this.un=e})}async start(e){try{let t=e.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||t?.hasAttribute("data-wc-definition"))&&b("scopes","<wcs-state>");let n=await this.Po(),r=y(n);if(r&&await r,this.getRootNode()!==e)return this.q=n,this.Ln=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&b("ssr","enable-ssr");let i=jt.get(e)?.element;i?.isConnected&&(i.V||i.Ge)&&$(47);let s=new re(n,new Gt);s.element=this,this.engine=s,c.element?.(s,"mounting"),Rt(s,e),Bt(),s.Nn(),this.To(),await s.Ee("$connectedCallback"),this.isConnected&&c.element?.(s,"connected"),this.cn()}catch(e){this.Ye=!this.V,this.xt(e)}}To(){this.V=!0,this.an()}xt(e,t){this.ze(this.V?50:49,e),this.an(),t?this.cn():this.No(e)}ze(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);v(t,`[@wcstack/state] ${_(e,[this.localName,...n])}`)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.ze(t,e))}},Zt=[];function en(){return(Zt=Zt.filter(e=>e.deref())).map(e=>e.deref())}var tn,nn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},rn="en";function sn(){if(ie.locale!==tn){tn=ie.locale;try{rn=Intl.getCanonicalLocales(tn)[0]}catch{console.warn(`[@wcstack/state] ${_(48,[tn])}`),rn="en"}}return rn}var on=["full","long","medium","short"];function ln(e,t){let[n,r]=e??[];return void 0===r&&void 0!==n&&on.includes(n)&&([n,r]=[void 0,n]),void 0!==r&&!on.includes(r)&&function(e,t){$(52,[e,t])}(t,r),[n,r]}var{eq:an,ne:un,not:cn,lt:hn,le:dn,gt:fn,ge:pn,falsy:mn,truthy:gn,boolean:yn}=Se,bn={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ye("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ye("locale",e),e.toLocaleString(t??sn()))},arity:[0,1]},upper:{factory:nn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:nn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:nn(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:nn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:nn(e=>{let t=[_e(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:nn(e=>{let t=_e(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:nn(e=>{let t=_e(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:nn(e=>{let t=_e(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:nn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:nn(e=>{let t=_e(e,0,"truncate"),n=e?.[1]??"…";return e=>{let r=String(e);return r.length<=t?r:r.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||$(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ye("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ye("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ye("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ye("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:nn(e=>{let t=e?.[0]??me("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:nn(e=>{let[t,n]=ln(e,"date"),r=n&&{dateStyle:n};return e=>(e instanceof Date||be("date",e),e.toLocaleDateString(t??sn(),r))}),arity:[0,2]},time:{factory:nn(e=>{let[t,n]=ln(e,"time"),r=n&&{timeStyle:n};return e=>(e instanceof Date||be("time",e),e.toLocaleTimeString(t??sn(),r))}),arity:[0,2]},datetime:{factory:nn(e=>{let[t,n]=ln(e,"datetime"),r=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||be("datetime",e),e.toLocaleString(t??sn(),r))}),arity:[0,2]},ymd:{factory:nn(e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||be("ymd",e);let n=e.getFullYear().toString(),r=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0");return`${n}${t}${r}${t}${i}`}}),arity:[0,1]},hms:{factory:nn(e=>{let t=e?.[0]??":";return e=>{e instanceof Date||be("hms",e);let n=e.getHours().toString().padStart(2,"0"),r=e.getMinutes().toString().padStart(2,"0"),i=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${r}${t}${i}`}}),arity:[0,1]},eq:an,ne:un,not:cn,lt:hn,le:dn,gt:fn,ge:pn,add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ye("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=_e(e,0,"clamp"),n=_e(e,1,"clamp");return e=>("number"!=typeof e&&ye("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:mn,truthy:gn,defaults:{factory:(e,t)=>{let n=$e(e?.[0]??me("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=$e(e?.[0]??me("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:yn,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??me("currency"),n=e?.[1],r={style:"currency",currency:t};try{new Intl.NumberFormat("en",r);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){$(53,[e])}(t)}return e=>("number"!=typeof e&&ye("currency",e),e.toLocaleString(n??sn(),r))},arity:[1,2]}},wn=!1,vn={name:"formats",hooks:c,install:function(){wn||(wn=!0,fe(bn))}};function _n(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let r=new Array(t.length+1),i=new Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let n=1;n<=e.length;n++){i[0]=n;for(let s=1;s<=t.length;s++){let o=e[n-1]===t[s-1]?0:1;i[s]=Math.min(r[s]+1,i[s-1]+1,r[s-1]+o)}for(let e=0;e<=t.length;e++)r[e]=i[e]}return r[t.length]}function $n(e,t){if(0===e.length)return"";let n=e.toLowerCase(),r=null,i=3;for(let e of t){let t=_n(n,e.toLowerCase(),2);t<i&&(r=e,i=t)}return null!==r?` Did you mean "${r}"?`:""}var kn=" Validate statically: npx @wcstack/lint <file>.",Sn=["","binding-syntax","template-syntax","binding-path-missing","binding-type-expectation","filter-unknown","filter-arity","getter-cycle","getter-depth-exceeded","index-arity","index-param-range","recursion-unsupported","token-misconfigured","token-undeclared","wildcard-rank","spread-no-bindable","declaration-alias","name-alias"],Nn=e=>{let t=Sn[e/100|0];return t?`[wcs/${t}] `:""},An=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Cn=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,En=["","","class.","attr.","style."],Tn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,xn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Pn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,r)=>`binding "${n?(En[r]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${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,t)=>`filter ${e} requires a number value, not ${Cn(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${Cn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&An.includes(t)?" 4.0 moved it to the state's $behavior.":""}`,45:()=>"a re-set state may not change $behavior: create the element again.",47:()=>'a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount="path"> (v1\'s name="…" is gone: read the mounted state by its path).',48:e=>`the locale "${e}" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use "en".`,46:()=>'$features must be an array of add-on names (["temporal", "formats"]).',49:(e,...t)=>`${Tn(e,t)} failed to initialize.`,50:(e,...t)=>`${Tn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Tn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,r)=>`${e}("${t}") takes ${n} index(es), got ${r}.`,902:(e,t,n,r)=>`${e}("${t}") takes at most ${n} index(es), got ${r}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function On(e,t){let n=Pn[e];return void 0===n?`${Nn(e)}#${e} ${t.join(" ")}`:Nn(e)+n(...t)}var Mn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Ln=[[/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.']],In={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function jn(e,t,n){let r=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(In,e)?In[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 Ln){let i=t.exec(e);null!==i&&(r+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(r+=` — write "${i[1]}#${i[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?r+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':ce.some(pe)||(r+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let s=/\[wcs\/([\w-]+)\]/.exec(e);return null!==s&&Mn.has(s[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=kn),r}var Rn=new WeakMap,Hn=new WeakMap,Wn=new WeakSet,Un=new WeakSet;function Dn(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 Fn(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 zn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let r=t=>null===t?null:function(e,t){let n=t.t.split("."),r=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return r<0||n.indexOf("*",r)>=0||void 0!==Dn(e.target,t.t)?.get?t:e.O.wt(o(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:qn(e,n,0,e.target,r)}function qn(e,t,n,r,i){for(;n<t.length;n++){let s=t[n];if(null===r||"object"!=typeof r)return null;if("*"===s.s){if(!Array.isArray(r)||0===r.length)return null;let s=null;for(let o of r){let r=qn(e,t,n+1,o,i);if(null===r)return null;if(null===s)s=r;else if(r.seg===s.seg)for(let e of r.names)s.names.includes(e)||s.names.push(e)}return s}if(Array.isArray(r)&&/^\d+$/.test(s.s)){if(Number(s.s)>=r.length)return null;r=r[Number(s.s)];continue}let o=Dn(r,s.s);if(void 0===o&&null===s.c&&e.tt.has(s.s))return null;if(void 0===o){let o=Fn(r),l=i(s.c);for(let t of e.O.all())t.c===l&&null!==t.getter&&o.push(t.s);return{seg:s.s,names:o,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==o.get||void 0!==o.set)return null;r=o.value}return null}function Bn(e){Wn.has(e)||(Wn.add(e),setTimeout(()=>function(e){Wn.delete(e);let t=Rn.get(e);if(void 0===t)return;let n=Hn.get(e);void 0===n&&Hn.set(e,n=new Set);let r=new Map(t),i=new Map;for(let s of e.O.all()){let e=null===s.c||n.has(s)||t.has(s)?void 0:s.B.find(e=>!e.hn);void 0!==e&&(i.set(s,e),r.set(s,3))}for(let[t,s]of r){if(n.has(t))continue;n.add(t);let r=zn(e,t);if(null===r)continue;let l=[...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Un.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==l){n.delete(t),l.initializePromise.then(()=>{Un.add(l),Bn(e)});continue}let a=e.O.wt(o(t.t).o),u="";if(void 0!==a&&a!==t&&null!==a.getter){let e=a.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(a.h[t].t.length+2)}`);u=` The getter "${a.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let h=$n(r.seg,r.names);if((r.r||3===s)&&""===h&&""===u)continue;let[d,f,p]=1===s?["watch-path-missing","$watch path","watch"]:2===s?["post-update-path-missing","$postUpdate path","postUpdate"]:3===s?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];c.at?.(e,{type:"state:path-unresolved",source:p,path:t.t,missingSegment:r.seg}),console.warn(`[@wcstack/state] [wcs/${d}] ${f} "${t.t}"${3===s?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${r.seg}" is not declared.${h}${u} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${kn}`)}}(e),0))}function Gn(e,t,n=!1){Kn(e,t,n?1:0)}function Kn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let r=Rn.get(e);void 0===r&&Rn.set(e,r=new Map),r.has(t)||r.set(t,n),Bn(e)}var Vn=new WeakSet,Jn=!1,Qn=new WeakMap;function Xn(e,t){let n=Qn.get(e),r=t.s;if(null!==t.c||Jn||void 0===n||n.has(r)||"$"===r[0]||e.tt.has(r))return;let i=$n(r,[...n]);n.add(r),""!==i&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${r}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${r}" is not declared: writing it creates a new key.${i}${kn}`)}var Yn=new WeakSet;function Zn(e){if(Yn.has(e))return;Yn.add(e);let t=e.emit,n=!1;e.emit=(...r)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${kn}`)),t.apply(e,r))}var er=new WeakMap;function tr(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Dn(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let i=er.get(e);void 0===i&&er.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${kn}`))}function nr(e){Rn.has(e)&&e.He.length>0&&Bn(e)}var rr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ir=!1;function sr(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(ir||!(t instanceof TypeError)||!xe(r)||!("trustedTypes"in globalThis))return;ir=!0;let i="function"==typeof Te()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${r}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${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:r})}var or=new WeakMap;function lr(e,t,n){let r=e[t],i=void 0===n?void 0===r?null:`the event carried no detail (undefined) while element.${t} is ${typeof r}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==r&&"object"==typeof r?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof r}`;if(null===i)return;let s=or.get(e);void 0===s&&or.set(e,s=new Set),!s.has(t)&&(s.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 ar=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],ur={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},cr={name:"diagnostics",hooks:c,install(){c.Bo=jn,c.Mo=On,c.Eo=Gn,c.detail=lr,c.Ye=h(c.Ye,sr);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&$(1);for(let[t,n]of ar)void 0!==e[t]&&$(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[r,i]=n[0];if(!r.endsWith(".*")||!i.endsWith(".*"))return;let s=r.slice(0,-2),o=i.slice(0,-2),l=`.${i}`,a=`${s}.**`,u=Fn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),h=e=>w(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${o}`||e.startsWith(`.${o}.`))&&h(`"${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(`^(?:${rr(l)})+$`).test(t.slice(0,t.length-e.length))&&h(`"${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(`^${rr(r)}(?:${rr(l)})*${rr(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&h(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(n),function(e){Hn.delete(e),Rn.has(e)&&Bn(e)}(t),function(e){if(Vn.has(e))return;Vn.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{Jn=!0;try{n(t)}finally{Jn=!1}let r=e.O.wt(o(t).o);void 0!==r&&Kn(e,r,2)}}(t),function(e){if(void 0!==Object.getOwnPropertyDescriptor(e,"commands")?.set)return;let t=e.commands;Object.defineProperty(e,"commands",{configurable:!0,get:()=>t,set:e=>{t=e;for(let t of Object.values(e))Zn(t)}})}(t),Qn.set(t,new Set(Fn(n)))},c.handlerThrew=tr,c.re=h(c.re,Xn),c.me=h(c.me,nr),c.rt=d(p,c.rt,(e,t)=>Object.hasOwn(ur,t)?$(1701,[t,ur[t]]):void 0)}},hr={},dr=/\.\d/,fr=new Set(Object.getOwnPropertyNames(Object.prototype)),pr=0,mr=!1,gr=null,yr=()=>{mr=!1,pr++};function br(){if(null===gr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=yr,e.port1.unref?.(),gr=()=>e.port2.postMessage(0)}else gr=()=>setTimeout(yr,0);return mr||(mr=!0,gr()),pr}function wr(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let r of t)if(n.ee(r)&&(n.n===r.n||!(r.n<e.n&&e.h[r.n+1].ee(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var vr=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Fo=-1,this.Mn=new Set,this.qe=null,this.engine=e,this.je=t}ur(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.je)t.getter=null!==t.p.getter||t.p.ae,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(hr,e.v(t.p,null)):this.Wn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[r,i,s,o]of t)if((null===i||i.w)&&Object.is(e.v(r,i),o)){n.add(r);for(let e of this.je)e.p===r&&this.dt(e,i,s,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&wr(_r(e.p),n)&&this.dt(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){v(t,`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`),c.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Oo(){this.active=!1,this.Fe.clear(),this.early=[]}Wn(e,t,n,r){let i=this.engine.Ue(n,e.h[t]);for(let n of i.f)t===e.n?r(n):this.Wn(e,t+1,n,r)}dt(e,t,n,r){let i=this.Fe.get(e);void 0===i&&this.Fe.set(e,i=new Map);let s=i.get(t);void 0===s?i.set(t,[n,this.n,r]):(s[1]<this.n&&(s[1]=this.n),s[2]||=r)}re(e,t,n,r,i,s){if(this.active){(this.qe??=new Set).add(e);for(let s of this.je){let o=s.p;o.n!==e.n||!o.ee(e)||this.dt(s,t,s.getter?s.s.get(t??hr):o===e&&i&&this.engine._t&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else s&&this.early.push([e,t,n,r])}Se(e,t){if(this.active)for(let n of this.je)(n.getter||=null!==n.p.getter||n.p.ae)&&n.p.n===e.n&&n.p.ee(e)&&this.dt(n,t,n.s.get(t??hr),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let r of this.je){let i=r.p;if(!(i.n<e.n||i.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.dt(r,t,void 0,!0):this.Wn(i,e.n+1,t,e=>this.dt(r,e,void 0,!0)))}}}me(){let e=this.qe;if(this.qe=null,!this.active||0===this.Fe.size)return;let t=this.Fe;this.Fe=new Map;let n=this.engine,r=[];for(let i of this.je){let s=t.get(i);if(void 0===s)continue;let o,l=[...s].filter(([e])=>null===e||e.w);l.length>1&&l.sort((e,t)=>$r(e[0],t[0]));for(let[t,[s,a,u]]of l){let l,h="evaluate",d=n.d;this.n=a+1,n.Ce++;try{if(l=n.v(i.p,t),i.getter&&(i.s.set(t??hr,l),Object.is(l,s)&&(dr.test(i.t)||null!==t&&!u&&!(o??=null!==e&&wr(_r(i.p),e)))))continue;if(a>32){r.includes(i.t)||r.push(i.t);continue}n.d=t,c.at?.(n,{type:"state:watch-fired",path:i.t}),h="handler",i.handler.call(n.proxy,l,s,...n.H(t))}catch(e){v(e,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),c.at?.(n,{type:"state:watch-error",phase:h,path:i.t,error:e})}finally{n.d=d,this.n=0,n.Ce--}}}r.length>0&&this.Co(r)}Co(e){let t=br();t!==this.Fo&&(this.Fo=t,this.Mn.clear());let n=e.filter(e=>!this.Mn.has(e));if(0!==n.length){for(let e of n)this.Mn.add(e);v("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function _r(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function $r(e,t){let n=[],r=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)r.unshift(e.y);for(let e=0;e<n.length&&e<r.length;e++)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}var kr="$streamStatus",Sr="$streamError",Nr=new Set(Object.getOwnPropertyNames(Object.prototype)),Ar=!1;function Cr(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 Er=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Ar=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Ar=!1}}dr(){for(let e of this.entries)this.start(e,!0)}fr(){for(let e of this.entries)e.ft=!1,e.J?.abort(),e.J=null}pr(){for(let e of this.entries)e.ft=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(kr,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.ft?Math.max(n.n,t):t,n.ft=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.ft)continue;let s=i.n;if(i.ft=!1,s>32)n.push(i.name),i.g.Y=r;else{t.n=s+1,e.Ce++;try{this.start(i,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Co(n)}start(e,t){let n,i=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let s=e.g;s.getter=e.args;let o=s.Q.slice();Tr(s);try{n=i.read(s,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&w(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&w(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${kr}.${e}`||n.t===`${Sr}.${e}`)&&w(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,s,n)}catch(n){Tr(s);for(let e of o)e._n(s);if(s.Y=r,t)throw n;return this.set(Sr,e.name,n),void this.set(kr,e.name,"error")}}let s=new AbortController;e.J=s,i.A(i.o(e.name),null,e.q),this.set(Sr,e.name,null),this.set(kr,e.name,"active"),this.mr(e,s,n)}async mr(e,t,n){let r=this.engine,i=t.signal,s=()=>!i.aborted&&e.J===t,o=r.o(e.name),l=this.W.n,a=br(),u=e=>{br()===a&&(this.W.n=l);try{e()}finally{this.W.n=0}},c=e.q;try{let t=await e.source(n,i);if(!s())return;let l=t=>{c=void 0!==e.Io?e.Io(c,t):t,u(()=>r.A(o,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(i.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!s())return;if(t.done)break;l(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(!s())return;if(t.done)break;l(t.value)}}}if(!s())return;e.J=null,u(()=>this.set(kr,e.name,"done"))}catch(n){if(!s())return;e.J=null,t.abort(),u(()=>{this.set(Sr,e.name,n),this.set(kr,e.name,"error")})}}};function Tr(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.ht.delete(e)}e.Q.length=0,e.Y=t}var xr=new WeakMap;function Pr(e){let t=xr.get(e);return t?.target===e.target?t:void 0}function Or(e,t){let n=new vr(e,function(e,t){if(void 0===t)return[];(null===t||"object"!=typeof t)&&w("$watch must be an object mapping paths to handler functions.");let n=[];for(let r of Object.keys(t)){let i=t[r];(""===r||"$"===r[0]||r.includes("@")||fr.has(r))&&w(`$watch path "${r}" is not a path of the state tree.`),"function"!=typeof i&&w(`$watch entry "${r}" must be a function.`);let s=e.o(r);c.Eo?.(e,s,!0),n.push({t:r,p:s,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),r=new Er(e,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&w("$stream must be an object mapping stream names to definitions.");let r=[],i={},s={};for(let o of Object.keys(n)){let l=n[o];(""===o||"$"===o[0]||/[.*]/.test(o)||Nr.has(o))&&w(`$stream entry "${o}" must be a flat property name.`),(null===l||"object"!=typeof l)&&w(`$stream entry "${o}" must be an object.`);let a=l.source,u=l.fold,c=l.args,h=l.initial;"function"!=typeof a&&w(`$stream entry "${o}" needs a source function.`),void 0!==u&&"function"!=typeof u&&w(`$stream entry "${o}": fold must be a function.`),void 0!==u&&!("initial"in l)&&w(`$stream entry "${o}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&w(`$stream entry "${o}": args must be a function.`),Cr(t,o)&&w(`$stream entry "${o}" collides with a getter, setter or method of the state.`),void 0===t[o]&&(t[o]=h),i[o]="idle",s[o]=null,r.push({name:o,source:a,Io:u,q:h,J:null,ft:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[kr]=i,t[Sr]=s,r}(e,t),n),i=xr.get(e);void 0!==i&&(i.W.Oo(),i.Ct.fr()),xr.set(e,{W:n,Ct:r,Je:i?.Je??!1,target:t})}function Mr(e,t){let n=xr.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Je="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.Oo(),void n.Ct.pr();n.Je&&(n.W.ur(),n.Ct.dr())}}var Lr=["$streamStatus","$streamError"],Ir={name:"temporal",hooks:c,install(){c.fe=h(c.fe,Or),c.element=h(c.element,Mr),c.re=h(c.re,(e,t,n,r,i,s,o)=>Pr(e)?.W.re(t,n,r,i,s,o)),c.Se=h(c.Se,(e,t,n)=>{let r=Pr(e);void 0!==r&&(r.W.Se(t,n),r.Ct.Se(t))}),c.Qt=h(c.Qt,(e,t,n)=>Pr(e)?.W.Qt(t,n)),c.me=h(c.me,e=>{let t=Pr(e);void 0!==t&&(t.W.me(),t.Ct.me())}),c.rt=d(p,c.rt,(e,t)=>{let n=t.split(".",1)[0];if(Lr.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=d(f,c.Ie,(e,t)=>(!Ar&&36===t.t.charCodeAt(0)&&Lr.includes(t.t.split(".",1)[0])&&w(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},jr=new WeakMap,Rr=!1,Hr=/^(?!prototype$)[^\d.*$][^.*]*$/;function Wr(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&w("$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?r.set(e.o(t),e=>e[i]):"function"==typeof i?r.set(e.o(t),i):w(`$listKeys "${t}" must be a field name or a function.`)}}jr.set(t,r)}function Ur(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Dr(e,t,n){let r=new Map;for(let i of t){Ur(i)||w(`$listKeys "${e}": rows must be plain objects.`);let t=n(i);null==t&&w(`$listKeys "${e}": a row has no key.`),r.has(t)&&w(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,i)}return r}function Fr(e,t,n,r){if(Rr||!Array.isArray(r))return!1;let i=jr.get(e.target)?.get(t);if(void 0===i)return!1;let s=e.it(t,n);if(!Array.isArray(s)||s===r)return!1;let o=Dr(t.t,s,i);Dr(t.t,r,i);let l=[],a=[],u=s.length===r.length;for(let e=0;e<r.length;e++){let t=r[e],n=o.get(i(t));l.push(n??t),void 0!==n&&a.push([e,n,t]),l[e]!==s[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let r of Object.keys(n))Object.is(t[r],n[r])||c.push([e,r,n[r]]);for(let r of Object.keys(t))!(r in n)&&null!==t[r]&&c.push([e,r,null])}if(u&&0===c.length)return!0;if(!u){Rr=!0;try{e.A(t,n,l)}finally{Rr=!1}}if(c.length>0){let r=e.Ue(0===t.n?null:n,t);for(let[n,i,s]of c){if("__proto__"===i)continue;let o=r.f[n],l=Hr.test(i)?e.o(`${t.t}.*.${i}`):null;null===l?.getter?e.A(l,o,s):(o.$[i]=s,e.A(e.o(`${t.t}.*`),o,o.$,!0))}}return!0}var zr={name:"list-keys",hooks:c,install(){c.fe=h(c.fe,Wr),c.Ie=d(f,c.Ie,Fr)}},qr=new WeakMap,Br=new WeakMap,Gr="will not graft: the root state failed to initialize.",Kr=new WeakSet,Vr=new WeakMap,Jr=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Qr=["$commandTokens","$eventTokens","$on","$errorCallback"],Xr=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,Yr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Zr=e=>e?.element?.isConnected?e:void 0;function ei(e){let t=Br.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ti(e,t){let n=Br.get(t);if(Br.delete(t),Array.isArray(n))for(let t of n)si(t,e)}function ni(e){let t=qr.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ri(e,t){v(`${Xr(e.t)} ${t}`),ni(e),e.Qe?.(),e.Qe=null}function ii(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,v)}catch(e){v(e)}}function si(e,t){if(Kr.has(t))return ri(e,"will not graft: its component is wired to its host.");let n=e.state,r=t.target,i=e.t.split("."),s=r;for(let e of i)s=s?.[e];if(void 0!==s&&!0!==t.hydrated)return ri(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,r){if("symbol"==typeof r)return;if(36!==r.charCodeAt(0))return e.proxy[n(r)];let i=e.proxy[r];return"$eqPath"===r?(e,t)=>i(n(e),n(t)):Yr.has(r)&&"function"==typeof i?(e,...t)=>i(n(e),...t):i},set:(t,r,i)=>"symbol"!=typeof r&&(e.proxy[n(r)]=i,!0)})}(t,e.t);e.chroot=o;let l={},a={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:r,set:i,value:s}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==r||void 0!==i)a[`${e.t}.${n}`]={get:r&&function(){return r.call(o)},set:i&&function(e){i.call(o,e)}};else{if("$"===n[0])continue;if("function"==typeof s){let t=s.bind(o);a[`${e.t}.${n}`]={get:()=>t}}else l[n]=s}}if(void 0===s){for(let e=1;e<i.length;e++){let n=t.o(i.slice(0,e).join("."));null==t.it(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,l)}t.no(Object.defineProperties({},a));for(let e in a)t.qe(t.o(e),null);e.engine=t;let c=Vr.get(t);void 0===c&&Vr.set(t,c=[]),c.push(e),e.el.isConnected&&ii(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function oi(e,t){let n=Br.get(e);if(Array.isArray(n))for(let e of n)ri(e,Gr);Br.set(e,t)}var li=new WeakMap;function ai(e,t){let n=e.getAttribute("mount");if(null===n)return null;let r={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=qr.get(t);void 0===e&&qr.set(t,e=new Map);let s=e.get(n);if(void 0!==s&&s!==r&&(null===s.engine?s.el.isConnected:Zr(s.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===s?.engine){let e=Br.get(t);Array.isArray(e)&&Br.set(t,e.filter(e=>e!==s)),s.Qe?.(),s.Qe=null}e.set(n,r)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ro:!0,start(e){if(null!==i)return ri(r,i);if(qr.get(t).get(n)===r){for(let t of Jr)if(void 0!==e[t])return ri(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of Qr)void 0!==e[t]&&console.warn(`${Xr(n)} ${t} is not run in a volume (it belongs to the root).`);return r.state=e,new Promise(e=>{r.Qe=e;let n=Zr(jt.get(t)),i=Br.get(t);void 0!==n?si(r,n):ei(t)?ri(r,Gr):Br.set(t,[...Array.isArray(i)?i:[],r])})}},Je(){null!==r.engine&&ii(r,"$connectedCallback")},Bn(){null!==r.engine&&ii(r,"$disconnectedCallback")},reset(){w(`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 ui=new WeakMap,ci=new WeakMap;function hi(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||w(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&w(`${t} entries must be non-empty strings.`),"$"===e[0]&&w(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&w(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function di(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let r=document.createDocumentFragment();for(let e of[...t.childNodes])r.appendChild(e.cloneNode(!0));let i=t.mode;return{start(t){e.hasAttribute("bind-component")&&w("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||w(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&w(`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}(r),s=hi(r,"$bindables"),o=hi(r,"$commands");for(let e of s){let t=i.get(e);void 0===t&&w(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&w(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of o){let t=i.get(e);void 0===t&&w(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&w(`$commands entry "${e}" is not a method: list it in $bindables.`)}let l={tag:e,bindables:s},a=new WeakMap,u=new WeakMap,c=r=>{if(a.has(r))return a.get(r);if(r.hasAttribute("data-wc-definition"))return null;let i=r.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(ie.tagNames.state);return a.set(r,o),ui.set(r,l),null===o&&s.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.tagNames.state}>: no change events.`),o},h=e=>c(e)?.engine??null,d=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=h(e);if(void 0!==t&&null!==n)for(let[e,r]of t)n.proxy[e]=r});class f extends HTMLElement{static{this.wcBindable=0===s.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:s.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:s.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&d(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"function"==typeof t.value?Object.defineProperty(f.prototype,e,{configurable:!0,value(...t){return d(this).then(()=>{let n=h(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(f.prototype,e,{configurable:!0,get(){return h(this)?.proxy[e]},set(t){let n=h(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,f)}(n.localName,r,i,t)},Je(){},Bn(){},reset(){w("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var fi=new WeakMap,pi=new WeakSet,mi=new WeakMap,gi=new WeakMap,yi="data-wcs-wired",bi=new WeakMap,wi=new WeakMap,vi=new WeakMap,_i=0,$i=new Set,ki={},Si=["$watch","$stream","$renderedCallback"],Ni=e=>e.split(".",1)[0];function Ai(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ci(e,t){let n=e.a,r=Ni(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(yi);else if(!Ti(n,r)){let e=n.getAttribute(yi)?.split(" ")??[];e.includes(r)||n.setAttribute(yi,[...e,r].join(" "))}bi.get(n)?.he===r&&w(`<${n.localName}>.${r} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let i=fi.get(n);void 0===i&&fi.set(n,i=[]),i.push(e),t&&pi.add(e);let s=mi.get(n);return void 0===s&&mi.set(n,s=new Map),s.has(r)||s.set(r,n[r]),gi.get(n)?.(),!1}function Ei(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Ti(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function xi(e){let t=e.parentElement;for(;null!==t&&!Ei(t);)t=t.parentElement;let n=jt.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.V:null===t)&&(null===t?qt(e):Ht(n,e))}var Pi=new Set;function Oi(e,t){Pi.has(e)||(Pi.add(e),console.warn(`[@wcstack/state] ${t}`))}var Mi=(e,t)=>t in e.state;function Li(e,t){let n=Ii(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Ii(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 ji(e,t,n){if(null!==n.getter)return;let r,i=e.host,s=i.engine,o=Ni(n.t),l=i.entries.find(e=>e.E===n.t);if(void 0===l&&null!==n.c)return function(e,t){let n,r=t.c;for(;null!==r&&void 0===(n=e.pt.get(r));)r=r.c;if(null===r||void 0===n)return;let i=e.R,s=e.host.engine,o=s.o(n.p.t+t.t.slice(r.t.length));if(null===o.getter)return;let l=n,a=()=>{let n=Ri(e,l.r);return 0===t.n?n:(s.resolve(Ai(o.t,[...s.H(n),...i.H(te(i.d,t.n))]),null),s.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:s.v(o,e)},null!==o.se&&(t.se=n=>{let r=a();Hi(e,l.e,()=>s.A(o,r,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.pt.set(t,{e:l.e,p:o,r:l.r})}(e,n);if(0!==n.n)return;if(void 0!==l){if(l.E!==o?Mi(i,o):Li(i,o))return;r=l.ye}else{if(null===t||null!==n.c||"$"===o[0]||Mi(i,o))return;l=t,r=s.o(`${t.ye.t}.${o}`)}let a=l.r,u=l;n.getter=()=>s.v(r,Ri(e,a)),n.se=t=>{Hi(e,u,()=>s.A(r,a,t)),e.dn=n},e.pt.set(n,{e:l,p:r,r:a})}function Ri(e,t){return null!==t&&!t.w&&w(`The host row of <${e.host.el.localName}> was removed.`),t}function Hi(e,t,n){let r=$i.has(e.R);$i.add(e.R),e.from=t;try{n()}finally{r||$i.delete(e.R),e.from=null}}var Wi=(e,t)=>t||!$i.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Ui(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,_i+=t?1:-1;let n=e.host.engine,r=vi.get(n);void 0===r&&vi.set(n,r=new Map);for(let n of e.pe){let e=r.get(n.e.ye);void 0===e&&r.set(n.e.ye,e=new Map);let i=e.get(n.e.r);void 0===i&&e.set(n.e.r,i=new Set),t?i.add(n):(i.delete(n),0===i.size&&e.delete(n.e.r))}let i=e.host.entries.find(e=>""===e.E);if(void 0!==i){null===e.ie&&function(e,t){let n=e.host,r=n.engine;e.ie=new Map;let i=new Set;for(let s=n.state;null!==s&&s!==Object.prototype;s=Object.getPrototypeOf(s))for(let o of Object.getOwnPropertyNames(s)){if(i.has(o))continue;i.add(o);let l=Object.getOwnPropertyDescriptor(s,o);if(void 0===l.get&&void 0===l.set||"$"===o[0]||o.includes("*"))continue;let a=Ni(o);if(o!==a&&!Mi(n,a))continue;let u=r.o(`${t.ye.t}.${o}`);if(null===u.getter)zi(r,u,t.ye);else if(!Di.has(u.getter))continue;e.ie.set(u,e.R.o(o))}}(e,i);for(let r of e.ie.keys())t&&null===r.getter&&zi(n,r,i.ye),n.T.ke(n,r,i.r);e.ie.size>0&&n.ve(),t&&function(e,t){let n=e.host.engine;for(let[r,i]of e.ie){let s=n.v(r.c,t.r);if(null===s||"object"!=typeof s||!(r.s in s))continue;let o=e.host.el.localName;Oi(`${o}|${r.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.he}.${i.t} is exported at "${r.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,i)}}var Di=new WeakSet;function Fi(e,t,n,r){let i=vi.get(e)?.get(t)?.get(n);if(void 0===i)return null;let s=null;for(let e of i)""!==e.e.E||!0!==e.m.ie?.has(r)||e.m===s||(null!==s&&w(`[wcs/mount-export-ambiguous] "${r.t}" is exported by two mounted components on the same instance: <${s.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.`),s=e.m);return s}function zi(e,t,n){let r=t.c,i=t.s,s=()=>{let t=e.read(r,e.d);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let r=s();if(null!==r)return r[i];let o=Fi(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Di.add(t.getter),t.se=o=>{let l=null===s()?Fi(e,n,e.d,t):null;if(null===l){let t=e.read(r,e.d);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=l.ie.get(t);void 0===Ii(l.host.state,a.t)?.set&&w(`Cannot write to "${a.t}" on mounted <${l.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),l.R.A(a,null,o)},t.n>0&&(t.F=e.Le++)}function qi(e,t,n,r,i,s){if(null!==t.getter)return e.T.ke(e,t,n),void e.ve();if("*"===t.s){if(null===n)return;if(n.$=n.l.P[n.y],e.T.Xt(n),null!==n.u)for(let t of n.u.values())e.G(t)}else e.$n(t,n);c.re?.(e,t,n,r,i,s),e.qe(t,n)}function Bi(e){let t=e.m.R;for(let[n,r]of e.m.pt)r.e===e.e&&(0===n.n?t.T.ke(t,n,null):t.nn(n.h[n.n],e=>t.T.ke(t,n,e)));t.ve()}function Gi(e,t,n,r,i,s,o){let l=n.t.slice(t.t.length);if(""===l)return Bi(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=l.slice(1);let e=Ni(a);if("$"===e[0]||Mi(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+l;let h=[];for(let e=t.n+1;e<=n.n;e++)h.push(te(r,e).y);c.resolve(Ai(a,h),null);let d=c.rp,f=c.rr;d.n>0&&null===f||qi(c,d,f,i,s,o)}function Ki(e,t,n,r,i,s,o){if(0===_i)return;let l=$i.has(e);$i.add(e);try{let l=wi.get(e);!o&&void 0!==l&&l.fn&&!$i.has(l.host.engine)&&function(e,t,n,r,i,s){let o,l=t;for(;null!==l&&void 0===(o=e.pt.get(l));)l=l.c;if(null===l||void 0===o)return;let a=e.host.engine;if(l===t&&e.dn===t)return void(e.dn=null);if(null!==o.r&&!o.r.w)return;let u=[...a.H(o.r),...e.R.H(n)];a.resolve(Ai(o.p.t+t.t.slice(l.t.length),u),null);let c=a.rp,h=a.rr;c.n>0&&null===h||Hi(e,o.e,()=>qi(a,c,h,r,i,s))}(l,t,n,r,i,s),o&&void 0!==l&&l.fn&&null!==l.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.E),r=e.host.engine;for(let[i,s]of e.ie)s===t&&(r.T.ke(r,i,n.r),r.ve())}(l,t);let a=vi.get(e);if(void 0===a)return;for(let[e,l]of a)if(t.ee(e)){let a=l.get(0===e.n?null:te(n,e.n));if(void 0!==a)for(let l of[...a])Wi(l,o)&&Gi(l,e,t,n,r,i,s)}else if(e.ee(t))for(let[e,r]of[...l])if(0===t.n||te(e,t.n)===n)for(let e of[...r])Wi(e,o)&&Bi(e)}finally{l||$i.delete(e)}}async function Vi(e,t,n,r,i){if(r===ki)return;let s=y(r);s&&await s;let o=bi.get(t);o.engine&&r.$recursion&&w(`[wcs/mount-dollar-declaration] <${t.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let l=o.I;if(null!==l&&l.el!==e&&l.el.isConnected&&w(`<${t.localName}> already has a connected <${ie.tagNames.state} bind-component="${o.he}">.`),null!==l&&Ui(l,!1),null!==l&&function(e,t,n){let r=e.R,i=`[${ie.bindAttributeName}]`,s=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,l=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.In(t);null!==n&&n!==t;n=n.nextSibling)l(n);l(t)};for(let e of r.ue.values())for(let t of e)if(null===t.j)l(t.a);else for(let e of t.j.K)a(t.j,e.S);for(let e of r.oe.values())for(let t of[e.N,...e.M??[]])null!==t&&a(t,t.S);for(let t of e.L)t.parentNode===n&&s(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)&&(s(n)||r.Wt&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(l,e,n))return async function(e,t,n,r){e.el.engine=null,e.el=t,e.R.element=t,t.engine=e.R,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await Ji(e,r):r()}(l,e,n,i);let a=new re(r,new Gt);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 r=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof r&&"constructor"!==t&&n.set(r,null)}let r=(t,n,r)=>Reflect.apply(t,e.proxy,r);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:r})),t}}(a,r);let u={el:e,L:[],R:a,host:o,pe:[],pt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of o.entries)u.pe.push({m:u,e:e});o.I=u,wi.set(a,u);let h=null===o.engine;h?c.element?.(a,"mounting"):(function(e){let t=e.R,n=e.host,r=n.engine,i=n.el.localName,s=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=Ni(e.E);Mi(n,t)&&(e.E!==t||Li(n,t))&&Oi(`${i}.${e.E}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==s){let e=r.v(s.ye,s.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)&&Oi(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${s.ye.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Si.filter(e=>void 0!==n.state[e]);o.length>0&&Oi(`${i}.${n.he}$`,`[wcs/mount-dollar-declaration] <${i}>: ${o.join(", ")} ${1===o.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let l=t.ot;t.ot=n=>{ji(e,s,n),l.call(t,n)};let a=[...t.O.all()];for(let t of a)ji(e,s,t);for(let e of a)l.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=wi.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Ui(u,!0),Kr.add(a),ti(a,n));let d=c.hr?.(n,a);Rt(a,n),d?.(),u.L=[...n.childNodes],Bt(),h&&a.Nn(),Object.defineProperty(t,o.he,{configurable:!0,enumerable:!0,get:()=>a.proxy});let f=t.$stateReadyCallback;if("function"==typeof f)try{let e=f.call(t,o.he);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,v)}catch(e){v(e)}i(),e.isConnected?(await a.Ee("$connectedCallback"),h&&e.isConnected&&c.element?.(a,"connected")):Ui(u,!1)}async function Ji(e,t){Ui(e,!0);for(let t of e.pe)Bi(t);t?.(),!e.broken&&(await e.R.Ee("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function Qi(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=jt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){oi(t,e);for(let e of li.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,s=i?r.host:r instanceof Element?r:null,o=()=>{let t=null===s?void 0:bi.get(s)?.I;return t?.el===e?t:null},l=t=>{throw i&&oi(r,e),t},a=!1;return{Mt:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,r){let i=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&w(`<${ie.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await je(n).whenDefined(i);let s=bi.get(n);if(void 0!==s)return s.he!==t&&w(`<${i}> already has a <${ie.tagNames.state} bind-component="${s.he}">.`),s.state;let o=()=>(fi.get(n)??[]).filter(e=>Ni(e.name)===t),l=Ti(n,t);if(l&&0===o().length&&xi(n),0===o().length&&(l||((e,t)=>!0===e.getAttribute(yi)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,s)=>{gi.set(n,r),e=function(e,t){ei(e)&&t();let n=li.get(e)??new Set;return li.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>s(new Error(`[@wcstack/state] <${i}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}gi.delete(n);let a=o(),u=mi.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&w(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&r){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),ki}let h=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.E===r)&&w(`<${i}> maps "${e.name}" twice.`);let s=r.split(".").indexOf("*");if(s>=0){let n=r.split(".").slice(0,s).join(".");w(`<${i}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({E:r,ye:e.o,r:e.r,ro:pi.has(e)}),e.engine.Rn(e),""!==r&&delete n[e.name]}let d=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 bi.set(n,s={el:n,he:t,state:d,engine:0===a.length?null:a[0].engine,entries:h,I:null}),d}(e,n,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(l),async start(t,n){await Vi(e,s,i?r:s,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),l(e)})},Je(){let t=o();null!==t?Ji(t).catch(v):a?Promise.resolve().then(()=>{if(e.parentNode===r)return Vi(e,s,i?r:s,bi.get(s).state,()=>{})}).catch(v):gi.has(s)&&xi(s)},Bn(){let e=o();null!==e&&(Ui(e,!1),!e.broken&&(e.R.Ee("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.R,"disconnected")))},reset(){w(`re-setting a component's state is not supported: write <${s?.localName}>.${n} instead.`)}}}var Xi={name:"scopes",hooks:c,install(){c.ut=d(m,c.ut,ai),c.ut=d(m,c.ut,di),c.ut=d(m,c.ut,Qi),c.ar=Ci,c.$o=Ei,c.element=h(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Vr.get(e)??[];if("disconnected"===t)for(let e of n)ni(e);else if("reset"!==t&&Zr(jt.get(e.root))===e){ti(e,e.root);for(let e of n)qr.get(e.root).has(e.t)||qr.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ti(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:ui.get(n);void 0!==r&&ci.set(e,{host:n,def:r})}(e,n)}),c.re=h(c.re,(e,t,n,r,i,s)=>{(function(e,t,n,r){let i=ci.get(e);if(void 0===i)return;let s=t.t.split(".",1)[0];if(!i.def.bindables.includes(s))return;let o=r&&t.t===s;i.host.dispatchEvent(new CustomEvent(`${i.def.tag}:${s}-changed`,{detail:o?n:void 0,bubbles:!0}))})(e,t,i,s),Ki(e,t,n,r,i,s,!1)}),c.Se=h(c.Se,(e,t,n)=>Ki(e,t,n,void 0,void 0,!1,!0)),c.Ie=d(f,c.Ie,(e,t,n,r,i)=>(function(e,t){let n=Vr.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&w(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,i=wi.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===r;e=e.c)r=i.pt.get(e);if(void 0===r)return!1;let s=r.e;return!((null===s.r||s.r.w)&&!s.ro)&&(!!n||(Ri(i,s.r),void w(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===s.E?"":`.${s.E}`}#ro: ${s.ye.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.fe;c.fe=(t,n)=>{let r=Vr.get(t);void 0!==r&&r.length>0&&w(`re-setting a root state with grafted volumes (${r.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=vi.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&w("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},Yi="$recursion",Zi=new WeakMap,es=new WeakSet,ts=new WeakSet,ns=0,rs=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),is=e=>`[wcs/recursion-${e}]`;function ss(e,t){let n=n=>w(`${is("declaration-invalid")} ${Yi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&w(`${is("declaration-invalid")} ${Yi} ${e} must be a non-empty string.`);let r=t.split(".");(r.length<2||"*"!==r[r.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<r.length-1;e++){let t=r[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var os=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function ls(e,t){let n=`${e.l}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&w(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),r}function as(e,t,n){let r=ls(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ce){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===i&&w(`[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.`),os(e,i.k)+r}function us(e,t,n){let r=new Set,i=new Set,s=(e,n,s)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&w(`${is("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&w(`${is("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),s+1>128&&w(`${is("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${s+1} (the limit is 128).`),i.add(e),0)),o=(i,l)=>{for(let a of i){n(l,a);let i=e.o(`${os(t,l)}.${t.key}`),u=e.read(i,a);s(u,i.t,l+1)&&(r.add(u),o(e.Ue(a,i).f,l+1),r.delete(u))}},l=e.o(t.l),a=e.read(l,null);s(a,t.l,0)&&(r.add(a),o(e.Ue(null,l).f,0))}function cs(e,t){let n=function(e){let t=e[Yi],n=[],r=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!r.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),r.add(e);if(void 0===t)return n.length>0&&D(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&w(`${is("declaration-invalid")} ${Yi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&w(`${is("declaration-invalid")} ${Yi} must declare exactly one anchor (it declares ${i.length}).`);let s=ss("anchor",i[0][0]),o=ss("repeat",i[0][1]),l=s.slice(0,-2),a=o.slice(0,-2),u=`.${o}`,c=new Map,h=[],d=`${l}.**`;for(let[e,t]of n){let n=e.slice(d.length);(!e.startsWith(d)||""!==n&&"."!==n[0]||n.includes("**"))&&w(`[wcs/recursion-anchor] "${e}": a recursive key is "${d}" followed by a path (the anchor is "${s}").`),(""===n||n.split(".").slice(1).some(e=>""===e))&&w(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&w(`${is("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),h.push([new RegExp(`^${rs(s)}((?:${rs(u)})*)${rs(n)}$`),n])}return{l:l,step:u,key:a,families:c,matchers:h,owners:new Map,nodeList:new RegExp(`^${rs(l)}((?:${rs(`.*.${a}`)})*)$`)}}(t),r=Zi.has(e);null!==n?(r||ns++,Zi.set(e,n),ts.add(e),es.has(e)||function(e){es.add(e);let t=e,n=t.ot;t.ot=r=>{let i=Zi.get(e);if(r.t.includes("**")){let t=e.O.wt(r.t)===r;return void(ts.has(e)||void 0===i&&t?r.getter=()=>D(r.t):t||n.call(e,r))}if(void 0!==i&&null===r.getter)for(let[e,n]of i.matchers)if(e.test(r.t)){r.getter=i.families.get(n),r.n>0&&(r.F=t.Le++),i.owners.set(r,i.l+".**"+n);break}n.call(e,r)};let r=t.resolve;t.resolve=(t,n)=>{let i=Zi.get(e);return r.call(e,void 0!==i&&t.includes("**")?as(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,r)=>{let s=Zi.get(e);if(void 0===s||!n.includes("**"))return i.call(e,n,r);if(void 0===r)return i.call(e,as(s,n,t.d));(!Array.isArray(r)||r.length>0)&&w(`${is("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=ls(s,n),l=[];return us(e,s,(t,n)=>{for(let r of i.call(e,os(s,t)+o,e.H(n)))l.push(r)}),l};let s=t.wn;t.wn=(n,r,i,o)=>{let l=Zi.get(e);if(void 0===l||!n.includes("**"))return s.call(e,n,r,i,o);Array.isArray(r)||$(9,[n]),r.length>0&&w(`${is("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&w(`${is("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&$(8);let a=ls(l,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(l.step);)u=u.slice(l.step.length);let c=l.key.split(".");(""===u||u===`.${l.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&w(`${is("structural-write")} "${n}" writes the recursion structure itself (a node, its "${l.key}" list or that list's length, or an object on the way to it).`);for(let e of l.families.keys()){let t=e;for(;t.startsWith(l.step);)t=t.slice(l.step.length);(u===t||u.startsWith(`${t}.`))&&w(`${is("readonly")} "${n}" writes into the recursive getter "${l.l}.**${e}".`)}let h=[];us(e,l,(e,t)=>h.push([e,t]));let d=0;for(let[t,n]of h)d+=s.call(e,os(l,t)+a,e.H(n),i);return d}}(e)):r&&(Zi.delete(e),ns--)}function hs(e,t){if(0===ns)return!1;let n=Zi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let r=n.owners.get(e);void 0!==r&&w(`${is("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var ds={name:"recursion",hooks:c,install(){c.fe=h(c.fe,cs),c.element=h(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ts.delete(e)}(e)}),c.Ie=d(f,c.Ie,hs)}},fs="4.8.0",ps=e=>e.split(".").slice(0,2).join("."),ms=class extends Xt{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return ps(this.version)===ps(fs)}};function gs(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends ms{})}var ys=()=>ie.tagNames.ssr,bs=Symbol.for("wcstack.ssr.snapshotBuilder"),ws=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),vs=e=>document.createComment(e),_s=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,$s=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),ks=new WeakMap,Ss=new WeakMap,Ns=new WeakMap,As=new WeakSet,Cs=new WeakMap;function Es(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function Ts(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 xs=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Ps(e,t,n,r){let i=vs(null===r?"wcs-[":`wcs-[:${r}`),s=vs("wcs-]");n.length>0&&n[0].Re().before(...Es(e,t)),t.after(i);for(let e of n)null===r&&e.Re().before(vs("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ct:e.L[e.L.length-1])(n[n.length-1]):i;(xs(o)??o).after(s);for(let e of Es(i,s))As.add(e)}function Os(e){if(e instanceof at){Ps(e.S,e.S,e.Ae,null);for(let t of e.Ae)Ms(t);return}let t=e.I;null!==t&&(Ps(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Ms(t))}function Ms(e){if(null!==e.u)for(let t of e.u)Os(t)}var Ls=new Set(["script","style","template","textarea","title"]),Is="data-wcs-raw",js=e=>Ls.has(e.localName)||e.localName===ys();function Rs(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(vs("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(vs("wcs-s")):1===t.nodeType&&!js(t)&&Rs(t)}var Hs=0;function Ws(e,t){let n=e.getRootNode(),r=[t];for(let e of Ss.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let i=new Map;for(let e of r){let t=ks.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.N&&n.set(t.N.S,t.N),null!==t.M)for(let e of t.M)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.j)for(let t of e.j.K)n.set(t.S,e.j);let r=new Set;for(let[e,s]of t){i.set(e,s);let t=n.get(e);void 0!==t&&!r.has(t)&&e.isConnected&&(r.add(t),Os(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ns.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>As.has(e)||1===e.nodeType&&t.has(e)&&qs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(js(e.parentNode)?Cs.has(e):t.has(n)&&$s(n,"wcs-t:"))&&(Cs.has(e)||t.get(e)!==e.data):!t.has(e))&&r.push(e)}for(let e of r)e.remove()}let n=Array.from(e.childNodes);js(e)&&n.some(e=>Cs.has(e))&&e.setAttribute(Is,n.map(e=>Cs.has(e)?`{{ ${Cs.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Rs(9===n.nodeType?n.body:n);let s=document.createElement(ys());s.setAttribute("version",fs);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 r=Object.getOwnPropertyDescriptor(e,n);void 0!==r.get||void 0!==r.set||"function"==typeof r.value||(t[n]=r.value)}return t}(t.target)),s.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 r="svg"===n?.localName,i=`wcs-${r?"s":"t"}${Hs++}`;e.replaceWith(vs(`wcs-p:${i}`));let o=document.importNode(xt(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Ts(e,document.createElement("template"),...e.childNodes));if(r){let e=document.createElementNS(n.namespaceURI,"svg");e.append(o),o=e}let l=document.createElement("template");l.id=i,s.append(Ts(t,l,o))}e.before(s)}function Us(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Cs.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===ys())continue;let e=t.engine;null!=e&&Ws(t,e)}}var Ds=Symbol.for("wcstack.state.ssr.impl"),Fs=new Map,zs=new WeakMap,qs=e=>!0===c.$o?.(e),Bs=e=>1===e.nodeType&&!js(e)&&!qs(e),Gs=e=>e.f.flat().concat(e.z??[]),Ks=e=>{for(let t of Gs(e))t.remove()};function Vs(e,t,n){let r=/^wcs-\[(?::(\d+))?/.exec(e.data),i=e.previousSibling,s=e.parentNode,o=[],l=e.nextSibling;for(e.remove();null!==l&&!_s(l,"wcs-]");){let e=l.nextSibling;if(_s(l,"wcs-|"))o.push([]),l.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];$s(l,"wcs-[")?e=Vs(l,t,n):(n.push(l),Bs(l)&&Js(l,t))}l=e}let a={branch:void 0===r[1]?null:Number(r[1]),f:o,z:l??s.appendChild(vs("wcs-]"))},u=Gs(a);l=a.z.nextSibling;for(let e of u)n?.push(e),t&&Ct.add(e);return t&&null!==i?Fs.set(i,a):Ks(a),l}function Js(e,t){for(let n=e.firstChild;null!==n;)$s(n,"wcs-[")?n=Vs(n,t):(Bs(n)&&Js(n,t),n=n.nextSibling)}function Qs(e,t,n){let r=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=vs(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!_s(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,r="s"===e[10]?Ts(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);r.removeAttribute("id"),t.replaceChild(r,i)}}}catch{}}else 1===i.nodeType&&!js(i)&&(qs(i)?zs.set(i,{ssr:t,Te:n}):r(i))};r(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||io(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{$s(e,"wcs-[")?r++:_s(e,"wcs-]")&&--r<0&&(r=0,n=t+1)}),0===r)continue;let i=0;for(let r=t.firstChild;null!==r;r=r.nextSibling)if($s(r,"wcs-["))i++;else if(_s(r,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Js(e,n)}function Xs(e,t){let n=zs.get(e);if(void 0===n)return null;zs.delete(e);let r=e=>Qs(e,n.ssr,n.Te);if(n.Te||to(t,e,e,r),r(e),!n.Te)return null;let i=c.Te;return c.Te=lo,()=>{c.Te=i,Ys()}}function Ys(){for(let e of Fs.values())Ks(e);Fs.clear()}function Zs(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function eo(e,t,n,r){let i=null;for(let r of e){let e=r[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===i||e.length>i[n].length)&&(i=r)}let s=i?.[r];if(null==s)return null;let o=i[n],l=""===o?t:t.slice(o.length+1);return""===s?l:""===l?s:`${s}.${l}`}function to(e,t,n,r){let i=document.createElement("template").content;for(let e of n.childNodes)i.appendChild(i.ownerDocument.importNode(e,!0));r(i),e.root=t;let s=()=>{};Et(e,[...i.childNodes],null,!0,s,s,s,(t,n)=>kt(e,n,null,0))}function no(e,t,n){if(ws()){if(n instanceof Array){for(let e=n.length;e-- >0;)yt(n[e])&&n.splice(e,1);let e=t;if(n.some(bt))As.add(e);else if(e.localName.includes("-")&&!qs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ns.set(e,t)}return}if("string"==typeof n){if(Cs.set(t,n),js(t.parentNode))return;let e=vs(`wcs-t:${encodeURIComponent(n)}`),r=vs("wcs-/t");return t.before(e),void t.after(r)}let r=ks.get(e);void 0===r&&ks.set(e,r=new Map),r.set(t,n);let i=t.getRootNode(),s=Ss.get(i);return void 0===s&&Ss.set(i,s=new Set),void s.add(e)}if("string"!=typeof n&&Fs.size>0){let e=Fs.get(n);void 0!==e&&(Fs.delete(n),Fs.set(t,e))}}var ro=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),io=e=>3===e.nodeType&&""===e.data.trim(),so=e=>{let t=Fs.get(e)?.z??e;return(xs(t)??t).nextSibling};function oo(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.Cn;for(let r=0;r<n.length;r++){let i=n[r],s=e.ln,o=t[i[0]];for(let e=0;;){if(s=s.childNodes[i[e]],o?.nodeName!==s.nodeName)return!1;if(++e===i.length)break;o=(xs(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=so(o)}e.So[r]=o}return!0}function lo(e,t,n){if(0===Fs.size)return null;let r=t,i=0;if(!n){let e=ie.commentIfPrefix;if(!_s(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(ro(n)&&i++,!_s(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Fs.has(r)&&null!==n&&!_s(n,e)&&1!==n.nodeType;n=n.nextSibling)ro(n)&&(r=n)}let s=Fs.get(r);if(void 0===s)return null;if(!n&&s.branch!==i)return Fs.delete(r),Ks(s),null;let o=s.f.shift();if(0===s.f.length&&Fs.delete(r),s.z?.replaceWith(...Es(t,r)),s.z=null,void 0===o)return null;let l=[];for(let e=0;e<o.length;e++){let t=Fs.get(o[e]);if(l.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else xs(o[e])===o[e+1]&&e++}if(!oo(e,l)){let n=(e.jn?e.root:e.ln).cloneNode(!0);l=e.jn?[n]:[...n.childNodes],oo(e,l),(o[0]??s.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of o)e.remove()}return l}var ao={name:"ssr",hooks:c,install(){c.Dn=no,c.hr=Xs;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||ws())return;let n=t.previousElementSibling,r=n?.localName===ys(),i=r?n.getAttribute("version"):null,s=null===i||ps(i)===ps(fs);if(s){let t=e,n=t.Ee;t.Ee=(t,r)=>"$connectedCallback"===t?void 0:n.call(e,t,r)}if(!r)return;let o=!s&&parseInt(i)<4,l=/^3\.(\d+)\.(\d+)$/.exec(i),a=null!==l&&(+l[1]-5||+l[2]-3)>=0;s||console.warn(`[@wcstack/state] <${ys()} version="${i}"> does not match ${fs}: 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=s?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 r=Object.getOwnPropertyDescriptor(n,e);void 0!==r&&(void 0!==r.get||void 0!==r.set||"function"==typeof r.value)||(n[e]=t[e])}e.hydrated=!0}let h=t.getRootNode();for(let e of Array.from(h.querySelectorAll(`[${Is}]`)))e.textContent=e.getAttribute(Is),e.removeAttribute(Is);let d=9===h.nodeType?h.body:h;n.remove();let f=e=>o?function(e,t,n){let r=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!qs(t);)t=t.parentElement;if(null===t)return null;let n=r.get(t);if(void 0===n){let e=i(t),s=t.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of ue(t.getAttribute(ie.bindAttributeName)??"")){let t=r.Ze;r.Ne[0]===s&&n.push([e?eo(e,t,1,0):t,r.Ne.slice(1).join("."),e&&t])}}return n},s=(e,t,n)=>{let r=i(e);if(null===r)return t;let s=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===s)return n?t:eo(r,t,0,1)??t;let o=s[1].replace(/#m\d+\./g,"").slice(0,-1);return r.some(e=>""===e[1]&&(e[0]===o||e[2]===o))?s[2]:eo(r,s[2],2,1)??s[2]};for(let t of Zs(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!_s(r,`@@wcs-${e[1]}-end:${e[2]}`);)r=r.nextSibling;if(null!==r){for(;t.nextSibling!==r;)t.nextSibling.remove();r.remove(),t.replaceWith(..."text"===e[1]?[vs(`@@:${s(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let r of Zs(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(r.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let l=document.importNode(i,!0),a=ie.bindAttributeName;l.removeAttribute("id"),l.setAttribute(a,l.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+s(n??r,i))),o(l.content,n??r);let u=l.content.firstChild;r.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?l.content.childNodes:[l])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,n,a):Qs(e,n,s);s||to(e,h,d,f),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),r=e.map(e=>e.selected),i=e.map(e=>e.hasAttribute("selected")),s=i.lastIndexOf(!0);s<0&&(s=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>r[t]!==i[t]):n.selectedIndex!==s)&&t.push([n,()=>e.forEach((e,t)=>e.selected=r[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(d)),f(d),s&&(c.Te=lo,queueMicrotask(()=>{Ys(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Ds]={build:Us,reset(){Hs=0}},void 0===e[bs]&&(e[bs]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Ds].build(t),reset:()=>e[Ds].reset()})}(),c.Ao=h(c.Ao,gs);for(let e of en())gs(e)}},uo="__WCSTACK_DEVTOOLS_HOOK__",co=null,ho=new Set,fo=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),po=new WeakMap,mo=0,go=new WeakMap;function yo(e){if(null===co)return;let t=go.get(e),n=ho.has(e)?function(e,t){let n=new Map,r=new Set,i=(r,i,s,o,l,a)=>{if(5===r)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(r,i),c=0===o.n?null:l,h=`${(e=>{let t=po.get(e);return void 0===t&&po.set(e,t=++mo),t})(s)}|${u}|${o.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(h))return;let d=t?.get(h);n.set(h,d??{binding:{propName:u,statePathName:o.t,bindingType:a,node:s,replaceNode:s},absoluteAddress:fo(e,o,c)})},s=e=>i(e.i,e.name,e.a,e.o,e.r,e.on()),o=e=>{if(!r.has(e)){if(r.add(e),null!==e.we)for(let t of e.we)s(t);if(e instanceof Ye&&null!==e.pe){let t=e.C.Xe;for(let n=0;n<t.length;n++){let r=e.V?.[n];void 0!==r?s(r):i(t[n].i,t[n].name,e.pe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)l(t)}},l=e=>{if(!r.has(e))if(r.add(e),e instanceof at){i(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Ae)o(t)}else null!==e.I&&o(e.I)};for(let t of e.ue.values())for(let e of t)s(e),null!==e.j&&l(e.j);for(let t of e.oe.values())if(null!==t.N&&l(t.N),null!==t.M)for(let e of t.M)l(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,r]of t)n.has(e)||co({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&co({type:"state:binding-added",...r});go.set(e,n)}function bo(e){let t=jt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function wo(e){let t=new Set,n=new Set,r=new Set,i=new Set;for(let s of e.O.all()){for(let e=1;e<=s.n;e++)t.add(s.h[e].t);"*"===s.s&&n.add(s.t),null!==s.getter&&r.add(s.t),null!==s.se&&i.add(s.t)}let s=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:r,setter:i},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.Oe.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==s.$watch&&"object"==typeof s.$watch?new Set(Object.keys(s.$watch)):null,keyedListPaths:null!==s.$listKeys&&"object"==typeof s.$listKeys?new Set(Object.keys(s.$listKeys)):null}}var vo=new WeakSet,_o=new WeakMap;function $o(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(vo.has(t))return;vo.add(t);let r=t.emit;t.emit=(...i)=>(null!==co&&co({type:"state:token-emit",kind:n,tokenName:t.name,args:i,subscriberCount:t.size,stateElement:e.element}),r.apply(t,i))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.Oe.values())t(n,"event")}(e),"connected"===t){if(ho.has(e))return;ho.add(e),co?.({type:"state:element-registered",rootNode:e.root,element:e.element}),yo(e)}else"disconnected"===t&&(ho.delete(e),yo(e),co?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function ko(e,t,n,r,i,s){if(null===co)return;let o=fo(e,t,0===t.n?null:n),l=_o.get(e);void 0===l&&_o.set(e,l=new Set),l.add(o),s&&co({type:"state:write",absoluteAddress:o,value:i,oldValue:r,hasOldValue:!0})}function So(e){if(null===co)return;let t=_o.get(e);_o.delete(e),void 0!==t&&co({type:"state:update-batch",addresses:t}),yo(e)}function No(e,t,n){co?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Ao={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Co(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...Ao["*"],...Object.hasOwn(Ao,e)?Ao[e]:[]])(n);return r.includes(t)||$(1205,[n,t,r.join(", ")],t,r),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)if(!g.has(t.name)){if(t.hooks!==c)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${t.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);g.add(t.name),t.install()}}([vn,cr,Ir,zr,Xi,ds,ao,{name:"devtools",hooks:c,install(){c.element=h(c.element,$o),c.re=h(c.re,ko),c.me=h(c.me,So),c.Ye=h(c.Ye,No),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[uo]??(e[uo]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let r of t)r.onEvent?.(e.id,n)})};return{version:2,sources:e,register(r){if(!e.has(r.id)){e.set(r.id,r),n(r);for(let e of t)e.onSourceRegistered?.(r)}},unregister(n){let r=e.get(n);if(void 0!==r){r._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(r){t.add(r);for(let t of e.values())n(t),r.onSourceRegistered?.(t);return()=>{if(t.delete(r))for(let t of e.values())n(t)}}}}());2!==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:fs,getStateElements:()=>[...ho].map(wo),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let r=n._,i=n.De?.length??0;if((null===r||0===r.size)&&0===i)continue;let s,o=0;if(null!==r)for(let e of r.values())o+=e.size;try{s=0===n.n?e.v(n,null):void 0}catch{s=void 0}t.push({path:n.t,tracked:!1,rows:o,keys:null===r?0:r.size,lists:i,lastValue:s})}return t}(bo(e)),keys(e){let t=bo(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return bo(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){bo(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(e){let t=null===co&&null!==e;co=e,null===e&&(go=new WeakMap),c.at=e&&((e,t)=>co?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of ho)yo(e)})}})}()}},{name:"native-commands",hooks:c,install(){c.or=Co}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Ut]&&(e[Ut]={protocol:"wcs-binder",version:1,bind:qt})})(),en().includes(e)||Zt.push(new WeakRef(e));let t=ie.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Yt{}),c.Ao?.(e)}();const Eo={route:"wcs-route",router:"wcs-router",outlet:"wcs-outlet",layout:"wcs-layout",layoutOutlet:"wcs-layout-outlet",link:"wcs-link",head:"wcs-head",guardHandler:"wcs-guard-handler"},To=!1,xo=[".html"];function Po(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function Oo(e,t){if(t&&"cause"in t)throw new Error(`[@wcstack/router] ${e}`,{cause:t.cause});throw new Error(`[@wcstack/router] ${e}`)}let Mo=class extends Error{fallbackPath;constructor(e,t){super(e),this.fallbackPath=t}};const Lo={int:{typeName:"int",pattern:/^-?\d+$/,parse(e){if(this.pattern.test(e))return parseInt(e,10)}},float:{typeName:"float",pattern:/^-?\d+(?:\.\d+)?$/,parse(e){if(this.pattern.test(e))return parseFloat(e)}},bool:{typeName:"bool",pattern:/^(true|false|0|1)$/,parse(e){if(this.pattern.test(e))return"true"===e||"1"===e}},uuid:{typeName:"uuid",pattern:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,parse(e){if(this.pattern.test(e))return e}},slug:{typeName:"slug",pattern:/^[a-z0-9]+(?:-[a-z0-9]+)*$/,parse(e){if(this.pattern.test(e))return e}},isoDate:{typeName:"isoDate",pattern:/^\d{4}-\d{2}-\d{2}$/,parse(e){if(!this.pattern.test(e))return;const[t,n,r]=e.split("-").map(Number),i=new Date(t,n-1,r);return i.getFullYear()===t&&i.getMonth()===n-1&&i.getDate()===r?i:void 0}},any:{typeName:"any",pattern:/^.+$/,parse(e){if(this.pattern.test(e))return e}}};function Io(e){const t={};for(const[n,r]of new URLSearchParams(e))t[n]=r;return Object.freeze(t)}function jo(e,t){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(e[r]!==t[r])return!1}return!0}const Ro={static:2,param:1,"catch-all":0};let Ho=class extends EventTarget{_target;_parentCore=null;_path="";_name="";_isFallbackRoute=!1;_segmentInfos=[];_absoluteSegmentInfos;_paramNames;_absoluteParamNames;_weight;_absoluteWeight;_segmentCount;_params={};_typedParams={};_active=!1;_hasGuard=!1;_guardHandler=null;_guardFallbackPath="";_waitForSetGuardHandler=null;_resolveSetGuardHandler=null;_guardHandlerLoadFailed=!1;constructor(e){super(),this._target=e??this}get parentCore(){return this._parentCore}set parentCore(e){this._parentCore=e}get path(){return this._path}get name(){return this._name}get isFallbackRoute(){return this._isFallbackRoute}get isRelative(){return!this._path.startsWith("/")}get segmentInfos(){return this._segmentInfos}_checkParentCore(e,t){return this._isFallbackRoute||(this.isRelative&&!this._parentCore&&Oo(`${Eo.route} is relative but has no parent route.`),!this.isRelative&&this._parentCore&&Oo(`${Eo.route} is absolute but has a parent route.`)),this.isRelative&&this._parentCore?e(this._parentCore):t()}get absolutePath(){return this._checkParentCore(e=>{const t=e.absolutePath;return t.endsWith("/")?t+this._path:t+"/"+this._path},()=>this._path)}get absoluteSegmentInfos(){return void 0===this._absoluteSegmentInfos&&(this._absoluteSegmentInfos=this._checkParentCore(e=>[...e.absoluteSegmentInfos,...this._segmentInfos],()=>[...this._segmentInfos])),this._absoluteSegmentInfos}get params(){return this._params}get typedParams(){return this._typedParams}get active(){return this._active}get paramNames(){if(void 0===this._paramNames){const e=[];for(const t of this._segmentInfos)t.paramName&&e.push(t.paramName);this._paramNames=e}return this._paramNames}get absoluteParamNames(){return void 0===this._absoluteParamNames&&(this._absoluteParamNames=this._checkParentCore(e=>[...e.absoluteParamNames,...this.paramNames],()=>[...this.paramNames])),this._absoluteParamNames}get weight(){if(void 0===this._weight){let e=0;for(const t of this._segmentInfos)e+=Ro[t.type];this._weight=e}return this._weight}get absoluteWeight(){return void 0===this._absoluteWeight&&(this._absoluteWeight=this._checkParentCore(e=>e.absoluteWeight+this.weight,()=>this.weight)),this._absoluteWeight}get segmentCount(){if(void 0===this._segmentCount){let e=0;for(const t of this._segmentInfos)"catch-all"!==t.type&&e++;this._segmentCount=""===this._path?0:e}return this._segmentCount}get absoluteSegmentCount(){return this._checkParentCore(e=>e.absoluteSegmentCount+this.segmentCount,()=>this.segmentCount)}parsePath(e,t={}){this._segmentInfos=[],this._absoluteSegmentInfos=void 0,this._paramNames=void 0,this._absoluteParamNames=void 0,this._weight=void 0,this._absoluteWeight=void 0,this._segmentCount=void 0,this._path=e,this._name=t.name||"",this._isFallbackRoute=t.isFallback||!1,t.isIndex&&this._segmentInfos.push({type:"static",segmentText:"",paramName:null,pattern:/^$/,isIndex:!0});const n=e.split("/");for(let e=0;e<n.length;e++){const r=n[e];if(!(""===r&&e===n.length-1&&e>0)){if("*"===r){this._segmentInfos.push({type:"catch-all",segmentText:r,paramName:"*",pattern:new RegExp("^(.*)$")});break}if(r.startsWith(":")){const e=r.match(/^:([^()]+)(\(([^)]+)\))?$/);let t,n="any";e?(t=e[1],e[3]&&Object.keys(Lo).includes(e[3])&&(n=e[3])):t=r.substring(1),this._segmentInfos.push({type:"param",segmentText:r,paramName:t,pattern:new RegExp("^([^\\/]+)$"),paramType:n})}else""===r&&t.isIndex||this._segmentInfos.push({type:"static",segmentText:r,paramName:null,pattern:new RegExp(`^${r}$`)})}}this._hasGuard=!1,t.hasGuard&&(this._guardFallbackPath=t.guardFallback||"/",this.enableGuard())}enableGuard(){this._hasGuard||(this._hasGuard=!0,this._guardFallbackPath||="/",this._waitForSetGuardHandler=new Promise(e=>{this._resolveSetGuardHandler=e}))}setParams(e,t){const n=this._active;this._params=e,this._typedParams=t,this._active=!0,this._target.dispatchEvent(new CustomEvent("wcs-route:params-changed",{detail:{params:e,typedParams:t},bubbles:!0})),n||this._target.dispatchEvent(new CustomEvent("wcs-route:active-changed",{detail:!0,bubbles:!0}))}clearParams(){const e=this._active;this._params={},this._typedParams={},this._active=!1,e&&this._target.dispatchEvent(new CustomEvent("wcs-route:active-changed",{detail:!1,bubbles:!0}))}shouldChange(e){for(const t of this.paramNames)if(this._params[t]!==e[t])return!0;return!1}get hasGuard(){return this._hasGuard}get guardHandler(){return this._guardHandler||Oo(`${Eo.route} has no guardHandler.`),this._guardHandler}set guardHandler(e){this._guardHandler=e,this._resolveSetGuardHandler?.()}notifyGuardHandlerLoadFailed(){this._guardHandlerLoadFailed=!0,this._resolveSetGuardHandler?.()}async guardCheck(e){if(this._hasGuard&&this._waitForSetGuardHandler&&await this._waitForSetGuardHandler,this._guardHandler){const t=e.path,n=e.lastPath,r=await this._guardHandler(t,n,function(e){return Object.freeze({params:Object.freeze({...e.params}),typedParams:Object.freeze({...e.typedParams}),searchParams:Io(e.search??""),routeName:e.routes[e.routes.length-1]?.name??""})}(e));if("string"==typeof r&&""!==r)throw new Mo("Navigation cancelled by guard.",r);if(!r)throw new Mo("Navigation cancelled by guard.",this._guardFallbackPath);return"object"==typeof r?r:null}if(this._hasGuard&&this._guardHandlerLoadFailed)throw new Mo("Navigation cancelled: guard handler failed to load.",this._guardFallbackPath);return null}};const Wo="data-wcs-ssr",Uo="data-wcs-ssr-link",Do="@@wcs-route-ph:",Fo="@@wcs-route-start:",zo="@@wcs-route-end:";let qo=class extends HTMLElement{_core;_routeParentNode=null;_routeChildNodes=[];_routerNode=null;_uuid=Po();_placeHolder=document.createComment(`@@route:${this._uuid}`);_childNodeArray;_endMarker;held=null;_childIndex=0;_initialized=!1;_routes;constructor(){super(),this._core=new Ho(this)}get routeParentNode(){return this._routeParentNode}get routeChildNodes(){return this._routeChildNodes}get routerNode(){return this._routerNode||Oo(`${Eo.route} has no routerNode.`),this._routerNode}get uuid(){return this._uuid}get placeHolder(){return this._placeHolder}get endMarker(){return void 0===this._endMarker&&(this._endMarker=document.createComment(`${zo}${this.absolutePath}`)),this._endMarker}get childNodeArray(){return void 0===this._childNodeArray&&(this._childNodeArray=Array.from(this.childNodes)),this._childNodeArray}adoptChildNodes(e,t){for(this._childNodeArray=[...e],t&&(this._endMarker=t);this.firstChild;)this.removeChild(this.firstChild)}get routes(){return void 0===this._routes&&(this._routes=this.routeParentNode?this.routeParentNode.routes.concat(this):[this]),this._routes}get childIndex(){return this._childIndex}get path(){return this._core.path}get name(){return this._core.name}get isRelative(){return this._core.isRelative}get absolutePath(){return this._core.absolutePath}get segmentInfos(){return this._core.segmentInfos}get absoluteSegmentInfos(){return this._core.absoluteSegmentInfos}get params(){return this._core.params}get typedParams(){return this._core.typedParams}get paramNames(){return this._core.paramNames}get absoluteParamNames(){return this._core.absoluteParamNames}get weight(){return this._core.weight}get absoluteWeight(){return this._core.absoluteWeight}get segmentCount(){return this._core.segmentCount}get absoluteSegmentCount(){return this._core.absoluteSegmentCount}get fullpath(){return this.absolutePath}get hasGuard(){return this._core.hasGuard}get guardHandler(){return this._core.guardHandler}set guardHandler(e){this._core.guardHandler=e}setParams(e,t){this._core.setParams(e,t)}clearParams(){this._core.clearParams()}shouldChange(e){return this._core.shouldChange(e)}async guardCheck(e){return this._core.guardCheck(e)}notifyGuardHandlerLoadFailed(){this._core.notifyGuardHandlerLoadFailed()}enableGuard(){this._core.enableGuard()}testAncestorNode(e){let t=this._routeParentNode;for(;t;){if(t===e)return!0;t=t.routeParentNode}return!1}initialize(e,t){if(this._initialized)return;let n;this._initialized=!0;let r=!1,i=!1;this.hasAttribute("path")?n=this.getAttribute("path")||"":this.hasAttribute("index")?(n="",r=!0):this.hasAttribute("fallback")?(n="",i=!0):Oo(`${Eo.route} should have a "path" or "index" attribute.`),this._routerNode=e,this._routeParentNode=t;const s=t||e;s.routeChildNodes.push(this),this._childIndex=s.routeChildNodes.length-1,i&&(t&&Oo(`${Eo.route} with fallback attribute must be a direct child of ${Eo.router}.`),e.fallbackRoute&&Oo(`${Eo.router} can have only one fallback route.`),e.fallbackRoute=this),t&&(this._core.parentCore=t._core),this._core.parsePath(n,{isIndex:r,isFallback:i,hasGuard:this.hasAttribute("guard"),guardFallback:this.getAttribute("guard"),name:this.getAttribute("name")||""}),this.setAttribute("fullpath",this.absolutePath)}};const Bo=Symbol.for("wcstack.trustedTypes.policy"),Go=Symbol.for("wcstack.trustedTypes.internal"),Ko="wcstack";function Vo(){const e=globalThis[Bo];return null===e||"object"!=typeof e?null:e}let Jo=!1;function Qo(e){const t=function(){const e=globalThis,t=e[Go];if(void 0!==t)return t;const n=globalThis.trustedTypes;let r=null;if(n&&"function"==typeof n.createPolicy)try{r=n.createPolicy(Ko,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){"function"!=typeof Vo()?.createHTML&&console.error(`[@wcstack/router] Could not create the Trusted Types policy "${Ko}". Allow it in the CSP (\`trusted-types ${Ko};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,e)}return e[Go]=r,r}(),n=t?.createHTML;if("function"==typeof n)return n.call(t,e);if(!("trustedTypes"in globalThis))return e;const r=Vo(),i=r?.createHTML;return"function"==typeof i?(Jo||(Jo=!0,console.warn(`[@wcstack/router] Falling back to the injected Trusted Types policy to expand a layout template, because the "${Ko}" policy could not be created. If that policy sanitizes (e.g. DOMPurify), custom elements in the layout may be stripped. Allow \`trusted-types ${Ko};\` in the CSP to avoid this. See docs/csp.md section 7.`)),i.call(r,e)):e}const Xo=new Map;let Yo=class extends HTMLElement{_uuid=Po();constructor(){super()}async _loadTemplateFromSource(e){try{const t=await fetch(e);t.ok||Oo(`${Eo.layout} failed to fetch layout from source: ${e}, status: ${t.status}`);const n=await t.text();return Xo.set(e,n),n}catch(t){Oo(`${Eo.layout} failed to load layout from source: ${e}, error: ${t}`,{cause:t})}}_loadTemplateFromDocument(e){const t=document.getElementById(`${e}`);return t&&t instanceof HTMLTemplateElement?t.innerHTML:null}async loadTemplate(){const e=this.getAttribute("src"),t=this.getAttribute("layout");e&&t&&console.warn(`${Eo.layout} have both "src" and "layout" attributes.`);const n=document.createElement("template");if(e)Xo.has(e)?n.innerHTML=Qo(Xo.get(e)||""):n.innerHTML=Qo(await this._loadTemplateFromSource(e)||"");else if(t){const e=this._loadTemplateFromDocument(t);e?n.innerHTML=Qo(e):console.warn(`${Eo.layout} could not find template with id "${t}".`)}return n}get uuid(){return this._uuid}get enableShadowRoot(){return!!this.hasAttribute("enable-shadow-root")||!this.hasAttribute("disable-shadow-root")&&To}get name(){return this.getAttribute("name")||""}},Zo=class extends HTMLElement{_routesNode=null;_lastRoutes=[];_initialized=!1;constructor(){super()}get routesNode(){return this._routesNode||Oo(`${Eo.outlet} has no routesNode.`),this._routesNode}set routesNode(e){this._routesNode=e}get rootNode(){return this.shadowRoot?this.shadowRoot:this}get lastRoutes(){return this._lastRoutes}set lastRoutes(e){this._lastRoutes=[...e]}_resolveEnableShadowRoot(){return!!this.hasAttribute("enable-shadow-root")||!this.hasAttribute("disable-shadow-root")&&To}_initialize(){this._resolveEnableShadowRoot()&&this.attachShadow({mode:"open"}),this._initialized=!0}connectedCallback(){this._initialized||this._initialize()}disconnectedCallback(){this._lastRoutes=[]}};const el=new Set(["props","states","attr",""]);function tl(e,t,n){for(const[r,i]of Object.entries(t))switch(n){case"props":e.props={...e.props,[r]:i};break;case"states":e.states={...e.states,[r]:i};break;case"attr":null==i?e.removeAttribute(r):e.setAttribute(r,String(i));break;case"":e[r]=i}}function nl(e,t){e.hasAttribute("data-bind")||Oo(`${e.tagName} has no 'data-bind' attribute.`);const n=e.getAttribute("data-bind")||"";el.has(n)||Oo(`${e.tagName} has invalid 'data-bind' attribute: ${n}`);const r=n,i=function(e){const t=e.tagName.toLowerCase();if(t.includes("-"))return t;const n=e.getAttribute("is");return n&&n.includes("-")?n:null}(e);i&&void 0===customElements.get(i)?customElements.whenDefined(i).then(()=>{e.isConnected&&tl(e,t,r)}).catch(()=>{Oo(`Failed to define custom element: ${i}`)}):tl(e,t,r)}const rl=Symbol.for("wcstack.binder");function il(){const e=globalThis[rl];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}const sl=Symbol.for("wcstack.binder.pending"),ol=Symbol.for("wcstack.binder.taken");function ll(){const e=globalThis;let t=e[ol];return void 0===t&&(t=new WeakSet,e[ol]=t),t}function al(e,t){const n=il();return null===n?(function(){const e=globalThis;let t=e[sl];return void 0===t&&(t=[],e[sl]=t),t}().push(e),!1):(ll().add(e),n.bind(e,t),!0)}const ul={range:!0};function cl(e,t){for(const n of e.routeChildNodes)t.add(n.placeHolder).add(n.endMarker),cl(n,t);return t}function hl(e){const t=e.placeHolder,n=e.endMarker,r=null!==n.parentNode&&n.parentNode===t.parentNode&&!!(4&t.compareDocumentPosition(n)),i=r?null:cl(e,new Set),s=[];let o=0;for(let l=t.nextSibling;null!==l&&l!==n&&(null===i||8!==l.nodeType||!/^@@(route:|wcs-route-)/.test(l.data)||i.has(l));l=l.nextSibling)s.push(l),(r||e.childNodeArray.includes(l))&&(o=s.length);return s.length=o,s}const dl=new WeakSet;function fl(e){const t=Eo.router,n=Eo.outlet;for(const r of e.querySelectorAll(n))dl.has(r)||r.previousElementSibling?.matches(t)||(dl.add(r),console.warn(`[@wcstack/router] [wcs/router-outlet-misplaced] A <${t}> uses only the element right after it as its outlet, and this page has a <${n}> that no router uses. The router makes an outlet of its own right after itself, so the routes render there and the <${n}> you placed stays empty. Move the <${n}> right after the <${t}>.`,r))}const pl=e=>{for(const t of e)if(t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&""!==t.textContent.trim())return!0;return!1};function ml(e){console.warn(`[@wcstack/router] [wcs/layout-slot-missing] This layout's template has no default <slot>, so what its <${Eo.layout}> holds outside the named slots — the nested routes and their pages — is not shown. Put a <slot></slot> where the page goes.`,e)}class gl extends HTMLElement{_layout=null;_initialized=!1;_initializing=!1;_disconnectedDuringInit=!1;_layoutChildNodes=[];constructor(){super()}get layout(){return this._layout||Oo(`${Eo.layoutOutlet} has no layout.`),this._layout}set layout(e){this._layout=e,this.setAttribute("name",e.name)}get name(){return this.layout.name}async _initialize(){this._initializing=!0;try{this._initialized=!0,this.layout.enableShadowRoot&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=await this.layout.loadTemplate();if(!this.isConnected)return void(this._initialized=!1);if(this.shadowRoot){this.shadowRoot.appendChild(e.content.cloneNode(!0));const t=[];for(const e of Array.from(this.layout.childNodes))this._layoutChildNodes.push(e),e instanceof Element&&e.getAttribute("slot")||t.push(e),this.appendChild(e);!this.shadowRoot.querySelector('slot:not([name]), slot[name=""]')&&pl(t)&&ml(this),fl(this.shadowRoot)}else{const t=e.content.cloneNode(!0),n=new Map;t.querySelectorAll("slot").forEach(e=>{const t=e.getAttribute("name")||"";n.has(t)?console.warn(`${Eo.layoutOutlet} duplicate slot name "${t}" in layout template.`):n.set(t,e)});const r=new Map,i=document.createDocumentFragment();for(const e of Array.from(this.layout.childNodes)){if(this._layoutChildNodes.push(e),e instanceof Element){const t=e.getAttribute("slot")||"";if(t.length>0&&n.has(t)){r.has(t)||r.set(t,document.createDocumentFragment()),r.get(t)?.appendChild(e);continue}}i.appendChild(e)}for(const[e,t]of n){const n=r.get(e);n&&t.replaceWith(n)}const s=n.get("");s?s.replaceWith(i):pl(i.childNodes)&&ml(this),this.appendChild(t),fl(this)}!function(e){if(null!==il())for(const t of e)1===t.nodeType&&al(t,ul)}(Array.from(this.childNodes))}finally{this._initializing=!1}}async connectedCallback(){null!==this._layout&&(this._initialized||(this._disconnectedDuringInit=!1,await this._initialize(),!this._disconnectedDuringInit&&this.isConnected))}disconnectedCallback(){this._initializing&&(this._disconnectedDuringInit=!0)}assignParams(e){for(const t of this._layoutChildNodes)t instanceof Element&&(t.querySelectorAll("[data-bind]").forEach(t=>{nl(t,e)}),t.hasAttribute("data-bind")&&nl(t,e))}}function yl(){return document.createElement(Eo.layoutOutlet)}const bl="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";function wl(e,t){(async function(e,t){let n=null,r=null;const i=t.uuid||"",s=`\n//# sourceURL=${i?`wcs-guard-handler:${i}`:"wcs-guard-handler"}\n`,o=e.text+s;let l=!1;const a=e=>{e.effectiveDirective.startsWith("script-src")&&(l=!0)};document.addEventListener("securitypolicyviolation",a);try{if("function"==typeof URL.createObjectURL){const t=new Blob([o],{type:"application/javascript"}),i=URL.createObjectURL(t);try{n=await(import(i))}catch(e){r=e}finally{URL.revokeObjectURL(i)}}if(!n){const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(o)));try{n=await(import(`data:application/javascript;base64,${t}`))}catch(e){await new Promise(e=>setTimeout(e)),Oo(function(e,t,n){return n?`The guard <script> was blocked by Content-Security-Policy. Guard scripts are inline-only and are evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/router, or allow blob: in script-src. See ${bl}`:`loadGuardHandler: failed to import guard script. data: URL error: ${e?.message??String(e)}`+(t?`. Blob URL error: ${t?.message??String(t)}`:"")+`. If this page sets a Content-Security-Policy, see ${bl}`}(e,r,l),{cause:r??e})}}}finally{document.removeEventListener("securitypolicyviolation",a)}return n&&"function"==typeof n.default?n.default:null})(e,t).then(e=>{e?t.guardHandler=e:(console.error(`${Eo.guardHandler}: the <script type="module"> has no default-exported function, so the route's guard redirects every navigation.`),t.notifyGuardHandlerLoadFailed())}).catch(e=>{console.error("loadGuardHandler failed:",e),t.notifyGuardHandlerLoadFailed()})}function vl(e,t){let n=e.get(t.absolutePath);n||(n=[]);for(const e of n)if(!t.testAncestorNode(e)){console.warn(`Duplicate route path detected: '${t.absolutePath}' (defined as '${t.path}')`);break}n.push(t),1===n.length&&e.set(t.absolutePath,n)}async function _l(e,t,n,r){const i=document.createDocumentFragment();let s=null;const o=Array.from(t.childNodes);for(const t of o)if(t.nodeType===Node.ELEMENT_NODE){let o=t,l=t,a=n;const u=l.tagName.toLowerCase();if(u===Eo.route){const t=document.createDocumentFragment();for(const e of Array.from(l.childNodes))t.appendChild(e);const i=document.importNode(l,!0);customElements.upgrade(i),i.appendChild(t);const u=i;u.initialize(e,n),vl(r,u),o=u.placeHolder,l=u,a=u,s=u}else{if(u===Eo.guardHandler){const e=n??s,t=l.querySelector('script[type="module"]');null===e?console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${Eo.guardHandler}> outside a <${Eo.route}> guards nothing: put it inside the route it guards.`):t?(null===n&&console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${Eo.guardHandler}> outside a <${Eo.route}> guards the route before it, "${e.absolutePath}": put it inside that route.`),e.enableGuard(),wl(t,e)):(e.enableGuard(),e.notifyGuardHandlerLoadFailed(),console.error(`[@wcstack/router] [wcs/guard-handler-ignored] The <${Eo.guardHandler}> of route "${e.absolutePath}" has no <script type="module">, so its guard cannot run: every navigation into the route is redirected to "${e.getAttribute("guard")||"/"}".`));continue}if("template"===u){i.appendChild(l);continue}if(u===Eo.layout){const e=document.createDocumentFragment();for(const t of Array.from(l.childNodes))e.appendChild(t);const t=document.importNode(l,!0);customElements.upgrade(t),t.appendChild(e);const n=t,r=yl();r.layout=n,o=r,l=t}}const c=await _l(e,l,a,r);l.replaceChildren(),l.appendChild(c),i.appendChild(o)}else i.appendChild(t);return i}async function $l(e){const t=new Map;return await _l(e,e.template.content,null,t)}function kl(e){return!1!==e.checkVisibility?.()}function Sl(e,t,n,r){const i=function(e,t,n){const r={},i={};let s=!0,o=!1,l=0,a=0;for(;l<e.absoluteSegmentInfos.length;){const t=e.absoluteSegmentInfos[l];if(t.isIndex){l++;continue}if(0===l&&""===t.segmentText&&"static"===t.type){l++;continue}const u=n[a];if(void 0===u){s=!1;break}let c=!1;if("param"===t.type){const e=t.paramType||"any",n=Lo[e].parse(u);void 0!==n&&(t.paramName&&(r[t.paramName]=u,i[t.paramName]=n),c=!0)}else c=null!==t.pattern.exec(u);if(!c){s=!1;break}if("catch-all"===t.type){const e=n.slice(a).join("/");r["*"]=e,i["*"]=e,o=!0;break}l++,a++}let u=!1;return s&&(o||l===e.absoluteSegmentInfos.length&&a===n.length)&&(u=!0),u?{path:t,routes:e.routes,params:r,typedParams:i,lastPath:""}:null}(e,t,n);i&&r.push(i);for(const i of e.routeChildNodes)Sl(i,t,n,r)}function Nl(e,t){const n=e.routeChildNodes,r=[],i=t.split("/"),s=i.filter((e,t)=>!(0===t&&""===e||t===i.length-1&&""===e&&i.length>1));for(const e of n)Sl(e,t,s,r);return r.sort((e,t)=>{const n=e.routes.at(-1),r=t.routes.at(-1),i=n.absoluteSegmentCount-r.absoluteSegmentCount;if(0!==i)return-i;const s=n.absoluteWeight-r.absoluteWeight;return 0!==s?-s:n.childIndex-r.childIndex}),r.length>0?r[0]:null}let Al=null,Cl=null;function El(){const e=xo;return 0===e.length?null:(Al===e&&Cl||(Al=e,Cl=new RegExp(`\\/[^/]+(?:${e.map(e=>e.replace(/\./g,"\\.")).join("|")})$`,"i")),Cl)}function Tl(e){let t=e||"/";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=El();return n&&(t=t.replace(n,"")),""===t&&(t="/"),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}function xl(e,t){let n=e;return""!==t&&(e===t?n="":e.startsWith(t+"/")&&(n=e.slice(t.length))),""===n?"/":n}function Pl(e){let t=e||"";if(!t)return"";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=El();return n&&(t=t.replace(n,"")),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),"/"===t?"":t}function Ol(e){if(null!==e.held)return;const t=hl(e),n=new Set(t),r=[...t,...e.childNodeArray];let i=null;for(const s of e.childNodeArray)n.has(s)?i=s:null===s.parentNode||r.some(e=>e!==s&&e.contains(s))||(t.splice(null===i?0:t.indexOf(i)+1,0,s),n.add(s),i=s);const s=document.createDocumentFragment();!function(e,t){const n=t.map(e=>e.parentNode);for(let r=0;r<t.length;r++)t[r].parentNode===n[r]&&e.appendChild(t[r])}(s,t),s.appendChild(e.endMarker),e.held=s}function Ml(e){e.clearParams(),Ol(e)}function Ll(e,t){const n={},r={};for(const i of e.paramNames)n[i]=t.params[i],r[i]=t.typedParams[i];e.setParams(n,r);for(const t of e.childNodeArray)if(t.nodeType===Node.ELEMENT_NODE){const n=t;n.querySelectorAll("[data-bind]").forEach(t=>{nl(t,e.typedParams)}),n.hasAttribute("data-bind")&&nl(n,e.typedParams),n.querySelectorAll(Eo.layoutOutlet).forEach(t=>{t.assignParams(e.typedParams)}),n.tagName.toLowerCase()===Eo.layoutOutlet&&n.assignParams(e.typedParams)}}const Il=new WeakSet;function jl(e){const t=e.placeHolder;null!==t.parentNode&&(Il.has(e)||null!==e.endMarker.parentNode?(Ol(e),t.after(e.held),e.held=null):t.after(...e.childNodeArray,e.endMarker),Il.add(e))}const Rl=Symbol.for("wcstack.transition-runner");const Hl=new WeakSet,Wl="data-wcs";function Ul(e){return e.hasAttribute(Wl)||null!==e.querySelector(`[${Wl}]`)}function Dl(e,t,n){!Hl.has(e)&&Ul(e)&&(Hl.add(e),function(e){"complete"===document.readyState?e():window.addEventListener("load",e,{once:!0})}(()=>{var r;null!==il()||(r=e,ll().has(r))||console.warn(`[@wcstack/router] ${t} contains ${Wl} bindings that will never be applied. A binding exists only for nodes that were in the document when @wcstack/state built its bindings, and these nodes were not. They will render empty. ${n}`)}))}function Fl(e){return"AbortError"===e?.name}const zl=new WeakMap;function ql(e){for(const t of e.childNodeArray)if(1===t.nodeType){if(t.isConnected){if(al(t,ul))continue}else if(null!==il())continue;Dl(t,`<${t.tagName.toLowerCase()}> inside a route`,'Load @wcstack/state on this page, or render data-driven markup outside <wcs-router> — bind the router\'s `path` into state and gate the markup with <template data-wcs="if: …">. See examples/router-i18n.')}}async function Bl(e,t){try{let n=null;for(const e of t.routes){const r=await e.guardCheck(t);r&&(n=null===n?r:Object.assign({},n,r))}t.data=n,zl.delete(e)}catch(n){if(n instanceof Mo){const r=(zl.get(e)??0)+1;return r>10?(zl.delete(e),console.error(`${Eo.router}: guard redirect loop — stopped after 10 redirects in a row (the last: ${t.path} → ${n.fallbackPath}). The guards of these routes send each other back and forth.`),!1):(zl.set(e,r),e.connectedCallbackPromise.catch(()=>{}).then(()=>e.replace(n.fallbackPath)).catch(e=>{Fl(e)||console.error("Fallback navigation failed:",e)}),!1)}throw n}return!0}async function Gl(e,t,n,r,i=""){const s=xl(n,e.basename);if(e.isSameMatch(s))return e.commitNavigation({params:e.params,typedParams:e.typedParams,routeName:e.routeName,data:e.data,search:i,path:s}),!0;let o=Nl(e,s);o||(e.fallbackRoute?o={routes:[e.fallbackRoute],params:{},typedParams:{},path:s,lastPath:r}:Oo(`${Eo.router} No route matched for path: ${s}`)),o.lastPath=r,o.search=i;const l=t.lastRoutes,a=await async function(e,t,n,r){if(!await Bl(e,t))return!1;r?.();const i=new Set(t.routes),s=new Set(n),o=()=>{for(const e of n)i.has(e)||Ml(e);const e=[];for(const n of t.routes)(e.length>0||!s.has(n)||n.shouldChange(t.params))&&(e.push(n),Ll(n,t));let r=!1;for(const t of e){const e=s.has(t);e&&r||jl(t),r||=e,n.length>0&&!e&&ql(t)}};let l;return 0===n.length?o():l=function(e,t,n){const r=function(e){const t=globalThis[Rl];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}(e);if(null!==r)return r.run(t,{source:e,types:n});t()}("router",o),void 0!==l&&await l,!0}(e,o,l,()=>{e.commitNavigation({params:o.params,typedParams:o.typedParams,routeName:o.routes[o.routes.length-1]?.name??"",data:o.data??null,search:i,path:s},!0)});return!!a&&(e.releasePath(),t.lastRoutes=o.routes,l.length>0&&function(e,t){if("title"===e.announcePolicy){const t=e.a11yRegion;null!==t&&(t.textContent=document.title)}if("heading"===e.focusPolicy){const e=function(e){for(const t of e){if(t.nodeType!==Node.ELEMENT_NODE)continue;const e=t;if(/^H[1-6]$/.test(e.tagName)){if(kl(e))return e}else for(const t of e.querySelectorAll("h1,h2,h3,h4,h5,h6"))if(kl(t))return t}return null}(t.routes[t.routes.length-1].childNodeArray);if(null!==e)e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1"),e.focus();else{const e=document.querySelector("[autofocus]");null!==e?e.focus():document.activeElement instanceof HTMLElement&&document.activeElement.blur()}}}(e,o),!0)}function Kl(){const e=window.navigation;return e?"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener?null:e:null}function Vl(e){let t=e,n="";const r=t.indexOf("#");r>=0&&(n=t.slice(r),t=t.slice(0,r));let i="";const s=t.indexOf("?");return s>=0&&(i=t.slice(s),t=t.slice(0,s)),{pathname:t,search:i,hash:n}}function Jl(e){return"?"===e?"":e}function Ql(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const Xl=new WeakSet;function Yl(e,t,n){if(Xl.has(e))return;Xl.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const Zl=new WeakMap;function ea(e,t,n){const r=function(e,t){let n=Zl.get(e);return void 0===n&&(n=new Map,Zl.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}(e,t);!function(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}(e,t,void 0===n?r:null===n?null:String(n))}function ta(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const na=Object.freeze({});class ra extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"navigateUrl",event:"wcs-router:navigate-url-changed",semantics:"state"},{name:"replaceUrl",event:"wcs-router:replace-url-changed",semantics:"state"},{name:"path",event:"wcs-router:path-changed",semantics:"state"},{name:"params",event:"wcs-router:params-changed",semantics:"state",getter:e=>e.detail.params},{name:"typedParams",event:"wcs-router:params-changed",semantics:"state",getter:e=>e.detail.typedParams},{name:"searchParams",event:"wcs-router:search-changed",semantics:"state"},{name:"routeName",event:"wcs-router:route-name-changed",semantics:"state"},{name:"data",event:"wcs-router:data-changed",semantics:"state"}],inputs:[{name:"basename",attribute:"basename"},{name:"navigateUrl"},{name:"replaceUrl"},{name:"leaveConfirm",attribute:"leave-confirm"}],commands:[{name:"navigate",async:!0},{name:"replace",async:!0}]};_outlet=null;_template=null;_routeChildNodes=[];_basename="";_path="";_initialized=!1;_fallbackRoute=null;_listeningPopState=!1;_listeningNavigate=!1;_navigateUrl=null;_replaceUrl=null;_disconnectedDuringInit=!1;_initializing=!1;_a11yRegion=null;_params=na;_typedParams=na;_searchParams=na;_routeName="";_data=null;_hasCommitted=!1;_pathHeld=!1;_leaveChecked=!1;_leaveConfirmed=!1;_unloadConfirmed=!1;_listeningUnload=!1;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;constructor(){super(),this._connectedCallbackPromise=new Promise((e,t)=>{this._resolveConnectedCallback=e,this._rejectConnectedCallback=t}),this._connectedCallbackPromise.catch(()=>{})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get a11yRegion(){return this._a11yRegion}get focusPolicy(){return"heading"===this.getAttribute("focus")?"heading":null}get announcePolicy(){return"title"===this.getAttribute("announce")?"title":null}_ensureA11yRegion(){if(null!==this._a11yRegion)return;const e=document.createElement("div");e.setAttribute("role","status"),e.style.position="absolute",e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.style.clipPath="inset(50%)",e.style.whiteSpace="nowrap",this.appendChild(e),this._a11yRegion=e}_normalizePathname(e){return Tl(e)}_normalizeBasename(e){return Pl(e)}_joinInternalPath(e,t){const n=this._normalizeBasename(e);let r=t.startsWith("/")?t:"/"+t;return r=this._normalizePathname(r),n?"/"===r?n+"/":n+r:r}_notifyLocationChange(){window.dispatchEvent(new CustomEvent("wcs:navigate"))}_getBasename(){let e=new URL(document.baseURI).pathname||"/";return"/"===e?"":this._normalizeBasename(e)}get basename(){return this._basename}set basename(e){ea(this,"basename",e)}get leaveConfirm(){return this.getAttribute("leave-confirm")||null}set leaveConfirm(e){ea(this,"leave-confirm",e),this._syncBeforeUnload()}_onBeforeUnload=e=>{null===this.leaveConfirm||this._unloadConfirmed||e.preventDefault()};_syncBeforeUnload(){const e=this.isConnected&&null!==this.leaveConfirm&&!ta();e!==this._listeningUnload&&(this._listeningUnload=e,e?window.addEventListener("beforeunload",this._onBeforeUnload):window.removeEventListener("beforeunload",this._onBeforeUnload))}_confirmLeave(e){const t=this.leaveConfirm;return!(null!==t&&this._hasCommitted&&!this._leaveConfirmed&&!this.isSameMatch(xl(this._normalizePathname(e),this._basename)))||(this._leaveConfirmed=window.confirm(t))}_confirmUnload(e){const t=this.leaveConfirm;null!==t&&!1!==e.cancelable&&this._hasCommitted&&!this._unloadConfirmed&&(window.confirm(t)?(this._unloadConfirmed=!0,setTimeout(()=>{this._unloadConfirmed=!1},0)):e.preventDefault?.())}_ownedByAnotherRouter(e){for(const t of document.querySelectorAll(Eo.router))if(t!==this&&t instanceof ra&&t._isOwnPath(e))return!0;return!1}_getOutlet(){const e=this.nextElementSibling;if(e&&e.matches(Eo.outlet))return e;!function(e){const t=e.getRootNode();t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE||fl(t)}(this);const t=document.createElement(Eo.outlet);return this.parentNode?this.parentNode.insertBefore(t,this.nextSibling):document.body.appendChild(t),t}_getTemplate(){return this.querySelector("template")}get outlet(){return this._outlet||Oo(`${Eo.router} has no outlet.`),this._outlet}get template(){return this._template||Oo(`${Eo.router} has no template.`),this._template}get routeChildNodes(){return this._routeChildNodes}get path(){return this._path}set path(e){const t=this._path!==e;this._path=e,t&&this.dispatchEvent(new CustomEvent("wcs-router:path-changed",{detail:e,bubbles:!0}))}get params(){return this._params}get typedParams(){return this._typedParams}get searchParams(){return this._searchParams}get routeName(){return this._routeName}get data(){return this._data}isSameMatch(e){return!!this._hasCommitted&&this._path===e}commitNavigation(e,t=!1){const n=Object.freeze({...e.params}),r=Object.freeze({...e.typedParams}),i=Io(e.search),s=e.data??null,o=this._data!==s,l=!jo(this._params,n),a=this._routeName!==e.routeName,u=!jo(this._searchParams,i),c=this._path!==e.path;o&&(this._data=s),l&&(this._params=n,this._typedParams=r),a&&(this._routeName=e.routeName),u&&(this._searchParams=i),this._path=e.path,this._hasCommitted=!0,this._leaveConfirmed=!1,o&&this.dispatchEvent(new CustomEvent("wcs-router:data-changed",{detail:this._data,bubbles:!0})),l&&this.dispatchEvent(new CustomEvent("wcs-router:params-changed",{detail:{params:this._params,typedParams:this._typedParams},bubbles:!0})),a&&this.dispatchEvent(new CustomEvent("wcs-router:route-name-changed",{detail:this._routeName,bubbles:!0})),u&&this.dispatchEvent(new CustomEvent("wcs-router:search-changed",{detail:this._searchParams,bubbles:!0})),this._pathHeld=c&&t,c&&!t&&this._firePathChanged()}releasePath(){this._pathHeld&&(this._pathHeld=!1,this._firePathChanged())}_firePathChanged(){this.dispatchEvent(new CustomEvent("wcs-router:path-changed",{detail:this._path,bubbles:!0}))}get fallbackRoute(){return this._fallbackRoute}set fallbackRoute(e){this._fallbackRoute=e}get navigateUrl(){return this._navigateUrl}set navigateUrl(e){null!=e&&""!==e&&this._navigateUrl!==e&&(this._navigateUrl=e,this.navigate(e).catch(e=>{Fl(e)||console.error(`${Eo.router} navigate failed:`,e)}).finally(()=>{this._navigateUrl=null,this.dispatchEvent(new CustomEvent("wcs-router:navigate-url-changed",{detail:null,bubbles:!0}))}))}get replaceUrl(){return this._replaceUrl}set replaceUrl(e){null!=e&&""!==e&&this._replaceUrl!==e&&(this._replaceUrl=e,this.replace(e).catch(e=>{Fl(e)||console.error(`${Eo.router} replace failed:`,e)}).finally(()=>{this._replaceUrl=null,this.dispatchEvent(new CustomEvent("wcs-router:replace-url-changed",{detail:null,bubbles:!0}))}))}async navigate(e){await this._performNavigation(e,!1)}async replace(e){await this._performNavigation(e,!0)}async _performNavigation(e,t){const n=Vl(e),r=""!==n.pathname||""===n.search&&""===n.hash?this._joinInternalPath(this._basename,n.pathname):window.location.pathname,i=r+Jl(n.search)+n.hash;if(null!==this.leaveConfirm&&(await Promise.resolve(),!this._confirmLeave(r)))return;const s=Kl();if(s?.navigate){let e;this._leaveChecked=!0;try{e=t?s.navigate(i,{history:"replace"}):s.navigate(i)}finally{this._leaveChecked=!1}await(e?.finished)}else{t?history.replaceState(null,"",i):history.pushState(null,"",i);const e=this._normalizePathname(r),s=this.isSameMatch(xl(e,this._basename));await Gl(this,this.outlet,e,this._path,Jl(n.search))&&!s&&window.scrollTo(0,0),this._notifyLocationChange()}}_isOwnPath(e){return""===this._basename||e===this._basename||e.startsWith(this._basename+"/")}_onNavigateFunc(e){if(e.defaultPrevented||e.hashChange||null!==e.downloadRequest||"reload"===e.navigationType)return;const t=new URL(e.destination.url),n=this._normalizePathname(t.pathname);if(!e.canIntercept||!this._isOwnPath(n))return void(e.canIntercept&&this._ownedByAnotherRouter(n)||this._confirmUnload(e));if(!this._leaveChecked&&!1!==e.cancelable&&!this._confirmLeave(n))return void e.preventDefault?.();const r=this.isSameMatch(xl(n,this._basename)),i=r&&("push"===e.navigationType||"replace"===e.navigationType),s=t.search,o=this;e.intercept({handler:async()=>{try{await Gl(o,o.outlet,n,o.path,s)}catch(e){throw console.error(`${Eo.router} applyRoute failed:`,e),e}},scroll:i?"manual":"after-transition",focusReset:r||null!==o.focusPolicy?"manual":"after-transition"})}_onNavigate=this._onNavigateFunc.bind(this);_onPopState=async()=>{const e=this._normalizePathname(window.location.pathname);this._isOwnPath(e)&&(await Gl(this,this.outlet,e,this._path,window.location.search||""),this._notifyLocationChange())};async _initialize(){this._initializing=!0;try{const e=ta();this._basename=this._normalizeBasename(this.getAttribute("basename")||this._getBasename()||"");const t=null!==document.querySelector("base[href]"),n=new URL(window.location.href);""!==this._basename||t||"/"===n.pathname||Oo(`${Eo.router} basename is empty, but current path is not "/".`),e||""===this._basename||t||this.getAttribute("basename")||console.warn(`[@wcstack/router] [wcs/base-href-missing] The basename "${this._basename}" was taken from this page's URL: the page has no <base href> and <${Eo.router}> no basename, so routes and links resolve under it, and a deep link or a reload away from the app's root shows the wrong route. Add <base href="/"> (or the app's folder) to <head>.`),this._outlet=this._getOutlet(),this._outlet.routesNode=this,this._template=this._getTemplate(),this._template||Oo(`${Eo.router} should have a <template> child element.`);const r=e?this._template.content.cloneNode(!0):null,i=await $l(this),s=!e&&this._outlet.hasAttribute(Wo);if(s||this._outlet.rootNode.appendChild(i),null!==r){const e=this._template.content;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(r)}0===this.routeChildNodes.length&&Oo(`${Eo.router} has no route definitions.`),e||this._ensureA11yRegion();const o=this._normalizePathname(window.location.pathname);if(e)return await this._renderForSsr(o),void(this._initialized=!0);if(s){if(await this._hydrateFromSsr(o))return this._notifyLocationChange(),void(this._initialized=!0);this._outlet.removeAttribute(Wo);const e=this._outlet.rootNode;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(i)}await Gl(this,this.outlet,o,this._path,window.location.search||""),(s||null!==il())&&this._offerInitialContentToBinder(),this._notifyLocationChange(),this._initialized=!0}finally{this._initializing=!1}}async _hydrateFromSsr(e){const t=this.outlet.rootNode,n=new Map;let r=!1;if(this._forEachRoute(e=>{n.has(e.absolutePath)?r=!0:n.set(e.absolutePath,e)}),r)return!1;if(null!==t.querySelector(Eo.layoutOutlet))return!1;const i=new Map,s=new Map,o=new Map,l=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);let a=0;for(;l.nextNode();){const e=l.currentNode,t=e.data;if(a++,t.startsWith(Do)){const r=t.slice(15);if(i.has(r)||!n.has(r))return!1;i.set(r,e)}else if(t.startsWith(Fo)){const r=t.slice(18);if(s.has(r)||!n.has(r))return!1;s.set(r,{comment:e,index:a})}else if(t.startsWith(zo)){const r=t.slice(16);if(o.has(r)||!n.has(r))return!1;o.set(r,{comment:e,index:a})}}if(s.size!==o.size)return!1;const u=[];for(const[e,t]of s){const n=o.get(e);if(!n)return!1;if(n.comment.parentNode!==t.comment.parentNode)return!1;if(n.index<=t.index)return!1;u.push({start:t.index,end:n.index})}for(const e of u)for(const t of u)if(e.start<t.start&&t.start<e.end&&e.end<t.end)return!1;const c=xl(e,this._basename);let h=Nl(this,c);if(!h){if(null===this._fallbackRoute)return!1;h={routes:[this._fallbackRoute],params:{},typedParams:{},path:c,lastPath:this._path}}if(h.lastPath=this._path,h.routes.length!==s.size)return!1;for(const e of h.routes)if(!s.has(e.absolutePath))return!1;const d=new Set;for(const e of this.routeChildNodes)d.add(e.absolutePath);for(const e of h.routes)for(const t of e.routeChildNodes)d.add(t.absolutePath);if(i.size!==d.size)return!1;for(const e of d)if(!i.has(e))return!1;for(const[e,t]of i){const r=n.get(e);t.parentNode.replaceChild(r.placeHolder,t)}for(const e of h.routes){const t=s.get(e.absolutePath).comment,n=o.get(e.absolutePath).comment,r=[],i=new Set;let l=t.nextSibling;for(;null!==l&&l!==n;){if(l.nodeType===Node.COMMENT_NODE){const e=l.data;if(e.startsWith(Fo)){const t=e.slice(18);l=o.get(t).comment.nextSibling;continue}}if(i.has(l))l=l.nextSibling;else{if(l.nodeType===Node.ELEMENT_NODE&&l.tagName.toLowerCase()===Eo.link){const e=l.anchorElement;null!==e&&i.add(e)}r.push(l),l=l.nextSibling}}e.adoptChildNodes(r,n)}for(const{comment:e}of s.values())e.remove();this.outlet.removeAttribute(Wo);for(const e of h.routes)Ll(e,h);return this.outlet.lastRoutes=h.routes,!await Bl(this,h)||(this.commitNavigation({params:h.params,typedParams:h.typedParams,routeName:h.routes[h.routes.length-1].name,data:h.data??null,search:window.location.search||"",path:c}),!0)}async _renderForSsr(e){const t=xl(e,this._basename),n=Nl(this,t),r=n?.routes??(null!==this._fallbackRoute?[this._fallbackRoute]:[]);if(0===r.length&&Oo(`${Eo.router} No route matched for path: ${t}`),!r.some(e=>e.hasGuard)){await Gl(this,this.outlet,e,this._path,window.location.search||""),this._offerInitialContentToBinder(),this._forEachRoute(e=>{e.placeHolder.data=`${Do}${e.absolutePath}`}),this.outlet.setAttribute(Wo,"");for(const e of this.outlet.lastRoutes)e.placeHolder.after(document.createComment(`${Fo}${e.absolutePath}`))}}_offerInitialContentToBinder(){for(const e of this.outlet.lastRoutes)for(const t of e.childNodeArray)t.nodeType===Node.ELEMENT_NODE&&t.isConnected&&al(t,ul)}_forEachRoute(e,t=this){for(const n of t.routeChildNodes)e(n),this._forEachRoute(e,n)}async connectedCallback(){if(function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&Yl(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!Ql(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this._syncBeforeUnload(),ta()){try{await Promise.resolve(),this.hasAttribute("enable-ssr")&&!this._initialized&&await this._initialize()}catch(e){throw this._rejectConnectedCallback?.(e),e}return void this._resolveConnectedCallback?.()}if(!this._initialized){this._disconnectedDuringInit=!1;try{null===this._getTemplate()&&await Promise.resolve(),await this._initialize()}catch(e){throw this._rejectConnectedCallback?.(e),e}if(this._disconnectedDuringInit)return void this._resolveConnectedCallback?.()}this._initialized&&this._ensureA11yRegion();const e=Kl();e&&!this._listeningNavigate&&(e.addEventListener("navigate",this._onNavigate),this._listeningNavigate=!0),e||this._listeningPopState||(window.addEventListener("popstate",this._onPopState),this._listeningPopState=!0),this._resolveConnectedCallback?.()}disconnectedCallback(){this._initializing&&(this._disconnectedDuringInit=!0),this._listeningNavigate&&(Kl()?.removeEventListener("navigate",this._onNavigate),this._listeningNavigate=!1),this._listeningPopState&&(window.removeEventListener("popstate",this._onPopState),this._listeningPopState=!1),this._syncBeforeUnload(),null!==this._a11yRegion&&(this._a11yRegion.remove(),this._a11yRegion=null)}}const ia=["title","rel","target","download","hreflang","lang","dir"];class sa extends HTMLElement{static get observedAttributes(){return["to","match",...ia]}_childNodeArray=[];_uuid=Po();_path="";_router=null;_anchorElement=null;_initialized=!1;_onClick;constructor(){super()}get uuid(){return this._uuid}get router(){if(this._router)return this._router;const e=this.closest(Eo.router);if(e)return this._router=e;const t=this.getRootNode(),n=t.querySelector?.(Eo.router);if(n)return this._router=n;Oo(`${Eo.link} is not connected to a router.`)}_initialize(){ta()||(this.style.display="none"),this._childNodeArray=Array.from(this.childNodes),this._path=this.getAttribute("to")||"",this._initialized=!0}_normalizePathname(e){return Tl(e)}_joinInternalPath(e,t){const n=Pl(e),r=t.startsWith("/")?t:"/"+t,i=this._normalizePathname(r);return n?"/"===i?n+"/":n+i:i}_isInternalTarget(e){return e.startsWith("/")||e.startsWith("?")}_setAnchorHref(e,t){if(""!==t)if(this._isInternalTarget(t)){const{pathname:n,search:r,hash:i}=Vl(t),s=""===n?window.location.pathname:this._joinInternalPath(this.router.basename,n);e.href=s+Jl(r)+i}else try{e.href=new URL(t).toString()}catch{Oo(`[${Eo.link}] Invalid URL in 'to' attribute: ${t}`)}else e.removeAttribute("href")}connectedCallback(){ta()?queueMicrotask(()=>{if(this.isConnected)try{this._connect()}catch(e){console.error(e)}}):this._connect()}_findSsrAnchor(){const e=this.nextElementSibling;return null!==e&&"A"===e.tagName&&e.hasAttribute(Uo)?e:null}_connect(){this._initialized||this._initialize();const e=this.parentNode;if(!e)return;const t=this._findSsrAnchor();let n;if(null!==t)n=t,n.removeAttribute(Uo),this._childNodeArray=Array.from(n.childNodes),this._setAnchorHref(n,this._path);else{const t=this.nextSibling;n=document.createElement("a"),this._setAnchorHref(n,this._path);for(const e of Array.from(this.attributes))(e.name.startsWith("aria-")||ia.includes(e.name))&&n.setAttribute(e.name,e.value);for(const e of this._childNodeArray)n.appendChild(e);t?e.insertBefore(n,t):e.appendChild(n)}if(this._anchorElement=n,ta())return this._updateActiveState(),void n.setAttribute(Uo,"");Kl()?.addEventListener("currententrychange",this._updateActiveState),window.addEventListener("wcs:navigate",this._updateActiveState),window.addEventListener("popstate",this._updateActiveState),""!==this._path&&!this._isInternalTarget(this._path)||Kl()?.navigate||(this._onClick=async e=>{e.defaultPrevented||0===e.button&&(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||this._isInternalTarget(this._path)&&(e.preventDefault(),await this.router.navigate(this._path),this._updateActiveState()))},n.addEventListener("click",this._onClick)),this._updateActiveState()}disconnectedCallback(){Kl()?.removeEventListener("currententrychange",this._updateActiveState),window.removeEventListener("wcs:navigate",this._updateActiveState),window.removeEventListener("popstate",this._updateActiveState);const e=this._anchorElement;e&&(this._onClick&&(e.removeEventListener("click",this._onClick),this._onClick=void 0),e.remove(),this._anchorElement=null);for(const t of this._childNodeArray)e&&t.parentNode===e&&e.removeChild(t);this._router=null}attributeChangedCallback(e,t,n){if("match"!==e||t===n){if("to"===e&&t!==n)this._path=n||"",this._anchorElement&&(this._setAnchorHref(this._anchorElement,this._path),this._updateActiveState());else if(ia.includes(e)){const t=this._anchorElement;t&&(null===n?t.removeAttribute(e):t.setAttribute(e,n))}}else this._updateActiveState()}_updateActiveState=()=>{this._path.startsWith("?")&&this._anchorElement&&this._setAnchorHref(this._anchorElement,this._path);const e=this._normalizePathname(new URL(window.location.href).pathname),{pathname:t}=Vl(this._path),n=this._normalizePathname(this._isInternalTarget(this._path)?""===t?window.location.pathname:this._joinInternalPath(this.router.basename,t):t),r=""!==this._path&&e===n,i=!r&&""!==this._path&&"prefix"===this.getAttribute("match")&&e.startsWith(n+"/");this._anchorElement&&(r||i?(this._anchorElement.classList.add("active"),this._anchorElement.setAttribute("aria-current",r?"page":"true")):(this._anchorElement.classList.remove("active"),this._anchorElement.removeAttribute("aria-current")))};get anchorElement(){return this._anchorElement}}const oa=[],la=new Map;let aa=!1;const ua=new WeakMap,ca=new WeakMap;class ha extends HTMLElement{_initialized=!1;_childElementArray=[];constructor(){super()}_initialize(){if(!this._initialized&&(this._initialized=!0,this._childElementArray=Array.from(this.children),!ta())){this.style.display="none";for(const e of this._childElementArray)this.removeChild(e)}}connectedCallback(){this._initialize(),aa||(this._captureInitialHead(),aa=!0),oa.push(this),this._reapplyHead()}disconnectedCallback(){const e=oa.indexOf(this);-1!==e&&oa.splice(e,1),this._reapplyHead()}get childElementArray(){return this._initialized||Oo("Head component is not initialized yet."),this._childElementArray}_cloneOf(e){if(!Ul(e))return e.cloneNode(!0);let t=ca.get(e);return void 0===t&&(t=e.cloneNode(!0),ca.set(e,t)),t}_getKey(e){const t=ua.get(e);if(void 0!==t)return t;const n=this._computeKey(e);return ua.set(e,n),n}_computeKey(e){const t=e.tagName.toLowerCase();if("title"===t)return"title";if("meta"===t)return`meta:${e.getAttribute("name")||""}:${e.getAttribute("property")||""}:${e.getAttribute("http-equiv")||""}:${e.hasAttribute("charset")?"charset":""}:${e.getAttribute("media")||""}`;if("link"===t)return`link:${e.getAttribute("rel")||""}:${e.getAttribute("href")||""}:${e.getAttribute("media")||""}:${e.getAttribute("hreflang")||""}`;if("base"===t)return"base";if("script"===t){const t=e.getAttribute("src")||"",n=e.getAttribute("id")||"",r=e.getAttribute("type")||"";return t||n?`script:${t}:${n}:${r}`:`script::${r}:${e.outerHTML.slice(0,100)}`}if("style"===t){const t=e.getAttribute("id")||"",n=e.getAttribute("media")||"";return t?`style:${t}:${n}`:`style::${n}:${e.outerHTML.slice(0,100)}`}return`${t}:${e.outerHTML.slice(0,100)}`}_buildHeadElementMap(){const e=new Map;for(const t of Array.from(document.head.children)){const n=this._getKey(t);e.has(n)||e.set(n,t)}return e}_captureInitialHead(){const e=document.head;for(const t of Array.from(e.children)){const e=this._getKey(t);la.has(e)||la.set(e,t.cloneNode(!0))}}_reapplyHead(){const e=new Set;for(const t of oa)for(const n of t._childElementArray)e.add(this._getKey(n));for(const t of la.keys())e.add(t);const t=this._buildHeadElementMap();for(const n of t.keys())e.add(n);for(const n of e){let e=null;for(let t=oa.length-1;t>=0;t--){const r=oa[t];for(const t of r._childElementArray)if(this._getKey(t)===n){e=this._cloneOf(t);break}if(e)break}!e&&la.has(n)&&(e=la.get(n).cloneNode(!0));const r=t.get(n)??null;null!==e&&r===e||e&&r?.isEqualNode(e)&&!Ul(e)||(e?(r?r.replaceWith(e):document.head.appendChild(e),t.set(n,e),al(e)||Dl(e,`<${e.tagName.toLowerCase()}> inside <${Eo.head}>`,`<${Eo.head}> reflects its children into <head> with cloneNode, so the clone is not the node that was bound. Load @wcstack/state on this page, or write the value statically here.`)):(r?.remove(),t.delete(n)))}}}await void function(e=customElements){e.get(Eo.layout)||e.define(Eo.layout,Yo),e.get(Eo.layoutOutlet)||e.define(Eo.layoutOutlet,gl),e.get(Eo.outlet)||e.define(Eo.outlet,Zo),e.get(Eo.route)||e.define(Eo.route,qo),e.get(Eo.router)||e.define(Eo.router,ra),e.get(Eo.link)||e.define(Eo.link,sa),e.get(Eo.head)||e.define(Eo.head,ha)}(void 0);const da="data-fetchtarget",fa={fetch:"wcs-fetch",fetchHeader:"wcs-fetch-header",fetchBody:"wcs-fetch-body",infiniteScroll:"wcs-infinite-scroll"};let pa=class{laneKey;policy;_ownerGeneration=0;_latestEpoch=0;_nextOperationId=1;_activeOperationId=void 0;_activeOperationIds=new Set;_queue=[];_inFlightCount=0;_terminal=new Map;_claimedOutcome=new Map;_controllers=new Map;_attempts=new Map;_withSignal;_trace;constructor(e,t,n={}){this.laneKey=e,this.policy=t,this._withSignal=n.withSignal??!1,this._trace=n.trace}get ownerGeneration(){return this._ownerGeneration}get inFlightCount(){return this._inFlightCount}get latestEpoch(){return this._latestEpoch}get activeOperationId(){return this._activeOperationId}begin(){let e;switch(this.policy){case"latest":e=++this._latestEpoch,void 0!==this._activeOperationId&&this._abortController(this._activeOperationId);break;case"exhaust":if(void 0!==this._activeOperationId)return null}const t=this._nextOperationId++,n={operationId:t,ownerGeneration:this._ownerGeneration,laneKey:this.laneKey,policy:this.policy,supersedeEpoch:e};switch(this.policy){case"latest":case"exhaust":this._activeOperationId=t;break;case"queue":this._queue.push(n),void 0===this._activeOperationId&&(this._activeOperationId=t);break;case"overlap":this._activeOperationIds.add(t)}this._inFlightCount+=1,this._attempts.set(t,1);const r=this._makeAttempt(t,1);return void 0!==this._trace&&this._trace({type:"io:operation-started",operationId:t,laneKey:this.laneKey,policy:this.policy}),{ticket:n,attempt:r}}retry(e){if(e.ownerGeneration!==this._ownerGeneration)return null;if(this._terminal.has(e.operationId))return null;const t=this._attempts.get(e.operationId);if(void 0===t)return null;const n=t+1;this._attempts.set(e.operationId,n),this._releaseController(e.operationId);const r=this._makeAttempt(e.operationId,n);return void 0!==this._trace&&this._trace({type:"io:operation-retried",operationId:e.operationId,laneKey:this.laneKey,attempt:n}),r}canCommit(e){if(e.ownerGeneration!==this._ownerGeneration)return!1;const t=this._terminal.get(e.operationId);return(void 0===t||"committing"===t)&&this._isEligible(e)}claimTerminal(e,t){return e.ownerGeneration===this._ownerGeneration&&!this._terminal.has(e.operationId)&&!!this._isEligible(e)&&(this._terminal.set(e.operationId,"committing"),this._claimedOutcome.set(e.operationId,t),!0)}claimedOutcome(e){return this._claimedOutcome.get(e.operationId)}finalize(e){const t=e.operationId,n=this._terminal.get(t);if(void 0!==n&&"committing"!==n)return;let r;r="committing"===n?this._claimedOutcome.get(t)??"stale":"stale",this._terminal.set(t,r),this._claimedOutcome.delete(t),this._releaseController(t),this._attempts.delete(t),this._inFlightCount>0&&(this._inFlightCount-=1),this._advanceBookkeeping(t),void 0!==this._trace&&("stale"===r?this._trace({type:"io:stale-dropped",operationId:t,laneKey:this.laneKey}):this._trace({type:"io:operation-settled",operationId:t,laneKey:this.laneKey,outcome:r}))}signalOf(e){return this._controllers.get(e.operationId)?.signal}abort(e){this._abortController(e.operationId)}abortActive(){void 0!==this._activeOperationId&&this._abortController(this._activeOperationId);for(const e of this._activeOperationIds)this._abortController(e)}disposeOwner(){this._ownerGeneration+=1;for(const e of Array.from(this._controllers.keys()))this._abortController(e),this._releaseController(e);for(const e of Array.from(this._attempts.keys()))this._terminal.has(e)||this._terminal.set(e,"stale"),this._claimedOutcome.delete(e),this._attempts.delete(e),void 0!==this._trace&&this._trace({type:"io:stale-dropped",operationId:e,laneKey:this.laneKey});this._activeOperationId=void 0,this._activeOperationIds.clear(),this._queue.length=0,this._inFlightCount=0}_makeAttempt(e,t){let n;if(this._withSignal&&"function"==typeof AbortController){const t=new AbortController;this._controllers.set(e,t),n=t.signal}return{operationId:e,attempt:t,signal:n}}_isEligible(e){switch(this.policy){case"latest":return e.supersedeEpoch===this._latestEpoch;case"queue":case"exhaust":return this._activeOperationId===e.operationId;case"overlap":return this._activeOperationIds.has(e.operationId)}}_advanceBookkeeping(e){switch(this.policy){case"latest":case"exhaust":this._activeOperationId===e&&(this._activeOperationId=void 0);break;case"queue":{const t=this._queue.filter(t=>t.operationId!==e);this._queue.length=0,this._queue.push(...t),this._activeOperationId=this._queue.length>0?this._queue[0].operationId:void 0;break}case"overlap":this._activeOperationIds.delete(e)}}_abortController(e){const t=this._controllers.get(e);void 0===t||t.signal.aborted||t.abort()}_releaseController(e){this._controllers.delete(e)}};function ma(e,t){return t.every(t=>"available"===e.availability.get(t))}const ga=new Map([["web.fetch",{probe:()=>"function"==typeof globalThis.fetch,compatKey:"api.fetch"}],["web.abort-controller",{probe:()=>"function"==typeof globalThis.AbortController,compatKey:"api.AbortController"}]]),ya=new Set(["GET","HEAD","OPTIONS"]);let ba=class e extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.value},{name:"loading",event:"wcs-fetch:loading-changed",semantics:"state"},{name:"error",event:"wcs-fetch:error",semantics:"state"},{name:"status",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.status},{name:"objectURL",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.objectURL},{name:"errorInfo",event:"wcs-fetch:error-info-changed",semantics:"state"}],inputs:[{name:"url"},{name:"method"}],commands:[{name:"fetch",async:!0},{name:"abort"}]};_target;_value=null;_loading=!1;_error=null;_status=0;_objectURL=null;_promise=Promise.resolve(null);_lane=new pa("fetch","latest",{withSignal:!0});_inFlight=null;_ready=Promise.resolve();_errorInfo=null;static REQUIRED_CAPABILITIES=["web.fetch"];static OPTIONAL_CAPABILITIES=["web.abort-controller"];constructor(e){super(),this._target=e??this}get ready(){return this._ready}observe(){return this._ready}dispose(){this._lane.disposeOwner(),null!==this._objectURL&&(this._revokeObjectURL(this._objectURL),this._objectURL=null)}get value(){return this._value}get loading(){return this._loading}get error(){return this._error}get status(){return this._status}get objectURL(){return this._objectURL}get promise(){return this._promise}get errorInfo(){return this._errorInfo}get supported(){return ma(this.platformAssessment,e.REQUIRED_CAPABILITIES)}get platformAssessment(){return function(e,t){const n=new Map,r=t=>{const n=e.get(t);return void 0===n?"unknown":n.probe()?"available":"missing"};let i=!0;for(const e of t.required){const t=r(e);n.set(e,t),"available"!==t&&(i=!1)}let s=!0;for(const e of t.optional??[]){const t=r(e);n.set(e,t),"available"!==t&&(s=!1)}const o=i?s?"ready":"degraded":"idle",l=[...t.required,...t.optional??[]],a=l.some(t=>!0===e.get(t)?.requiresSecureContext),u=l.some(t=>!0===e.get(t)?.requiresUserActivation),c=a?!0===globalThis.isSecureContext?"satisfied":"required":"not-applicable",h=u?"required":"not-applicable";return{availability:n,permission:t.permission??"not-applicable",readiness:o,activity:t.activity??"inactive",preconditions:{secureContext:c,userActivation:h},epoch:t.epoch??0,lastError:t.lastError}}(ga,{required:e.REQUIRED_CAPABILITIES,optional:e.OPTIONAL_CAPABILITIES,activity:this._loading?"active":"inactive",lastError:this._errorInfo??void 0})}_setErrorInfo(e,t,n,r,i){this._commitErrorInfo({code:e,phase:t,recoverable:n,message:r,...void 0===i?{}:{capabilityId:i}})}_commitErrorInfo(e){this._errorInfo!==e&&(this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:error-info-changed",{detail:e,bubbles:!0})))}_setLoading(e){this._loading=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:loading-changed",{detail:e,bubbles:!0}))}_setError(e){this._error!==e&&(this._error=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:error",{detail:e,bubbles:!0})))}_setResponse(e,t,n=null){null!==this._objectURL&&this._revokeObjectURL(this._objectURL),this._objectURL=n,this._value=e,this._status=t,this._target.dispatchEvent(new CustomEvent("wcs-fetch:response",{detail:{value:e,status:t,objectURL:n},bubbles:!0}))}_createObjectURL(e){return"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL?URL.createObjectURL(e):null}_revokeObjectURL(e){"undefined"!=typeof URL&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(e)}abort(){this._lane.abortActive()}_commitStep(e,t){this._lane.canCommit(e)&&t()}async fetch(t,n={}){if(!t)return this._setErrorInfo("invalid-argument","start",!1,"url attribute is required."),this._setError({message:"url attribute is required."}),null;const r=this.platformAssessment;if(!ma(r,e.REQUIRED_CAPABILITIES)){const t=e.REQUIRED_CAPABILITIES.find(e=>"available"!==r.availability.get(e));return this._setErrorInfo("capability-missing","start",!1,`Required capability "${t}" is unavailable.`,t),this._setError({message:`Required capability "${t}" is unavailable.`}),null}const i=this._doFetch(t,n);return this._promise=i,i}async _doFetch(e,t){const n=this._inFlight;null===n||ya.has(n.method)||console.warn(`[@wcstack/fetch] [wcs/fetch-request-superseded] A ${n.method} request to "${n.url}" was still in flight when another request started on the same element: it was aborted and its response dropped (the server may have applied it). Give each change its own <wcs-fetch>, or wait for loading to end before starting the next request.`);const r=this._lane.begin(),{ticket:i,attempt:s}=r,o=s.signal,l={method:String(t.method??"GET").toUpperCase(),url:e};this._inFlight=l,this._commitStep(i,()=>this._setLoading(!0)),this._commitStep(i,()=>{this._commitErrorInfo(null),this._setError(null)});const{method:a="GET",body:u=null,contentType:c=null,forceText:h=!1,responseType:d="auto",timeout:f=0}=t;let p=null;f>0&&(p=setTimeout(()=>{if(!this._lane.claimTerminal(i,"timeout"))return;const e=`Request timed out after ${f}ms.`;this._commitStep(i,()=>{this._setErrorInfo("timeout","execute",!0,e),this._setError({name:"TimeoutError",message:e})}),this._commitStep(i,()=>this._setResponse(null,0)),this._commitStep(i,()=>this._setLoading(!1)),this._lane.abort(i),this._lane.finalize(i)},f));const m={...t.headers??{}};try{c&&!m["Content-Type"]&&(m["Content-Type"]=c);const t={method:a,headers:m,signal:o};"GET"!==a&&"HEAD"!==a&&null!==u&&(t.body=u);const n=await globalThis.fetch(e,t);let r=null;if("HEAD"===a);else if(n.ok)if(h)r=await n.text();else if("blob"===d)r=await n.blob();else if("arrayBuffer"===d)r=await n.arrayBuffer();else if("text"===d)r=await n.text();else if("json"===d)r=await n.json();else{const e=n.headers.get("Content-Type")||"";r=e.includes("application/json")?await n.json():await n.text()}if(!n.ok){const e=await n.text().catch(()=>""),t={status:n.status,statusText:n.statusText,body:e};return this._lane.claimTerminal(i,"error")?(this._commitStep(i,()=>{this._setErrorInfo("http-error","execute",!0,`HTTP ${n.status} ${n.statusText}`),this._setError(t)}),this._commitStep(i,()=>this._setResponse(null,n.status)),this._commitStep(i,()=>this._setLoading(!1)),null):null}if(!this._lane.claimTerminal(i,"success"))return null;const s=r instanceof Blob?this._createObjectURL(r):null;return this._commitStep(i,()=>this._setResponse(r,n.status,s)),this._commitStep(i,()=>this._setLoading(!1)),this._value}catch(e){return e&&"AbortError"===e.name?(this._lane.claimTerminal(i,"aborted")&&this._commitStep(i,()=>this._setLoading(!1)),null):this._lane.claimTerminal(i,"error")?(this._commitStep(i,()=>{const t=String(e?.message??"Network request failed.");this._setErrorInfo("network","execute",!0,t),this._setError(e??{message:t})}),this._commitStep(i,()=>this._setResponse(null,0)),this._commitStep(i,()=>this._setLoading(!1)),null):null}finally{this._inFlight===l&&(this._inFlight=null),null!==p&&clearTimeout(p),this._lane.finalize(i)}}},wa=!1;function va(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${da}]`);if(!n)return;const r=n.getAttribute(da);if(!r)return;const i=customElements.get(fa.fetch),s=document.getElementById(r);if(!(i&&s instanceof i))return;const o=s;o.url&&(e.preventDefault(),o.fetch())}function _a(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const $a=new WeakSet;function ka(e,t,n){if($a.has(e))return;$a.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const Sa=new WeakMap;function Na(e,t){let n=Sa.get(e);return void 0===n&&(n=new Map,Sa.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function Aa(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Ca(e,t,n){const r=Na(e,t);Aa(e,t,void 0===n?r:null===n?null:String(n))}const Ea=Symbol.for("wcstack.trustedTypes.policy");function Ta(){const e=globalThis[Ea];return null===e||"object"!=typeof e?null:e}let xa,Pa=!1;class Oa extends HTMLElement{static hasConnectedCallbackPromise=!0;static hasPendingPromise=!0;static wcBindable={...ba.wcBindable,properties:[...ba.wcBindable.properties,{name:"trigger",event:"wcs-fetch:trigger-changed",semantics:"state"}],inputs:[{name:"url"},{name:"method"},{name:"target"},{name:"manual"},{name:"body"},{name:"responseType"},{name:"trigger"}]};static get observedAttributes(){return["url"]}_core;_body=null;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_autoPending=!1;_connectResolve=null;_lastFetchedUrl=null;_toldTriggerWithoutUrl=!1;_toldUndefinedHelper=!1;_internals=null;constructor(){super(),this._internals=this._initInternals(),this._wireStates({"wcs-fetch:loading-changed":e=>({loading:!0===e}),"wcs-fetch:error":e=>({error:null!=e})}),this._core=new ba(this)}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[n,r]of Object.entries(e))this.addEventListener(n,e=>{const n=this.hasAttribute("debug-states");for(const[i,s]of Object.entries(r(e.detail))){try{s?t.add(i):t.delete(i)}catch{}n&&this.toggleAttribute(`data-wcs-state-${i}`,s)}})}get url(){return this.getAttribute("url")||""}set url(e){Ca(this,"url",e)}get method(){return(this.getAttribute("method")||"GET").toUpperCase()}set method(e){Ca(this,"method",e)}get target(){return this.getAttribute("target")}set target(e){Ca(this,"target",e)}get responseType(){return this.getAttribute("response-type")||"auto"}set responseType(e){Ca(this,"response-type",e)}get value(){return this._core.value}get loading(){return this._core.loading}get error(){return this._core.error}get status(){return this._core.status}get objectURL(){return this._core.objectURL}get errorInfo(){return this._core.errorInfo}get promise(){return this._core.promise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get pendingPromise(){return this._autoPending&&!this.manual&&this.url?Promise.resolve().then(()=>this.pendingPromise??void 0):this.loading?this._core.promise.then(()=>{}):null}get manual(){return this.hasAttribute("manual")}set manual(e){!function(e,t,n){const r=Na(e,t);Aa(e,t,void 0===n?r:n?"":null)}(this,"manual",e)}get body(){return this._body}set body(e){this._body=e??null}get trigger(){return this._trigger}set trigger(e){if(e){if(!this.url)return void this._warnTriggerWithoutUrl();this._trigger=!0,this.fetch().finally(()=>{this._trigger=!1,this.dispatchEvent(new CustomEvent("wcs-fetch:trigger-changed",{detail:!1,bubbles:!0}))})}}_collectHeaders(){const e={},t=this.querySelectorAll(fa.fetchHeader);for(const n of t)"boolean"==typeof n.hasHeader?n.hasHeader&&(e[n.headerName]=n.headerValue):this._warnUndefinedHelper(fa.fetchHeader,"header");return e}_isNativeBodyInit(e){return e instanceof Blob||e instanceof FormData||e instanceof URLSearchParams||e instanceof ArrayBuffer||ArrayBuffer.isView(e)}_collectBody(e){if(null!==e)return"string"==typeof e||this._isNativeBodyInit(e)?{body:e,contentType:null}:{body:JSON.stringify(e),contentType:"application/json"};const t=this.querySelector(fa.fetchBody);if(t&&"string"!=typeof t.bodyContent)this._warnUndefinedHelper(fa.fetchBody,"body");else if(t)return{body:t.bodyContent||null,contentType:t.contentType};return{body:null,contentType:null}}abort(){this._core.abort()}_scheduleAutoFetch(){this._autoPending||(this._autoPending=!0,queueMicrotask(()=>{this._autoPending=!1;const e=this._connectResolve;this._connectResolve=null;const t=this.url;t||(this._lastFetchedUrl=null),this.isConnected&&!this.manual&&t&&t!==this._lastFetchedUrl?(null===e&&this._warnUnsafeAutoFetch(),this.fetch().finally(()=>e?.())):e?.()}))}_warnTriggerWithoutUrl(){this._toldTriggerWithoutUrl||(this._toldTriggerWithoutUrl=!0,console.warn("[@wcstack/fetch] [wcs/command-not-ready] trigger was refused: there is no url, so nothing is fetched. Write url before trigger (bindings apply in the order written), and write trigger again once there is one. (Said once until a request is sent again.)",this))}_warnUndefinedHelper(e,t){this._toldUndefinedHelper||(this._toldUndefinedHelper=!0,console.warn(`[@wcstack/fetch] [wcs/fetch-helper-undefined] <${e}> inside this <${fa.fetch}> is not defined, so its ${t} is not sent. Load @wcstack/fetch/auto, or define WcsFetchHeader and WcsFetchBody with WcsFetch when the page defines the tags itself. (Said once per element.)`,this))}_warnUnsafeAutoFetch(){const e=this.method;"GET"!==e&&"HEAD"!==e&&"OPTIONS"!==e&&null===this._body&&null===this.querySelector(fa.fetchBody)&&console.warn(`[@wcstack/fetch] [wcs/fetch-auto-unsafe] The url changed to "${this.url}", so this <wcs-fetch> sent a ${e} with no body (its method stays ${e}; a body is sent once). Give loading and each change its own <wcs-fetch>, or set \`manual\` on the one that changes data.`)}async fetch(){this._lastFetchedUrl=this.url,this.url&&(this._toldTriggerWithoutUrl=!1);const e=this._collectHeaders(),t=this._body;this._body=null;const{body:n,contentType:r}=this._collectBody(t);n instanceof FormData&&Object.keys(e).some(e=>"content-type"===e.toLowerCase())&&console.warn("[@wcstack/fetch] A manual Content-Type header was set alongside a FormData body. This drops the multipart boundary the browser adds automatically; remove the Content-Type header (e.g. the <wcs-fetch-header>) to fix multipart uploads.");const i=await this._core.fetch(this.url,{method:this.method,headers:e,body:n,contentType:r,forceText:!!this.target,responseType:this.responseType});if(this.target&&null!==i){const e=document.getElementById(this.target);e&&function(e,t){try{e.innerHTML=function(e){if("string"!=typeof e)return e;const t=Ta(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(t)}catch(e){if(function(){if(void 0!==xa)return xa;if(!("trustedTypes"in globalThis))return xa=!1,xa;try{document.createElement("div").innerHTML="<i></i>",xa=!1}catch{xa=!0}return xa}())return void function(){if(Pa)return;Pa=!0;const e="function"==typeof Ta()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/fetch deliberately does not pass responses through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/fetch] The "target" HTML replace mode was blocked by Trusted Types (require-trusted-types-for 'script'). ${e}\nInstall a sanitizing policy before the first fetch:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr drop "target" and bind the response through @wcstack/state. See docs/csp.md section 7.`)}();throw e}}(e,i)}return i}attributeChangedCallback(e,t,n){"url"===e&&this._scheduleAutoFetch()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&ka(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!_a(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",wa||(wa=!0,document.addEventListener("click",va)),!this.manual&&this.url&&(this._connectedCallbackPromise=new Promise(e=>{this._connectResolve=e})),this._scheduleAutoFetch()}disconnectedCallback(){this.abort(),this._lastFetchedUrl=null,this._connectResolve?.(),this._connectResolve=null}}class Ma extends HTMLElement{connectedCallback(){for(const e of["name","value"])if(Object.prototype.hasOwnProperty.call(this,e)){const t=this[e];delete this[e],this[e]=t}this.style.display="none"}get name(){return this.getAttribute("name")??""}set name(e){Ca(this,"name",e)}get value(){return this.getAttribute("value")??""}set value(e){Ca(this,"value",e)}get headerName(){return this.name}get headerValue(){return this.value}get hasHeader(){return""!==this.name&&this.hasAttribute("value")}}let La=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}get contentType(){return this.getAttribute("type")||"application/json"}get bodyContent(){return this.textContent?.trim()||""}};class Ia extends HTMLElement{static get observedAttributes(){return["target","root","root-margin","threshold","disabled"]}_observer=null;_done=!1;_warnedTarget=null;get target(){return this.getAttribute("target")||""}set target(e){this.setAttribute("target",e)}get root(){return this.getAttribute("root")}set root(e){null===e?this.removeAttribute("root"):this.setAttribute("root",e)}get rootMargin(){return this.getAttribute("root-margin")||"0px"}set rootMargin(e){this.setAttribute("root-margin",e)}get threshold(){const e=Number(this.getAttribute("threshold")??"0");return Number.isFinite(e)?e:0}set threshold(e){this.setAttribute("threshold",String(e))}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get once(){return this.hasAttribute("once")}set once(e){e?this.setAttribute("once",""):this.removeAttribute("once")}connectedCallback(){this._observe()}disconnectedCallback(){this._disconnectObserver()}attributeChangedCallback(){this.isConnected&&this._observe()}_observe(){this._disconnectObserver(),this._done||this.disabled||!this.target||"undefined"==typeof IntersectionObserver||(this._observer=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&this._triggerFetch()},{root:this._resolveRoot(),rootMargin:this.rootMargin,threshold:this.threshold}),this._observer.observe(this))}_disconnectObserver(){this._observer&&(this._observer.disconnect(),this._observer=null)}_resolveRoot(){return this.root&&document.getElementById(this.root)||null}_triggerFetch(){const e=document.getElementById(this.target);e instanceof Oa?e.loading||(e.trigger=!0,this.once&&(this._done=!0,this._disconnectObserver())):this._warnedTarget!==this.target&&(this._warnedTarget=this.target,console.warn(`[@wcstack/fetch] [wcs/infinite-scroll-target] <${fa.infiniteScroll} target="${this.target}"> came into view, but no <${fa.fetch}> has that id, so no page was loaded.`))}}!function(e=customElements){e.get(fa.fetch)||e.define(fa.fetch,Oa),e.get(fa.fetchHeader)||e.define(fa.fetchHeader,Ma),e.get(fa.fetchBody)||e.define(fa.fetchBody,La),e.get(fa.infiniteScroll)||e.define(fa.infiniteScroll,Ia)}(void 0);const ja="data-storagetarget",Ra={storage:"wcs-storage"},Ha="wcs-storage:value-changed",Wa="wcs-storage:loading-changed",Ua="wcs-storage:error",Da="wcs-storage:error-info-changed",Fa="wcs-storage:trigger-changed";let za=class extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:Ha,semantics:"state",getter:e=>e.detail},{name:"loading",event:Wa,semantics:"state"},{name:"error",event:Ua,semantics:"state"},{name:"errorInfo",event:Da,semantics:"state"}],inputs:[{name:"key"},{name:"type"}],commands:[{name:"load"},{name:"save"},{name:"remove"}]};_target;_value=null;_loading=!1;_error=null;_errorInfo=null;_key="";_toldUnkept=!1;_toldNoKey=!1;_type="local";_storageListener=null;_gen=0;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get ready(){return this._ready}observe(){return this._ready}dispose(){this._gen++,this.stopSync()}get value(){return this._value}set value(e){Object.is(e,this._value)||this._setValue(e)}get loading(){return this._loading}get error(){return this._error}get errorInfo(){return this._errorInfo}get key(){return this._key}set key(e){this._key=String(e),this._key&&(this._toldNoKey=!1)}get type(){return this._type}set type(e){"local"===e||"session"===e?this._type=e:this._setError({operation:"type",message:`Invalid storage type: "${e}". Must be "local" or "session".`})}_getStorage(){return"session"===this._type?sessionStorage:localStorage}_setLoading(e){this._loading=e,this._target.dispatchEvent(new CustomEvent(Wa,{detail:e,bubbles:!0}))}_setError(e,t){this._error!==e&&(this._error=e,this._commitErrorInfo(null===e?null:function(e,t){return void 0===t?{code:"invalid-argument",phase:"start",recoverable:!1,message:e.message}:"QuotaExceededError"===t?{code:"quota-exceeded",phase:"execute",recoverable:!0,message:e.message}:"SecurityError"===t?{code:"not-allowed",phase:"execute",recoverable:!1,message:e.message}:{code:"storage-error",phase:"execute",recoverable:!0,message:e.message}}(e,t)),this._target.dispatchEvent(new CustomEvent(Ua,{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent(Da,{detail:e,bubbles:!0}))}_toStorageError(e,t){return{operation:e,message:t instanceof Error?t.message:String(t)}}_errName(e){return e instanceof Error?e.name:""}_setValue(e){this._value=e,this._target.dispatchEvent(new CustomEvent(Ha,{detail:e,bubbles:!0}))}load(){if(!this._key)return this._setError({operation:"load",message:"key is required."}),this._warnNoKey("load"),null;this._setLoading(!0),this._setError(null);try{const e=this._getStorage().getItem(this._key);if(null===e)this._setValue(null);else try{this._setValue(JSON.parse(e))}catch{this._setValue(e)}return this._setLoading(!1),this._value}catch(e){return this._setError(this._toStorageError("load",e),this._errName(e)),this._setLoading(!1),null}}save(e){if(!this._key)return this._setError({operation:"save",message:"key is required."}),void this._warnNoKey("save");this._setLoading(!0),this._setError(null);try{const t=this._getStorage();if(null==e)t.removeItem(this._key),this._setValue(null);else if("string"==typeof e)t.setItem(this._key,e),this._setValue(e);else{let n=null;const r=JSON.stringify(e,(e,t)=>{if(null===n){const r=function(e){return null===e||"object"!=typeof e?null:"undefined"!=typeof File&&e instanceof File?"a File":"undefined"!=typeof Blob&&e instanceof Blob?"a Blob":e instanceof Map?"a Map":e instanceof Set?"a Set":e instanceof ArrayBuffer||ArrayBuffer.isView(e)?"binary data":null}(t);null!==r&&(n=""===e?r:`${r} at "${e}"`)}return t});t.setItem(this._key,r),this._setValue(e),null!==n&&this._warnUnkept(n)}this._setLoading(!1)}catch(e){this._setError(this._toStorageError("save",e),this._errName(e)),this._setLoading(!1)}}_warnNoKey(e){this._toldNoKey||(this._toldNoKey=!0,console.warn(`[@wcstack/storage] [wcs/command-not-ready] ${e}() was refused: there is no key, so nothing is loaded or stored. It goes to \`error\` too. Give the element a \`key\` — in React and Vue, which keep \`key\` for themselves, write \`storage-key\`. (Said once until the element has a key again.)`,this._target))}_warnUnkept(e){this._toldUnkept||(this._toldUnkept=!0,console.warn(`[@wcstack/storage] [wcs/storage-unserializable] The value saved under "${this._key}" holds ${e}, which JSON cannot keep: it is stored as {} and comes back empty after a reload. Keep it out of the stored value (Blobs and files belong in IndexedDB or on a server). (Said once per element.)`,this._target))}remove(){if(!this._key)return this._setError({operation:"remove",message:"key is required."}),void this._warnNoKey("remove");this._setLoading(!0),this._setError(null);try{this._getStorage().removeItem(this._key),this._setValue(null),this._setLoading(!1)}catch(e){this._setError(this._toStorageError("remove",e),this._errName(e)),this._setLoading(!1)}}startSync(){if(this._storageListener)return;const e=++this._gen;this._storageListener=t=>{if(e===this._gen&&t.key===this._key&&"session"!==this._type)if(this._setError(null),null===t.newValue)this._setValue(null);else try{this._setValue(JSON.parse(t.newValue))}catch{this._setValue(t.newValue)}},globalThis.addEventListener("storage",this._storageListener)}stopSync(){this._storageListener&&(globalThis.removeEventListener("storage",this._storageListener),this._storageListener=null)}},qa=!1;function Ba(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${ja}]`);if(!n)return;const r=n.getAttribute(ja);if(!r)return;const i=customElements.get(Ra.storage),s=document.getElementById(r);i&&s instanceof i&&(e.preventDefault(),s.save())}function Ga(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const Ka=new WeakSet;function Va(e,t,n){if(Ka.has(e))return;Ka.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const Ja=new WeakMap;function Qa(e,t){let n=Ja.get(e);return void 0===n&&(n=new Map,Ja.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function Xa(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Ya(e,t,n){const r=Qa(e,t);Xa(e,t,void 0===n?r:null===n?null:String(n))}let Za=class extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...za.wcBindable,properties:[...za.wcBindable.properties,{name:"trigger",event:Fa,semantics:"state"}],inputs:[{name:"key"},{name:"storageKey"},{name:"type"},{name:"value"},{name:"manual"},{name:"trigger"}]};static get observedAttributes(){return["key","storage-key","type"]}_core;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_internals=null;_everConnected=!1;_loadPending=!1;constructor(){super(),this._core=new za(this),this._internals=this._initInternals(),this._wireStates({[Wa]:e=>({loading:!0===e}),[Ua]:e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[n,r]of Object.entries(e))this.addEventListener(n,e=>{const n=this.hasAttribute("debug-states");for(const[i,s]of Object.entries(r(e.detail))){try{s?t.add(i):t.delete(i)}catch{}n&&this.toggleAttribute(`data-wcs-state-${i}`,s)}})}_syncCore(){this._core.key=this.key,this._core.type=this.type}get key(){return this.getAttribute("key")||this.getAttribute("storage-key")||""}set key(e){Ya(this,"key",e)}get storageKey(){return this.key}set storageKey(e){Ya(this,"storage-key",e)}get type(){return"session"===this.getAttribute("type")?"session":"local"}set type(e){Ya(this,"type",e)}_warnedType=null;_checkType(){const e=this.getAttribute("type");null!==e&&""!==e&&"local"!==e&&"session"!==e&&e!==this._warnedType&&(this._warnedType=e,console.warn(`[@wcstack/storage] [wcs/storage-type-invalid] <${Ra.storage} type="${e}"> is neither "local" nor "session": it uses localStorage, so the data is kept after the session ends.`))}get value(){return this._core.value}set value(e){void 0!==e&&(this.manual?this._core.value=e:(this._syncCore(),this._core.save(e)))}get loading(){return this._core.loading}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}get manual(){return this.hasAttribute("manual")}set manual(e){!function(e,t,n){const r=Qa(e,t);Xa(e,t,void 0===n?r:n?"":null)}(this,"manual",e)}get trigger(){return this._trigger}set trigger(e){if(e){this._trigger=!0;try{this.save()}finally{this._trigger=!1,this.dispatchEvent(new CustomEvent(Fa,{detail:!1,bubbles:!0}))}}}load(){return this._syncCore(),this._core.load()}save(){this._syncCore(),this._core.save(this._core.value)}remove(){this._syncCore(),this._core.remove()}attributeChangedCallback(e,t,n){this.isConnected&&("storage-key"===e&&this.getAttribute("key")||("key"!==e&&"storage-key"!==e||(this._syncCore(),!this.key||this.manual||this._loadPending||this.load()),"type"===e&&(this._checkType(),this._syncCore())))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&Va(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!Ga(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",this._checkType(),qa||(qa=!0,document.addEventListener("click",Ba)),this._everConnected?this._scheduleLoad():(this._everConnected=!0,!this.manual&&this.key&&this.load()),this._syncCore(),this._core.startSync()}disconnectedCallback(){this._core.stopSync()}_scheduleLoad(){this._loadPending||(this._loadPending=!0,queueMicrotask(()=>{this._loadPending=!1,this.isConnected&&!this.manual&&this.key&&this.load()}))}};!function(e=customElements){e.get(Ra.storage)||e.define(Ra.storage,Za)}(void 0);const eu="*",tu="vanilla",nu={loaders:{[tu]:{postfix:".js",loader:async function(e){return(await(import(`${e}`))).default}},[eu]:tu},observable:!0,tagNames:{autoloader:"wcs-autoloader"}};function ru(e){if(e.startsWith("@components/")){if(e.endsWith("/")){const t=e.slice(12,e.length-1),[n,r]=t.split("|",2);if(""===n)throw new Error("Invalid importmap key: "+e);return{key:e,prefix:n.replaceAll("/","-").toLowerCase(),loaderKey:r??null,isNameSpaced:!0}}{const t=e.slice(12),[n,r]=t.split("|",2),[i,s]=(r??"").split(",",2);if(""===n)throw new Error("Invalid importmap key: "+e);return{key:e,tagName:n.replaceAll("/","-").toLowerCase(),loaderKey:i||null,extends:s||null,isNameSpaced:!1}}}return null}function iu(e,t,n){let r;if(null===t||t===eu||""===t){let t=null;const i=[];for(const[e,t]of Object.entries(n)){if(e===eu)continue;const r="string"==typeof t?n[t]:t;"string"!=typeof r&&i.push(r)}i.sort((e,t)=>t.postfix.length-e.postfix.length);for(const n of i)if(e.endsWith(n.postfix)){t=n;break}t?r=t:(r=n[eu],"string"==typeof r&&(r=n[r]))}else if(r=n[t],!r)throw new Error("Loader not found: "+t);if("string"==typeof r)throw new Error("Loader redirection is not supported here");return r}const su=new Set,ou=new Map;let lu=new WeakMap;function au(e){if(e===globalThis.customElements)return ou;let t=lu.get(e);return void 0===t&&(t=new Map,lu.set(e,t)),t}const uu=new Map;async function cu(e,t,n){try{if(customElements.get(t))return;const r=await n.loader(e.key);if(null!==r){let n=e.extends;if(null===n&&(n=function(e){for(const[t,n]of uu)if(e.prototype instanceof t)return n;return null}(r)),customElements.get(t))return;null===n?customElements.define(t,r):customElements.define(t,r,{extends:n})}}catch(e){su.has(t)||(console.error(`Failed to eager load component '${t}':`,e),su.add(t))}}function hu(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined||"function"!=typeof t.define?null:t}function du(e){const t=e.tagName.toLowerCase();let n,r;if(t.includes("-"))n=t,r=null;else{const i=e.getAttribute("is");if(null===i)throw new Error("Custom element without a dash or 'is' attribute found: "+t);if(!i.includes("-"))throw new Error("Custom element 'is' attribute without a dash found: "+t);n=i,r=t}return{name:n,extends:r}}"undefined"!=typeof window&&[[HTMLButtonElement,"button"],[HTMLInputElement,"input"],[HTMLAnchorElement,"a"],[HTMLImageElement,"img"],[HTMLDivElement,"div"],[HTMLSpanElement,"span"],[HTMLParagraphElement,"p"],[HTMLUListElement,"ul"],[HTMLOListElement,"ol"],[HTMLLIElement,"li"],[HTMLTableElement,"table"],[HTMLFormElement,"form"],[HTMLLabelElement,"label"],[HTMLSelectElement,"select"],[HTMLTextAreaElement,"textarea"],[HTMLHeadingElement,"h1"],[HTMLQuoteElement,"blockquote"],[HTMLPreElement,"pre"],[HTMLBRElement,"br"],[HTMLHRElement,"hr"],[HTMLModElement,"ins"],[HTMLTableCaptionElement,"caption"],[HTMLTableColElement,"col"],[HTMLTableSectionElement,"tbody"],[HTMLTableRowElement,"tr"],[HTMLTableCellElement,"td"],[HTMLFieldSetElement,"fieldset"],[HTMLLegendElement,"legend"],[HTMLDListElement,"dl"],[HTMLOptGroupElement,"optgroup"],[HTMLOptionElement,"option"],[HTMLStyleElement,"style"],[HTMLScriptElement,"script"],[HTMLTemplateElement,"template"],[HTMLCanvasElement,"canvas"],[HTMLIFrameElement,"iframe"],[HTMLObjectElement,"object"],[HTMLEmbedElement,"embed"],[HTMLVideoElement,"video"],[HTMLAudioElement,"audio"],[HTMLTrackElement,"track"],[HTMLMapElement,"map"],[HTMLAreaElement,"area"],[HTMLSourceElement,"source"],[HTMLParamElement,"param"],[HTMLMeterElement,"meter"],[HTMLProgressElement,"progress"],[HTMLOutputElement,"output"],[HTMLDetailsElement,"details"],[HTMLDialogElement,"dialog"],[HTMLMenuElement,"menu"],[HTMLSlotElement,"slot"],[HTMLTimeElement,"time"],[HTMLDataElement,"data"],[HTMLPictureElement,"picture"]].forEach(([e,t])=>{void 0!==e&&uu.set(e,t)});const fu=new WeakSet,pu=new WeakSet;async function mu(e,t,n){e.shadowRoot&&(fu.has(e)||await async function(e,t,n){fu.add(e),await vu(e.shadowRoot,t,n)}(e,t,n))}function gu(e,t){for(const[n,r]of Object.entries(t))if(e.startsWith(n+"-"))return r;return null}async function yu(e,t,n,r){const i=au(r),s=i.get(e.name);if(void 0!==s)return void await s;const o=async function(e,t,n,r){try{let i;try{i=iu("",n.loaderKey,t.loaders)}catch(t){throw new Error("Loader redirection is not supported for lazy loaded components: "+e.name)}const s=e.name.slice(n.prefix.length+1);if(""===s)throw new Error("Invalid component name for lazy loaded component: "+e.name);const o=n.key+s+i.postfix;if(r.get(e.name))return;const l=await i.loader(o);if(null===l)throw new Error("Loader returned null for component: "+e.name);if(r.get(e.name))return;null===e.extends?r.define(e.name,l):r.define(e.name,l,{extends:e.extends})}catch(t){console.error(`Failed to lazy load component '${e.name}':`,t),su.add(e.name)}}(e,t,n,r);i.set(e.name,o);try{await o}finally{i.delete(e.name)}}async function bu(e,t,n,r){const i=[],s=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_ELEMENT,e=>(e=>(e instanceof Element&&(e.tagName.includes("-")||e.getAttribute("is")?.includes("-")))??!1)(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);for(;s.nextNode();)i.push(s.currentNode);const o=[],l=new Set;for(const e of i){const i=du(e);if(void 0===r.get(i.name)){pu.has(e)||(pu.add(e),r.whenDefined(i.name).then(async()=>{await mu(e,t,n)}));const s=gu(i.name,n);null===s||l.has(i.name)||su.has(i.name)||(l.add(i.name),o.push([i,s]))}else await mu(e,t,n)}let a=0;for(const[e,n]of o)await yu(e,t,n,r),a++;return a}async function wu(e,t,n,r){for(;await bu(e,t,n,r)>0;);}async function vu(e,t,n){if(0===Object.keys(n).length)return null;const r=function(e=null){if(null!=e){const t=e.customElementRegistry;if(null===t)return null;if(void 0!==t)return hu(t)}return hu(globalThis.customElements)}(e);if(null===r)return console.error("Cannot autoload components: the root has a null custom element registry."),null;try{await wu(e,t,n,r)}catch(e){throw new Error("Failed to lazy load components: "+e)}if(!t.observable)return null;const i=new MutationObserver(async()=>{try{await wu(e,t,n,r)}catch(e){console.error("Failed to lazy load components: "+e)}});return i.observe(e,{childList:!0,subtree:!0}),i}class _u extends HTMLElement{static _instance=null;_initialized=!1;_prefixMap=null;_observer=null;constructor(){if(super(),_u._instance)throw new Error(`${nu.tagNames.autoloader} can only be instantiated once.`);_u._instance=this;const e=function(){const e={imports:{}};return document.querySelectorAll('script[type="importmap"]').forEach(t=>{try{const n=JSON.parse(t.innerHTML);n.imports&&(e.imports=Object.assign(e.imports,n.imports))}catch(e){throw new Error("Failed to parse importmap JSON: "+e)}}),Object.keys(e.imports).length>0?e:null}();if(e){const{prefixMap:t,loadMap:n}=function(e){const t={},n={};for(const[r,i]of Object.entries(e.imports)){const e=ru(r);null!==e&&(e.isNameSpaced?t[e.prefix]=e:n[e.tagName]=e)}return{prefixMap:t,loadMap:n}}(e);this._prefixMap=t,async function(e,t){const n=[];for(const[r,i]of Object.entries(e)){let s;try{s=iu(i.key,i.loaderKey,t)}catch(e){throw new Error("Loader redirection is not supported for eager loaded components: "+r)}n.push(cu(i,r,s))}await Promise.all(n)}(n,nu.loaders).catch(e=>{console.error("Failed to eager load components:",e)})}}async connectedCallback(){this._initialized||(this._initialized=!0,this._prefixMap&&("loading"===document.readyState&&await new Promise(e=>document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})),this._observer=await vu(document,nu,this._prefixMap)))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,_u._instance===this&&(_u._instance=null)}}!function(e=customElements){e.get(nu.tagNames.autoloader)||e.define(nu.tagNames.autoloader,_u)}(void 0);
|
|
1
|
+
var e=class{constructor(e,n,r){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.B=[],this.Q=[],this.ht=null,this.F=-1,this.Y=t,this.De=null,this.jt=null,this.Dt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.yt=new Set,this.t=e,this.a=r,this.s=n;let i=null===r?[null]:r.h.slice(),s="*"===n;s&&i.push(r),this.n=i.length-1,this.z=s?[]:null===r?[n]:[...r.z,n],this.h=i}Hn(e){this.yt.has(e)||(this.yt.add(e),this.B.push(e),e.Q.push(this))}Bo(e){this.yt.delete(e);let t=this.B;t.splice(t.indexOf(e),1)}Mo(){this.getter=null,this.se=null,this.F=-1,this.Y=t,this.B.length=0,this.yt.clear(),this.Q.length=0,this.ht=null,this.De=null,this.jt=null,this.Dt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.a}return!1}},t=Symbol("unset"),n=Symbol("dirty"),r=Symbol("failed"),i=class{constructor(e=null){this.wt=new Map,this.Un=e}bt(e){return this.wt.get(e)}get(t){let n=this.wt.get(t);if(void 0!==n)return n;let r=t.lastIndexOf("."),i=r<0?null:this.get(t.slice(0,r));return n=new e(t,t.slice(r+1),i),this.Un?.(n),this.wt.set(t,n),i&&i.u.push(n),n}all(){return this.wt.values()}Lt(e){this.wt.delete(e.t)}},s=new Map;function o(e){let t=s.get(e);if(void 0!==t)return t;let n=!0,r=e.split("."),i=[];for(let e=0;e<r.length;e++){let t=r[e],s=t.charCodeAt(0);e>0&&s>=48&&s<=57?(n=!1,i.push(Number(t)),r[e]="*"):"*"===t&&i.push(-1)}if(!n)return{o:r.join("."),indexes:i};let o={o:e,indexes:null};return s.size>4095&&s.clear(),s.set(e,o),o}var l=class{constructor(e,t,n){this.vt=null,this.N=null,this.we=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.E=n}},a=class{constructor(e,t){this.P=null,this.f=[],this.N=null,this.M=null,this.te=!1,this.Bt=!1,this.kt=!1,this.o=e,this.ce=t,this.n=e.n+1}},u=[],c={};function h(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function d(e,t,n){return null==t?n:(...r)=>{let i=t(...r);return e(i)?i:n(...r)}}var f=e=>!0===e,p=e=>void 0!==e,m=e=>null!=e,g=new Set;function y(e){let t=e.$features;if(null!=c.Wt&&Array.isArray(t)){let e=t.filter(e=>!g.has(e));if(e.length>0)return c.Wt(e)}}function b(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 w(e,t,n){throw new Error(`[@wcstack/state] ${e}${c._o?.(e,t,n)??""}`)}function v(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function _(e,t=[]){return c.Vo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function $(e,t,n,r){w(_(e,t),n,r)}var k=class{constructor(e){this.St=new Set,this.name=e}get size(){return this.St.size}subscribe(e){return this.St.add(e),()=>{this.St.delete(e)}}unsubscribe(e){return this.St.delete(e)}emit(...e){let t=[];for(let n of this.St)try{t.push(n(...e))}catch(e){t.push(void 0),v(e,`[@wcstack/state] ${_(17,[this.name])}`)}return t}};function S(e,t,n){if(void 0===e)return[];Array.isArray(e)||$(18,[t]);let r=new Set;for(let i of e)("string"!=typeof i||""===i)&&$(19,[t]),i===n&&$(20,[t,i,n]),r.has(i)&&$(21,[t,i]),r.add(i);return e}var N=Symbol.for("wcstack.transition-runner");function A(e){let t=globalThis[N];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function C(e,t,n){let r=A(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var E="else",T="eventToken",x="class",P="attr",O=/^\$[1-9]\d{0,2}$/,L=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function M(e){let t=[],n=[],r="",i=null,s=!1,o=-1,l=-1,a=e=>{let i=function(e,t,n){let r=-1===t?e.length:t,i=-1===n?0:n;return e.slice(r-e.slice(0,r).trimStart().length,i+e.slice(i).trimEnd().length)}(r,o,l);(!e||i||s)&&(t.push(i),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:L.test(e)?Number(e):e)}(i,s))),r="",s=!1,o=-1,l=-1};for(let t=0;t<e.length;t++){let n=e[t];i?n===i?i=null:(-1===o&&(o=r.length),r+=n,l=r.length):'"'===n||"'"===n?(i=n,s=!0):","===n?a():r+=n}return null!==i&&$(107,[i,e]),a(!0),{args:t,literals:n}}var I=e=>e.trim();function j(e,t){let n=[],r=null;for(let i=0;i<e.length;i++){let s=e[i];null!==r?s===r&&(r=null):"'"===s||'"'===s?r=s:s===t&&n.push(i)}return n}var R=(e,t)=>j(e,t)[0]??-1;function H(e,t){let n=[],r=0;for(let i of j(e,t))n.push(e.slice(r,i)),r=i+1;return n.push(e.slice(r)),n}function W(e,t,n){let r=R(e,"|");if(-1===r)return[e.trim(),[]];let i=e.slice(r+1).trim(),s=n.get(i);return void 0===s&&(s=function(e,t,n){let r=n??e.join("|");return e.map(e=>{let n=R(e,"("),i=(e=>j(e,")").pop()??-1)(e);if(-1===i&&(i=e.lastIndexOf(")")),-1!==n&&-1===i&&$(108,[e]),-1!==i&&-1===n&&$(109,[e]),-1!==i&&i<n&&$(110,[e]),-1!==i&&e.slice(i+1).trim().length>0){let t=e.slice(i+1).trim();$(111,[e,t])}let s=(-1===n?e:e.substring(0,n)).trim();if(0===s.length&&$(112,[r]),s.includes("#")){let[,e]=s.split("#");$("input"===t?113:114,[s,e])}return-1===n?{qn:s,args:[],literals:[]}:{qn:s,...M(e.substring(n+1,i))}})}(H(i,"|").map(I),t,e),n.set(i,s)),[e.slice(0,r).trim(),s]}var U=new Map;function D(e){$(1101,[e])}function F(e){let[t,n]=W(e,"output",U);t.includes("@")&&$(32,[t]);let r=t,i=r.startsWith("."),s=i?r.slice(1):r;return(s.length>0&&s.split(".").some(e=>0===e.length)||!i&&0===s.length)&&$(119,[e]),function(e){e.includes("**")&&D(e);let t=e.split(".").length;t>512&&$(117,[e,t])}(r),{et:r,tt:n}}var z=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],q=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function B(e){return e.includes("**")&&D(e),e}var K=0;function G(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var V=()=>new Set,J=()=>[],Q=new WeakMap;function Y(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Z(e,t,n){let r=e._?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e._.delete(t)}function ee(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function te(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function ne(e,t,n){let r=te(e,n);return null!==r&&r.l.o===t.h[n]?r:null}var re=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.nt=new Set,this.ot=new Map,this.Kn=Symbol("wcs.block"),this.element=null,this.$t=[],this.Me=null,this.zn=[],this.Ut=0,this.G=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.He=!1,this.gn=!1,this.qt=new WeakMap,this.j=0,this.Kt=0,this.yn=0,this.wn=0,this.bn=!1,this.zt=!1,this.Yt=!1,this.Ce=0,this.Yn=()=>{this.j=0,this.bn=!1},this.Gn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Ho=()=>{this.He&&this.Et()},this.Uo=(e,t)=>e(this.proxy,...t),this.Xn=[],this.Ue=[],this.Jn={$untracked:e=>{let t=this.G;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=te(this.d,t);null===n&&$(7,[e]);let r=this.o(e);if(null!==r.getter||r.ae)return this.watchIndex(t),n.y===this.read(r,null);let i=this.G;if(null!==i){let e=i.getter,n=r.De??(r.De=[]);if(!n.some(n=>n.getter===e&&n.Qn===t)){n.push({getter:e,Qn:t});let i=e.h[t];(i.jt??(i.jt=[])).push({source:r,getter:e})}}return n.y===this.v(r,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,te(this.d,n.n)))},$dependOn:e=>{this.resolve(B(e),this.d),null!==this.G&&0===this.G.be&&this.Zn(this.rp,this.rr,this.G)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,r)=>this.vn(e,t,n,r),$resolve:(...e)=>{let t=B(e[0]),n=e[1]??[],r=this.o(t,!0);this.kn("$resolve",t,r,n,!0);let i=this.eo(r,n,null);if(e.length<3)return this.read(r,i);this.A(r,i,e[2])},$postUpdate:e=>{this.resolve(B(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.E=n.l.P[n.y],Q.delete(n.l.P),this.T.Gt(n)),this.Sn(t,n),null!==n&&this.to(n,t,void 0,n.E,!1),0===t.n&&this.no(t,void 0,void 0,!0),this.Xt(t,n,void 0,void 0,!1)}},this.T=t,this.O=new i(e=>{this.Ue.push(e),this.rt(e)}),this.oo(e);let n=this,r={getOwnPropertyDescriptor(e,t){let r=Reflect.getOwnPropertyDescriptor(n.target,t);return r&&(r.configurable=!0),r},get(e,t,r){let i=n.target;if("symbol"==typeof t)return Reflect.get(i,t);if(36===t.charCodeAt(0))return n.it(t);if(t.indexOf(".")<0){let e=n.O.bt(t);if(void 0===e||null===e.getter){let e=i[t];if("function"==typeof e)return r===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,r)=>"symbol"==typeof t?Reflect.set(n.target,t,r):(n.resolve(B(t),n.d),n.A(n.rp,n.rr,r),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])r[e]=(t,...r)=>Reflect[e](n.target,...r);this.proxy=new Proxy({},r)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}io(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let r=Object.getOwnPropertyDescriptor(n,e);if(void 0===r.get&&void 0===r.set)continue;let i=this.o(e);i.getter=r.get??null,i.se=r.set??null,null!==i.getter&&i.n>0&&(i.F=this.Le++)}for(let e of this.O.all())this.rt(e)}rt(e){e.t.includes("**")&&D(e.t),("__proto__"===e.s||"prototype"===e.s)&&$(120,[e.t]);let t=e.a;e.ae=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ae),null===e.getter&&this.qo(e)}qo(e){let t=e.t,n=e.s;if(O.test(n))e.getter=function(){return this[n]};else{let r=t.split("."),i=r.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(i<0||r.indexOf("*",i)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.a,this.d)?.[n]),e.se=r=>{if(this.resolve(t,this.d),this.rp!==e)return this.A(this.rp,this.rr,r);let i=this.read(e.a,this.d);null==i&&$(4,[t,i]),i[n]=r}}e.hn=!0,e.n>0&&(e.F=this.Le++)}qe(e,t){let n=null===e?this.oe:e.u??=new Map,r=n.get(t);return void 0===r&&n.set(t,r=new a(t,e)),t.pn=!0,this.X(r),r}so(e){try{this.X(e)}catch(t){this.Jt(t,e.o.t,e.N?.S??null,"for")}}X(e){let t=this.v(e.o,e.ce);if(t===e.P)return;this.lo(e);let n=function(e,t,n){let r=Array.isArray(t)?t:u;if(r===e.P)return null;let i=e.f,s=r.length,o=i.length,a=new Array(s),c=0;for(;c<s&&c<o&&i[c].E===r[c];)a[c]=i[c],c++;let h=o-1,d=s-1;for(;h>=c&&d>=c&&i[h].E===r[d];)a[d]=i[h],h--,d--;if(c>h)for(let t=c;t<=d;t++)a[t]=new l(e,t,r[t]);else if(c>d)for(let e=c;e<=h;e++)n.Mt(i[e]);else{let t=h<d?h:d;for(let e=c;e<=t;e++)i[e].E===r[e]&&(a[e]=i[e]);let s=new Map;for(let e=h;e>=c;e--){let n=i[e];if(e<=t&&a[e]===n)continue;let r=s.get(n.E);void 0===r?s.set(n.E,n):Array.isArray(r)?r.push(n):s.set(n.E,[r,n])}for(let t=c;t<=d;t++){if(void 0!==a[t])continue;let n,i=r[t],o=s.get(i);void 0!==o&&(Array.isArray(o)?(n=o.pop(),0===o.length&&s.delete(i)):(n=o,s.delete(i))),a[t]=n??new l(e,t,i)}for(let e of s.values())if(Array.isArray(e))for(let t of e)n.Mt(t);else n.Mt(e)}for(let e=c;e<s;e++){let t=a[e];t.y!==e&&(t.y=e,n.Wo(t))}return e.f=a,e.P=r,i}(e,t,this);if(null===n)return;if(e.P===t){let n=G(this.qt,t,J);if(n.push(e),n.length>1)for(let e of n)e.kt=!0}c.Qt?.(this,e,n),(null!==e.N||null!==e.M)&&!e.te&&(e.te=!0,this._e.push(e),this.ve());let r=e.o.jt;if(null!==r)for(let{source:t,getter:i}of r){let r=this.v(t,null),s=n[r],o=e.f[r];s!==o&&(void 0!==s&&s.w&&this.$n(i,s),void 0!==o&&this.$n(i,o))}}Wo(e){this.T.Ko(this,e)}Mt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)Z(e.source,e.key,e.sub);e._=null}if(null!==e.u)for(let t of e.u.values()){this.lo(t);for(let e of t.f)this.Mt(e)}}lo(e){let t=this.qt.get(e.P);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.kt=!1,1===t.length&&(t[0].kt=!1))}resolve(e,t){let n=o(e),r=this.rp=this.o(n.o,!0),i=n.indexes;this.rr=0===r.n?null:null===i?ne(t,r,r.n):this.eo(r,i,t,e)}eo(e,t,n,r){let i=null;for(let s,o=1,l=0;o<=e.n;o++){let a=e.h[o],c=this.qe(i,a),h=t[l++];if(h<0)h=ne(n,e,o)?.y??-1;else if(r&&c.P===u&&Object(s=this.v(a,i))===s){let t=e.t.split("."),n=a.t.split(".").length;t[n]=r.split(".")[n],e=this.o(t.join("."),!0),o--;continue}if(i=c.f[h]??null,null===i)break}return this.rp=e,i}st(e,t){return 0===e.n?ee(this.target,e.z):null===t?void 0:ee(t.E,e.z)}read(e,t){let n=this.G;if(null!==n&&0===n.be&&this.Zn(e,t,n),null!==e.getter)return this.T.zo(this,e,t);if(e.ae){let n=this.read(e.a,t);return n?.[e.s]}return null===e.a&&!(e.s in this.target)&&!this.nt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&$(301,[e.t],e.s,Object.keys(this.target)),this.st(e,t)}v(e,t){let n=this.G;if(null===n)return this.read(e,t);n.be++;try{return this.read(e,t)}finally{n.be--}}Zn(e,t,n){let r=n.getter;e.Hn(r),0===r.n?e.Z!==n.de&&(e.Z=n.de,n.En.push(e)):e.n>0&&te(t,Math.min(e.n,r.n))!==te(n.r,Math.min(e.n,r.n))&&(r.ht??(r.ht=new Set)).add(e)}Yo(e,t){for(let n=0;n<this.Ut;n++){let r=this.zn[n];r.getter===e&&r.r===t&&$(701,[e.t])}this.Ut>=128&&$(801,[e.t]);let n=this.Ut++;this.Be++;let r=this.zn[n]??={getter:e,r:t,be:0,de:0,En:[]};r.getter=e,r.r=t,r.be=0,r.de=++K,r.En.length=0;let i=this.G;this.G=r;let s=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Go(e,r),t}finally{this.Be--,this.Ut--,this.G=i,this.d=s,r.r=null}}Go(e,t){let n=t.de;for(let e of t.En)e.Z=n;e.Q=e.Q.filter(t=>t.Z===n||t.n>0||!t.ae&&Array.isArray(null!==t.getter?t.Y:this.st(t,null))||this.ao(t,e))}ao(e,t){return e.Bo(t),this.Ue.push(e),!1}Xo(){for(let e=this.Ue;e.length>0;e=this.Ue){this.Ue=[];let t=new Set;for(let n of e)if(!(n.pn||n.mn||null===n.a||n.u.length>0||n.B.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.Lt(n),t.add(n.a);for(let e of n.Q)this.ao(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.mn)).length||this.Ue.push(e)}}watchIndex(e){let t=this.G;if(null!==t&&0===t.be){let n=t.getter,r=n.h[e];if(r){let e=r.Dt??(r.Dt=[]);e.includes(n)||e.push(n)}}}it(e){let t=e.charCodeAt(1);if(t>=48&&t<=57){let n=2===e.length?t-48:O.test(e)?+e.slice(1):0;return(n<1||n>128)&&$(1001,[e]),this.watchIndex(n),te(this.d,n)?.y}let n=this.Jn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.it?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,r=this.rr;if(null!==n.getter||n.ae||n.n>0)return X(this.read(n,r),t);let i=this.G;return null!==i&&0===i.be&&this.Jo(n,t,i),X(this.v(n,null),t)}Jo(e,t,n){let r=n.getter,i=n.r,s=null===i?this.Xn:i._??(i._=[]);for(let i=0;i<s.length;i++){let o=s[i];if(o.sub.getter===r&&o.source===e){if(X(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Z(e,o.key,o.sub),s.splice(i--,1))}}let o={getter:r,r:i};G(e._??=new Map,t,V).add(o),s.push({source:e,key:t,sub:o,de:n.de})}no(e,t,n,r){this.Zt(e,i=>{let s=i._;if(null===s&&null===i.De)return;let o=i===e?[]:i.t.slice(e.t.length+1).split("."),l=ee(t,o),a=ee(n,o);if(null!==i.De&&this.Qo(i,l,a,r),null!==s)for(let e of r?s.keys():[l,a]){let t=s.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.w?this.T.ke(this,n.getter,n.r):Z(i,e,n)}})}A(e,t,n,r=!1,i=!1){if(this.Be>0&&$(8),i||this.Ce>0?this.zt=!0:this.Yt=!0,c.Ie?.(this,e,t,n,i))return;if(null!==e.se){try{this.Nn(e.se,t,[n])}finally{this.Xt(e,t,void 0,void 0,!1,i)}return}null!==e.getter&&$(2,[e.t]),e.n>0&&null===t&&$(3,[e.t]);let s=e.ae?this.v(e,t):this.st(e,t);if(r||!this.Vt||!Object.is(s,n)||Object(n)===n){if("*"===e.s){let e=t;e.l.P[e.y]=n,Q.delete(e.l.P),e.E=n,this.T.Gt(e)}else{let r=1===e.z.length?0===e.n?this.target:t.E:this.v(e.a,t);null==r&&$(4,[e.t,r]),r[e.s]=n}this.xn(e,t),null!==t&&this.to(t,e,s,n),0===e.n&&this.no(e,s,n),this.Xt(e,t,s,n,!0,i)}}co(e){return(this.qt.get(e.P)??[]).filter(t=>t.P===e.P&&(null===t.ce||t.ce.w))}to(e,t,r,i,s=!0){let o=e.l,l=t.t.slice(o.o.t.length+2),a=""!==l&&function(e){let t=Q.get(e);if(void 0===t){let n=new Set;Q.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(o.P);if(!a&&!o.kt&&null===o.o.getter&&!o.o.B.length)return;let u=e.E,c=(t,n)=>{if(void 0===n||n===e)return;let o=this.o(`${t.o.t}.*${l}`,!0);""===l&&(n.E=i,this.T.Gt(n)),s?this.xn(o,n):this.Sn(o,n),this.Xt(o,n,r,i,s)};for(let t of this.co(o))if(c(t,t.f[e.y]),a)for(let n of t.f)n.E===u&&n.y!==e.y&&c(t,n);if(""===l)return;let h=new Set([o.P]),d=e=>Array.isArray(e)&&e.includes(u),f=(e,t)=>{if(!h.has(e)&&h.add(e))for(let t of this.qt.get(e)??[])for(let e of t.f)e.E===u&&c(t,e);for(let r of t){let t=r.Y,i=t===n;i&&(t=this.oe.get(r)?.P),(i||d(t))&&!h.has(r.B)&&h.add(r.B)&&(!i&&t!==e&&this.T.ke(this,r,null),f(t,r.B))}},p=e=>{for(let t of e.Q)if(!h.has(t)&&h.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.st(t,null);d(e)&&f(e,t.B)}};null!==o.o.getter?p(o.o):f(o.P,o.o.B)}Sn(e,t){this.Zo(e,t,e=>{this.X(e);for(let t of e.kt?this.co(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.Nt(e,n),this.Sn(e,n)}})}xn(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.X(t)}Zo(e,t,n){let r=null===t?this.oe:t.u;if(null!==r)for(let t of r.values())t.o.ee(e)&&n(t)}Qo(e,t,n,r){for(let{getter:i,Qn:s}of e.De)this.uo(i.h[s],e=>{for(let s of r?e.f.keys():[t,n]){let t="number"==typeof s?e.f[s]:void 0;void 0!==t&&this.$n(i,t)}})}$n(e,t){t.l.n===e.n?this.T.ke(this,e,t):this.en(t,e,t=>this.T.ke(this,e,t))}Xt(e,t,n,r,i,s){c.re?.(this,e,t,n,r,i,s),this.Ke(e,t)}Ke(e,t){this.T.er(this,e,t),this.ve()}fo(e){let t=this.ot.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.ot.set(e,n);let r=this.root,i=this.Kn;return r.addEventListener(e,t=>{for(let s=t.target;null!==s&&s!==r;s=s.parentNode){let r=s[n];if(void 0!==r&&(r(t),t.cancelBubble))return;let o=s[i];if(void 0!==o&&o.w&&o.tr(e,t))return}}),n}reset(e){let t=this.target,n=this.nt;for(let e of this.O.all())null===e.a&&null!==e.getter&&n.add(e.s);this.oo(e);for(let e in t)"$"!==e[0]&&n.add(e);for(let t of n)t in e&&n.delete(t);for(let e of this.ue.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.po(e);this.Me=null;try{this.Et()}finally{this.Rn()}c.element?.(this,"reset")}oo(e){for(let[t,n]of z)void 0!==e[t]&&b(n,t);let t=e.$features;if(void 0!==t){Array.isArray(t)||$(46);for(let e of t)b(e,"$features")}let n=void 0===e.$behavior?{}:e.$behavior;("object"!=typeof n||!n||Array.isArray(n))&&$(44,["state","$behavior"]);for(let e in n)(!q.includes(e)||"boolean"!=typeof n[e])&&$(44,["$behavior",e]);let[r,i,s]=q.map(e=>n[e]??!0);void 0!==this.target&&(r!==this._t||i!==this.Vt||s!==this.Ht)&&$(45);let o=function(e,t){let n={};for(let r of S(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new k(r);return Object.freeze(n)}(e,this.commands),l=function(e,t){let n=new Map;for(let t of S(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let r=e.$on;if(void 0===r)return n;(null===r||"object"!=typeof r)&&$(22);for(let[e,i]of Object.entries(r)){let r=n.get(e);void 0===r&&$(23,[e]),"function"!=typeof i&&$(24,[e]),r.subscribe((...e)=>t(i,e))}return n}(e,this.Uo);this._t=r,this.Vt=i,this.Ht=s,c.fe?.(this,e),this.target=e,this.Le=0;for(let e of this.O.all())e.Mo();this.Xn.length=0,this.io(e),this.commands=o,this.Oe=l}po(e){this.so(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.vt=null,n._=null,this.Nt(t,n),null!==n.u)for(let e of n.u.values())this.po(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}nr(e,t,n){let r=this.Oe.get(e);void 0===r&&$(1301,[e],e,this.Oe.keys()),r.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&$(1302,[e],e,Object.keys(this.commands)),t}or(e,t,n){this.command(e).emit(t,...this.H(n))}ir(e,t,n){let r=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof r&&$(5,[e]),this.Nn(r,n,[t,...this.H(n)])}Nn(e,t,n){let r=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=r}}Nt(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Bt&&t.o.ee(e)&&(t.Bt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.ue.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.we;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let r=t.N;null!==r&&null!==r.pe&&r.mo(this,e);let i=t.l.M;if(null!==i)for(let n of i){let r=n.map.get(t);void 0!==r&&null!==r.pe&&r.mo(this,e)}}Pn(e,t,n){this.Zt(e,e=>{let r=e.B;for(let i=0;i<r.length;i++){let s=r[i];if(0===s.n)this.at(s,null,n);else if(null===t||0===e.n||s.h[1]!==e.h[1]||null!==s.ht&&s.ht.has(e))this.nn(s.h[s.n],e=>this.at(s,e,n));else if(s.n<=e.n){let e=te(t,s.n);null!==e&&this.at(s,e,n)}else this.en(t,s,e=>this.at(s,e,n))}})}at(e,t,n){n(e,t)&&(c.Se?.(this,e,t),this.Nt(e,t),this.Pn(e,t,n))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.uo(e,e=>{for(let n of e.f)t(n)})}uo(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let r=n.u?.get(e);void 0!==r&&t(r)})}en(e,t,n){if(e.l.n===t.n)return n(e);let r=e.u?.get(t.h[e.l.n+1]);if(void 0!==r)for(let e of r.f)this.en(e,t,n)}sr(e){let t=e.r;null===t?G(this.ue,e.o,V).add(e):(t.we??(t.we=[])).push(e)}Tn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.He||(this.He=!0,queueMicrotask(this.Ho))}An(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Bt=!1;this.We=[],this._e=[],this.Ve=[],this.T.nt(this)}ho(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];v(n,`[@wcstack/state] ${_(e)}`),c.ct?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.An()}Et(){this.He=!1;let e=this.Kt;this.Kt=0;let t=0;if(!this.zt||this.Yt?this.Yn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Yn,0),this.zt=this.Yt=!1,t>100)101===t?this.ho(41,100):this.An();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.bn?this.An():this.ho(11,32),this.bn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Bt=!1,this.so(e)}let r=this._e,i=this.We;this._e=[],this.We=[];let s=!1,o=()=>{s=!0;for(let e of r){e.te=!1;for(let t of[e.N,...e.M??[]])if(null!==t&&t.w)try{t.xt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<i.length;t++){let n=i[t];!n.te||null===n.j==(0===e)||(n.te=!1,(null===n.Fn||n.Fn.w)&&this.ze(n))}if(!this.gn&&(this.Ye(),0===--this.yn&&this.go(),this.He)){this.Kt=t+1,this.wn++;try{for(;this.He;)this.Et()}finally{this.wn--}}},l=(r.length>0||i.some(e=>null!==e.j))&&0===this.wn?C("state",o):o();s||this.yn++,void 0!==l&&l.then(void 0,v)}}finally{this.gn=!1}this.zt=this.Yt=!1,this.Ye(),0===this.yn&&this.go(),e>0&&this.He&&(this.Kt=t+1)}}go(){c.me?.(this),this.Xo()}Rt(e,t){this.$t.push([e,t])}Jt(e,t,n,r){this.Rt(e,{o:{t:t},c:n,on:()=>r})}ze(e){try{e.apply()}catch(t){return void this.$t.push([t,e])}null!==this.Me&&this.yo(e.o,e.r)}yo(e,t){let n=G(this.Me,e.t,J);null!==t&&n.push(this.H(t))}Rn(){this.Me="function"==typeof this.target.$renderedCallback?new Map:null}Ye(){let e=this.Me;if(null!==e&&e.size>0){this.Me=new Map;let t,n=[...e.keys()],r={};for(let[t,n]of e)n.length>0&&(r[t]=n);this.Ce++;try{t=this.$e("$renderedCallback",[n,r])}catch(e){v(e)}Y(t)?t.then(this.Gn,e=>{this.Gn(),v(e)}):this.Ce--}if(0===this.$t.length)return;let t=this.$t;this.$t=[];let n=this.target.$errorCallback;for(let[r,i]of t){c.Ge?.(this,r,i);let t=i.o.t,s=i.on();if("function"==typeof n)try{let e=this.$e("$errorCallback",[r,{path:t,bindingType:s,node:i.c}]);Y(e)&&e.then(void 0,v)}catch(e){v(e)}else v(r,`[@wcstack/state] ${_(12,i.name?[s,t,i.name,i.i]:[s,t])}`,i.c)}}$e(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Nn(n,null,t):void 0}wo(e,t,n){if(0===e.n)return void n(null,[]);let r=[],i=(s,o)=>{let l=e.h[s];this.read(l,o);let a=this.qe(o,l),u=t=>{r.push(t.y),s===e.n?n(t,r):i(s+1,t),r.pop()};for(let e of s-1<t.length?[a.f[t[s-1]]]:a.f)void 0!==e&&u(e)};i(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.kn("$getAll",e,n,t,!1);let r=t;if(void 0===r){r=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let i=ne(t,n,e);if(null===i)break;r.push(i.y)}0===r.length&&$(6,[e])}}let i=[];return this.wo(n,r,e=>i.push(this.read(n,e))),i}vn(e,t,n,r){Array.isArray(t)||$(9,[e]),this.Be>0&&$(8);let i=this.o(e,!0);this.kn("$setAll",e,i,t,!1);let s=[];this.wo(i,t,(e,t)=>s.push([e,t.slice()]));let o=!0===r?.spread;o&&(!Array.isArray(n)||n.length!==s.length)&&$(10,[e,s.length]);let l=0;for(let e=0;e<s.length;e++){let[t,r]=s[e],a="function"==typeof n?n(this.v(i,t),...r):o?n[e]:n;void 0!==a&&(this.A(i,t,a),l++)}return l}kn(e,t,n,r,i){let s=r.length;(s>n.n||i&&s<n.n)&&$(i?901:902,[e,t,n.n,s])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en"},se=new Map,oe=new Set(["if","elseif","else","for"]),le=new Set([E,"if","elseif","for","..."]),ae=new Set([x,P,"style","command",T,"state"]);function ue(e){let t=function(e){return H(e,";")}(e).map(I).filter(e=>e.length>0).map(e=>{let t=R(e,":");-1===t&&$(101,[e]);let n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),i=n.split("#")[0].split("|")[0].trim();if(le.has(i)){let t;return i!==n&&$(102,[e,i]),i===E?(r.length>0&&$(103,[e]),t={et:"#else",tt:[]}):"..."===i?(0===r.length&&$(104,[e]),t=F(r),t.tt.length>0&&$(105,[e])):(t=F(r),"for"===i&&t.tt.length>0&&$(121,[e])),{Ee:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===x||i===P)&&$(122,[e,i]);let s=F(r),o=function(e){let[t,n]=W(e,"input",se),r=t.split("#").map(I);r.length>2&&$(115,[t]);let[i,s]=r,o=i.split(".").map(I);return!(o.length>1&&""===o[0])&&(0===i.length||o.some(e=>0===e.length))&&$(116,[e]),{Ee:i,Ne:o,rn:s?s.split(",").map(I):[],D:n}}(n),[l]=o.Ne;if(""===l&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||ae.has(e[0]))&&$(106,[n]),{...o,Ee:e.join("."),Ne:e,...s,b:"prop"}}return{...o,...s,b:"radio"===i||"checkbox"===i?i:l===T||l.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>oe.has(e.b))&&$(201,[e]),t}var ce=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],he=new Map,de=new Map;function fe(e){for(let t of Object.keys(e))he.set(t,{...e[t]});de.clear()}function pe(e){return he.has(e)}function me(e){$(26,[e])}function ge(e){$(27,[e])}function ye(e,t){$(28,[e,t])}function be(e,t){$(29,[e,t])}function we(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return we(e)||ge(t),Number(e)}function _e(e,t,n){return ve(e?.[t]??me(n),n)}function $e(e,t){return void 0!==t&&t.length>0?t[0]:e}var ke=(e,t)=>({factory:n=>{let r=_e(n,0,e);return n=>("number"!=typeof n&&ye(e,n),t(n,r))},arity:[1,1]}),Se={eq:{factory:(e,t)=>{let n=e?.[0]??me("eq"),r=$e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(we(n)||ge("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??me("ne"),r=$e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(we(n)||ge("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:ke("lt",(e,t)=>e<t),le:ke("le",(e,t)=>e<=t),gt:ke("gt",(e,t)=>e>t),ge:ke("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ne=!1;function Ae(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ce(e){return 0===e.length?null:(Ne||(Ne=!0,fe(Se)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=de.get(r);if(typeof i<"u")return i;let s=he.get(e);void 0===s&&function(e,t){ce.includes(e)&&w(`[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),$(501,[e],e,t)}(e,he.keys());let[o,l]=s.arity;t.length<o&&$(601,[e,o,t.length]),t.length>l&&$(602,[e,l,t.length]);let a=s.factory(t,n);return de.set(r,a),a}(e.qn,e.args,e.literals)))}var Ee=Symbol.for("wcstack.trustedTypes.policy");function Te(){let e=globalThis[Ee];return null!==e&&"object"==typeof e?e:null}function xe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Pe(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Te(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Oe=Symbol.for("wcstack.state.view-transition-naming"),Le=new WeakSet;function Me(){let e=A("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Ie=new WeakMap,je=e=>e.customElementRegistry??customElements;function Re(e,t,n,r,i,s=!1){let o=n.localName;if(!o.includes("-"))return i(null);let l=je(n);if(!s&&!n.isConnected&&void 0===l.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>Re(e,t,n,r,i,!0));let a=()=>{let e=l.get(o);l.upgrade(n),i(e?function(e){if(Ie.has(e))return Ie.get(e);let t=e.wcBindable,n=null;if(null!==t&&"object"==typeof t&&"wc-bindable"===t.protocol&&Number.isInteger(t.version)&&t.version>=1){n={properties:new Map,inputs:new Set,commands:new Set};for(let e of t.properties??[])n.properties.set(e.name,{event:e.event,getter:"function"==typeof e.getter?e.getter:null,bo:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return Ie.set(e,n),n}(e):null)};if(!s&&void 0!==l.get(o))return a();null!==r&&!r.w||function(e,t,n){let r=n;null!==t&&(t.Pt??=[]).push(()=>{r=null}),e.then(()=>r?.())}(l.whenDefined(o),r,()=>{try{a()}catch(r){ze(e,r,t,n)}e.ve()})}function He(e,t,n,r,i=t.o,s,o,l){let a=l.properties.get(r)??null,u=l.inputs.has(r),h=e.Ht;h&&null===a&&!u&&$(38,[r]);let d=t.U;(null===a?"element"===d||"auto"===d:!u&&("state"===d||"auto"===d))&&$(39,[d,r]),"connect"===t.X&&null===a&&$(40,[r]);let f=h&&null!==a&&!u,p=new Ke(e,De,n,r,i,s,o,t.x,void 0);p.D=t.D,et(e,p,!f),null!==a&&!t.ro&&n.addEventListener(a.event,t=>{let i;null!==a.getter?i=a.getter(t):(i=t.detail,a.bo||c.detail?.(n,r,i)),(!p.On||!Object.is(i,p.value))&&(i=Ae(p.D,i),null===p.x&&(p.value=i),e.A(p.o,p.r,i,a.bo,!0))});let m=d??(f?"element":"state");if("state"===m)f||e.ze(p);else if("element"===m||"auto"===m){let i=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==e.v(p.o,p.r))return void(f||e.ze(p));let t=n[r];null===p.x&&(p.value=t),e.A(p.o,p.r,t,!1,!0)};"connect"!==t.X||n.isConnected?i():Promise.resolve().then(i)}return p}function We(e,t,n){$(e,[t.localName,n])}var Ue=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),De=11,Fe=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],ze=(e,t,n,r)=>e.Jt(t,n.o?.t??n.Tt,r,Fe[n.i]),qe=Symbol();function Be(e,t,n){let r=t.U;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.q:qe}var Ke=class{constructor(e,t,n,r,i,s,o,l,a,u=null){this.te=!1,this.D=null,this.On=!1,this.engine=e,this.i=t,this.c=n,this.name=r,this.o=i,this.r=s,this.Fn=o,this.x=l,this.value=a,this.j=u}on(){return Fe[this.i]}apply(){if(null!==this.j)return void this.j.xt();let e=Ae(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===De||8===this.i||xe(this.name)))return;if(this.value===qe)return void(this.value=e);let t=this.c;if(this.i!==De)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ve(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.On=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.On=!1}}}sn(){return Ae(this.D,this.c.value)}ar(){let e,t=this.c,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let r=this.sn(),i=n.v(this.o,this.r),s=Array.isArray(i)?i:[],o=s.includes(r);if(t.checked?o:!o)return;e=o?s.filter(e=>e!==r):[...s,r]}else e=Ae(this.D,t[this.name]),this.value=NaN;n.A(this.o,this.r,e,!1,!0)}},Ge=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Ve(e,t,n,r){switch(e){case 0:return void(t.data=null==r?"":String(r));case 1:return void(Ge(n)?t[n]="innerHTML"===n?Pe(r):null==r?"":String(r):xe(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Pe(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Je]=[n,r])));case 8:return void(t.innerHTML=Pe(r));case 2:return null!=r&&"boolean"!=typeof r&&$(401,[n,typeof r]),void t.classList.toggle(n,!0===r);case 3:return void(null==r?t.removeAttribute(n):t.setAttribute(n,String(r)));case 4:return void(n.includes("-")?null==r?t.style.removeProperty(n):t.style.setProperty(n,String(r)):t.style[n]=null==r?"":String(r))}}var Je=Symbol();function Qe(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Je];void 0!==n&&(t[n[0]]=n[1])}var Ye=class{constructor(e,t,n,r){this.w=!0,this.we=null,this.u=null,this.Pt=null,this.In=null,this.r=e,this.ut=t,this.L=n,this.C=r}tr(e,t){let n=t.target,r=this.C,i=[],s=null;for(let t of r.Oe){if(t.name!==e)continue;let o=r.jn[t.c],l=ut(null===this.L?this.ut:this.L[o[0]],o,1);l.contains(n)&&(l!==s&&i.unshift([]),i[0].push(t),s=l)}for(let e of i){for(let n of e)n.Cn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.ut:this.L[this.L.length-1]}Re(){let e=this.In;return(null===e?null:e.Dn(this.ut))??this.ut}insertBefore(e,t){let n=this.s;for(let r=this.Re();;){let i=r.nextSibling;if(e.insertBefore(r,t),r===n)return;r=i}}So(){null===this.L?this.ut.remove():ct(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Pt)for(let e of this.Pt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Tn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Xe=class extends Ye{constructor(e,t,n,r){super(e,t,n,r),this.$o=0,this.V=null,this.pe=0===r.Xe.length?null:new Array(2*r.Xe.length)}Eo(e,t){let n=this.V??=new Array(this.C.Xe.length),r=n[t];if(void 0===r){let i=this.C.Xe[t],s=this.pe;r=n[t]=new Ke(e,i.i,s[2*t],i.name,i.o,this.r,this,i.x,s[2*t+1])}return r}mo(e,t){let n=this.C.Xe;for(let r=0;r<n.length;r++)n[r].o.ee(t)&&e.tn(this.Eo(e,r))}Pe(e){let t=this.r;t.N===this&&(t.N=null),super.Pe(e)}};function Ze(e,t,n,r){let i=te(n,t.n);try{return e.qe(i,t)}catch(n){return e.Jt(n,t.t,r,"for"),null===i?e.oe.get(t):i.u.get(t)}}function et(e,t,n){n&&e.sr(t);let r=t.Fn;null!==r&&(r.we??=[]).push(t)}var tt=null;function nt(){let e=tt;return tt=null,e}var rt=-1;function it(e,t,n,r,i=null){let s,o=t.jn,l=t.build,a=t.No,u=null,h=c.Te?.(t,null===r?i:r.S,null!==r),d=!h&&t.Ln,f=h?document.createDocumentFragment():(d?t.root:t.ln).cloneNode(!0);if(!h)for(let e=0;e<l.length;e++){let t=l[e];a[t]=ut(f,o[t],d?1:0)}d?s=f:(u=h||[...f.childNodes],s=u[0]);let p,m=null;if(null!==r?(p=m=new Xe(n,s,u,t),null===r.map?n.N=m:r.map.set(n,m)):p=new Ye(n,s,u,t),rt>=0&&function(e,t,n,r){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 s=i?.style;if(null===i||void 0===s||Le.has(i))return;let o=globalThis[Oe]??={counter:0,assigned:0,warned:!1};o.assigned>=r?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${_(25,[r])}`)):(Le.add(i),o.assigned++,s.setProperty("view-transition-name",`wcs-${n}-${++o.counter}`),s.setProperty("view-transition-class",`wcs-${n}`))}(s,u,null!==r?"row":"branch",rt),t.Oe.length>0){let t=e.Kn;if(null===u)s[t]=p;else for(let e of u)1===e.nodeType&&(e[t]=p)}let g=t.cr,y=e.Me,b=t.ur?a.slice(0,o.length):a,w=null===m?null:m.pe;if(null!==w){let e=t.Xe;for(let t=0;t<e.length;t++)w[2*t]=b[e[t].c],w[2*t+1]=e[t].q}for(let r=0;r<g.length;r++){let i=g[r],o=b[i.c],l=i.F;if(l>=0&&null!==w){let r=m.V?.[l];if(void 0!==r){r.te=!1,e.ze(r);continue}try{let t=Ae(i.x,e.read(i.o,n));t!==i.q&&(Ve(i.i,o,i.name,t),w[2*l+1]=t),null!==y&&e.yo(i.o,n)}catch(t){e.Rt(t,m.Eo(e,l))}continue}switch(i.i){case 6:{let t=new at(e,i.C,Ze(e,i.o,n,o),o);(p.u??=[]).push(t),o===s&&(p.In=t),t.xt();break}case 7:{let t=ot(e,i.K.map(e=>({C:e.C,o:e.o,x:e.x,S:b[e.c]})),n,p);(p.u??=[]).push(t),o===s&&(p.In=t);break}default:try{st(e,i,o,n,p)}catch(t){ze(e,t,i,o)}}}return tt=p,f}function st(e,t,n,r,i){let s=n;switch(t.i){case 5:return void function(e,t,n,r,i){let s=n.Cn,o=e=>s(e,r);if(n.ot){let r=e.fo(n.name),i=t[r];t[r]=void 0===i?o:e=>{i(e),o(e)},n.xe&&t.addEventListener(n.name,e=>e.bubbles||o(e))}else t.addEventListener(n.name,o),n.ko&&null!==i&&(i.Pt??=[]).push(()=>t.removeEventListener(n.name,o))}(e,n,t,r,i);case 12:return void Re(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name,o=e.command(t.Tt.slice(9)),l=null===i?c.lr?.(n,s):null;l||(null===i&&We(1202,n,`command.${s}`),i.commands.has(s)||$(1203,[n.localName,s]));let a=new WeakRef(n),u=o.subscribe((...e)=>{let t=a.deref();if(void 0!==t)return t.isConnected?l?l(t,e):t[s](...e):void 0;u()});null!==r&&(r.Pt??=[]).push(u)}(e,t,s,i,n));case 13:return void Re(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name;null===i&&We(1202,n,`eventToken.${s}`);let o=i.properties.get(s);void 0===o&&$(1204,[n.localName,s]);let l=t.Tt;n.addEventListener(o.event,n=>{t.At&&n.preventDefault(),t.Ft&&n.stopPropagation();try{e.nr(l,n,r)}catch(e){v(e)}})}(e,t,s,r,n))}let o=t.o,l=te(r,o.n);if(14===t.i)return void Re(e,t,s,i,n=>function(e,t,n,r,i,s){null===s&&We(1501,n,`"...: ${t.o.t}"`);let o=new Set([...s.properties.keys(),...s.inputs]);for(let l of o){if(t.vo?.includes(l))continue;let o=e.o(`${t.o.t}.${l}`),a=0===o.n?null:r;He(e,{...t,U:null,X:null},n,l,o,a,i,s)}}(e,t,s,l,i,n));if(t.xe&&1===t.i)return void Re(e,t,s,i,n=>function(e,t,n,r,i,s){if(null!==s)return void He(e,t,n,t.name,t.o,r,i,s);let o=new Ke(e,1,n,t.name,t.o,r,i,t.x,Be(e,t,r));o.D=t.D,!c.dr?.(o,t.ro)&&(et(e,o,!0),e.ze(o))}(e,t,s,l,i,n));let a=new Ke(e,t.i,n,t.name,o,l,i,t.x,Be(e,t,l));a.D=t.D,et(e,a,!0),e.ze(a),null!==t.Ot&&n.addEventListener(t.Ot,()=>a.ar())}function ot(e,t,n,r){let i=new lt(e,t,n),s=null;for(let o of t){if(null===o.o)continue;let t=o.o,l=new Ke(e,7,o.S,"if",t,te(n,t.n),r,null,void 0,i);et(e,l,!0),null===r&&i.ue.push(l),s??=l}return e.ze(s),i}var lt=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}Dn(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}xt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let r=this.K[n];if(null===r.o||Ae(r.x,e.read(r.o,te(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(rt=Me(),null!==this.I&&(this.I.So(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],r=it(e,n.C,this.r,null,n.S);this.I=nt();let i=n.S.parentNode;i.insertBefore(r,n.S),Qe(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Tn(e);null!==this.I&&this.I.Pe(this.engine)}},at=class{constructor(e,t,n,r){this.w=!0,this.Ae=[],this.engine=e,this.C=t,this.l=n,this.S=r,null===n.N?(n.N=this,this.map=null):((n.M??=[]).push(this),this.map=new Map)}Dn(e){return 0===this.Ae.length?null:this.Ae[0].Re()}Ct(e){return null===this.map?e.N:this.map.get(e)??null}Lt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Pe(this.engine)}xt(){let e=this.engine,t=this.l.f,n=this.Ae;rt=Me();let r=t.length,i=n.length,s=this.S,o=s.parentNode;if(0===r){if(i>0){let e=n[0].Re(),t=n[i-1].s,r=[];for(let n=o.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==s&&3!==n.nodeType){r=null;break}r.push(n)}null!==r?o.replaceChildren(...r):ct(e,t);for(let e=0;e<i;e++)this.Lt(n[e])}return void(this.Ae=[])}let l=new Array(r),a=0;for(;a<r&&a<i&&this.Ct(t[a])===n[a];)l[a]=n[a],a++;let u=i-1,c=r-1;for(;u>=a&&c>=a&&this.Ct(t[c])===n[u];)l[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],r=t.r;r.w&&this.Ct(r)===t?t.$o=e:(t.So(),this.Lt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),h=!1;if(i>0)for(let e=0;e<n;e++){let n=this.Ct(t[a+e]);null!==n&&n.w?(u[e]=n.$o,h=!0):u[e]=-1}let d=c+1<r?l[c+1].Re():s;if(h){let r=function(e){let t=e.length,n=new Uint8Array(t),r=new Int32Array(t).fill(-1),i=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let s=0,o=i.length;for(;s<o;){let n=s+o>>1;e[i[n]]<t?s=n+1:o=n}s>0&&(r[n]=i[s-1]),i[s]=n}let s=i.length>0?i[i.length-1]:-1;for(;s>=0;)n[s]=1,s=r[s];return n}(u),i=d;for(let s=n-1;s>=0;s--){let n=t[a+s],u=this.Ct(n);null!==u&&u.w?0===r[s]&&u.insertBefore(o,i):(o.insertBefore(it(e,this.C,n,this),i),u=nt()),l[a+s]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(it(e,this.C,t[r],this)),l[r]=nt();o.insertBefore(n,d)}}this.Ae=l,Qe(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function ut(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function ct(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var ht=()=>ie.bindAttributeName;function dt(){return{c:0,i:1,name:"",o:null,x:null,q:t,Cn:null,C:null,K:null,D:null,Ot:null,xe:!1,U:null,X:null,ro:!1,At:!1,Ft:!1,Tt:null,vo:null,F:-1,ot:!1,ko:!1}}var ft=["state","element","auto","none"],pt=["call","connect"],mt="$command.";function gt(e,t,n){O.test(t)&&(null===n&&$(1401,[t,Number(t.slice(1))]),t=`${n.t}.*.${t}`);let r=e.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&$(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(t,n)),i=null===n?0:n.n+1;r.n>i&&$(1401,[r.t,r.n,i]);for(let e=1;e<=r.n;e++){let t=e===i?n:n.h[e];r.h[e]!==t&&$(1403,[r.t,r.h[e].t,t.t])}return c.xo?.(e,r),r}var yt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),bt=e=>8===e.i||yt(e)||1===e.i&&Ge(e.name);function wt(e){$(202,[e])}function vt(e,t,n,r,i){let s=ue(t).map(t=>function(e,t,n,r,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),r=null,i=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Ht||$(31);let s=n.slice(0,t).trim(),o=n.slice(t+1).trim(),l="init"===s;!l&&"sync"!==s&&$(33,[s,n]),null!==(l?r:i)&&$(34,[s]),(l?ft:pt).includes(o)||$(35,[s,o]),l?r=o:i=o}return{ro:t.includes("ro"),At:t.includes("prevent"),Ft:t.includes("stop"),event:n?n.slice(2):null,U:r,X:i}}(e,t.rn),o=r.localName.includes("-"),l=t.Ne,a=t.et;if("event"===t.b){if(null!==s.U&&"none"!==s.U&&$(36),"eventToken"===l[0])return{...dt(),c:i,i:13,name:l.slice(1).join("."),Tt:a,xe:o,At:s.At,Ft:s.Ft};let n=a.startsWith(mt)?a.slice(9):null,{At:r,Ft:u}=s,h=t.Ee.slice(2),d=t.rn.includes("direct"),f=!d&&Ue.has(h);f&&e.fo(h);let p=t=>{v(t),f&&c.handlerThrew?.(e,a,h)};return{...dt(),c:i,i:5,name:h,ot:f,xe:o,ko:d,Cn(t,i){r&&t.preventDefault(),u&&t.stopPropagation();try{if(null!==n)e.or(n,t,i);else{let n=e.ir(a,t,i);Y(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...dt(),c:i,i:14,o:gt(e,a,n),xe:o};if("command"===l[0]&&l.length>1)return a.startsWith(mt)||$(1201,[t.Ee,a]),{...dt(),c:i,i:12,name:l.slice(1).join("."),Tt:a,xe:o};let u=gt(e,a,n),h={...dt(),c:i,i:1,name:t.Ee,o:u,x:Ce(t.tt),D:Ce(t.D),ro:s.ro,U:s.U,X:s.X};if("radio"===t.b||"checkbox"===t.b)return("element"===s.U||"auto"===s.U)&&$(37,[t.b,s.U]),h.i="radio"===t.b?9:10,s.ro||(h.Ot=s.event??"input"),h;if(l.length>1){let e=l.slice(1).join("."),t=l[0];if("class"===t||"attr"===t||"style"===t)return h.U=null,h.name=e,"class"===t?(h.i=2,h.q=r.classList.contains(e)):h.i="attr"===t?"srcdoc"===e&&"iframe"===r.localName?1:3:4,h}return"html"===t.Ee?(h.i=8,h):(h.name="text"===t.Ee?"textContent":t.Ee,h.xe=o&&!xe(h.name),!o&&!s.ro&&function(e,t){let n=e.localName;if("input"===n){let n=(e.getAttribute("type")||"text").toLowerCase();return"button"!==n&&(("radio"===n||"checkbox"===n)&&"checked"===t||"value"===t||"valueAsNumber"===t||"valueAsDate"===t)}return("select"===n||"textarea"===n)&&"value"===t}(r,h.name)&&(h.Ot=s.event??("select"===r.localName?"change":"input")),h)}(e,t,n,r,i));for(let e=0;e<s.length;e++)14===s[e].i&&(s[e].vo=s.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return s}var _t=/\{\{([\s\S]+?)\}\}/g;function $t(e){let t=e.data,n=[],r=0;_t.lastIndex=0;for(let i=_t.exec(t);null!==i;i=_t.exec(t)){let s=_t.lastIndex-i[0].length;s>r&&e.before(t.slice(r,s));let o=e.ownerDocument.createTextNode("");e.before(o),n.push({c:o,fr:i[1].trim()}),r=_t.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function kt(e,t,n,r){let i=function(e){return{Ee:"textContent",Ne:["textContent"],rn:[],D:[],...F(e),b:"text"}}(t);return{...dt(),c:r,i:0,o:gt(e,i.et,n),x:Ce(i.tt),q:""}}function St(e){let t=e.getAttribute(ht());if(null===t)return null;let n=ue(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var Nt=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function At(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:gt(e,r.et,n),x:"else"===r.b?null:Ce(r.tt)}),i=[r(t,St(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=St(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(r(e,t)),"else"===t.b))break}return i}var Ct=new WeakSet;function Et(e,t,n,r,i,s,o,l){let a=(t,n)=>{let i=document.createComment(n);return t.replaceWith(i),r&&c.Bn?.(e,i,t),i},u=t=>{for(let h=0;h<t.length;h++){let d=t[h];if(null!==d.parentNode)if(1===d.nodeType){let t=d,l=t.localName;if(t.hasAttribute(ht()+"-ignore"))continue;if(r){if("script"===l||"style"===l||Ct.has(t))continue;if(Ct.add(t),l===ie.tagNames.state){u([...t.childNodes]);continue}}let h="template"===l?St(t):null;if(null!==h){if("for"===h.b){let r=gt(e,h.et,n),s=Pt(e,t,r,!0);i(a(t,ie.commentForPrefix),r,s)}else"if"===h.b?s(At(e,t,n).map((t,r)=>({C:Pt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,Nt(r,t))}))):wt(h.b);continue}let f=t.getAttribute(ht()),p=null===f?null:vt(e,f,n,t,0),m="noscript"!==l&&"iframe"!==l&&!p?.some(bt)&&!c.Ro?.(t);try{r&&m&&u([...t.childNodes])}finally{null!==p&&o(t,p)}!r&&m&&u([...t.childNodes])}else if(3===d.nodeType&&e._t&&d.data.includes("{{")&&!Ct.has(d))for(let{c:e,fr:t}of $t(d))l(e,t);else if(8===d.nodeType){let e=Tt.exec(d.data),t=e&&d.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");d.replaceWith(t),l(t,e[1])}}}};u(t)}var Tt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,xt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Pt(e,t,n,r){let i=document.importNode(xt(t),!0),s=[],o=[],l=e=>s.push(e)-1;Et(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...dt(),c:l(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({c:l(e.S),C:e.C,o:e.o,x:e.x}));o.push({...dt(),c:t[0].c,i:7,K:t})},(e,t)=>{let n=l(e);for(let e of t)yt(e)&&$(203,[e.name]),e.c=n;o.push(...t),e.removeAttribute(ht())},(t,r)=>{o.push(kt(e,r,n,l(t)))}),It(i,new Set(s),!0);let a=s.map(e=>function(e,t){let n=[];for(let r=t;r!==e;r=r.parentNode){let e=0;for(let t=r.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(i,e)),u=1===i.childNodes.length&&8!==i.firstChild.nodeType,c=o.some(e=>6===e.i||7===e.i),h=[],d=new Set,f=[],p=[],m=r?n.n+1:-1;for(let e of o){if(5===e.i&&e.ot&&!e.xe&&!Ot(s[e.c],i)){f.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Lt(e)&&(e.F=h.push(e)-1),7===e.i)for(let t of e.K)d.add(t.c);else d.add(e.c)}let g=[...d].sort((e,t)=>e-t);return{ln:i,root:u?i.firstChild:null,jn:a,build:g,Oe:f,cr:p,Ln:u,ur:c,No:[],Xe:h}}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 Lt(e){if(null!==e.U)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.xe&&null===e.Ot;default:return!1}}var Mt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function It(e,t,n){for(let r=e.firstChild;null!==r;){let e=r.nextSibling;3===r.nodeType?n&&!t.has(r)&&""===r.data.trim()&&r.remove():1===r.nodeType&&It(r,t,Mt.has(r.localName)),r=e}}var jt=new WeakMap;function Rt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,jt.set(t,e),Wt(e,[...n.childNodes]),e.Ye()}function Ht(e,t,n){try{let r="template"===t.localName?St(t):null;null!==r&&!n&&$(204,[r.b]),Wt(e,[t])}catch(e){v(e)}e.Ye()}function Wt(e,t){Et(e,t,null,!0,(t,n,r)=>{new at(e,r,Ze(e,n,null,t),t).xt()},t=>{ot(e,t,null,null)},(t,n)=>{c.Bn?.(e,t,n);for(let r of n)st(e,r,t,null,null)},(t,n)=>{c.Bn?.(e,t,n),st(e,kt(e,n,null,0),t,null,null)})}var Ut=Symbol.for("wcstack.binder"),Dt=Symbol.for("wcstack.binder.pending"),Ft=Symbol.for("wcstack.binder.taken"),zt=new Map;function qt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=jt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?zt.set(e,t):Ht(n,e,t?.range)}function Bt(){let e=[...zt];zt.clear();for(let[t,n]of e)qt(t,n);!function(){let e=function(){let e=globalThis[Ut];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),r=function(){let e=globalThis,t=e[Ft];return void 0===t&&(t=new WeakSet,e[Ft]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Kt=class{constructor(){this.name="dirty",this.Z=(e,r)=>{if(0===e.n){let r=e.Y;return r!==t&&r!==n&&(e.Y=n,!0)}let i=null===r?null:r.vt;if(null===i)return!1;let s=i[e.F];return s!==t&&s!==n&&(i[e.F]=n,!0)}}er(e,t,n){null!==t.getter&&this.Z(t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}Ko(e,t){let n=t.l.o.Dt;if(null!==n)for(let r of n)r.n===t.l.n?e.at(r,t,this.Z):e.en(t,r,t=>e.at(r,t,this.Z))}ke(e,t,n){this.Z(t,n),c.Se?.(e,t,n),e.Nt(t,n),e.Pn(t,n,this.Z)}zo(e,i,s){let o=0===i.n;if(!o&&null===s)return;let l=o?null:s.vt??=new Array(e.Le).fill(t),a=null===l?i.Y:l[i.F];if(a!==t&&a!==n&&a!==r&&(null===l||i.F in l))return a;a=r;try{return a=e.Yo(i,null===l?null:s)}finally{null===l?i.Y=a:l[i.F]=a}}Gt(e){e.vt=null}nt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===n&&(t.Y=r):e.nn(t.h[t.n],e=>{let i=e.vt;null!==i&&i[t.F]===n&&(i[t.F]=r)}))}},Gt=0,Vt=new WeakMap;function Jt(e,t=e.getRootNode()){Vt.set(t,[...Vt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Qt(e){let t=Vt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Vt.get(e)!==t?Qt(e):Promise.reject(r.errors[0]):void 0)}var Yt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Yt{constructor(){super(),this.engine=null,this.Mn=!1,this.Ge=!1,this.q=null,this.Je=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.Po=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Qt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Mn){if(null!==this.Je)return void this.Je.Qe();Jt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!jt.has(t)&&jt.set(t,e),Bt(),c.element?.(e,"back"),this.To("$connectedCallback",50,()=>{this.isConnected&&c.element?.(e,"connected")})}return}this.Mn=!0;let e=this.getRootNode(),t=c.dt?.(this,e);if(t)return this.Je=t,!t.Ao&&this.parentNode instanceof ShadowRoot&&Jt(this),void(void 0===t.Wt?this.Fo():t.Wt()).then(e=>(this.loaded=!0,t.start(e,()=>this.Oo()))).then(()=>{this.an(),this.cn()},e=>this.Rt(e,t.Ao));this.start(e),Jt(this)}disconnectedCallback(){if(null!==this.Je)return void this.Je.Wn();let e=this.engine;if(null===e)return;let t=e.root;jt.get(t)===e&&jt.delete(t),Jt(this,t),this.To("$disconnectedCallback",51),c.element?.(e,"disconnected")}setInitialState(e){if(this.Ge&&$(14),this.loaded)this.Je.reset(e);else if(null===this.engine)if(null!==this.un){let t=this.un;this.un=null,t(e)}else this.q=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&$(15),"readonly"===e&&n.Be++;try{t(n.proxy)}finally{"readonly"===e&&n.Be--}}async createStateAsync(e,t){let n=this.engine;null===n&&$(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let r=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&$(8),r(...e)):r},set(){$(8)}}))}async Fo(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${_(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||$(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let r=this.querySelector('script[type="module"]');return null!==r?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let r="function"==typeof URL.createObjectURL,i=r?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Gt}`);try{return(await(import(i))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?_(42):_(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),r&&URL.revokeObjectURL(i)}}(r):null!==this.q?Promise.resolve(this.q):new Promise(e=>{this.un=e})}async start(e){try{let t=e.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||t?.hasAttribute("data-wc-definition"))&&b("scopes","<wcs-state>");let n=await this.Fo(),r=y(n);if(r&&await r,this.getRootNode()!==e)return this.q=n,this.Mn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&b("ssr","enable-ssr");let i=jt.get(e)?.element;i?.isConnected&&(i.V||i.Je)&&$(47);let s=new re(n,new Kt);s.element=this,this.engine=s,c.element?.(s,"mounting"),Rt(s,e),Bt(),s.Rn(),this.Oo(),await s.$e("$connectedCallback"),this.isConnected&&c.element?.(s,"connected"),this.cn()}catch(e){this.Ge=!this.V,this.Rt(e)}}Oo(){this.V=!0,this.an()}Rt(e,t){this.Ye(this.V?50:49,e),this.an(),t?this.cn():this.Po(e)}Ye(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);v(t,`[@wcstack/state] ${_(e,[this.localName,...n])}`)}To(e,t,n){(async()=>this.engine.$e(e))().then(n,e=>this.Ye(t,e))}},Zt=[];function en(){return(Zt=Zt.filter(e=>e.deref())).map(e=>e.deref())}var tn,nn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},rn="en";function sn(){if(ie.locale!==tn){tn=ie.locale;try{rn=Intl.getCanonicalLocales(tn)[0]}catch{console.warn(`[@wcstack/state] ${_(48,[tn])}`),rn="en"}}return rn}var on=["full","long","medium","short"];function ln(e,t){let[n,r,i]=(e??[]).map(e=>e||void 0);!r&&on.includes(n)?[n,r]=[void 0,n]:!r&&!i&&/\/|^UTC$/.test(n)&&([n,i]=[void 0,n]),r&&!on.includes(r)&&function(e,t){$(52,[e,t])}(t,r);try{i&&new Intl.DateTimeFormat(void 0,{timeZone:i})}catch{$(54,[t,i])}return[n,r,i]}var an=e=>String(e).padStart(2,"0"),{eq:un,ne:cn,not:hn,lt:dn,le:fn,gt:pn,ge:mn,falsy:gn,truthy:yn,boolean:bn}=Se,wn={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ye("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ye("locale",e),e.toLocaleString(t??sn()))},arity:[0,1]},upper:{factory:nn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:nn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:nn(()=>e=>{let t=String(e);return t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:nn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:nn(e=>{let t=[_e(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:nn(e=>{let t=_e(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:nn(e=>{let t=_e(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:nn(e=>{let t=_e(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:nn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:nn(e=>{let t=_e(e,0,"truncate"),n=e?.[1]??"…";return e=>{let r=String(e);return r.length<=t?r:r.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||$(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ye("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ye("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ye("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ye("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:nn(e=>{let t=e?.[0]??me("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:nn(e=>{let[t,n,r]=ln(e,"date"),i=(n||r)&&{dateStyle:n,timeZone:r};return e=>(e instanceof Date||be("date",e),e.toLocaleDateString(t??sn(),i))}),arity:[0,3]},time:{factory:nn(e=>{let[t,n,r]=ln(e,"time"),i=(n||r)&&{timeStyle:n,timeZone:r};return e=>(e instanceof Date||be("time",e),e.toLocaleTimeString(t??sn(),i))}),arity:[0,3]},datetime:{factory:nn(e=>{let[t,n,r]=ln(e,"datetime"),i=(n||r)&&{dateStyle:n,timeStyle:n,timeZone:r};return e=>(e instanceof Date||be("datetime",e),e.toLocaleString(t??sn(),i))}),arity:[0,3]},ymd:{factory:nn(e=>{let t=e?.[0]??"-";return e=>(e instanceof Date||be("ymd",e),`${e.getFullYear()}${t}${an(e.getMonth()+1)}${t}${an(e.getDate())}`)}),arity:[0,1]},hms:{factory:nn(e=>{let t=e?.[0]??":";return e=>(e instanceof Date||be("hms",e),`${an(e.getHours())}${t}${an(e.getMinutes())}${t}${an(e.getSeconds())}`)}),arity:[0,1]},eq:un,ne:cn,not:hn,lt:dn,le:fn,gt:pn,ge:mn,add:ke("add",(e,t)=>e+t),sub:ke("sub",(e,t)=>e-t),mul:ke("mul",(e,t)=>e*t),div:ke("div",(e,t)=>e/t),mod:ke("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ye("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=_e(e,0,"clamp"),n=_e(e,1,"clamp");return e=>("number"!=typeof e&&ye("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:gn,truthy:yn,defaults:{factory:(e,t)=>{let n=$e(e?.[0]??me("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=$e(e?.[0]??me("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:bn,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??me("currency"),n=e?.[1],r={style:"currency",currency:t};try{new Intl.NumberFormat("en",r);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){$(53,[e])}(t)}return e=>("number"!=typeof e&&ye("currency",e),e.toLocaleString(n??sn(),r))},arity:[1,2]}},vn=!1,_n={name:"formats",hooks:c,install:function(){vn||(vn=!0,fe(wn))}};function $n(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let r=new Array(t.length+1),i=new Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let n=1;n<=e.length;n++){i[0]=n;for(let s=1;s<=t.length;s++){let o=e[n-1]===t[s-1]?0:1;i[s]=Math.min(r[s]+1,i[s-1]+1,r[s-1]+o)}for(let e=0;e<=t.length;e++)r[e]=i[e]}return r[t.length]}function kn(e,t){if(0===e.length)return"";let n=e.toLowerCase(),r=null,i=3;for(let e of t){let t=$n(n,e.toLowerCase(),2);t<i&&(r=e,i=t)}return null!==r?` Did you mean "${r}"?`:""}var Sn=" Validate statically: npx @wcstack/lint <file>.",Nn=["","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"],An=e=>{let t=Nn[e/100|0];return t?`[wcs/${t}] `:""},Cn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],En=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Tn=["","","class.","attr.","style."],xn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Pn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",On={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,r)=>`binding "${n?(Tn[r]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Pn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Pn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${En(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${En(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}${"string"==typeof t&&/^\d{4}-\d\d-\d\d$/.test(t)?`. A date-only string is a day, not a moment: new Date(${JSON.stringify(t)}) is midnight UTC, the day before west of Greenwich — new Date(y, m - 1, d) is that day where the page is`:""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"${/\/|^UTC$/.test(t)?` — a time zone is the third argument, after the locale and the style, and an empty argument keeps its default: ${e}(,,${t}), ${e}(en-US,long,${t})`:""}`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,54:(e,t)=>`filter ${e} takes an IANA time zone (Asia/Tokyo, America/New_York, UTC), not "${t}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&Cn.includes(t)?" 4.0 moved it to the state's $behavior.":""}`,45:()=>"a re-set state may not change $behavior: create the element again.",47:()=>'a second <wcs-state> on the same root: there is one state tree per root — graft a subtree with <wcs-state mount="path"> (v1\'s name="…" is gone: read the mounted state by its path).',48:e=>`the locale "${e}" (<html lang> or bootstrapState's locale) is not a language tag Intl takes (en-US, not en_US): the locale filters use "en".`,46:()=>'$features must be an array of add-on names (["temporal", "formats"]).',49:(e,...t)=>`${xn(e,t)} failed to initialize.`,50:(e,...t)=>`${xn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${xn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,r)=>`${e}("${t}") takes ${n} index(es), got ${r}.`,902:(e,t,n,r)=>`${e}("${t}") takes at most ${n} index(es), got ${r}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function Ln(e,t){let n=On[e];return void 0===n?`${An(e)}#${e} ${t.join(" ")}`:An(e)+n(...t)}var Mn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),In=[[/no loop level in common with the context/,"; pass indexes ([] for all)."],[/"([^"#]+)#([^"]*)" is not a filter name: a modifier list .* comes before the input filters/,' — write "<property>#$2|$1".'],[/\[wcs\/recursion-unsupported\]/," It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll — and only when the state declares a $recursion anchor."],[/must be single binding/,' Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).'],[/\[wcs\/wildcard-rank\] .* needs \d+ enclosing/,' Wrap it in that many "for" templates, or use $resolve(path, indexes) to name the row explicitly.'],[/\[wcs\/wildcard-rank\] .* ranges over the rows of/,' A "*" in a binding is the row of the loop around it: read a row of another list in a getter, with $resolve(path, indexes).'],[/\[wcs\/binding-type-expectation\] class\.([^ ]+)/,' Write "class.$1: path|truthy" to toggle on truthiness.'],[/path segments — the limit/," Every prefix of a path is interned, so the cost grows with the square of the depth."],[/\[wcs\/index-arity\] \$resolve/,' $resolve takes one index per "*"; $getAll / $setAll take at most that many (fewer expands the rest).'],[/"([^"#]+)#[^"]*" is not a filter name: "#" cannot appear in one/,' Modifiers belong on the left side of the binding, before the ":" — write "$1" here.']],jn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Rn(e,t,n){let r=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(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?kn(t,n):"");for(let[t,n]of In){let i=t.exec(e);null!==i&&(r+=n.replace(/\$(\d)/g,(e,t)=>i[Number(t)]))}let i=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==i&&(r+=` — write "${i[1]}#${i[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?r+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':ce.some(pe)||(r+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let s=/\[wcs\/([\w-]+)\]/.exec(e);return null!==s&&Mn.has(s[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=Sn),r}var Hn=new WeakMap,Wn=new WeakMap,Un=new WeakSet,Dn=new WeakSet;function Fn(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function zn(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 qn(e,t){let n=[];for(let e=t;null!==e;e=e.a)n.unshift(e);let r=t=>null===t?null:function(e,t){let n=t.t.split("."),r=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return r<0||n.indexOf("*",r)>=0||void 0!==Fn(e.target,t.t)?.get?t:e.O.bt(o(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:Bn(e,n,0,e.target,r)}function Bn(e,t,n,r,i){for(;n<t.length;n++){let s=t[n];if(null===r||"object"!=typeof r)return null;if("*"===s.s){if(!Array.isArray(r)||0===r.length)return null;let s=null;for(let o of r){let r=Bn(e,t,n+1,o,i);if(null===r)return null;if(null===s)s=r;else if(r.seg===s.seg)for(let e of r.names)s.names.includes(e)||s.names.push(e)}return s}if(Array.isArray(r)&&/^\d+$/.test(s.s)){if(Number(s.s)>=r.length)return null;r=r[Number(s.s)];continue}let o=Fn(r,s.s);if(void 0===o&&null===s.a&&e.nt.has(s.s))return null;if(void 0===o){let o=zn(r),l=i(s.a);for(let t of e.O.all())t.a===l&&null!==t.getter&&o.push(t.s);return n>0&&0===o.length?null:{seg:s.s,names:o,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==o.get||void 0!==o.set)return null;r=o.value}return null}function Kn(e){Un.has(e)||(Un.add(e),setTimeout(()=>function(e){Un.delete(e);let t=Hn.get(e);if(void 0===t)return;let n=Wn.get(e);void 0===n&&Wn.set(e,n=new Set);let r=new Map(t),i=new Map;for(let s of e.O.all()){let e=null===s.a||n.has(s)||t.has(s)?void 0:s.B.find(e=>!e.hn);void 0!==e&&(i.set(s,e),r.set(s,3))}for(let[t,s]of r){if(n.has(t))continue;n.add(t);let r=qn(e,t);if(null===r)continue;let l=Xn.get(e),a=t.a;for(;null!==a&&!l?.has(a);)a=a.a;if(null!==a)continue;let u=[...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Dn.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==u){n.delete(t),u.initializePromise.then(()=>{Dn.add(u),Kn(e)});continue}let h=e.O.bt(o(t.t).o),d="";if(void 0!==h&&h!==t&&null!==h.getter){let e=h.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(h.h[t].t.length+2)}`);d=` The getter "${h.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let f=kn(r.seg,r.names);if((r.r||3===s)&&""===f&&""===d)continue;let[p,m,g]=1===s?["watch-path-missing","$watch path","watch"]:2===s?["post-update-path-missing","$postUpdate path","postUpdate"]:3===s?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];c.ct?.(e,{type:"state:path-unresolved",source:g,path:t.t,missingSegment:r.seg}),console.warn(`[@wcstack/state] [wcs/${p}] ${m} "${t.t}"${3===s?` read by the getter "${i.get(t).t}"`:""} does not resolve on the state tree: "${r.seg}" is not declared.${f}${d} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${Sn}`)}}(e),0))}function Gn(e,t,n=!1){Vn(e,t,n?1:0)}function Vn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.a)return;let r=Hn.get(e);void 0===r&&Hn.set(e,r=new Map),r.has(t)||r.set(t,n),Kn(e)}var Jn=new WeakSet,Qn=!1,Yn=new WeakMap,Xn=new WeakMap;function Zn(e,t,n,r,i,s,o){if(!o)return;let l=Xn.get(e);void 0===l&&Xn.set(e,l=new Set),l.add(t)}function er(e,t){let n=Yn.get(e),r=t.s;if(null!==t.a||Qn||void 0===n||n.has(r)||"$"===r[0]||e.nt.has(r))return;let i=kn(r,[...n]);n.add(r),""!==i&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${r}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${r}" is not declared: writing it creates a new key.${i}${Sn}`)}var tr=new WeakSet;function nr(e){if(tr.has(e))return;tr.add(e);let t=e.emit,n=!1;e.emit=(...r)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${Sn}`)),t.apply(e,r))}var rr=new WeakMap;function ir(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Fn(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let i=rr.get(e);void 0===i&&rr.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${Sn}`))}var sr=new WeakSet,or=/\bthis\s*[.[]|=\s*this\b/,lr=new WeakSet,ar=e=>{for(let t of["src","state","json"])if(e.hasAttribute(t))return`<${e.localName} ${t}${"json"===t?"":`="${e.getAttribute(t)}"`}>`;return`<${e.localName}>`};function ur(e,t){let n=e.element;if("mounting"!==t||!n)return;let r=n.getRootNode();if(lr.has(r))return;let i=[...r.querySelectorAll(ie.tagNames.state)].filter(e=>e!==n&&!e.hasAttribute("mount")&&!e.hasAttribute("bind-component"));0!==i.length&&(lr.add(r),console.warn(`[@wcstack/state] [wcs/second-root] ${i.length+1} root <wcs-state> elements share one root, and there is one state tree per root: ${ar(n)} takes it — its state was ready first, whatever the order in the document — and ${i.map(ar).join(", ")} is refused (#47). Keep one, and graft the others with <wcs-state mount="path">.${Sn}`))}function cr(e){Hn.has(e)&&e.Ue.length>0&&Kn(e)}var hr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),dr=!1;function fr(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(dr||!(t instanceof TypeError)||!xe(r)||!("trustedTypes"in globalThis))return;dr=!0;let i="function"==typeof Te()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${r}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${i}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.c,property:r})}var pr=new WeakMap;function mr(e,t,n){let r=e[t],i=void 0===n?void 0===r?null:`the event carried no detail (undefined) while element.${t} is ${typeof r}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==r&&"object"==typeof r?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof r}`;if(null===i)return;let s=pr.get(e);void 0===s&&pr.set(e,s=new Set),!s.has(t)&&(s.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 gr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],yr={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},br={name:"diagnostics",hooks:c,install(){c._o=Rn,c.Vo=Ln,c.xo=Gn,c.detail=mr,c.Ge=h(c.Ge,fr);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&$(1);for(let[t,n]of gr)void 0!==e[t]&&$(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[r,i]=n[0];if(!r.endsWith(".*")||!i.endsWith(".*"))return;let s=r.slice(0,-2),o=i.slice(0,-2),l=`.${i}`,a=`${s}.**`,u=zn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),h=e=>w(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${o}`||e.startsWith(`.${o}.`))&&h(`"${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(`^(?:${hr(l)})+$`).test(t.slice(0,t.length-e.length))&&h(`"${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(`^${hr(r)}(?:${hr(l)})*${hr(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&h(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(n),function(e){let t=Fn(e,"$on")?.value;if(null!==t&&"object"==typeof t)for(let e of Object.keys(t)){let n=t[e];"function"!=typeof n||sr.has(n)||!or.test(String(n))||(sr.add(n),console.warn(`[@wcstack/state] [wcs/on-handler-this] The $on handler "${e}" uses this. A $on handler is called as ${e}(state, event): this is undefined there, so it throws when the event arrives — write ${e}(state, event) { state.x = … }.${Sn}`))}}(n),function(e){Wn.delete(e),Hn.has(e)&&Kn(e)}(t),function(e){if(Jn.has(e))return;Jn.add(e);let t=e.Jn,n=t.$postUpdate;t.$postUpdate=t=>{Qn=!0;try{n(t)}finally{Qn=!1}let r=e.O.bt(o(t).o);void 0!==r&&Vn(e,r,2)}}(t),function(e){if(void 0!==Object.getOwnPropertyDescriptor(e,"commands")?.set)return;let t=e.commands;Object.defineProperty(e,"commands",{configurable:!0,get:()=>t,set:e=>{t=e;for(let t of Object.values(e))nr(t)}})}(t),Yn.set(t,new Set(zn(n)))},c.handlerThrew=ir,c.element=h(c.element,ur),c.re=h(h(c.re,er),Zn),c.me=h(c.me,cr),c.it=d(p,c.it,(e,t)=>Object.hasOwn(yr,t)?$(1701,[t,yr[t]]):void 0)}},wr={},vr=/\.\d/,_r=new Set(Object.getOwnPropertyNames(Object.prototype)),$r=0,kr=!1,Sr=null,Nr=()=>{kr=!1,$r++};function Ar(){if(null===Sr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=Nr,e.port1.unref?.(),Sr=()=>e.port2.postMessage(0)}else Sr=()=>setTimeout(Nr,0);return kr||(kr=!0,Sr()),$r}function Cr(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let r of t)if(n.ee(r)&&(n.n===r.n||!(r.n<e.n&&e.h[r.n+1].ee(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var Er=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Io=-1,this._n=new Set,this.Ke=null,this.engine=e,this.je=t}pr(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.je)t.getter=null!==t.p.getter||t.p.ae,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(wr,e.v(t.p,null)):this.Vn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[r,i,s,o]of t)if((null===i||i.w)&&Object.is(e.v(r,i),o)){n.add(r);for(let e of this.je)e.p===r&&this.ft(e,i,s,!0)}for(let e of this.je)e.getter&&0===e.p.n&&!this.Fe.has(e)&&Cr(Tr(e.p),n)&&this.ft(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){v(t,`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`),c.ct?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}jo(){this.active=!1,this.Fe.clear(),this.early=[]}Vn(e,t,n,r){let i=this.engine.qe(n,e.h[t]);for(let n of i.f)t===e.n?r(n):this.Vn(e,t+1,n,r)}ft(e,t,n,r){let i=this.Fe.get(e);void 0===i&&this.Fe.set(e,i=new Map);let s=i.get(t);void 0===s?i.set(t,[n,this.n,r]):(s[1]<this.n&&(s[1]=this.n),s[2]||=r)}re(e,t,n,r,i,s){if(this.active){(this.Ke??=new Set).add(e);for(let s of this.je){let o=s.p;o.n!==e.n||!o.ee(e)||this.ft(s,t,s.getter?s.s.get(t??wr):o===e&&i&&this.engine.Vt&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else s&&this.early.push([e,t,n,r])}Se(e,t){if(this.active)for(let n of this.je)(n.getter||=null!==n.p.getter||n.p.ae)&&n.p.n===e.n&&n.p.ee(e)&&this.ft(n,t,n.s.get(t??wr),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let r of this.je){let i=r.p;if(!(i.n<e.n||i.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(i.n===e.n?this.ft(r,t,void 0,!0):this.Vn(i,e.n+1,t,e=>this.ft(r,e,void 0,!0)))}}}me(){let e=this.Ke;if(this.Ke=null,!this.active||0===this.Fe.size)return;let t=this.Fe;this.Fe=new Map;let n=this.engine,r=[];for(let i of this.je){let s=t.get(i);if(void 0===s)continue;let o,l=[...s].filter(([e])=>null===e||e.w);l.length>1&&l.sort((e,t)=>xr(e[0],t[0]));for(let[t,[s,a,u]]of l){let l,h="evaluate",d=n.d;this.n=a+1,n.Ce++;try{if(l=n.v(i.p,t),i.getter&&(i.s.set(t??wr,l),Object.is(l,s)&&(vr.test(i.t)||null!==t&&!u&&!(o??=null!==e&&Cr(Tr(i.p),e)))))continue;if(a>32){r.includes(i.t)||r.push(i.t);continue}n.d=t,c.ct?.(n,{type:"state:watch-fired",path:i.t}),h="handler",i.handler.call(n.proxy,l,s,...n.H(t))}catch(e){v(e,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),c.ct?.(n,{type:"state:watch-error",phase:h,path:i.t,error:e})}finally{n.d=d,this.n=0,n.Ce--}}}r.length>0&&this.Do(r)}Do(e){let t=Ar();t!==this.Io&&(this.Io=t,this._n.clear());let n=e.filter(e=>!this._n.has(e));if(0!==n.length){for(let e of n)this._n.add(e);v("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.ct?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function Tr(e){for(;null===e.getter&&null!==e.a;)e=e.a;return e}function xr(e,t){let n=[],r=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)r.unshift(e.y);for(let e=0;e<n.length&&e<r.length;e++)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}var Pr="$streamStatus",Or="$streamError",Lr=new Set(Object.getOwnPropertyNames(Object.prototype)),Mr=!1;function Ir(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 jr=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Mr=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Mr=!1}}mr(){for(let e of this.entries)this.start(e,!0)}hr(){for(let e of this.entries)e.pt=!1,e.J?.abort(),e.J=null}gr(){for(let e of this.entries)e.pt=!1,null!==e.J&&(e.J.abort(),e.J=null),this.set(Pr,e.name,"idle")}Se(e){let t=this.W.n;for(let n of this.entries)n.g===e&&(n.n=n.pt?Math.max(n.n,t):t,n.pt=!0)}me(){let e=this.engine,t=this.W,n=[];for(let i of this.entries){if(!i.pt)continue;let s=i.n;if(i.pt=!1,s>32)n.push(i.name),i.g.Y=r;else{t.n=s+1,e.Ce++;try{this.start(i,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Do(n)}start(e,t){let n,i=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let s=e.g;s.getter=e.args;let o=s.Q.slice();Rr(s);try{n=i.read(s,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&w(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&w(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Pr}.${e}`||n.t===`${Or}.${e}`)&&w(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,s,n)}catch(n){Rr(s);for(let e of o)e.Hn(s);if(s.Y=r,t)throw n;return this.set(Or,e.name,n),void this.set(Pr,e.name,"error")}}let s=new AbortController;e.J=s,i.A(i.o(e.name),null,e.q),this.set(Or,e.name,null),this.set(Pr,e.name,"active"),this.yr(e,s,n)}async yr(e,t,n){let r=this.engine,i=t.signal,s=()=>!i.aborted&&e.J===t,o=r.o(e.name),l=this.W.n,a=Ar(),u=e=>{Ar()===a&&(this.W.n=l);try{e()}finally{this.W.n=0}},c=e.q;try{let t=await e.source(n,i);if(!s())return;let l=t=>{c=void 0!==e.Lo?e.Lo(c,t):t,u(()=>r.A(o,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(i.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!s())return;if(t.done)break;l(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(!s())return;if(t.done)break;l(t.value)}}}if(!s())return;e.J=null,u(()=>this.set(Pr,e.name,"done"))}catch(n){if(!s())return;e.J=null,t.abort(),u(()=>{this.set(Or,e.name,n),this.set(Pr,e.name,"error")})}}};function Rr(e){for(let t of e.Q){let n=t.B.indexOf(e);n>=0&&t.B.splice(n,1),t.yt.delete(e)}e.Q.length=0,e.Y=t}var Hr=new WeakMap;function Wr(e){let t=Hr.get(e);return t?.target===e.target?t:void 0}function Ur(e,t){let n=new Er(e,function(e,t){if(void 0===t)return[];(null===t||"object"!=typeof t)&&w("$watch must be an object mapping paths to handler functions.");let n=[];for(let r of Object.keys(t)){let i=t[r];(""===r||"$"===r[0]||r.includes("@")||_r.has(r))&&w(`$watch path "${r}" is not a path of the state tree.`),"function"!=typeof i&&w(`$watch entry "${r}" must be a function.`);let s=e.o(r);c.xo?.(e,s,!0),n.push({t:r,p:s,handler:i,getter:!1,s:new WeakMap})}return n}(e,t.$watch)),r=new jr(e,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&w("$stream must be an object mapping stream names to definitions.");let r=[],i={},s={};for(let o of Object.keys(n)){let l=n[o];(""===o||"$"===o[0]||/[.*]/.test(o)||Lr.has(o))&&w(`$stream entry "${o}" must be a flat property name.`),(null===l||"object"!=typeof l)&&w(`$stream entry "${o}" must be an object.`);let a=l.source,u=l.fold,c=l.args,h=l.initial;"function"!=typeof a&&w(`$stream entry "${o}" needs a source function.`),void 0!==u&&"function"!=typeof u&&w(`$stream entry "${o}": fold must be a function.`),void 0!==u&&!("initial"in l)&&w(`$stream entry "${o}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&w(`$stream entry "${o}": args must be a function.`),Ir(t,o)&&w(`$stream entry "${o}" collides with a getter, setter or method of the state.`),void 0===t[o]&&(t[o]=h),i[o]="idle",s[o]=null,r.push({name:o,source:a,Lo:u,q:h,J:null,pt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${o}`),args:void 0===c?null:function(){return c(this)}})}return t[Pr]=i,t[Or]=s,r}(e,t),n),i=Hr.get(e);void 0!==i&&(i.W.jo(),i.It.hr()),Hr.set(e,{W:n,It:r,Qe:i?.Qe??!1,target:t})}function Dr(e,t){let n=Hr.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Qe="connected"===t),n.target===e.target)){if("disconnected"===t)return n.W.jo(),void n.It.gr();n.Qe&&(n.W.pr(),n.It.mr())}}var Fr=["$streamStatus","$streamError"],zr={name:"temporal",hooks:c,install(){c.fe=h(c.fe,Ur),c.element=h(c.element,Dr),c.re=h(c.re,(e,t,n,r,i,s,o)=>Wr(e)?.W.re(t,n,r,i,s,o)),c.Se=h(c.Se,(e,t,n)=>{let r=Wr(e);void 0!==r&&(r.W.Se(t,n),r.It.Se(t))}),c.Qt=h(c.Qt,(e,t,n)=>Wr(e)?.W.Qt(t,n)),c.me=h(c.me,e=>{let t=Wr(e);void 0!==t&&(t.W.me(),t.It.me())}),c.it=d(p,c.it,(e,t)=>{let n=t.split(".",1)[0];if(Fr.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=d(f,c.Ie,(e,t)=>(!Mr&&36===t.t.charCodeAt(0)&&Fr.includes(t.t.split(".",1)[0])&&w(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},qr=new WeakMap,Br=!1,Kr=/^(?!prototype$)[^\d.*$][^.*]*$/;function Gr(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&w("$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?r.set(e.o(t),e=>e[i]):"function"==typeof i?r.set(e.o(t),i):w(`$listKeys "${t}" must be a field name or a function.`)}}qr.set(t,r)}function Vr(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Jr(e,t,n){let r=new Map;for(let i of t){Vr(i)||w(`$listKeys "${e}": rows must be plain objects.`);let t=n(i);null==t&&w(`$listKeys "${e}": a row has no key.`),r.has(t)&&w(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,i)}return r}function Qr(e,t,n,r){if(Br||!Array.isArray(r))return!1;let i=qr.get(e.target)?.get(t);if(void 0===i)return!1;let s=e.st(t,n);if(!Array.isArray(s)||s===r)return!1;let o=Jr(t.t,s,i);Jr(t.t,r,i);let l=[],a=[],u=s.length===r.length;for(let e=0;e<r.length;e++){let t=r[e],n=o.get(i(t));l.push(n??t),void 0!==n&&a.push([e,n,t]),l[e]!==s[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let r of Object.keys(n))Object.is(t[r],n[r])||c.push([e,r,n[r]]);for(let r of Object.keys(t))!(r in n)&&null!==t[r]&&c.push([e,r,null])}if(u&&0===c.length)return!0;if(!u){Br=!0;try{e.A(t,n,l)}finally{Br=!1}}if(c.length>0){let r=e.qe(0===t.n?null:n,t);for(let[n,i,s]of c){if("__proto__"===i)continue;let o=r.f[n],l=Kr.test(i)?e.o(`${t.t}.*.${i}`):null;null===l?.getter?e.A(l,o,s):(o.E[i]=s,e.A(e.o(`${t.t}.*`),o,o.E,!0))}}return!0}var Yr={name:"list-keys",hooks:c,install(){c.fe=h(c.fe,Gr),c.Ie=d(f,c.Ie,Qr)}},Xr=new WeakMap,Zr=new WeakMap,ei="will not graft: the root state failed to initialize.",ti=new WeakSet,ni=new WeakMap,ri=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],ii=["$commandTokens","$eventTokens","$on","$errorCallback"],si=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,oi=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),li=e=>e?.element?.isConnected?e:void 0;function ai(e){let t=Zr.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ui(e,t){let n=Zr.get(t);if(Zr.delete(t),Array.isArray(n))for(let t of n)fi(t,e)}function ci(e){let t=Xr.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function hi(e,t){v(`${si(e.t)} ${t}`),ci(e),e.Ze?.(),e.Ze=null}function di(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,v)}catch(e){v(e)}}function fi(e,t){if(ti.has(t))return hi(e,"will not graft: its component is wired to its host.");let n=e.state,r=t.target,i=e.t.split("."),s=r;for(let e of i)s=s?.[e];if(void 0!==s&&!0!==t.hydrated)return hi(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,r){if("symbol"==typeof r)return;if(36!==r.charCodeAt(0))return e.proxy[n(r)];let i=e.proxy[r];return"$eqPath"===r?(e,t)=>i(n(e),n(t)):oi.has(r)&&"function"==typeof i?(e,...t)=>i(n(e),...t):i},set:(t,r,i)=>"symbol"!=typeof r&&(e.proxy[n(r)]=i,!0)})}(t,e.t);e.chroot=o;let l={},a={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:r,set:i,value:s}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==r||void 0!==i)a[`${e.t}.${n}`]={get:r&&function(){return r.call(o)},set:i&&function(e){i.call(o,e)}};else{if("$"===n[0])continue;if("function"==typeof s){let t=s.bind(o);a[`${e.t}.${n}`]={get:()=>t}}else l[n]=s}}if(void 0===s){for(let e=1;e<i.length;e++){let n=t.o(i.slice(0,e).join("."));null==t.st(n,null)&&t.A(n,null,{})}t.A(t.o(e.t),null,l)}t.io(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=ni.get(t);void 0===c&&ni.set(t,c=[]),c.push(e),e.el.isConnected&&di(e,"$connectedCallback"),e.Ze?.(),e.Ze=null}function pi(e,t){let n=Zr.get(e);if(Array.isArray(n))for(let e of n)hi(e,ei);Zr.set(e,t)}var mi=new WeakMap;function gi(e,t){let n=e.getAttribute("mount");if(null===n)return null;let r={el:e,root:t,t:n,state:null,engine:null,chroot:null,Ze:null},i=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Xr.get(t);void 0===e&&Xr.set(t,e=new Map);let s=e.get(n);if(void 0!==s&&s!==r&&(null===s.engine?s.el.isConnected:li(s.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===s?.engine){let e=Zr.get(t);Array.isArray(e)&&Zr.set(t,e.filter(e=>e!==s)),s.Ze?.(),s.Ze=null}e.set(n,r)}}else i='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Ao:!0,start(e){if(null!==i)return hi(r,i);if(Xr.get(t).get(n)===r){for(let t of ri)if(void 0!==e[t])return hi(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of ii)void 0!==e[t]&&console.warn(`${si(n)} ${t} is not run in a volume (it belongs to the root).`);return r.state=e,new Promise(e=>{r.Ze=e;let n=li(jt.get(t)),i=Zr.get(t);void 0!==n?fi(r,n):ai(t)?hi(r,ei):Zr.set(t,[...Array.isArray(i)?i:[],r])})}},Qe(){null!==r.engine&&di(r,"$connectedCallback")},Wn(){null!==r.engine&&di(r,"$disconnectedCallback")},reset(){w(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var yi=new WeakMap,bi=new WeakMap;function wi(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||w(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&w(`${t} entries must be non-empty strings.`),"$"===e[0]&&w(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&w(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function vi(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let r=document.createDocumentFragment();for(let e of[...t.childNodes])r.appendChild(e.cloneNode(!0));let i=t.mode;return{start(t){e.hasAttribute("bind-component")&&w("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||w(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&w(`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}(r),s=wi(r,"$bindables"),o=wi(r,"$commands");for(let e of s){let t=i.get(e);void 0===t&&w(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&w(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of o){let t=i.get(e);void 0===t&&w(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&w(`$commands entry "${e}" is not a method: list it in $bindables.`)}let l={tag:e,bindables:s},a=new WeakMap,u=new WeakMap,c=r=>{if(a.has(r))return a.get(r);if(r.hasAttribute("data-wc-definition"))return null;let i=r.attachShadow({mode:n});i.appendChild(t.cloneNode(!0));let o=i.querySelector(ie.tagNames.state);return a.set(r,o),yi.set(r,l),null===o&&s.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.tagNames.state}>: no change events.`),o},h=e=>c(e)?.engine??null,d=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=h(e);if(void 0!==t&&null!==n)for(let[e,r]of t)n.proxy[e]=r});class f extends HTMLElement{static{this.wcBindable=0===s.length&&0===o.length?null:{protocol:"wc-bindable",version:1,properties:s.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:s.map(e=>({name:e})),...0===o.length?{}:{commands:o.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&d(this)}get stateElement(){return c(this)}}for(let[e,t]of i)"function"==typeof t.value?Object.defineProperty(f.prototype,e,{configurable:!0,value(...t){return d(this).then(()=>{let n=h(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(f.prototype,e,{configurable:!0,get(){return h(this)?.proxy[e]},set(t){let n=h(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,f)}(n.localName,r,i,t)},Qe(){},Wn(){},reset(){w("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var _i=new WeakMap,$i=new WeakSet,ki=new WeakMap,Si=new WeakMap,Ni="data-wcs-wired",Ai=new WeakMap,Ci=new WeakMap,Ei=new WeakMap,Ti=0,xi=new Set,Pi={},Oi=["$watch","$stream","$renderedCallback"],Li=e=>e.split(".",1)[0];function Mi(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ii(e,t){let n=e.c,r=Li(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(Ni);else if(!Ri(n,r)){let e=n.getAttribute(Ni)?.split(" ")??[];e.includes(r)||n.setAttribute(Ni,[...e,r].join(" "))}Ai.get(n)?.he===r&&w(`<${n.localName}>.${r} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let i=_i.get(n);void 0===i&&_i.set(n,i=[]),i.push(e),t&&$i.add(e);let s=ki.get(n);return void 0===s&&ki.set(n,s=new Map),s.has(r)||s.set(r,n[r]),Si.get(n)?.(),!1}function ji(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Ri(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Hi(e){let t=e.parentElement;for(;null!==t&&!ji(t);)t=t.parentElement;let n=jt.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.V:null===t)&&(null===t?qt(e):Ht(n,e))}var Wi=new Set;function Ui(e,t){Wi.has(e)||(Wi.add(e),console.warn(`[@wcstack/state] ${t}`))}var Di=(e,t)=>t in e.state;function Fi(e,t){let n=zi(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function zi(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 qi(e,t,n){if(null!==n.getter)return;let r,i=e.host,s=i.engine,o=Li(n.t),l=i.entries.find(e=>e.$===n.t);if(void 0===l&&null!==n.a)return function(e,t){let n,r=t.a;for(;null!==r&&void 0===(n=e.mt.get(r));)r=r.a;if(null===r||void 0===n)return;let i=e.R,s=e.host.engine,o=s.o(n.p.t+t.t.slice(r.t.length));if(null===o.getter)return;let l=n,a=()=>{let n=Bi(e,l.r);return 0===t.n?n:(s.resolve(Mi(o.t,[...s.H(n),...i.H(te(i.d,t.n))]),null),s.rr)};t.getter=()=>{let e=a();return o.n>0&&null===e?void 0:s.v(o,e)},null!==o.se&&(t.se=n=>{let r=a();Ki(e,l.e,()=>s.A(o,r,n)),e.dn=t}),t.n>0&&(t.F=i.Le++),e.mt.set(t,{e:l.e,p:o,r:l.r})}(e,n);if(0!==n.n)return;if(void 0!==l){if(l.$!==o?Di(i,o):Fi(i,o))return;r=l.ye}else{if(null===t||null!==n.a||"$"===o[0]||Di(i,o))return;l=t,r=s.o(`${t.ye.t}.${o}`)}let a=l.r,u=l;n.getter=()=>s.v(r,Bi(e,a)),n.se=t=>{Ki(e,u,()=>s.A(r,a,t)),e.dn=n},e.mt.set(n,{e:l,p:r,r:a})}function Bi(e,t){return null!==t&&!t.w&&w(`The host row of <${e.host.el.localName}> was removed.`),t}function Ki(e,t,n){let r=xi.has(e.R);xi.add(e.R),e.from=t;try{n()}finally{r||xi.delete(e.R),e.from=null}}var Gi=(e,t)=>t||!xi.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Vi(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,Ti+=t?1:-1;let n=e.host.engine,r=Ei.get(n);void 0===r&&Ei.set(n,r=new Map);for(let n of e.pe){let e=r.get(n.e.ye);void 0===e&&r.set(n.e.ye,e=new Map);let i=e.get(n.e.r);void 0===i&&e.set(n.e.r,i=new Set),t?i.add(n):(i.delete(n),0===i.size&&e.delete(n.e.r))}let i=e.host.entries.find(e=>""===e.$);if(void 0!==i){null===e.ie&&function(e,t){let n=e.host,r=n.engine;e.ie=new Map;let i=new Set;for(let s=n.state;null!==s&&s!==Object.prototype;s=Object.getPrototypeOf(s))for(let o of Object.getOwnPropertyNames(s)){if(i.has(o))continue;i.add(o);let l=Object.getOwnPropertyDescriptor(s,o);if(void 0===l.get&&void 0===l.set||"$"===o[0]||o.includes("*"))continue;let a=Li(o);if(o!==a&&!Di(n,a))continue;let u=r.o(`${t.ye.t}.${o}`);if(null===u.getter)Yi(r,u,t.ye);else if(!Ji.has(u.getter))continue;e.ie.set(u,e.R.o(o))}}(e,i);for(let r of e.ie.keys())t&&null===r.getter&&Yi(n,r,i.ye),n.T.ke(n,r,i.r);e.ie.size>0&&n.ve(),t&&function(e,t){let n=e.host.engine;for(let[r,i]of e.ie){let s=n.v(r.a,t.r);if(null===s||"object"!=typeof s||!(r.s in s))continue;let o=e.host.el.localName;Ui(`${o}|${r.t}`,`[wcs/mount-export-shadowed] <${o}>.${e.host.he}.${i.t} is exported at "${r.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,i)}}var Ji=new WeakSet;function Qi(e,t,n,r){let i=Ei.get(e)?.get(t)?.get(n);if(void 0===i)return null;let s=null;for(let e of i)""!==e.e.$||!0!==e.m.ie?.has(r)||e.m===s||(null!==s&&w(`[wcs/mount-export-ambiguous] "${r.t}" is exported by two mounted components on the same instance: <${s.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.`),s=e.m);return s}function Yi(e,t,n){let r=t.a,i=t.s,s=()=>{let t=e.read(r,e.d);return null!==t&&"object"==typeof t&&i in t?t:null};t.getter=()=>{let r=s();if(null!==r)return r[i];let o=Qi(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Ji.add(t.getter),t.se=o=>{let l=null===s()?Qi(e,n,e.d,t):null;if(null===l){let t=e.read(r,e.d);return void(null!==t&&"object"==typeof t&&(t[i]=o))}let a=l.ie.get(t);void 0===zi(l.host.state,a.t)?.set&&w(`Cannot write to "${a.t}" on mounted <${l.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),l.R.A(a,null,o)},t.n>0&&(t.F=e.Le++)}function Xi(e,t,n,r,i,s){if(null!==t.getter)return e.T.ke(e,t,n),void e.ve();if("*"===t.s){if(null===n)return;if(n.E=n.l.P[n.y],e.T.Gt(n),null!==n.u)for(let t of n.u.values())e.X(t)}else e.xn(t,n);c.re?.(e,t,n,r,i,s),e.Ke(t,n)}function Zi(e){let t=e.m.R;for(let[n,r]of e.m.mt)r.e===e.e&&(0===n.n?t.T.ke(t,n,null):t.nn(n.h[n.n],e=>t.T.ke(t,n,e)));t.ve()}function es(e,t,n,r,i,s,o){let l=n.t.slice(t.t.length);if(""===l)return Zi(e);let a,u=e.m,c=u.R;if(""===e.e.$){a=l.slice(1);let e=Li(a);if("$"===e[0]||Di(u.host,e)||u.host.entries.some(e=>""!==e.$&&(a===e.$||a.startsWith(`${e.$}.`))))return}else a=e.e.$+l;let h=[];for(let e=t.n+1;e<=n.n;e++)h.push(te(r,e).y);c.resolve(Mi(a,h),null);let d=c.rp,f=c.rr;d.n>0&&null===f||Xi(c,d,f,i,s,o)}function ts(e,t,n,r,i,s,o){if(0===Ti)return;let l=xi.has(e);xi.add(e);try{let l=Ci.get(e);!o&&void 0!==l&&l.fn&&!xi.has(l.host.engine)&&function(e,t,n,r,i,s){let o,l=t;for(;null!==l&&void 0===(o=e.mt.get(l));)l=l.a;if(null===l||void 0===o)return;let a=e.host.engine;if(l===t&&e.dn===t)return void(e.dn=null);if(null!==o.r&&!o.r.w)return;let u=[...a.H(o.r),...e.R.H(n)];a.resolve(Mi(o.p.t+t.t.slice(l.t.length),u),null);let c=a.rp,h=a.rr;c.n>0&&null===h||Ki(e,o.e,()=>Xi(a,c,h,r,i,s))}(l,t,n,r,i,s),o&&void 0!==l&&l.fn&&null!==l.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.$),r=e.host.engine;for(let[i,s]of e.ie)s===t&&(r.T.ke(r,i,n.r),r.ve())}(l,t);let a=Ei.get(e);if(void 0===a)return;for(let[e,l]of a)if(t.ee(e)){let a=l.get(0===e.n?null:te(n,e.n));if(void 0!==a)for(let l of[...a])Gi(l,o)&&es(l,e,t,n,r,i,s)}else if(e.ee(t))for(let[e,r]of[...l])if(0===t.n||te(e,t.n)===n)for(let e of[...r])Gi(e,o)&&Zi(e)}finally{l||xi.delete(e)}}async function ns(e,t,n,r,i){if(r===Pi)return;let s=y(r);s&&await s;let o=Ai.get(t);o.engine&&r.$recursion&&w(`[wcs/mount-dollar-declaration] <${t.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let l=o.I;if(null!==l&&l.el!==e&&l.el.isConnected&&w(`<${t.localName}> already has a connected <${ie.tagNames.state} bind-component="${o.he}">.`),null!==l&&Vi(l,!1),null!==l&&function(e,t,n){let r=e.R,i=`[${ie.bindAttributeName}]`,s=e=>1===e.nodeType&&(e.matches(i)||null!==e.querySelector(i)),o=new Set,l=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&o.add(e)},a=(e,t)=>{for(let n=e.Dn(t);null!==n&&n!==t;n=n.nextSibling)l(n);l(t)};for(let e of r.ue.values())for(let t of e)if(null===t.j)l(t.c);else for(let e of t.j.K)a(t.j,e.S);for(let e of r.oe.values())for(let t of[e.N,...e.M??[]])null!==t&&a(t,t.S);for(let t of e.L)t.parentNode===n&&s(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)&&(s(n)||r._t&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(l,e,n))return async function(e,t,n,r){e.el.engine=null,e.el=t,e.R.element=t,t.engine=e.R,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await rs(e,r):r()}(l,e,n,i);let a=new re(r,new Kt);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 r=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof r&&"constructor"!==t&&n.set(r,null)}let r=(t,n,r)=>Reflect.apply(t,e.proxy,r);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:r})),t}}(a,r);let u={el:e,L:[],R:a,host:o,pe:[],mt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of o.entries)u.pe.push({m:u,e:e});o.I=u,Ci.set(a,u);let h=null===o.engine;h?c.element?.(a,"mounting"):(function(e){let t=e.R,n=e.host,r=n.engine,i=n.el.localName,s=n.entries.find(e=>""===e.$)??null;for(let e of n.entries){if(""===e.$)continue;let t=Li(e.$);Di(n,t)&&(e.$!==t||Fi(n,t))&&Ui(`${i}.${e.$}`,`[wcs/mount-own-key-shadow] <${i}>: "${n.he}.${e.$}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==s){let e=r.v(s.ye,s.r);if(null!==e&&"object"==typeof e)for(let t of Object.keys(n.state))"$"!==t[0]&&t in e&&!n.entries.some(e=>e.$===t)&&Ui(`${i}.${t}`,`[wcs/mount-own-key-shadow] <${i}>: its own "${t}" hides "${s.ye.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let o=Oi.filter(e=>void 0!==n.state[e]);o.length>0&&Ui(`${i}.${n.he}$`,`[wcs/mount-dollar-declaration] <${i}>: ${o.join(", ")} ${1===o.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let l=t.rt;t.rt=n=>{qi(e,s,n),l.call(t,n)};let a=[...t.O.all()];for(let t of a)qi(e,s,t);for(let e of a)l.call(t,e);let u=t.Et;t.Et=()=>{(function(e){for(;void 0!==e;e=Ci.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(u),Vi(u,!0),ti.add(a),ui(a,n));let d=c.wr?.(n,a);Rt(a,n),d?.(),u.L=[...n.childNodes],Bt(),h&&a.Rn(),Object.defineProperty(t,o.he,{configurable:!0,enumerable:!0,get:()=>a.proxy});let f=t.$stateReadyCallback;if("function"==typeof f)try{let e=f.call(t,o.he);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,v)}catch(e){v(e)}i(),e.isConnected?(await a.$e("$connectedCallback"),h&&e.isConnected&&c.element?.(a,"connected")):Vi(u,!1)}async function rs(e,t){Vi(e,!0);for(let t of e.pe)Zi(t);t?.(),!e.broken&&(await e.R.$e("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function is(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=jt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){pi(t,e);for(let e of mi.get(t)??[])e()}}),null}(e,t);let r=e.parentNode,i=r instanceof ShadowRoot,s=i?r.host:r instanceof Element?r:null,o=()=>{let t=null===s?void 0:Ai.get(s)?.I;return t?.el===e?t:null},l=t=>{throw i&&pi(r,e),t},a=!1;return{Wt:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,r){let i=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&w(`<${ie.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await je(n).whenDefined(i);let s=Ai.get(n);if(void 0!==s)return s.he!==t&&w(`<${i}> already has a <${ie.tagNames.state} bind-component="${s.he}">.`),s.state;let o=()=>(_i.get(n)??[]).filter(e=>Li(e.name)===t),l=Ri(n,t);if(l&&0===o().length&&Hi(n),0===o().length&&(l||((e,t)=>!0===e.getAttribute(Ni)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,s)=>{Si.set(n,r),e=function(e,t){ai(e)&&t();let n=mi.get(e)??new Set;return mi.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>s(new Error(`[@wcstack/state] <${i}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Si.delete(n);let a=o(),u=ki.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&w(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&r){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Pi}let h=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.$===r)&&w(`<${i}> maps "${e.name}" twice.`);let s=r.split(".").indexOf("*");if(s>=0){let n=r.split(".").slice(0,s).join(".");w(`<${i}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({$:r,ye:e.o,r:e.r,ro:$i.has(e)}),e.engine.Tn(e),""!==r&&delete n[e.name]}let d=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 Ai.set(n,s={el:n,he:t,state:d,engine:0===a.length?null:a[0].engine,entries:h,I:null}),d}(e,n,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(l),async start(t,n){await ns(e,s,i?r:s,t,()=>{a=!0,n()}).catch(e=>{let t=o();return!a&&null!==t&&(t.broken=!0),l(e)})},Qe(){let t=o();null!==t?rs(t).catch(v):a?Promise.resolve().then(()=>{if(e.parentNode===r)return ns(e,s,i?r:s,Ai.get(s).state,()=>{})}).catch(v):Si.has(s)&&Hi(s)},Wn(){let e=o();null!==e&&(Vi(e,!1),!e.broken&&(e.R.$e("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.R,"disconnected")))},reset(){w(`re-setting a component's state is not supported: write <${s?.localName}>.${n} instead.`)}}}var ss={name:"scopes",hooks:c,install(){c.dt=d(m,c.dt,gi),c.dt=d(m,c.dt,vi),c.dt=d(m,c.dt,is),c.dr=Ii,c.Ro=ji,c.element=h(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=ni.get(e)??[];if("disconnected"===t)for(let e of n)ci(e);else if("reset"!==t&&li(jt.get(e.root))===e){ui(e,e.root);for(let e of n)Xr.get(e.root).has(e.t)||Xr.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ui(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:yi.get(n);void 0!==r&&bi.set(e,{host:n,def:r})}(e,n)}),c.re=h(c.re,(e,t,n,r,i,s)=>{(function(e,t,n,r){let i=bi.get(e);if(void 0===i)return;let s=t.t.split(".",1)[0];if(!i.def.bindables.includes(s))return;let o=r&&t.t===s;i.host.dispatchEvent(new CustomEvent(`${i.def.tag}:${s}-changed`,{detail:o?n:void 0,bubbles:!0}))})(e,t,i,s),ts(e,t,n,r,i,s,!1)}),c.Se=h(c.Se,(e,t,n)=>ts(e,t,n,void 0,void 0,!1,!0)),c.Ie=d(f,c.Ie,(e,t,n,r,i)=>(function(e,t){let n=ni.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&w(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,i=Ci.get(e);if(void 0===i)return!1;for(let e=t;null!==e&&void 0===r;e=e.a)r=i.mt.get(e);if(void 0===r)return!1;let s=r.e;return!((null===s.r||s.r.w)&&!s.ro)&&(!!n||(Bi(i,s.r),void w(`[wcs/mount-readonly] <${i.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${i.host.he}${""===s.$?"":`.${s.$}`}#ro: ${s.ye.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,i)));let e=c.fe;c.fe=(t,n)=>{let r=ni.get(t);void 0!==r&&r.length>0&&w(`re-setting a root state with grafted volumes (${r.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Ei.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(t)&&w("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},os="$recursion",ls=new WeakMap,as=new WeakSet,us=new WeakSet,cs=0,hs=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ds=e=>`[wcs/recursion-${e}]`;function fs(e,t){let n=n=>w(`${ds("declaration-invalid")} ${os} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&w(`${ds("declaration-invalid")} ${os} ${e} must be a non-empty string.`);let r=t.split(".");(r.length<2||"*"!==r[r.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<r.length-1;e++){let t=r[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var ps=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function ms(e,t){let n=`${e.l}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&w(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),r}function gs(e,t,n){let r=ms(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ce){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===i&&w(`[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.`),ps(e,i.k)+r}function ys(e,t,n){let r=new Set,i=new Set,s=(e,n,s)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&w(`${ds("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&w(`${ds("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),s+1>128&&w(`${ds("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${s+1} (the limit is 128).`),i.add(e),0)),o=(i,l)=>{for(let a of i){n(l,a);let i=e.o(`${ps(t,l)}.${t.key}`),u=e.read(i,a);s(u,i.t,l+1)&&(r.add(u),o(e.qe(a,i).f,l+1),r.delete(u))}},l=e.o(t.l),a=e.read(l,null);s(a,t.l,0)&&(r.add(a),o(e.qe(null,l).f,0))}function bs(e,t){let n=function(e){let t=e[os],n=[],r=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!r.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),r.add(e);if(void 0===t)return n.length>0&&D(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&w(`${ds("declaration-invalid")} ${os} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&w(`${ds("declaration-invalid")} ${os} must declare exactly one anchor (it declares ${i.length}).`);let s=fs("anchor",i[0][0]),o=fs("repeat",i[0][1]),l=s.slice(0,-2),a=o.slice(0,-2),u=`.${o}`,c=new Map,h=[],d=`${l}.**`;for(let[e,t]of n){let n=e.slice(d.length);(!e.startsWith(d)||""!==n&&"."!==n[0]||n.includes("**"))&&w(`[wcs/recursion-anchor] "${e}": a recursive key is "${d}" followed by a path (the anchor is "${s}").`),(""===n||n.split(".").slice(1).some(e=>""===e))&&w(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&w(`${ds("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),h.push([new RegExp(`^${hs(s)}((?:${hs(u)})*)${hs(n)}$`),n])}return{l:l,step:u,key:a,families:c,matchers:h,owners:new Map,nodeList:new RegExp(`^${hs(l)}((?:${hs(`.*.${a}`)})*)$`)}}(t),r=ls.has(e);null!==n?(r||cs++,ls.set(e,n),us.add(e),as.has(e)||function(e){as.add(e);let t=e,n=t.rt;t.rt=r=>{let i=ls.get(e);if(r.t.includes("**")){let t=e.O.bt(r.t)===r;return void(us.has(e)||void 0===i&&t?r.getter=()=>D(r.t):t||n.call(e,r))}if(void 0!==i&&null===r.getter)for(let[e,n]of i.matchers)if(e.test(r.t)){r.getter=i.families.get(n),r.n>0&&(r.F=t.Le++),i.owners.set(r,i.l+".**"+n);break}n.call(e,r)};let r=t.resolve;t.resolve=(t,n)=>{let i=ls.get(e);return r.call(e,void 0!==i&&t.includes("**")?gs(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,r)=>{let s=ls.get(e);if(void 0===s||!n.includes("**"))return i.call(e,n,r);if(void 0===r)return i.call(e,gs(s,n,t.d));(!Array.isArray(r)||r.length>0)&&w(`${ds("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=ms(s,n),l=[];return ys(e,s,(t,n)=>{for(let r of i.call(e,ps(s,t)+o,e.H(n)))l.push(r)}),l};let s=t.vn;t.vn=(n,r,i,o)=>{let l=ls.get(e);if(void 0===l||!n.includes("**"))return s.call(e,n,r,i,o);Array.isArray(r)||$(9,[n]),r.length>0&&w(`${ds("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&w(`${ds("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&$(8);let a=ms(l,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(l.step);)u=u.slice(l.step.length);let c=l.key.split(".");(""===u||u===`.${l.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&w(`${ds("structural-write")} "${n}" writes the recursion structure itself (a node, its "${l.key}" list or that list's length, or an object on the way to it).`);for(let e of l.families.keys()){let t=e;for(;t.startsWith(l.step);)t=t.slice(l.step.length);(u===t||u.startsWith(`${t}.`))&&w(`${ds("readonly")} "${n}" writes into the recursive getter "${l.l}.**${e}".`)}let h=[];ys(e,l,(e,t)=>h.push([e,t]));let d=0;for(let[t,n]of h)d+=s.call(e,ps(l,t)+a,e.H(n),i);return d}}(e)):r&&(ls.delete(e),cs--)}function ws(e,t){if(0===cs)return!1;let n=ls.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.a){let r=n.owners.get(e);void 0!==r&&w(`${ds("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var vs={name:"recursion",hooks:c,install(){c.fe=h(c.fe,bs),c.element=h(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){us.delete(e)}(e)}),c.Ie=d(f,c.Ie,ws)}},_s="4.10.0",$s=e=>e.split(".").slice(0,2).join("."),ks=class extends Yt{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return $s(this.version)===$s(_s)}};function Ss(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends ks{})}var Ns=()=>ie.tagNames.ssr,As=Symbol.for("wcstack.ssr.snapshotBuilder"),Cs=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Es=e=>document.createComment(e),Ts=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,xs=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),Ps=new WeakMap,Os=new WeakMap,Ls=new WeakMap,Ms=new WeakSet,Is=new WeakMap;function js(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function Rs(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 Hs=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Ws(e,t,n,r){let i=Es(null===r?"wcs-[":`wcs-[:${r}`),s=Es("wcs-]");n.length>0&&n[0].Re().before(...js(e,t)),t.after(i);for(let e of n)null===r&&e.Re().before(Es("wcs-|"));let o=n.length>0?(e=>null===e.L?e.ut:e.L[e.L.length-1])(n[n.length-1]):i;(Hs(o)??o).after(s);for(let e of js(i,s))Ms.add(e)}function Us(e){if(e instanceof at){Ws(e.S,e.S,e.Ae,null);for(let t of e.Ae)Ds(t);return}let t=e.I;null!==t&&(Ws(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Ds(t))}function Ds(e){if(null!==e.u)for(let t of e.u)Us(t)}var Fs=new Set(["script","style","template","textarea","title"]),zs="data-wcs-raw",qs=e=>Fs.has(e.localName)||e.localName===Ns();function Bs(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Es("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Es("wcs-s")):1===t.nodeType&&!qs(t)&&Bs(t)}var Ks=0;function Gs(e,t){let n=e.getRootNode(),r=[t];for(let e of Os.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let i=new Map;for(let e of r){let t=Ps.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.N&&n.set(t.N.S,t.N),null!==t.M)for(let e of t.M)n.set(e.S,e);for(let t of e.ue.values())for(let e of t)if(null!==e.j)for(let t of e.j.K)n.set(t.S,e.j);let r=new Set;for(let[e,s]of t){i.set(e,s);let t=n.get(e);void 0!==t&&!r.has(t)&&e.isConnected&&(r.add(t),Us(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ls.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ms.has(e)||1===e.nodeType&&t.has(e)&&Xs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(qs(e.parentNode)?Is.has(e):t.has(n)&&xs(n,"wcs-t:"))&&(Is.has(e)||t.get(e)!==e.data):!t.has(e))&&r.push(e)}for(let e of r)e.remove()}let n=Array.from(e.childNodes);qs(e)&&n.some(e=>Is.has(e))&&e.setAttribute(zs,n.map(e=>Is.has(e)?`{{ ${Is.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Bs(9===n.nodeType?n.body:n);let s=document.createElement(Ns());s.setAttribute("version",_s);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 r=Object.getOwnPropertyDescriptor(e,n);void 0!==r.get||void 0!==r.set||"function"==typeof r.value||(t[n]=r.value)}return t}(t.target)),s.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 r="svg"===n?.localName,i=`wcs-${r?"s":"t"}${Ks++}`;e.replaceWith(Es(`wcs-p:${i}`));let o=document.importNode(xt(t),!0);for(let e of Array.from(o.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Rs(e,document.createElement("template"),...e.childNodes));if(r){let e=document.createElementNS(n.namespaceURI,"svg");e.append(o),o=e}let l=document.createElement("template");l.id=i,s.append(Rs(t,l,o))}e.before(s)}function Vs(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Is.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===Ns())continue;let e=t.engine;null!=e&&Gs(t,e)}}var Js=Symbol.for("wcstack.state.ssr.impl"),Qs=new Map,Ys=new WeakMap,Xs=e=>!0===c.Ro?.(e),Zs=e=>1===e.nodeType&&!qs(e)&&!Xs(e),eo=e=>e.f.flat().concat(e.z??[]),to=e=>{for(let t of eo(e))t.remove()};function no(e,t,n){let r=/^wcs-\[(?::(\d+))?/.exec(e.data),i=e.previousSibling,s=e.parentNode,o=[],l=e.nextSibling;for(e.remove();null!==l&&!Ts(l,"wcs-]");){let e=l.nextSibling;if(Ts(l,"wcs-|"))o.push([]),l.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];xs(l,"wcs-[")?e=no(l,t,n):(n.push(l),Zs(l)&&ro(l,t))}l=e}let a={branch:void 0===r[1]?null:Number(r[1]),f:o,z:l??s.appendChild(Es("wcs-]"))},u=eo(a);l=a.z.nextSibling;for(let e of u)n?.push(e),t&&Ct.add(e);return t&&null!==i?Qs.set(i,a):to(a),l}function ro(e,t){for(let n=e.firstChild;null!==n;)xs(n,"wcs-[")?n=no(n,t):(Zs(n)&&ro(n,t),n=n.nextSibling)}function io(e,t,n){let r=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=Es(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!Ts(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,r="s"===e[10]?Rs(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);r.removeAttribute("id"),t.replaceChild(r,i)}}}catch{}}else 1===i.nodeType&&!qs(i)&&(Xs(i)?Ys.set(i,{ssr:t,Te:n}):r(i))};r(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||fo(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{xs(e,"wcs-[")?r++:Ts(e,"wcs-]")&&--r<0&&(r=0,n=t+1)}),0===r)continue;let i=0;for(let r=t.firstChild;null!==r;r=r.nextSibling)if(xs(r,"wcs-["))i++;else if(Ts(r,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),ro(e,n)}function so(e,t){let n=Ys.get(e);if(void 0===n)return null;Ys.delete(e);let r=e=>io(e,n.ssr,n.Te);if(n.Te||uo(t,e,e,r),r(e),!n.Te)return null;let i=c.Te;return c.Te=go,()=>{c.Te=i,oo()}}function oo(){for(let e of Qs.values())to(e);Qs.clear()}function lo(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function ao(e,t,n,r){let i=null;for(let r of e){let e=r[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===i||e.length>i[n].length)&&(i=r)}let s=i?.[r];if(null==s)return null;let o=i[n],l=""===o?t:t.slice(o.length+1);return""===s?l:""===l?s:`${s}.${l}`}function uo(e,t,n,r){let i=document.createElement("template").content;for(let e of n.childNodes)i.appendChild(i.ownerDocument.importNode(e,!0));r(i),e.root=t;let s=()=>{};Et(e,[...i.childNodes],null,!0,s,s,s,(t,n)=>kt(e,n,null,0))}function co(e,t,n){if(Cs()){if(n instanceof Array){for(let e=n.length;e-- >0;)yt(n[e])&&n.splice(e,1);let e=t;if(n.some(bt))Ms.add(e);else if(e.localName.includes("-")&&!Xs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ls.set(e,t)}return}if("string"==typeof n){if(Is.set(t,n),qs(t.parentNode))return;let e=Es(`wcs-t:${encodeURIComponent(n)}`),r=Es("wcs-/t");return t.before(e),void t.after(r)}let r=Ps.get(e);void 0===r&&Ps.set(e,r=new Map),r.set(t,n);let i=t.getRootNode(),s=Os.get(i);return void 0===s&&Os.set(i,s=new Set),void s.add(e)}if("string"!=typeof n&&Qs.size>0){let e=Qs.get(n);void 0!==e&&(Qs.delete(n),Qs.set(t,e))}}var ho=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),fo=e=>3===e.nodeType&&""===e.data.trim(),po=e=>{let t=Qs.get(e)?.z??e;return(Hs(t)??t).nextSibling};function mo(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.jn;for(let r=0;r<n.length;r++){let i=n[r],s=e.ln,o=t[i[0]];for(let e=0;;){if(s=s.childNodes[i[e]],o?.nodeName!==s.nodeName)return!1;if(++e===i.length)break;o=(Hs(o)??o).firstChild;for(let t=i[e];t>0&&null!==o;t--)o=po(o)}e.No[r]=o}return!0}function go(e,t,n){if(0===Qs.size)return null;let r=t,i=0;if(!n){let e=ie.commentIfPrefix;if(!Ts(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(ho(n)&&i++,!Ts(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Qs.has(r)&&null!==n&&!Ts(n,e)&&1!==n.nodeType;n=n.nextSibling)ho(n)&&(r=n)}let s=Qs.get(r);if(void 0===s)return null;if(!n&&s.branch!==i)return Qs.delete(r),to(s),null;let o=s.f.shift();if(0===s.f.length&&Qs.delete(r),s.z?.replaceWith(...js(t,r)),s.z=null,void 0===o)return null;let l=[];for(let e=0;e<o.length;e++){let t=Qs.get(o[e]);if(l.push(o[e]),void 0!==t)for(;e<o.length&&o[e]!==t.z;)e++;else Hs(o[e])===o[e+1]&&e++}if(!mo(e,l)){let n=(e.Ln?e.root:e.ln).cloneNode(!0);l=e.Ln?[n]:[...n.childNodes],mo(e,l),(o[0]??s.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of o)e.remove()}return l}var yo={name:"ssr",hooks:c,install(){c.Bn=co,c.wr=so;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||Cs())return;let n=t.previousElementSibling,r=n?.localName===Ns(),i=r?n.getAttribute("version"):null,s=null===i||$s(i)===$s(_s);if(s){let t=e,n=t.$e;t.$e=(t,r)=>"$connectedCallback"===t?void 0:n.call(e,t,r)}if(!r)return;let o=!s&&parseInt(i)<4,l=/^3\.(\d+)\.(\d+)$/.exec(i),a=null!==l&&(+l[1]-5||+l[2]-3)>=0;s||console.warn(`[@wcstack/state] <${Ns()} version="${i}"> does not match ${_s}: 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=s?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 r=Object.getOwnPropertyDescriptor(n,e);void 0!==r&&(void 0!==r.get||void 0!==r.set||"function"==typeof r.value)||(n[e]=t[e])}e.hydrated=!0}let h=t.getRootNode();for(let e of Array.from(h.querySelectorAll(`[${zs}]`)))e.textContent=e.getAttribute(zs),e.removeAttribute(zs);let d=9===h.nodeType?h.body:h;n.remove();let f=e=>o?function(e,t,n){let r=new Map,i=e=>{let t=e.parentElement;for(;null!==t&&!Xs(t);)t=t.parentElement;if(null===t)return null;let n=r.get(t);if(void 0===n){let e=i(t),s=t.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of ue(t.getAttribute(ie.bindAttributeName)??"")){let t=r.et;r.Ne[0]===s&&n.push([e?ao(e,t,1,0):t,r.Ne.slice(1).join("."),e&&t])}}return n},s=(e,t,n)=>{let r=i(e);if(null===r)return t;let s=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===s)return n?t:ao(r,t,0,1)??t;let o=s[1].replace(/#m\d+\./g,"").slice(0,-1);return r.some(e=>""===e[1]&&(e[0]===o||e[2]===o))?s[2]:ao(r,s[2],2,1)??s[2]};for(let t of lo(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!Ts(r,`@@wcs-${e[1]}-end:${e[2]}`);)r=r.nextSibling;if(null!==r){for(;t.nextSibling!==r;)t.nextSibling.remove();r.remove(),t.replaceWith(..."text"===e[1]?[Es(`@@:${s(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let r of lo(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(r.data)?.[1],i=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===i)continue;let l=document.importNode(i,!0),a=ie.bindAttributeName;l.removeAttribute("id"),l.setAttribute(a,l.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,i)=>t+s(n??r,i))),o(l.content,n??r);let u=l.content.firstChild;r.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?l.content.childNodes:[l])}};o(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,n,a):io(e,n,s);s||uo(e,h,d,f),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),r=e.map(e=>e.selected),i=e.map(e=>e.hasAttribute("selected")),s=i.lastIndexOf(!0);s<0&&(s=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>r[t]!==i[t]):n.selectedIndex!==s)&&t.push([n,()=>e.forEach((e,t)=>e.selected=r[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(d)),f(d),s&&(c.Te=go,queueMicrotask(()=>{oo(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Js]={build:Vs,reset(){Ks=0}},void 0===e[As]&&(e[As]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Js].build(t),reset:()=>e[Js].reset()})}(),c.Co=h(c.Co,Ss);for(let e of en())Ss(e)}},bo="__WCSTACK_DEVTOOLS_HOOK__",wo=null,vo=new Set,_o=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),$o=new WeakMap,ko=0,So=new WeakMap;function No(e){if(null===wo)return;let t=So.get(e),n=vo.has(e)?function(e,t){let n=new Map,r=new Set,i=(r,i,s,o,l,a)=>{if(5===r)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(r,i),c=0===o.n?null:l,h=`${(e=>{let t=$o.get(e);return void 0===t&&$o.set(e,t=++ko),t})(s)}|${u}|${o.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(h))return;let d=t?.get(h);n.set(h,d??{binding:{propName:u,statePathName:o.t,bindingType:a,node:s,replaceNode:s},absoluteAddress:_o(e,o,c)})},s=e=>i(e.i,e.name,e.c,e.o,e.r,e.on()),o=e=>{if(!r.has(e)){if(r.add(e),null!==e.we)for(let t of e.we)s(t);if(e instanceof Xe&&null!==e.pe){let t=e.C.Xe;for(let n=0;n<t.length;n++){let r=e.V?.[n];void 0!==r?s(r):i(t[n].i,t[n].name,e.pe[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)l(t)}},l=e=>{if(!r.has(e))if(r.add(e),e instanceof at){i(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Ae)o(t)}else null!==e.I&&o(e.I)};for(let t of e.ue.values())for(let e of t)s(e),null!==e.j&&l(e.j);for(let t of e.oe.values())if(null!==t.N&&l(t.N),null!==t.M)for(let e of t.M)l(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,r]of t)n.has(e)||wo({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&wo({type:"state:binding-added",...r});So.set(e,n)}function Ao(e){let t=jt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function Co(e){let t=new Set,n=new Set,r=new Set,i=new Set;for(let s of e.O.all()){for(let e=1;e<=s.n;e++)t.add(s.h[e].t);"*"===s.s&&n.add(s.t),null!==s.getter&&r.add(s.t),null!==s.se&&i.add(s.t)}let s=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:r,setter:i},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.Oe.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==s.$watch&&"object"==typeof s.$watch?new Set(Object.keys(s.$watch)):null,keyedListPaths:null!==s.$listKeys&&"object"==typeof s.$listKeys?new Set(Object.keys(s.$listKeys)):null}}var Eo=new WeakSet,To=new WeakMap;function xo(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Eo.has(t))return;Eo.add(t);let r=t.emit;t.emit=(...i)=>(null!==wo&&wo({type:"state:token-emit",kind:n,tokenName:t.name,args:i,subscriberCount:t.size,stateElement:e.element}),r.apply(t,i))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.Oe.values())t(n,"event")}(e),"connected"===t){if(vo.has(e))return;vo.add(e),wo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),No(e)}else"disconnected"===t&&(vo.delete(e),No(e),wo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function Po(e,t,n,r,i,s){if(null===wo)return;let o=_o(e,t,0===t.n?null:n),l=To.get(e);void 0===l&&To.set(e,l=new Set),l.add(o),s&&wo({type:"state:write",absoluteAddress:o,value:i,oldValue:r,hasOldValue:!0})}function Oo(e){if(null===wo)return;let t=To.get(e);To.delete(e),void 0!==t&&wo({type:"state:update-batch",addresses:t}),No(e)}function Lo(e,t,n){wo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Mo={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Io(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...Mo["*"],...Object.hasOwn(Mo,e)?Mo[e]:[]])(n);return r.includes(t)||$(1205,[n,t,r.join(", ")],t,r),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}!function(e){for(let t of e)if(!g.has(t.name)){if(t.hooks!==c)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${t.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);g.add(t.name),t.install()}}([_n,br,zr,Yr,ss,vs,yo,{name:"devtools",hooks:c,install(){c.element=h(c.element,xo),c.re=h(c.re,Po),c.me=h(c.me,Oo),c.Ge=h(c.Ge,Lo),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[bo]??(e[bo]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let r of t)r.onEvent?.(e.id,n)})};return{version:2,sources:e,register(r){if(!e.has(r.id)){e.set(r.id,r),n(r);for(let e of t)e.onSourceRegistered?.(r)}},unregister(n){let r=e.get(n);if(void 0!==r){r._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(r){t.add(r);for(let t of e.values())n(t),r.onSourceRegistered?.(t);return()=>{if(t.delete(r))for(let t of e.values())n(t)}}}}());2!==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:_s,getStateElements:()=>[...vo].map(Co),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let r=n._,i=n.De?.length??0;if((null===r||0===r.size)&&0===i)continue;let s,o=0;if(null!==r)for(let e of r.values())o+=e.size;try{s=0===n.n?e.v(n,null):void 0}catch{s=void 0}t.push({path:n.t,tracked:!1,rows:o,keys:null===r?0:r.size,lists:i,lastValue:s})}return t}(Ao(e)),keys(e){let t=Ao(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return Ao(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){Ao(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(e){let t=null===wo&&null!==e;wo=e,null===e&&(So=new WeakMap),c.ct=e&&((e,t)=>wo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of vo)No(e)})}})}()}},{name:"native-commands",hooks:c,install(){c.lr=Io}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Ut]&&(e[Ut]={protocol:"wcs-binder",version:1,bind:qt})})(),en().includes(e)||Zt.push(new WeakRef(e));let t=ie.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),c.Co?.(e)}();const jo={route:"wcs-route",router:"wcs-router",outlet:"wcs-outlet",layout:"wcs-layout",layoutOutlet:"wcs-layout-outlet",link:"wcs-link",head:"wcs-head",guardHandler:"wcs-guard-handler"},Ro=!1,Ho=[".html"];function Wo(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function Uo(e,t){if(t&&"cause"in t)throw new Error(`[@wcstack/router] ${e}`,{cause:t.cause});throw new Error(`[@wcstack/router] ${e}`)}let Do=class extends Error{fallbackPath;constructor(e,t){super(e),this.fallbackPath=t}};const Fo={int:{typeName:"int",pattern:/^-?\d+$/,parse(e){if(this.pattern.test(e))return parseInt(e,10)}},float:{typeName:"float",pattern:/^-?\d+(?:\.\d+)?$/,parse(e){if(this.pattern.test(e))return parseFloat(e)}},bool:{typeName:"bool",pattern:/^(true|false|0|1)$/,parse(e){if(this.pattern.test(e))return"true"===e||"1"===e}},uuid:{typeName:"uuid",pattern:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,parse(e){if(this.pattern.test(e))return e}},slug:{typeName:"slug",pattern:/^[a-z0-9]+(?:-[a-z0-9]+)*$/,parse(e){if(this.pattern.test(e))return e}},isoDate:{typeName:"isoDate",pattern:/^\d{4}-\d{2}-\d{2}$/,parse(e){if(!this.pattern.test(e))return;const[t,n,r]=e.split("-").map(Number),i=new Date(t,n-1,r);return i.getFullYear()===t&&i.getMonth()===n-1&&i.getDate()===r?i:void 0}},any:{typeName:"any",pattern:/^.+$/,parse(e){if(this.pattern.test(e))return e}}};function zo(e){const t={};for(const[n,r]of new URLSearchParams(e))t[n]=r;return Object.freeze(t)}function qo(e,t){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const r of n){if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(e[r]!==t[r])return!1}return!0}const Bo={static:2,param:1,"catch-all":0};let Ko=class extends EventTarget{_target;_parentCore=null;_path="";_name="";_isFallbackRoute=!1;_segmentInfos=[];_absoluteSegmentInfos;_paramNames;_absoluteParamNames;_weight;_absoluteWeight;_segmentCount;_params={};_typedParams={};_active=!1;_hasGuard=!1;_guardHandler=null;_guardFallbackPath="";_waitForSetGuardHandler=null;_resolveSetGuardHandler=null;_guardHandlerLoadFailed=!1;constructor(e){super(),this._target=e??this}get parentCore(){return this._parentCore}set parentCore(e){this._parentCore=e}get path(){return this._path}get name(){return this._name}get isFallbackRoute(){return this._isFallbackRoute}get isRelative(){return!this._path.startsWith("/")}get segmentInfos(){return this._segmentInfos}_checkParentCore(e,t){return this._isFallbackRoute||(this.isRelative&&!this._parentCore&&Uo(`${jo.route} is relative but has no parent route.`),!this.isRelative&&this._parentCore&&Uo(`${jo.route} is absolute but has a parent route.`)),this.isRelative&&this._parentCore?e(this._parentCore):t()}get absolutePath(){return this._checkParentCore(e=>{const t=e.absolutePath;return t.endsWith("/")?t+this._path:t+"/"+this._path},()=>this._path)}get absoluteSegmentInfos(){return void 0===this._absoluteSegmentInfos&&(this._absoluteSegmentInfos=this._checkParentCore(e=>[...e.absoluteSegmentInfos,...this._segmentInfos],()=>[...this._segmentInfos])),this._absoluteSegmentInfos}get params(){return this._params}get typedParams(){return this._typedParams}get active(){return this._active}get paramNames(){if(void 0===this._paramNames){const e=[];for(const t of this._segmentInfos)t.paramName&&e.push(t.paramName);this._paramNames=e}return this._paramNames}get absoluteParamNames(){return void 0===this._absoluteParamNames&&(this._absoluteParamNames=this._checkParentCore(e=>[...e.absoluteParamNames,...this.paramNames],()=>[...this.paramNames])),this._absoluteParamNames}get weight(){if(void 0===this._weight){let e=0;for(const t of this._segmentInfos)e+=Bo[t.type];this._weight=e}return this._weight}get absoluteWeight(){return void 0===this._absoluteWeight&&(this._absoluteWeight=this._checkParentCore(e=>e.absoluteWeight+this.weight,()=>this.weight)),this._absoluteWeight}get segmentCount(){if(void 0===this._segmentCount){let e=0;for(const t of this._segmentInfos)"catch-all"!==t.type&&e++;this._segmentCount=""===this._path?0:e}return this._segmentCount}get absoluteSegmentCount(){return this._checkParentCore(e=>e.absoluteSegmentCount+this.segmentCount,()=>this.segmentCount)}parsePath(e,t={}){this._segmentInfos=[],this._absoluteSegmentInfos=void 0,this._paramNames=void 0,this._absoluteParamNames=void 0,this._weight=void 0,this._absoluteWeight=void 0,this._segmentCount=void 0,this._path=e,this._name=t.name||"",this._isFallbackRoute=t.isFallback||!1,t.isIndex&&this._segmentInfos.push({type:"static",segmentText:"",paramName:null,pattern:/^$/,isIndex:!0});const n=e.split("/");for(let e=0;e<n.length;e++){const r=n[e];if(!(""===r&&e===n.length-1&&e>0)){if("*"===r){this._segmentInfos.push({type:"catch-all",segmentText:r,paramName:"*",pattern:new RegExp("^(.*)$")});break}if(r.startsWith(":")){const e=r.match(/^:([^()]+)(\(([^)]+)\))?$/);let t,n="any";e?(t=e[1],e[3]&&Object.keys(Fo).includes(e[3])&&(n=e[3])):t=r.substring(1),this._segmentInfos.push({type:"param",segmentText:r,paramName:t,pattern:new RegExp("^([^\\/]+)$"),paramType:n})}else""===r&&t.isIndex||this._segmentInfos.push({type:"static",segmentText:r,paramName:null,pattern:new RegExp(`^${r}$`)})}}this._hasGuard=!1,t.hasGuard&&(this._guardFallbackPath=t.guardFallback||"/",this.enableGuard())}enableGuard(){this._hasGuard||(this._hasGuard=!0,this._guardFallbackPath||="/",this._waitForSetGuardHandler=new Promise(e=>{this._resolveSetGuardHandler=e}))}setParams(e,t){const n=this._active;this._params=e,this._typedParams=t,this._active=!0,this._target.dispatchEvent(new CustomEvent("wcs-route:params-changed",{detail:{params:e,typedParams:t},bubbles:!0})),n||this._target.dispatchEvent(new CustomEvent("wcs-route:active-changed",{detail:!0,bubbles:!0}))}clearParams(){const e=this._active;this._params={},this._typedParams={},this._active=!1,e&&this._target.dispatchEvent(new CustomEvent("wcs-route:active-changed",{detail:!1,bubbles:!0}))}shouldChange(e){for(const t of this.paramNames)if(this._params[t]!==e[t])return!0;return!1}get hasGuard(){return this._hasGuard}get guardHandler(){return this._guardHandler||Uo(`${jo.route} has no guardHandler.`),this._guardHandler}set guardHandler(e){this._guardHandler=e,this._resolveSetGuardHandler?.()}notifyGuardHandlerLoadFailed(){this._guardHandlerLoadFailed=!0,this._resolveSetGuardHandler?.()}async guardCheck(e){if(this._hasGuard&&this._waitForSetGuardHandler&&await this._waitForSetGuardHandler,this._guardHandler){const t=e.path,n=e.lastPath,r=await this._guardHandler(t,n,function(e){return Object.freeze({params:Object.freeze({...e.params}),typedParams:Object.freeze({...e.typedParams}),searchParams:zo(e.search??""),routeName:e.routes[e.routes.length-1]?.name??""})}(e));if("string"==typeof r&&""!==r)throw new Do("Navigation cancelled by guard.",r);if(!r)throw new Do("Navigation cancelled by guard.",this._guardFallbackPath);return"object"==typeof r?r:null}if(this._hasGuard&&this._guardHandlerLoadFailed)throw new Do("Navigation cancelled: guard handler failed to load.",this._guardFallbackPath);return null}};const Go="data-wcs-ssr",Vo="data-wcs-ssr-link",Jo="@@wcs-route-ph:",Qo="@@wcs-route-start:",Yo="@@wcs-route-end:";let Xo=class extends HTMLElement{_core;_routeParentNode=null;_routeChildNodes=[];_routerNode=null;_uuid=Wo();_placeHolder=document.createComment(`@@route:${this._uuid}`);_childNodeArray;_endMarker;held=null;_childIndex=0;_initialized=!1;_routes;constructor(){super(),this._core=new Ko(this)}get routeParentNode(){return this._routeParentNode}get routeChildNodes(){return this._routeChildNodes}get routerNode(){return this._routerNode||Uo(`${jo.route} has no routerNode.`),this._routerNode}get uuid(){return this._uuid}get placeHolder(){return this._placeHolder}get endMarker(){return void 0===this._endMarker&&(this._endMarker=document.createComment(`${Yo}${this.absolutePath}`)),this._endMarker}get childNodeArray(){return void 0===this._childNodeArray&&(this._childNodeArray=Array.from(this.childNodes)),this._childNodeArray}adoptChildNodes(e,t){for(this._childNodeArray=[...e],t&&(this._endMarker=t);this.firstChild;)this.removeChild(this.firstChild)}get routes(){return void 0===this._routes&&(this._routes=this.routeParentNode?this.routeParentNode.routes.concat(this):[this]),this._routes}get childIndex(){return this._childIndex}get path(){return this._core.path}get name(){return this._core.name}get isRelative(){return this._core.isRelative}get absolutePath(){return this._core.absolutePath}get segmentInfos(){return this._core.segmentInfos}get absoluteSegmentInfos(){return this._core.absoluteSegmentInfos}get params(){return this._core.params}get typedParams(){return this._core.typedParams}get paramNames(){return this._core.paramNames}get absoluteParamNames(){return this._core.absoluteParamNames}get weight(){return this._core.weight}get absoluteWeight(){return this._core.absoluteWeight}get segmentCount(){return this._core.segmentCount}get absoluteSegmentCount(){return this._core.absoluteSegmentCount}get fullpath(){return this.absolutePath}get hasGuard(){return this._core.hasGuard}get guardHandler(){return this._core.guardHandler}set guardHandler(e){this._core.guardHandler=e}setParams(e,t){this._core.setParams(e,t)}clearParams(){this._core.clearParams()}shouldChange(e){return this._core.shouldChange(e)}async guardCheck(e){return this._core.guardCheck(e)}notifyGuardHandlerLoadFailed(){this._core.notifyGuardHandlerLoadFailed()}enableGuard(){this._core.enableGuard()}testAncestorNode(e){let t=this._routeParentNode;for(;t;){if(t===e)return!0;t=t.routeParentNode}return!1}initialize(e,t){if(this._initialized)return;let n;this._initialized=!0;let r=!1,i=!1;this.hasAttribute("path")?n=this.getAttribute("path")||"":this.hasAttribute("index")?(n="",r=!0):this.hasAttribute("fallback")?(n="",i=!0):Uo(`${jo.route} should have a "path" or "index" attribute.`),this._routerNode=e,this._routeParentNode=t;const s=t||e;s.routeChildNodes.push(this),this._childIndex=s.routeChildNodes.length-1,i&&(t&&Uo(`${jo.route} with fallback attribute must be a direct child of ${jo.router}.`),e.fallbackRoute&&Uo(`${jo.router} can have only one fallback route.`),e.fallbackRoute=this),t&&(this._core.parentCore=t._core),this._core.parsePath(n,{isIndex:r,isFallback:i,hasGuard:this.hasAttribute("guard"),guardFallback:this.getAttribute("guard"),name:this.getAttribute("name")||""}),this.setAttribute("fullpath",this.absolutePath)}};const Zo=Symbol.for("wcstack.trustedTypes.policy"),el=Symbol.for("wcstack.trustedTypes.internal"),tl="wcstack";function nl(){const e=globalThis[Zo];return null===e||"object"!=typeof e?null:e}let rl=!1;function il(e){const t=function(){const e=globalThis,t=e[el];if(void 0!==t)return t;const n=globalThis.trustedTypes;let r=null;if(n&&"function"==typeof n.createPolicy)try{r=n.createPolicy(tl,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){"function"!=typeof nl()?.createHTML&&console.error(`[@wcstack/router] Could not create the Trusted Types policy "${tl}". Allow it in the CSP (\`trusted-types ${tl};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,e)}return e[el]=r,r}(),n=t?.createHTML;if("function"==typeof n)return n.call(t,e);if(!("trustedTypes"in globalThis))return e;const r=nl(),i=r?.createHTML;return"function"==typeof i?(rl||(rl=!0,console.warn(`[@wcstack/router] Falling back to the injected Trusted Types policy to expand a layout template, because the "${tl}" policy could not be created. If that policy sanitizes (e.g. DOMPurify), custom elements in the layout may be stripped. Allow \`trusted-types ${tl};\` in the CSP to avoid this. See docs/csp.md section 7.`)),i.call(r,e)):e}const sl=new Map;let ol=class extends HTMLElement{_uuid=Wo();constructor(){super()}async _loadTemplateFromSource(e){try{const t=await fetch(e);t.ok||Uo(`${jo.layout} failed to fetch layout from source: ${e}, status: ${t.status}`);const n=await t.text();return sl.set(e,n),n}catch(t){Uo(`${jo.layout} failed to load layout from source: ${e}, error: ${t}`,{cause:t})}}_loadTemplateFromDocument(e){const t=document.getElementById(`${e}`);return t&&t instanceof HTMLTemplateElement?t.innerHTML:null}async loadTemplate(){const e=this.getAttribute("src"),t=this.getAttribute("layout");e&&t&&console.warn(`${jo.layout} have both "src" and "layout" attributes.`);const n=document.createElement("template");if(e)sl.has(e)?n.innerHTML=il(sl.get(e)||""):n.innerHTML=il(await this._loadTemplateFromSource(e)||"");else if(t){const e=this._loadTemplateFromDocument(t);e?n.innerHTML=il(e):console.warn(`${jo.layout} could not find template with id "${t}".`)}return n}get uuid(){return this._uuid}get enableShadowRoot(){return!!this.hasAttribute("enable-shadow-root")||!this.hasAttribute("disable-shadow-root")&&Ro}get name(){return this.getAttribute("name")||""}},ll=class extends HTMLElement{_routesNode=null;_lastRoutes=[];_initialized=!1;constructor(){super()}get routesNode(){return this._routesNode||Uo(`${jo.outlet} has no routesNode.`),this._routesNode}set routesNode(e){this._routesNode=e}get rootNode(){return this.shadowRoot?this.shadowRoot:this}get lastRoutes(){return this._lastRoutes}set lastRoutes(e){this._lastRoutes=[...e]}_resolveEnableShadowRoot(){return!!this.hasAttribute("enable-shadow-root")||!this.hasAttribute("disable-shadow-root")&&Ro}_initialize(){this._resolveEnableShadowRoot()&&this.attachShadow({mode:"open"}),this._initialized=!0}connectedCallback(){this._initialized||this._initialize()}disconnectedCallback(){this._lastRoutes=[]}};const al=new Set(["props","states","attr",""]);function ul(e,t,n){for(const[r,i]of Object.entries(t))switch(n){case"props":e.props={...e.props,[r]:i};break;case"states":e.states={...e.states,[r]:i};break;case"attr":null==i?e.removeAttribute(r):e.setAttribute(r,String(i));break;case"":e[r]=i}}function cl(e,t){e.hasAttribute("data-bind")||Uo(`${e.tagName} has no 'data-bind' attribute.`);const n=e.getAttribute("data-bind")||"";al.has(n)||Uo(`${e.tagName} has invalid 'data-bind' attribute: ${n}`);const r=n,i=function(e){const t=e.tagName.toLowerCase();if(t.includes("-"))return t;const n=e.getAttribute("is");return n&&n.includes("-")?n:null}(e);i&&void 0===customElements.get(i)?customElements.whenDefined(i).then(()=>{e.isConnected&&ul(e,t,r)}).catch(()=>{Uo(`Failed to define custom element: ${i}`)}):ul(e,t,r)}const hl=Symbol.for("wcstack.binder");function dl(){const e=globalThis[hl];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}const fl=Symbol.for("wcstack.binder.pending"),pl=Symbol.for("wcstack.binder.taken");function ml(){const e=globalThis;let t=e[pl];return void 0===t&&(t=new WeakSet,e[pl]=t),t}function gl(e,t){const n=dl();return null===n?(function(){const e=globalThis;let t=e[fl];return void 0===t&&(t=[],e[fl]=t),t}().push(e),!1):(ml().add(e),n.bind(e,t),!0)}const yl={range:!0};function bl(e,t){for(const n of e.routeChildNodes)t.add(n.placeHolder).add(n.endMarker),bl(n,t);return t}function wl(e){const t=e.placeHolder,n=e.endMarker,r=null!==n.parentNode&&n.parentNode===t.parentNode&&!!(4&t.compareDocumentPosition(n)),i=r?null:bl(e,new Set),s=[];let o=0;for(let l=t.nextSibling;null!==l&&l!==n&&(null===i||8!==l.nodeType||!/^@@(route:|wcs-route-)/.test(l.data)||i.has(l));l=l.nextSibling)s.push(l),(r||e.childNodeArray.includes(l))&&(o=s.length);return s.length=o,s}const vl=new WeakSet;function _l(e){const t=jo.router,n=jo.outlet;for(const r of e.querySelectorAll(n))vl.has(r)||r.previousElementSibling?.matches(t)||(vl.add(r),console.warn(`[@wcstack/router] [wcs/router-outlet-misplaced] A <${t}> uses only the element right after it as its outlet, and this page has a <${n}> that no router uses. The router makes an outlet of its own right after itself, so the routes render there and the <${n}> you placed stays empty. Move the <${n}> right after the <${t}>.`,r))}const $l=e=>{for(const t of e)if(t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&""!==t.textContent.trim())return!0;return!1};function kl(e){console.warn(`[@wcstack/router] [wcs/layout-slot-missing] This layout's template has no default <slot>, so what its <${jo.layout}> holds outside the named slots — the nested routes and their pages — is not shown. Put a <slot></slot> where the page goes.`,e)}class Sl extends HTMLElement{_layout=null;_initialized=!1;_initializing=!1;_disconnectedDuringInit=!1;_layoutChildNodes=[];constructor(){super()}get layout(){return this._layout||Uo(`${jo.layoutOutlet} has no layout.`),this._layout}set layout(e){this._layout=e,this.setAttribute("name",e.name)}get name(){return this.layout.name}async _initialize(){this._initializing=!0;try{this._initialized=!0,this.layout.enableShadowRoot&&!this.shadowRoot&&this.attachShadow({mode:"open"});const e=await this.layout.loadTemplate();if(!this.isConnected)return void(this._initialized=!1);if(this.shadowRoot){this.shadowRoot.appendChild(e.content.cloneNode(!0));const t=[];for(const e of Array.from(this.layout.childNodes))this._layoutChildNodes.push(e),e instanceof Element&&e.getAttribute("slot")||t.push(e),this.appendChild(e);!this.shadowRoot.querySelector('slot:not([name]), slot[name=""]')&&$l(t)&&kl(this),_l(this.shadowRoot)}else{const t=e.content.cloneNode(!0),n=new Map;t.querySelectorAll("slot").forEach(e=>{const t=e.getAttribute("name")||"";n.has(t)?console.warn(`${jo.layoutOutlet} duplicate slot name "${t}" in layout template.`):n.set(t,e)});const r=new Map,i=document.createDocumentFragment();for(const e of Array.from(this.layout.childNodes)){if(this._layoutChildNodes.push(e),e instanceof Element){const t=e.getAttribute("slot")||"";if(t.length>0&&n.has(t)){r.has(t)||r.set(t,document.createDocumentFragment()),r.get(t)?.appendChild(e);continue}}i.appendChild(e)}for(const[e,t]of n){const n=r.get(e);n&&t.replaceWith(n)}const s=n.get("");s?s.replaceWith(i):$l(i.childNodes)&&kl(this),this.appendChild(t),_l(this)}!function(e){if(null!==dl())for(const t of e)1===t.nodeType&&gl(t,yl)}(Array.from(this.childNodes))}finally{this._initializing=!1}}async connectedCallback(){null!==this._layout&&(this._initialized||(this._disconnectedDuringInit=!1,await this._initialize(),!this._disconnectedDuringInit&&this.isConnected))}disconnectedCallback(){this._initializing&&(this._disconnectedDuringInit=!0)}assignParams(e){for(const t of this._layoutChildNodes)t instanceof Element&&(t.querySelectorAll("[data-bind]").forEach(t=>{cl(t,e)}),t.hasAttribute("data-bind")&&cl(t,e))}}function Nl(){return document.createElement(jo.layoutOutlet)}const Al="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";function Cl(e,t){(async function(e,t){let n=null,r=null;const i=t.uuid||"",s=`\n//# sourceURL=${i?`wcs-guard-handler:${i}`:"wcs-guard-handler"}\n`,o=e.text+s;let l=!1;const a=e=>{e.effectiveDirective.startsWith("script-src")&&(l=!0)};document.addEventListener("securitypolicyviolation",a);try{if("function"==typeof URL.createObjectURL){const t=new Blob([o],{type:"application/javascript"}),i=URL.createObjectURL(t);try{n=await(import(i))}catch(e){r=e}finally{URL.revokeObjectURL(i)}}if(!n){const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(o)));try{n=await(import(`data:application/javascript;base64,${t}`))}catch(e){await new Promise(e=>setTimeout(e)),Uo(function(e,t,n){return n?`The guard <script> was blocked by Content-Security-Policy. Guard scripts are inline-only and are evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/router, or allow blob: in script-src. See ${Al}`:`loadGuardHandler: failed to import guard script. data: URL error: ${e?.message??String(e)}`+(t?`. Blob URL error: ${t?.message??String(t)}`:"")+`. If this page sets a Content-Security-Policy, see ${Al}`}(e,r,l),{cause:r??e})}}}finally{document.removeEventListener("securitypolicyviolation",a)}return n&&"function"==typeof n.default?n.default:null})(e,t).then(e=>{e?t.guardHandler=e:(console.error(`${jo.guardHandler}: the <script type="module"> has no default-exported function, so the route's guard redirects every navigation.`),t.notifyGuardHandlerLoadFailed())}).catch(e=>{console.error("loadGuardHandler failed:",e),t.notifyGuardHandlerLoadFailed()})}function El(e,t){let n=e.get(t.absolutePath);n||(n=[]);for(const e of n)if(!t.testAncestorNode(e)){console.warn(`Duplicate route path detected: '${t.absolutePath}' (defined as '${t.path}')`);break}n.push(t),1===n.length&&e.set(t.absolutePath,n)}async function Tl(e,t,n,r){const i=document.createDocumentFragment();let s=null;const o=Array.from(t.childNodes);for(const t of o)if(t.nodeType===Node.ELEMENT_NODE){let o=t,l=t,a=n;const u=l.tagName.toLowerCase();if(u===jo.route){const t=document.createDocumentFragment();for(const e of Array.from(l.childNodes))t.appendChild(e);const i=document.importNode(l,!0);customElements.upgrade(i),i.appendChild(t);const u=i;u.initialize(e,n),El(r,u),o=u.placeHolder,l=u,a=u,s=u}else{if(u===jo.guardHandler){const e=n??s,t=l.querySelector('script[type="module"]');null===e?console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${jo.guardHandler}> outside a <${jo.route}> guards nothing: put it inside the route it guards.`):t?(null===n&&console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${jo.guardHandler}> outside a <${jo.route}> guards the route before it, "${e.absolutePath}": put it inside that route.`),e.enableGuard(),Cl(t,e)):(e.enableGuard(),e.notifyGuardHandlerLoadFailed(),console.error(`[@wcstack/router] [wcs/guard-handler-ignored] The <${jo.guardHandler}> of route "${e.absolutePath}" has no <script type="module">, so its guard cannot run: every navigation into the route is redirected to "${e.getAttribute("guard")||"/"}".`));continue}if("template"===u){i.appendChild(l);continue}if(u===jo.layout){const e=document.createDocumentFragment();for(const t of Array.from(l.childNodes))e.appendChild(t);const t=document.importNode(l,!0);customElements.upgrade(t),t.appendChild(e);const n=t,r=Nl();r.layout=n,o=r,l=t}}const c=await Tl(e,l,a,r);l.replaceChildren(),l.appendChild(c),i.appendChild(o)}else i.appendChild(t);return i}async function xl(e){const t=new Map;return await Tl(e,e.template.content,null,t)}function Pl(e){return!1!==e.checkVisibility?.()}function Ol(e,t,n,r){const i=function(e,t,n){const r={},i={};let s=!0,o=!1,l=0,a=0;for(;l<e.absoluteSegmentInfos.length;){const t=e.absoluteSegmentInfos[l];if(t.isIndex){l++;continue}if(0===l&&""===t.segmentText&&"static"===t.type){l++;continue}const u=n[a];if(void 0===u){s=!1;break}let c=!1;if("param"===t.type){const e=t.paramType||"any",n=Fo[e].parse(u);void 0!==n&&(t.paramName&&(r[t.paramName]=u,i[t.paramName]=n),c=!0)}else c=null!==t.pattern.exec(u);if(!c){s=!1;break}if("catch-all"===t.type){const e=n.slice(a).join("/");r["*"]=e,i["*"]=e,o=!0;break}l++,a++}let u=!1;return s&&(o||l===e.absoluteSegmentInfos.length&&a===n.length)&&(u=!0),u?{path:t,routes:e.routes,params:r,typedParams:i,lastPath:""}:null}(e,t,n);i&&r.push(i);for(const i of e.routeChildNodes)Ol(i,t,n,r)}function Ll(e,t){const n=e.routeChildNodes,r=[],i=t.split("/"),s=i.filter((e,t)=>!(0===t&&""===e||t===i.length-1&&""===e&&i.length>1));for(const e of n)Ol(e,t,s,r);return r.sort((e,t)=>{const n=e.routes.at(-1),r=t.routes.at(-1),i=n.absoluteSegmentCount-r.absoluteSegmentCount;if(0!==i)return-i;const s=n.absoluteWeight-r.absoluteWeight;return 0!==s?-s:n.childIndex-r.childIndex}),r.length>0?r[0]:null}let Ml=null,Il=null;function jl(){const e=Ho;return 0===e.length?null:(Ml===e&&Il||(Ml=e,Il=new RegExp(`\\/[^/]+(?:${e.map(e=>e.replace(/\./g,"\\.")).join("|")})$`,"i")),Il)}function Rl(e){let t=e||"/";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=jl();return n&&(t=t.replace(n,"")),""===t&&(t="/"),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}function Hl(e,t){let n=e;return""!==t&&(e===t?n="":e.startsWith(t+"/")&&(n=e.slice(t.length))),""===n?"/":n}function Wl(e){let t=e||"";if(!t)return"";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=jl();return n&&(t=t.replace(n,"")),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),"/"===t?"":t}function Ul(e){if(null!==e.held)return;const t=wl(e),n=new Set(t),r=[...t,...e.childNodeArray];let i=null;for(const s of e.childNodeArray)n.has(s)?i=s:null===s.parentNode||r.some(e=>e!==s&&e.contains(s))||(t.splice(null===i?0:t.indexOf(i)+1,0,s),n.add(s),i=s);const s=document.createDocumentFragment();!function(e,t){const n=t.map(e=>e.parentNode);for(let r=0;r<t.length;r++)t[r].parentNode===n[r]&&e.appendChild(t[r])}(s,t),s.appendChild(e.endMarker),e.held=s}function Dl(e){e.clearParams(),Ul(e)}function Fl(e,t){const n={},r={};for(const i of e.paramNames)n[i]=t.params[i],r[i]=t.typedParams[i];e.setParams(n,r);for(const t of e.childNodeArray)if(t.nodeType===Node.ELEMENT_NODE){const n=t;n.querySelectorAll("[data-bind]").forEach(t=>{cl(t,e.typedParams)}),n.hasAttribute("data-bind")&&cl(n,e.typedParams),n.querySelectorAll(jo.layoutOutlet).forEach(t=>{t.assignParams(e.typedParams)}),n.tagName.toLowerCase()===jo.layoutOutlet&&n.assignParams(e.typedParams)}}const zl=new WeakSet;function ql(e){const t=e.placeHolder;null!==t.parentNode&&(zl.has(e)||null!==e.endMarker.parentNode?(Ul(e),t.after(e.held),e.held=null):t.after(...e.childNodeArray,e.endMarker),zl.add(e))}const Bl=Symbol.for("wcstack.transition-runner");const Kl=new WeakSet,Gl="data-wcs";function Vl(e){return e.hasAttribute(Gl)||null!==e.querySelector(`[${Gl}]`)}function Jl(e,t,n){!Kl.has(e)&&Vl(e)&&(Kl.add(e),function(e){"complete"===document.readyState?e():window.addEventListener("load",e,{once:!0})}(()=>{var r;null!==dl()||(r=e,ml().has(r))||console.warn(`[@wcstack/router] ${t} contains ${Gl} bindings that will never be applied. A binding exists only for nodes that were in the document when @wcstack/state built its bindings, and these nodes were not. They will render empty. ${n}`)}))}function Ql(e){return"AbortError"===e?.name}const Yl=new WeakMap;function Xl(e){for(const t of e.childNodeArray)if(1===t.nodeType){if(t.isConnected){if(gl(t,yl))continue}else if(null!==dl())continue;Jl(t,`<${t.tagName.toLowerCase()}> inside a route`,'Load @wcstack/state on this page, or render data-driven markup outside <wcs-router> — bind the router\'s `path` into state and gate the markup with <template data-wcs="if: …">. See examples/router-i18n.')}}async function Zl(e,t){try{let n=null;for(const e of t.routes){const r=await e.guardCheck(t);r&&(n=null===n?r:Object.assign({},n,r))}t.data=n,Yl.delete(e)}catch(n){if(n instanceof Do){const r=(Yl.get(e)??0)+1;return r>10?(Yl.delete(e),console.error(`${jo.router}: guard redirect loop — stopped after 10 redirects in a row (the last: ${t.path} → ${n.fallbackPath}). The guards of these routes send each other back and forth.`),!1):(Yl.set(e,r),e.connectedCallbackPromise.catch(()=>{}).then(()=>e.replace(n.fallbackPath)).catch(e=>{Ql(e)||console.error("Fallback navigation failed:",e)}),!1)}throw n}return!0}async function ea(e,t,n,r,i=""){const s=Hl(n,e.basename);if(e.isSameMatch(s))return e.commitNavigation({params:e.params,typedParams:e.typedParams,routeName:e.routeName,data:e.data,search:i,path:s}),!0;let o=Ll(e,s);o||(e.fallbackRoute?o={routes:[e.fallbackRoute],params:{},typedParams:{},path:s,lastPath:r}:Uo(`${jo.router} No route matched for path: ${s}`)),o.lastPath=r,o.search=i;const l=t.lastRoutes,a=await async function(e,t,n,r){if(!await Zl(e,t))return!1;r?.();const i=new Set(t.routes),s=new Set(n),o=()=>{for(const e of n)i.has(e)||Dl(e);const e=[];for(const n of t.routes)(e.length>0||!s.has(n)||n.shouldChange(t.params))&&(e.push(n),Fl(n,t));let r=!1;for(const t of e){const e=s.has(t);e&&r||ql(t),r||=e,n.length>0&&!e&&Xl(t)}};let l;return 0===n.length?o():l=function(e,t,n){const r=function(e){const t=globalThis[Bl];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}(e);if(null!==r)return r.run(t,{source:e,types:n});t()}("router",o),void 0!==l&&await l,!0}(e,o,l,()=>{e.commitNavigation({params:o.params,typedParams:o.typedParams,routeName:o.routes[o.routes.length-1]?.name??"",data:o.data??null,search:i,path:s},!0)});return!!a&&(e.releasePath(),t.lastRoutes=o.routes,l.length>0&&function(e,t){if("title"===e.announcePolicy){const t=e.a11yRegion;null!==t&&(t.textContent=document.title)}if("heading"===e.focusPolicy){const e=function(e){for(const t of e){if(t.nodeType!==Node.ELEMENT_NODE)continue;const e=t;if(/^H[1-6]$/.test(e.tagName)){if(Pl(e))return e}else for(const t of e.querySelectorAll("h1,h2,h3,h4,h5,h6"))if(Pl(t))return t}return null}(t.routes[t.routes.length-1].childNodeArray);if(null!==e)e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1"),e.focus();else{const e=document.querySelector("[autofocus]");null!==e?e.focus():document.activeElement instanceof HTMLElement&&document.activeElement.blur()}}}(e,o),!0)}function ta(){const e=window.navigation;return e?"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener?null:e:null}function na(e){let t=e,n="";const r=t.indexOf("#");r>=0&&(n=t.slice(r),t=t.slice(0,r));let i="";const s=t.indexOf("?");return s>=0&&(i=t.slice(s),t=t.slice(0,s)),{pathname:t,search:i,hash:n}}function ra(e){return"?"===e?"":e}function ia(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const sa=new WeakSet;function oa(e,t,n){if(sa.has(e))return;sa.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const la=new WeakMap;function aa(e,t,n){const r=function(e,t){let n=la.get(e);return void 0===n&&(n=new Map,la.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}(e,t);!function(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}(e,t,void 0===n?r:null===n?null:String(n))}function ua(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}function ca(e){if(!e||"a"!==e.localName&&"area"!==e.localName)return null;const t=e.getAttribute("href")?.trim();return void 0!==t&&t.startsWith("#")?t:null}function ha(e){const t=new URL(window.location.href),n=new URL(e);return t.hash="",n.hash="",t.href===n.href}function da(e){const t=function(e){if(""===e)return null;const t=e=>document.getElementById(e)??Array.from(document.getElementsByName(e)).find(e=>"a"===e.localName)??null,n=t(e);if(null!==n)return n;let r;try{r=decodeURIComponent(e)}catch{return null}return r===e?null:t(r)}(e);null!==t&&(t.matches("a[href], area[href], button, input, select, textarea, iframe, summary, [contenteditable], audio[controls], video[controls], [tabindex]")||t.setAttribute("tabindex","-1"),t.focus({preventScroll:!0}))}function fa(e){const t=new URL(e,window.location.href);window.location.assign(t.href),da(t.hash.slice(1))}const pa=Object.freeze({});class ma extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"navigateUrl",event:"wcs-router:navigate-url-changed",semantics:"state"},{name:"replaceUrl",event:"wcs-router:replace-url-changed",semantics:"state"},{name:"path",event:"wcs-router:path-changed",semantics:"state"},{name:"params",event:"wcs-router:params-changed",semantics:"state",getter:e=>e.detail.params},{name:"typedParams",event:"wcs-router:params-changed",semantics:"state",getter:e=>e.detail.typedParams},{name:"searchParams",event:"wcs-router:search-changed",semantics:"state"},{name:"routeName",event:"wcs-router:route-name-changed",semantics:"state"},{name:"data",event:"wcs-router:data-changed",semantics:"state"}],inputs:[{name:"basename",attribute:"basename"},{name:"navigateUrl"},{name:"replaceUrl"},{name:"leaveConfirm",attribute:"leave-confirm"}],commands:[{name:"navigate",async:!0},{name:"replace",async:!0}]};_outlet=null;_template=null;_routeChildNodes=[];_basename="";_path="";_initialized=!1;_fallbackRoute=null;_listeningPopState=!1;_listeningNavigate=!1;_listeningClick=!1;_navigateUrl=null;_replaceUrl=null;_disconnectedDuringInit=!1;_initializing=!1;_a11yRegion=null;_params=pa;_typedParams=pa;_searchParams=pa;_routeName="";_data=null;_hasCommitted=!1;_pathHeld=!1;_leaveChecked=!1;_leaveConfirmed=!1;_unloadConfirmed=!1;_listeningUnload=!1;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;constructor(){super(),this._connectedCallbackPromise=new Promise((e,t)=>{this._resolveConnectedCallback=e,this._rejectConnectedCallback=t}),this._connectedCallbackPromise.catch(()=>{})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get a11yRegion(){return this._a11yRegion}get focusPolicy(){return"heading"===this.getAttribute("focus")?"heading":null}get announcePolicy(){return"title"===this.getAttribute("announce")?"title":null}_ensureA11yRegion(){if(null!==this._a11yRegion)return;const e=document.createElement("div");e.setAttribute("role","status"),e.style.position="absolute",e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.style.clipPath="inset(50%)",e.style.whiteSpace="nowrap",this.appendChild(e),this._a11yRegion=e}_normalizePathname(e){return Rl(e)}_normalizeBasename(e){return Wl(e)}_joinInternalPath(e,t){const n=this._normalizeBasename(e);let r=t.startsWith("/")?t:"/"+t;return r=this._normalizePathname(r),n?"/"===r?n+"/":n+r:r}_notifyLocationChange(){window.dispatchEvent(new CustomEvent("wcs:navigate"))}_getBasename(){let e=new URL(document.baseURI).pathname||"/";return"/"===e?"":this._normalizeBasename(e)}get basename(){return this._basename}set basename(e){aa(this,"basename",e)}get leaveConfirm(){return this.getAttribute("leave-confirm")||null}set leaveConfirm(e){aa(this,"leave-confirm",!0===e?"Leave this page? Changes you made may not be saved.":!1===e?null:e),this._syncBeforeUnload()}_onBeforeUnload=e=>{null===this.leaveConfirm||this._unloadConfirmed||e.preventDefault()};_syncBeforeUnload(){const e=this.isConnected&&null!==this.leaveConfirm&&!ua();e!==this._listeningUnload&&(this._listeningUnload=e,e?window.addEventListener("beforeunload",this._onBeforeUnload):window.removeEventListener("beforeunload",this._onBeforeUnload))}_confirmLeave(e){const t=this.leaveConfirm;return!(null!==t&&this._hasCommitted&&!this._leaveConfirmed&&!this.isSameMatch(Hl(this._normalizePathname(e),this._basename)))||(this._leaveConfirmed=window.confirm(t))}_confirmUnload(e){const t=this.leaveConfirm;null!==t&&!1!==e.cancelable&&this._hasCommitted&&!this._unloadConfirmed&&(window.confirm(t)?(this._unloadConfirmed=!0,setTimeout(()=>{this._unloadConfirmed=!1},0)):e.preventDefault?.())}_ownedByAnotherRouter(e){for(const t of document.querySelectorAll(jo.router))if(t!==this&&t instanceof ma&&t._isOwnPath(e))return!0;return!1}_getOutlet(){const e=this.nextElementSibling;if(e&&e.matches(jo.outlet))return e;!function(e){const t=e.getRootNode();t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE||_l(t)}(this);const t=document.createElement(jo.outlet);return this.parentNode?this.parentNode.insertBefore(t,this.nextSibling):document.body.appendChild(t),t}_getTemplate(){return this.querySelector("template")}get outlet(){return this._outlet||Uo(`${jo.router} has no outlet.`),this._outlet}get template(){return this._template||Uo(`${jo.router} has no template.`),this._template}get routeChildNodes(){return this._routeChildNodes}get path(){return this._path}set path(e){const t=this._path!==e;this._path=e,t&&this.dispatchEvent(new CustomEvent("wcs-router:path-changed",{detail:e,bubbles:!0}))}get params(){return this._params}get typedParams(){return this._typedParams}get searchParams(){return this._searchParams}get routeName(){return this._routeName}get data(){return this._data}isSameMatch(e){return!!this._hasCommitted&&this._path===e}commitNavigation(e,t=!1){const n=Object.freeze({...e.params}),r=Object.freeze({...e.typedParams}),i=zo(e.search),s=e.data??null,o=this._data!==s,l=!qo(this._params,n),a=this._routeName!==e.routeName,u=!qo(this._searchParams,i),c=this._path!==e.path;o&&(this._data=s),l&&(this._params=n,this._typedParams=r),a&&(this._routeName=e.routeName),u&&(this._searchParams=i),this._path=e.path,this._hasCommitted=!0,this._leaveConfirmed=!1,o&&this.dispatchEvent(new CustomEvent("wcs-router:data-changed",{detail:this._data,bubbles:!0})),l&&this.dispatchEvent(new CustomEvent("wcs-router:params-changed",{detail:{params:this._params,typedParams:this._typedParams},bubbles:!0})),a&&this.dispatchEvent(new CustomEvent("wcs-router:route-name-changed",{detail:this._routeName,bubbles:!0})),u&&this.dispatchEvent(new CustomEvent("wcs-router:search-changed",{detail:this._searchParams,bubbles:!0})),this._pathHeld=c&&t,c&&!t&&this._firePathChanged()}releasePath(){this._pathHeld&&(this._pathHeld=!1,this._firePathChanged())}_firePathChanged(){this.dispatchEvent(new CustomEvent("wcs-router:path-changed",{detail:this._path,bubbles:!0}))}get fallbackRoute(){return this._fallbackRoute}set fallbackRoute(e){this._fallbackRoute=e}get navigateUrl(){return this._navigateUrl}set navigateUrl(e){null!=e&&""!==e&&this._navigateUrl!==e&&(this._navigateUrl=e,this.navigate(e).catch(e=>{Ql(e)||console.error(`${jo.router} navigate failed:`,e)}).finally(()=>{this._navigateUrl=null,this.dispatchEvent(new CustomEvent("wcs-router:navigate-url-changed",{detail:null,bubbles:!0}))}))}get replaceUrl(){return this._replaceUrl}set replaceUrl(e){null!=e&&""!==e&&this._replaceUrl!==e&&(this._replaceUrl=e,this.replace(e).catch(e=>{Ql(e)||console.error(`${jo.router} replace failed:`,e)}).finally(()=>{this._replaceUrl=null,this.dispatchEvent(new CustomEvent("wcs-router:replace-url-changed",{detail:null,bubbles:!0}))}))}async navigate(e){await this._performNavigation(e,!1)}async replace(e){await this._performNavigation(e,!0)}async _performNavigation(e,t){const n=na(e),r=""!==n.pathname||""===n.search&&""===n.hash?this._joinInternalPath(this._basename,n.pathname):window.location.pathname,i=r+ra(n.search)+n.hash;if(null!==this.leaveConfirm&&(await Promise.resolve(),!this._confirmLeave(r)))return;const s=ta();if(s?.navigate){let e;this._leaveChecked=!0;try{e=t?s.navigate(i,{history:"replace"}):s.navigate(i)}finally{this._leaveChecked=!1}await(e?.finished)}else{t?history.replaceState(null,"",i):history.pushState(null,"",i);const e=this._normalizePathname(r),s=this.isSameMatch(Hl(e,this._basename));await ea(this,this.outlet,e,this._path,ra(n.search))&&!s&&window.scrollTo(0,0),this._notifyLocationChange()}}_isOwnPath(e){return""===this._basename||e===this._basename||e.startsWith(this._basename+"/")}_ownsCurrentPage(){return this._isOwnPath(this._normalizePathname(window.location.pathname))}_onFragmentLinkNavigate(e,t){if(!this._ownsCurrentPage())return;const n=e.destination.url;ha(n)?da(new URL(n).hash.slice(1)):(e.preventDefault?.(),fa(t))}_onNavigateFunc(e){if(e.defaultPrevented||null!==e.downloadRequest||"reload"===e.navigationType)return;const t=e.sourceElement,n=t?.ownerDocument===document?ca(t):null;if(null!==n)return void this._onFragmentLinkNavigate(e,n);if(e.hashChange||e.destination.url.includes("#")&&ha(e.destination.url))return;const r=new URL(e.destination.url),i=this._normalizePathname(r.pathname);if(!e.canIntercept||!this._isOwnPath(i))return void(e.canIntercept&&this._ownedByAnotherRouter(i)||this._confirmUnload(e));if(!this._leaveChecked&&!1!==e.cancelable&&!this._confirmLeave(i))return void e.preventDefault?.();const s=this.isSameMatch(Hl(i,this._basename)),o=s&&("push"===e.navigationType||"replace"===e.navigationType),l=r.search,a=this;e.intercept({handler:async()=>{try{await ea(a,a.outlet,i,a.path,l)}catch(e){throw console.error(`${jo.router} applyRoute failed:`,e),e}},scroll:o?"manual":"after-transition",focusReset:s||null!==a.focusPolicy?"manual":"after-transition"})}_onNavigate=this._onNavigateFunc.bind(this);_onPopState=async()=>{const e=this._normalizePathname(window.location.pathname);this._isOwnPath(e)&&(await ea(this,this.outlet,e,this._path,window.location.search||""),this._notifyLocationChange())};_onClick=e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;const t=e.composedPath().find(e=>e instanceof Element&&("a"===e.localName||"area"===e.localName)&&e.hasAttribute("href")),n=ca(t);null!==n&&!t.hasAttribute("download")&&function(e){const t=e.getAttribute("target")??document.querySelector("base[target]")?.getAttribute("target")??"";return""===t||"_self"===t.toLowerCase()}(t)&&this._ownsCurrentPage()&&(e.preventDefault(),fa(n))};async _initialize(){this._initializing=!0;try{const e=ua();this._basename=this._normalizeBasename(this.getAttribute("basename")||this._getBasename()||"");const t=null!==document.querySelector("base[href]"),n=new URL(window.location.href);""!==this._basename||t||"/"===n.pathname||Uo(`${jo.router} basename is empty, but current path is not "/".`),e||""===this._basename||t||this.getAttribute("basename")||console.warn(`[@wcstack/router] [wcs/base-href-missing] The basename "${this._basename}" was taken from this page's URL: the page has no <base href> and <${jo.router}> no basename, so routes and links resolve under it, and a deep link or a reload away from the app's root shows the wrong route. Add <base href="/"> (or the app's folder) to <head>.`),this._outlet=this._getOutlet(),this._outlet.routesNode=this,this._template=this._getTemplate(),this._template||Uo(`${jo.router} should have a <template> child element.`);const r=e?this._template.content.cloneNode(!0):null,i=await xl(this),s=!e&&this._outlet.hasAttribute(Go);if(s||this._outlet.rootNode.appendChild(i),null!==r){const e=this._template.content;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(r)}0===this.routeChildNodes.length&&Uo(`${jo.router} has no route definitions.`),e||this._ensureA11yRegion();const o=this._normalizePathname(window.location.pathname);if(e)return await this._renderForSsr(o),void(this._initialized=!0);if(s){if(await this._hydrateFromSsr(o))return this._notifyLocationChange(),void(this._initialized=!0);this._outlet.removeAttribute(Go);const e=this._outlet.rootNode;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(i)}await ea(this,this.outlet,o,this._path,window.location.search||""),(s||null!==dl())&&this._offerInitialContentToBinder(),this._notifyLocationChange(),this._initialized=!0}finally{this._initializing=!1}}async _hydrateFromSsr(e){const t=this.outlet.rootNode,n=new Map;let r=!1;if(this._forEachRoute(e=>{n.has(e.absolutePath)?r=!0:n.set(e.absolutePath,e)}),r)return!1;if(null!==t.querySelector(jo.layoutOutlet))return!1;const i=new Map,s=new Map,o=new Map,l=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);let a=0;for(;l.nextNode();){const e=l.currentNode,t=e.data;if(a++,t.startsWith(Jo)){const r=t.slice(15);if(i.has(r)||!n.has(r))return!1;i.set(r,e)}else if(t.startsWith(Qo)){const r=t.slice(18);if(s.has(r)||!n.has(r))return!1;s.set(r,{comment:e,index:a})}else if(t.startsWith(Yo)){const r=t.slice(16);if(o.has(r)||!n.has(r))return!1;o.set(r,{comment:e,index:a})}}if(s.size!==o.size)return!1;const u=[];for(const[e,t]of s){const n=o.get(e);if(!n)return!1;if(n.comment.parentNode!==t.comment.parentNode)return!1;if(n.index<=t.index)return!1;u.push({start:t.index,end:n.index})}for(const e of u)for(const t of u)if(e.start<t.start&&t.start<e.end&&e.end<t.end)return!1;const c=Hl(e,this._basename);let h=Ll(this,c);if(!h){if(null===this._fallbackRoute)return!1;h={routes:[this._fallbackRoute],params:{},typedParams:{},path:c,lastPath:this._path}}if(h.lastPath=this._path,h.routes.length!==s.size)return!1;for(const e of h.routes)if(!s.has(e.absolutePath))return!1;const d=new Set;for(const e of this.routeChildNodes)d.add(e.absolutePath);for(const e of h.routes)for(const t of e.routeChildNodes)d.add(t.absolutePath);if(i.size!==d.size)return!1;for(const e of d)if(!i.has(e))return!1;for(const[e,t]of i){const r=n.get(e);t.parentNode.replaceChild(r.placeHolder,t)}for(const e of h.routes){const t=s.get(e.absolutePath).comment,n=o.get(e.absolutePath).comment,r=[],i=new Set;let l=t.nextSibling;for(;null!==l&&l!==n;){if(l.nodeType===Node.COMMENT_NODE){const e=l.data;if(e.startsWith(Qo)){const t=e.slice(18);l=o.get(t).comment.nextSibling;continue}}if(i.has(l))l=l.nextSibling;else{if(l.nodeType===Node.ELEMENT_NODE&&l.tagName.toLowerCase()===jo.link){const e=l.anchorElement;null!==e&&i.add(e)}r.push(l),l=l.nextSibling}}e.adoptChildNodes(r,n)}for(const{comment:e}of s.values())e.remove();this.outlet.removeAttribute(Go);for(const e of h.routes)Fl(e,h);return this.outlet.lastRoutes=h.routes,!await Zl(this,h)||(this.commitNavigation({params:h.params,typedParams:h.typedParams,routeName:h.routes[h.routes.length-1].name,data:h.data??null,search:window.location.search||"",path:c}),!0)}async _renderForSsr(e){const t=Hl(e,this._basename),n=Ll(this,t),r=n?.routes??(null!==this._fallbackRoute?[this._fallbackRoute]:[]);if(0===r.length&&Uo(`${jo.router} No route matched for path: ${t}`),!r.some(e=>e.hasGuard)){await ea(this,this.outlet,e,this._path,window.location.search||""),this._offerInitialContentToBinder(),this._forEachRoute(e=>{e.placeHolder.data=`${Jo}${e.absolutePath}`}),this.outlet.setAttribute(Go,"");for(const e of this.outlet.lastRoutes)e.placeHolder.after(document.createComment(`${Qo}${e.absolutePath}`))}}_offerInitialContentToBinder(){for(const e of this.outlet.lastRoutes)for(const t of e.childNodeArray)t.nodeType===Node.ELEMENT_NODE&&t.isConnected&&gl(t,yl)}_forEachRoute(e,t=this){for(const n of t.routeChildNodes)e(n),this._forEachRoute(e,n)}async connectedCallback(){if(function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&oa(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!ia(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this._syncBeforeUnload(),ua()){try{await Promise.resolve(),this.hasAttribute("enable-ssr")&&!this._initialized&&await this._initialize()}catch(e){throw this._rejectConnectedCallback?.(e),e}return void this._resolveConnectedCallback?.()}if(!this._initialized){this._disconnectedDuringInit=!1;try{null===this._getTemplate()&&await Promise.resolve(),await this._initialize()}catch(e){throw this._rejectConnectedCallback?.(e),e}if(this._disconnectedDuringInit)return void this._resolveConnectedCallback?.()}this._initialized&&this._ensureA11yRegion();const e=ta();e&&!this._listeningNavigate&&(e.addEventListener("navigate",this._onNavigate),this._listeningNavigate=!0),e||this._listeningPopState||(window.addEventListener("popstate",this._onPopState),this._listeningPopState=!0),e&&function(){const e=globalThis.NavigateEvent;return"function"==typeof e&&"sourceElement"in e.prototype}()||this._listeningClick||(window.addEventListener("click",this._onClick),this._listeningClick=!0),this._resolveConnectedCallback?.()}disconnectedCallback(){this._initializing&&(this._disconnectedDuringInit=!0),this._listeningNavigate&&(ta()?.removeEventListener("navigate",this._onNavigate),this._listeningNavigate=!1),this._listeningPopState&&(window.removeEventListener("popstate",this._onPopState),this._listeningPopState=!1),this._listeningClick&&(window.removeEventListener("click",this._onClick),this._listeningClick=!1),this._syncBeforeUnload(),null!==this._a11yRegion&&(this._a11yRegion.remove(),this._a11yRegion=null)}}const ga=["title","rel","target","download","hreflang","lang","dir"];class ya extends HTMLElement{static get observedAttributes(){return["to","match",...ga]}_childNodeArray=[];_uuid=Wo();_path="";_router=null;_anchorElement=null;_initialized=!1;_onClick;constructor(){super()}get uuid(){return this._uuid}get router(){if(this._router)return this._router;const e=this.closest(jo.router);if(e)return this._router=e;const t=this.getRootNode(),n=t.querySelector?.(jo.router);if(n)return this._router=n;Uo(`${jo.link} is not connected to a router.`)}_initialize(){ua()||(this.style.display="none"),this._childNodeArray=Array.from(this.childNodes),this._path=this.getAttribute("to")||"",this._initialized=!0}_normalizePathname(e){return Rl(e)}_joinInternalPath(e,t){const n=Wl(e),r=t.startsWith("/")?t:"/"+t,i=this._normalizePathname(r);return n?"/"===i?n+"/":n+i:i}_isInternalTarget(e){return e.startsWith("/")||e.startsWith("?")}_setAnchorHref(e,t){if(""!==t)if(this._isInternalTarget(t)){const{pathname:n,search:r,hash:i}=na(t),s=""===n?window.location.pathname:this._joinInternalPath(this.router.basename,n);e.href=s+ra(r)+i}else try{e.href=new URL(t).toString()}catch{Uo(`[${jo.link}] Invalid URL in 'to' attribute: ${t}`)}else e.removeAttribute("href")}connectedCallback(){ua()?queueMicrotask(()=>{if(this.isConnected)try{this._connect()}catch(e){console.error(e)}}):this._connect()}_findSsrAnchor(){const e=this.nextElementSibling;return null!==e&&"A"===e.tagName&&e.hasAttribute(Vo)?e:null}_connect(){this._initialized||this._initialize();const e=this.parentNode;if(!e)return;const t=this._findSsrAnchor();let n;if(null!==t)n=t,n.removeAttribute(Vo),this._childNodeArray=Array.from(n.childNodes),this._setAnchorHref(n,this._path);else{const t=this.nextSibling;n=document.createElement("a"),this._setAnchorHref(n,this._path);for(const e of Array.from(this.attributes))(e.name.startsWith("aria-")||ga.includes(e.name))&&n.setAttribute(e.name,e.value);for(const e of this._childNodeArray)n.appendChild(e);t?e.insertBefore(n,t):e.appendChild(n)}if(this._anchorElement=n,ua())return this._updateActiveState(),void n.setAttribute(Vo,"");ta()?.addEventListener("currententrychange",this._updateActiveState),window.addEventListener("wcs:navigate",this._updateActiveState),window.addEventListener("popstate",this._updateActiveState),""!==this._path&&!this._isInternalTarget(this._path)||ta()?.navigate||(this._onClick=async e=>{e.defaultPrevented||0===e.button&&(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||this._isInternalTarget(this._path)&&(e.preventDefault(),await this.router.navigate(this._path),this._updateActiveState()))},n.addEventListener("click",this._onClick)),this._updateActiveState()}disconnectedCallback(){ta()?.removeEventListener("currententrychange",this._updateActiveState),window.removeEventListener("wcs:navigate",this._updateActiveState),window.removeEventListener("popstate",this._updateActiveState);const e=this._anchorElement;e&&(this._onClick&&(e.removeEventListener("click",this._onClick),this._onClick=void 0),e.remove(),this._anchorElement=null);for(const t of this._childNodeArray)e&&t.parentNode===e&&e.removeChild(t);this._router=null}attributeChangedCallback(e,t,n){if("match"!==e||t===n){if("to"===e&&t!==n)this._path=n||"",this._anchorElement&&(this._setAnchorHref(this._anchorElement,this._path),this._updateActiveState());else if(ga.includes(e)){const t=this._anchorElement;t&&(null===n?t.removeAttribute(e):t.setAttribute(e,n))}}else this._anchorElement&&this._updateActiveState()}_updateActiveState=()=>{this._path.startsWith("?")&&this._anchorElement&&this._setAnchorHref(this._anchorElement,this._path);const e=new URL(window.location.href),t=this._normalizePathname(e.pathname),{pathname:n,search:r}=na(this._path),i=function(e,t){const n=new URLSearchParams(t),r=new URLSearchParams(e);for(const e of new Set(n.keys())){const t=n.getAll(e).sort(),i=r.getAll(e).sort();if(t.length!==i.length||t.some((e,t)=>e!==i[t]))return!1}return!0}(e.search,ra(r)),s=this._normalizePathname(this._isInternalTarget(this._path)?""===n?window.location.pathname:this._joinInternalPath(this.router.basename,n):n),o=""!==this._path&&i&&t===s,l=!o&&""!==this._path&&i&&"prefix"===this.getAttribute("match")&&t.startsWith(s+"/");this._anchorElement&&(o||l?(this._anchorElement.classList.add("active"),this._anchorElement.setAttribute("aria-current",o?"page":"true")):(this._anchorElement.classList.remove("active"),this._anchorElement.removeAttribute("aria-current")))};get anchorElement(){return this._anchorElement}}const ba=[],wa=new Map;let va=!1;const _a=new WeakMap,$a=new WeakMap;class ka extends HTMLElement{_initialized=!1;_childElementArray=[];constructor(){super()}_initialize(){if(!this._initialized&&(this._initialized=!0,this._childElementArray=Array.from(this.children),!ua())){this.style.display="none";for(const e of this._childElementArray)this.removeChild(e)}}connectedCallback(){this._initialize(),va||(this._captureInitialHead(),va=!0),ba.push(this),this._reapplyHead()}disconnectedCallback(){const e=ba.indexOf(this);-1!==e&&ba.splice(e,1),this._reapplyHead()}get childElementArray(){return this._initialized||Uo("Head component is not initialized yet."),this._childElementArray}_cloneOf(e){if(!Vl(e))return e.cloneNode(!0);let t=$a.get(e);return void 0===t&&(t=e.cloneNode(!0),$a.set(e,t)),t}_getKey(e){const t=_a.get(e);if(void 0!==t)return t;const n=this._computeKey(e);return _a.set(e,n),n}_computeKey(e){const t=e.tagName.toLowerCase();if("title"===t)return"title";if("meta"===t)return`meta:${e.getAttribute("name")||""}:${e.getAttribute("property")||""}:${e.getAttribute("http-equiv")||""}:${e.hasAttribute("charset")?"charset":""}:${e.getAttribute("media")||""}`;if("link"===t)return`link:${e.getAttribute("rel")||""}:${e.getAttribute("href")||""}:${e.getAttribute("media")||""}:${e.getAttribute("hreflang")||""}`;if("base"===t)return"base";if("script"===t){const t=e.getAttribute("src")||"",n=e.getAttribute("id")||"",r=e.getAttribute("type")||"";return t||n?`script:${t}:${n}:${r}`:`script::${r}:${e.outerHTML.slice(0,100)}`}if("style"===t){const t=e.getAttribute("id")||"",n=e.getAttribute("media")||"";return t?`style:${t}:${n}`:`style::${n}:${e.outerHTML.slice(0,100)}`}return`${t}:${e.outerHTML.slice(0,100)}`}_buildHeadElementMap(){const e=new Map;for(const t of Array.from(document.head.children)){const n=this._getKey(t);e.has(n)||e.set(n,t)}return e}_captureInitialHead(){const e=document.head;for(const t of Array.from(e.children)){const e=this._getKey(t);wa.has(e)||wa.set(e,t.cloneNode(!0))}}_reapplyHead(){const e=new Set;for(const t of ba)for(const n of t._childElementArray)e.add(this._getKey(n));for(const t of wa.keys())e.add(t);const t=this._buildHeadElementMap();for(const n of t.keys())e.add(n);for(const n of e){let e=null;for(let t=ba.length-1;t>=0;t--){const r=ba[t];for(const t of r._childElementArray)if(this._getKey(t)===n){e=this._cloneOf(t);break}if(e)break}!e&&wa.has(n)&&(e=wa.get(n).cloneNode(!0));const r=t.get(n)??null;null!==e&&r===e||e&&r?.isEqualNode(e)&&!Vl(e)||(e?(r?r.replaceWith(e):document.head.appendChild(e),t.set(n,e),gl(e)||Jl(e,`<${e.tagName.toLowerCase()}> inside <${jo.head}>`,`<${jo.head}> reflects its children into <head> with cloneNode, so the clone is not the node that was bound. Load @wcstack/state on this page, or write the value statically here.`)):(r?.remove(),t.delete(n)))}}}await void function(e=customElements){e.get(jo.layout)||e.define(jo.layout,ol),e.get(jo.layoutOutlet)||e.define(jo.layoutOutlet,Sl),e.get(jo.outlet)||e.define(jo.outlet,ll),e.get(jo.route)||e.define(jo.route,Xo),e.get(jo.router)||e.define(jo.router,ma),e.get(jo.link)||e.define(jo.link,ya),e.get(jo.head)||e.define(jo.head,ka)}(void 0);const Sa="data-fetchtarget",Na={fetch:"wcs-fetch",fetchHeader:"wcs-fetch-header",fetchBody:"wcs-fetch-body",infiniteScroll:"wcs-infinite-scroll"};let Aa=class{laneKey;policy;_ownerGeneration=0;_latestEpoch=0;_nextOperationId=1;_activeOperationId=void 0;_activeOperationIds=new Set;_queue=[];_inFlightCount=0;_terminal=new Map;_claimedOutcome=new Map;_controllers=new Map;_attempts=new Map;_withSignal;_trace;constructor(e,t,n={}){this.laneKey=e,this.policy=t,this._withSignal=n.withSignal??!1,this._trace=n.trace}get ownerGeneration(){return this._ownerGeneration}get inFlightCount(){return this._inFlightCount}get latestEpoch(){return this._latestEpoch}get activeOperationId(){return this._activeOperationId}begin(){let e;switch(this.policy){case"latest":e=++this._latestEpoch,void 0!==this._activeOperationId&&this._abortController(this._activeOperationId);break;case"exhaust":if(void 0!==this._activeOperationId)return null}const t=this._nextOperationId++,n={operationId:t,ownerGeneration:this._ownerGeneration,laneKey:this.laneKey,policy:this.policy,supersedeEpoch:e};switch(this.policy){case"latest":case"exhaust":this._activeOperationId=t;break;case"queue":this._queue.push(n),void 0===this._activeOperationId&&(this._activeOperationId=t);break;case"overlap":this._activeOperationIds.add(t)}this._inFlightCount+=1,this._attempts.set(t,1);const r=this._makeAttempt(t,1);return void 0!==this._trace&&this._trace({type:"io:operation-started",operationId:t,laneKey:this.laneKey,policy:this.policy}),{ticket:n,attempt:r}}retry(e){if(e.ownerGeneration!==this._ownerGeneration)return null;if(this._terminal.has(e.operationId))return null;const t=this._attempts.get(e.operationId);if(void 0===t)return null;const n=t+1;this._attempts.set(e.operationId,n),this._releaseController(e.operationId);const r=this._makeAttempt(e.operationId,n);return void 0!==this._trace&&this._trace({type:"io:operation-retried",operationId:e.operationId,laneKey:this.laneKey,attempt:n}),r}canCommit(e){if(e.ownerGeneration!==this._ownerGeneration)return!1;const t=this._terminal.get(e.operationId);return(void 0===t||"committing"===t)&&this._isEligible(e)}claimTerminal(e,t){return e.ownerGeneration===this._ownerGeneration&&!this._terminal.has(e.operationId)&&!!this._isEligible(e)&&(this._terminal.set(e.operationId,"committing"),this._claimedOutcome.set(e.operationId,t),!0)}claimedOutcome(e){return this._claimedOutcome.get(e.operationId)}finalize(e){const t=e.operationId,n=this._terminal.get(t);if(void 0!==n&&"committing"!==n)return;let r;r="committing"===n?this._claimedOutcome.get(t)??"stale":"stale",this._terminal.set(t,r),this._claimedOutcome.delete(t),this._releaseController(t),this._attempts.delete(t),this._inFlightCount>0&&(this._inFlightCount-=1),this._advanceBookkeeping(t),void 0!==this._trace&&("stale"===r?this._trace({type:"io:stale-dropped",operationId:t,laneKey:this.laneKey}):this._trace({type:"io:operation-settled",operationId:t,laneKey:this.laneKey,outcome:r}))}signalOf(e){return this._controllers.get(e.operationId)?.signal}abort(e){this._abortController(e.operationId)}abortActive(){void 0!==this._activeOperationId&&this._abortController(this._activeOperationId);for(const e of this._activeOperationIds)this._abortController(e)}disposeOwner(){this._ownerGeneration+=1;for(const e of Array.from(this._controllers.keys()))this._abortController(e),this._releaseController(e);for(const e of Array.from(this._attempts.keys()))this._terminal.has(e)||this._terminal.set(e,"stale"),this._claimedOutcome.delete(e),this._attempts.delete(e),void 0!==this._trace&&this._trace({type:"io:stale-dropped",operationId:e,laneKey:this.laneKey});this._activeOperationId=void 0,this._activeOperationIds.clear(),this._queue.length=0,this._inFlightCount=0}_makeAttempt(e,t){let n;if(this._withSignal&&"function"==typeof AbortController){const t=new AbortController;this._controllers.set(e,t),n=t.signal}return{operationId:e,attempt:t,signal:n}}_isEligible(e){switch(this.policy){case"latest":return e.supersedeEpoch===this._latestEpoch;case"queue":case"exhaust":return this._activeOperationId===e.operationId;case"overlap":return this._activeOperationIds.has(e.operationId)}}_advanceBookkeeping(e){switch(this.policy){case"latest":case"exhaust":this._activeOperationId===e&&(this._activeOperationId=void 0);break;case"queue":{const t=this._queue.filter(t=>t.operationId!==e);this._queue.length=0,this._queue.push(...t),this._activeOperationId=this._queue.length>0?this._queue[0].operationId:void 0;break}case"overlap":this._activeOperationIds.delete(e)}}_abortController(e){const t=this._controllers.get(e);void 0===t||t.signal.aborted||t.abort()}_releaseController(e){this._controllers.delete(e)}};function Ca(e,t){return t.every(t=>"available"===e.availability.get(t))}const Ea=new Map([["web.fetch",{probe:()=>"function"==typeof globalThis.fetch,compatKey:"api.fetch"}],["web.abort-controller",{probe:()=>"function"==typeof globalThis.AbortController,compatKey:"api.AbortController"}]]),Ta=new Set(["GET","HEAD","OPTIONS"]);let xa=class e extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.value},{name:"loading",event:"wcs-fetch:loading-changed",semantics:"state"},{name:"error",event:"wcs-fetch:error",semantics:"state"},{name:"status",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.status},{name:"objectURL",event:"wcs-fetch:response",semantics:"state",getter:e=>e.detail.objectURL},{name:"errorInfo",event:"wcs-fetch:error-info-changed",semantics:"state"}],inputs:[{name:"url"},{name:"method"}],commands:[{name:"fetch",async:!0},{name:"abort"}]};_target;_value=null;_loading=!1;_error=null;_status=0;_objectURL=null;_promise=Promise.resolve(null);_lane=new Aa("fetch","latest",{withSignal:!0});_inFlight=null;_ready=Promise.resolve();_errorInfo=null;static REQUIRED_CAPABILITIES=["web.fetch"];static OPTIONAL_CAPABILITIES=["web.abort-controller"];constructor(e){super(),this._target=e??this}get ready(){return this._ready}observe(){return this._ready}dispose(){this._lane.disposeOwner(),null!==this._objectURL&&(this._revokeObjectURL(this._objectURL),this._objectURL=null)}get value(){return this._value}get loading(){return this._loading}get error(){return this._error}get status(){return this._status}get objectURL(){return this._objectURL}get promise(){return this._promise}get errorInfo(){return this._errorInfo}get supported(){return Ca(this.platformAssessment,e.REQUIRED_CAPABILITIES)}get platformAssessment(){return function(e,t){const n=new Map,r=t=>{const n=e.get(t);return void 0===n?"unknown":n.probe()?"available":"missing"};let i=!0;for(const e of t.required){const t=r(e);n.set(e,t),"available"!==t&&(i=!1)}let s=!0;for(const e of t.optional??[]){const t=r(e);n.set(e,t),"available"!==t&&(s=!1)}const o=i?s?"ready":"degraded":"idle",l=[...t.required,...t.optional??[]],a=l.some(t=>!0===e.get(t)?.requiresSecureContext),u=l.some(t=>!0===e.get(t)?.requiresUserActivation),c=a?!0===globalThis.isSecureContext?"satisfied":"required":"not-applicable",h=u?"required":"not-applicable";return{availability:n,permission:t.permission??"not-applicable",readiness:o,activity:t.activity??"inactive",preconditions:{secureContext:c,userActivation:h},epoch:t.epoch??0,lastError:t.lastError}}(Ea,{required:e.REQUIRED_CAPABILITIES,optional:e.OPTIONAL_CAPABILITIES,activity:this._loading?"active":"inactive",lastError:this._errorInfo??void 0})}_setErrorInfo(e,t,n,r,i){this._commitErrorInfo({code:e,phase:t,recoverable:n,message:r,...void 0===i?{}:{capabilityId:i}})}_commitErrorInfo(e){this._errorInfo!==e&&(this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:error-info-changed",{detail:e,bubbles:!0})))}_setLoading(e){this._loading=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:loading-changed",{detail:e,bubbles:!0}))}_setError(e){this._error!==e&&(this._error=e,this._target.dispatchEvent(new CustomEvent("wcs-fetch:error",{detail:e,bubbles:!0})))}_setResponse(e,t,n=null){null!==this._objectURL&&this._revokeObjectURL(this._objectURL),this._objectURL=n,this._value=e,this._status=t,this._target.dispatchEvent(new CustomEvent("wcs-fetch:response",{detail:{value:e,status:t,objectURL:n},bubbles:!0}))}_createObjectURL(e){return"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL?URL.createObjectURL(e):null}_revokeObjectURL(e){"undefined"!=typeof URL&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(e)}abort(){this._lane.abortActive()}_commitStep(e,t){this._lane.canCommit(e)&&t()}async fetch(t,n={}){if(!t)return this._setErrorInfo("invalid-argument","start",!1,"url attribute is required."),this._setError({message:"url attribute is required."}),null;const r=this.platformAssessment;if(!Ca(r,e.REQUIRED_CAPABILITIES)){const t=e.REQUIRED_CAPABILITIES.find(e=>"available"!==r.availability.get(e));return this._setErrorInfo("capability-missing","start",!1,`Required capability "${t}" is unavailable.`,t),this._setError({message:`Required capability "${t}" is unavailable.`}),null}const i=this._doFetch(t,n);return this._promise=i,i}async _doFetch(e,t){const n=this._inFlight;null===n||Ta.has(n.method)||console.warn(`[@wcstack/fetch] [wcs/fetch-request-superseded] A ${n.method} request to "${n.url}" was still in flight when another request started on the same element: it was aborted and its response dropped (the server may have applied it). Give each change its own <wcs-fetch>, or wait for loading to end before starting the next request.`);const r=this._lane.begin(),{ticket:i,attempt:s}=r,o=s.signal,l={method:String(t.method??"GET").toUpperCase(),url:e};this._inFlight=l,this._commitStep(i,()=>this._setLoading(!0)),this._commitStep(i,()=>{this._commitErrorInfo(null),this._setError(null)});const{method:a="GET",body:u=null,contentType:c=null,forceText:h=!1,responseType:d="auto",timeout:f=0}=t;let p=null;f>0&&(p=setTimeout(()=>{if(!this._lane.claimTerminal(i,"timeout"))return;const e=`Request timed out after ${f}ms.`;this._commitStep(i,()=>{this._setErrorInfo("timeout","execute",!0,e),this._setError({name:"TimeoutError",message:e})}),this._commitStep(i,()=>this._setResponse(null,0)),this._commitStep(i,()=>this._setLoading(!1)),this._lane.abort(i),this._lane.finalize(i)},f));const m={...t.headers??{}};try{c&&!m["Content-Type"]&&(m["Content-Type"]=c);const t={method:a,headers:m,signal:o};"GET"!==a&&"HEAD"!==a&&null!==u&&(t.body=u);const n=await globalThis.fetch(e,t);let r=null;if("HEAD"===a);else if(n.ok)if(h)r=await n.text();else if("blob"===d)r=await n.blob();else if("arrayBuffer"===d)r=await n.arrayBuffer();else if("text"===d)r=await n.text();else if("json"===d)r=await n.json();else{const e=n.headers.get("Content-Type")||"";r=e.includes("application/json")?await n.json():await n.text()}if(!n.ok){const e=await n.text().catch(()=>""),t={status:n.status,statusText:n.statusText,body:e};return this._lane.claimTerminal(i,"error")?(this._commitStep(i,()=>{this._setErrorInfo("http-error","execute",!0,`HTTP ${n.status} ${n.statusText}`),this._setError(t)}),this._commitStep(i,()=>this._setResponse(null,n.status)),this._commitStep(i,()=>this._setLoading(!1)),null):null}if(!this._lane.claimTerminal(i,"success"))return null;const s=r instanceof Blob?this._createObjectURL(r):null;return this._commitStep(i,()=>this._setResponse(r,n.status,s)),this._commitStep(i,()=>this._setLoading(!1)),this._value}catch(e){return e&&"AbortError"===e.name?(this._lane.claimTerminal(i,"aborted")&&this._commitStep(i,()=>this._setLoading(!1)),null):this._lane.claimTerminal(i,"error")?(this._commitStep(i,()=>{const t=String(e?.message??"Network request failed.");this._setErrorInfo("network","execute",!0,t),this._setError(e??{message:t})}),this._commitStep(i,()=>this._setResponse(null,0)),this._commitStep(i,()=>this._setLoading(!1)),null):null}finally{this._inFlight===l&&(this._inFlight=null),null!==p&&clearTimeout(p),this._lane.finalize(i)}}},Pa=!1;function Oa(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${Sa}]`);if(!n)return;const r=n.getAttribute(Sa);if(!r)return;const i=customElements.get(Na.fetch),s=document.getElementById(r);if(!(i&&s instanceof i))return;const o=s;o.url&&(e.preventDefault(),o.fetch())}function La(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const Ma=new WeakSet;function Ia(e,t,n){if(Ma.has(e))return;Ma.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const ja=new WeakMap;function Ra(e,t){let n=ja.get(e);return void 0===n&&(n=new Map,ja.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function Ha(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Wa(e,t,n){const r=Ra(e,t);Ha(e,t,void 0===n?r:null===n?null:String(n))}const Ua=Symbol.for("wcstack.trustedTypes.policy");function Da(){const e=globalThis[Ua];return null===e||"object"!=typeof e?null:e}let Fa,za=!1;class qa extends HTMLElement{static hasConnectedCallbackPromise=!0;static hasPendingPromise=!0;static wcBindable={...xa.wcBindable,properties:[...xa.wcBindable.properties,{name:"trigger",event:"wcs-fetch:trigger-changed",semantics:"state"}],inputs:[{name:"url"},{name:"method"},{name:"target"},{name:"manual"},{name:"body"},{name:"responseType"},{name:"trigger"}]};static get observedAttributes(){return["url"]}_core;_body=null;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_autoPending=!1;_connectResolve=null;_lastFetchedUrl=null;_toldTriggerWithoutUrl=!1;_toldUndefinedHelper=!1;_internals=null;constructor(){super(),this._internals=this._initInternals(),this._wireStates({"wcs-fetch:loading-changed":e=>({loading:!0===e}),"wcs-fetch:error":e=>({error:null!=e})}),this._core=new xa(this)}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[n,r]of Object.entries(e))this.addEventListener(n,e=>{const n=this.hasAttribute("debug-states");for(const[i,s]of Object.entries(r(e.detail))){try{s?t.add(i):t.delete(i)}catch{}n&&this.toggleAttribute(`data-wcs-state-${i}`,s)}})}get url(){return this.getAttribute("url")||""}set url(e){Wa(this,"url",e)}get method(){return(this.getAttribute("method")||"GET").toUpperCase()}set method(e){Wa(this,"method",e)}get target(){return this.getAttribute("target")}set target(e){Wa(this,"target",e)}get responseType(){return this.getAttribute("response-type")||"auto"}set responseType(e){Wa(this,"response-type",e)}get value(){return this._core.value}get loading(){return this._core.loading}get error(){return this._core.error}get status(){return this._core.status}get objectURL(){return this._core.objectURL}get errorInfo(){return this._core.errorInfo}get promise(){return this._core.promise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get pendingPromise(){return this._autoPending&&!this.manual&&this.url?Promise.resolve().then(()=>this.pendingPromise??void 0):this.loading?this._core.promise.then(()=>{}):null}get manual(){return this.hasAttribute("manual")}set manual(e){!function(e,t,n){const r=Ra(e,t);Ha(e,t,void 0===n?r:n?"":null)}(this,"manual",e)}get body(){return this._body}set body(e){this._body=e??null}get trigger(){return this._trigger}set trigger(e){if(e){if(!this.url)return void this._warnTriggerWithoutUrl();this._trigger=!0,this.fetch().finally(()=>{this._trigger=!1,this.dispatchEvent(new CustomEvent("wcs-fetch:trigger-changed",{detail:!1,bubbles:!0}))})}}_collectHeaders(){const e={},t=this.querySelectorAll(Na.fetchHeader);for(const n of t)"boolean"==typeof n.hasHeader?n.hasHeader&&(e[n.headerName]=n.headerValue):this._warnUndefinedHelper(Na.fetchHeader,"header");return e}_isNativeBodyInit(e){return e instanceof Blob||e instanceof FormData||e instanceof URLSearchParams||e instanceof ArrayBuffer||ArrayBuffer.isView(e)}_collectBody(e){if(null!==e)return"string"==typeof e||this._isNativeBodyInit(e)?{body:e,contentType:null}:{body:JSON.stringify(e),contentType:"application/json"};const t=this.querySelector(Na.fetchBody);if(t&&"string"!=typeof t.bodyContent)this._warnUndefinedHelper(Na.fetchBody,"body");else if(t)return{body:t.bodyContent||null,contentType:t.contentType};return{body:null,contentType:null}}abort(){this._core.abort()}_scheduleAutoFetch(){this._autoPending||(this._autoPending=!0,queueMicrotask(()=>{this._autoPending=!1;const e=this._connectResolve;this._connectResolve=null;const t=this.url;t||(this._lastFetchedUrl=null),this.isConnected&&!this.manual&&t&&t!==this._lastFetchedUrl?(null===e&&this._warnUnsafeAutoFetch(),this.fetch().finally(()=>e?.())):e?.()}))}_warnTriggerWithoutUrl(){this._toldTriggerWithoutUrl||(this._toldTriggerWithoutUrl=!0,console.warn("[@wcstack/fetch] [wcs/command-not-ready] trigger was refused: there is no url, so nothing is fetched. Write url before trigger (bindings apply in the order written), and write trigger again once there is one. (Said once until a request is sent again.)",this))}_warnUndefinedHelper(e,t){this._toldUndefinedHelper||(this._toldUndefinedHelper=!0,console.warn(`[@wcstack/fetch] [wcs/fetch-helper-undefined] <${e}> inside this <${Na.fetch}> is not defined, so its ${t} is not sent. Load @wcstack/fetch/auto, or define WcsFetchHeader and WcsFetchBody with WcsFetch when the page defines the tags itself. (Said once per element.)`,this))}_warnUnsafeAutoFetch(){const e=this.method;"GET"!==e&&"HEAD"!==e&&"OPTIONS"!==e&&null===this._body&&null===this.querySelector(Na.fetchBody)&&console.warn(`[@wcstack/fetch] [wcs/fetch-auto-unsafe] The url changed to "${this.url}", so this <wcs-fetch> sent a ${e} with no body (its method stays ${e}; a body is sent once). Give loading and each change its own <wcs-fetch>, or set \`manual\` on the one that changes data.`)}async fetch(){this._lastFetchedUrl=this.url,this.url&&(this._toldTriggerWithoutUrl=!1);const e=this._collectHeaders(),t=this._body;this._body=null;const{body:n,contentType:r}=this._collectBody(t);n instanceof FormData&&Object.keys(e).some(e=>"content-type"===e.toLowerCase())&&console.warn("[@wcstack/fetch] A manual Content-Type header was set alongside a FormData body. This drops the multipart boundary the browser adds automatically; remove the Content-Type header (e.g. the <wcs-fetch-header>) to fix multipart uploads.");const i=await this._core.fetch(this.url,{method:this.method,headers:e,body:n,contentType:r,forceText:!!this.target,responseType:this.responseType});if(this.target&&null!==i){const e=document.getElementById(this.target);e&&function(e,t){try{e.innerHTML=function(e){if("string"!=typeof e)return e;const t=Da(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(t)}catch(e){if(function(){if(void 0!==Fa)return Fa;if(!("trustedTypes"in globalThis))return Fa=!1,Fa;try{document.createElement("div").innerHTML="<i></i>",Fa=!1}catch{Fa=!0}return Fa}())return void function(){if(za)return;za=!0;const e="function"==typeof Da()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/fetch deliberately does not pass responses through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/fetch] The "target" HTML replace mode was blocked by Trusted Types (require-trusted-types-for 'script'). ${e}\nInstall a sanitizing policy before the first fetch:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr drop "target" and bind the response through @wcstack/state. See docs/csp.md section 7.`)}();throw e}}(e,i)}return i}attributeChangedCallback(e,t,n){"url"===e&&this._scheduleAutoFetch()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&Ia(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!La(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",Pa||(Pa=!0,document.addEventListener("click",Oa)),!this.manual&&this.url&&(this._connectedCallbackPromise=new Promise(e=>{this._connectResolve=e})),this._scheduleAutoFetch()}disconnectedCallback(){this.abort(),this._lastFetchedUrl=null,this._connectResolve?.(),this._connectResolve=null}}class Ba extends HTMLElement{connectedCallback(){for(const e of["name","value"])if(Object.prototype.hasOwnProperty.call(this,e)){const t=this[e];delete this[e],this[e]=t}this.style.display="none"}get name(){return this.getAttribute("name")??""}set name(e){Wa(this,"name",e)}get value(){return this.getAttribute("value")??""}set value(e){Wa(this,"value",e)}get headerName(){return this.name}get headerValue(){return this.value}get hasHeader(){return""!==this.name&&this.hasAttribute("value")}}let Ka=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}get contentType(){return this.getAttribute("type")||"application/json"}get bodyContent(){return this.textContent?.trim()||""}};class Ga extends HTMLElement{static get observedAttributes(){return["target","root","root-margin","threshold","disabled"]}_observer=null;_done=!1;_warnedTarget=null;get target(){return this.getAttribute("target")||""}set target(e){this.setAttribute("target",e)}get root(){return this.getAttribute("root")}set root(e){null===e?this.removeAttribute("root"):this.setAttribute("root",e)}get rootMargin(){return this.getAttribute("root-margin")||"0px"}set rootMargin(e){this.setAttribute("root-margin",e)}get threshold(){const e=Number(this.getAttribute("threshold")??"0");return Number.isFinite(e)?e:0}set threshold(e){this.setAttribute("threshold",String(e))}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get once(){return this.hasAttribute("once")}set once(e){e?this.setAttribute("once",""):this.removeAttribute("once")}connectedCallback(){this._observe()}disconnectedCallback(){this._disconnectObserver()}attributeChangedCallback(){this.isConnected&&this._observe()}_observe(){this._disconnectObserver(),this._done||this.disabled||!this.target||"undefined"==typeof IntersectionObserver||(this._observer=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&this._triggerFetch()},{root:this._resolveRoot(),rootMargin:this.rootMargin,threshold:this.threshold}),this._observer.observe(this))}_disconnectObserver(){this._observer&&(this._observer.disconnect(),this._observer=null)}_resolveRoot(){return this.root&&document.getElementById(this.root)||null}_triggerFetch(){const e=document.getElementById(this.target);e instanceof qa?e.loading||(e.trigger=!0,this.once&&(this._done=!0,this._disconnectObserver())):this._warnedTarget!==this.target&&(this._warnedTarget=this.target,console.warn(`[@wcstack/fetch] [wcs/infinite-scroll-target] <${Na.infiniteScroll} target="${this.target}"> came into view, but no <${Na.fetch}> has that id, so no page was loaded.`))}}!function(e=customElements){e.get(Na.fetch)||e.define(Na.fetch,qa),e.get(Na.fetchHeader)||e.define(Na.fetchHeader,Ba),e.get(Na.fetchBody)||e.define(Na.fetchBody,Ka),e.get(Na.infiniteScroll)||e.define(Na.infiniteScroll,Ga)}(void 0);const Va="data-storagetarget",Ja={storage:"wcs-storage"},Qa="wcs-storage:value-changed",Ya="wcs-storage:loading-changed",Xa="wcs-storage:error",Za="wcs-storage:error-info-changed",eu="wcs-storage:trigger-changed";let tu=class extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:Qa,semantics:"state",getter:e=>e.detail},{name:"loading",event:Ya,semantics:"state"},{name:"error",event:Xa,semantics:"state"},{name:"errorInfo",event:Za,semantics:"state"}],inputs:[{name:"key"},{name:"type"}],commands:[{name:"load"},{name:"save"},{name:"remove"}]};_target;_value=null;_loading=!1;_error=null;_errorInfo=null;_key="";_toldUnkept=!1;_toldNoKey=!1;_type="local";_storageListener=null;_gen=0;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get ready(){return this._ready}observe(){return this._ready}dispose(){this._gen++,this.stopSync()}get value(){return this._value}set value(e){Object.is(e,this._value)||this._setValue(e)}get loading(){return this._loading}get error(){return this._error}get errorInfo(){return this._errorInfo}get key(){return this._key}set key(e){this._key=String(e),this._key&&(this._toldNoKey=!1)}get type(){return this._type}set type(e){"local"===e||"session"===e?this._type=e:this._setError({operation:"type",message:`Invalid storage type: "${e}". Must be "local" or "session".`})}_getStorage(){return"session"===this._type?sessionStorage:localStorage}_setLoading(e){this._loading=e,this._target.dispatchEvent(new CustomEvent(Ya,{detail:e,bubbles:!0}))}_setError(e,t){this._error!==e&&(this._error=e,this._commitErrorInfo(null===e?null:function(e,t){return void 0===t?{code:"invalid-argument",phase:"start",recoverable:!1,message:e.message}:"QuotaExceededError"===t?{code:"quota-exceeded",phase:"execute",recoverable:!0,message:e.message}:"SecurityError"===t?{code:"not-allowed",phase:"execute",recoverable:!1,message:e.message}:{code:"storage-error",phase:"execute",recoverable:!0,message:e.message}}(e,t)),this._target.dispatchEvent(new CustomEvent(Xa,{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent(Za,{detail:e,bubbles:!0}))}_toStorageError(e,t){return{operation:e,message:t instanceof Error?t.message:String(t)}}_errName(e){return e instanceof Error?e.name:""}_setValue(e){this._value=e,this._target.dispatchEvent(new CustomEvent(Qa,{detail:e,bubbles:!0}))}load(){if(!this._key)return this._setError({operation:"load",message:"key is required."}),this._warnNoKey("load"),null;this._setLoading(!0),this._setError(null);try{const e=this._getStorage().getItem(this._key);if(null===e)this._setValue(null);else try{this._setValue(JSON.parse(e))}catch{this._setValue(e)}return this._setLoading(!1),this._value}catch(e){return this._setError(this._toStorageError("load",e),this._errName(e)),this._setLoading(!1),null}}save(e){if(!this._key)return this._setError({operation:"save",message:"key is required."}),void this._warnNoKey("save");this._setLoading(!0),this._setError(null);try{const t=this._getStorage();if(null==e)t.removeItem(this._key),this._setValue(null);else if("string"==typeof e)t.setItem(this._key,e),this._setValue(e);else{let n=null;const r=JSON.stringify(e,(e,t)=>{if(null===n){const r=function(e){return null===e||"object"!=typeof e?null:"undefined"!=typeof File&&e instanceof File?"a File":"undefined"!=typeof Blob&&e instanceof Blob?"a Blob":e instanceof Map?"a Map":e instanceof Set?"a Set":e instanceof ArrayBuffer||ArrayBuffer.isView(e)?"binary data":null}(t);null!==r&&(n=""===e?r:`${r} at "${e}"`)}return t});t.setItem(this._key,r),this._setValue(e),null!==n&&this._warnUnkept(n)}this._setLoading(!1)}catch(e){this._setError(this._toStorageError("save",e),this._errName(e)),this._setLoading(!1)}}_warnNoKey(e){this._toldNoKey||(this._toldNoKey=!0,console.warn(`[@wcstack/storage] [wcs/command-not-ready] ${e}() was refused: there is no key, so nothing is loaded or stored. It goes to \`error\` too. Give the element a \`key\` — in React and Vue, which keep \`key\` for themselves, write \`storage-key\`. (Said once until the element has a key again.)`,this._target))}_warnUnkept(e){this._toldUnkept||(this._toldUnkept=!0,console.warn(`[@wcstack/storage] [wcs/storage-unserializable] The value saved under "${this._key}" holds ${e}, which JSON cannot keep: it is stored as {} and comes back empty after a reload. Keep it out of the stored value (Blobs and files belong in IndexedDB or on a server). (Said once per element.)`,this._target))}remove(){if(!this._key)return this._setError({operation:"remove",message:"key is required."}),void this._warnNoKey("remove");this._setLoading(!0),this._setError(null);try{this._getStorage().removeItem(this._key),this._setValue(null),this._setLoading(!1)}catch(e){this._setError(this._toStorageError("remove",e),this._errName(e)),this._setLoading(!1)}}startSync(){if(this._storageListener)return;const e=++this._gen;this._storageListener=t=>{if(e===this._gen&&t.key===this._key&&"session"!==this._type)if(this._setError(null),null===t.newValue)this._setValue(null);else try{this._setValue(JSON.parse(t.newValue))}catch{this._setValue(t.newValue)}},globalThis.addEventListener("storage",this._storageListener)}stopSync(){this._storageListener&&(globalThis.removeEventListener("storage",this._storageListener),this._storageListener=null)}},nu=!1;function ru(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${Va}]`);if(!n)return;const r=n.getAttribute(Va);if(!r)return;const i=customElements.get(Ja.storage),s=document.getElementById(r);i&&s instanceof i&&(e.preventDefault(),s.save())}function iu(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const su=new WeakSet;function ou(e,t,n){if(su.has(e))return;su.add(e);const r=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${r}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const lu=new WeakMap;function au(e,t){let n=lu.get(e);return void 0===n&&(n=new Map,lu.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function uu(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function cu(e,t,n){const r=au(e,t);uu(e,t,void 0===n?r:null===n?null:String(n))}let hu=class extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...tu.wcBindable,properties:[...tu.wcBindable.properties,{name:"trigger",event:eu,semantics:"state"}],inputs:[{name:"key"},{name:"storageKey"},{name:"type"},{name:"value"},{name:"manual"},{name:"trigger"}]};static get observedAttributes(){return["key","storage-key","type"]}_core;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_internals=null;_everConnected=!1;_loadPending=!1;constructor(){super(),this._core=new tu(this),this._internals=this._initInternals(),this._wireStates({[Ya]:e=>({loading:!0===e}),[Xa]:e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[n,r]of Object.entries(e))this.addEventListener(n,e=>{const n=this.hasAttribute("debug-states");for(const[i,s]of Object.entries(r(e.detail))){try{s?t.add(i):t.delete(i)}catch{}n&&this.toggleAttribute(`data-wcs-state-${i}`,s)}})}_syncCore(){this._core.key=this.key,this._core.type=this.type}get key(){return this.getAttribute("key")||this.getAttribute("storage-key")||""}set key(e){cu(this,"key",e)}get storageKey(){return this.key}set storageKey(e){cu(this,"storage-key",e)}get type(){return"session"===this.getAttribute("type")?"session":"local"}set type(e){cu(this,"type",e)}_warnedType=null;_checkType(){const e=this.getAttribute("type");null!==e&&""!==e&&"local"!==e&&"session"!==e&&e!==this._warnedType&&(this._warnedType=e,console.warn(`[@wcstack/storage] [wcs/storage-type-invalid] <${Ja.storage} type="${e}"> is neither "local" nor "session": it uses localStorage, so the data is kept after the session ends.`))}get value(){return this._core.value}set value(e){void 0!==e&&(this.manual?this._core.value=e:(this._syncCore(),this._core.save(e)))}get loading(){return this._core.loading}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}get manual(){return this.hasAttribute("manual")}set manual(e){!function(e,t,n){const r=au(e,t);uu(e,t,void 0===n?r:n?"":null)}(this,"manual",e)}get trigger(){return this._trigger}set trigger(e){if(e){this._trigger=!0;try{this.save()}finally{this._trigger=!1,this.dispatchEvent(new CustomEvent(eu,{detail:!1,bubbles:!0}))}}}load(){return this._syncCore(),this._core.load()}save(){this._syncCore(),this._core.save(this._core.value)}remove(){this._syncCore(),this._core.remove()}attributeChangedCallback(e,t,n){this.isConnected&&("storage-key"===e&&this.getAttribute("key")||("key"!==e&&"storage-key"!==e||(this._syncCore(),!this.key||this.manual||this._loadPending||this.load()),"type"===e&&(this._checkType(),this._syncCore())))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const r=e.getAttribute;for(const t of n){const n=t.name,i="function"==typeof r?r.call(e,n.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&ou(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!iu(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",this._checkType(),nu||(nu=!0,document.addEventListener("click",ru)),this._everConnected?this._scheduleLoad():(this._everConnected=!0,!this.manual&&this.key&&this.load()),this._syncCore(),this._core.startSync()}disconnectedCallback(){this._core.stopSync()}_scheduleLoad(){this._loadPending||(this._loadPending=!0,queueMicrotask(()=>{this._loadPending=!1,this.isConnected&&!this.manual&&this.key&&this.load()}))}};!function(e=customElements){e.get(Ja.storage)||e.define(Ja.storage,hu)}(void 0);const du="*",fu="vanilla",pu={loaders:{[fu]:{postfix:".js",loader:async function(e){return(await(import(`${e}`))).default}},[du]:fu},observable:!0,tagNames:{autoloader:"wcs-autoloader"}};function mu(e){if(e.startsWith("@components/")){if(e.endsWith("/")){const t=e.slice(12,e.length-1),[n,r]=t.split("|",2);if(""===n)throw new Error("Invalid importmap key: "+e);return{key:e,prefix:n.replaceAll("/","-").toLowerCase(),loaderKey:r??null,isNameSpaced:!0}}{const t=e.slice(12),[n,r]=t.split("|",2),[i,s]=(r??"").split(",",2);if(""===n)throw new Error("Invalid importmap key: "+e);return{key:e,tagName:n.replaceAll("/","-").toLowerCase(),loaderKey:i||null,extends:s||null,isNameSpaced:!1}}}return null}function gu(e,t,n){let r;if(null===t||t===du||""===t){let t=null;const i=[];for(const[e,t]of Object.entries(n)){if(e===du)continue;const r="string"==typeof t?n[t]:t;"string"!=typeof r&&i.push(r)}i.sort((e,t)=>t.postfix.length-e.postfix.length);for(const n of i)if(e.endsWith(n.postfix)){t=n;break}t?r=t:(r=n[du],"string"==typeof r&&(r=n[r]))}else if(r=n[t],!r)throw new Error("Loader not found: "+t);if("string"==typeof r)throw new Error("Loader redirection is not supported here");return r}const yu=new Set,bu=new Map;let wu=new WeakMap;function vu(e){if(e===globalThis.customElements)return bu;let t=wu.get(e);return void 0===t&&(t=new Map,wu.set(e,t)),t}const _u=new Map;async function $u(e,t,n){try{if(customElements.get(t))return;const r=await n.loader(e.key);if(null!==r){let n=e.extends;if(null===n&&(n=function(e){for(const[t,n]of _u)if(e.prototype instanceof t)return n;return null}(r)),customElements.get(t))return;null===n?customElements.define(t,r):customElements.define(t,r,{extends:n})}}catch(e){yu.has(t)||(console.error(`Failed to eager load component '${t}':`,e),yu.add(t))}}function ku(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined||"function"!=typeof t.define?null:t}function Su(e){const t=e.tagName.toLowerCase();let n,r;if(t.includes("-"))n=t,r=null;else{const i=e.getAttribute("is");if(null===i)throw new Error("Custom element without a dash or 'is' attribute found: "+t);if(!i.includes("-"))throw new Error("Custom element 'is' attribute without a dash found: "+t);n=i,r=t}return{name:n,extends:r}}"undefined"!=typeof window&&[[HTMLButtonElement,"button"],[HTMLInputElement,"input"],[HTMLAnchorElement,"a"],[HTMLImageElement,"img"],[HTMLDivElement,"div"],[HTMLSpanElement,"span"],[HTMLParagraphElement,"p"],[HTMLUListElement,"ul"],[HTMLOListElement,"ol"],[HTMLLIElement,"li"],[HTMLTableElement,"table"],[HTMLFormElement,"form"],[HTMLLabelElement,"label"],[HTMLSelectElement,"select"],[HTMLTextAreaElement,"textarea"],[HTMLHeadingElement,"h1"],[HTMLQuoteElement,"blockquote"],[HTMLPreElement,"pre"],[HTMLBRElement,"br"],[HTMLHRElement,"hr"],[HTMLModElement,"ins"],[HTMLTableCaptionElement,"caption"],[HTMLTableColElement,"col"],[HTMLTableSectionElement,"tbody"],[HTMLTableRowElement,"tr"],[HTMLTableCellElement,"td"],[HTMLFieldSetElement,"fieldset"],[HTMLLegendElement,"legend"],[HTMLDListElement,"dl"],[HTMLOptGroupElement,"optgroup"],[HTMLOptionElement,"option"],[HTMLStyleElement,"style"],[HTMLScriptElement,"script"],[HTMLTemplateElement,"template"],[HTMLCanvasElement,"canvas"],[HTMLIFrameElement,"iframe"],[HTMLObjectElement,"object"],[HTMLEmbedElement,"embed"],[HTMLVideoElement,"video"],[HTMLAudioElement,"audio"],[HTMLTrackElement,"track"],[HTMLMapElement,"map"],[HTMLAreaElement,"area"],[HTMLSourceElement,"source"],[HTMLParamElement,"param"],[HTMLMeterElement,"meter"],[HTMLProgressElement,"progress"],[HTMLOutputElement,"output"],[HTMLDetailsElement,"details"],[HTMLDialogElement,"dialog"],[HTMLMenuElement,"menu"],[HTMLSlotElement,"slot"],[HTMLTimeElement,"time"],[HTMLDataElement,"data"],[HTMLPictureElement,"picture"]].forEach(([e,t])=>{void 0!==e&&_u.set(e,t)});const Nu=new WeakSet,Au=new WeakSet;async function Cu(e,t,n){e.shadowRoot&&(Nu.has(e)||await async function(e,t,n){Nu.add(e),await Ou(e.shadowRoot,t,n)}(e,t,n))}function Eu(e,t){for(const[n,r]of Object.entries(t))if(e.startsWith(n+"-"))return r;return null}async function Tu(e,t,n,r){const i=vu(r),s=i.get(e.name);if(void 0!==s)return void await s;const o=async function(e,t,n,r){try{let i;try{i=gu("",n.loaderKey,t.loaders)}catch(t){throw new Error("Loader redirection is not supported for lazy loaded components: "+e.name)}const s=e.name.slice(n.prefix.length+1);if(""===s)throw new Error("Invalid component name for lazy loaded component: "+e.name);const o=n.key+s+i.postfix;if(r.get(e.name))return;const l=await i.loader(o);if(null===l)throw new Error("Loader returned null for component: "+e.name);if(r.get(e.name))return;null===e.extends?r.define(e.name,l):r.define(e.name,l,{extends:e.extends})}catch(t){console.error(`Failed to lazy load component '${e.name}':`,t),yu.add(e.name)}}(e,t,n,r);i.set(e.name,o);try{await o}finally{i.delete(e.name)}}async function xu(e,t,n,r){const i=[],s=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_ELEMENT,e=>(e=>(e instanceof Element&&(e.tagName.includes("-")||e.getAttribute("is")?.includes("-")))??!1)(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP);for(;s.nextNode();)i.push(s.currentNode);const o=[],l=new Set;for(const e of i){const i=Su(e);if(void 0===r.get(i.name)){Au.has(e)||(Au.add(e),r.whenDefined(i.name).then(async()=>{await Cu(e,t,n)}));const s=Eu(i.name,n);null===s||l.has(i.name)||yu.has(i.name)||(l.add(i.name),o.push([i,s]))}else await Cu(e,t,n)}let a=0;for(const[e,n]of o)await Tu(e,t,n,r),a++;return a}async function Pu(e,t,n,r){for(;await xu(e,t,n,r)>0;);}async function Ou(e,t,n){if(0===Object.keys(n).length)return null;const r=function(e=null){if(null!=e){const t=e.customElementRegistry;if(null===t)return null;if(void 0!==t)return ku(t)}return ku(globalThis.customElements)}(e);if(null===r)return console.error("Cannot autoload components: the root has a null custom element registry."),null;try{await Pu(e,t,n,r)}catch(e){throw new Error("Failed to lazy load components: "+e)}if(!t.observable)return null;const i=new MutationObserver(async()=>{try{await Pu(e,t,n,r)}catch(e){console.error("Failed to lazy load components: "+e)}});return i.observe(e,{childList:!0,subtree:!0}),i}class Lu extends HTMLElement{static _instance=null;_initialized=!1;_prefixMap=null;_observer=null;constructor(){if(super(),Lu._instance)throw new Error(`${pu.tagNames.autoloader} can only be instantiated once.`);Lu._instance=this;const e=function(){const e={imports:{}};return document.querySelectorAll('script[type="importmap"]').forEach(t=>{try{const n=JSON.parse(t.innerHTML);n.imports&&(e.imports=Object.assign(e.imports,n.imports))}catch(e){throw new Error("Failed to parse importmap JSON: "+e)}}),Object.keys(e.imports).length>0?e:null}();if(e){const{prefixMap:t,loadMap:n}=function(e){const t={},n={};for(const[r,i]of Object.entries(e.imports)){const e=mu(r);null!==e&&(e.isNameSpaced?t[e.prefix]=e:n[e.tagName]=e)}return{prefixMap:t,loadMap:n}}(e);this._prefixMap=t,async function(e,t){const n=[];for(const[r,i]of Object.entries(e)){let s;try{s=gu(i.key,i.loaderKey,t)}catch(e){throw new Error("Loader redirection is not supported for eager loaded components: "+r)}n.push($u(i,r,s))}await Promise.all(n)}(n,pu.loaders).catch(e=>{console.error("Failed to eager load components:",e)})}}async connectedCallback(){this._initialized||(this._initialized=!0,this._prefixMap&&("loading"===document.readyState&&await new Promise(e=>document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})),this._observer=await Ou(document,pu,this._prefixMap)))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,Lu._instance===this&&(Lu._instance=null)}}!function(e=customElements){e.get(pu.tagNames.autoloader)||e.define(pu.tagNames.autoloader,Lu)}(void 0);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|