wcstack 4.4.0 → 4.6.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/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 v(e,t,n){throw new Error(`[@wcstack/state] ${e}${c.Bo?.(e,t,n)??""}`)}function w(e,t=[]){return c.Mo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function _(e,t,n,r){v(w(e,t),n,r)}var $=class{constructor(e){this.kt=new Set,this.name=e}get size(){return this.kt.size}subscribe(e){return this.kt.add(e),()=>{this.kt.delete(e)}}unsubscribe(e){return this.kt.delete(e)}emit(...e){let t=[];for(let n of this.kt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${w(17,[this.name])}`,e)}return t}};function k(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 S=Symbol.for("wcstack.transition-runner");function N(e){let t=globalThis[S];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function A(e,t,n){let r=N(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var E="else",C="eventToken",x="class",T="attr",P=/^\$[1-9]\d{0,2}$/,O=/^[+-]?(\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:O.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 L=e=>e.trim();function I(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 j=(e,t)=>I(e,t)[0]??-1;function R(e,t){let n=[],r=0;for(let i of I(e,t))n.push(e.slice(r,i)),r=i+1;return n.push(e.slice(r)),n}function H(e,t,n){let r=j(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=j(e,"("),i=(e=>I(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,...M(e.substring(n+1,i))}})}(R(i,"|").map(L),t,e),n.set(i,s)),[e.slice(0,r).trim(),s]}var W=new Map;function U(e){_(1101,[e])}function D(e){let[t,n]=H(e,"output",W);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("**")&&U(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"]],F=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function q(e){return e.includes("**")&&U(e),e}var B=0;function G(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var K=()=>new Set,V=()=>[],J=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Y(e,t,n){let r=e._?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e._.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function te(e,t,n){let r=ee(e,n);return null!==r&&r.l.o===t.h[n]?r:null}var ne=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.St=[],this.Me=null,this.qn=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.j=0,this.qt=0,this.yn=!1,this.Kt=!1,this.zt=!1,this.Ce=0,this.Kn=()=>{this.j=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.He=[],this.Xn={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=ee(this.d,t);null===n&&_(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,ee(this.d,n.n)))},$dependOn:e=>{this.resolve(q(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=q(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(q(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.P[n.y],J.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(q(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("**")&&U(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(P.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=G(this.Ut,t,V);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)Y(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?te(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=te(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?Z(this.target,e.z):null===t?void 0:Z(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Jn(e,t,n),null!==e.getter)return this.T.Uo(this,e,t);if(e.ae){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.tt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&_(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&&ee(t,Math.min(e.n,r.n))!==ee(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=++B,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:P.test(e)?+e.slice(1):0;return(n<1||n>128)&&_(1001,[e]),this.watchIndex(n),ee(this.d,n)?.y}let n=this.Xn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.rt?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,r=this.rr;if(null!==n.getter||n.ae||n.n>0)return X(this.read(n,r),t);let i=this.X;return null!==i&&0===i.be&&this.Yo(n,t,i),X(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(X(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Y(e,o.key,o.sub),s.splice(i--,1))}}let o={getter:r,r:i};G(e._??=new Map,t,K).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=Z(t,o),a=Z(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):Y(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,J.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=J.get(e);if(void 0===t){let n=new Set;J.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)(!F.includes(e)||"boolean"!=typeof n[e])&&_(44,["$behavior",e]);let[r,i,s]=F.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 k(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new $(r);return Object.freeze(n)}(e,this.commands),l=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new $(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=ee(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?G(this.ue,e.o,K).add(e):(t.we??(t.we=[])).push(e)}Rn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Pn(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Lt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${w(e)}`,n),c.at?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Pn()}Yt(){this.Et=!1;let e=this.qt;this.qt=0;let t=0;if(!this.Kt||this.zt?this.Kn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Kn,0),this.Kt=this.zt=!1,t>100)101===t?this.po(41,100):this.Pn();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.yn?this.Pn():this.po(11,32),this.yn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Lt=!1,this.oo(e)}let 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)?A("state",s):s();void 0!==o&&o.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.Kt=this.zt=!1,this.ze(),c.me?.(this),this.zo(),e>0&&this.Et&&(this.qt=t+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,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=G(this.Me,e.t,V);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){console.error(e)}Q(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.St.length)return;let t=this.St;this.St=[];let n=this.target.$errorCallback;for(let[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}]);Q(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${w(12,i.name?[s,t,i.name,i.i]:[s,t])}`,r,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=te(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])}},re={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"},ie=new Map,se=new Set(["if","elseif","else","for"]),oe=new Set([E,"if","elseif","for","..."]),le=new Set([x,T,"style","command",C,"state"]);function ae(e){let t=function(e){return R(e,";")}(e).map(L).filter(e=>e.length>0).map(e=>{let t=j(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(oe.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=D(r),t.et.length>0&&_(105,[e])):(t=D(r),"for"===i&&t.et.length>0&&_(121,[e])),{$e:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===x||i===T)&&_(122,[e,i]);let s=D(r),o=function(e){let[t,n]=H(e,"input",ie),r=t.split("#").map(L);r.length>2&&_(115,[t]);let[i,s]=r,o=i.split(".").map(L);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(L):[],D:n}}(n),[l]=o.Ne;if(""===l&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||le.has(e[0]))&&_(106,[n]),{...o,$e:e.join("."),Ne:e,...s,b:"prop"}}return{...o,...s,b:"radio"===i||"checkbox"===i?i:l===C||l.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>se.has(e.b))&&_(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],ce=new Map,he=new Map;function de(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});he.clear()}function fe(e){return ce.has(e)}function pe(e){_(26,[e])}function me(e){_(27,[e])}function ge(e,t){_(28,[e,t])}function ye(e,t){_(29,[e,t])}function be(e){return!(!e||isNaN(Number(e)))}function ve(e,t){return be(e)||me(t),Number(e)}function we(e,t,n){return ve(e?.[t]??pe(n),n)}function _e(e,t){return void 0!==t&&t.length>0?t[0]:e}var $e=(e,t)=>({factory:n=>{let r=we(n,0,e);return n=>("number"!=typeof n&&ge(e,n),t(n,r))},arity:[1,1]}),ke={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),r=_e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(be(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),r=_e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(be(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:$e("lt",(e,t)=>e<t),le:$e("le",(e,t)=>e<=t),gt:$e("gt",(e,t)=>e>t),ge:$e("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Se=!1;function Ne(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ae(e){return 0===e.length?null:(Se||(Se=!0,de(ke)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=he.get(r);if(typeof i<"u")return i;let s=ce.get(e);void 0===s&&function(e,t){ue.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),_(501,[e],e,t)}(e,ce.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 he.set(r,a),a}(e.Hn,e.args,e.literals)))}var Ee=Symbol.for("wcstack.trustedTypes.policy");function Ce(){let e=globalThis[Ee];return null!==e&&"object"==typeof e?e:null}function xe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Te(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ce(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Pe=Symbol.for("wcstack.state.view-transition-naming"),Oe=new WeakSet;function Me(){let e=N("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Le=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function je(e,t,n,r,i,s=!1){let o=n.localName;if(!o.includes("-"))return i(null);let l=Ie(n);if(!s&&!n.isConnected&&void 0===l.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>je(e,t,n,r,i,!0));let a=()=>{let e=l.get(o);l.upgrade(n),i(e?function(e){if(Le.has(e))return Le.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 Le.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 Re(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 Be(e,Ue,n,r,i,s,o,t.x,void 0);p.D=t.D,Ze(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=Ne(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 He(e,t,n){_(e,[t.localName,n])}var We=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Ue=11,De=["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,De[n.i]),Fe=Symbol();function qe(e,t,n){let r=t.U;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.q:Fe}var Be=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 De[this.i]}apply(){if(null!==this.j)return void this.j.Nt();let e=Ne(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Ue||8===this.i||xe(this.name)))return;if(this.value===Fe)return void(this.value=e);let t=this.a;if(this.i!==Ue)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ke(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ne(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=Ne(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 Ke(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?Te(r):null==r?"":String(r):xe(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Te(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ve]=[n,r])));case 8:return void(t.innerHTML=Te(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 Ve=Symbol();function Je(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ve];void 0!==n&&(t[n[0]]=n[1])}var Qe=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=at(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():ut(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Rt)for(let e of this.Rt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Rn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Xe=class extends Qe{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 Be(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 Ye(e,t,n,r){let i=ee(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 Ze(e,t,n){n&&e.nr(t);let r=t.Tn;null!==r&&(r.we??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function rt(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]=at(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 Qe(n,s,u,t),nt>=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||Oe.has(i))return;let o=globalThis[Pe]??={counter:0,assigned:0,warned:!1};o.assigned>=r?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${w(25,[r])}`)):(Oe.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",nt),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,v=null===m?null:m.pe;if(null!==v){let e=t.Xe;for(let t=0;t<e.length;t++)v[2*t]=b[e[t].a],v[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!==v){let r=m.V?.[l];if(void 0!==r){r.te=!1,e.Ke(r);continue}try{let t=Ne(i.x,e.read(i.o,n));t!==i.q&&(Ke(i.i,o,i.name,t),v[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 lt(e,i.C,Ye(e,i.o,n,o),o);(p.u??=[]).push(t),o===s&&(p.On=t),t.Nt();break}case 7:{let t=st(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{it(e,i,o,n,p)}catch(t){ze(e,t,i,o)}}}return et=p,f}function it(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 je(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&&He(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 je(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name;null===i&&He(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){console.error(e)}})}(e,t,s,r,n))}let o=t.o,l=ee(r,o.n);if(14===t.i)return void je(e,t,s,i,n=>function(e,t,n,r,i,s){null===s&&He(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;Re(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 je(e,t,s,i,n=>function(e,t,n,r,i,s){if(null!==s)return void Re(e,t,n,t.name,t.o,r,i,s);let o=new Be(e,1,n,t.name,t.o,r,i,t.x,qe(e,t,r));o.D=t.D,!c.ar?.(o,t.ro)&&(Ze(e,o,!0),e.Ke(o))}(e,t,s,l,i,n));let a=new Be(e,t.i,n,t.name,o,l,i,t.x,qe(e,t,l));a.D=t.D,Ze(e,a,!0),e.Ke(a),null!==t.Ft&&n.addEventListener(t.Ft,()=>a.ir())}function st(e,t,n,r){let i=new ot(e,t,n),s=null;for(let o of t){if(null===o.o)continue;let t=o.o,l=new Be(e,7,o.S,"if",t,ee(n,t.n),r,null,void 0,i);Ze(e,l,!0),null===r&&i.ue.push(l),s??=l}return e.Ke(s),i}var ot=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}In(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}Nt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let r=this.K[n];if(null===r.o||Ne(r.x,e.read(r.o,ee(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(nt=Me(),null!==this.I&&(this.I.bo(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],r=rt(e,n.C,this.r,null,n.S);this.I=tt();let i=n.S.parentNode;i.insertBefore(r,n.S),Je(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Rn(e);null!==this.I&&this.I.Pe(this.engine)}},lt=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;nt=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):ut(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(rt(e,this.C,n,this),i),u=tt()),l[a+s]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(rt(e,this.C,t[r],this)),l[r]=tt();o.insertBefore(n,d)}}this.Ae=l,Je(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function at(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function ut(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var ct=()=>re.bindAttributeName;function ht(){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 dt=["state","element","auto","none"],ft=["call","connect"],pt="$command.";function mt(e,t,n){P.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 gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&Ge(e.name);function bt(e){_(202,[e])}function vt(e,t,n,r,i){let s=ae(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?dt:ft).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{...ht(),a:i,i:13,name:l.slice(1).join("."),Pt:a,xe:o,Tt:s.Tt,At:s.At};let n=a.startsWith(pt)?a.slice(9):null,{Tt:r,At:u}=s,h=t.$e.slice(2),d=t.rn.includes("direct"),f=!d&&We.has(h);f&&e.co(h);let p=t=>{console.error(t),f&&c.handlerThrew?.(e,a,h)};return{...ht(),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);Q(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ht(),a:i,i:14,o:mt(e,a,n),xe:o};if("command"===l[0]&&l.length>1)return a.startsWith(pt)||_(1201,[t.$e,a]),{...ht(),a:i,i:12,name:l.slice(1).join("."),Pt:a,xe:o};let u=mt(e,a,n),h={...ht(),a:i,i:1,name:t.$e,o:u,x:Ae(t.et),D:Ae(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 wt=/\{\{([\s\S]+?)\}\}/g;function _t(e){let t=e.data,n=[],r=0;wt.lastIndex=0;for(let i=wt.exec(t);null!==i;i=wt.exec(t)){let s=wt.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=wt.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function $t(e,t,n,r){let i=function(e){return{$e:"textContent",Ne:["textContent"],rn:[],D:[],...D(e),b:"text"}}(t);return{...ht(),a:r,i:0,o:mt(e,i.Ze,n),x:Ae(i.et),q:""}}function kt(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var St=(e,t)=>0===e?re.commentIfPrefix:null===t.o?re.commentElsePrefix:re.commentElseIfPrefix;function Nt(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:mt(e,r.Ze,n),x:"else"===r.b?null:Ae(r.et)}),i=[r(t,kt(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=kt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(r(e,t)),"else"===t.b))break}return i}var At=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(ct()+"-ignore"))continue;if(r){if("script"===l||"style"===l||At.has(t))continue;if(At.add(t),l===re.tagNames.state){u([...t.childNodes]);continue}}let h="template"===l?kt(t):null;if(null!==h){if("for"===h.b){let r=mt(e,h.Ze,n),s=Tt(e,t,r,!0);i(a(t,re.commentForPrefix),r,s)}else"if"===h.b?s(Nt(e,t,n).map((t,r)=>({C:Tt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,St(r,t))}))):bt(h.b);continue}let f=t.getAttribute(ct()),p=null===f?null:vt(e,f,n,t,0),m="noscript"!==l&&"iframe"!==l&&!p?.some(yt)&&!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("{{")&&!At.has(d))for(let{a:e,cr:t}of _t(d))l(e,t);else if(8===d.nodeType){let e=Ct.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 Ct=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,xt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Tt(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({...ht(),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({...ht(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=l(e);for(let e of t)gt(e)&&_(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,r)=>{o.push($t(e,r,n,l(t)))}),Lt(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&&!Pt(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&&Ot(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 Pt(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function Ot(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 Mt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Lt(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&&Lt(r,t,Mt.has(r.localName)),r=e}}var It=new WeakMap;function jt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),Ht(e,[...n.childNodes]),e.ze()}function Rt(e,t,n){try{let r="template"===t.localName?kt(t):null;null!==r&&!n&&_(204,[r.b]),Ht(e,[t])}catch(e){console.error(e)}e.ze()}function Ht(e,t){Et(e,t,null,!0,(t,n,r)=>{new lt(e,r,Ye(e,n,null,t),t).Nt()},t=>{st(e,t,null,null)},(t,n)=>{c.Dn?.(e,t,n);for(let r of n)it(e,r,t,null,null)},(t,n)=>{c.Dn?.(e,t,n),it(e,$t(e,n,null,0),t,null,null)})}var Wt=Symbol.for("wcstack.binder"),Ut=Symbol.for("wcstack.binder.pending"),Dt=Symbol.for("wcstack.binder.taken"),zt=new Map;function Ft(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?zt.set(e,t):Rt(n,e,t?.range)}function qt(){let e=[...zt];zt.clear();for(let[t,n]of e)Ft(t,n);!function(){let e=function(){let e=globalThis[Wt];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;let t=function(){let e=globalThis,t=e[Ut];return void 0===t&&(t=[],e[Ut]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),r=function(){let e=globalThis,t=e[Dt];return void 0===t&&(t=new WeakSet,e[Dt]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Bt=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)}))}},Gt=0,Kt=new WeakMap;function Vt(e,t=e.getRootNode()){Kt.set(t,[...Kt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Jt(e){let t=Kt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Kt.get(e)!==t?Jt(e):Promise.reject(r.errors[0]):void 0)}var Qt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Qt{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=Jt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();Vt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!It.has(t)&&It.set(t,e),qt(),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&&Vt(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),Vt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let e=this.engine;if(null===e)return;let t=e.root;It.get(t)===e&&It.delete(t),Vt(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] ${w(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||_(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?w(42):w(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=It.get(e)?.element;i?.isConnected&&(i.V||i.Ge)&&_(47);let s=new ne(n,new Bt);s.element=this,this.engine=s,c.element?.(s,"mounting"),jt(s,e),qt(),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)]:[]);console.error(`[@wcstack/state] ${w(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.ze(t,e))}},Yt=[];function Zt(){return(Yt=Yt.filter(e=>e.deref())).map(e=>e.deref())}var en,tn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},nn="en";function rn(){if(re.locale!==en){en=re.locale;try{nn=Intl.getCanonicalLocales(en)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[en])}`),nn="en"}}return nn}var sn=["full","long","medium","short"];function on(e,t){let[n,r]=e??[];return void 0===r&&void 0!==n&&sn.includes(n)&&([n,r]=[void 0,n]),void 0!==r&&!sn.includes(r)&&function(e,t){_(52,[e,t])}(t,r),[n,r]}var{eq:ln,ne:an,not:un,lt:cn,le:hn,gt:dn,ge:fn,falsy:pn,truthy:mn,boolean:gn}=ke,yn={toFixed:{factory:e=>{let t=ve(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale",e),e.toLocaleString(t??rn()))},arity:[0,1]},upper:{factory:tn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:tn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:tn(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:tn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:tn(e=>{let t=[we(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ve(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:tn(e=>{let t=we(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:tn(e=>{let t=we(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:tn(e=>{let t=we(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:tn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:tn(e=>{let t=we(e,0,"truncate"),n=e?.[1]??"…";return e=>{let 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&&ge("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,ve(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=ve(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:tn(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=on(e,"date"),r=n&&{dateStyle:n};return e=>(e instanceof Date||ye("date",e),e.toLocaleDateString(t??rn(),r))},arity:[0,2]},time:{factory:e=>{let[t,n]=on(e,"time"),r=n&&{timeStyle:n};return e=>(e instanceof Date||ye("time",e),e.toLocaleTimeString(t??rn(),r))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=on(e,"datetime"),r=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||ye("datetime",e),e.toLocaleString(t??rn(),r))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("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:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("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:ln,ne:an,not:un,lt:cn,le:hn,gt:dn,ge:fn,add:$e("add",(e,t)=>e+t),sub:$e("sub",(e,t)=>e-t),mul:$e("mul",(e,t)=>e*t),div:$e("div",(e,t)=>e/t),mod:$e("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=we(e,0,"clamp"),n=we(e,1,"clamp");return e=>("number"!=typeof e&&ge("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:pn,truthy:mn,defaults:{factory:(e,t)=>{let n=_e(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=_e(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:gn,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??pe("currency"),n=e?.[1],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&&ge("currency",e),e.toLocaleString(n??rn(),r))},arity:[1,2]}},bn=!1,vn={name:"formats",install:function(){bn||(bn=!0,de(yn))}};function wn(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=wn(n,e.toLowerCase(),2);t<i&&(r=e,i=t)}return null!==r?` Did you mean "${r}"?`:""}var $n=" Validate statically: npx @wcstack/lint <file>.",kn=["","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"],Sn=e=>{let t=kn[e/100|0];return t?`[wcs/${t}] `:""},Nn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],An=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."],Cn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,xn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Tn={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 ${An(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 ${An(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&&Nn.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)=>`${Cn(e,t)} failed to initialize.`,50:(e,...t)=>`${Cn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Cn(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 Pn(e,t){let n=Tn[e];return void 0===n?`${Sn(e)}#${e} ${t.join(" ")}`:Sn(e)+n(...t)}var On=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Mn=[[/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.']],Ln={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function In(e,t,n){let 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(Ln,e)?Ln[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 Mn){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"].':ue.some(fe)||(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&&On.has(s[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=$n),r}var jn=new WeakMap,Rn=new WeakMap,Hn=new WeakSet,Wn=new WeakSet;function Un(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 Dn(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!==Un(e.target,t.t)?.get?t:e.O.wt(o(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:Fn(e,n,0,e.target,r)}function Fn(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=Fn(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=Un(r,s.s);if(void 0===o&&null===s.c&&e.tt.has(s.s))return null;if(void 0===o){let o=Dn(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 qn(e){Hn.has(e)||(Hn.add(e),setTimeout(()=>function(e){Hn.delete(e);let t=jn.get(e);if(void 0===t)return;let n=Rn.get(e);void 0===n&&Rn.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(`${re.tagNames.state}[mount]`)??[]].find(e=>!Wn.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==l){n.delete(t),l.initializePromise.then(()=>{Wn.add(l),qn(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."}${$n}`)}}(e),0))}function Bn(e,t,n=!1){Gn(e,t,n?1:0)}function Gn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let r=jn.get(e);void 0===r&&jn.set(e,r=new Map),r.has(t)||r.set(t,n),qn(e)}var Kn=new WeakSet,Vn=!1,Jn=new WeakMap;function Qn(e,t){let n=Jn.get(e),r=t.s;if(null!==t.c||Vn||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(`${re.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}${$n}`)}var Xn=new WeakSet;function Yn(e){if(Xn.has(e))return;Xn.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.${$n}`)),t.apply(e,r))}var Zn=new WeakMap;function er(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Un(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let i=Zn.get(e);void 0===i&&Zn.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${$n}`))}function tr(e){jn.has(e)&&e.He.length>0&&qn(e)}var nr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),rr=!1;function ir(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(rr||!(t instanceof TypeError)||!xe(r)||!("trustedTypes"in globalThis))return;rr=!0;let i="function"==typeof Ce()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${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 sr=new WeakMap;function or(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=sr.get(e);void 0===s&&sr.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 lr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],ar={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},ur={name:"diagnostics",install(){c.Bo=In,c.Mo=Pn,c.Eo=Bn,c.detail=or,c.Ye=h(c.Ye,ir);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&_(1);for(let[t,n]of lr)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=Dn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),h=e=>v(`[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(`^(?:${nr(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(`^${nr(r)}(?:${nr(l)})*${nr(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){Rn.delete(e),jn.has(e)&&qn(e)}(t),function(e){if(Kn.has(e))return;Kn.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{Vn=!0;try{n(t)}finally{Vn=!1}let r=e.O.wt(o(t).o);void 0!==r&&Gn(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))Yn(t)}})}(t),Jn.set(t,new Set(Dn(n)))},c.handlerThrew=er,c.re=h(c.re,Qn),c.me=h(c.me,tr),c.rt=d(p,c.rt,(e,t)=>Object.hasOwn(ar,t)?_(1701,[t,ar[t]]):void 0)}},cr={},hr=/\.\d/,dr=new Set(Object.getOwnPropertyNames(Object.prototype)),fr=0,pr=!1,mr=null,gr=()=>{pr=!1,fr++};function yr(){if(null===mr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=gr,e.port1.unref?.(),mr=()=>e.port2.postMessage(0)}else mr=()=>setTimeout(gr,0);return pr||(pr=!0,mr()),fr}function br(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(cr,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)&&br(wr(e.p),n)&&this.dt(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Oo(){this.active=!1,this.Fe.clear(),this.early=[]}Wn(e,t,n,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??cr):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??cr),!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??cr,l),Object.is(l,s)&&(hr.test(i.t)||null!==t&&!u&&!(o??=null!==e&&br(wr(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){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),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=yr();t!==this.Fo&&(this.Fo=t,this.Mn.clear());let n=e.filter(e=>!this.Mn.has(e));if(0!==n.length){for(let e of n)this.Mn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function wr(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 $r="$streamStatus",kr="$streamError",Sr=new Set(Object.getOwnPropertyNames(Object.prototype)),Nr=!1;function Ar(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){Nr=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Nr=!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($r,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();Cr(s);try{n=i.read(s,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&v(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${$r}.${e}`||n.t===`${kr}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,s,n)}catch(n){Cr(s);for(let e of o)e._n(s);if(s.Y=r,t)throw n;return this.set(kr,e.name,n),void this.set($r,e.name,"error")}}let s=new AbortController;e.J=s,i.A(i.o(e.name),null,e.q),this.set(kr,e.name,null),this.set($r,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=yr(),u=e=>{yr()===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($r,e.name,"done"))}catch(n){if(!s())return;e.J=null,t.abort(),u(()=>{this.set(kr,e.name,n),this.set($r,e.name,"error")})}}};function Cr(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 Tr(e){let t=xr.get(e);return t?.target===e.target?t:void 0}function Pr(e,t){let n=new vr(e,function(e,t){if(void 0===t)return[];(null===t||"object"!=typeof t)&&v("$watch must be an object mapping paths to handler functions.");let n=[];for(let r of Object.keys(t)){let i=t[r];(""===r||"$"===r[0]||r.includes("@")||dr.has(r))&&v(`$watch path "${r}" is not a path of the state tree.`),"function"!=typeof i&&v(`$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)&&v("$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)||Sr.has(o))&&v(`$stream entry "${o}" must be a flat property name.`),(null===l||"object"!=typeof l)&&v(`$stream entry "${o}" must be an object.`);let a=l.source,u=l.fold,c=l.args,h=l.initial;"function"!=typeof a&&v(`$stream entry "${o}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${o}": fold must be a function.`),void 0!==u&&!("initial"in l)&&v(`$stream entry "${o}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${o}": args must be a function.`),Ar(t,o)&&v(`$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[$r]=i,t[kr]=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 Or(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 Mr=["$streamStatus","$streamError"],Lr={name:"temporal",install(){c.fe=h(c.fe,Pr),c.element=h(c.element,Or),c.re=h(c.re,(e,t,n,r,i,s,o)=>Tr(e)?.W.re(t,n,r,i,s,o)),c.Se=h(c.Se,(e,t,n)=>{let r=Tr(e);void 0!==r&&(r.W.Se(t,n),r.Ct.Se(t))}),c.Qt=h(c.Qt,(e,t,n)=>Tr(e)?.W.Qt(t,n)),c.me=h(c.me,e=>{let t=Tr(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(Mr.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=d(f,c.Ie,(e,t)=>(!Nr&&36===t.t.charCodeAt(0)&&Mr.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Ir=new WeakMap,jr=!1,Rr=/^(?!prototype$)[^\d.*$][^.*]*$/;function Hr(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let i=n[t];"string"==typeof i?r.set(e.o(t),e=>e[i]):"function"==typeof i?r.set(e.o(t),i):v(`$listKeys "${t}" must be a field name or a function.`)}}Ir.set(t,r)}function Wr(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Ur(e,t,n){let r=new Map;for(let i of t){Wr(i)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(i);null==t&&v(`$listKeys "${e}": a row has no key.`),r.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,i)}return r}function Dr(e,t,n,r){if(jr||!Array.isArray(r))return!1;let i=Ir.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=Ur(t.t,s,i);Ur(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){jr=!0;try{e.A(t,n,l)}finally{jr=!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=Rr.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",install(){c.fe=h(c.fe,Hr),c.Ie=d(f,c.Ie,Dr)}},Fr=new WeakMap,qr=new WeakMap,Br="will not graft: the root state failed to initialize.",Gr=new WeakSet,Kr=new WeakMap,Vr=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Jr=["$commandTokens","$eventTokens","$on","$errorCallback"],Qr=e=>`[@wcstack/state] <${re.tagNames.state} mount="${e}">`,Xr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Yr=e=>e?.element?.isConnected?e:void 0;function Zr(e){let t=qr.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ei(e,t){let n=qr.get(t);if(qr.delete(t),Array.isArray(n))for(let t of n)ii(t,e)}function ti(e){let t=Fr.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ni(e,t){console.error(`${Qr(e.t)} ${t}`),ti(e),e.Qe?.(),e.Qe=null}function ri(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function ii(e,t){if(Gr.has(t))return ni(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 ni(e,`will not graft: the root state already has "${e.t}".`);let o=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,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)):Xr.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=Kr.get(t);void 0===c&&Kr.set(t,c=[]),c.push(e),e.el.isConnected&&ri(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function si(e,t){let n=qr.get(e);if(Array.isArray(n))for(let e of n)ni(e,Br);qr.set(e,t)}var oi=new WeakMap;function li(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(re.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Fr.get(t);void 0===e&&Fr.set(t,e=new Map);let s=e.get(n);if(void 0!==s&&s!==r&&(null===s.engine?s.el.isConnected:Yr(s.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===s?.engine){let e=qr.get(t);Array.isArray(e)&&qr.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 ni(r,i);if(Fr.get(t).get(n)===r){for(let t of Vr)if(void 0!==e[t])return ni(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of Jr)void 0!==e[t]&&console.warn(`${Qr(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=Yr(It.get(t)),i=qr.get(t);void 0!==n?ii(r,n):Zr(t)?ni(r,Br):qr.set(t,[...Array.isArray(i)?i:[],r])})}},Je(){null!==r.engine&&ri(r,"$connectedCallback")},Bn(){null!==r.engine&&ri(r,"$disconnectedCallback")},reset(){v(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var ai=new WeakMap,ui=new WeakMap;function ci(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||v(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&v(`${t} entries must be non-empty strings.`),"$"===e[0]&&v(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&v(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function hi(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")&&v("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||v(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&v(`DCC: <${e}> is already defined.`);let i=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(r),s=ci(r,"$bindables"),o=ci(r,"$commands");for(let e of s){let t=i.get(e);void 0===t&&v(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&v(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of o){let t=i.get(e);void 0===t&&v(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&v(`$commands entry "${e}" is not a method: list it in $bindables.`)}let 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(re.tagNames.state);return a.set(r,o),ai.set(r,l),null===o&&s.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${re.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(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var di=new WeakMap,fi=new WeakSet,pi=new WeakMap,mi=new WeakMap,gi="data-wcs-wired",yi=new WeakMap,bi=new WeakMap,vi=new WeakMap,wi=0,_i=new Set,$i={},ki=["$watch","$stream","$renderedCallback"],Si=e=>e.split(".",1)[0];function Ni(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ai(e,t){let n=e.a,r=Si(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(gi);else if(!Ci(n,r)){let e=n.getAttribute(gi)?.split(" ")??[];e.includes(r)||n.setAttribute(gi,[...e,r].join(" "))}yi.get(n)?.he===r&&v(`<${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=di.get(n);void 0===i&&di.set(n,i=[]),i.push(e),t&&fi.add(e);let s=pi.get(n);return void 0===s&&pi.set(n,s=new Map),s.has(r)||s.set(r,n[r]),mi.get(n)?.(),!1}function Ei(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${re.tagNames.state}[bind-component]`)}function Ci(e,t){let n=e.getAttribute(re.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=It.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.V:null===t)&&(null===t?Ft(e):Rt(n,e))}var Ti=new Set;function Pi(e,t){Ti.has(e)||(Ti.add(e),console.warn(`[@wcstack/state] ${t}`))}var Oi=(e,t)=>t in e.state;function Mi(e,t){let n=Li(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Li(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function Ii(e,t,n){if(null!==n.getter)return;let r,i=e.host,s=i.engine,o=Si(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=ji(e,l.r);return 0===t.n?n:(s.resolve(Ni(o.t,[...s.H(n),...i.H(ee(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();Ri(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?Oi(i,o):Mi(i,o))return;r=l.ye}else{if(null===t||null!==n.c||"$"===o[0]||Oi(i,o))return;l=t,r=s.o(`${t.ye.t}.${o}`)}let a=l.r,u=l;n.getter=()=>s.v(r,ji(e,a)),n.se=t=>{Ri(e,u,()=>s.A(r,a,t)),e.dn=n},e.pt.set(n,{e:l,p:r,r:a})}function ji(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function Ri(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 Hi=(e,t)=>t||!_i.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Wi(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,wi+=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=Si(o);if(o!==a&&!Oi(n,a))continue;let u=r.o(`${t.ye.t}.${o}`);if(null===u.getter)zi(r,u,t.ye);else if(!Ui.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;Pi(`${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 Ui=new WeakSet;function Di(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&&v(`[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=Di(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Ui.add(t.getter),t.se=o=>{let l=null===s()?Di(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===Li(l.host.state,a.t)?.set&&v(`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 Fi(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 qi(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 Bi(e,t,n,r,i,s,o){let l=n.t.slice(t.t.length);if(""===l)return qi(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=l.slice(1);let e=Si(a);if("$"===e[0]||Oi(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(ee(r,e).y);c.resolve(Ni(a,h),null);let d=c.rp,f=c.rr;d.n>0&&null===f||Fi(c,d,f,i,s,o)}function Gi(e,t,n,r,i,s,o){if(0===wi)return;let l=_i.has(e);_i.add(e);try{let l=bi.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(Ni(o.p.t+t.t.slice(l.t.length),u),null);let c=a.rp,h=a.rr;c.n>0&&null===h||Ri(e,o.e,()=>Fi(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:ee(n,e.n));if(void 0!==a)for(let l of[...a])Hi(l,o)&&Bi(l,e,t,n,r,i,s)}else if(e.ee(t))for(let[e,r]of[...l])if(0===t.n||ee(e,t.n)===n)for(let e of[...r])Hi(e,o)&&qi(e)}finally{l||_i.delete(e)}}async function Ki(e,t,n,r,i){if(r===$i)return;let s=y(r);s&&await s;let o=yi.get(t);o.engine&&r.$recursion&&v(`[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&&v(`<${t.localName}> already has a connected <${re.tagNames.state} bind-component="${o.he}">.`),null!==l&&Wi(l,!1),null!==l&&function(e,t,n){let r=e.R,i=`[${re.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 Vi(e,r):r()}(l,e,n,i);let a=new ne(r,new Bt);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,bi.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=Si(e.E);Oi(n,t)&&(e.E!==t||Mi(n,t))&&Pi(`${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)&&Pi(`${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=ki.filter(e=>void 0!==n.state[e]);o.length>0&&Pi(`${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=>{Ii(e,s,n),l.call(t,n)};let a=[...t.O.all()];for(let t of a)Ii(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=bi.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),Wi(u,!0),Gr.add(a),ei(a,n));let d=c.hr?.(n,a);jt(a,n),d?.(),u.L=[...n.childNodes],qt(),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,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.Ee("$connectedCallback"),h&&e.isConnected&&c.element?.(a,"connected")):Wi(u,!1)}async function Vi(e,t){Wi(e,!0);for(let t of e.pe)qi(t);t?.(),!e.broken&&(await e.R.Ee("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function Ji(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){si(t,e);for(let e of oi.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:yi.get(s)?.I;return t?.el===e?t:null},l=t=>{throw i&&si(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"]'))&&v(`<${re.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let s=yi.get(n);if(void 0!==s)return s.he!==t&&v(`<${i}> already has a <${re.tagNames.state} bind-component="${s.he}">.`),s.state;let o=()=>(di.get(n)??[]).filter(e=>Si(e.name)===t),l=Ci(n,t);if(l&&0===o().length&&xi(n),0===o().length&&(l||((e,t)=>!0===e.getAttribute(gi)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,s)=>{mi.set(n,r),e=function(e,t){Zr(e)&&t();let n=oi.get(e)??new Set;return oi.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())}mi.delete(n);let a=o(),u=pi.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${i}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&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 (${re.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),$i}let h=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);h.some(e=>e.E===r)&&v(`<${i}> maps "${e.name}" twice.`);let s=r.split(".").indexOf("*");if(s>=0){let n=r.split(".").slice(0,s).join(".");v(`<${i}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}h.push({E:r,ye:e.o,r:e.r,ro:fi.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 yi.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 <${re.tagNames.state}> to be a direct child of a custom element.`))).catch(l),async start(t,n){await Ki(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?Vi(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===r)return Ki(e,s,i?r:s,yi.get(s).state,()=>{})}).catch(e=>console.error(e)):mi.has(s)&&xi(s)},Bn(){let e=o();null!==e&&(Wi(e,!1),!e.broken&&(e.R.Ee("$disconnectedCallback"),null===e.host.engine&&c.element?.(e.R,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${s?.localName}>.${n} instead.`)}}}var Qi={name:"scopes",install(){c.ut=d(m,c.ut,li),c.ut=d(m,c.ut,hi),c.ut=d(m,c.ut,Ji),c.ar=Ai,c.$o=Ei,c.element=h(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Kr.get(e)??[];if("disconnected"===t)for(let e of n)ti(e);else if("reset"!==t&&Yr(It.get(e.root))===e){ei(e,e.root);for(let e of n)Fr.get(e.root).has(e.t)||Fr.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ei(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:ai.get(n);void 0!==r&&ui.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=ui.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),Gi(e,t,n,r,i,s,!1)}),c.Se=h(c.Se,(e,t,n)=>Gi(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=Kr.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,i=bi.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||(ji(i,s.r),void v(`[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=Kr.get(t);void 0!==r&&r.length>0&&v(`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)&&v("re-setting a root state with mounted components is not supported: they read its data."),e?.(t,n)}}},Xi="$recursion",Yi=new WeakMap,Zi=new WeakSet,es=new WeakSet,ts=0,ns=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),rs=e=>`[wcs/recursion-${e}]`;function is(e,t){let n=n=>v(`${rs("declaration-invalid")} ${Xi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${rs("declaration-invalid")} ${Xi} ${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 ss=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function os(e,t){let n=`${e.l}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),r}function ls(e,t,n){let r=os(e,t),i=function(e,t){for(let n=t;null!==n;n=n.l.ce){let t=e.nodeList.exec(n.l.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===i&&v(`[wcs/recursion-context] "${t}" uses "**", which is bound to the depth of the row it is evaluated in; there is none here — use $getAll("${t}", []) for every depth.`),ss(e,i.k)+r}function as(e,t,n){let r=new Set,i=new Set,s=(e,n,s)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&v(`${rs("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&v(`${rs("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&&v(`${rs("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(`${ss(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 us(e,t){let n=function(e){let t=e[Xi],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&&U(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${rs("declaration-invalid")} ${Xi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&v(`${rs("declaration-invalid")} ${Xi} must declare exactly one anchor (it declares ${i.length}).`);let s=is("anchor",i[0][0]),o=is("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("**"))&&v(`[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))&&v(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&v(`${rs("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),h.push([new RegExp(`^${ns(s)}((?:${ns(u)})*)${ns(n)}$`),n])}return{l:l,step:u,key:a,families:c,matchers:h,owners:new Map,nodeList:new RegExp(`^${ns(l)}((?:${ns(`.*.${a}`)})*)$`)}}(t),r=Yi.has(e);null!==n?(r||ts++,Yi.set(e,n),es.add(e),Zi.has(e)||function(e){Zi.add(e);let t=e,n=t.ot;t.ot=r=>{let i=Yi.get(e);if(r.t.includes("**")){let t=e.O.wt(r.t)===r;return void(es.has(e)||void 0===i&&t?r.getter=()=>U(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=Yi.get(e);return r.call(e,void 0!==i&&t.includes("**")?ls(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,r)=>{let s=Yi.get(e);if(void 0===s||!n.includes("**"))return i.call(e,n,r);if(void 0===r)return i.call(e,ls(s,n,t.d));(!Array.isArray(r)||r.length>0)&&v(`${rs("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=os(s,n),l=[];return as(e,s,(t,n)=>{for(let r of i.call(e,ss(s,t)+o,e.H(n)))l.push(r)}),l};let s=t.wn;t.wn=(n,r,i,o)=>{let l=Yi.get(e);if(void 0===l||!n.includes("**"))return s.call(e,n,r,i,o);Array.isArray(r)||_(9,[n]),r.length>0&&v(`${rs("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&v(`${rs("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&_(8);let a=os(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(".")}`))&&v(`${rs("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}.`))&&v(`${rs("readonly")} "${n}" writes into the recursive getter "${l.l}.**${e}".`)}let h=[];as(e,l,(e,t)=>h.push([e,t]));let d=0;for(let[t,n]of h)d+=s.call(e,ss(l,t)+a,e.H(n),i);return d}}(e)):r&&(Yi.delete(e),ts--)}function cs(e,t){if(0===ts)return!1;let n=Yi.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&&v(`${rs("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var hs={name:"recursion",install(){c.fe=h(c.fe,us),c.element=h(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){es.delete(e)}(e)}),c.Ie=d(f,c.Ie,cs)}},ds="4.4.0",fs=e=>e.split(".").slice(0,2).join("."),ps=class extends Qt{static find(e){return e.querySelector?.(re.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 fs(this.version)===fs(ds)}};function ms(e){let t=re.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends ps{})}var gs=()=>re.tagNames.ssr,ys=Symbol.for("wcstack.ssr.snapshotBuilder"),bs=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),vs=e=>document.createComment(e),ws=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,_s=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),$s=new WeakMap,ks=new WeakMap,Ss=new WeakMap,Ns=new WeakSet,As=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 Cs(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 Ts(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))Ns.add(e)}function Ps(e){if(e instanceof lt){Ts(e.S,e.S,e.Ae,null);for(let t of e.Ae)Os(t);return}let t=e.I;null!==t&&(Ts(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Os(t))}function Os(e){if(null!==e.u)for(let t of e.u)Ps(t)}var Ms=new Set(["script","style","template","textarea","title"]),Ls="data-wcs-raw",Is=e=>Ms.has(e.localName)||e.localName===gs();function js(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&&!Is(t)&&js(t)}var Rs=0;function Hs(e,t){let n=e.getRootNode(),r=[t];for(let e of ks.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let i=new Map;for(let e of r){let t=$s.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),Ps(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ss.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ns.has(e)||1===e.nodeType&&t.has(e)&&Fs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Is(e.parentNode)?As.has(e):t.has(n)&&_s(n,"wcs-t:"))&&(As.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);Is(e)&&n.some(e=>As.has(e))&&e.setAttribute(Ls,n.map(e=>As.has(e)?`{{ ${As.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}js(9===n.nodeType?n.body:n);let s=document.createElement(gs());s.setAttribute("version",ds);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"}${Rs++}`;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(Cs(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(Cs(t,l,o))}e.before(s)}function Ws(e){!function(e){if(null!==e.querySelector(re.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=>As.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(`${re.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===gs())continue;let e=t.engine;null!=e&&Hs(t,e)}}var Us=Symbol.for("wcstack.state.ssr.impl"),Ds=new Map,zs=new WeakMap,Fs=e=>!0===c.$o?.(e),qs=e=>1===e.nodeType&&!Is(e)&&!Fs(e),Bs=e=>e.f.flat().concat(e.z??[]),Gs=e=>{for(let t of Bs(e))t.remove()};function Ks(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&&!ws(l,"wcs-]");){let e=l.nextSibling;if(ws(l,"wcs-|"))o.push([]),l.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];_s(l,"wcs-[")?e=Ks(l,t,n):(n.push(l),qs(l)&&Vs(l,t))}l=e}let a={branch:void 0===r[1]?null:Number(r[1]),f:o,z:l??s.appendChild(vs("wcs-]"))},u=Bs(a);l=a.z.nextSibling;for(let e of u)n?.push(e),t&&At.add(e);return t&&null!==i?Ds.set(i,a):Gs(a),l}function Vs(e,t){for(let n=e.firstChild;null!==n;)_s(n,"wcs-[")?n=Ks(n,t):(qs(n)&&Vs(n,t),n=n.nextSibling)}function Js(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&&!ws(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]?Cs(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&&!Is(i)&&(Fs(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||ro(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{_s(e,"wcs-[")?r++:ws(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(ws(r,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Vs(e,n)}function Qs(e,t){let n=zs.get(e);if(void 0===n)return null;zs.delete(e);let r=e=>Js(e,n.ssr,n.Te);if(n.Te||eo(t,e,e,r),r(e),!n.Te)return null;let i=c.Te;return c.Te=oo,()=>{c.Te=i,Xs()}}function Xs(){for(let e of Ds.values())Gs(e);Ds.clear()}function Ys(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Zs(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 eo(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)=>$t(e,n,null,0))}function to(e,t,n){if(bs()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Ns.add(e);else if(e.localName.includes("-")&&!Fs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ss.set(e,t)}return}if("string"==typeof n){if(As.set(t,n),Is(t.parentNode))return;let e=vs(`wcs-t:${encodeURIComponent(n)}`),r=vs("wcs-/t");return t.before(e),void t.after(r)}let r=$s.get(e);void 0===r&&$s.set(e,r=new Map),r.set(t,n);let i=t.getRootNode(),s=ks.get(i);return void 0===s&&ks.set(i,s=new Set),void s.add(e)}if("string"!=typeof n&&Ds.size>0){let e=Ds.get(n);void 0!==e&&(Ds.delete(n),Ds.set(t,e))}}var no=e=>null!==e&&8===e.nodeType&&[re.commentIfPrefix,re.commentElseIfPrefix,re.commentElsePrefix].includes(e.data),ro=e=>3===e.nodeType&&""===e.data.trim(),io=e=>{let t=Ds.get(e)?.z??e;return(xs(t)??t).nextSibling};function so(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=io(o)}e.So[r]=o}return!0}function oo(e,t,n){if(0===Ds.size)return null;let r=t,i=0;if(!n){let e=re.commentIfPrefix;if(!ws(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(no(n)&&i++,!ws(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ds.has(r)&&null!==n&&!ws(n,e)&&1!==n.nodeType;n=n.nextSibling)no(n)&&(r=n)}let s=Ds.get(r);if(void 0===s)return null;if(!n&&s.branch!==i)return Ds.delete(r),Gs(s),null;let o=s.f.shift();if(0===s.f.length&&Ds.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=Ds.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(!so(e,l)){let n=(e.jn?e.root:e.ln).cloneNode(!0);l=e.jn?[n]:[...n.childNodes],so(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 lo={name:"ssr",install(){c.Dn=to,c.hr=Qs;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||bs())return;let n=t.previousElementSibling,r=n?.localName===gs(),i=r?n.getAttribute("version"):null,s=null===i||fs(i)===fs(ds);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] <${gs()} version="${i}"> does not match ${ds}: 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(`[${Ls}]`)))e.textContent=e.getAttribute(Ls),e.removeAttribute(Ls);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&&!Fs(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 > ${re.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of ae(t.getAttribute(re.bindAttributeName)??"")){let t=r.Ze;r.Ne[0]===s&&n.push([e?Zs(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:Zs(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]:Zs(r,s[2],2,1)??s[2]};for(let t of Ys(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!ws(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 Ys(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=re.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):Js(e,n,s);s||eo(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=oo,queueMicrotask(()=>{Xs(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Us]={build:Ws,reset(){Rs=0}},void 0===e[ys]&&(e[ys]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Us].build(t),reset:()=>e[Us].reset()})}(),c.Ao=h(c.Ao,ms);for(let e of Zt())ms(e)}},ao="__WCSTACK_DEVTOOLS_HOOK__",uo=null,co=new Set,ho=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),fo=new WeakMap,po=0,mo=new WeakMap;function go(e){if(null===uo)return;let t=mo.get(e),n=co.has(e)?function(e,t){let n=new Map,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=fo.get(e);return void 0===t&&fo.set(e,t=++po),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:ho(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 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 lt){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)||uo({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&uo({type:"state:binding-added",...r});mo.set(e,n)}function yo(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function bo(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,wo=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!==uo&&uo({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(co.has(e))return;co.add(e),uo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),go(e)}else"disconnected"===t&&(co.delete(e),go(e),uo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function $o(e,t,n,r,i,s){if(null===uo)return;let o=ho(e,t,0===t.n?null:n),l=wo.get(e);void 0===l&&wo.set(e,l=new Set),l.add(o),s&&uo({type:"state:write",absoluteAddress:o,value:i,oldValue:r,hasOldValue:!0})}function ko(e){if(null===uo)return;let t=wo.get(e);wo.delete(e),void 0!==t&&uo({type:"state:update-batch",addresses:t}),go(e)}function So(e,t,n){uo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var No={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Ao(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...No["*"],...Object.hasOwn(No,e)?No[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)g.has(t.name)||(g.add(t.name),t.install())}([vn,ur,Lr,zr,Qi,hs,lo,{name:"devtools",install(){c.element=h(c.element,_o),c.re=h(c.re,$o),c.me=h(c.me,ko),c.Ye=h(c.Ye,So),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[ao]??(e[ao]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let 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:ds,getStateElements:()=>[...co].map(bo),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}(yo(e)),keys(e){let t=yo(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return yo(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){yo(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(e){let t=null===uo&&null!==e;uo=e,null===e&&(mo=new WeakMap),c.at=e&&((e,t)=>uo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of co)go(e)})}})}()}},{name:"native-commands",install(){c.or=Ao}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Wt]&&(e[Wt]={protocol:"wcs-binder",version:1,bind:Ft})})(),Zt().includes(e)||Yt.push(new WeakRef(e));let t=re.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),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"},Co=!1,xo=[".html"];function To(){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 Po(e,t){if(t&&"cause"in t)throw new Error(`[@wcstack/router] ${e}`,{cause:t.cause});throw new Error(`[@wcstack/router] ${e}`)}let Oo=class extends Error{fallbackPath;constructor(e,t){super(e),this.fallbackPath=t}};const Mo={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 Lo(e){const t={};for(const[n,r]of new URLSearchParams(e))t[n]=r;return Object.freeze(t)}function Io(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 jo={static:2,param:1,"catch-all":0};let Ro=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&&Po(`${Eo.route} is relative but has no parent route.`),!this.isRelative&&this._parentCore&&Po(`${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+=jo[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(Mo).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||Po(`${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:Lo(e.search??""),routeName:e.routes[e.routes.length-1]?.name??""})}(e));if("string"==typeof r&&""!==r)throw new Oo("Navigation cancelled by guard.",r);if(!r)throw new Oo("Navigation cancelled by guard.",this._guardFallbackPath);return"object"==typeof r?r:null}if(this._hasGuard&&this._guardHandlerLoadFailed)throw new Oo("Navigation cancelled: guard handler failed to load.",this._guardFallbackPath);return null}};const Ho="data-wcs-ssr",Wo="data-wcs-ssr-link",Uo="@@wcs-route-ph:",Do="@@wcs-route-start:",zo="@@wcs-route-end:";let Fo=class extends HTMLElement{_core;_routeParentNode=null;_routeChildNodes=[];_routerNode=null;_uuid=To();_placeHolder=document.createComment(`@@route:${this._uuid}`);_childNodeArray;_endMarker;held=null;_childIndex=0;_initialized=!1;_routes;constructor(){super(),this._core=new Ro(this)}get routeParentNode(){return this._routeParentNode}get routeChildNodes(){return this._routeChildNodes}get routerNode(){return this._routerNode||Po(`${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):Po(`${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&&Po(`${Eo.route} with fallback attribute must be a direct child of ${Eo.router}.`),e.fallbackRoute&&Po(`${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 qo=Symbol.for("wcstack.trustedTypes.policy"),Bo=Symbol.for("wcstack.trustedTypes.internal"),Go="wcstack";function Ko(){const e=globalThis[qo];return null===e||"object"!=typeof e?null:e}let Vo=!1;function Jo(e){const t=function(){const e=globalThis,t=e[Bo];if(void 0!==t)return t;const n=globalThis.trustedTypes;let r=null;if(n&&"function"==typeof n.createPolicy)try{r=n.createPolicy(Go,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){"function"!=typeof Ko()?.createHTML&&console.error(`[@wcstack/router] Could not create the Trusted Types policy "${Go}". Allow it in the CSP (\`trusted-types ${Go};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,e)}return e[Bo]=r,r}(),n=t?.createHTML;if("function"==typeof n)return n.call(t,e);if(!("trustedTypes"in globalThis))return e;const r=Ko(),i=r?.createHTML;return"function"==typeof i?(Vo||(Vo=!0,console.warn(`[@wcstack/router] Falling back to the injected Trusted Types policy to expand a layout template, because the "${Go}" policy could not be created. If that policy sanitizes (e.g. DOMPurify), custom elements in the layout may be stripped. Allow \`trusted-types ${Go};\` in the CSP to avoid this. See docs/csp.md section 7.`)),i.call(r,e)):e}const Qo=new Map;let Xo=class extends HTMLElement{_uuid=To();constructor(){super()}async _loadTemplateFromSource(e){try{const t=await fetch(e);t.ok||Po(`${Eo.layout} failed to fetch layout from source: ${e}, status: ${t.status}`);const n=await t.text();return Qo.set(e,n),n}catch(t){Po(`${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)Qo.has(e)?n.innerHTML=Jo(Qo.get(e)||""):n.innerHTML=Jo(await this._loadTemplateFromSource(e)||"");else if(t){const e=this._loadTemplateFromDocument(t);e?n.innerHTML=Jo(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")&&Co}get name(){return this.getAttribute("name")||""}},Yo=class extends HTMLElement{_routesNode=null;_lastRoutes=[];_initialized=!1;constructor(){super()}get routesNode(){return this._routesNode||Po(`${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")&&Co}_initialize(){this._resolveEnableShadowRoot()&&this.attachShadow({mode:"open"}),this._initialized=!0}connectedCallback(){this._initialized||this._initialize()}disconnectedCallback(){this._lastRoutes=[]}};const Zo=new Set(["props","states","attr",""]);function el(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 tl(e,t){e.hasAttribute("data-bind")||Po(`${e.tagName} has no 'data-bind' attribute.`);const n=e.getAttribute("data-bind")||"";Zo.has(n)||Po(`${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&&el(e,t,r)}).catch(()=>{Po(`Failed to define custom element: ${i}`)}):el(e,t,r)}const nl=Symbol.for("wcstack.binder");function rl(){const e=globalThis[nl];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}const il=Symbol.for("wcstack.binder.pending"),sl=Symbol.for("wcstack.binder.taken");function ol(){const e=globalThis;let t=e[sl];return void 0===t&&(t=new WeakSet,e[sl]=t),t}function ll(e,t){const n=rl();return null===n?(function(){const e=globalThis;let t=e[il];return void 0===t&&(t=[],e[il]=t),t}().push(e),!1):(ol().add(e),n.bind(e,t),!0)}const al={range:!0};function ul(e,t){for(const n of e.routeChildNodes)t.add(n.placeHolder).add(n.endMarker),ul(n,t);return t}function cl(e){const t=e.placeHolder,n=e.endMarker,r=null!==n.parentNode&&n.parentNode===t.parentNode&&!!(4&t.compareDocumentPosition(n)),i=r?null:ul(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 hl=new WeakSet;function dl(e){const t=Eo.router,n=Eo.outlet;for(const r of e.querySelectorAll(n))hl.has(r)||r.previousElementSibling?.matches(t)||(hl.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 fl=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 pl(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 ml extends HTMLElement{_layout=null;_initialized=!1;_initializing=!1;_disconnectedDuringInit=!1;_layoutChildNodes=[];constructor(){super()}get layout(){return this._layout||Po(`${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=""]')&&fl(t)&&pl(this),dl(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):fl(i.childNodes)&&pl(this),this.appendChild(t),dl(this)}!function(e){if(null!==rl())for(const t of e)1===t.nodeType&&ll(t,al)}(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=>{tl(t,e)}),t.hasAttribute("data-bind")&&tl(t,e))}}function gl(){return document.createElement(Eo.layoutOutlet)}const yl="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";function bl(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)),Po(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 ${yl}`:`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 ${yl}`}(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 wl(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(),bl(t,e)):console.error(`[@wcstack/router] [wcs/guard-handler-ignored] The <${Eo.guardHandler}> of route "${e.absolutePath}" has no <script type="module">, so the route is not guarded.`);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=gl();r.layout=n,o=r,l=t}}const c=await wl(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 wl(e,e.template.content,null,t)}function $l(e){return!1!==e.checkVisibility?.()}function kl(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=Mo[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)kl(i,t,n,r)}function Sl(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)kl(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 Nl=null,Al=null;function El(){const e=xo;return 0===e.length?null:(Nl===e&&Al||(Nl=e,Al=new RegExp(`\\/[^/]+(?:${e.map(e=>e.replace(/\./g,"\\.")).join("|")})$`,"i")),Al)}function Cl(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 Tl(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 Pl(e){if(null!==e.held)return;const t=cl(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 Ol(e){e.clearParams(),Pl(e)}function Ml(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=>{tl(t,e.typedParams)}),n.hasAttribute("data-bind")&&tl(n,e.typedParams),n.querySelectorAll(Eo.layoutOutlet).forEach(t=>{t.assignParams(e.typedParams)}),n.tagName.toLowerCase()===Eo.layoutOutlet&&n.assignParams(e.typedParams)}}const Ll=new WeakSet;function Il(e){const t=e.placeHolder;null!==t.parentNode&&(Ll.has(e)||null!==e.endMarker.parentNode?(Pl(e),t.after(e.held),e.held=null):t.after(...e.childNodeArray,e.endMarker),Ll.add(e))}const jl=Symbol.for("wcstack.transition-runner");const Rl=new WeakSet,Hl="data-wcs";function Wl(e,t,n){!Rl.has(e)&&function(e){return e.hasAttribute(Hl)||null!==e.querySelector(`[${Hl}]`)}(e)&&(Rl.add(e),function(e){"complete"===document.readyState?e():window.addEventListener("load",e,{once:!0})}(()=>{var r;null!==rl()||(r=e,ol().has(r))||console.warn(`[@wcstack/router] ${t} contains ${Hl} 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 Ul(e){return"AbortError"===e?.name}const Dl=new WeakMap;function zl(e){for(const t of e.childNodeArray)if(1===t.nodeType){if(t.isConnected){if(ll(t,al))continue}else if(null!==rl())continue;Wl(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 Fl(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,Dl.delete(e)}catch(n){if(n instanceof Oo){const r=(Dl.get(e)??0)+1;return r>10?(Dl.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):(Dl.set(e,r),e.connectedCallbackPromise.catch(()=>{}).then(()=>e.replace(n.fallbackPath)).catch(e=>{Ul(e)||console.error("Fallback navigation failed:",e)}),!1)}throw n}return!0}async function ql(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=Sl(e,s);o||(e.fallbackRoute?o={routes:[e.fallbackRoute],params:{},typedParams:{},path:s,lastPath:r}:Po(`${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 Fl(e,t))return!1;r?.();const i=new Set(t.routes),s=new Set(n),o=()=>{for(const e of n)i.has(e)||Ol(e);const e=[];for(const n of t.routes)(e.length>0||!s.has(n)||n.shouldChange(t.params))&&(e.push(n),Ml(n,t));let r=!1;for(const t of e){const e=s.has(t);e&&r||Il(t),r||=e,n.length>0&&!e&&zl(t)}};let l;return 0===n.length?o():l=function(e,t,n){const r=function(e){const t=globalThis[jl];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($l(e))return e}else for(const t of e.querySelectorAll("h1,h2,h3,h4,h5,h6"))if($l(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 Bl(){const e=window.navigation;return e?"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener?null:e:null}function Gl(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 Kl(e){return"?"===e?"":e}function Vl(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 Jl=new WeakMap;function Ql(e,t,n){const r=function(e,t){let n=Jl.get(e);return void 0===n&&(n=new Map,Jl.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 Xl(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const Yl=Object.freeze({});class Zl 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=Yl;_typedParams=Yl;_searchParams=Yl;_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 Cl(e)}_normalizeBasename(e){return Tl(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){Ql(this,"basename",e)}get leaveConfirm(){return this.getAttribute("leave-confirm")||null}set leaveConfirm(e){Ql(this,"leave-confirm",e),this._syncBeforeUnload()}_onBeforeUnload=e=>{null===this.leaveConfirm||this._unloadConfirmed||e.preventDefault()};_syncBeforeUnload(){const e=this.isConnected&&null!==this.leaveConfirm&&!Xl();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 Zl&&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||dl(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||Po(`${Eo.router} has no outlet.`),this._outlet}get template(){return this._template||Po(`${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=Lo(e.search),s=e.data??null,o=this._data!==s,l=!Io(this._params,n),a=this._routeName!==e.routeName,u=!Io(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=>{Ul(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=>{Ul(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=Gl(e),r=""!==n.pathname||""===n.search&&""===n.hash?this._joinInternalPath(this._basename,n.pathname):window.location.pathname,i=r+Kl(n.search)+n.hash;if(null!==this.leaveConfirm&&(await Promise.resolve(),!this._confirmLeave(r)))return;const s=Bl();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 ql(this,this.outlet,e,this._path,Kl(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)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 ql(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 ql(this,this.outlet,e,this._path,window.location.search||""),this._notifyLocationChange())};async _initialize(){this._initializing=!0;try{const e=Xl();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||Po(`${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||Po(`${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(Ho);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&&Po(`${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(Ho);const e=this._outlet.rootNode;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(i)}await ql(this,this.outlet,o,this._path,window.location.search||""),(s||null!==rl())&&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(Uo)){const r=t.slice(15);if(i.has(r)||!n.has(r))return!1;i.set(r,e)}else if(t.startsWith(Do)){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=Sl(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(Do)){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(Ho);for(const e of h.routes)Ml(e,h);return this.outlet.lastRoutes=h.routes,!await Fl(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=Sl(this,t),r=n?.routes??(null!==this._fallbackRoute?[this._fallbackRoute]:[]);if(0===r.length&&Po(`${Eo.router} No route matched for path: ${t}`),!r.some(e=>e.hasGuard)){await ql(this,this.outlet,e,this._path,window.location.search||""),this._offerInitialContentToBinder(),this._forEachRoute(e=>{e.placeHolder.data=`${Uo}${e.absolutePath}`}),this.outlet.setAttribute(Ho,"");for(const e of this.outlet.lastRoutes)e.placeHolder.after(document.createComment(`${Do}${e.absolutePath}`))}}_offerInitialContentToBinder(){for(const e of this.outlet.lastRoutes)for(const t of e.childNodeArray)t.nodeType===Node.ELEMENT_NODE&&t.isConnected&&ll(t,al)}_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)for(const t of n){const n=t.name;if(!Object.prototype.hasOwnProperty.call(e,n))continue;if(!Vl(e,n))continue;const r=e,i=r[n];delete r[n],r[n]=i}}(this),this._syncBeforeUnload(),Xl()){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=Bl();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&&(Bl()?.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 ea=["title","rel","target","download","hreflang","lang","dir"];class ta extends HTMLElement{static get observedAttributes(){return["to","match",...ea]}_childNodeArray=[];_uuid=To();_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;Po(`${Eo.link} is not connected to a router.`)}_initialize(){Xl()||(this.style.display="none"),this._childNodeArray=Array.from(this.childNodes),this._path=this.getAttribute("to")||"",this._initialized=!0}_normalizePathname(e){return Cl(e)}_joinInternalPath(e,t){const n=Tl(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}=Gl(t),s=""===n?window.location.pathname:this._joinInternalPath(this.router.basename,n);e.href=s+Kl(r)+i}else try{e.href=new URL(t).toString()}catch{Po(`[${Eo.link}] Invalid URL in 'to' attribute: ${t}`)}else e.removeAttribute("href")}connectedCallback(){Xl()?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(Wo)?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(Wo),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-")||ea.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,Xl())return this._updateActiveState(),void n.setAttribute(Wo,"");Bl()?.addEventListener("currententrychange",this._updateActiveState),window.addEventListener("wcs:navigate",this._updateActiveState),window.addEventListener("popstate",this._updateActiveState),""!==this._path&&!this._isInternalTarget(this._path)||Bl()?.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(){Bl()?.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(ea.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}=Gl(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 na=[],ra=new Map;let ia=!1;const sa=new WeakMap;class oa extends HTMLElement{_initialized=!1;_childElementArray=[];constructor(){super()}_initialize(){if(!this._initialized&&(this._initialized=!0,this._childElementArray=Array.from(this.children),!Xl())){this.style.display="none";for(const e of this._childElementArray)this.removeChild(e)}}connectedCallback(){this._initialize(),ia||(this._captureInitialHead(),ia=!0),na.push(this),this._reapplyHead()}disconnectedCallback(){const e=na.indexOf(this);-1!==e&&na.splice(e,1),this._reapplyHead()}get childElementArray(){return this._initialized||Po("Head component is not initialized yet."),this._childElementArray}_getKey(e){const t=sa.get(e);if(void 0!==t)return t;const n=this._computeKey(e);return sa.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);ra.has(e)||ra.set(e,t.cloneNode(!0))}}_reapplyHead(){const e=new Set;for(const t of na)for(const n of t._childElementArray)e.add(this._getKey(n));for(const t of ra.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=na.length-1;t>=0;t--){const r=na[t];for(const t of r._childElementArray)if(this._getKey(t)===n){e=t.cloneNode(!0);break}if(e)break}!e&&ra.has(n)&&(e=ra.get(n).cloneNode(!0));const r=t.get(n)??null;e?(r?r.replaceWith(e):document.head.appendChild(e),t.set(n,e),ll(e)||Wl(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,Xo),e.get(Eo.layoutOutlet)||e.define(Eo.layoutOutlet,ml),e.get(Eo.outlet)||e.define(Eo.outlet,Yo),e.get(Eo.route)||e.define(Eo.route,Fo),e.get(Eo.router)||e.define(Eo.router,Zl),e.get(Eo.link)||e.define(Eo.link,ta),e.get(Eo.head)||e.define(Eo.head,oa)}(void 0);const la="data-fetchtarget",aa={fetch:"wcs-fetch",fetchHeader:"wcs-fetch-header",fetchBody:"wcs-fetch-body",infiniteScroll:"wcs-infinite-scroll"};let ua=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 ha=new Map([["web.fetch",{probe:()=>"function"==typeof globalThis.fetch,compatKey:"api.fetch"}],["web.abort-controller",{probe:()=>"function"==typeof globalThis.AbortController,compatKey:"api.AbortController"}]]),da=new Set(["GET","HEAD","OPTIONS"]);let fa=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 ua("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}}(ha,{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||da.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 ma(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${la}]`);if(!n)return;const r=n.getAttribute(la);if(!r)return;const i=customElements.get(aa.fetch),s=document.getElementById(r);if(!(i&&s instanceof i))return;const o=s;o.url&&(e.preventDefault(),o.fetch())}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 ya=new WeakMap;function ba(e,t){let n=ya.get(e);return void 0===n&&(n=new Map,ya.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function va(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function wa(e,t,n){const r=ba(e,t);va(e,t,void 0===n?r:null===n?null:String(n))}const _a=Symbol.for("wcstack.trustedTypes.policy");function $a(){const e=globalThis[_a];return null===e||"object"!=typeof e?null:e}let ka,Sa=!1;let Na=class extends HTMLElement{static hasConnectedCallbackPromise=!0;static hasPendingPromise=!0;static wcBindable={...fa.wcBindable,properties:[...fa.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;_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 fa(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=ba(e,t);va(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;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(aa.fetchHeader);for(const n of t)n.hasHeader&&(e[n.headerName]=n.headerValue);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(aa.fetchBody);return t?{body:t.bodyContent||null,contentType:t.contentType}:{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?.()}))}_warnUnsafeAutoFetch(){const e=this.method;"GET"!==e&&"HEAD"!==e&&"OPTIONS"!==e&&null===this._body&&null===this.querySelector(aa.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;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=$a(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(t)}catch(e){if(function(){if(void 0!==ka)return ka;if(!("trustedTypes"in globalThis))return ka=!1,ka;try{document.createElement("div").innerHTML="<i></i>",ka=!1}catch{ka=!0}return ka}())return void function(){if(Sa)return;Sa=!0;const e="function"==typeof $a()?.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)for(const t of n){const n=t.name;if(!Object.prototype.hasOwnProperty.call(e,n))continue;if(!ga(e,n))continue;const r=e,i=r[n];delete r[n],r[n]=i}}(this),this.style.display="none",pa||(pa=!0,document.addEventListener("click",ma)),!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 Aa 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")}}class Ea extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}get contentType(){return this.getAttribute("type")||"application/json"}get bodyContent(){return this.textContent?.trim()||""}}class Ca 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 Na?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] <${aa.infiniteScroll} target="${this.target}"> came into view, but no <${aa.fetch}> has that id, so no page was loaded.`))}}!function(e=customElements){e.get(aa.fetch)||e.define(aa.fetch,Na),e.get(aa.fetchHeader)||e.define(aa.fetchHeader,Aa),e.get(aa.fetchBody)||e.define(aa.fetchBody,Ea),e.get(aa.infiniteScroll)||e.define(aa.infiniteScroll,Ca)}(void 0);const xa="data-storagetarget",Ta={storage:"wcs-storage"},Pa="wcs-storage:value-changed",Oa="wcs-storage:loading-changed",Ma="wcs-storage:error",La="wcs-storage:error-info-changed",Ia="wcs-storage:trigger-changed";let ja=class extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:Pa,semantics:"state",getter:e=>e.detail},{name:"loading",event:Oa,semantics:"state"},{name:"error",event:Ma,semantics:"state"},{name:"errorInfo",event:La,semantics:"state"}],inputs:[{name:"key"},{name:"type"}],commands:[{name:"load"},{name:"save"},{name:"remove"}]};_target;_value=null;_loading=!1;_error=null;_errorInfo=null;_key="";_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)}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(Oa,{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(Ma,{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent(La,{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(Pa,{detail:e,bubbles:!0}))}load(){if(!this._key)return this._setError({operation:"load",message:"key is required."}),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){this._setLoading(!0),this._setError(null);try{const t=this._getStorage();null==e?(t.removeItem(this._key),this._setValue(null)):"string"==typeof e?(t.setItem(this._key,e),this._setValue(e)):(t.setItem(this._key,JSON.stringify(e)),this._setValue(e)),this._setLoading(!1)}catch(e){this._setError(this._toStorageError("save",e),this._errName(e)),this._setLoading(!1)}}else this._setError({operation:"save",message:"key is required."})}remove(){if(this._key){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)}}else this._setError({operation:"remove",message:"key is required."})}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)}},Ra=!1;function Ha(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${xa}]`);if(!n)return;const r=n.getAttribute(xa);if(!r)return;const i=customElements.get(Ta.storage),s=document.getElementById(r);i&&s instanceof i&&(e.preventDefault(),s.save())}function Wa(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 Ua=new WeakMap;function Da(e,t){let n=Ua.get(e);return void 0===n&&(n=new Map,Ua.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function za(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Fa(e,t,n){const r=Da(e,t);za(e,t,void 0===n?r:null===n?null:String(n))}class qa extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...ja.wcBindable,properties:[...ja.wcBindable.properties,{name:"trigger",event:Ia,semantics:"state"}],inputs:[{name:"key"},{name:"type"},{name:"value"},{name:"manual"},{name:"trigger"}]};static get observedAttributes(){return["key","type"]}_core;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new ja(this),this._internals=this._initInternals(),this._wireStates({[Oa]:e=>({loading:!0===e}),[Ma]: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")||""}set key(e){Fa(this,"key",e)}get type(){return"session"===this.getAttribute("type")?"session":"local"}set type(e){Fa(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] <${Ta.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=Da(e,t);za(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(Ia,{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&&("key"===e&&(this._syncCore(),n&&!this.manual&&this.load()),"type"===e&&(this._checkType(),this._syncCore()))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0!==n)for(const t of n){const n=t.name;if(!Object.prototype.hasOwnProperty.call(e,n))continue;if(!Wa(e,n))continue;const r=e,i=r[n];delete r[n],r[n]=i}}(this),this.style.display="none",this._checkType(),Ra||(Ra=!0,document.addEventListener("click",Ha)),!this.manual&&this.key&&this.load(),this._syncCore(),this._core.startSync()}disconnectedCallback(){this._core.stopSync()}}!function(e=customElements){e.get(Ta.storage)||e.define(Ta.storage,qa)}(void 0);const Ba="*",Ga="vanilla",Ka={loaders:{[Ga]:{postfix:".js",loader:async function(e){return(await(import(`${e}`))).default}},[Ba]:Ga},observable:!0,tagNames:{autoloader:"wcs-autoloader"}};function Va(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 Ja(e,t,n){let r;if(null===t||t===Ba||""===t){let t=null;const i=[];for(const[e,t]of Object.entries(n)){if(e===Ba)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[Ba],"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 Qa=new Set,Xa=new Map;let Ya=new WeakMap;function Za(e){if(e===globalThis.customElements)return Xa;let t=Ya.get(e);return void 0===t&&(t=new Map,Ya.set(e,t)),t}const eu=new Map;async function tu(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 eu)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){Qa.has(t)||(console.error(`Failed to eager load component '${t}':`,e),Qa.add(t))}}function nu(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 ru(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&&eu.set(e,t)});const iu=new WeakSet,su=new WeakSet;async function ou(e,t,n){e.shadowRoot&&(iu.has(e)||await async function(e,t,n){iu.add(e),await cu(e.shadowRoot,t,n)}(e,t,n))}async function lu(e,t,n,r){const i=function(e,t){for(const[n,r]of Object.entries(t))if(e.startsWith(n+"-"))return r;return null}(e.name,n);if(null===i)throw new Error("No matching namespace found for lazy loaded component: "+e.name);const s=Za(r),o=s.get(e.name);if(void 0!==o)return void await o;const l=async function(e,t,n,r){try{let i;try{i=Ja("",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),Qa.add(e.name)}}(e,t,i,r);s.set(e.name,l);try{await l}finally{s.delete(e.name)}}async function au(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=ru(e);void 0===r.get(i.name)?(su.has(e)||(su.add(e),r.whenDefined(i.name).then(async()=>{await ou(e,t,n)})),l.has(i.name)||Qa.has(i.name)||(l.add(i.name),o.push(i))):await ou(e,t,n)}let a=0;for(const e of o)await lu(e,t,n,r),a++;return a}async function uu(e,t,n,r){for(;await au(e,t,n,r)>0;);}async function cu(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 nu(t)}return nu(globalThis.customElements)}(e);if(null===r)return console.error("Cannot autoload components: the root has a null custom element registry."),null;try{await uu(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 uu(e,t,n,r)}catch(e){console.error("Failed to lazy load components: "+e)}});return i.observe(e,{childList:!0,subtree:!0}),i}class hu extends HTMLElement{static _instance=null;_initialized=!1;_prefixMap=null;_observer=null;constructor(){if(super(),hu._instance)throw new Error(`${Ka.tagNames.autoloader} can only be instantiated once.`);hu._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=Va(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=Ja(i.key,i.loaderKey,t)}catch(e){throw new Error("Loader redirection is not supported for eager loaded components: "+r)}n.push(tu(i,r,s))}await Promise.all(n)}(n,Ka.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 cu(document,Ka,this._prefixMap)))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,hu._instance===this&&(hu._instance=null)}}!function(e=customElements){e.get(Ka.tagNames.autoloader)||e.define(Ka.tagNames.autoloader,hu)}(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.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=[]){return c.Mo?.(e,t)??`#${e}${t.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function _(e,t,n,r){w(v(e,t),n,r)}var $=class{constructor(e){this.kt=new Set,this.name=e}get size(){return this.kt.size}subscribe(e){return this.kt.add(e),()=>{this.kt.delete(e)}}unsubscribe(e){return this.kt.delete(e)}emit(...e){let t=[];for(let n of this.kt)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${v(17,[this.name])}`,e)}return t}};function k(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 S=Symbol.for("wcstack.transition-runner");function N(e){let t=globalThis[S];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function A(e,t,n){let r=N(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var C="else",E="eventToken",x="class",T="attr",P=/^\$[1-9]\d{0,2}$/,O=/^[+-]?(\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:O.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 L=e=>e.trim();function I(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 j=(e,t)=>I(e,t)[0]??-1;function R(e,t){let n=[],r=0;for(let i of I(e,t))n.push(e.slice(r,i)),r=i+1;return n.push(e.slice(r)),n}function H(e,t,n){let r=j(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=j(e,"("),i=(e=>I(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,...M(e.substring(n+1,i))}})}(R(i,"|").map(L),t,e),n.set(i,s)),[e.slice(0,r).trim(),s]}var W=new Map;function U(e){_(1101,[e])}function D(e){let[t,n]=H(e,"output",W);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("**")&&U(e);let t=e.split(".").length;t>512&&_(117,[e,t])}(r),{Ze:r,et:n}}var F=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],z=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function q(e){return e.includes("**")&&U(e),e}var B=0;function G(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var K=()=>new Set,V=()=>[],J=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function X(e,t){return e===t||e!=e&&t!=t}function Y(e,t,n){let r=e._?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e._.delete(t)}function Z(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ee(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function te(e,t,n){let r=ee(e,n);return null!==r&&r.l.o===t.h[n]?r:null}var ne=class{constructor(e,t){this.Le=0,this.d=null,this.Be=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.St=[],this.Me=null,this.qn=[],this.Ht=0,this.X=null,this.oe=new Map,this.ue=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.j=0,this.qt=0,this.yn=!1,this.Kt=!1,this.zt=!1,this.Ce=0,this.Kn=()=>{this.j=0,this.yn=!1},this.zn=()=>{this.Ce--},this.rp=null,this.rr=null,this.Wo=()=>this.Yt(),this._o=(e,t)=>e(this.proxy,...t),this.Yn=[],this.He=[],this.Xn={$untracked:e=>{let t=this.X;if(null===t)return e();t.be++;try{return e()}finally{t.be--}},$eqIndex:(e,t=1)=>{let n=ee(this.d,t);null===n&&_(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,ee(this.d,n.n)))},$dependOn:e=>{this.resolve(q(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=q(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(q(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.P[n.y],J.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(q(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("**")&&U(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(P.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=G(this.Ut,t,V);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)Y(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?te(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=te(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?Z(this.target,e.z):null===t?void 0:Z(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.be&&this.Jn(e,t,n),null!==e.getter)return this.T.Uo(this,e,t);if(e.ae){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.tt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&_(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&&ee(t,Math.min(e.n,r.n))!==ee(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=++B,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:P.test(e)?+e.slice(1):0;return(n<1||n>128)&&_(1001,[e]),this.watchIndex(n),ee(this.d,n)?.y}let n=this.Xn[e];if(void 0!==n)return n;switch(e){case"$stateElement":return this.element;case"$command":return this.commands}return c.rt?.(this,e)}eq(e,t){this.resolve(e,this.d);let n=this.rp,r=this.rr;if(null!==n.getter||n.ae||n.n>0)return X(this.read(n,r),t);let i=this.X;return null!==i&&0===i.be&&this.Yo(n,t,i),X(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(X(o.key,t))return void(o.de=n.de);o.de!==n.de&&(Y(e,o.key,o.sub),s.splice(i--,1))}}let o={getter:r,r:i};G(e._??=new Map,t,K).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=Z(t,o),a=Z(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):Y(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,J.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=J.get(e);if(void 0===t){let n=new Set;J.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 F)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)(!z.includes(e)||"boolean"!=typeof n[e])&&_(44,["$behavior",e]);let[r,i,s]=z.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 k(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new $(r);return Object.freeze(n)}(e,this.commands),l=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new $(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=ee(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?G(this.ue,e.o,K).add(e):(t.we??(t.we=[])).push(e)}Rn(e){let t=e.r;if(null===t)return void this.ue.get(e.o)?.delete(e);let n=t.we;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.ve())}ve(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Pn(){for(let e of this.We)e.te=!1;for(let e of this._e)e.te=!1;for(let e of this.Ve)e.Lt=!1;this.We=[],this._e=[],this.Ve=[],this.T.tt(this)}po(e,t){let n=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${v(e)}`,n),c.at?.(this,{type:"state:render-chain-limit",maxDepth:t,paths:n}),this.Pn()}Yt(){this.Et=!1;let e=this.qt;this.qt=0;let t=0;if(!this.Kt||this.zt?this.Kn():e>0?t=e:1===(t=++this.j)&&setTimeout(this.Kn,0),this.Kt=this.zt=!1,t>100)101===t?this.po(41,100):this.Pn();else{this.gn=!0;try{for(let e=0;this.We.length>0||this._e.length>0||this.Ve.length>0;e++){if(e>=32){this.yn?this.Pn():this.po(11,32),this.yn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Lt=!1,this.oo(e)}let 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)?A("state",s):s();void 0!==o&&o.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.Kt=this.zt=!1,this.ze(),c.me?.(this),this.zo(),e>0&&this.Et&&(this.qt=t+1)}}xt(e,t){this.St.push([e,t])}Jt(e,t,n,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=G(this.Me,e.t,V);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){console.error(e)}Q(t)?t.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.St.length)return;let t=this.St;this.St=[];let n=this.target.$errorCallback;for(let[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}]);Q(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${v(12,i.name?[s,t,i.name,i.i]:[s,t])}`,r,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=te(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])}},re={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"},ie=new Map,se=new Set(["if","elseif","else","for"]),oe=new Set([C,"if","elseif","for","..."]),le=new Set([x,T,"style","command",E,"state"]);function ae(e){let t=function(e){return R(e,";")}(e).map(L).filter(e=>e.length>0).map(e=>{let t=j(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(oe.has(i)){let t;return i!==n&&_(102,[e,i]),i===C?(r.length>0&&_(103,[e]),t={Ze:"#else",et:[]}):"..."===i?(0===r.length&&_(104,[e]),t=D(r),t.et.length>0&&_(105,[e])):(t=D(r),"for"===i&&t.et.length>0&&_(121,[e])),{$e:i,Ne:[i],rn:[],D:[],...t,b:"..."===i?"spread":i}}(i===x||i===T)&&_(122,[e,i]);let s=D(r),o=function(e){let[t,n]=H(e,"input",ie),r=t.split("#").map(L);r.length>2&&_(115,[t]);let[i,s]=r,o=i.split(".").map(L);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(L):[],D:n}}(n),[l]=o.Ne;if(""===l&&o.Ne.length>1){let e=o.Ne.slice(1);return(e.includes("")||le.has(e[0]))&&_(106,[n]),{...o,$e:e.join("."),Ne:e,...s,b:"prop"}}return{...o,...s,b:"radio"===i||"checkbox"===i?i:l===E||l.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>se.has(e.b))&&_(201,[e]),t}var ue=["toFixed","locale","upper","lower","capitalize","trim","slice","padStart","padEnd","repeat","reverse","truncate","join","round","floor","ceil","percent","unit","date","time","datetime","ymd","hms","add","sub","mul","div","mod","abs","clamp","int","float","defaults","coalesce","number","string","nullIfEmpty","currency"],ce=new Map,he=new Map;function de(e){for(let t of Object.keys(e))ce.set(t,{...e[t]});he.clear()}function fe(e){return ce.has(e)}function pe(e){_(26,[e])}function me(e){_(27,[e])}function ge(e,t){_(28,[e,t])}function ye(e,t){_(29,[e,t])}function be(e){return!(!e||isNaN(Number(e)))}function we(e,t){return be(e)||me(t),Number(e)}function ve(e,t,n){return we(e?.[t]??pe(n),n)}function _e(e,t){return void 0!==t&&t.length>0?t[0]:e}var $e=(e,t)=>({factory:n=>{let r=ve(n,0,e);return n=>("number"!=typeof n&&ge(e,n),t(n,r))},arity:[1,1]}),ke={eq:{factory:(e,t)=>{let n=e?.[0]??pe("eq"),r=_e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(be(n)||me("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??pe("ne"),r=_e(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(be(n)||me("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:$e("lt",(e,t)=>e<t),le:$e("le",(e,t)=>e<=t),gt:$e("gt",(e,t)=>e>t),ge:$e("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Se=!1;function Ne(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ae(e){return 0===e.length?null:(Se||(Se=!0,de(ke)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,i=he.get(r);if(typeof i<"u")return i;let s=ce.get(e);void 0===s&&function(e,t){ue.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,ce.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 he.set(r,a),a}(e.Hn,e.args,e.literals)))}var Ce=Symbol.for("wcstack.trustedTypes.policy");function Ee(){let e=globalThis[Ce];return null!==e&&"object"==typeof e?e:null}function xe(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Te(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Ee(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Pe=Symbol.for("wcstack.state.view-transition-naming"),Oe=new WeakSet;function Me(){let e=N("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var Le=new WeakMap,Ie=e=>e.customElementRegistry??customElements;function je(e,t,n,r,i,s=!1){let o=n.localName;if(!o.includes("-"))return i(null);let l=Ie(n);if(!s&&!n.isConnected&&void 0===l.get(o)&&"customElementRegistry"in n)return void queueMicrotask(()=>je(e,t,n,r,i,!0));let a=()=>{let e=l.get(o);l.upgrade(n),i(e?function(e){if(Le.has(e))return Le.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 Le.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){Fe(e,r,t,n)}e.ve()})}function Re(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 Be(e,Ue,n,r,i,s,o,t.x,void 0);p.D=t.D,Ze(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=Ne(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 He(e,t,n){_(e,[t.localName,n])}var We=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Ue=11,De=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Fe=(e,t,n,r)=>e.Jt(t,n.o?.t??n.Pt,r,De[n.i]),ze=Symbol();function qe(e,t,n){let r=t.U;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.q:ze}var Be=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 De[this.i]}apply(){if(null!==this.j)return void this.j.Nt();let e=Ne(this.x,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Ue||8===this.i||xe(this.name)))return;if(this.value===ze)return void(this.value=e);let t=this.a;if(this.i!==Ue)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Ke(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.An=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.An=!1}}}sn(){return Ne(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=Ne(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 Ke(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?Te(r):null==r?"":String(r):xe(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Te(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Ve]=[n,r])));case 8:return void(t.innerHTML=Te(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 Ve=Symbol();function Je(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Ve];void 0!==n&&(t[n[0]]=n[1])}var Qe=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=at(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():ut(this.Re(),this.s)}Pe(e){if(this.w=!1,null!==this.Rt)for(let e of this.Rt)e();let t=this.we;if(null!==t)for(let n=0;n<t.length;n++)e.Rn(t[n]);if(null!==this.u)for(let e of this.u)e.Pe()}},Xe=class extends Qe{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 Be(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 Ye(e,t,n,r){let i=ee(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 Ze(e,t,n){n&&e.nr(t);let r=t.Tn;null!==r&&(r.we??=[]).push(t)}var et=null;function tt(){let e=et;return et=null,e}var nt=-1;function rt(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]=at(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 Qe(n,s,u,t),nt>=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||Oe.has(i))return;let o=globalThis[Pe]??={counter:0,assigned:0,warned:!1};o.assigned>=r?o.warned||(o.warned=!0,console.warn(`[@wcstack/state] ${v(25,[r])}`)):(Oe.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",nt),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=Ne(i.x,e.read(i.o,n));t!==i.q&&(Ke(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 lt(e,i.C,Ye(e,i.o,n,o),o);(p.u??=[]).push(t),o===s&&(p.On=t),t.Nt();break}case 7:{let t=st(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{it(e,i,o,n,p)}catch(t){Fe(e,t,i,o)}}}return et=p,f}function it(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 je(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&&He(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 je(e,t,s,i,n=>function(e,t,n,r,i){let s=t.name;null===i&&He(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){console.error(e)}})}(e,t,s,r,n))}let o=t.o,l=ee(r,o.n);if(14===t.i)return void je(e,t,s,i,n=>function(e,t,n,r,i,s){null===s&&He(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;Re(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 je(e,t,s,i,n=>function(e,t,n,r,i,s){if(null!==s)return void Re(e,t,n,t.name,t.o,r,i,s);let o=new Be(e,1,n,t.name,t.o,r,i,t.x,qe(e,t,r));o.D=t.D,!c.ar?.(o,t.ro)&&(Ze(e,o,!0),e.Ke(o))}(e,t,s,l,i,n));let a=new Be(e,t.i,n,t.name,o,l,i,t.x,qe(e,t,l));a.D=t.D,Ze(e,a,!0),e.Ke(a),null!==t.Ft&&n.addEventListener(t.Ft,()=>a.ir())}function st(e,t,n,r){let i=new ot(e,t,n),s=null;for(let o of t){if(null===o.o)continue;let t=o.o,l=new Be(e,7,o.S,"if",t,ee(n,t.n),r,null,void 0,i);Ze(e,l,!0),null===r&&i.ue.push(l),s??=l}return e.Ke(s),i}var ot=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.ue=[],this.engine=e,this.K=t,this.r=n}In(e){return null!==this.I&&this.K[this.y].S===e?this.I.Re():null}Nt(){let e=this.engine,t=-1;for(let n=0;n<this.K.length;n++){let r=this.K[n];if(null===r.o||Ne(r.x,e.read(r.o,ee(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(nt=Me(),null!==this.I&&(this.I.bo(),this.I.Pe(e),this.I=null),this.y=t,t>=0)){let n=this.K[t],r=rt(e,n.C,this.r,null,n.S);this.I=tt();let i=n.S.parentNode;i.insertBefore(r,n.S),Je(i)}}Pe(){this.w=!1;for(let e of this.ue)this.engine.Rn(e);null!==this.I&&this.I.Pe(this.engine)}},lt=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;nt=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):ut(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(rt(e,this.C,n,this),i),u=tt()),l[a+s]=u,i=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(rt(e,this.C,t[r],this)),l[r]=tt();o.insertBefore(n,d)}}this.Ae=l,Je(o)}Pe(){this.w=!1;let e=this.l;if(e.N===this)e.N=null;else if(null!==e.M){let t=e.M.indexOf(this);t>=0&&e.M.splice(t,1),0===e.M.length&&(e.M=null)}for(let e of this.Ae)e.Pe(this.engine);this.map?.clear()}};function at(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function ut(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var ct=()=>re.bindAttributeName;function ht(){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 dt=["state","element","auto","none"],ft=["call","connect"],pt="$command.";function mt(e,t,n){P.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 gt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),yt=e=>8===e.i||gt(e)||1===e.i&&Ge(e.name);function bt(e){_(202,[e])}function wt(e,t,n,r,i){let s=ae(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?dt:ft).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{...ht(),a:i,i:13,name:l.slice(1).join("."),Pt:a,xe:o,Tt:s.Tt,At:s.At};let n=a.startsWith(pt)?a.slice(9):null,{Tt:r,At:u}=s,h=t.$e.slice(2),d=t.rn.includes("direct"),f=!d&&We.has(h);f&&e.co(h);let p=t=>{console.error(t),f&&c.handlerThrew?.(e,a,h)};return{...ht(),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);Q(n)&&n.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===t.b)return{...ht(),a:i,i:14,o:mt(e,a,n),xe:o};if("command"===l[0]&&l.length>1)return a.startsWith(pt)||_(1201,[t.$e,a]),{...ht(),a:i,i:12,name:l.slice(1).join("."),Pt:a,xe:o};let u=mt(e,a,n),h={...ht(),a:i,i:1,name:t.$e,o:u,x:Ae(t.et),D:Ae(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 vt=/\{\{([\s\S]+?)\}\}/g;function _t(e){let t=e.data,n=[],r=0;vt.lastIndex=0;for(let i=vt.exec(t);null!==i;i=vt.exec(t)){let s=vt.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=vt.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function $t(e,t,n,r){let i=function(e){return{$e:"textContent",Ne:["textContent"],rn:[],D:[],...D(e),b:"text"}}(t);return{...ht(),a:r,i:0,o:mt(e,i.Ze,n),x:Ae(i.et),q:""}}function kt(e){let t=e.getAttribute(ct());if(null===t)return null;let n=ae(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var St=(e,t)=>0===e?re.commentIfPrefix:null===t.o?re.commentElsePrefix:re.commentElseIfPrefix;function Nt(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:mt(e,r.Ze,n),x:"else"===r.b?null:Ae(r.et)}),i=[r(t,kt(t))];for(let e=t.nextSibling;null!==e;e=e.nextSibling){if(3===e.nodeType&&""===e.data.trim()||8===e.nodeType)continue;if(1!==e.nodeType||"template"!==e.localName)break;let t=kt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(i.push(r(e,t)),"else"===t.b))break}return i}var At=new WeakSet;function Ct(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(ct()+"-ignore"))continue;if(r){if("script"===l||"style"===l||At.has(t))continue;if(At.add(t),l===re.tagNames.state){u([...t.childNodes]);continue}}let h="template"===l?kt(t):null;if(null!==h){if("for"===h.b){let r=mt(e,h.Ze,n),s=Tt(e,t,r,!0);i(a(t,re.commentForPrefix),r,s)}else"if"===h.b?s(Nt(e,t,n).map((t,r)=>({C:Tt(e,t.el,n,!1),o:t.o,x:t.x,S:a(t.el,St(r,t))}))):bt(h.b);continue}let f=t.getAttribute(ct()),p=null===f?null:wt(e,f,n,t,0),m="noscript"!==l&&"iframe"!==l&&!p?.some(yt)&&!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("{{")&&!At.has(d))for(let{a:e,cr:t}of _t(d))l(e,t);else if(8===d.nodeType){let e=Et.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 Et=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,xt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Tt(e,t,n,r){let i=document.importNode(xt(t),!0),s=[],o=[],l=e=>s.push(e)-1;Ct(e,[...i.childNodes],n,!1,(e,t,n)=>{o.push({...ht(),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({...ht(),a:t[0].a,i:7,K:t})},(e,t)=>{let n=l(e);for(let e of t)gt(e)&&_(203,[e.name]),e.a=n;o.push(...t),e.removeAttribute(ct())},(t,r)=>{o.push($t(e,r,n,l(t)))}),Lt(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&&!Pt(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&&Ot(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 Pt(e,t){for(;e.parentNode!==t;e=e.parentNode){if(e.parentNode.localName.includes("-"))return!0;for(let t=e.previousSibling;t;t=t.previousSibling)if(8===t.nodeType)return!0}return!1}function Ot(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 Mt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function Lt(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&&Lt(r,t,Mt.has(r.localName)),r=e}}var It=new WeakMap;function jt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,It.set(t,e),Ht(e,[...n.childNodes]),e.ze()}function Rt(e,t,n){try{let r="template"===t.localName?kt(t):null;null!==r&&!n&&_(204,[r.b]),Ht(e,[t])}catch(e){console.error(e)}e.ze()}function Ht(e,t){Ct(e,t,null,!0,(t,n,r)=>{new lt(e,r,Ye(e,n,null,t),t).Nt()},t=>{st(e,t,null,null)},(t,n)=>{c.Dn?.(e,t,n);for(let r of n)it(e,r,t,null,null)},(t,n)=>{c.Dn?.(e,t,n),it(e,$t(e,n,null,0),t,null,null)})}var Wt=Symbol.for("wcstack.binder"),Ut=Symbol.for("wcstack.binder.pending"),Dt=Symbol.for("wcstack.binder.taken"),Ft=new Map;function zt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=It.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ft.set(e,t):Rt(n,e,t?.range)}function qt(){let e=[...Ft];Ft.clear();for(let[t,n]of e)zt(t,n);!function(){let e=function(){let e=globalThis[Wt];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;let t=function(){let e=globalThis,t=e[Ut];return void 0===t&&(t=[],e[Ut]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),r=function(){let e=globalThis,t=e[Dt];return void 0===t&&(t=new WeakSet,e[Dt]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Bt=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)}))}},Gt=0,Kt=new WeakMap;function Vt(e,t=e.getRootNode()){Kt.set(t,[...Kt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Jt(e){let t=Kt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Kt.get(e)!==t?Jt(e):Promise.reject(r.errors[0]):void 0)}var Qt=typeof HTMLElement>"u"?class{}:HTMLElement,Xt=class extends Qt{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=Jt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Ln){if(null!==this.Ge)return void this.Ge.Je();Vt(this);let e=this.engine;if(null!==e){let t=e.root;t===this.getRootNode()&&!It.has(t)&&It.set(t,e),qt(),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&&Vt(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),Vt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Bn();let e=this.engine;if(null===e)return;let t=e.root;It.get(t)===e&&It.delete(t),Vt(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] ${v(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?v(42):v(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=It.get(e)?.element;i?.isConnected&&(i.V||i.Ge)&&_(47);let s=new ne(n,new Bt);s.element=this,this.engine=s,c.element?.(s,"mounting"),jt(s,e),qt(),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)]:[]);console.error(`[@wcstack/state] ${v(e,[this.localName,...n])}`,t)}xo(e,t,n){(async()=>this.engine.Ee(e))().then(n,e=>this.ze(t,e))}},Yt=[];function Zt(){return(Yt=Yt.filter(e=>e.deref())).map(e=>e.deref())}var en,tn=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},nn="en";function rn(){if(re.locale!==en){en=re.locale;try{nn=Intl.getCanonicalLocales(en)[0]}catch{console.warn(`[@wcstack/state] ${v(48,[en])}`),nn="en"}}return nn}var sn=["full","long","medium","short"];function on(e,t){let[n,r]=e??[];return void 0===r&&void 0!==n&&sn.includes(n)&&([n,r]=[void 0,n]),void 0!==r&&!sn.includes(r)&&function(e,t){_(52,[e,t])}(t,r),[n,r]}var{eq:ln,ne:an,not:un,lt:cn,le:hn,gt:dn,ge:fn,falsy:pn,truthy:mn,boolean:gn}=ke,yn={toFixed:{factory:e=>{let t=we(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ge("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ge("locale",e),e.toLocaleString(t??rn()))},arity:[0,1]},upper:{factory:tn(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:tn(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:tn(()=>e=>{let t=String(e);return 0===t.length?t:1===t.length?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1)}),arity:[0,0]},trim:{factory:tn(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:tn(e=>{let t=[ve(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(we(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:tn(e=>{let t=ve(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:tn(e=>{let t=ve(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:tn(e=>{let t=ve(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:tn(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:tn(e=>{let t=ve(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,we(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ge("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ge("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,we(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ge("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=we(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ge("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:tn(e=>{let t=e?.[0]??pe("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=on(e,"date"),r=n&&{dateStyle:n};return e=>(e instanceof Date||ye("date",e),e.toLocaleDateString(t??rn(),r))},arity:[0,2]},time:{factory:e=>{let[t,n]=on(e,"time"),r=n&&{timeStyle:n};return e=>(e instanceof Date||ye("time",e),e.toLocaleTimeString(t??rn(),r))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=on(e,"datetime"),r=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||ye("datetime",e),e.toLocaleString(t??rn(),r))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||ye("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:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||ye("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:ln,ne:an,not:un,lt:cn,le:hn,gt:dn,ge:fn,add:$e("add",(e,t)=>e+t),sub:$e("sub",(e,t)=>e-t),mul:$e("mul",(e,t)=>e*t),div:$e("div",(e,t)=>e/t),mod:$e("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ge("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ve(e,0,"clamp"),n=ve(e,1,"clamp");return e=>("number"!=typeof e&&ge("clamp",e),Math.min(Math.max(e,t),n))},arity:[2,2]},int:{factory:()=>e=>parseInt(String(e),10),arity:[0,0]},float:{factory:()=>e=>parseFloat(String(e)),arity:[0,0]},falsy:pn,truthy:mn,defaults:{factory:(e,t)=>{let n=_e(e?.[0]??pe("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=_e(e?.[0]??pe("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:gn,number:{factory:()=>e=>Number(e),arity:[0,0]},string:{factory:()=>e=>String(e),arity:[0,0]},nullIfEmpty:{factory:()=>e=>""===e?null:e,arity:[0,0]},currency:{factory:e=>{let t=e?.[0]??pe("currency"),n=e?.[1],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&&ge("currency",e),e.toLocaleString(n??rn(),r))},arity:[1,2]}},bn=!1,wn={name:"formats",install:function(){bn||(bn=!0,de(yn))}};function vn(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=vn(n,e.toLowerCase(),2);t<i&&(r=e,i=t)}return null!==r?` Did you mean "${r}"?`:""}var $n=" Validate statically: npx @wcstack/lint <file>.",kn=["","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"],Sn=e=>{let t=kn[e/100|0];return t?`[wcs/${t}] `:""},Nn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],An=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Cn=["","","class.","attr.","style."],En=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,xn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Tn={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?(Cn[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 ${An(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 ${An(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&&Nn.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)=>`${En(e,t)} failed to initialize.`,50:(e,...t)=>`${En(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${En(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 Pn(e,t){let n=Tn[e];return void 0===n?`${Sn(e)}#${e} ${t.join(" ")}`:Sn(e)+n(...t)}var On=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Mn=[[/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.']],Ln={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function In(e,t,n){let 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(Ln,e)?Ln[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 Mn){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"].':ue.some(fe)||(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&&On.has(s[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=$n),r}var jn=new WeakMap,Rn=new WeakMap,Hn=new WeakSet,Wn=new WeakSet;function Un(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 Dn(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"$"!==e[0]&&"constructor"!==e&&t.add(e);return[...t]}function Fn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let 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!==Un(e.target,t.t)?.get?t:e.O.wt(o(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:zn(e,n,0,e.target,r)}function zn(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=zn(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=Un(r,s.s);if(void 0===o&&null===s.c&&e.tt.has(s.s))return null;if(void 0===o){let o=Dn(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 qn(e){Hn.has(e)||(Hn.add(e),setTimeout(()=>function(e){Hn.delete(e);let t=jn.get(e);if(void 0===t)return;let n=Rn.get(e);void 0===n&&Rn.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=Fn(e,t);if(null===r)continue;let l=[...e.root?.querySelectorAll(`${re.tagNames.state}[mount]`)??[]].find(e=>!Wn.has(e)&&(t.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==l){n.delete(t),l.initializePromise.then(()=>{Wn.add(l),qn(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."}${$n}`)}}(e),0))}function Bn(e,t,n=!1){Gn(e,t,n?1:0)}function Gn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let r=jn.get(e);void 0===r&&jn.set(e,r=new Map),r.has(t)||r.set(t,n),qn(e)}var Kn=new WeakSet,Vn=!1,Jn=new WeakMap;function Qn(e,t){let n=Jn.get(e),r=t.s;if(null!==t.c||Vn||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(`${re.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}${$n}`)}var Xn=new WeakSet;function Yn(e){if(Xn.has(e))return;Xn.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.${$n}`)),t.apply(e,r))}var Zn=new WeakMap;function er(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Un(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let i=Zn.get(e);void 0===i&&Zn.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/delegated-current-target] "${t}" reads event.currentTarget, the root for a delegated on${n}:. Write on${n}#direct:, or use event.target.closest(…).${$n}`))}function tr(e){jn.has(e)&&e.He.length>0&&qn(e)}var nr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),rr=!1;function ir(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(rr||!(t instanceof TypeError)||!xe(r)||!("trustedTypes"in globalThis))return;rr=!0;let i="function"==typeof Ee()?.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 sr=new WeakMap;function or(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=sr.get(e);void 0===s&&sr.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 lr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],ar={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},ur={name:"diagnostics",install(){c.Bo=In,c.Mo=Pn,c.Eo=Bn,c.detail=or,c.Ye=h(c.Ye,ir);let e=c.fe;c.fe=(t,n)=>{(function(e){void 0!==e.$scan&&_(1);for(let[t,n]of lr)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=Dn(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(`^(?:${nr(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(`^${nr(r)}(?:${nr(l)})*${nr(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){Rn.delete(e),jn.has(e)&&qn(e)}(t),function(e){if(Kn.has(e))return;Kn.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{Vn=!0;try{n(t)}finally{Vn=!1}let r=e.O.wt(o(t).o);void 0!==r&&Gn(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))Yn(t)}})}(t),Jn.set(t,new Set(Dn(n)))},c.handlerThrew=er,c.re=h(c.re,Qn),c.me=h(c.me,tr),c.rt=d(p,c.rt,(e,t)=>Object.hasOwn(ar,t)?_(1701,[t,ar[t]]):void 0)}},cr={},hr=/\.\d/,dr=new Set(Object.getOwnPropertyNames(Object.prototype)),fr=0,pr=!1,mr=null,gr=()=>{pr=!1,fr++};function yr(){if(null===mr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=gr,e.port1.unref?.(),mr=()=>e.port2.postMessage(0)}else mr=()=>setTimeout(gr,0);return pr||(pr=!0,mr()),fr}function br(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 wr=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(cr,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)&&br(vr(e.p),n)&&this.dt(e,null,void 0,!0);this.Fe.size>0&&e.ve()}prime(e,t){try{t()}catch(t){console.error(`[@wcstack/state] $watch initial evaluation of "${e.t}" threw.`,t),c.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:e.t,error:t})}}Oo(){this.active=!1,this.Fe.clear(),this.early=[]}Wn(e,t,n,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??cr):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??cr),!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??cr,l),Object.is(l,s)&&(hr.test(i.t)||null!==t&&!u&&!(o??=null!==e&&br(vr(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){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,e),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=yr();t!==this.Fo&&(this.Fo=t,this.Mn.clear());let n=e.filter(e=>!this.Mn.has(e));if(0!==n.length){for(let e of n)this.Mn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),c.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:n})}}};function vr(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 $r="$streamStatus",kr="$streamError",Sr=new Set(Object.getOwnPropertyNames(Object.prototype)),Nr=!1;function Ar(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 Cr=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Nr=!0;try{this.engine.A(this.engine.o(`${e}.${t}`),null,n)}finally{Nr=!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($r,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();Er(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===`${$r}.${e}`||n.t===`${kr}.${e}`)&&w(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,s,n)}catch(n){Er(s);for(let e of o)e._n(s);if(s.Y=r,t)throw n;return this.set(kr,e.name,n),void this.set($r,e.name,"error")}}let s=new AbortController;e.J=s,i.A(i.o(e.name),null,e.q),this.set(kr,e.name,null),this.set($r,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=yr(),u=e=>{yr()===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($r,e.name,"done"))}catch(n){if(!s())return;e.J=null,t.abort(),u(()=>{this.set(kr,e.name,n),this.set($r,e.name,"error")})}}};function Er(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 Tr(e){let t=xr.get(e);return t?.target===e.target?t:void 0}function Pr(e,t){let n=new wr(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("@")||dr.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 Cr(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)||Sr.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.`),Ar(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[$r]=i,t[kr]=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 Or(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 Mr=["$streamStatus","$streamError"],Lr={name:"temporal",install(){c.fe=h(c.fe,Pr),c.element=h(c.element,Or),c.re=h(c.re,(e,t,n,r,i,s,o)=>Tr(e)?.W.re(t,n,r,i,s,o)),c.Se=h(c.Se,(e,t,n)=>{let r=Tr(e);void 0!==r&&(r.W.Se(t,n),r.Ct.Se(t))}),c.Qt=h(c.Qt,(e,t,n)=>Tr(e)?.W.Qt(t,n)),c.me=h(c.me,e=>{let t=Tr(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(Mr.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),c.Ie=d(f,c.Ie,(e,t)=>(!Nr&&36===t.t.charCodeAt(0)&&Mr.includes(t.t.split(".",1)[0])&&w(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Ir=new WeakMap,jr=!1,Rr=/^(?!prototype$)[^\d.*$][^.*]*$/;function Hr(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.`)}}Ir.set(t,r)}function Wr(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Ur(e,t,n){let r=new Map;for(let i of t){Wr(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 Dr(e,t,n,r){if(jr||!Array.isArray(r))return!1;let i=Ir.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=Ur(t.t,s,i);Ur(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){jr=!0;try{e.A(t,n,l)}finally{jr=!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=Rr.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 Fr={name:"list-keys",install(){c.fe=h(c.fe,Hr),c.Ie=d(f,c.Ie,Dr)}},zr=new WeakMap,qr=new WeakMap,Br="will not graft: the root state failed to initialize.",Gr=new WeakSet,Kr=new WeakMap,Vr=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],Jr=["$commandTokens","$eventTokens","$on","$errorCallback"],Qr=e=>`[@wcstack/state] <${re.tagNames.state} mount="${e}">`,Xr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),Yr=e=>e?.element?.isConnected?e:void 0;function Zr(e){let t=qr.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function ei(e,t){let n=qr.get(t);if(qr.delete(t),Array.isArray(n))for(let t of n)ii(t,e)}function ti(e){let t=zr.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ni(e,t){console.error(`${Qr(e.t)} ${t}`),ti(e),e.Qe?.(),e.Qe=null}function ri(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,e=>console.error(e))}catch(e){console.error(e)}}function ii(e,t){if(Gr.has(t))return ni(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 ni(e,`will not graft: the root state already has "${e.t}".`);let o=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,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)):Xr.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=Kr.get(t);void 0===c&&Kr.set(t,c=[]),c.push(e),e.el.isConnected&&ri(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function si(e,t){let n=qr.get(e);if(Array.isArray(n))for(let e of n)ni(e,Br);qr.set(e,t)}var oi=new WeakMap;function li(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(re.bindAttributeName))i='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=zr.get(t);void 0===e&&zr.set(t,e=new Map);let s=e.get(n);if(void 0!==s&&s!==r&&(null===s.engine?s.el.isConnected:Yr(s.engine)))i=`will not graft: another volume already holds "${n}".`;else{if(null===s?.engine){let e=qr.get(t);Array.isArray(e)&&qr.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 ni(r,i);if(zr.get(t).get(n)===r){for(let t of Vr)if(void 0!==e[t])return ni(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of Jr)void 0!==e[t]&&console.warn(`${Qr(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=Yr(It.get(t)),i=qr.get(t);void 0!==n?ii(r,n):Zr(t)?ni(r,Br):qr.set(t,[...Array.isArray(i)?i:[],r])})}},Je(){null!==r.engine&&ri(r,"$connectedCallback")},Bn(){null!==r.engine&&ri(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 ai=new WeakMap,ui=new WeakMap;function ci(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 hi(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=ci(r,"$bindables"),o=ci(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(re.tagNames.state);return a.set(r,o),ai.set(r,l),null===o&&s.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${re.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 di=new WeakMap,fi=new WeakSet,pi=new WeakMap,mi=new WeakMap,gi="data-wcs-wired",yi=new WeakMap,bi=new WeakMap,wi=new WeakMap,vi=0,_i=new Set,$i={},ki=["$watch","$stream","$renderedCallback"],Si=e=>e.split(".",1)[0];function Ni(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Ai(e,t){let n=e.a,r=Si(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(gi);else if(!Ei(n,r)){let e=n.getAttribute(gi)?.split(" ")??[];e.includes(r)||n.setAttribute(gi,[...e,r].join(" "))}yi.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=di.get(n);void 0===i&&di.set(n,i=[]),i.push(e),t&&fi.add(e);let s=pi.get(n);return void 0===s&&pi.set(n,s=new Map),s.has(r)||s.set(r,n[r]),mi.get(n)?.(),!1}function Ci(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${re.tagNames.state}[bind-component]`)}function Ei(e,t){let n=e.getAttribute(re.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function xi(e){let t=e.parentElement;for(;null!==t&&!Ci(t);)t=t.parentElement;let n=It.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.V:null===t)&&(null===t?zt(e):Rt(n,e))}var Ti=new Set;function Pi(e,t){Ti.has(e)||(Ti.add(e),console.warn(`[@wcstack/state] ${t}`))}var Oi=(e,t)=>t in e.state;function Mi(e,t){let n=Li(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Li(e,t){for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e}}function Ii(e,t,n){if(null!==n.getter)return;let r,i=e.host,s=i.engine,o=Si(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=ji(e,l.r);return 0===t.n?n:(s.resolve(Ni(o.t,[...s.H(n),...i.H(ee(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();Ri(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?Oi(i,o):Mi(i,o))return;r=l.ye}else{if(null===t||null!==n.c||"$"===o[0]||Oi(i,o))return;l=t,r=s.o(`${t.ye.t}.${o}`)}let a=l.r,u=l;n.getter=()=>s.v(r,ji(e,a)),n.se=t=>{Ri(e,u,()=>s.A(r,a,t)),e.dn=n},e.pt.set(n,{e:l,p:r,r:a})}function ji(e,t){return null!==t&&!t.w&&w(`The host row of <${e.host.el.localName}> was removed.`),t}function Ri(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 Hi=(e,t)=>t||!_i.has(e.m.R)||null!==e.m.from&&e.m.from!==e.e;function Wi(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,vi+=t?1:-1;let n=e.host.engine,r=wi.get(n);void 0===r&&wi.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=Si(o);if(o!==a&&!Oi(n,a))continue;let u=r.o(`${t.ye.t}.${o}`);if(null===u.getter)Fi(r,u,t.ye);else if(!Ui.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&&Fi(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;Pi(`${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 Ui=new WeakSet;function Di(e,t,n,r){let i=wi.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 Fi(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=Di(e,n,e.d,t);return null===o?void 0:o.R.read(o.ie.get(t),null)},Ui.add(t.getter),t.se=o=>{let l=null===s()?Di(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===Li(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 zi(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 qi(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 Bi(e,t,n,r,i,s,o){let l=n.t.slice(t.t.length);if(""===l)return qi(e);let a,u=e.m,c=u.R;if(""===e.e.E){a=l.slice(1);let e=Si(a);if("$"===e[0]||Oi(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(ee(r,e).y);c.resolve(Ni(a,h),null);let d=c.rp,f=c.rr;d.n>0&&null===f||zi(c,d,f,i,s,o)}function Gi(e,t,n,r,i,s,o){if(0===vi)return;let l=_i.has(e);_i.add(e);try{let l=bi.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(Ni(o.p.t+t.t.slice(l.t.length),u),null);let c=a.rp,h=a.rr;c.n>0&&null===h||Ri(e,o.e,()=>zi(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=wi.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:ee(n,e.n));if(void 0!==a)for(let l of[...a])Hi(l,o)&&Bi(l,e,t,n,r,i,s)}else if(e.ee(t))for(let[e,r]of[...l])if(0===t.n||ee(e,t.n)===n)for(let e of[...r])Hi(e,o)&&qi(e)}finally{l||_i.delete(e)}}async function Ki(e,t,n,r,i){if(r===$i)return;let s=y(r);s&&await s;let o=yi.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 <${re.tagNames.state} bind-component="${o.he}">.`),null!==l&&Wi(l,!1),null!==l&&function(e,t,n){let r=e.R,i=`[${re.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 Vi(e,r):r()}(l,e,n,i);let a=new ne(r,new Bt);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,bi.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=Si(e.E);Oi(n,t)&&(e.E!==t||Mi(n,t))&&Pi(`${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)&&Pi(`${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=ki.filter(e=>void 0!==n.state[e]);o.length>0&&Pi(`${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=>{Ii(e,s,n),l.call(t,n)};let a=[...t.O.all()];for(let t of a)Ii(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=bi.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),Wi(u,!0),Gr.add(a),ei(a,n));let d=c.hr?.(n,a);jt(a,n),d?.(),u.L=[...n.childNodes],qt(),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,e=>console.error(e))}catch(e){console.error(e)}i(),e.isConnected?(await a.Ee("$connectedCallback"),h&&e.isConnected&&c.element?.(a,"connected")):Wi(u,!1)}async function Vi(e,t){Wi(e,!0);for(let t of e.pe)qi(t);t?.(),!e.broken&&(await e.R.Ee("$connectedCallback"),null===e.host.engine&&e.el.isConnected&&c.element?.(e.R,"connected"))}function Ji(e,t){let n=e.getAttribute("bind-component");if(null===n)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=It.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){si(t,e);for(let e of oi.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:yi.get(s)?.I;return t?.el===e?t:null},l=t=>{throw i&&si(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(`<${re.tagNames.state} bind-component> takes its state from <${i}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Ie(n).whenDefined(i);let s=yi.get(n);if(void 0!==s)return s.he!==t&&w(`<${i}> already has a <${re.tagNames.state} bind-component="${s.he}">.`),s.state;let o=()=>(di.get(n)??[]).filter(e=>Si(e.name)===t),l=Ei(n,t);if(l&&0===o().length&&xi(n),0===o().length&&(l||((e,t)=>!0===e.getAttribute(gi)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,s)=>{mi.set(n,r),e=function(e,t){Zr(e)&&t();let n=oi.get(e)??new Set;return oi.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())}mi.delete(n);let a=o(),u=pi.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&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 (${re.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),$i}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:fi.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 yi.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 <${re.tagNames.state}> to be a direct child of a custom element.`))).catch(l),async start(t,n){await Ki(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?Vi(t).catch(e=>console.error(e)):a?Promise.resolve().then(()=>{if(e.parentNode===r)return Ki(e,s,i?r:s,yi.get(s).state,()=>{})}).catch(e=>console.error(e)):mi.has(s)&&xi(s)},Bn(){let e=o();null!==e&&(Wi(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 Qi={name:"scopes",install(){c.ut=d(m,c.ut,li),c.ut=d(m,c.ut,hi),c.ut=d(m,c.ut,Ji),c.ar=Ai,c.$o=Ci,c.element=h(c.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=Kr.get(e)??[];if("disconnected"===t)for(let e of n)ti(e);else if("reset"!==t&&Yr(It.get(e.root))===e){ei(e,e.root);for(let e of n)zr.get(e.root).has(e.t)||zr.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();ei(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:ai.get(n);void 0!==r&&ui.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=ui.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),Gi(e,t,n,r,i,s,!1)}),c.Se=h(c.Se,(e,t,n)=>Gi(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=Kr.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=bi.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||(ji(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=Kr.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=wi.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)}}},Xi="$recursion",Yi=new WeakMap,Zi=new WeakSet,es=new WeakSet,ts=0,ns=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),rs=e=>`[wcs/recursion-${e}]`;function is(e,t){let n=n=>w(`${rs("declaration-invalid")} ${Xi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&w(`${rs("declaration-invalid")} ${Xi} ${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 ss=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function os(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 ls(e,t,n){let r=os(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.`),ss(e,i.k)+r}function as(e,t,n){let r=new Set,i=new Set,s=(e,n,s)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&w(`${rs("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),i.has(e)&&w(`${rs("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(`${rs("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(`${ss(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 us(e,t){let n=function(e){let t=e[Xi],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&&U(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&w(`${rs("declaration-invalid")} ${Xi} must be an object mapping one anchor path to its repeating sub-path.`);let i=Object.entries(t);1!==i.length&&w(`${rs("declaration-invalid")} ${Xi} must declare exactly one anchor (it declares ${i.length}).`);let s=is("anchor",i[0][0]),o=is("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(`${rs("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),h.push([new RegExp(`^${ns(s)}((?:${ns(u)})*)${ns(n)}$`),n])}return{l:l,step:u,key:a,families:c,matchers:h,owners:new Map,nodeList:new RegExp(`^${ns(l)}((?:${ns(`.*.${a}`)})*)$`)}}(t),r=Yi.has(e);null!==n?(r||ts++,Yi.set(e,n),es.add(e),Zi.has(e)||function(e){Zi.add(e);let t=e,n=t.ot;t.ot=r=>{let i=Yi.get(e);if(r.t.includes("**")){let t=e.O.wt(r.t)===r;return void(es.has(e)||void 0===i&&t?r.getter=()=>U(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=Yi.get(e);return r.call(e,void 0!==i&&t.includes("**")?ls(i,t,n):t,n)};let i=t.getAll;t.getAll=(n,r)=>{let s=Yi.get(e);if(void 0===s||!n.includes("**"))return i.call(e,n,r);if(void 0===r)return i.call(e,ls(s,n,t.d));(!Array.isArray(r)||r.length>0)&&w(`${rs("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let o=os(s,n),l=[];return as(e,s,(t,n)=>{for(let r of i.call(e,ss(s,t)+o,e.H(n)))l.push(r)}),l};let s=t.wn;t.wn=(n,r,i,o)=>{let l=Yi.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(`${rs("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof i||!0===o?.spread)&&w(`${rs("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Be>0&&_(8);let a=os(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(`${rs("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(`${rs("readonly")} "${n}" writes into the recursive getter "${l.l}.**${e}".`)}let h=[];as(e,l,(e,t)=>h.push([e,t]));let d=0;for(let[t,n]of h)d+=s.call(e,ss(l,t)+a,e.H(n),i);return d}}(e)):r&&(Yi.delete(e),ts--)}function cs(e,t){if(0===ts)return!1;let n=Yi.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(`${rs("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var hs={name:"recursion",install(){c.fe=h(c.fe,us),c.element=h(c.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){es.delete(e)}(e)}),c.Ie=d(f,c.Ie,cs)}},ds="4.6.0",fs=e=>e.split(".").slice(0,2).join("."),ps=class extends Qt{static find(e){return e.querySelector?.(re.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 fs(this.version)===fs(ds)}};function ms(e){let t=re.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends ps{})}var gs=()=>re.tagNames.ssr,ys=Symbol.for("wcstack.ssr.snapshotBuilder"),bs=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),ws=e=>document.createComment(e),vs=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,_s=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),$s=new WeakMap,ks=new WeakMap,Ss=new WeakMap,Ns=new WeakSet,As=new WeakMap;function Cs(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function Es(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 Ts(e,t,n,r){let i=ws(null===r?"wcs-[":`wcs-[:${r}`),s=ws("wcs-]");n.length>0&&n[0].Re().before(...Cs(e,t)),t.after(i);for(let e of n)null===r&&e.Re().before(ws("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 Cs(i,s))Ns.add(e)}function Ps(e){if(e instanceof lt){Ts(e.S,e.S,e.Ae,null);for(let t of e.Ae)Os(t);return}let t=e.I;null!==t&&(Ts(e.K[e.y].S,e.K[e.K.length-1].S,[t],e.y),Os(t))}function Os(e){if(null!==e.u)for(let t of e.u)Ps(t)}var Ms=new Set(["script","style","template","textarea","title"]),Ls="data-wcs-raw",Is=e=>Ms.has(e.localName)||e.localName===gs();function js(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(ws("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(ws("wcs-s")):1===t.nodeType&&!Is(t)&&js(t)}var Rs=0;function Hs(e,t){let n=e.getRootNode(),r=[t];for(let e of ks.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let i=new Map;for(let e of r){let t=$s.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),Ps(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ss.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ns.has(e)||1===e.nodeType&&t.has(e)&&zs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Is(e.parentNode)?As.has(e):t.has(n)&&_s(n,"wcs-t:"))&&(As.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);Is(e)&&n.some(e=>As.has(e))&&e.setAttribute(Ls,n.map(e=>As.has(e)?`{{ ${As.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}js(9===n.nodeType?n.body:n);let s=document.createElement(gs());s.setAttribute("version",ds);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"}${Rs++}`;e.replaceWith(ws(`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(Es(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(Es(t,l,o))}e.before(s)}function Ws(e){!function(e){if(null!==e.querySelector(re.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=>As.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(`${re.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===gs())continue;let e=t.engine;null!=e&&Hs(t,e)}}var Us=Symbol.for("wcstack.state.ssr.impl"),Ds=new Map,Fs=new WeakMap,zs=e=>!0===c.$o?.(e),qs=e=>1===e.nodeType&&!Is(e)&&!zs(e),Bs=e=>e.f.flat().concat(e.z??[]),Gs=e=>{for(let t of Bs(e))t.remove()};function Ks(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&&!vs(l,"wcs-]");){let e=l.nextSibling;if(vs(l,"wcs-|"))o.push([]),l.remove();else{0===o.length&&o.push([]);let n=o[o.length-1];_s(l,"wcs-[")?e=Ks(l,t,n):(n.push(l),qs(l)&&Vs(l,t))}l=e}let a={branch:void 0===r[1]?null:Number(r[1]),f:o,z:l??s.appendChild(ws("wcs-]"))},u=Bs(a);l=a.z.nextSibling;for(let e of u)n?.push(e),t&&At.add(e);return t&&null!==i?Ds.set(i,a):Gs(a),l}function Vs(e,t){for(let n=e.firstChild;null!==n;)_s(n,"wcs-[")?n=Ks(n,t):(qs(n)&&Vs(n,t),n=n.nextSibling)}function Js(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=ws(`@@:${decodeURIComponent(e.slice(6))}`),n=i.nextSibling;for(;null!==n&&!vs(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]?Es(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&&!Is(i)&&(zs(i)?Fs.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||ro(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{_s(e,"wcs-[")?r++:vs(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(vs(r,"wcs-]")&&0===i--){t.prepend(...e.slice(n));break}}}(e),Vs(e,n)}function Qs(e,t){let n=Fs.get(e);if(void 0===n)return null;Fs.delete(e);let r=e=>Js(e,n.ssr,n.Te);if(n.Te||eo(t,e,e,r),r(e),!n.Te)return null;let i=c.Te;return c.Te=oo,()=>{c.Te=i,Xs()}}function Xs(){for(let e of Ds.values())Gs(e);Ds.clear()}function Ys(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function Zs(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 eo(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=()=>{};Ct(e,[...i.childNodes],null,!0,s,s,s,(t,n)=>$t(e,n,null,0))}function to(e,t,n){if(bs()){if(n instanceof Array){for(let e=n.length;e-- >0;)gt(n[e])&&n.splice(e,1);let e=t;if(n.some(yt))Ns.add(e);else if(e.localName.includes("-")&&!zs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ss.set(e,t)}return}if("string"==typeof n){if(As.set(t,n),Is(t.parentNode))return;let e=ws(`wcs-t:${encodeURIComponent(n)}`),r=ws("wcs-/t");return t.before(e),void t.after(r)}let r=$s.get(e);void 0===r&&$s.set(e,r=new Map),r.set(t,n);let i=t.getRootNode(),s=ks.get(i);return void 0===s&&ks.set(i,s=new Set),void s.add(e)}if("string"!=typeof n&&Ds.size>0){let e=Ds.get(n);void 0!==e&&(Ds.delete(n),Ds.set(t,e))}}var no=e=>null!==e&&8===e.nodeType&&[re.commentIfPrefix,re.commentElseIfPrefix,re.commentElsePrefix].includes(e.data),ro=e=>3===e.nodeType&&""===e.data.trim(),io=e=>{let t=Ds.get(e)?.z??e;return(xs(t)??t).nextSibling};function so(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=io(o)}e.So[r]=o}return!0}function oo(e,t,n){if(0===Ds.size)return null;let r=t,i=0;if(!n){let e=re.commentIfPrefix;if(!vs(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(no(n)&&i++,!vs(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ds.has(r)&&null!==n&&!vs(n,e)&&1!==n.nodeType;n=n.nextSibling)no(n)&&(r=n)}let s=Ds.get(r);if(void 0===s)return null;if(!n&&s.branch!==i)return Ds.delete(r),Gs(s),null;let o=s.f.shift();if(0===s.f.length&&Ds.delete(r),s.z?.replaceWith(...Cs(t,r)),s.z=null,void 0===o)return null;let l=[];for(let e=0;e<o.length;e++){let t=Ds.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(!so(e,l)){let n=(e.jn?e.root:e.ln).cloneNode(!0);l=e.jn?[n]:[...n.childNodes],so(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 lo={name:"ssr",install(){c.Dn=to,c.hr=Qs;let e=c.element;c.element=(t,n)=>{"mounting"===n&&function(e){let t=e.element;if(!t.hasAttribute("enable-ssr")||bs())return;let n=t.previousElementSibling,r=n?.localName===gs(),i=r?n.getAttribute("version"):null,s=null===i||fs(i)===fs(ds);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] <${gs()} version="${i}"> does not match ${ds}: 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(`[${Ls}]`)))e.textContent=e.getAttribute(Ls),e.removeAttribute(Ls);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&&!zs(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 > ${re.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of ae(t.getAttribute(re.bindAttributeName)??"")){let t=r.Ze;r.Ne[0]===s&&n.push([e?Zs(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:Zs(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]:Zs(r,s[2],2,1)??s[2]};for(let t of Ys(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!vs(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]?[ws(`@@:${s(t,e[2],n)}`)]:[])}}let o=(e,n)=>{for(let r of Ys(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=re.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):Js(e,n,s);s||eo(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=oo,queueMicrotask(()=>{Xs(),c.Te=null}))}(t),e?.(t,n)},function(){let e=globalThis;e[Us]={build:Ws,reset(){Rs=0}},void 0===e[ys]&&(e[ys]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Us].build(t),reset:()=>e[Us].reset()})}(),c.Ao=h(c.Ao,ms);for(let e of Zt())ms(e)}},ao="__WCSTACK_DEVTOOLS_HOOK__",uo=null,co=new Set,ho=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),fo=new WeakMap,po=0,mo=new WeakMap;function go(e){if(null===uo)return;let t=mo.get(e),n=co.has(e)?function(e,t){let n=new Map,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=fo.get(e);return void 0===t&&fo.set(e,t=++po),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:ho(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 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 lt){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)||uo({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&uo({type:"state:binding-added",...r});mo.set(e,n)}function yo(e){let t=It.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function bo(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 wo=new WeakSet,vo=new WeakMap;function _o(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(wo.has(t))return;wo.add(t);let r=t.emit;t.emit=(...i)=>(null!==uo&&uo({type:"state:token-emit",kind:n,tokenName:t.name,args:i,subscriberCount:t.size,stateElement:e.element}),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(co.has(e))return;co.add(e),uo?.({type:"state:element-registered",rootNode:e.root,element:e.element}),go(e)}else"disconnected"===t&&(co.delete(e),go(e),uo?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function $o(e,t,n,r,i,s){if(null===uo)return;let o=ho(e,t,0===t.n?null:n),l=vo.get(e);void 0===l&&vo.set(e,l=new Set),l.add(o),s&&uo({type:"state:write",absoluteAddress:o,value:i,oldValue:r,hasOldValue:!0})}function ko(e){if(null===uo)return;let t=vo.get(e);vo.delete(e),void 0!==t&&uo({type:"state:update-batch",addresses:t}),go(e)}function So(e,t,n){uo?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var No={"*":["focus","blur","click","scrollIntoView","showPopover","hidePopover","togglePopover"],dialog:["show","showModal","close","requestClose"],form:["requestSubmit","checkValidity","reportValidity"],input:["select","setSelectionRange","showPicker","setCustomValidity","checkValidity","reportValidity"],textarea:["select","setSelectionRange","setCustomValidity","checkValidity","reportValidity"],select:["showPicker","setCustomValidity","checkValidity","reportValidity"],audio:["play","pause","load"],video:["play","pause","load"]};function Ao(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...No["*"],...Object.hasOwn(No,e)?No[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)g.has(t.name)||(g.add(t.name),t.install())}([wn,ur,Lr,Fr,Qi,hs,lo,{name:"devtools",install(){c.element=h(c.element,_o),c.re=h(c.re,$o),c.me=h(c.me,ko),c.Ye=h(c.Ye,So),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let e=globalThis,t=e[ao]??(e[ao]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let 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:ds,getStateElements:()=>[...co].map(bo),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}(yo(e)),keys(e){let t=yo(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return yo(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){yo(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(e){let t=null===uo&&null!==e;uo=e,null===e&&(mo=new WeakMap),c.at=e&&((e,t)=>uo?.({...t,stateElement:e.element})),t&&queueMicrotask(()=>{for(let e of co)go(e)})}})}()}},{name:"native-commands",install(){c.or=Ao}}]),function(e=customElements){(function(){let e=globalThis;void 0===e[Wt]&&(e[Wt]={protocol:"wcs-binder",version:1,bind:zt})})(),Zt().includes(e)||Yt.push(new WeakRef(e));let t=re.tagNames.state;void 0===e.get(t)&&e.define(t,class extends Xt{}),c.Ao?.(e)}();const Co={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"},Eo=!1,xo=[".html"];function To(){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 Po(e,t){if(t&&"cause"in t)throw new Error(`[@wcstack/router] ${e}`,{cause:t.cause});throw new Error(`[@wcstack/router] ${e}`)}let Oo=class extends Error{fallbackPath;constructor(e,t){super(e),this.fallbackPath=t}};const Mo={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 Lo(e){const t={};for(const[n,r]of new URLSearchParams(e))t[n]=r;return Object.freeze(t)}function Io(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 jo={static:2,param:1,"catch-all":0};let Ro=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&&Po(`${Co.route} is relative but has no parent route.`),!this.isRelative&&this._parentCore&&Po(`${Co.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+=jo[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(Mo).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||Po(`${Co.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:Lo(e.search??""),routeName:e.routes[e.routes.length-1]?.name??""})}(e));if("string"==typeof r&&""!==r)throw new Oo("Navigation cancelled by guard.",r);if(!r)throw new Oo("Navigation cancelled by guard.",this._guardFallbackPath);return"object"==typeof r?r:null}if(this._hasGuard&&this._guardHandlerLoadFailed)throw new Oo("Navigation cancelled: guard handler failed to load.",this._guardFallbackPath);return null}};const Ho="data-wcs-ssr",Wo="data-wcs-ssr-link",Uo="@@wcs-route-ph:",Do="@@wcs-route-start:",Fo="@@wcs-route-end:";let zo=class extends HTMLElement{_core;_routeParentNode=null;_routeChildNodes=[];_routerNode=null;_uuid=To();_placeHolder=document.createComment(`@@route:${this._uuid}`);_childNodeArray;_endMarker;held=null;_childIndex=0;_initialized=!1;_routes;constructor(){super(),this._core=new Ro(this)}get routeParentNode(){return this._routeParentNode}get routeChildNodes(){return this._routeChildNodes}get routerNode(){return this._routerNode||Po(`${Co.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(`${Fo}${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):Po(`${Co.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&&Po(`${Co.route} with fallback attribute must be a direct child of ${Co.router}.`),e.fallbackRoute&&Po(`${Co.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 qo=Symbol.for("wcstack.trustedTypes.policy"),Bo=Symbol.for("wcstack.trustedTypes.internal"),Go="wcstack";function Ko(){const e=globalThis[qo];return null===e||"object"!=typeof e?null:e}let Vo=!1;function Jo(e){const t=function(){const e=globalThis,t=e[Bo];if(void 0!==t)return t;const n=globalThis.trustedTypes;let r=null;if(n&&"function"==typeof n.createPolicy)try{r=n.createPolicy(Go,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){"function"!=typeof Ko()?.createHTML&&console.error(`[@wcstack/router] Could not create the Trusted Types policy "${Go}". Allow it in the CSP (\`trusted-types ${Go};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,e)}return e[Bo]=r,r}(),n=t?.createHTML;if("function"==typeof n)return n.call(t,e);if(!("trustedTypes"in globalThis))return e;const r=Ko(),i=r?.createHTML;return"function"==typeof i?(Vo||(Vo=!0,console.warn(`[@wcstack/router] Falling back to the injected Trusted Types policy to expand a layout template, because the "${Go}" policy could not be created. If that policy sanitizes (e.g. DOMPurify), custom elements in the layout may be stripped. Allow \`trusted-types ${Go};\` in the CSP to avoid this. See docs/csp.md section 7.`)),i.call(r,e)):e}const Qo=new Map;let Xo=class extends HTMLElement{_uuid=To();constructor(){super()}async _loadTemplateFromSource(e){try{const t=await fetch(e);t.ok||Po(`${Co.layout} failed to fetch layout from source: ${e}, status: ${t.status}`);const n=await t.text();return Qo.set(e,n),n}catch(t){Po(`${Co.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(`${Co.layout} have both "src" and "layout" attributes.`);const n=document.createElement("template");if(e)Qo.has(e)?n.innerHTML=Jo(Qo.get(e)||""):n.innerHTML=Jo(await this._loadTemplateFromSource(e)||"");else if(t){const e=this._loadTemplateFromDocument(t);e?n.innerHTML=Jo(e):console.warn(`${Co.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")&&Eo}get name(){return this.getAttribute("name")||""}},Yo=class extends HTMLElement{_routesNode=null;_lastRoutes=[];_initialized=!1;constructor(){super()}get routesNode(){return this._routesNode||Po(`${Co.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")&&Eo}_initialize(){this._resolveEnableShadowRoot()&&this.attachShadow({mode:"open"}),this._initialized=!0}connectedCallback(){this._initialized||this._initialize()}disconnectedCallback(){this._lastRoutes=[]}};const Zo=new Set(["props","states","attr",""]);function el(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 tl(e,t){e.hasAttribute("data-bind")||Po(`${e.tagName} has no 'data-bind' attribute.`);const n=e.getAttribute("data-bind")||"";Zo.has(n)||Po(`${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&&el(e,t,r)}).catch(()=>{Po(`Failed to define custom element: ${i}`)}):el(e,t,r)}const nl=Symbol.for("wcstack.binder");function rl(){const e=globalThis[nl];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}const il=Symbol.for("wcstack.binder.pending"),sl=Symbol.for("wcstack.binder.taken");function ol(){const e=globalThis;let t=e[sl];return void 0===t&&(t=new WeakSet,e[sl]=t),t}function ll(e,t){const n=rl();return null===n?(function(){const e=globalThis;let t=e[il];return void 0===t&&(t=[],e[il]=t),t}().push(e),!1):(ol().add(e),n.bind(e,t),!0)}const al={range:!0};function ul(e,t){for(const n of e.routeChildNodes)t.add(n.placeHolder).add(n.endMarker),ul(n,t);return t}function cl(e){const t=e.placeHolder,n=e.endMarker,r=null!==n.parentNode&&n.parentNode===t.parentNode&&!!(4&t.compareDocumentPosition(n)),i=r?null:ul(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 hl=new WeakSet;function dl(e){const t=Co.router,n=Co.outlet;for(const r of e.querySelectorAll(n))hl.has(r)||r.previousElementSibling?.matches(t)||(hl.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 fl=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 pl(e){console.warn(`[@wcstack/router] [wcs/layout-slot-missing] This layout's template has no default <slot>, so what its <${Co.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 ml extends HTMLElement{_layout=null;_initialized=!1;_initializing=!1;_disconnectedDuringInit=!1;_layoutChildNodes=[];constructor(){super()}get layout(){return this._layout||Po(`${Co.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=""]')&&fl(t)&&pl(this),dl(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(`${Co.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):fl(i.childNodes)&&pl(this),this.appendChild(t),dl(this)}!function(e){if(null!==rl())for(const t of e)1===t.nodeType&&ll(t,al)}(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=>{tl(t,e)}),t.hasAttribute("data-bind")&&tl(t,e))}}function gl(){return document.createElement(Co.layoutOutlet)}const yl="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";function bl(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)),Po(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 ${yl}`:`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 ${yl}`}(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(`${Co.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 wl(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 vl(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===Co.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),wl(r,u),o=u.placeHolder,l=u,a=u,s=u}else{if(u===Co.guardHandler){const e=n??s,t=l.querySelector('script[type="module"]');null===e?console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${Co.guardHandler}> outside a <${Co.route}> guards nothing: put it inside the route it guards.`):t?(null===n&&console.error(`[@wcstack/router] [wcs/guard-handler-ignored] A <${Co.guardHandler}> outside a <${Co.route}> guards the route before it, "${e.absolutePath}": put it inside that route.`),e.enableGuard(),bl(t,e)):console.error(`[@wcstack/router] [wcs/guard-handler-ignored] The <${Co.guardHandler}> of route "${e.absolutePath}" has no <script type="module">, so the route is not guarded.`);continue}if("template"===u){i.appendChild(l);continue}if(u===Co.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=gl();r.layout=n,o=r,l=t}}const c=await vl(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 vl(e,e.template.content,null,t)}function $l(e){return!1!==e.checkVisibility?.()}function kl(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=Mo[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)kl(i,t,n,r)}function Sl(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)kl(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 Nl=null,Al=null;function Cl(){const e=xo;return 0===e.length?null:(Nl===e&&Al||(Nl=e,Al=new RegExp(`\\/[^/]+(?:${e.map(e=>e.replace(/\./g,"\\.")).join("|")})$`,"i")),Al)}function El(e){let t=e||"/";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=Cl();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 Tl(e){let t=e||"";if(!t)return"";t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/");const n=Cl();return n&&(t=t.replace(n,"")),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),"/"===t?"":t}function Pl(e){if(null!==e.held)return;const t=cl(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 Ol(e){e.clearParams(),Pl(e)}function Ml(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=>{tl(t,e.typedParams)}),n.hasAttribute("data-bind")&&tl(n,e.typedParams),n.querySelectorAll(Co.layoutOutlet).forEach(t=>{t.assignParams(e.typedParams)}),n.tagName.toLowerCase()===Co.layoutOutlet&&n.assignParams(e.typedParams)}}const Ll=new WeakSet;function Il(e){const t=e.placeHolder;null!==t.parentNode&&(Ll.has(e)||null!==e.endMarker.parentNode?(Pl(e),t.after(e.held),e.held=null):t.after(...e.childNodeArray,e.endMarker),Ll.add(e))}const jl=Symbol.for("wcstack.transition-runner");const Rl=new WeakSet,Hl="data-wcs";function Wl(e,t,n){!Rl.has(e)&&function(e){return e.hasAttribute(Hl)||null!==e.querySelector(`[${Hl}]`)}(e)&&(Rl.add(e),function(e){"complete"===document.readyState?e():window.addEventListener("load",e,{once:!0})}(()=>{var r;null!==rl()||(r=e,ol().has(r))||console.warn(`[@wcstack/router] ${t} contains ${Hl} 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 Ul(e){return"AbortError"===e?.name}const Dl=new WeakMap;function Fl(e){for(const t of e.childNodeArray)if(1===t.nodeType){if(t.isConnected){if(ll(t,al))continue}else if(null!==rl())continue;Wl(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,Dl.delete(e)}catch(n){if(n instanceof Oo){const r=(Dl.get(e)??0)+1;return r>10?(Dl.delete(e),console.error(`${Co.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):(Dl.set(e,r),e.connectedCallbackPromise.catch(()=>{}).then(()=>e.replace(n.fallbackPath)).catch(e=>{Ul(e)||console.error("Fallback navigation failed:",e)}),!1)}throw n}return!0}async function ql(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=Sl(e,s);o||(e.fallbackRoute?o={routes:[e.fallbackRoute],params:{},typedParams:{},path:s,lastPath:r}:Po(`${Co.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)||Ol(e);const e=[];for(const n of t.routes)(e.length>0||!s.has(n)||n.shouldChange(t.params))&&(e.push(n),Ml(n,t));let r=!1;for(const t of e){const e=s.has(t);e&&r||Il(t),r||=e,n.length>0&&!e&&Fl(t)}};let l;return 0===n.length?o():l=function(e,t,n){const r=function(e){const t=globalThis[jl];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($l(e))return e}else for(const t of e.querySelectorAll("h1,h2,h3,h4,h5,h6"))if($l(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 Bl(){const e=window.navigation;return e?"function"!=typeof e.addEventListener||"function"!=typeof e.removeEventListener?null:e:null}function Gl(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 Kl(e){return"?"===e?"":e}function Vl(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 Jl=new WeakSet;function Ql(e,t,n){if(Jl.has(e))return;Jl.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 Xl=new WeakMap;function Yl(e,t,n){const r=function(e,t){let n=Xl.get(e);return void 0===n&&(n=new Map,Xl.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 Zl(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const ea=Object.freeze({});class ta 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=ea;_typedParams=ea;_searchParams=ea;_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 El(e)}_normalizeBasename(e){return Tl(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){Yl(this,"basename",e)}get leaveConfirm(){return this.getAttribute("leave-confirm")||null}set leaveConfirm(e){Yl(this,"leave-confirm",e),this._syncBeforeUnload()}_onBeforeUnload=e=>{null===this.leaveConfirm||this._unloadConfirmed||e.preventDefault()};_syncBeforeUnload(){const e=this.isConnected&&null!==this.leaveConfirm&&!Zl();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(Co.router))if(t!==this&&t instanceof ta&&t._isOwnPath(e))return!0;return!1}_getOutlet(){const e=this.nextElementSibling;if(e&&e.matches(Co.outlet))return e;!function(e){const t=e.getRootNode();t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE||dl(t)}(this);const t=document.createElement(Co.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||Po(`${Co.router} has no outlet.`),this._outlet}get template(){return this._template||Po(`${Co.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=Lo(e.search),s=e.data??null,o=this._data!==s,l=!Io(this._params,n),a=this._routeName!==e.routeName,u=!Io(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=>{Ul(e)||console.error(`${Co.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=>{Ul(e)||console.error(`${Co.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=Gl(e),r=""!==n.pathname||""===n.search&&""===n.hash?this._joinInternalPath(this._basename,n.pathname):window.location.pathname,i=r+Kl(n.search)+n.hash;if(null!==this.leaveConfirm&&(await Promise.resolve(),!this._confirmLeave(r)))return;const s=Bl();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 ql(this,this.outlet,e,this._path,Kl(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)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 ql(o,o.outlet,n,o.path,s)}catch(e){throw console.error(`${Co.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 ql(this,this.outlet,e,this._path,window.location.search||""),this._notifyLocationChange())};async _initialize(){this._initializing=!0;try{const e=Zl();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||Po(`${Co.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 <${Co.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||Po(`${Co.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(Ho);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&&Po(`${Co.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(Ho);const e=this._outlet.rootNode;for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(i)}await ql(this,this.outlet,o,this._path,window.location.search||""),(s||null!==rl())&&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(Co.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(Uo)){const r=t.slice(15);if(i.has(r)||!n.has(r))return!1;i.set(r,e)}else if(t.startsWith(Do)){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(Fo)){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=Sl(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(Do)){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()===Co.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(Ho);for(const e of h.routes)Ml(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=xl(e,this._basename),n=Sl(this,t),r=n?.routes??(null!==this._fallbackRoute?[this._fallbackRoute]:[]);if(0===r.length&&Po(`${Co.router} No route matched for path: ${t}`),!r.some(e=>e.hasGuard)){await ql(this,this.outlet,e,this._path,window.location.search||""),this._offerInitialContentToBinder(),this._forEachRoute(e=>{e.placeHolder.data=`${Uo}${e.absolutePath}`}),this.outlet.setAttribute(Ho,"");for(const e of this.outlet.lastRoutes)e.placeHolder.after(document.createComment(`${Do}${e.absolutePath}`))}}_offerInitialContentToBinder(){for(const e of this.outlet.lastRoutes)for(const t of e.childNodeArray)t.nodeType===Node.ELEMENT_NODE&&t.isConnected&&ll(t,al)}_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 ")&&Ql(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!Vl(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this._syncBeforeUnload(),Zl()){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=Bl();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&&(Bl()?.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 na=["title","rel","target","download","hreflang","lang","dir"];class ra extends HTMLElement{static get observedAttributes(){return["to","match",...na]}_childNodeArray=[];_uuid=To();_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(Co.router);if(e)return this._router=e;const t=this.getRootNode(),n=t.querySelector?.(Co.router);if(n)return this._router=n;Po(`${Co.link} is not connected to a router.`)}_initialize(){Zl()||(this.style.display="none"),this._childNodeArray=Array.from(this.childNodes),this._path=this.getAttribute("to")||"",this._initialized=!0}_normalizePathname(e){return El(e)}_joinInternalPath(e,t){const n=Tl(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}=Gl(t),s=""===n?window.location.pathname:this._joinInternalPath(this.router.basename,n);e.href=s+Kl(r)+i}else try{e.href=new URL(t).toString()}catch{Po(`[${Co.link}] Invalid URL in 'to' attribute: ${t}`)}else e.removeAttribute("href")}connectedCallback(){Zl()?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(Wo)?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(Wo),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-")||na.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,Zl())return this._updateActiveState(),void n.setAttribute(Wo,"");Bl()?.addEventListener("currententrychange",this._updateActiveState),window.addEventListener("wcs:navigate",this._updateActiveState),window.addEventListener("popstate",this._updateActiveState),""!==this._path&&!this._isInternalTarget(this._path)||Bl()?.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(){Bl()?.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(na.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}=Gl(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 ia=[],sa=new Map;let oa=!1;const la=new WeakMap;class aa extends HTMLElement{_initialized=!1;_childElementArray=[];constructor(){super()}_initialize(){if(!this._initialized&&(this._initialized=!0,this._childElementArray=Array.from(this.children),!Zl())){this.style.display="none";for(const e of this._childElementArray)this.removeChild(e)}}connectedCallback(){this._initialize(),oa||(this._captureInitialHead(),oa=!0),ia.push(this),this._reapplyHead()}disconnectedCallback(){const e=ia.indexOf(this);-1!==e&&ia.splice(e,1),this._reapplyHead()}get childElementArray(){return this._initialized||Po("Head component is not initialized yet."),this._childElementArray}_getKey(e){const t=la.get(e);if(void 0!==t)return t;const n=this._computeKey(e);return la.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);sa.has(e)||sa.set(e,t.cloneNode(!0))}}_reapplyHead(){const e=new Set;for(const t of ia)for(const n of t._childElementArray)e.add(this._getKey(n));for(const t of sa.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=ia.length-1;t>=0;t--){const r=ia[t];for(const t of r._childElementArray)if(this._getKey(t)===n){e=t.cloneNode(!0);break}if(e)break}!e&&sa.has(n)&&(e=sa.get(n).cloneNode(!0));const r=t.get(n)??null;e?(r?r.replaceWith(e):document.head.appendChild(e),t.set(n,e),ll(e)||Wl(e,`<${e.tagName.toLowerCase()}> inside <${Co.head}>`,`<${Co.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(Co.layout)||e.define(Co.layout,Xo),e.get(Co.layoutOutlet)||e.define(Co.layoutOutlet,ml),e.get(Co.outlet)||e.define(Co.outlet,Yo),e.get(Co.route)||e.define(Co.route,zo),e.get(Co.router)||e.define(Co.router,ta),e.get(Co.link)||e.define(Co.link,ra),e.get(Co.head)||e.define(Co.head,aa)}(void 0);const ua="data-fetchtarget",ca={fetch:"wcs-fetch",fetchHeader:"wcs-fetch-header",fetchBody:"wcs-fetch-body",infiniteScroll:"wcs-infinite-scroll"};let ha=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 da(e,t){return t.every(t=>"available"===e.availability.get(t))}const fa=new Map([["web.fetch",{probe:()=>"function"==typeof globalThis.fetch,compatKey:"api.fetch"}],["web.abort-controller",{probe:()=>"function"==typeof globalThis.AbortController,compatKey:"api.AbortController"}]]),pa=new Set(["GET","HEAD","OPTIONS"]);let ma=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 ha("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 da(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}}(fa,{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(!da(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||pa.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)}}},ga=!1;function ya(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${ua}]`);if(!n)return;const r=n.getAttribute(ua);if(!r)return;const i=customElements.get(ca.fetch),s=document.getElementById(r);if(!(i&&s instanceof i))return;const o=s;o.url&&(e.preventDefault(),o.fetch())}function ba(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 wa=new WeakSet;function va(e,t,n){if(wa.has(e))return;wa.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 _a=new WeakMap;function $a(e,t){let n=_a.get(e);return void 0===n&&(n=new Map,_a.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function ka(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Sa(e,t,n){const r=$a(e,t);ka(e,t,void 0===n?r:null===n?null:String(n))}const Na=Symbol.for("wcstack.trustedTypes.policy");function Aa(){const e=globalThis[Na];return null===e||"object"!=typeof e?null:e}let Ca,Ea=!1;class xa extends HTMLElement{static hasConnectedCallbackPromise=!0;static hasPendingPromise=!0;static wcBindable={...ma.wcBindable,properties:[...ma.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 ma(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){Sa(this,"url",e)}get method(){return(this.getAttribute("method")||"GET").toUpperCase()}set method(e){Sa(this,"method",e)}get target(){return this.getAttribute("target")}set target(e){Sa(this,"target",e)}get responseType(){return this.getAttribute("response-type")||"auto"}set responseType(e){Sa(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=$a(e,t);ka(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(ca.fetchHeader);for(const n of t)"boolean"==typeof n.hasHeader?n.hasHeader&&(e[n.headerName]=n.headerValue):this._warnUndefinedHelper(ca.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(ca.fetchBody);if(t&&"string"!=typeof t.bodyContent)this._warnUndefinedHelper(ca.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 per element.)",this))}_warnUndefinedHelper(e,t){this._toldUndefinedHelper||(this._toldUndefinedHelper=!0,console.warn(`[@wcstack/fetch] [wcs/fetch-helper-undefined] <${e}> inside this <${ca.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(ca.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;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=Aa(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(t)}catch(e){if(function(){if(void 0!==Ca)return Ca;if(!("trustedTypes"in globalThis))return Ca=!1,Ca;try{document.createElement("div").innerHTML="<i></i>",Ca=!1}catch{Ca=!0}return Ca}())return void function(){if(Ea)return;Ea=!0;const e="function"==typeof Aa()?.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 ")&&va(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!ba(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",ga||(ga=!0,document.addEventListener("click",ya)),!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 Ta 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){Sa(this,"name",e)}get value(){return this.getAttribute("value")??""}set value(e){Sa(this,"value",e)}get headerName(){return this.name}get headerValue(){return this.value}get hasHeader(){return""!==this.name&&this.hasAttribute("value")}}let Pa=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}get contentType(){return this.getAttribute("type")||"application/json"}get bodyContent(){return this.textContent?.trim()||""}};class Oa 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 xa?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] <${ca.infiniteScroll} target="${this.target}"> came into view, but no <${ca.fetch}> has that id, so no page was loaded.`))}}!function(e=customElements){e.get(ca.fetch)||e.define(ca.fetch,xa),e.get(ca.fetchHeader)||e.define(ca.fetchHeader,Ta),e.get(ca.fetchBody)||e.define(ca.fetchBody,Pa),e.get(ca.infiniteScroll)||e.define(ca.infiniteScroll,Oa)}(void 0);const Ma="data-storagetarget",La={storage:"wcs-storage"},Ia="wcs-storage:value-changed",ja="wcs-storage:loading-changed",Ra="wcs-storage:error",Ha="wcs-storage:error-info-changed",Wa="wcs-storage:trigger-changed";let Ua=class extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:Ia,semantics:"state",getter:e=>e.detail},{name:"loading",event:ja,semantics:"state"},{name:"error",event:Ra,semantics:"state"},{name:"errorInfo",event:Ha,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)}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(ja,{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(Ra,{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent(Ha,{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(Ia,{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 per element.)`,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)}},Da=!1;function Fa(e){const t=e.target;if(!(t instanceof Element))return;const n=t.closest(`[${Ma}]`);if(!n)return;const r=n.getAttribute(Ma);if(!r)return;const i=customElements.get(La.storage),s=document.getElementById(r);i&&s instanceof i&&(e.preventDefault(),s.save())}function za(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 qa=new WeakSet;function Ba(e,t,n){if(qa.has(e))return;qa.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 Ga=new WeakMap;function Ka(e,t){let n=Ga.get(e);return void 0===n&&(n=new Map,Ga.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function Va(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}function Ja(e,t,n){const r=Ka(e,t);Va(e,t,void 0===n?r:null===n?null:String(n))}let Qa=class extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...Ua.wcBindable,properties:[...Ua.wcBindable.properties,{name:"trigger",event:Wa,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;constructor(){super(),this._core=new Ua(this),this._internals=this._initInternals(),this._wireStates({[ja]:e=>({loading:!0===e}),[Ra]: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){Ja(this,"key",e)}get storageKey(){return this.key}set storageKey(e){Ja(this,"storage-key",e)}get type(){return"session"===this.getAttribute("type")?"session":"local"}set type(e){Ja(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] <${La.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=Ka(e,t);Va(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(Wa,{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.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 ")&&Ba(e,n,i),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!za(e,n))continue;const s=e,o=s[n];delete s[n],s[n]=o}}(this),this.style.display="none",this._checkType(),Da||(Da=!0,document.addEventListener("click",Fa)),!this.manual&&this.key&&this.load(),this._syncCore(),this._core.startSync()}disconnectedCallback(){this._core.stopSync()}};!function(e=customElements){e.get(La.storage)||e.define(La.storage,Qa)}(void 0);const Xa="*",Ya="vanilla",Za={loaders:{[Ya]:{postfix:".js",loader:async function(e){return(await(import(`${e}`))).default}},[Xa]:Ya},observable:!0,tagNames:{autoloader:"wcs-autoloader"}};function eu(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 tu(e,t,n){let r;if(null===t||t===Xa||""===t){let t=null;const i=[];for(const[e,t]of Object.entries(n)){if(e===Xa)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[Xa],"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 nu=new Set,ru=new Map;let iu=new WeakMap;function su(e){if(e===globalThis.customElements)return ru;let t=iu.get(e);return void 0===t&&(t=new Map,iu.set(e,t)),t}const ou=new Map;async function lu(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 ou)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){nu.has(t)||(console.error(`Failed to eager load component '${t}':`,e),nu.add(t))}}function au(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 uu(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&&ou.set(e,t)});const cu=new WeakSet,hu=new WeakSet;async function du(e,t,n){e.shadowRoot&&(cu.has(e)||await async function(e,t,n){cu.add(e),await gu(e.shadowRoot,t,n)}(e,t,n))}async function fu(e,t,n,r){const i=function(e,t){for(const[n,r]of Object.entries(t))if(e.startsWith(n+"-"))return r;return null}(e.name,n);if(null===i)throw new Error("No matching namespace found for lazy loaded component: "+e.name);const s=su(r),o=s.get(e.name);if(void 0!==o)return void await o;const l=async function(e,t,n,r){try{let i;try{i=tu("",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),nu.add(e.name)}}(e,t,i,r);s.set(e.name,l);try{await l}finally{s.delete(e.name)}}async function pu(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=uu(e);void 0===r.get(i.name)?(hu.has(e)||(hu.add(e),r.whenDefined(i.name).then(async()=>{await du(e,t,n)})),l.has(i.name)||nu.has(i.name)||(l.add(i.name),o.push(i))):await du(e,t,n)}let a=0;for(const e of o)await fu(e,t,n,r),a++;return a}async function mu(e,t,n,r){for(;await pu(e,t,n,r)>0;);}async function gu(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 au(t)}return au(globalThis.customElements)}(e);if(null===r)return console.error("Cannot autoload components: the root has a null custom element registry."),null;try{await mu(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 mu(e,t,n,r)}catch(e){console.error("Failed to lazy load components: "+e)}});return i.observe(e,{childList:!0,subtree:!0}),i}class yu extends HTMLElement{static _instance=null;_initialized=!1;_prefixMap=null;_observer=null;constructor(){if(super(),yu._instance)throw new Error(`${Za.tagNames.autoloader} can only be instantiated once.`);yu._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=eu(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=tu(i.key,i.loaderKey,t)}catch(e){throw new Error("Loader redirection is not supported for eager loaded components: "+r)}n.push(lu(i,r,s))}await Promise.all(n)}(n,Za.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 gu(document,Za,this._prefixMap)))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,yu._instance===this&&(yu._instance=null)}}!function(e=customElements){e.get(Za.tagNames.autoloader)||e.define(Za.tagNames.autoloader,yu)}(void 0);
2
2
  //# sourceMappingURL=auto.min.js.map