@wcstack/state 4.4.0 → 4.5.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/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- var e={};function t(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function n(e,t,n){return null==t?n:(...l)=>{let r=t(...l);return e(r)?r:n(...l)}}var l=e=>!0===e,r=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.It&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.It(t)}}function a(e,t){if(!s.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}var u=class{constructor(e,t,n){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.L=[],this.Q=[],this.mt=null,this.F=-1,this.Y=c,this.Me=null,this.Dt=null,this.Mt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=e,this.c=n,this.s=t;let l=null===n?[null]:n.h.slice(),r="*"===t;r&&l.push(n),this.n=l.length-1,this.z=r?[]:null===n?[t]:[...n.z,t],this.h=l}_n(e){this.ht.has(e)||(this.ht.add(e),this.L.push(e),e.Q.push(this))}Do(e){this.ht.delete(e);let t=this.L;t.splice(t.indexOf(e),1)}Mo(){this.getter=null,this.se=null,this.F=-1,this.Y=c,this.L.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.Me=null,this.Dt=null,this.Mt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.c}return!1}},c=Symbol("unset"),f=Symbol("dirty"),h=Symbol("failed"),d=class{constructor(e=null){this.yt=new Map,this.Vn=e}wt(e){return this.yt.get(e)}get(e){let t=this.yt.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),l=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),l),this.Vn?.(t),this.yt.set(e,t),l&&l.u.push(t),t}all(){return this.yt.values()}jt(e){this.yt.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,l=e.split("."),r=[];for(let e=0;e<l.length;e++){let t=l[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,r.push(Number(t)),l[e]="*"):"*"===t&&r.push(-1)}if(!n)return{o:l.join("."),indexes:r};let i={o:e,indexes:null};return p.size>4095&&p.clear(),p.set(e,i),i}var g=class{constructor(e,t,n){this.bt=null,this.x=null,this.be=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.$=n}},y=class{constructor(e,t){this.R=null,this.f=[],this.x=null,this.B=null,this.te=!1,this.Lt=!1,this.vt=!1,this.o=e,this.ce=t,this.n=e.n+1}},b=[];function v(t,n,l){throw new Error(`[@wcstack/state] ${t}${e.Lo?.(t,n,l)??""}`)}function $(t,n=[]){return e.Bo?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function w(e,t,n,l){v($(e,t),n,l)}var A=class{constructor(e){this.St=new Set,this.name=e}get size(){return this.St.size}subscribe(e){return this.St.add(e),()=>{this.St.delete(e)}}unsubscribe(e){return this.St.delete(e)}emit(...e){let t=[];for(let n of this.St)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${$(17,[this.name])}`,e)}return t}};function k(e,t,n){if(void 0===e)return[];Array.isArray(e)||w(18,[t]);let l=new Set;for(let r of e)("string"!=typeof r||""===r)&&w(19,[t]),r===n&&w(20,[t,r,n]),l.has(r)&&w(21,[t,r]),l.add(r);return e}var x=Symbol.for("wcstack.transition-runner");function S(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function T(e,t,n){let l=S(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var N="else",O="eventToken",j="command",C="class",M="attr",P="style",E=/^\$[1-9]\d{0,2}$/,W=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function I(e){let t=[],n=[],l="",r=null,i=!1,s=-1,o=-1,a=e=>{let r=function(e,t,n){let l=-1===t?e.length:t,r=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,r+e.slice(r).trimEnd().length)}(l,s,o);(!e||r||i)&&(t.push(r),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:W.test(e)?Number(e):e)}(r,i))),l="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];r?n===r?r=null:(-1===s&&(s=l.length),l+=n,o=l.length):'"'===n||"'"===n?(r=n,i=!0):","===n?a():l+=n}return null!==r&&w(107,[r,e]),a(!0),{args:t,literals:n}}var R=e=>e.trim();function D(e,t){let n=[],l=null;for(let r=0;r<e.length;r++){let i=e[r];null!==l?i===l&&(l=null):"'"===i||'"'===i?l=i:i===t&&n.push(r)}return n}var q=(e,t)=>D(e,t)[0]??-1;function L(e,t){let n=[],l=0;for(let r of D(e,t))n.push(e.slice(l,r)),l=r+1;return n.push(e.slice(l)),n}function z(e,t,n){let l=q(e,"|");if(-1===l)return[e.trim(),[]];let r=e.slice(l+1).trim(),i=n.get(r);return void 0===i&&(i=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=q(e,"("),r=(e=>D(e,")").pop()??-1)(e);if(-1===r&&(r=e.lastIndexOf(")")),-1!==n&&-1===r&&w(108,[e]),-1!==r&&-1===n&&w(109,[e]),-1!==r&&r<n&&w(110,[e]),-1!==r&&e.slice(r+1).trim().length>0){let t=e.slice(r+1).trim();w(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&w(112,[l]),i.includes("#")){let[,e]=i.split("#");w("input"===t?113:114,[i,e])}return-1===n?{Hn:i,args:[],literals:[]}:{Hn:i,...I(e.substring(n+1,r))}})}(L(r,"|").map(R),t,e),n.set(r,i)),[e.slice(0,l).trim(),i]}var U=new Map;function F(e){w(1101,[e])}function V(e){let[t,n]=z(e,"output",U);t.includes("@")&&w(32,[t]);let l=t,r=l.startsWith("."),i=r?l.slice(1):l;return(i.length>0&&i.split(".").some(e=>0===e.length)||!r&&0===i.length)&&w(119,[e]),function(e){e.includes("**")&&F(e);let t=e.split(".").length;t>512&&w(117,[e,t])}(l),{Ze:l,et:n}}var _=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&F(e),e}var K=0;function J(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var Y=()=>new Set,G=()=>[],X=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Z(e,t){return e===t||e!=e&&t!=t}function ee(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function te(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ne(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function le(e,t,n){let l=ne(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var re=class{constructor(e,t){this.je=0,this.d=null,this.Le=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.kt=[],this.Be=null,this.Kn=[],this.Ht=0,this.X=null,this.oe=new Map,this.de=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.D=0,this.Kt=0,this.yn=!1,this.qt=!1,this.zt=!1,this.Ce=0,this.qn=()=>{this.D=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.ve++;try{return e()}finally{t.ve--}},$eqIndex:(e,t=1)=>{let n=ne(this.d,t);null===n&&w(7,[e]);let l=this.o(e);if(null!==l.getter||l.ae)return this.watchIndex(t),n.y===this.read(l,null);let r=this.X;if(null!==r){let e=r.getter,n=l.Me??(l.Me=[]);if(!n.some(n=>n.getter===e&&n.Gn===t)){n.push({getter:e,Gn:t});let r=e.h[t];(r.Dt??(r.Dt=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,ne(this.d,n.n)))},$dependOn:e=>{this.resolve(H(e),this.d),null!==this.X&&0===this.X.ve&&this.Jn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.wn(e,t,n,l),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],l=this.o(t,!0);this.bn("$resolve",t,l,n,!0);let r=this.Qn(l,n,null);if(e.length<3)return this.read(l,r);this.P(l,r,e[2])},$postUpdate:e=>{this.resolve(H(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.R[n.y],X.delete(n.l.R),this.A.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.A=t,this.O=new d(e=>{this.He.push(e),this.ot(e)}),this.to(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let r=n.target;if("symbol"==typeof t)return Reflect.get(r,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=r[t];if("function"==typeof e)return l===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(H(t),n.d),n.P(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}no(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let l=Object.getOwnPropertyDescriptor(n,e);if(void 0===l.get&&void 0===l.set)continue;let r=this.o(e);r.getter=l.get??null,r.se=l.set??null,null!==r.getter&&r.n>0&&(r.F=this.je++)}for(let e of this.O.all())this.ot(e)}ot(e){e.t.includes("**")&&F(e.t),("__proto__"===e.s||"prototype"===e.s)&&w(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(E.test(n))e.getter=function(){return this[n]};else{let l=t.split("."),r=l.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(r<0||l.indexOf("*",r)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.c,this.d)?.[n]),e.se=l=>{if(this.resolve(t,this.d),this.rp!==e)return this.P(this.rp,this.rr,l);let r=this.read(e.c,this.d);null==r&&w(4,[t,r]),r[n]=l}}e.hn=!0,e.n>0&&(e.F=this.je++)}Ue(e,t){let n=null===e?this.oe:e.u??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new y(t,e)),t.pn=!0,this.G(l),l}oo(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.x?.S??null,"for")}}G(t){let n=this.v(t.o,t.ce);if(n===t.R)return;this.io(t);let l=function(e,t,n){let l=Array.isArray(t)?t:b;if(l===e.R)return null;let r=e.f,i=l.length,s=r.length,o=new Array(i),a=0;for(;a<i&&a<s&&r[a].$===l[a];)o[a]=r[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&r[u].$===l[c];)o[c]=r[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,l[t]);else if(a>c)for(let e=a;e<=u;e++)n.Bt(r[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)r[e].$===l[e]&&(o[e]=r[e]);let i=new Map;for(let e=u;e>=a;e--){let n=r[e];if(e<=t&&o[e]===n)continue;let l=i.get(n.$);void 0===l?i.set(n.$,n):Array.isArray(l)?l.push(n):i.set(n.$,[l,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,r=l[t],s=i.get(r);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(r)):(n=s,i.delete(r))),o[t]=n??new g(e,t,r)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Bt(t);else n.Bt(e)}for(let e=a;e<i;e++){let t=o[e];t.y!==e&&(t.y=e,n.jo(t))}return e.f=o,e.R=l,r}(t,n,this);if(null===l)return;if(t.R===n){let e=J(this.Ut,n,G);if(e.push(t),e.length>1)for(let t of e)t.vt=!0}e.Qt?.(this,t,l),(null!==t.x||null!==t.B)&&!t.te&&(t.te=!0,this._e.push(t),this.Se());let r=t.o.Dt;if(null!==r)for(let{source:e,getter:n}of r){let r=this.v(e,null),i=l[r],s=t.f[r];i!==s&&(void 0!==i&&i.w&&this.Sn(n,i),void 0!==s&&this.Sn(n,s))}}jo(e){this.A.Ho(this,e)}Bt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)ee(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.R);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=m(e),l=this.rp=this.o(n.o,!0),r=n.indexes;this.rr=0===l.n?null:null===r?le(t,l,l.n):this.Qn(l,r,t,e)}Qn(e,t,n,l){let r=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.Ue(r,a),c=t[o++];if(c<0)c=le(n,e,s)?.y??-1;else if(l&&u.R===b&&Object(i=this.v(a,r))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=l.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(r=u.f[c]??null,null===r)break}return this.rp=e,r}it(e,t){return 0===e.n?te(this.target,e.z):null===t?void 0:te(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.ve&&this.Jn(e,t,n),null!==e.getter)return this.A.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&&w(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.ve++;try{return this.read(e,t)}finally{n.ve--}}Jn(e,t,n){let l=n.getter;e._n(l),0===l.n?e.Z!==n.fe&&(e.Z=n.fe,n.kn.push(e)):e.n>0&&ne(t,Math.min(e.n,l.n))!==ne(n.r,Math.min(e.n,l.n))&&(l.mt??(l.mt=new Set)).add(e)}Ko(e,t){for(let n=0;n<this.Ht;n++){let l=this.Kn[n];l.getter===e&&l.r===t&&w(701,[e.t])}this.Ht>=128&&w(801,[e.t]);let n=this.Ht++;this.Le++;let l=this.Kn[n]??={getter:e,r:t,ve:0,fe:0,kn:[]};l.getter=e,l.r=t,l.ve=0,l.fe=++K,l.kn.length=0;let r=this.X;this.X=l;let i=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.qo(e,l),t}finally{this.Le--,this.Ht--,this.X=r,this.d=i,l.r=null}}qo(e,t){let n=t.fe;for(let e of t.kn)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.Do(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.L.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.jt(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.ve){let n=t.getter,l=n.h[e];if(l){let e=l.Mt??(l.Mt=[]);e.includes(n)||e.push(n)}}}rt(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:E.test(t)?+t.slice(1):0;return(e<1||e>128)&&w(1001,[t]),this.watchIndex(e),ne(this.d,e)?.y}let l=this.Xn[t];if(void 0!==l)return l;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.rt?.(this,t)}eq(e,t){this.resolve(e,this.d);let n=this.rp,l=this.rr;if(null!==n.getter||n.ae||n.n>0)return Z(this.read(n,l),t);let r=this.X;return null!==r&&0===r.ve&&this.Yo(n,t,r),Z(this.v(n,null),t)}Yo(e,t,n){let l=n.getter,r=n.r,i=null===r?this.Yn:r._??(r._=[]);for(let r=0;r<i.length;r++){let s=i[r];if(s.sub.getter===l&&s.source===e){if(Z(s.key,t))return void(s.fe=n.fe);s.fe!==n.fe&&(ee(e,s.key,s.sub),i.splice(r--,1))}}let s={getter:l,r};J(e._??=new Map,t,Y).add(s),i.push({source:e,key:t,sub:s,fe:n.fe})}eo(e,t,n,l){this.Zt(e,r=>{let i=r._;if(null===i&&null===r.Me)return;let s=r===e?[]:r.t.slice(e.t.length+1).split("."),o=te(t,s),a=te(n,s);if(null!==r.Me&&this.Xo(r,o,a,l),null!==i)for(let e of l?i.keys():[o,a]){let t=i.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.w?this.A.ke(this,n.getter,n.r):ee(r,e,n)}})}P(t,n,l,r=!1,i=!1){if(this.Le>0&&w(8),i||this.Ce>0?this.qt=!0:this.zt=!0,e.Ie?.(this,t,n,l,i))return;if(null!==t.se){try{this.En(t.se,n,[l])}finally{this.Gt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&w(2,[t.t]),t.n>0&&null===n&&w(3,[t.t]);let s=t.ae?this.v(t,n):this.it(t,n);if(r||!this._t||!Object.is(s,l)||Object(l)===l){if("*"===t.s){let e=n;e.l.R[e.y]=l,X.delete(e.l.R),e.$=l,this.A.Xt(e)}else{let e=1===t.z.length?0===t.n?this.target:n.$:this.v(t.c,n);null==e&&w(4,[t.t,e]),e[t.s]=l}this.$n(t,n),null!==n&&this.Zn(n,t,s,l),0===t.n&&this.eo(t,s,l),this.Gt(t,n,s,l,!0,i)}}lo(e){return(this.Ut.get(e.R)??[]).filter(t=>t.R===e.R&&(null===t.ce||t.ce.w))}Zn(e,t,n,l,r=!0){let i=e.l,s=t.t.slice(i.o.t.length+2),o=""!==s&&function(e){let t=X.get(e);if(void 0===t){let n=new Set;X.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(i.R);if(!o&&!i.vt&&null===i.o.getter&&!i.o.L.length)return;let a=e.$,u=(t,i)=>{if(void 0===i||i===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(i.$=l,this.A.Xt(i)),r?this.$n(o,i):this.vn(o,i),this.Gt(o,i,n,l,r)};for(let t of this.lo(i))if(u(t,t.f[e.y]),o)for(let n of t.f)n.$===a&&n.y!==e.y&&u(t,n);if(""===s)return;let c=new Set([i.R]),h=e=>Array.isArray(e)&&e.includes(a),d=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.Ut.get(e)??[])for(let e of t.f)e.$===a&&u(t,e);for(let n of t){let t=n.Y,l=t===f;l&&(t=this.oe.get(n)?.R),(l||h(t))&&!c.has(n.L)&&c.add(n.L)&&(!l&&t!==e&&this.A.ke(this,n,null),d(t,n.L))}},p=e=>{for(let t of e.Q)if(!c.has(t)&&c.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.it(t,null);h(e)&&d(e,t.L)}};null!==i.o.getter?p(i.o):d(i.R,i.o.L)}vn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.vt?this.lo(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.$t(e,n),this.vn(e,n)}})}$n(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Xo(e,t,n,l){for(let{getter:r,Gn:i}of e.Me)this.ao(r.h[i],e=>{for(let i of l?e.f.keys():[t,n]){let t="number"==typeof i?e.f[i]:void 0;void 0!==t&&this.Sn(r,t)}})}Sn(e,t){t.l.n===e.n?this.A.ke(this,e,t):this.en(t,e,t=>this.A.ke(this,e,t))}Gt(t,n,l,r,i,s){e.re?.(this,t,n,l,r,i,s),this.Ke(t,n)}Ke(e,t){this.A.Jo(this,e,t),this.Se()}co(e){let t=this.nt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.nt.set(e,n);let l=this.root,r=this.Un;return l.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==l;i=i.parentNode){let l=i[n];if(void 0!==l&&(l(t),t.cancelBubble))return;let s=i[r];if(void 0!==s&&s.w&&s.Qo(e,t))return}}),n}reset(t){let n=this.target,l=this.tt;for(let e of this.O.all())null===e.c&&null!==e.getter&&l.add(e.s);this.to(t);for(let e in n)"$"!==e[0]&&l.add(e);for(let e of l)e in t&&l.delete(e);for(let e of this.de.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.uo(e);this.Be=null;try{this.Yt()}finally{this.xn()}e.element?.(this,"reset")}to(t){for(let[e,n]of _)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||w(46);for(let e of n)a(e,"$features")}let l=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof l||!l||Array.isArray(l))&&w(44,["state","$behavior"]);for(let e in l)(!B.includes(e)||"boolean"!=typeof l[e])&&w(44,["$behavior",e]);let[r,i,s]=B.map(e=>l[e]??!0);void 0!==this.target&&(r!==this.Wt||i!==this._t||s!==this.Vt)&&w(45);let o=function(e,t){let n={};for(let l of k(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new A(l);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new A(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&w(22);for(let[e,r]of Object.entries(l)){let l=n.get(e);void 0===l&&w(23,[e]),"function"!=typeof r&&w(24,[e]),l.subscribe((...e)=>t(r,e))}return n}(t,this._o);this.Wt=r,this._t=i,this.Vt=s,e.pe?.(this,t),this.target=t,this.je=0;for(let e of this.O.all())e.Mo();this.Yn.length=0,this.no(t),this.commands=o,this.ue=u}uo(e){this.oo(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.bt=null,n._=null,this.$t(t,n),null!==n.u)for(let e of n.u.values())this.uo(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}Zo(e,t,n){let l=this.ue.get(e);void 0===l&&w(1301,[e],e,this.ue.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&w(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&w(5,[e]),this.En(l,n,[t,...this.H(n)])}En(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}$t(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.de.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.be;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let l=t.x;null!==l&&null!==l.me&&l.fo(this,e);let r=t.l.B;if(null!==r)for(let n of r){let l=n.map.get(t);void 0!==l&&null!==l.me&&l.fo(this,e)}}Nn(e,t,n){this.Zt(e,e=>{let l=e.L;for(let r=0;r<l.length;r++){let i=l[r];if(0===i.n)this.st(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.mt&&i.mt.has(e))this.nn(i.h[i.n],e=>this.st(i,e,n));else if(i.n<=e.n){let e=ne(t,i.n);null!==e&&this.st(i,e,n)}else this.en(t,i,e=>this.st(i,e,n))}})}st(t,n,l){l(t,n)&&(e.Ee?.(this,t,n),this.$t(t,n),this.Nn(t,n,l))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.ao(e,e=>{for(let n of e.f)t(n)})}ao(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}en(e,t,n){if(e.l.n===t.n)return n(e);let l=e.u?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.en(e,t,n)}nr(e){let t=e.r;null===t?J(this.de,e.o,Y).add(e):(t.be??(t.be=[])).push(e)}Tn(e){let t=e.r;if(null===t)return void this.de.get(e.o)?.delete(e);let n=t.be;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.Se())}Se(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Rn(){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.A.tt(this)}po(t,n){let l=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${$(t)}`,l),e.at?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:l}),this.Rn()}Yt(){this.Et=!1;let t=this.Kt;this.Kt=0;let n=0;if(!this.qt||this.zt?this.qn():t>0?n=t:1===(n=++this.D)&&setTimeout(this.qn,0),this.qt=this.zt=!1,n>100)101===n?this.po(41,100):this.Rn();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.Rn():this.po(11,32),this.yn=!0;break}let t=this.Ve;if(t.length>0){this.Ve=[];for(let e of t)e.Lt=!1,this.oo(e)}let l=this._e,r=this.We;this._e=[],this.We=[];let i=()=>{for(let e of l){e.te=!1;for(let t of[e.x,...e.B??[]])if(null!==t&&t.w)try{t.xt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<r.length;t++){let n=r[t];!n.te||null===n.D==(0===e)||(n.te=!1,(null===n.An||n.An.w)&&this.qe(n))}this.gn||(this.ze(),this.Et&&(this.Kt=n+1))},s=l.length>0||r.some(e=>null!==e.D)?T("state",i):i();void 0!==s&&s.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.qt=this.zt=!1,this.ze(),e.he?.(this),this.zo(),t>0&&this.Et&&(this.Kt=n+1)}}Nt(e,t){this.kt.push([e,t])}Jt(e,t,n,l){this.Nt(e,{o:{t},a:n,on:()=>l})}qe(e){try{e.apply()}catch(t){return void this.kt.push([t,e])}null!==this.Be&&this.mo(e.o,e.r)}mo(e,t){let n=J(this.Be,e.t,G);null!==t&&n.push(this.H(t))}xn(){this.Be="function"==typeof this.target.$renderedCallback?new Map:null}ze(){let t=this.Be;if(null!==t&&t.size>0){this.Be=new Map;let e,n=[...t.keys()],l={};for(let[e,n]of t)n.length>0&&(l[e]=n);this.Ce++;try{e=this.$e("$renderedCallback",[n,l])}catch(e){console.error(e)}Q(e)?e.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.kt.length)return;let n=this.kt;this.kt=[];let l=this.target.$errorCallback;for(let[t,r]of n){e.Ye?.(this,t,r);let n=r.o.t,i=r.on();if("function"==typeof l)try{let e=this.$e("$errorCallback",[t,{path:n,bindingType:i,node:r.a}]);Q(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${$(12,r.name?[i,n,r.name,r.i]:[i,n])}`,t,r.a)}}$e(e,t=[]){let n=this.target[e];return"function"==typeof n?this.En(n,null,t):void 0}ho(e,t,n){if(0===e.n)return void n(null,[]);let l=[],r=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.Ue(s,o),u=t=>{l.push(t.y),i===e.n?n(t,l):r(i+1,t),l.pop()};for(let e of i-1<t.length?[a.f[t[i-1]]]:a.f)void 0!==e&&u(e)};r(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.bn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let r=le(t,n,e);if(null===r)break;l.push(r.y)}0===l.length&&w(6,[e])}}let r=[];return this.ho(n,l,e=>r.push(this.read(n,e))),r}wn(e,t,n,l){Array.isArray(t)||w(9,[e]),this.Le>0&&w(8);let r=this.o(e,!0);this.bn("$setAll",e,r,t,!1);let i=[];this.ho(r,t,(e,t)=>i.push([e,t.slice()]));let s=!0===l?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&w(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,l]=i[e],a="function"==typeof n?n(this.v(r,t),...l):s?n[e]:n;void 0!==a&&(this.P(r,t,a),o++)}return o}bn(e,t,n,l,r){let i=l.length;(i>n.n||r&&i<n.n)&&w(r?901:902,[e,t,n.n,i])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},se=()=>ie,oe=new Map,ae=new Set(["if","elseif","else","for"]),ue=new Set([N,"if","elseif","for","..."]),ce=new Set([C,M,P,j,O,"state"]);function fe(e){let t=function(e){return L(e,";")}(e).map(R).filter(e=>e.length>0).map(e=>{let t=q(e,":");-1===t&&w(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),r=n.split("#")[0].split("|")[0].trim();if(ue.has(r)){let t;return r!==n&&w(102,[e,r]),r===N?(l.length>0&&w(103,[e]),t={Ze:"#else",et:[]}):"..."===r?(0===l.length&&w(104,[e]),t=V(l),t.et.length>0&&w(105,[e])):(t=V(l),"for"===r&&t.et.length>0&&w(121,[e])),{xe:r,Ne:[r],rn:[],M:[],...t,b:"..."===r?"spread":r}}(r===C||r===M)&&w(122,[e,r]);let i=V(l),s=function(e){let[t,n]=z(e,"input",oe),l=t.split("#").map(R);l.length>2&&w(115,[t]);let[r,i]=l,s=r.split(".").map(R);return!(s.length>1&&""===s[0])&&(0===r.length||s.some(e=>0===e.length))&&w(116,[e]),{xe:r,Ne:s,rn:i?i.split(",").map(R):[],M:n}}(n),[o]=s.Ne;if(""===o&&s.Ne.length>1){let e=s.Ne.slice(1);return(e.includes("")||ce.has(e[0]))&&w(106,[n]),{...s,xe:e.join("."),Ne:e,...i,b:"prop"}}return{...s,...i,b:"radio"===r||"checkbox"===r?r:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ae.has(e.b))&&w(201,[e]),t}var he=["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"],de=new Map,pe=new Map;function me(e){for(let t of Object.keys(e))de.set(t,{...e[t]});pe.clear()}function ge(e){return de.has(e)}function ye(e){w(26,[e])}function be(e){w(27,[e])}function ve(e,t){w(28,[e,t])}function $e(e,t){w(29,[e,t])}function we(e){return!(!e||isNaN(Number(e)))}function Ae(e,t){return we(e)||be(t),Number(e)}function ke(e,t,n){return Ae(e?.[t]??ye(n),n)}function xe(e,t){return void 0!==t&&t.length>0?t[0]:e}var Se=(e,t)=>({factory:n=>{let l=ke(n,0,e);return n=>("number"!=typeof n&&ve(e,n),t(n,l))},arity:[1,1]}),Te={eq:{factory:(e,t)=>{let n=e?.[0]??ye("eq"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(we(n)||be("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??ye("ne"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(we(n)||be("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Se("lt",(e,t)=>e<t),le:Se("le",(e,t)=>e<=t),gt:Se("gt",(e,t)=>e>t),ge:Se("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ne=!1;function Oe(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function je(e){return 0===e.length?null:(Ne||(Ne=!0,me(Te)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,r=pe.get(l);if(typeof r<"u")return r;let i=de.get(e);void 0===i&&function(e,t){he.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),w(501,[e],e,t)}(e,de.keys());let[s,o]=i.arity;t.length<s&&w(601,[e,s,t.length]),t.length>o&&w(602,[e,o,t.length]);let a=i.factory(t,n);return pe.set(l,a),a}(e.Hn,e.args,e.literals)))}var Ce=Symbol.for("wcstack.trustedTypes.policy");function Me(){let e=globalThis[Ce];return null!==e&&"object"==typeof e?e:null}function Pe(e){globalThis[Ce]=e}function Ee(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function We(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Me(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Ie=Symbol.for("wcstack.state.view-transition-naming"),Re=new WeakSet;function De(){let e=S("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var qe=new WeakMap,Le=e=>e.customElementRegistry??customElements;function ze(e,t,n,l,r,i=!1){let s=n.localName;if(!s.includes("-"))return r(null);let o=Le(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>ze(e,t,n,l,r,!0));let a=()=>{let e=o.get(s);o.upgrade(n),r(e?function(e){if(qe.has(e))return qe.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 qe.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==l&&!l.w||function(e,t,n){let l=n;null!==t&&(t.Tt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(o.whenDefined(s),l,()=>{try{a()}catch(l){He(e,l,t,n)}e.Se()})}function Ue(t,n,l,r,i=n.o,s,o,a){let u=a.properties.get(r)??null,c=a.inputs.has(r),f=t.Vt;f&&null===u&&!c&&w(38,[r]);let h=n.U;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&w(39,[h,r]),"connect"===n.G&&null===u&&w(40,[r]);let d=f&&null!==u&&!c,p=new Ye(t,_e,l,r,i,s,o,n.N,void 0);p.M=n.M,lt(t,p,!d),null!==u&&!n.ro&&l.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.go||e.detail?.(l,r,i)),(!p.Pn||!Object.is(i,p.value))&&(i=Oe(p.M,i),null===p.N&&(p.value=i),t.P(p.o,p.r,i,u.go,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.qe(p);else if("element"===m||"auto"===m){let e=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==t.v(p.o,p.r))return void(d||t.qe(p));let e=l[r];null===p.N&&(p.value=e),t.P(p.o,p.r,e,!1,!0)};"connect"!==n.G||l.isConnected?e():Promise.resolve().then(e)}return p}function Fe(e,t,n){w(e,[t.localName,n])}var Ve=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),_e=11,Be=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],He=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Rt,l,Be[n.i]),Ke=Symbol();function Je(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.K:Ke}var Ye=class{constructor(e,t,n,l,r,i,s,o,a,u=null){this.te=!1,this.M=null,this.Pn=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=r,this.r=i,this.An=s,this.N=o,this.value=a,this.D=u}on(){return Be[this.i]}apply(){if(null!==this.D)return void this.D.xt();let e=Oe(this.N,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===_e||8===this.i||Ee(this.name)))return;if(this.value===Ke)return void(this.value=e);let t=this.a;if(this.i!==_e)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Xe(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.Pn=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.Pn=!1}}}sn(){return Oe(this.M,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),r=n.v(this.o,this.r),i=Array.isArray(r)?r:[],s=i.includes(l);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==l):[...i,l]}else e=Oe(this.M,t[this.name]),this.value=NaN;n.P(this.o,this.r,e,!1,!0)}},Ge=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Xe(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ge(n)?t[n]="innerHTML"===n?We(l):null==l?"":String(l):Ee(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=We(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Qe]=[n,l])));case 8:return void(t.innerHTML=We(l));case 2:return null!=l&&"boolean"!=typeof l&&w(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Qe=Symbol();function Ze(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Qe];void 0!==n&&(t[n[0]]=n[1])}var et=class{constructor(e,t,n,l){this.w=!0,this.be=null,this.u=null,this.Tt=null,this.On=null,this.r=e,this.ct=t,this.j=n,this.C=l}Qo(e,t){let n=t.target,l=this.C,r=[],i=null;for(let t of l.ue){if(t.name!==e)continue;let s=l.Cn[t.a],o=ht(null===this.j?this.ct:this.j[s[0]],s,1);o.contains(n)&&(o!==i&&r.unshift([]),r[0].push(t),i=o)}for(let e of r){for(let n of e)n.Fn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.j?this.ct:this.j[this.j.length-1]}Re(){let e=this.On;return(null===e?null:e.In(this.ct))??this.ct}insertBefore(e,t){let n=this.s;for(let l=this.Re();;){let r=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=r}}bo(){null===this.j?this.ct.remove():dt(this.Re(),this.s)}Ae(e){if(this.w=!1,null!==this.Tt)for(let e of this.Tt)e();let t=this.be;if(null!==t)for(let n=0;n<t.length;n++)e.Tn(t[n]);if(null!==this.u)for(let e of this.u)e.Ae()}},tt=class extends et{constructor(e,t,n,l){super(e,t,n,l),this.vo=0,this.V=null,this.me=0===l.Xe.length?null:new Array(2*l.Xe.length)}So(e,t){let n=this.V??=new Array(this.C.Xe.length),l=n[t];if(void 0===l){let r=this.C.Xe[t],i=this.me;l=n[t]=new Ye(e,r.i,i[2*t],r.name,r.o,this.r,this,r.N,i[2*t+1])}return l}fo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.So(e,l))}Ae(e){let t=this.r;t.x===this&&(t.x=null),super.Ae(e)}};function nt(e,t,n,l){let r=ne(n,t.n);try{return e.Ue(r,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===r?e.oe.get(t):r.u.get(t)}}function lt(e,t,n){n&&e.nr(t);let l=t.An;null!==l&&(l.be??=[]).push(t)}var rt=null;function it(){let e=rt;return rt=null,e}var st=-1;function ot(t,n,l,r,i=null){let s,o=n.Cn,a=n.build,u=n.ko,c=null,f=e.Pe?.(n,null===r?i:r.S,null!==r),h=!f&&n.Dn,d=f?document.createDocumentFragment():(h?n.root:n.ln).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=ht(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==r?(p=m=new tt(l,s,c,n),null===r.map?l.x=m:r.map.set(l,m)):p=new et(l,s,c,n),st>=0&&function(e,t,n,l){let r=null;if(null===t)r=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===r;e++)1===t[e].nodeType&&(r=t[e]);let i=r?.style;if(null===r||void 0===i||Re.has(r))return;let s=globalThis[Ie]??={counter:0,assigned:0,warned:!1};s.assigned>=l?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${$(25,[l])}`)):(Re.add(r),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==r?"row":"branch",st),n.ue.length>0){let e=t.Un;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.sr,y=t.Be,b=n.lr?u.slice(0,o.length):u,v=null===m?null:m.me;if(null!==v){let e=n.Xe;for(let t=0;t<e.length;t++)v[2*t]=b[e[t].a],v[2*t+1]=e[t].K}for(let e=0;e<g.length;e++){let n=g[e],r=b[n.a],i=n.F;if(i>=0&&null!==v){let e=m.V?.[i];if(void 0!==e){e.te=!1,t.qe(e);continue}try{let e=Oe(n.N,t.read(n.o,l));e!==n.K&&(Xe(n.i,r,n.name,e),v[2*i+1]=e),null!==y&&t.mo(n.o,l)}catch(e){t.Nt(e,m.So(t,i))}continue}switch(n.i){case 6:{let e=new ft(t,n.C,nt(t,n.o,l,r),r);(p.u??=[]).push(e),r===s&&(p.On=e),e.xt();break}case 7:{let e=ut(t,n.q.map(e=>({C:e.C,o:e.o,N:e.N,S:b[e.a]})),l,p);(p.u??=[]).push(e),r===s&&(p.On=e);break}default:try{at(t,n,r,l,p)}catch(e){He(t,e,n,r)}}}return rt=p,d}function at(t,n,l,r,i){let s=l;switch(n.i){case 5:return void function(e,t,n,l,r){let i=n.Fn,s=e=>i(e,l);if(n.nt){let l=e.co(n.name),r=t[l];t[l]=void 0===r?s:e=>{r(e),s(e)},n.Te&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.wo&&null!==r&&(r.Tt??=[]).push(()=>t.removeEventListener(n.name,s))}(t,l,n,r,i);case 12:return void ze(t,n,s,i,l=>function(t,n,l,r,i){let s=n.name,o=t.command(n.Rt.slice(9)),a=null===i?e.or?.(l,s):null;a||(null===i&&Fe(1202,l,`command.${s}`),i.commands.has(s)||w(1203,[l.localName,s]));let u=new WeakRef(l),c=o.subscribe((...e)=>{let t=u.deref();if(void 0!==t)return t.isConnected?a?a(t,e):t[s](...e):void 0;c()});null!==r&&(r.Tt??=[]).push(c)}(t,n,s,i,l));case 13:return void ze(t,n,s,i,e=>function(e,t,n,l,r){let i=t.name;null===r&&Fe(1202,n,`eventToken.${i}`);let s=r.properties.get(i);void 0===s&&w(1204,[n.localName,i]);let o=t.Rt;n.addEventListener(s.event,n=>{t.At&&n.preventDefault(),t.Pt&&n.stopPropagation();try{e.Zo(o,n,l)}catch(e){console.error(e)}})}(t,n,s,r,e))}let o=n.o,a=ne(r,o.n);if(14===n.i)return void ze(t,n,s,i,e=>function(e,t,n,l,r,i){null===i&&Fe(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.yo?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:l;Ue(e,{...t,U:null,G:null},n,o,s,a,r,i)}}(t,n,s,a,i,e));if(n.Te&&1===n.i)return void ze(t,n,s,i,l=>function(t,n,l,r,i,s){if(null!==s)return void Ue(t,n,l,n.name,n.o,r,i,s);let o=new Ye(t,1,l,n.name,n.o,r,i,n.N,Je(t,n,r));o.M=n.M,!e.ar?.(o,n.ro)&&(lt(t,o,!0),t.qe(o))}(t,n,s,a,i,l));let u=new Ye(t,n.i,l,n.name,o,a,i,n.N,Je(t,n,a));u.M=n.M,lt(t,u,!0),t.qe(u),null!==n.Ft&&l.addEventListener(n.Ft,()=>u.ir())}function ut(e,t,n,l){let r=new ct(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Ye(e,7,s.S,"if",t,ne(n,t.n),l,null,void 0,r);lt(e,o,!0),null===l&&r.de.push(o),i??=o}return e.qe(i),r}var ct=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.de=[],this.engine=e,this.q=t,this.r=n}In(e){return null!==this.I&&this.q[this.y].S===e?this.I.Re():null}xt(){let e=this.engine,t=-1;for(let n=0;n<this.q.length;n++){let l=this.q[n];if(null===l.o||Oe(l.N,e.read(l.o,ne(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(st=De(),null!==this.I&&(this.I.bo(),this.I.Ae(e),this.I=null),this.y=t,t>=0)){let n=this.q[t],l=ot(e,n.C,this.r,null,n.S);this.I=it();let r=n.S.parentNode;r.insertBefore(l,n.S),Ze(r)}}Ae(){this.w=!1;for(let e of this.de)this.engine.Tn(e);null!==this.I&&this.I.Ae(this.engine)}},ft=class{constructor(e,t,n,l){this.w=!0,this.Fe=[],this.engine=e,this.C=t,this.l=n,this.S=l,null===n.x?(n.x=this,this.map=null):((n.B??=[]).push(this),this.map=new Map)}In(e){return 0===this.Fe.length?null:this.Fe[0].Re()}Ot(e){return null===this.map?e.x:this.map.get(e)??null}jt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ae(this.engine)}xt(){let e=this.engine,t=this.l.f,n=this.Fe;st=De();let l=t.length,r=n.length,i=this.S,s=i.parentNode;if(0===l){if(r>0){let e=n[0].Re(),t=n[r-1].s,l=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){l=null;break}l.push(n)}null!==l?s.replaceChildren(...l):dt(e,t);for(let e=0;e<r;e++)this.jt(n[e])}return void(this.Fe=[])}let o=new Array(l),a=0;for(;a<l&&a<r&&this.Ot(t[a])===n[a];)o[a]=n[a],a++;let u=r-1,c=l-1;for(;u>=a&&c>=a&&this.Ot(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],l=t.r;l.w&&this.Ot(l)===t?t.vo=e:(t.bo(),this.jt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(r>0)for(let e=0;e<n;e++){let n=this.Ot(t[a+e]);null!==n&&n.w?(u[e]=n.vo,f=!0):u[e]=-1}let h=c+1<l?o[c+1].Re():i;if(f){let l=function(e){let t=e.length,n=new Uint8Array(t),l=new Int32Array(t).fill(-1),r=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=r.length;for(;i<s;){let n=i+s>>1;e[r[n]]<t?i=n+1:s=n}i>0&&(l[n]=r[i-1]),r[i]=n}let i=r.length>0?r[r.length-1]:-1;for(;i>=0;)n[i]=1,i=l[i];return n}(u),r=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Ot(n);null!==u&&u.w?0===l[i]&&u.insertBefore(s,r):(s.insertBefore(ot(e,this.C,n,this),r),u=it()),o[a+i]=u,r=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(ot(e,this.C,t[l],this)),o[l]=it();s.insertBefore(n,h)}}this.Fe=o,Ze(s)}Ae(){this.w=!1;let e=this.l;if(e.x===this)e.x=null;else if(null!==e.B){let t=e.B.indexOf(this);t>=0&&e.B.splice(t,1),0===e.B.length&&(e.B=null)}for(let e of this.Fe)e.Ae(this.engine);this.map?.clear()}};function ht(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let l=t[n];l>0;l--)e=e.nextSibling}return e}function dt(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var pt=()=>ie.bindAttributeName;function mt(){return{a:0,i:1,name:"",o:null,N:null,K:c,Fn:null,C:null,q:null,M:null,Ft:null,Te:!1,U:null,G:null,ro:!1,At:!1,Pt:!1,Rt:null,yo:null,F:-1,nt:!1,wo:!1}}var gt=["state","element","auto","none"],yt=["call","connect"],bt="$command.";function vt(t,n,l){E.test(n)&&(null===l&&w(1401,[n,Number(n.slice(1))]),n=`${l.t}.*.${n}`);let r=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&w(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,l)),i=null===l?0:l.n+1;r.n>i&&w(1401,[r.t,r.n,i]);for(let e=1;e<=r.n;e++){let t=e===i?l:l.h[e];r.h[e]!==t&&w(1403,[r.t,r.h[e].t,t.t])}return e.Eo?.(t,r),r}var $t=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),wt=e=>8===e.i||$t(e)||1===e.i&&Ge(e.name);function At(e){w(202,[e])}function kt(t,n,l,r,i){let s=fe(n).map(n=>function(t,n,l,r,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,r=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||w(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&w(33,[i,n]),null!==(o?l:r)&&w(34,[i]),(o?gt:yt).includes(s)||w(35,[i,s]),o?l=s:r=s}return{ro:t.includes("ro"),At:t.includes("prevent"),Pt:t.includes("stop"),event:n?n.slice(2):null,U:l,G:r}}(t,n.rn),o=r.localName.includes("-"),a=n.Ne,u=n.Ze;if("event"===n.b){if(null!==s.U&&"none"!==s.U&&w(36),"eventToken"===a[0])return{...mt(),a:i,i:13,name:a.slice(1).join("."),Rt:u,Te:o,At:s.At,Pt:s.Pt};let l=u.startsWith(bt)?u.slice(9):null,{At:r,Pt:c}=s,f=n.xe.slice(2),h=n.rn.includes("direct"),d=!h&&Ve.has(f);d&&t.co(f);let p=n=>{console.error(n),d&&e.handlerThrew?.(t,u,f)};return{...mt(),a:i,i:5,name:f,nt:d,Te:o,wo:h,Fn(e,n){r&&e.preventDefault(),c&&e.stopPropagation();try{if(null!==l)t.er(l,e,n);else{let l=t.tr(u,e,n);Q(l)&&l.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===n.b)return{...mt(),a:i,i:14,o:vt(t,u,l),Te:o};if("command"===a[0]&&a.length>1)return u.startsWith(bt)||w(1201,[n.xe,u]),{...mt(),a:i,i:12,name:a.slice(1).join("."),Rt:u,Te:o};let c=vt(t,u,l),f={...mt(),a:i,i:1,name:n.xe,o:c,N:je(n.et),M:je(n.M),ro:s.ro,U:s.U,G:s.G};if("radio"===n.b||"checkbox"===n.b)return("element"===s.U||"auto"===s.U)&&w(37,[n.b,s.U]),f.i="radio"===n.b?9:10,s.ro||(f.Ft=s.event??"input"),f;if(a.length>1){let e=a.slice(1).join("."),t=a[0];if("class"===t||"attr"===t||"style"===t)return f.U=null,f.name=e,"class"===t?(f.i=2,f.K=r.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===r.localName?1:3:4,f}return"html"===n.xe?(f.i=8,f):(f.name="text"===n.xe?"textContent":n.xe,f.Te=o&&!Ee(f.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,f.name)&&(f.Ft=s.event??("select"===r.localName?"change":"input")),f)}(t,n,l,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 xt=/\{\{([\s\S]+?)\}\}/g;function St(e){let t=e.data,n=[],l=0;xt.lastIndex=0;for(let r=xt.exec(t);null!==r;r=xt.exec(t)){let i=xt.lastIndex-r[0].length;i>l&&e.before(t.slice(l,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({a:s,cr:r[1].trim()}),l=xt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function Tt(e,t,n,l){let r=function(e){return{xe:"textContent",Ne:["textContent"],rn:[],M:[],...V(e),b:"text"}}(t);return{...mt(),a:l,i:0,o:vt(e,r.Ze,n),N:je(r.et),K:""}}function Nt(e){let t=e.getAttribute(pt());if(null===t)return null;let n=fe(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var Ot=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function jt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:vt(e,l.Ze,n),N:"else"===l.b?null:je(l.et)}),r=[l(t,Nt(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=Nt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(r.push(l(e,t)),"else"===t.b))break}return r}var Ct=new WeakSet;function Mt(t,n,l,r,i,s,o,a){let u=(n,l)=>{let i=document.createComment(l);return n.replaceWith(i),r&&e.Mn?.(t,i,n),i},c=n=>{for(let f=0;f<n.length;f++){let h=n[f];if(null!==h.parentNode)if(1===h.nodeType){let n=h,a=n.localName;if(n.hasAttribute(pt()+"-ignore"))continue;if(r){if("script"===a||"style"===a||Ct.has(n))continue;if(Ct.add(n),a===ie.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?Nt(n):null;if(null!==f){if("for"===f.b){let e=vt(t,f.Ze,l),r=Wt(t,n,e,!0);i(u(n,ie.commentForPrefix),e,r)}else"if"===f.b?s(jt(t,n,l).map((e,n)=>({C:Wt(t,e.el,l,!1),o:e.o,N:e.N,S:u(e.el,Ot(n,e))}))):At(f.b);continue}let d=n.getAttribute(pt()),p=null===d?null:kt(t,d,l,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some(wt)&&!e.$o?.(n);try{r&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!r&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t.Wt&&h.data.includes("{{")&&!Ct.has(h))for(let{a:e,cr:t}of St(h))a(e,t);else if(8===h.nodeType){let e=Pt.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),a(t,e[1])}}}};c(n)}var Pt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Et=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Wt(e,t,n,l){let r=document.importNode(Et(t),!0),i=[],s=[],o=e=>i.push(e)-1;Mt(e,[...r.childNodes],n,!1,(e,t,n)=>{s.push({...mt(),a:o(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({a:o(e.S),C:e.C,o:e.o,N:e.N}));s.push({...mt(),a:t[0].a,i:7,q:t})},(e,t)=>{let n=o(e);for(let e of t)$t(e)&&w(203,[e.name]),e.a=n;s.push(...t),e.removeAttribute(pt())},(t,l)=>{s.push(Tt(e,l,n,o(t)))}),qt(r,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let l=t;l!==e;l=l.parentNode){let e=0;for(let t=l.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(r,e)),u=1===r.childNodes.length&&8!==r.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of s){if(5===e.i&&e.nt&&!e.Te&&!It(i[e.a],r)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Rt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.q)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:r,root:u?r.firstChild:null,Cn:a,build:g,ue:d,sr:p,Dn:u,lr:c,ko:[],Xe:f}}function It(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 Rt(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.Te&&null===e.Ft;default:return!1}}var Dt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function qt(e,t,n){for(let l=e.firstChild;null!==l;){let e=l.nextSibling;3===l.nodeType?n&&!t.has(l)&&""===l.data.trim()&&l.remove():1===l.nodeType&&qt(l,t,Dt.has(l.localName)),l=e}}var Lt=new WeakMap;function zt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Lt.set(t,e),Ft(e,[...n.childNodes]),e.ze()}function Ut(e,t,n){try{let l="template"===t.localName?Nt(t):null;null!==l&&!n&&w(204,[l.b]),Ft(e,[t])}catch(e){console.error(e)}e.ze()}function Ft(t,n){Mt(t,n,null,!0,(e,n,l)=>{new ft(t,l,nt(t,n,null,e),e).xt()},e=>{ut(t,e,null,null)},(n,l)=>{e.Mn?.(t,n,l);for(let e of l)at(t,e,n,null,null)},(n,l)=>{e.Mn?.(t,n,l),at(t,Tt(t,l,null,0),n,null,null)})}var Vt=Symbol.for("wcstack.binder"),_t=Symbol.for("wcstack.binder.pending"),Bt=Symbol.for("wcstack.binder.taken");var Ht=new Map;function Kt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Lt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ht.set(e,t):Ut(n,e,t?.range)}function Jt(){let e=[...Ht];Ht.clear();for(let[t,n]of e)Kt(t,n);!function(){let e=function(){let e=globalThis[Vt];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[_t];return void 0===t&&(t=[],e[_t]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Bt];return void 0===t&&(t=new WeakSet,e[Bt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Yt=class{constructor(){this.name="dirty",this.Z=(e,t)=>{if(0===e.n){let t=e.Y;return t!==c&&t!==f&&(e.Y=f,!0)}let n=null===t?null:t.bt;if(null===n)return!1;let l=n[e.F];return l!==c&&l!==f&&(n[e.F]=f,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.$t(t,n),e.Nn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Mt;if(null!==n)for(let l of n)l.n===t.l.n?e.st(l,t,this.Z):e.en(t,l,t=>e.st(l,t,this.Z))}ke(t,n,l){this.Z(n,l),e.Ee?.(t,n,l),t.$t(n,l),t.Nn(n,l,this.Z)}Uo(e,t,n){let l=0===t.n;if(!l&&null===n)return;let r=l?null:n.bt??=new Array(e.je).fill(c),i=null===r?t.Y:r[t.F];if(i!==c&&i!==f&&i!==h&&(null===r||t.F in r))return i;i=h;try{return i=e.Ko(t,null===r?null:n)}finally{null===r?t.Y=i:r[t.F]=i}}Xt(e){e.bt=null}tt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===f&&(t.Y=h):e.nn(t.h[t.n],e=>{let n=e.bt;null!==n&&n[t.F]===f&&(n[t.F]=h)}))}},Gt=0,Xt=new WeakMap;function Qt(e,t=e.getRootNode()){Xt.set(t,[...Xt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Zt(e){let t=Xt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Xt.get(e)!==t?Zt(e):Promise.reject(l.errors[0]):void 0)}var en=typeof HTMLElement>"u"?class{}:HTMLElement,tn=class extends en{constructor(){super(),this.engine=null,this.jn=!1,this.Ye=!1,this.K=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.xo=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Zt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.jn){if(null!==this.Ge)return void this.Ge.Je();Qt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!Lt.has(n)&&Lt.set(n,t),Jt(),e.element?.(t,"back"),this.No("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.jn=!0;let t=this.getRootNode(),n=e.ut?.(this,t);if(n)return this.Ge=n,!n.To&&this.parentNode instanceof ShadowRoot&&Qt(this),void(void 0===n.It?this.Ro():n.It()).then(e=>(this.loaded=!0,n.start(e,()=>this.Ao()))).then(()=>{this.an(),this.cn()},e=>this.Nt(e,n.To));this.start(t),Qt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Ln();let t=this.engine;if(null===t)return;let n=t.root;Lt.get(n)===t&&Lt.delete(n),Qt(this,n),this.No("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.Ye&&w(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.K=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&w(15),"readonly"===e&&n.Le++;try{t(n.proxy)}finally{"readonly"===e&&n.Le--}}async createStateAsync(e,t){let n=this.engine;null===n&&w(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let l=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&w(8),l(...e)):l},set(){w(8)}}))}async Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${$(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||w(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let l=this.querySelector('script[type="module"]');return null!==l?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let l="function"==typeof URL.createObjectURL,r=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Gt}`);try{return(await(import(r))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?$(42):$(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(r)}}(l):null!==this.K?Promise.resolve(this.K):new Promise(e=>{this.un=e})}async start(t){try{let n=t.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||n?.hasAttribute("data-wc-definition"))&&a("scopes","<wcs-state>");let l=await this.Ro(),r=o(l);if(r&&await r,this.getRootNode()!==t)return this.K=l,this.jn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=Lt.get(t)?.element;i?.isConnected&&(i.V||i.Ge)&&w(47);let s=new re(l,new Yt);s.element=this,this.engine=s,e.element?.(s,"mounting"),zt(s,t),Jt(),s.xn(),this.Ao(),await s.$e("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.cn()}catch(e){this.Ye=!this.V,this.Nt(e)}}Ao(){this.V=!0,this.an()}Nt(e,t){this.ze(this.V?50:49,e),this.an(),t?this.cn():this.xo(e)}ze(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${$(e,[this.localName,...n])}`,t)}No(e,t,n){(async()=>this.engine.$e(e))().then(n,e=>this.ze(t,e))}},nn=[];function ln(){return(nn=nn.filter(e=>e.deref())).map(e=>e.deref())}function rn(t,n){t&&function(e){let t=ie,n=ie.tagNames,l=Object.entries(e).filter(([,e])=>void 0!==e),r=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of l){let l=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof l||Array.isArray(n)!==Array.isArray(l))&&w(44,["bootstrapState",e])}for(let[e,t]of r)(!Object.hasOwn(n,e)||"string"!=typeof t)&&w(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of l)"tagNames"!==e&&(t[e]=n);for(let[e,t]of r)n[e]=t}(t),function(t=customElements){(function(){let e=globalThis;void 0===e[Vt]&&(e[Vt]={protocol:"wcs-binder",version:1,bind:Kt})})(),ln().includes(t)||nn.push(new WeakRef(t));let n=ie.tagNames.state;void 0===t.get(n)&&t.define(n,class extends tn{}),e.Po?.(t)}(n)}var sn,on=e=>Zt(e),an=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},un="en";function cn(){if(ie.locale!==sn){sn=ie.locale;try{un=Intl.getCanonicalLocales(sn)[0]}catch{console.warn(`[@wcstack/state] ${$(48,[sn])}`),un="en"}}return un}var fn=["full","long","medium","short"];function hn(e,t){let[n,l]=e??[];return void 0===l&&void 0!==n&&fn.includes(n)&&([n,l]=[void 0,n]),void 0!==l&&!fn.includes(l)&&function(e,t){w(52,[e,t])}(t,l),[n,l]}var{eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,falsy:$n,truthy:wn,boolean:An}=Te,kn={toFixed:{factory:e=>{let t=Ae(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ve("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ve("locale",e),e.toLocaleString(t??cn()))},arity:[0,1]},upper:{factory:an(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:an(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:an(()=>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:an(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:an(e=>{let t=[ke(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(Ae(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:an(e=>{let t=ke(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:an(e=>{let t=ke(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:an(e=>{let t=ke(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:an(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:an(e=>{let t=ke(e,0,"truncate"),n=e?.[1]??"…";return e=>{let l=String(e);return l.length<=t?l:l.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||w(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ve("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ve("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ve("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=Ae(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ve("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:an(e=>{let t=e?.[0]??ye("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=hn(e,"date"),l=n&&{dateStyle:n};return e=>(e instanceof Date||$e("date",e),e.toLocaleDateString(t??cn(),l))},arity:[0,2]},time:{factory:e=>{let[t,n]=hn(e,"time"),l=n&&{timeStyle:n};return e=>(e instanceof Date||$e("time",e),e.toLocaleTimeString(t??cn(),l))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=hn(e,"datetime"),l=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||$e("datetime",e),e.toLocaleString(t??cn(),l))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||$e("ymd",e);let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),r=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||$e("hms",e);let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),r=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,add:Se("add",(e,t)=>e+t),sub:Se("sub",(e,t)=>e-t),mul:Se("mul",(e,t)=>e*t),div:Se("div",(e,t)=>e/t),mod:Se("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ve("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ke(e,0,"clamp"),n=ke(e,1,"clamp");return e=>("number"!=typeof e&&ve("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:$n,truthy:wn,defaults:{factory:(e,t)=>{let n=xe(e?.[0]??ye("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=xe(e?.[0]??ye("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:An,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]??ye("currency"),n=e?.[1],l={style:"currency",currency:t};try{new Intl.NumberFormat("en",l);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){w(53,[e])}(t)}return e=>("number"!=typeof e&&ve("currency",e),e.toLocaleString(n??cn(),l))},arity:[1,2]}},xn=Object.fromEntries(Object.entries(kn).filter(([e])=>!(e in Te))),Sn=!1,Tn={name:"formats",install:function(){Sn||(Sn=!0,me(kn))}};function Nn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let l=new Array(t.length+1),r=new Array(t.length+1);for(let e=0;e<=t.length;e++)l[e]=e;for(let n=1;n<=e.length;n++){r[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;r[i]=Math.min(l[i]+1,r[i-1]+1,l[i-1]+s)}for(let e=0;e<=t.length;e++)l[e]=r[e]}return l[t.length]}function On(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,r=3;for(let e of t){let t=Nn(n,e.toLowerCase(),2);t<r&&(l=e,r=t)}return null!==l?` Did you mean "${l}"?`:""}var jn=" Validate statically: npx @wcstack/lint <file>.",Cn=["","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"],Mn=e=>{let t=Cn[e/100|0];return t?`[wcs/${t}] `:""},Pn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],En=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Wn=["","","class.","attr.","style."],In=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Rn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Dn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,l)=>`binding "${n?(Wn[l]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Rn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Rn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${En(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${En(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,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&&Pn.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)=>`${In(e,t)} failed to initialize.`,50:(e,...t)=>`${In(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${In(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,l)=>`${e}("${t}") takes ${n} index(es), got ${l}.`,902:(e,t,n,l)=>`${e}("${t}") takes at most ${n} index(es), got ${l}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function qn(e,t){let n=Dn[e];return void 0===n?`${Mn(e)}#${e} ${t.join(" ")}`:Mn(e)+n(...t)}var Ln=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),zn=[[/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.']],Un={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Fn(e,t,n){let l=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(Un,e)?Un[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?On(t,n):"");for(let[t,n]of zn){let r=t.exec(e);null!==r&&(l+=n.replace(/\$(\d)/g,(e,t)=>r[Number(t)]))}let r=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==r&&(l+=` — write "${r[1]}#${r[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?l+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':he.some(ge)||(l+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&Ln.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=jn),l}var Vn=new WeakMap,_n=new WeakMap,Bn=new WeakSet,Hn=new WeakSet;function Kn(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 Jn(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 Yn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let l=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==Kn(e.target,t.t)?.get?t:e.O.wt(m(t.t).o)}(e,t);return n.some(e=>null!=l(e)?.getter)?null:Gn(e,n,0,e.target,l)}function Gn(e,t,n,l,r){for(;n<t.length;n++){let i=t[n];if(null===l||"object"!=typeof l)return null;if("*"===i.s){if(!Array.isArray(l)||0===l.length)return null;let i=null;for(let s of l){let l=Gn(e,t,n+1,s,r);if(null===l)return null;if(null===i)i=l;else if(l.seg===i.seg)for(let e of l.names)i.names.includes(e)||i.names.push(e)}return i}if(Array.isArray(l)&&/^\d+$/.test(i.s)){if(Number(i.s)>=l.length)return null;l=l[Number(i.s)];continue}let s=Kn(l,i.s);if(void 0===s&&null===i.c&&e.tt.has(i.s))return null;if(void 0===s){let s=Jn(l),o=r(i.c);for(let t of e.O.all())t.c===o&&null!==t.getter&&s.push(t.s);return{seg:i.s,names:s,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==s.get||void 0!==s.set)return null;l=s.value}return null}function Xn(t){Bn.has(t)||(Bn.add(t),setTimeout(()=>function(t){Bn.delete(t);let n=Vn.get(t);if(void 0===n)return;let l=_n.get(t);void 0===l&&_n.set(t,l=new Set);let r=new Map(n),i=new Map;for(let e of t.O.all()){let t=null===e.c||l.has(e)||n.has(e)?void 0:e.L.find(e=>!e.hn);void 0!==t&&(i.set(e,t),r.set(e,3))}for(let[n,s]of r){if(l.has(n))continue;l.add(n);let r=Yn(t,n);if(null===r)continue;let o=[...t.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Hn.has(e)&&(n.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==o){l.delete(n),o.initializePromise.then(()=>{Hn.add(o),Xn(t)});continue}let a=t.O.wt(m(n.t).o),u="";if(void 0!==a&&a!==n&&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 c=On(r.seg,r.names);if((r.r||3===s)&&""===c&&""===u)continue;let[f,h,d]=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"];e.at?.(t,{type:"state:path-unresolved",source:d,path:n.t,missingSegment:r.seg}),console.warn(`[@wcstack/state] [wcs/${f}] ${h} "${n.t}"${3===s?` read by the getter "${i.get(n).t}"`:""} does not resolve on the state tree: "${r.seg}" is not declared.${c}${u} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${jn}`)}}(t),0))}function Qn(e,t,n=!1){Zn(e,t,n?1:0)}function Zn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let l=Vn.get(e);void 0===l&&Vn.set(e,l=new Map),l.has(t)||l.set(t,n),Xn(e)}var el=new WeakSet,tl=!1,nl=new WeakMap;function ll(e,t){let n=nl.get(e),l=t.s;if(null!==t.c||tl||void 0===n||n.has(l)||"$"===l[0]||e.tt.has(l))return;let r=On(l,[...n]);n.add(l),""!==r&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${l}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${l}" is not declared: writing it creates a new key.${r}${jn}`)}var rl=new WeakSet;function il(e){if(rl.has(e))return;rl.add(e);let t=e.emit,n=!1;e.emit=(...l)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${jn}`)),t.apply(e,l))}var sl=new WeakMap;function ol(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:Kn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let r=sl.get(e);void 0===r&&sl.set(e,r=new Set),!r.has(t)&&(r.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(…).${jn}`))}function al(e){Vn.has(e)&&e.He.length>0&&Xn(e)}var ul=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),cl=!1;function fl(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(cl||!(t instanceof TypeError)||!Ee(l)||!("trustedTypes"in globalThis))return;cl=!0;let r="function"==typeof Me()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${l}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${r}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:l})}var hl=new WeakMap;function dl(e,t,n){let l=e[t],r=void 0===n?void 0===l?null:`the event carried no detail (undefined) while element.${t} is ${typeof l}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==l&&"object"==typeof l?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof l}`;if(null===r)return;let i=hl.get(e);void 0===i&&hl.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${r}. 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 pl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],ml={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},gl={name:"diagnostics",install(){e.Lo=Fn,e.Bo=qn,e.Eo=Qn,e.detail=dl,e.Ye=t(e.Ye,fl);let l=e.pe;e.pe=(e,t)=>{(function(e){void 0!==e.$scan&&w(1);for(let[t,n]of pl)void 0!==e[t]&&w(1601,[t,n])})(t),l?.(e,t),function(e){let t=e.$recursion;if(null===t||"object"!=typeof t)return;let n=Object.entries(t);if(1!==n.length||"string"!=typeof n[0][1])return;let[l,r]=n[0];if(!l.endsWith(".*")||!r.endsWith(".*"))return;let i=l.slice(0,-2),s=r.slice(0,-2),o=`.${r}`,a=`${i}.**`,u=Jn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>v(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${s}`||e.startsWith(`.${s}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${s}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${ul(o)})+$`).test(t.slice(0,t.length-e.length))&&f(`"${a}${e}" and "${a}${t}" expand to the same concrete path at different depths (they differ by whole repetitions of "${r}"). Rename one of them.`);let t=new RegExp(`^${ul(l)}(?:${ul(o)})*${ul(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&f(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(t),function(e){_n.delete(e),Vn.has(e)&&Xn(e)}(e),function(e){if(el.has(e))return;el.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{tl=!0;try{n(t)}finally{tl=!1}let l=e.O.wt(m(t).o);void 0!==l&&Zn(e,l,2)}}(e),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))il(t)}})}(e),nl.set(e,new Set(Jn(t)))},e.handlerThrew=ol,e.re=t(e.re,ll),e.he=t(e.he,al),e.rt=n(r,e.rt,(e,t)=>Object.hasOwn(ml,t)?w(1701,[t,ml[t]]):void 0)}},yl={},bl=/\.\d/,vl=new Set(Object.getOwnPropertyNames(Object.prototype)),$l=0,wl=!1,Al=null,kl=()=>{wl=!1,$l++};function xl(){if(null===Al)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=kl,e.port1.unref?.(),Al=()=>e.port2.postMessage(0)}else Al=()=>setTimeout(kl,0);return wl||(wl=!0,Al()),$l}function Sl(e,t){let n=new Set,l=[e];for(;l.length>0;){let e=l.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let l of t)if(n.ee(l)&&(n.n===l.n||!(l.n<e.n&&e.h[l.n+1].ee(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Tl=class{constructor(e,t){this.active=!1,this.Oe=new Map,this.early=[],this.n=0,this.Fo=-1,this.Bn=new Set,this.Ke=null,this.engine=e,this.De=t}ur(){let e=this.engine;this.Oe.clear();let t=this.early;this.early=[];for(let t of this.De)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(yl,e.v(t.p,null)):this.Wn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[l,r,i,s]of t)if((null===r||r.w)&&Object.is(e.v(l,r),s)){n.add(l);for(let e of this.De)e.p===l&&this.dt(e,r,i,!0)}for(let e of this.De)e.getter&&0===e.p.n&&!this.Oe.has(e)&&Sl(Nl(e.p),n)&&this.dt(e,null,void 0,!0);this.Oe.size>0&&e.Se()}prime(t,n){try{n()}catch(n){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,n),e.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}Oo(){this.active=!1,this.Oe.clear(),this.early=[]}Wn(e,t,n,l){let r=this.engine.Ue(n,e.h[t]);for(let n of r.f)t===e.n?l(n):this.Wn(e,t+1,n,l)}dt(e,t,n,l){let r=this.Oe.get(e);void 0===r&&this.Oe.set(e,r=new Map);let i=r.get(t);void 0===i?r.set(t,[n,this.n,l]):(i[1]<this.n&&(i[1]=this.n),i[2]||=l)}re(e,t,n,l,r,i){if(this.active){(this.Ke??=new Set).add(e);for(let i of this.De){let s=i.p;s.n!==e.n||!s.ee(e)||this.dt(i,t,i.getter?i.s.get(t??yl):s===e&&r&&this.engine._t&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}else i&&this.early.push([e,t,n,l])}Ee(e,t){if(this.active)for(let n of this.De)(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??yl),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.De){let r=l.p;if(!(r.n<e.n||r.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(r.n===e.n?this.dt(l,t,void 0,!0):this.Wn(r,e.n+1,t,e=>this.dt(l,e,void 0,!0)))}}}he(){let t=this.Ke;if(this.Ke=null,!this.active||0===this.Oe.size)return;let n=this.Oe;this.Oe=new Map;let l=this.engine,r=[];for(let i of this.De){let s=n.get(i);if(void 0===s)continue;let o,a=[...s].filter(([e])=>null===e||e.w);a.length>1&&a.sort((e,t)=>Ol(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=l.d;this.n=u+1,l.Ce++;try{if(a=l.v(i.p,n),i.getter&&(i.s.set(n??yl,a),Object.is(a,s)&&(bl.test(i.t)||null!==n&&!c&&!(o??=null!==t&&Sl(Nl(i.p),t)))))continue;if(u>32){r.includes(i.t)||r.push(i.t);continue}l.d=n,e.at?.(l,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(l.proxy,a,s,...l.H(n))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),e.at?.(l,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{l.d=h,this.n=0,l.Ce--}}}r.length>0&&this.Co(r)}Co(t){let n=xl();n!==this.Fo&&(this.Fo=n,this.Bn.clear());let l=t.filter(e=>!this.Bn.has(e));if(0!==l.length){for(let e of l)this.Bn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:l})}}};function Nl(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function Ol(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)l.unshift(e.y);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var jl="$streamStatus",Cl="$streamError",Ml=new Set(Object.getOwnPropertyNames(Object.prototype)),Pl=!1;function El(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 Wl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Pl=!0;try{this.engine.P(this.engine.o(`${e}.${t}`),null,n)}finally{Pl=!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(jl,e.name,"idle")}Ee(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)}he(){let e=this.engine,t=this.W,n=[];for(let l of this.entries){if(!l.ft)continue;let r=l.n;if(l.ft=!1,r>32)n.push(l.name),l.g.Y=h;else{t.n=r+1,e.Ce++;try{this.start(l,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Co(n)}start(e,t){let n,l=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let r=e.g;r.getter=e.args;let i=r.Q.slice();Il(r);try{n=l.read(r,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&v(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${jl}.${e}`||n.t===`${Cl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Il(r);for(let e of i)e._n(r);if(r.Y=h,t)throw n;return this.set(Cl,e.name,n),void this.set(jl,e.name,"error")}}let r=new AbortController;e.J=r,l.P(l.o(e.name),null,e.K),this.set(Cl,e.name,null),this.set(jl,e.name,"active"),this.mr(e,r,n)}async mr(e,t,n){let l=this.engine,r=t.signal,i=()=>!r.aborted&&e.J===t,s=l.o(e.name),o=this.W.n,a=xl(),u=e=>{xl()===a&&(this.W.n=o);try{e()}finally{this.W.n=0}},c=e.K;try{let t=await e.source(n,r);if(!i())return;let o=t=>{c=void 0!==e.Io?e.Io(c,t):t,u(()=>l.P(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(r.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!i())return;if(t.done)break;o(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(r.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.J=null,u(()=>this.set(jl,e.name,"done"))}catch(n){if(!i())return;e.J=null,t.abort(),u(()=>{this.set(Cl,e.name,n),this.set(jl,e.name,"error")})}}};function Il(e){for(let t of e.Q){let n=t.L.indexOf(e);n>=0&&t.L.splice(n,1),t.ht.delete(e)}e.Q.length=0,e.Y=c}var Rl=new WeakMap;function Dl(e){let t=Rl.get(e);return t?.target===e.target?t:void 0}function ql(t,n){let l=new Tl(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$watch must be an object mapping paths to handler functions.");let l=[];for(let r of Object.keys(n)){let i=n[r];(""===r||"$"===r[0]||r.includes("@")||vl.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=t.o(r);e.Eo?.(t,s,!0),l.push({t:r,p:s,handler:i,getter:!1,s:new WeakMap})}return l}(t,n.$watch)),r=new Wl(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$stream must be an object mapping stream names to definitions.");let l=[],r={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||Ml.has(s))&&v(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&v(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&v(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&v(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${s}": args must be a function.`),El(t,s)&&v(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),r[s]="idle",i[s]=null,l.push({name:s,source:a,Io:u,K:f,J:null,ft:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[jl]=r,t[Cl]=i,l}(t,n),l),i=Rl.get(t);void 0!==i&&(i.W.Oo(),i.Ct.fr()),Rl.set(t,{W:l,Ct:r,Je:i?.Je??!1,target:n})}function Ll(e,t){let n=Rl.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 zl=["$streamStatus","$streamError"],Ul={name:"temporal",install(){e.pe=t(e.pe,ql),e.element=t(e.element,Ll),e.re=t(e.re,(e,t,n,l,r,i,s)=>Dl(e)?.W.re(t,n,l,r,i,s)),e.Ee=t(e.Ee,(e,t,n)=>{let l=Dl(e);void 0!==l&&(l.W.Ee(t,n),l.Ct.Ee(t))}),e.Qt=t(e.Qt,(e,t,n)=>Dl(e)?.W.Qt(t,n)),e.he=t(e.he,e=>{let t=Dl(e);void 0!==t&&(t.W.he(),t.Ct.he())}),e.rt=n(r,e.rt,(e,t)=>{let n=t.split(".",1)[0];if(zl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Ie=n(l,e.Ie,(e,t)=>(!Pl&&36===t.t.charCodeAt(0)&&zl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Fl=new WeakMap,Vl=!1,_l=/^(?!prototype$)[^\d.*$][^.*]*$/;function Bl(e,t){let n=t.$listKeys,l=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let r=n[t];"string"==typeof r?l.set(e.o(t),e=>e[r]):"function"==typeof r?l.set(e.o(t),r):v(`$listKeys "${t}" must be a field name or a function.`)}}Fl.set(t,l)}function Hl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Kl(e,t,n){let l=new Map;for(let r of t){Hl(r)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(r);null==t&&v(`$listKeys "${e}": a row has no key.`),l.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),l.set(t,r)}return l}function Jl(e,t,n,l){if(Vl||!Array.isArray(l))return!1;let r=Fl.get(e.target)?.get(t);if(void 0===r)return!1;let i=e.it(t,n);if(!Array.isArray(i)||i===l)return!1;let s=Kl(t.t,i,r);Kl(t.t,l,r);let o=[],a=[],u=i.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=s.get(r(t));o.push(n??t),void 0!==n&&a.push([e,n,t]),o[e]!==i[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let l of Object.keys(n))Object.is(t[l],n[l])||c.push([e,l,n[l]]);for(let l of Object.keys(t))!(l in n)&&null!==t[l]&&c.push([e,l,null])}if(u&&0===c.length)return!0;if(!u){Vl=!0;try{e.P(t,n,o)}finally{Vl=!1}}if(c.length>0){let l=e.Ue(0===t.n?null:n,t);for(let[n,r,i]of c){if("__proto__"===r)continue;let s=l.f[n],o=_l.test(r)?e.o(`${t.t}.*.${r}`):null;null===o?.getter?e.P(o,s,i):(s.$[r]=i,e.P(e.o(`${t.t}.*`),s,s.$,!0))}}return!0}var Yl={name:"list-keys",install(){e.pe=t(e.pe,Bl),e.Ie=n(l,e.Ie,Jl)}},Gl=new WeakMap,Xl=new WeakMap,Ql="will not graft: the root state failed to initialize.",Zl=new WeakSet,er=new WeakMap,tr=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],nr=["$commandTokens","$eventTokens","$on","$errorCallback"],lr=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,rr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),ir=e=>e?.element?.isConnected?e:void 0;function sr(e){let t=Xl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function or(e,t){let n=Xl.get(t);if(Xl.delete(t),Array.isArray(n))for(let t of n)fr(t,e)}function ar(e){let t=Gl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ur(e,t){console.error(`${lr(e.t)} ${t}`),ar(e),e.Qe?.(),e.Qe=null}function cr(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 fr(e,t){if(Zl.has(t))return ur(e,"will not graft: its component is wired to its host.");let n=e.state,l=t.target,r=e.t.split("."),i=l;for(let e of r)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return ur(e,`will not graft: the root state already has "${e.t}".`);let s=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,l){if("symbol"==typeof l)return;if(36!==l.charCodeAt(0))return e.proxy[n(l)];let r=e.proxy[l];return"$eqPath"===l?(e,t)=>r(n(e),n(t)):rr.has(l)&&"function"==typeof r?(e,...t)=>r(n(e),...t):r},set:(t,l,r)=>"symbol"!=typeof l&&(e.proxy[n(l)]=r,!0)})}(t,e.t);e.chroot=s;let o={},a={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:l,set:r,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==l||void 0!==r)a[`${e.t}.${n}`]={get:l&&function(){return l.call(s)},set:r&&function(e){r.call(s,e)}};else{if("$"===n[0])continue;if("function"==typeof i){let t=i.bind(s);a[`${e.t}.${n}`]={get:()=>t}}else o[n]=i}}if(void 0===i){for(let e=1;e<r.length;e++){let n=t.o(r.slice(0,e).join("."));null==t.it(n,null)&&t.P(n,null,{})}t.P(t.o(e.t),null,o)}t.no(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=er.get(t);void 0===c&&er.set(t,c=[]),c.push(e),e.el.isConnected&&cr(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function hr(e,t){let n=Xl.get(e);if(Array.isArray(n))for(let e of n)ur(e,Ql);Xl.set(e,t)}var dr=new WeakMap;function pr(e,t){let n=e.getAttribute("mount");if(null===n)return null;let l={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Gl.get(t);void 0===e&&Gl.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==l&&(null===i.engine?i.el.isConnected:ir(i.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=Xl.get(t);Array.isArray(e)&&Xl.set(t,e.filter(e=>e!==i)),i.Qe?.(),i.Qe=null}e.set(n,l)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{To:!0,start(e){if(null!==r)return ur(l,r);if(Gl.get(t).get(n)===l){for(let t of tr)if(void 0!==e[t])return ur(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of nr)void 0!==e[t]&&console.warn(`${lr(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Qe=e;let n=ir(Lt.get(t)),r=Xl.get(t);void 0!==n?fr(l,n):sr(t)?ur(l,Ql):Xl.set(t,[...Array.isArray(r)?r:[],l])})}},Je(){null!==l.engine&&cr(l,"$connectedCallback")},Ln(){null!==l.engine&&cr(l,"$disconnectedCallback")},reset(){v(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var mr=new WeakMap,gr=new WeakMap;function yr(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||v(`${t} must be an array of state member names.`);let l=new Set;for(let e of n)("string"!=typeof e||""===e)&&v(`${t} entries must be non-empty strings.`),"$"===e[0]&&v(`${t} entry "${e}": internal ($) members are never exposed.`),l.has(e)&&v(`${t} entry "${e}" is duplicated.`),l.add(e);return n}function br(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let l=document.createDocumentFragment();for(let e of[...t.childNodes])l.appendChild(e.cloneNode(!0));let r=t.mode;return{start(t){e.hasAttribute("bind-component")&&v("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,l){e.includes("-")||v(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&v(`DCC: <${e}> is already defined.`);let r=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(l),i=yr(l,"$bindables"),s=yr(l,"$commands");for(let e of i){let t=r.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 s){let t=r.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 o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=l=>{if(a.has(l))return a.get(l);if(l.hasAttribute("data-wc-definition"))return null;let r=l.attachShadow({mode:n});r.appendChild(t.cloneNode(!0));let s=r.querySelector(ie.tagNames.state);return a.set(l,s),mr.set(l,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.tagNames.state}>: no change events.`),s},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,l]of t)n.proxy[e]=l});class d extends HTMLElement{static{this.wcBindable=0===i.length&&0===s.length?null:{protocol:"wc-bindable",version:1,properties:i.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:i.map(e=>({name:e})),...0===s.length?{}:{commands:s.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of r)"function"==typeof t.value?Object.defineProperty(d.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(d.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,l,r,t)},Je(){},Ln(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var vr=new WeakMap,$r=new WeakSet,wr=new WeakMap,Ar=new WeakMap,kr="data-wcs-wired",xr=new WeakMap,Sr=new WeakMap,Tr=new WeakMap,Nr=0,Or=new Set,jr={},Cr=["$watch","$stream","$renderedCallback"],Mr=e=>e.split(".",1)[0];function Pr(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Er(e,t){let n=e.a,l=Mr(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(kr);else if(!Ir(n,l)){let e=n.getAttribute(kr)?.split(" ")??[];e.includes(l)||n.setAttribute(kr,[...e,l].join(" "))}xr.get(n)?.ye===l&&v(`<${n.localName}>.${l} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let r=vr.get(n);void 0===r&&vr.set(n,r=[]),r.push(e),t&&$r.add(e);let i=wr.get(n);return void 0===i&&wr.set(n,i=new Map),i.has(l)||i.set(l,n[l]),Ar.get(n)?.(),!1}function Wr(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Ir(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Rr(e){let t=e.parentElement;for(;null!==t&&!Wr(t);)t=t.parentElement;let n=Lt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Kt(e):Ut(n,e))}var Dr=new Set;function qr(e,t){Dr.has(e)||(Dr.add(e),console.warn(`[@wcstack/state] ${t}`))}var Lr=(e,t)=>t in e.state;function zr(e,t){let n=Ur(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Ur(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 Fr(e,t,n){if(null!==n.getter)return;let l,r=e.host,i=r.engine,s=Mr(n.t),o=r.entries.find(e=>e.E===n.t);if(void 0===o&&null!==n.c)return function(e,t){let n,l=t.c;for(;null!==l&&void 0===(n=e.pt.get(l));)l=l.c;if(null===l||void 0===n)return;let r=e.T,i=e.host.engine,s=i.o(n.p.t+t.t.slice(l.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=Vr(e,o.r);return 0===t.n?n:(i.resolve(Pr(s.t,[...i.H(n),...r.H(ne(r.d,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.se&&(t.se=n=>{let l=a();_r(e,o.e,()=>i.P(s,l,n)),e.dn=t}),t.n>0&&(t.F=r.je++),e.pt.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.E!==s?Lr(r,s):zr(r,s))return;l=o.we}else{if(null===t||null!==n.c||"$"===s[0]||Lr(r,s))return;o=t,l=i.o(`${t.we.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(l,Vr(e,a)),n.se=t=>{_r(e,u,()=>i.P(l,a,t)),e.dn=n},e.pt.set(n,{e:o,p:l,r:a})}function Vr(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function _r(e,t,n){let l=Or.has(e.T);Or.add(e.T),e.from=t;try{n()}finally{l||Or.delete(e.T),e.from=null}}var Br=(e,t)=>t||!Or.has(e.m.T)||null!==e.m.from&&e.m.from!==e.e;function Hr(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,Nr+=t?1:-1;let n=e.host.engine,l=Tr.get(n);void 0===l&&Tr.set(n,l=new Map);for(let n of e.me){let e=l.get(n.e.we);void 0===e&&l.set(n.e.we,e=new Map);let r=e.get(n.e.r);void 0===r&&e.set(n.e.r,r=new Set),t?r.add(n):(r.delete(n),0===r.size&&e.delete(n.e.r))}let r=e.host.entries.find(e=>""===e.E);if(void 0!==r){null===e.ie&&function(e,t){let n=e.host,l=n.engine;e.ie=new Map;let r=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(r.has(s))continue;r.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=Mr(s);if(s!==a&&!Lr(n,a))continue;let u=l.o(`${t.we.t}.${s}`);if(null===u.getter)Yr(l,u,t.we);else if(!Kr.has(u.getter))continue;e.ie.set(u,e.T.o(s))}}(e,r);for(let l of e.ie.keys())t&&null===l.getter&&Yr(n,l,r.we),n.A.ke(n,l,r.r);e.ie.size>0&&n.Se(),t&&function(e,t){let n=e.host.engine;for(let[l,r]of e.ie){let i=n.v(l.c,t.r);if(null===i||"object"!=typeof i||!(l.s in i))continue;let s=e.host.el.localName;qr(`${s}|${l.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.ye}.${r.t} is exported at "${l.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,r)}}var Kr=new WeakSet;function Jr(e,t,n,l){let r=Tr.get(e)?.get(t)?.get(n);if(void 0===r)return null;let i=null;for(let e of r)""!==e.e.E||!0!==e.m.ie?.has(l)||e.m===i||(null!==i&&v(`[wcs/mount-export-ambiguous] "${l.t}" is exported by two mounted components on the same instance: <${i.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.`),i=e.m);return i}function Yr(e,t,n){let l=t.c,r=t.s,i=()=>{let t=e.read(l,e.d);return null!==t&&"object"==typeof t&&r in t?t:null};t.getter=()=>{let l=i();if(null!==l)return l[r];let s=Jr(e,n,e.d,t);return null===s?void 0:s.T.read(s.ie.get(t),null)},Kr.add(t.getter),t.se=s=>{let o=null===i()?Jr(e,n,e.d,t):null;if(null===o){let t=e.read(l,e.d);return void(null!==t&&"object"==typeof t&&(t[r]=s))}let a=o.ie.get(t);void 0===Ur(o.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${o.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),o.T.P(a,null,s)},t.n>0&&(t.F=e.je++)}function Gr(t,n,l,r,i,s){if(null!==n.getter)return t.A.ke(t,n,l),void t.Se();if("*"===n.s){if(null===l)return;if(l.$=l.l.R[l.y],t.A.Xt(l),null!==l.u)for(let e of l.u.values())t.G(e)}else t.$n(n,l);e.re?.(t,n,l,r,i,s),t.Ke(n,l)}function Xr(e){let t=e.m.T;for(let[n,l]of e.m.pt)l.e===e.e&&(0===n.n?t.A.ke(t,n,null):t.nn(n.h[n.n],e=>t.A.ke(t,n,e)));t.Se()}function Qr(e,t,n,l,r,i,s){let o=n.t.slice(t.t.length);if(""===o)return Xr(e);let a,u=e.m,c=u.T;if(""===e.e.E){a=o.slice(1);let e=Mr(a);if("$"===e[0]||Lr(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ne(l,e).y);c.resolve(Pr(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Gr(c,h,d,r,i,s)}function Zr(e,t,n,l,r,i,s){if(0===Nr)return;let o=Or.has(e);Or.add(e);try{let o=Sr.get(e);!s&&void 0!==o&&o.fn&&!Or.has(o.host.engine)&&function(e,t,n,l,r,i){let s,o=t;for(;null!==o&&void 0===(s=e.pt.get(o));)o=o.c;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.dn===t)return void(e.dn=null);if(null!==s.r&&!s.r.w)return;let u=[...a.H(s.r),...e.T.H(n)];a.resolve(Pr(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||_r(e,s.e,()=>Gr(a,c,f,l,r,i))}(o,t,n,l,r,i),s&&void 0!==o&&o.fn&&null!==o.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[r,i]of e.ie)i===t&&(l.A.ke(l,r,n.r),l.Se())}(o,t);let a=Tr.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.ee(e)){let a=o.get(0===e.n?null:ne(n,e.n));if(void 0!==a)for(let o of[...a])Br(o,s)&&Qr(o,e,t,n,l,r,i)}else if(e.ee(t))for(let[e,l]of[...o])if(0===t.n||ne(e,t.n)===n)for(let e of[...l])Br(e,s)&&Xr(e)}finally{o||Or.delete(e)}}async function ei(t,n,l,r,i){if(r===jr)return;let s=o(r);s&&await s;let a=xr.get(n);a.engine&&r.$recursion&&v(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.I;if(null!==u&&u.el!==t&&u.el.isConnected&&v(`<${n.localName}> already has a connected <${ie.tagNames.state} bind-component="${a.ye}">.`),null!==u&&Hr(u,!1),null!==u&&function(e,t,n){let l=e.T,r=`[${ie.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(r)||null!==e.querySelector(r)),s=new Set,o=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&s.add(e)},a=(e,t)=>{for(let n=e.In(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of l.de.values())for(let t of e)if(null===t.D)o(t.a);else for(let e of t.D.q)a(t.D,e.S);for(let e of l.oe.values())for(let t of[e.x,...e.B??[]])null!==t&&a(t,t.S);for(let t of e.j)t.parentNode===n&&i(t)&&s.add(t);if(0===s.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!s.has(n)&&!e.j.includes(n)&&(i(n)||l.Wt&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(u,t,l))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.T.element=t,t.engine=e.T,e.j=e.j.filter(e=>e.parentNode===n),t.isConnected?await ti(e,l):l()}(u,t,l,i);let c=new re(r,new Yt);c.element=t,t.engine=c,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let l=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof l&&"constructor"!==t&&n.set(l,null)}let l=(t,n,l)=>Reflect.apply(t,e.proxy,l);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:l})),t}}(c,r);let f={el:t,j:[],T:c,host:a,me:[],pt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of a.entries)f.me.push({m:f,e});a.I=f,Sr.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.T,n=e.host,l=n.engine,r=n.el.localName,i=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=Mr(e.E);Lr(n,t)&&(e.E!==t||zr(n,t))&&qr(`${r}.${e.E}`,`[wcs/mount-own-key-shadow] <${r}>: "${n.ye}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=l.v(i.we,i.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)&&qr(`${r}.${t}`,`[wcs/mount-own-key-shadow] <${r}>: its own "${t}" hides "${i.we.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=Cr.filter(e=>void 0!==n.state[e]);s.length>0&&qr(`${r}.${n.ye}$`,`[wcs/mount-dollar-declaration] <${r}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.ot;t.ot=n=>{Fr(e,i,n),o.call(t,n)};let a=[...t.O.all()];for(let t of a)Fr(e,i,t);for(let e of a)o.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=Sr.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(f),Hr(f,!0),Zl.add(c),or(c,l));let d=e.hr?.(l,c);zt(c,l),d?.(),f.j=[...l.childNodes],Jt(),h&&c.xn(),Object.defineProperty(n,a.ye,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.ye);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),t.isConnected?(await c.$e("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):Hr(f,!1)}async function ti(t,n){Hr(t,!0);for(let e of t.me)Xr(e);n?.(),!t.broken&&(await t.T.$e("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.T,"connected"))}function ni(t,n){let l=t.getAttribute("bind-component");if(null===l)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Lt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){hr(t,e);for(let e of dr.get(t)??[])e()}}),null}(t,n);let r=t.parentNode,i=r instanceof ShadowRoot,s=i?r.host:r instanceof Element?r:null,o=()=>{let e=null===s?void 0:xr.get(s)?.I;return e?.el===t?e:null},a=e=>{throw i&&hr(r,t),e},u=!1;return{It:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&v(`<${ie.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Le(n).whenDefined(r);let i=xr.get(n);if(void 0!==i)return i.ye!==t&&v(`<${r}> already has a <${ie.tagNames.state} bind-component="${i.ye}">.`),i.state;let s=()=>(vr.get(n)??[]).filter(e=>Mr(e.name)===t),o=Ir(n,t);if(o&&0===s().length&&Rr(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(kr)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,i)=>{Ar.set(n,l),e=function(e,t){sr(e)&&t();let n=dr.get(e)??new Set;return dr.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Ar.delete(n);let a=s(),u=wr.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),jr}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===l)&&v(`<${r}> maps "${e.name}" twice.`);let i=l.split(".").indexOf("*");if(i>=0){let n=l.split(".").slice(0,i).join(".");v(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}f.push({E:l,we:e.o,r:e.r,ro:$r.has(e)}),e.engine.Tn(e),""!==l&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return xr.set(n,i={el:n,ye:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,I:null}),h}(t,l,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await ei(t,s,i?r:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Je(){let e=o();null!==e?ti(e).catch(e=>console.error(e)):u?Promise.resolve().then(()=>{if(t.parentNode===r)return ei(t,s,i?r:s,xr.get(s).state,()=>{})}).catch(e=>console.error(e)):Ar.has(s)&&Rr(s)},Ln(){let t=o();null!==t&&(Hr(t,!1),!t.broken&&(t.T.$e("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.T,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${s?.localName}>.${l} instead.`)}}}var li={name:"scopes",install(){e.ut=n(i,e.ut,pr),e.ut=n(i,e.ut,br),e.ut=n(i,e.ut,ni),e.ar=Er,e.$o=Wr,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=er.get(e)??[];if("disconnected"===t)for(let e of n)ar(e);else if("reset"!==t&&ir(Lt.get(e.root))===e){or(e,e.root);for(let e of n)Gl.get(e.root).has(e.t)||Gl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();or(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:mr.get(n);void 0!==l&&gr.set(e,{host:n,def:l})}(e,n)}),e.re=t(e.re,(e,t,n,l,r,i)=>{(function(e,t,n,l){let r=gr.get(e);if(void 0===r)return;let i=t.t.split(".",1)[0];if(!r.def.bindables.includes(i))return;let s=l&&t.t===i;r.host.dispatchEvent(new CustomEvent(`${r.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,r,i),Zr(e,t,n,l,r,i,!1)}),e.Ee=t(e.Ee,(e,t,n)=>Zr(e,t,n,void 0,void 0,!1,!0)),e.Ie=n(l,e.Ie,(e,t,n,l,r)=>(function(e,t){let n=er.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let l,r=Sr.get(e);if(void 0===r)return!1;for(let e=t;null!==e&&void 0===l;e=e.c)l=r.pt.get(e);if(void 0===l)return!1;let i=l.e;return!((null===i.r||i.r.w)&&!i.ro)&&(!!n||(Vr(r,i.r),void v(`[wcs/mount-readonly] <${r.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${r.host.ye}${""===i.E?"":`.${i.E}`}#ro: ${i.we.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,r)));let r=e.pe;e.pe=(e,t)=>{let n=er.get(e);void 0!==n&&n.length>0&&v(`re-setting a root state with grafted volumes (${n.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Tr.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&v("re-setting a root state with mounted components is not supported: they read its data."),r?.(e,t)}}},ri="$recursion",ii=new WeakMap,si=new WeakSet,oi=new WeakSet,ai=0,ui=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ci=e=>`[wcs/recursion-${e}]`;function fi(e,t){let n=n=>v(`${ci("declaration-invalid")} ${ri} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${ci("declaration-invalid")} ${ri} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var hi=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function di(e,t){let n=`${e.l}.**`,l=t.slice(n.length);return(!t.startsWith(n)||""!==l&&"."!==l[0]||l.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function pi(e,t,n){let l=di(e,t),r=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===r&&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.`),hi(e,r.k)+l}function mi(e,t,n){let l=new Set,r=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${ci("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),r.has(e)&&v(`${ci("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),i+1>128&&v(`${ci("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${i+1} (the limit is 128).`),r.add(e),0)),s=(r,o)=>{for(let a of r){n(o,a);let r=e.o(`${hi(t,o)}.${t.key}`),u=e.read(r,a);i(u,r.t,o+1)&&(l.add(u),s(e.Ue(a,r).f,o+1),l.delete(u))}},o=e.o(t.l),a=e.read(o,null);i(a,t.l,0)&&(l.add(a),s(e.Ue(null,o).f,0))}function gi(e,t){let n=function(e){let t=e[ri],n=[],l=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!l.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),l.add(e);if(void 0===t)return n.length>0&&F(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${ci("declaration-invalid")} ${ri} must be an object mapping one anchor path to its repeating sub-path.`);let r=Object.entries(t);1!==r.length&&v(`${ci("declaration-invalid")} ${ri} must declare exactly one anchor (it declares ${r.length}).`);let i=fi("anchor",r[0][0]),s=fi("repeat",r[0][1]),o=i.slice(0,-2),a=s.slice(0,-2),u=`.${s}`,c=new Map,f=[],h=`${o}.**`;for(let[e,t]of n){let n=e.slice(h.length);(!e.startsWith(h)||""!==n&&"."!==n[0]||n.includes("**"))&&v(`[wcs/recursion-anchor] "${e}": a recursive key is "${h}" followed by a path (the anchor is "${i}").`),(""===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(`${ci("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${ui(i)}((?:${ui(u)})*)${ui(n)}$`),n])}return{l:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${ui(o)}((?:${ui(`.*.${a}`)})*)$`)}}(t),l=ii.has(e);null!==n?(l||ai++,ii.set(e,n),oi.add(e),si.has(e)||function(e){si.add(e);let t=e,n=t.ot;t.ot=l=>{let r=ii.get(e);if(l.t.includes("**")){let t=e.O.wt(l.t)===l;return void(oi.has(e)||void 0===r&&t?l.getter=()=>F(l.t):t||n.call(e,l))}if(void 0!==r&&null===l.getter)for(let[e,n]of r.matchers)if(e.test(l.t)){l.getter=r.families.get(n),l.n>0&&(l.F=t.je++),r.owners.set(l,r.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let r=ii.get(e);return l.call(e,void 0!==r&&t.includes("**")?pi(r,t,n):t,n)};let r=t.getAll;t.getAll=(n,l)=>{let i=ii.get(e);if(void 0===i||!n.includes("**"))return r.call(e,n,l);if(void 0===l)return r.call(e,pi(i,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${ci("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=di(i,n),o=[];return mi(e,i,(t,n)=>{for(let l of r.call(e,hi(i,t)+s,e.H(n)))o.push(l)}),o};let i=t.wn;t.wn=(n,l,r,s)=>{let o=ii.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,l,r,s);Array.isArray(l)||w(9,[n]),l.length>0&&v(`${ci("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof r||!0===s?.spread)&&v(`${ci("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Le>0&&w(8);let a=di(o,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(o.step);)u=u.slice(o.step.length);let c=o.key.split(".");(""===u||u===`.${o.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${ci("structural-write")} "${n}" writes the recursion structure itself (a node, its "${o.key}" list or that list's length, or an object on the way to it).`);for(let e of o.families.keys()){let t=e;for(;t.startsWith(o.step);)t=t.slice(o.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${ci("readonly")} "${n}" writes into the recursive getter "${o.l}.**${e}".`)}let f=[];mi(e,o,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=i.call(e,hi(o,t)+a,e.H(n),r);return h}}(e)):l&&(ii.delete(e),ai--)}function yi(e,t){if(0===ai)return!1;let n=ii.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let l=n.owners.get(e);void 0!==l&&v(`${ci("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var bi={name:"recursion",install(){e.pe=t(e.pe,gi),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){oi.delete(e)}(e)}),e.Ie=n(l,e.Ie,yi)}},vi="4.4.0",$i=e=>e.split(".").slice(0,2).join("."),wi=class extends en{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return $i(this.version)===$i(vi)}};function Ai(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends wi{})}var ki=()=>ie.tagNames.ssr,xi=Symbol.for("wcstack.ssr.snapshotBuilder"),Si=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Ti=e=>document.createComment(e),Ni=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Oi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),ji=new WeakMap,Ci=new WeakMap,Mi=new WeakMap,Pi=new WeakSet,Ei=new WeakMap;function Wi(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Ii(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 Ri=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Di(e,t,n,l){let r=Ti(null===l?"wcs-[":`wcs-[:${l}`),i=Ti("wcs-]");n.length>0&&n[0].Re().before(...Wi(e,t)),t.after(r);for(let e of n)null===l&&e.Re().before(Ti("wcs-|"));let s=n.length>0?(e=>null===e.j?e.ct:e.j[e.j.length-1])(n[n.length-1]):r;(Ri(s)??s).after(i);for(let e of Wi(r,i))Pi.add(e)}function qi(e){if(e instanceof ft){Di(e.S,e.S,e.Fe,null);for(let t of e.Fe)Li(t);return}let t=e.I;null!==t&&(Di(e.q[e.y].S,e.q[e.q.length-1].S,[t],e.y),Li(t))}function Li(e){if(null!==e.u)for(let t of e.u)qi(t)}var zi=new Set(["script","style","template","textarea","title"]),Ui="data-wcs-raw",Fi=e=>zi.has(e.localName)||e.localName===ki();function Vi(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Ti("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Ti("wcs-s")):1===t.nodeType&&!Fi(t)&&Vi(t)}var _i=0;function Bi(e,t){let n=e.getRootNode(),l=[t];for(let e of Ci.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let r=new Map;for(let e of l){let t=ji.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.x&&n.set(t.x.S,t.x),null!==t.B)for(let e of t.B)n.set(e.S,e);for(let t of e.de.values())for(let e of t)if(null!==e.D)for(let t of e.D.q)n.set(t.S,e.D);let l=new Set;for(let[e,i]of t){r.set(e,i);let t=n.get(e);void 0!==t&&!l.has(t)&&e.isConnected&&(l.add(t),qi(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Mi.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Pi.has(e)||1===e.nodeType&&t.has(e)&&Gi(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Fi(e.parentNode)?Ei.has(e):t.has(n)&&Oi(n,"wcs-t:"))&&(Ei.has(e)||t.get(e)!==e.data):!t.has(e))&&l.push(e)}for(let e of l)e.remove()}let n=Array.from(e.childNodes);Fi(e)&&n.some(e=>Ei.has(e))&&e.setAttribute(Ui,n.map(e=>Ei.has(e)?`{{ ${Ei.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Vi(9===n.nodeType?n.body:n);let i=document.createElement(ki());i.setAttribute("version",vi);let s=document.createElement("script");s.type="application/json",s.textContent=function(e){return JSON.stringify(e).replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`)}(function(e){let t={};for(let n of Object.keys(e)){if("$"===n[0])continue;let l=Object.getOwnPropertyDescriptor(e,n);void 0!==l.get||void 0!==l.set||"function"==typeof l.value||(t[n]=l.value)}return t}(t.target)),i.append(s);for(let[e,t]of r){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let l="svg"===n?.localName,r=`wcs-${l?"s":"t"}${_i++}`;e.replaceWith(Ti(`wcs-p:${r}`));let s=document.importNode(Et(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Ii(e,document.createElement("template"),...e.childNodes));if(l){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=r,i.append(Ii(t,o,s))}e.before(i)}function Hi(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Ei.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===ki())continue;let e=t.engine;null!=e&&Bi(t,e)}}var Ki=Symbol.for("wcstack.state.ssr.impl"),Ji=new Map,Yi=new WeakMap,Gi=t=>!0===e.$o?.(t),Xi=e=>1===e.nodeType&&!Fi(e)&&!Gi(e),Qi=e=>e.f.flat().concat(e.z??[]),Zi=e=>{for(let t of Qi(e))t.remove()};function es(e,t,n){let l=/^wcs-\[(?::(\d+))?/.exec(e.data),r=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!Ni(o,"wcs-]");){let e=o.nextSibling;if(Ni(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];Oi(o,"wcs-[")?e=es(o,t,n):(n.push(o),Xi(o)&&ts(o,t))}o=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:s,z:o??i.appendChild(Ti("wcs-]"))},u=Qi(a);o=a.z.nextSibling;for(let e of u)n?.push(e),t&&Ct.add(e);return t&&null!==r?Ji.set(r,a):Zi(a),o}function ts(e,t){for(let n=e.firstChild;null!==n;)Oi(n,"wcs-[")?n=es(n,t):(Xi(n)&&ts(n,t),n=n.nextSibling)}function ns(e,t,n){let l=e=>{for(let r of Array.from(e.childNodes))if(r.parentNode===e)if(8===r.nodeType){let e=r.data;try{if("wcs-s"===e)r.remove();else if("wcs-e"===e)r.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Ti(`@@:${decodeURIComponent(e.slice(6))}`),n=r.nextSibling;for(;null!==n&&!Ni(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),r.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=r.parentNode,l="s"===e[10]?Ii(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);l.removeAttribute("id"),t.replaceChild(l,r)}}}catch{}}else 1===r.nodeType&&!Fi(r)&&(Gi(r)?Yi.set(r,{ssr:t,Pe:n}):l(r))};l(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||cs(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Oi(e,"wcs-[")?l++:Ni(e,"wcs-]")&&--l<0&&(l=0,n=t+1)}),0===l)continue;let r=0;for(let l=t.firstChild;null!==l;l=l.nextSibling)if(Oi(l,"wcs-["))r++;else if(Ni(l,"wcs-]")&&0===r--){t.prepend(...e.slice(n));break}}}(e),ts(e,n)}function ls(t,n){let l=Yi.get(t);if(void 0===l)return null;Yi.delete(t);let r=e=>ns(e,l.ssr,l.Pe);if(l.Pe||os(n,t,t,r),r(t),!l.Pe)return null;let i=e.Pe;return e.Pe=ds,()=>{e.Pe=i,rs()}}function rs(){for(let e of Ji.values())Zi(e);Ji.clear()}function is(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function ss(e,t,n,l){let r=null;for(let l of e){let e=l[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===r||e.length>r[n].length)&&(r=l)}let i=r?.[l];if(null==i)return null;let s=r[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function os(e,t,n,l){let r=document.createElement("template").content;for(let e of n.childNodes)r.appendChild(r.ownerDocument.importNode(e,!0));l(r),e.root=t;let i=()=>{};Mt(e,[...r.childNodes],null,!0,i,i,i,(t,n)=>Tt(e,n,null,0))}function as(e,t,n){if(Si()){if(n instanceof Array){for(let e=n.length;e-- >0;)$t(n[e])&&n.splice(e,1);let e=t;if(n.some(wt))Pi.add(e);else if(e.localName.includes("-")&&!Gi(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Mi.set(e,t)}return}if("string"==typeof n){if(Ei.set(t,n),Fi(t.parentNode))return;let e=Ti(`wcs-t:${encodeURIComponent(n)}`),l=Ti("wcs-/t");return t.before(e),void t.after(l)}let l=ji.get(e);void 0===l&&ji.set(e,l=new Map),l.set(t,n);let r=t.getRootNode(),i=Ci.get(r);return void 0===i&&Ci.set(r,i=new Set),void i.add(e)}if("string"!=typeof n&&Ji.size>0){let e=Ji.get(n);void 0!==e&&(Ji.delete(n),Ji.set(t,e))}}var us=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),cs=e=>3===e.nodeType&&""===e.data.trim(),fs=e=>{let t=Ji.get(e)?.z??e;return(Ri(t)??t).nextSibling};function hs(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.Cn;for(let l=0;l<n.length;l++){let r=n[l],i=e.ln,s=t[r[0]];for(let e=0;;){if(i=i.childNodes[r[e]],s?.nodeName!==i.nodeName)return!1;if(++e===r.length)break;s=(Ri(s)??s).firstChild;for(let t=r[e];t>0&&null!==s;t--)s=fs(s)}e.ko[l]=s}return!0}function ds(e,t,n){if(0===Ji.size)return null;let l=t,r=0;if(!n){let e=ie.commentIfPrefix;if(!Ni(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(us(n)&&r++,!Ni(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ji.has(l)&&null!==n&&!Ni(n,e)&&1!==n.nodeType;n=n.nextSibling)us(n)&&(l=n)}let i=Ji.get(l);if(void 0===i)return null;if(!n&&i.branch!==r)return Ji.delete(l),Zi(i),null;let s=i.f.shift();if(0===i.f.length&&Ji.delete(l),i.z?.replaceWith(...Wi(t,l)),i.z=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=Ji.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.z;)e++;else Ri(s[e])===s[e+1]&&e++}if(!hs(e,o)){let n=(e.Dn?e.root:e.ln).cloneNode(!0);o=e.Dn?[n]:[...n.childNodes],hs(e,o),(s[0]??i.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var ps={name:"ssr",install(){e.Mn=as,e.hr=ls;let n=e.element;e.element=(t,l)=>{"mounting"===l&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||Si())return;let l=n.previousElementSibling,r=l?.localName===ki(),i=r?l.getAttribute("version"):null,s=null===i||$i(i)===$i(vi);if(s){let e=t,n=e.$e;e.$e=(e,l)=>"$connectedCallback"===e?void 0:n.call(t,e,l)}if(!r)return;let o=!s&&parseInt(i)<4,a=/^3\.(\d+)\.(\d+)$/.exec(i),u=null!==a&&(+a[1]-5||+a[2]-3)>=0;s||console.warn(`[@wcstack/state] <${ki()} version="${i}"> does not match ${vi}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!u?" 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 c=s?l.querySelector('script[type="application/json"]'):null;if(null!==c){let e=JSON.parse(c.textContent||"{}"),n=t.target;for(let t of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(n,t);void 0!==l&&(void 0!==l.get||void 0!==l.set||"function"==typeof l.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${Ui}]`)))e.textContent=e.getAttribute(Ui),e.removeAttribute(Ui);let h=9===f.nodeType?f.body:f;l.remove();let d=e=>o?function(e,t,n){let l=new Map,r=e=>{let t=e.parentElement;for(;null!==t&&!Gi(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=r(t),i=t.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of fe(t.getAttribute(ie.bindAttributeName)??"")){let t=l.Ze;l.Ne[0]===i&&n.push([e?ss(e,t,1,0):t,l.Ne.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let l=r(e);if(null===l)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:ss(l,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return l.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:ss(l,i[2],2,1)??i[2]};for(let t of is(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Ni(l,`@@wcs-${e[1]}-end:${e[2]}`);)l=l.nextSibling;if(null!==l){for(;t.nextSibling!==l;)t.nextSibling.remove();l.remove(),t.replaceWith(..."text"===e[1]?[Ti(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let l of is(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],r=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===r)continue;let o=document.importNode(r,!0),a=ie.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,r)=>t+i(n??l,r))),s(o.content,n??l);let u=o.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?o.content.childNodes:[o])}};s(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,l,u):ns(e,l,s);s||os(t,f,h,d),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),l=e.map(e=>e.selected),r=e.map(e=>e.hasAttribute("selected")),i=r.lastIndexOf(!0);i<0&&(i=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>l[t]!==r[t]):n.selectedIndex!==i)&&t.push([n,()=>e.forEach((e,t)=>e.selected=l[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),s&&(e.Pe=ds,queueMicrotask(()=>{rs(),e.Pe=null}))}(t),n?.(t,l)},function(){let e=globalThis;e[Ki]={build:Hi,reset(){_i=0}},void 0===e[xi]&&(e[xi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Ki].build(t),reset:()=>e[Ki].reset()})}(),e.Po=t(e.Po,Ai);for(let e of ln())Ai(e)}},ms="__WCSTACK_DEVTOOLS_HOOK__",gs=null,ys=new Set,bs=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),vs=new WeakMap,$s=0;var ws=new WeakMap;function As(e){if(null===gs)return;let t=ws.get(e),n=ys.has(e)?function(e,t){let n=new Map,l=new Set,r=(l,r,i,s,o,a)=>{if(5===l)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(l,r),c=0===s.n?null:o,f=`${(e=>{let t=vs.get(e);return void 0===t&&vs.set(e,t=++$s),t})(i)}|${u}|${s.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:s.t,bindingType:a,node:i,replaceNode:i},absoluteAddress:bs(e,s,c)})},i=e=>r(e.i,e.name,e.a,e.o,e.r,e.on()),s=e=>{if(!l.has(e)){if(l.add(e),null!==e.be)for(let t of e.be)i(t);if(e instanceof tt&&null!==e.me){let t=e.C.Xe;for(let n=0;n<t.length;n++){let l=e.V?.[n];void 0!==l?i(l):r(t[n].i,t[n].name,e.me[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)o(t)}},o=e=>{if(!l.has(e))if(l.add(e),e instanceof ft){r(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Fe)s(t)}else null!==e.I&&s(e.I)};for(let t of e.de.values())for(let e of t)i(e),null!==e.D&&o(e.D);for(let t of e.oe.values())if(null!==t.x&&o(t.x),null!==t.B)for(let e of t.B)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||gs({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&gs({type:"state:binding-added",...l});ws.set(e,n)}function ks(e){let t=Lt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function xs(e){let t=new Set,n=new Set,l=new Set,r=new Set;for(let i of e.O.all()){for(let e=1;e<=i.n;e++)t.add(i.h[e].t);"*"===i.s&&n.add(i.t),null!==i.getter&&l.add(i.t),null!==i.se&&r.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:l,setter:r},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.ue.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==i.$watch&&"object"==typeof i.$watch?new Set(Object.keys(i.$watch)):null,keyedListPaths:null!==i.$listKeys&&"object"==typeof i.$listKeys?new Set(Object.keys(i.$listKeys)):null}}var Ss=new WeakSet,Ts=new WeakMap;function Ns(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Ss.has(t))return;Ss.add(t);let l=t.emit;t.emit=(...r)=>(null!==gs&&gs({type:"state:token-emit",kind:n,tokenName:t.name,args:r,subscriberCount:t.size,stateElement:e.element}),l.apply(t,r))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.ue.values())t(n,"event")}(e),"connected"===t){if(ys.has(e))return;ys.add(e),gs?.({type:"state:element-registered",rootNode:e.root,element:e.element}),As(e)}else"disconnected"===t&&(ys.delete(e),As(e),gs?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function Os(e,t,n,l,r,i){if(null===gs)return;let s=bs(e,t,0===t.n?null:n),o=Ts.get(e);void 0===o&&Ts.set(e,o=new Set),o.add(s),i&&gs({type:"state:write",absoluteAddress:s,value:r,oldValue:l,hasOldValue:!0})}function js(e){if(null===gs)return;let t=Ts.get(e);Ts.delete(e),void 0!==t&&gs({type:"state:update-batch",addresses:t}),As(e)}function Cs(e,t,n){gs?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Ms={"*":["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 Ps(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Ms["*"],...Object.hasOwn(Ms,e)?Ms[e]:[]])(n);return l.includes(t)||w(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var Es=[Tn,gl,Ul,Yl,li,bi,ps,{name:"devtools",install(){e.element=t(e.element,Ns),e.re=t(e.re,Os),e.he=t(e.he,js),e.Ye=t(e.Ye,Cs),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let t=globalThis,n=t[ms]??(t[ms]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let l of t)l.onEvent?.(e.id,n)})};return{version:2,sources:e,register(l){if(!e.has(l.id)){e.set(l.id,l),n(l);for(let e of t)e.onSourceRegistered?.(l)}},unregister(n){let l=e.get(n);if(void 0!==l){l._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(l){t.add(l);for(let t of e.values())n(t),l.onSourceRegistered?.(t);return()=>{if(t.delete(l))for(let t of e.values())n(t)}}}}());2!==n.version&&console.warn(`[@wcstack/state] devtools hook registry version ${n.version}, expected 2: keeping the existing one.`),n.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:vi,getStateElements:()=>[...ys].map(xs),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let l=n._,r=n.Me?.length??0;if((null===l||0===l.size)&&0===r)continue;let i,s=0;if(null!==l)for(let e of l.values())s+=e.size;try{i=0===n.n?e.v(n,null):void 0}catch{i=void 0}t.push({path:n.t,tracked:!1,rows:s,keys:null===l?0:l.size,lists:r,lastValue:i})}return t}(ks(e)),keys(e){let t=ks(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let l;return ks(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){ks(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(t){let n=null===gs&&null!==t;gs=t,null===t&&(ws=new WeakMap),e.at=t&&((e,t)=>gs?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of ys)As(e)})}})}()}},{name:"native-commands",install(){e.or=Ps}}];function Ws(e){return e}var Is=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],Rs={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"真偽性を反転(falsy → true)",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},add:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},sub:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},abs:{description:"絶対値",hasArgs:!1,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:0},clamp:{description:"範囲内に丸める (min,max)",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:2,maxArgs:2,argTypes:["number","number"]},toFixed:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},upper:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lower:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},capitalize:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},padStart:{description:"先頭を埋める (length[,char]。char の既定は 0 — JS の既定は空白なので注意)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},padEnd:{description:"末尾を埋める (length[,char]。char の既定は空白 — JS と同じ)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},repeat:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},reverse:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},truncate:{description:"切り詰めて省略記号 (length[,suffix]。suffix の既定は … — U+2026 の 1 文字)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},join:{description:"配列を連結 ([separator]。既定はカンマ + 空白)",hasArgs:!0,resultType:"string",acceptTypes:["array"],minArgs:0,maxArgs:1,argTypes:["string"]},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},unit:{description:"単位(接尾辞)を付加",hasArgs:!0,resultType:"string",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["string"]},date:{description:"ロケール形式の日付 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},ymd:{description:"YYYY-MM-DD 形式 ([separator]。既定は -)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},hms:{description:"HH:MM:SS 形式 ([separator]。既定は :)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},coalesce:{description:"null / undefined の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},nullIfEmpty:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0},currency:{description:"通貨の書式 (code[, locale]。code は ISO 4217 — JPY / USD / EUR、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:1,maxArgs:2,argTypes:["string","string"]}},Ds=2,qs=Object.freeze({}),Ls=Object.freeze({}),zs=Object.freeze({}),Us=Object.freeze(["prevent","stop","ro","direct"]),Fs=Object.freeze(["init","sync"]),Vs=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function _s(){return{version:2,syntax:{bindAttribute:ie.bindAttributeName,tagName:ie.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(ae),modifiers:{flags:Us,keyValue:Fs,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:N,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:j,class:C,attr:M,style:P}}},filters:[...Object.keys(Te),...Object.keys(xn)],filterMeta:Rs,filterAliases:qs,declarationAliases:Ls,apiAliases:zs,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(Vs.map(e=>[e,{type:"boolean",default:!0}])),features:[...Is],nativeCommands:Object.fromEntries(Object.entries(Ms).map(([e,t])=>[e,[...t]]))}}var Bs=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),Hs=Object.freeze([]);function Ks(e){if(!ie.enableContractAnalyzer)return Hs;let t=[],n=gs,l=e=>{t.push(e),n?.(e)},r=e.manifestExtensions;if(null===r||"object"!=typeof r)return t;for(let e of Object.keys(r))Bs.has(e)||l({type:"contract:unsupported-extension",namespace:e});let i=r["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=Js(e);if(l({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){l({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let r=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(r.observables??{})){let r=n.ue.get(t);if(void 0===r){l({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==r&&l({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:r})}for(let t of Object.keys(r.inputs??{}))n.inputs.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(r.commands??{}))n.commands.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function Js(e){let t=customElements.get(e)?.wcBindable;if(null===t||"object"!=typeof t||"wc-bindable"!==t.protocol)return null;let n=e=>Array.isArray(e)?e:[],l=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&l.set(e.name,e.event);let r=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{ue:l,inputs:r(t.inputs),commands:r(t.commands)}}function Ys(e,t){(function(e){for(let t of e)s.has(t.name)||(s.add(t.name),t.install())})(Es),rn(e,t)}export{wi as Ssr,Ce as TRUSTED_TYPES_POLICY_SLOT,vi as VERSION,Ds as WCS_MANIFEST_VERSION,Ks as analyzeContract,Ys as bootstrapState,on as buildBindings,qs as builtinFilterAliases,Rs as builtinFilterMeta,Ws as defineState,Zt as getBindingsReady,se as getConfig,Me as getTrustedTypesPolicy,_s as getWcsManifest,Pe as setTrustedTypesPolicy};
1
+ var e={};function t(e,t){return null==e?t:(...n)=>{e(...n),t(...n)}}function n(e,t,n){return null==t?n:(...l)=>{let r=t(...l);return e(r)?r:n(...l)}}var l=e=>!0===e,r=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.It&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.It(t)}}function a(e,t){if(!s.has(e))throw new Error(`[@wcstack/state] [wcs/feature-not-installed] ${t} needs the add-on @wcstack/state/features/${e}`)}var u=class{constructor(e,t,n){this.u=[],this.getter=null,this.se=null,this.ae=!1,this.L=[],this.Q=[],this.mt=null,this.F=-1,this.Y=c,this.Me=null,this.Dt=null,this.Mt=null,this._=null,this.pn=!1,this.mn=!1,this.hn=!1,this.Z=0,this.ht=new Set,this.t=e,this.c=n,this.s=t;let l=null===n?[null]:n.h.slice(),r="*"===t;r&&l.push(n),this.n=l.length-1,this.z=r?[]:null===n?[t]:[...n.z,t],this.h=l}_n(e){this.ht.has(e)||(this.ht.add(e),this.L.push(e),e.Q.push(this))}Do(e){this.ht.delete(e);let t=this.L;t.splice(t.indexOf(e),1)}Mo(){this.getter=null,this.se=null,this.F=-1,this.Y=c,this.L.length=0,this.ht.clear(),this.Q.length=0,this.mt=null,this.Me=null,this.Dt=null,this.Mt=null,this._=null}ee(e){let t=this;for(;null!==t;){if(t===e)return!0;t=t.c}return!1}},c=Symbol("unset"),f=Symbol("dirty"),h=Symbol("failed"),d=class{constructor(e=null){this.yt=new Map,this.Vn=e}wt(e){return this.yt.get(e)}get(e){let t=this.yt.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),l=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),l),this.Vn?.(t),this.yt.set(e,t),l&&l.u.push(t),t}all(){return this.yt.values()}jt(e){this.yt.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,l=e.split("."),r=[];for(let e=0;e<l.length;e++){let t=l[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,r.push(Number(t)),l[e]="*"):"*"===t&&r.push(-1)}if(!n)return{o:l.join("."),indexes:r};let i={o:e,indexes:null};return p.size>4095&&p.clear(),p.set(e,i),i}var g=class{constructor(e,t,n){this.bt=null,this.x=null,this.be=null,this._=null,this.u=null,this.w=!0,this.l=e,this.y=t,this.$=n}},y=class{constructor(e,t){this.R=null,this.f=[],this.x=null,this.B=null,this.te=!1,this.Lt=!1,this.vt=!1,this.o=e,this.ce=t,this.n=e.n+1}},b=[];function v(t,n,l){throw new Error(`[@wcstack/state] ${t}${e.Lo?.(t,n,l)??""}`)}function $(t,n=[]){return e.Bo?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function w(e,t,n,l){v($(e,t),n,l)}var A=class{constructor(e){this.St=new Set,this.name=e}get size(){return this.St.size}subscribe(e){return this.St.add(e),()=>{this.St.delete(e)}}unsubscribe(e){return this.St.delete(e)}emit(...e){let t=[];for(let n of this.St)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[@wcstack/state] ${$(17,[this.name])}`,e)}return t}};function k(e,t,n){if(void 0===e)return[];Array.isArray(e)||w(18,[t]);let l=new Set;for(let r of e)("string"!=typeof r||""===r)&&w(19,[t]),r===n&&w(20,[t,r,n]),l.has(r)&&w(21,[t,r]),l.add(r);return e}var x=Symbol.for("wcstack.transition-runner");function S(e){let t=globalThis[x];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function T(e,t,n){let l=S(e);if(null!==l)return l.run(t,{source:e,types:n});t()}var N="else",O="eventToken",j="command",C="class",M="attr",P="style",E=/^\$[1-9]\d{0,2}$/,W=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function I(e){let t=[],n=[],l="",r=null,i=!1,s=-1,o=-1,a=e=>{let r=function(e,t,n){let l=-1===t?e.length:t,r=-1===n?0:n;return e.slice(l-e.slice(0,l).trimStart().length,r+e.slice(r).trimEnd().length)}(l,s,o);(!e||r||i)&&(t.push(r),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:W.test(e)?Number(e):e)}(r,i))),l="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];r?n===r?r=null:(-1===s&&(s=l.length),l+=n,o=l.length):'"'===n||"'"===n?(r=n,i=!0):","===n?a():l+=n}return null!==r&&w(107,[r,e]),a(!0),{args:t,literals:n}}var R=e=>e.trim();function D(e,t){let n=[],l=null;for(let r=0;r<e.length;r++){let i=e[r];null!==l?i===l&&(l=null):"'"===i||'"'===i?l=i:i===t&&n.push(r)}return n}var q=(e,t)=>D(e,t)[0]??-1;function L(e,t){let n=[],l=0;for(let r of D(e,t))n.push(e.slice(l,r)),l=r+1;return n.push(e.slice(l)),n}function z(e,t,n){let l=q(e,"|");if(-1===l)return[e.trim(),[]];let r=e.slice(l+1).trim(),i=n.get(r);return void 0===i&&(i=function(e,t,n){let l=n??e.join("|");return e.map(e=>{let n=q(e,"("),r=(e=>D(e,")").pop()??-1)(e);if(-1===r&&(r=e.lastIndexOf(")")),-1!==n&&-1===r&&w(108,[e]),-1!==r&&-1===n&&w(109,[e]),-1!==r&&r<n&&w(110,[e]),-1!==r&&e.slice(r+1).trim().length>0){let t=e.slice(r+1).trim();w(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&w(112,[l]),i.includes("#")){let[,e]=i.split("#");w("input"===t?113:114,[i,e])}return-1===n?{Hn:i,args:[],literals:[]}:{Hn:i,...I(e.substring(n+1,r))}})}(L(r,"|").map(R),t,e),n.set(r,i)),[e.slice(0,l).trim(),i]}var U=new Map;function F(e){w(1101,[e])}function V(e){let[t,n]=z(e,"output",U);t.includes("@")&&w(32,[t]);let l=t,r=l.startsWith("."),i=r?l.slice(1):l;return(i.length>0&&i.split(".").some(e=>0===e.length)||!r&&0===i.length)&&w(119,[e]),function(e){e.includes("**")&&F(e);let t=e.split(".").length;t>512&&w(117,[e,t])}(l),{Ze:l,et:n}}var _=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],B=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function H(e){return e.includes("**")&&F(e),e}var K=0;function J(e,t,n){let l=e.get(t);return void 0===l&&e.set(t,l=n()),l}var Y=()=>new Set,G=()=>[],X=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function Z(e,t){return e===t||e!=e&&t!=t}function ee(e,t,n){let l=e._?.get(t);void 0!==l&&l.delete(n)&&0===l.size&&e._.delete(t)}function te(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function ne(e,t){for(;null!==e&&e.l.n>t;)e=e.l.ce;return null!==e&&e.l.n===t?e:null}function le(e,t,n){let l=ne(e,n);return null!==l&&l.l.o===t.h[n]?l:null}var re=class{constructor(e,t){this.je=0,this.d=null,this.Le=0,this.tt=new Set,this.nt=new Map,this.Un=Symbol("wcs.block"),this.element=null,this.kt=[],this.Be=null,this.Kn=[],this.Ht=0,this.X=null,this.oe=new Map,this.de=new Map,this.We=[],this._e=[],this.Ve=[],this.Et=!1,this.gn=!1,this.Ut=new WeakMap,this.D=0,this.Kt=0,this.yn=!1,this.qt=!1,this.zt=!1,this.Ce=0,this.qn=()=>{this.D=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.ve++;try{return e()}finally{t.ve--}},$eqIndex:(e,t=1)=>{let n=ne(this.d,t);null===n&&w(7,[e]);let l=this.o(e);if(null!==l.getter||l.ae)return this.watchIndex(t),n.y===this.read(l,null);let r=this.X;if(null!==r){let e=r.getter,n=l.Me??(l.Me=[]);if(!n.some(n=>n.getter===e&&n.Gn===t)){n.push({getter:e,Gn:t});let r=e.h[t];(r.Dt??(r.Dt=[])).push({source:l,getter:e})}}return n.y===this.v(l,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,ne(this.d,n.n)))},$dependOn:e=>{this.resolve(H(e),this.d),null!==this.X&&0===this.X.ve&&this.Jn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,l)=>this.wn(e,t,n,l),$resolve:(...e)=>{let t=H(e[0]),n=e[1]??[],l=this.o(t,!0);this.bn("$resolve",t,l,n,!0);let r=this.Qn(l,n,null);if(e.length<3)return this.read(l,r);this.P(l,r,e[2])},$postUpdate:e=>{this.resolve(H(e),this.d);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.$=n.l.R[n.y],X.delete(n.l.R),this.A.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.A=t,this.O=new d(e=>{this.He.push(e),this.ot(e)}),this.to(e);let n=this,l={getOwnPropertyDescriptor(e,t){let l=Reflect.getOwnPropertyDescriptor(n.target,t);return l&&(l.configurable=!0),l},get(e,t,l){let r=n.target;if("symbol"==typeof t)return Reflect.get(r,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=r[t];if("function"==typeof e)return l===n.proxy&&n.V?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.d),n.read(n.rp,n.rr)},set:(e,t,l)=>"symbol"==typeof t?Reflect.set(n.target,t,l):(n.resolve(H(t),n.d),n.P(n.rp,n.rr,l),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])l[e]=(t,...l)=>Reflect[e](n.target,...l);this.proxy=new Proxy({},l)}o(e,t){let n=this.O.get(e);return t||(n.pn=!0),n}no(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let l=Object.getOwnPropertyDescriptor(n,e);if(void 0===l.get&&void 0===l.set)continue;let r=this.o(e);r.getter=l.get??null,r.se=l.set??null,null!==r.getter&&r.n>0&&(r.F=this.je++)}for(let e of this.O.all())this.ot(e)}ot(e){e.t.includes("**")&&F(e.t),("__proto__"===e.s||"prototype"===e.s)&&w(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(E.test(n))e.getter=function(){return this[n]};else{let l=t.split("."),r=l.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(r<0||l.indexOf("*",r)>=0)return;e.getter=()=>(this.resolve(t,this.d),this.rp!==e?this.read(this.rp,this.rr):this.read(e.c,this.d)?.[n]),e.se=l=>{if(this.resolve(t,this.d),this.rp!==e)return this.P(this.rp,this.rr,l);let r=this.read(e.c,this.d);null==r&&w(4,[t,r]),r[n]=l}}e.hn=!0,e.n>0&&(e.F=this.je++)}Ue(e,t){let n=null===e?this.oe:e.u??=new Map,l=n.get(t);return void 0===l&&n.set(t,l=new y(t,e)),t.pn=!0,this.G(l),l}oo(e){try{this.G(e)}catch(t){this.Jt(t,e.o.t,e.x?.S??null,"for")}}G(t){let n=this.v(t.o,t.ce);if(n===t.R)return;this.io(t);let l=function(e,t,n){let l=Array.isArray(t)?t:b;if(l===e.R)return null;let r=e.f,i=l.length,s=r.length,o=new Array(i),a=0;for(;a<i&&a<s&&r[a].$===l[a];)o[a]=r[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&r[u].$===l[c];)o[c]=r[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,l[t]);else if(a>c)for(let e=a;e<=u;e++)n.Bt(r[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)r[e].$===l[e]&&(o[e]=r[e]);let i=new Map;for(let e=u;e>=a;e--){let n=r[e];if(e<=t&&o[e]===n)continue;let l=i.get(n.$);void 0===l?i.set(n.$,n):Array.isArray(l)?l.push(n):i.set(n.$,[l,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,r=l[t],s=i.get(r);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(r)):(n=s,i.delete(r))),o[t]=n??new g(e,t,r)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Bt(t);else n.Bt(e)}for(let e=a;e<i;e++){let t=o[e];t.y!==e&&(t.y=e,n.jo(t))}return e.f=o,e.R=l,r}(t,n,this);if(null===l)return;if(t.R===n){let e=J(this.Ut,n,G);if(e.push(t),e.length>1)for(let t of e)t.vt=!0}e.Qt?.(this,t,l),(null!==t.x||null!==t.B)&&!t.te&&(t.te=!0,this._e.push(t),this.Se());let r=t.o.Dt;if(null!==r)for(let{source:e,getter:n}of r){let r=this.v(e,null),i=l[r],s=t.f[r];i!==s&&(void 0!==i&&i.w&&this.Sn(n,i),void 0!==s&&this.Sn(n,s))}}jo(e){this.A.Ho(this,e)}Bt(e){e.w=!1;let t=e._;if(null!==t){for(let e of t)ee(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.R);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=m(e),l=this.rp=this.o(n.o,!0),r=n.indexes;this.rr=0===l.n?null:null===r?le(t,l,l.n):this.Qn(l,r,t,e)}Qn(e,t,n,l){let r=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.Ue(r,a),c=t[o++];if(c<0)c=le(n,e,s)?.y??-1;else if(l&&u.R===b&&Object(i=this.v(a,r))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=l.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(r=u.f[c]??null,null===r)break}return this.rp=e,r}it(e,t){return 0===e.n?te(this.target,e.z):null===t?void 0:te(t.$,e.z)}read(e,t){let n=this.X;if(null!==n&&0===n.ve&&this.Jn(e,t,n),null!==e.getter)return this.A.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&&w(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.ve++;try{return this.read(e,t)}finally{n.ve--}}Jn(e,t,n){let l=n.getter;e._n(l),0===l.n?e.Z!==n.fe&&(e.Z=n.fe,n.kn.push(e)):e.n>0&&ne(t,Math.min(e.n,l.n))!==ne(n.r,Math.min(e.n,l.n))&&(l.mt??(l.mt=new Set)).add(e)}Ko(e,t){for(let n=0;n<this.Ht;n++){let l=this.Kn[n];l.getter===e&&l.r===t&&w(701,[e.t])}this.Ht>=128&&w(801,[e.t]);let n=this.Ht++;this.Le++;let l=this.Kn[n]??={getter:e,r:t,ve:0,fe:0,kn:[]};l.getter=e,l.r=t,l.ve=0,l.fe=++K,l.kn.length=0;let r=this.X;this.X=l;let i=this.d;this.d=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.qo(e,l),t}finally{this.Le--,this.Ht--,this.X=r,this.d=i,l.r=null}}qo(e,t){let n=t.fe;for(let e of t.kn)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.Do(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.L.length>0)&&(null===n.getter||n.hn&&n.F<0)&&null===n._){n.mn=!0,this.O.jt(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.ve){let n=t.getter,l=n.h[e];if(l){let e=l.Mt??(l.Mt=[]);e.includes(n)||e.push(n)}}}rt(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:E.test(t)?+t.slice(1):0;return(e<1||e>128)&&w(1001,[t]),this.watchIndex(e),ne(this.d,e)?.y}let l=this.Xn[t];if(void 0!==l)return l;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.rt?.(this,t)}eq(e,t){this.resolve(e,this.d);let n=this.rp,l=this.rr;if(null!==n.getter||n.ae||n.n>0)return Z(this.read(n,l),t);let r=this.X;return null!==r&&0===r.ve&&this.Yo(n,t,r),Z(this.v(n,null),t)}Yo(e,t,n){let l=n.getter,r=n.r,i=null===r?this.Yn:r._??(r._=[]);for(let r=0;r<i.length;r++){let s=i[r];if(s.sub.getter===l&&s.source===e){if(Z(s.key,t))return void(s.fe=n.fe);s.fe!==n.fe&&(ee(e,s.key,s.sub),i.splice(r--,1))}}let s={getter:l,r};J(e._??=new Map,t,Y).add(s),i.push({source:e,key:t,sub:s,fe:n.fe})}eo(e,t,n,l){this.Zt(e,r=>{let i=r._;if(null===i&&null===r.Me)return;let s=r===e?[]:r.t.slice(e.t.length+1).split("."),o=te(t,s),a=te(n,s);if(null!==r.Me&&this.Xo(r,o,a,l),null!==i)for(let e of l?i.keys():[o,a]){let t=i.get(e);if(void 0!==t)for(let n of t)null===n.r||n.r.w?this.A.ke(this,n.getter,n.r):ee(r,e,n)}})}P(t,n,l,r=!1,i=!1){if(this.Le>0&&w(8),i||this.Ce>0?this.qt=!0:this.zt=!0,e.Ie?.(this,t,n,l,i))return;if(null!==t.se){try{this.En(t.se,n,[l])}finally{this.Gt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&w(2,[t.t]),t.n>0&&null===n&&w(3,[t.t]);let s=t.ae?this.v(t,n):this.it(t,n);if(r||!this._t||!Object.is(s,l)||Object(l)===l){if("*"===t.s){let e=n;e.l.R[e.y]=l,X.delete(e.l.R),e.$=l,this.A.Xt(e)}else{let e=1===t.z.length?0===t.n?this.target:n.$:this.v(t.c,n);null==e&&w(4,[t.t,e]),e[t.s]=l}this.$n(t,n),null!==n&&this.Zn(n,t,s,l),0===t.n&&this.eo(t,s,l),this.Gt(t,n,s,l,!0,i)}}lo(e){return(this.Ut.get(e.R)??[]).filter(t=>t.R===e.R&&(null===t.ce||t.ce.w))}Zn(e,t,n,l,r=!0){let i=e.l,s=t.t.slice(i.o.t.length+2),o=""!==s&&function(e){let t=X.get(e);if(void 0===t){let n=new Set;X.set(e,t=e.some(e=>Object(e)===e&&(n.has(e)||!n.add(e))))}return t}(i.R);if(!o&&!i.vt&&null===i.o.getter&&!i.o.L.length)return;let a=e.$,u=(t,i)=>{if(void 0===i||i===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(i.$=l,this.A.Xt(i)),r?this.$n(o,i):this.vn(o,i),this.Gt(o,i,n,l,r)};for(let t of this.lo(i))if(u(t,t.f[e.y]),o)for(let n of t.f)n.$===a&&n.y!==e.y&&u(t,n);if(""===s)return;let c=new Set([i.R]),h=e=>Array.isArray(e)&&e.includes(a),d=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.Ut.get(e)??[])for(let e of t.f)e.$===a&&u(t,e);for(let n of t){let t=n.Y,l=t===f;l&&(t=this.oe.get(n)?.R),(l||h(t))&&!c.has(n.L)&&c.add(n.L)&&(!l&&t!==e&&this.A.ke(this,n,null),d(t,n.L))}},p=e=>{for(let t of e.Q)if(!c.has(t)&&c.add(t))if(null!==t.getter)p(t);else if(!t.ae){let e=this.it(t,null);h(e)&&d(e,t.L)}};null!==i.o.getter?p(i.o):d(i.R,i.o.L)}vn(e,t){this.Go(e,t,e=>{this.G(e);for(let t of e.vt?this.lo(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.f)this.$t(e,n),this.vn(e,n)}})}$n(e,t){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())t.o.ee(e)&&this.G(t)}Go(e,t,n){let l=null===t?this.oe:t.u;if(null!==l)for(let t of l.values())t.o.ee(e)&&n(t)}Xo(e,t,n,l){for(let{getter:r,Gn:i}of e.Me)this.ao(r.h[i],e=>{for(let i of l?e.f.keys():[t,n]){let t="number"==typeof i?e.f[i]:void 0;void 0!==t&&this.Sn(r,t)}})}Sn(e,t){t.l.n===e.n?this.A.ke(this,e,t):this.en(t,e,t=>this.A.ke(this,e,t))}Gt(t,n,l,r,i,s){e.re?.(this,t,n,l,r,i,s),this.Ke(t,n)}Ke(e,t){this.A.Jo(this,e,t),this.Se()}co(e){let t=this.nt.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.nt.set(e,n);let l=this.root,r=this.Un;return l.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==l;i=i.parentNode){let l=i[n];if(void 0!==l&&(l(t),t.cancelBubble))return;let s=i[r];if(void 0!==s&&s.w&&s.Qo(e,t))return}}),n}reset(t){let n=this.target,l=this.tt;for(let e of this.O.all())null===e.c&&null!==e.getter&&l.add(e.s);this.to(t);for(let e in n)"$"!==e[0]&&l.add(e);for(let e of l)e in t&&l.delete(e);for(let e of this.de.values())for(let t of e)this.tn(t);for(let e of this.oe.values())this.uo(e);this.Be=null;try{this.Yt()}finally{this.xn()}e.element?.(this,"reset")}to(t){for(let[e,n]of _)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||w(46);for(let e of n)a(e,"$features")}let l=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof l||!l||Array.isArray(l))&&w(44,["state","$behavior"]);for(let e in l)(!B.includes(e)||"boolean"!=typeof l[e])&&w(44,["$behavior",e]);let[r,i,s]=B.map(e=>l[e]??!0);void 0!==this.target&&(r!==this.Wt||i!==this._t||s!==this.Vt)&&w(45);let o=function(e,t){let n={};for(let l of k(e.$commandTokens,"$commandTokens","$command"))n[l]=t?.[l]??new A(l);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of k(e.$eventTokens,"$eventTokens"))n.set(t,new A(t));let l=e.$on;if(void 0===l)return n;(null===l||"object"!=typeof l)&&w(22);for(let[e,r]of Object.entries(l)){let l=n.get(e);void 0===l&&w(23,[e]),"function"!=typeof r&&w(24,[e]),l.subscribe((...e)=>t(r,e))}return n}(t,this._o);this.Wt=r,this._t=i,this.Vt=s,e.pe?.(this,t),this.target=t,this.je=0;for(let e of this.O.all())e.Mo();this.Yn.length=0,this.no(t),this.commands=o,this.ue=u}uo(e){this.oo(e);let t=this.o(`${e.o.t}.*`);for(let n of e.f)if(n.bt=null,n._=null,this.$t(t,n),null!==n.u)for(let e of n.u.values())this.uo(e)}H(e){let t=[];for(let n=e;null!==n;n=n.l.ce)t.unshift(n.y);return t}Zo(e,t,n){let l=this.ue.get(e);void 0===l&&w(1301,[e],e,this.ue.keys()),l.emit(t,...this.H(n))}command(e){let t=this.commands[e];return void 0===t&&w(1302,[e],e,Object.keys(this.commands)),t}er(e,t,n){this.command(e).emit(t,...this.H(n))}tr(e,t,n){let l=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof l&&w(5,[e]),this.En(l,n,[t,...this.H(n)])}En(e,t,n){let l=this.d;this.d=t;try{return e.apply(this.proxy,n)}finally{this.d=l}}$t(e,t){if(null!==e.getter){let n=null===t?this.oe:t.u;if(null!==n)for(let t of n.values())!t.Lt&&t.o.ee(e)&&(t.Lt=!0,this.Ve.push(t))}if(null===t)return void this.Zt(e,e=>{let t=this.de.get(e);if(void 0!==t)for(let e of t)this.tn(e)});let n=t.be;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.ee(e)&&this.tn(n[t]);let l=t.x;null!==l&&null!==l.me&&l.fo(this,e);let r=t.l.B;if(null!==r)for(let n of r){let l=n.map.get(t);void 0!==l&&null!==l.me&&l.fo(this,e)}}Nn(e,t,n){this.Zt(e,e=>{let l=e.L;for(let r=0;r<l.length;r++){let i=l[r];if(0===i.n)this.st(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.mt&&i.mt.has(e))this.nn(i.h[i.n],e=>this.st(i,e,n));else if(i.n<=e.n){let e=ne(t,i.n);null!==e&&this.st(i,e,n)}else this.en(t,i,e=>this.st(i,e,n))}})}st(t,n,l){l(t,n)&&(e.Ee?.(this,t,n),this.$t(t,n),this.Nn(t,n,l))}Zt(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.Zt(n[e],t)}nn(e,t){this.ao(e,e=>{for(let n of e.f)t(n)})}ao(e,t){if(0===e.n){let n=this.oe.get(e);return void(void 0!==n&&t(n))}this.nn(e.h[e.n],n=>{let l=n.u?.get(e);void 0!==l&&t(l)})}en(e,t,n){if(e.l.n===t.n)return n(e);let l=e.u?.get(t.h[e.l.n+1]);if(void 0!==l)for(let e of l.f)this.en(e,t,n)}nr(e){let t=e.r;null===t?J(this.de,e.o,Y).add(e):(t.be??(t.be=[])).push(e)}Tn(e){let t=e.r;if(null===t)return void this.de.get(e.o)?.delete(e);let n=t.be;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}tn(e){e.te||(e.te=!0,this.We.push(e),this.Se())}Se(){this.Et||(this.Et=!0,queueMicrotask(this.Wo))}Rn(){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.A.tt(this)}po(t,n){let l=[...new Set([...this.We,...this._e,...this.Ve].map(e=>e.o.t))];console.error(`[@wcstack/state] ${$(t)}`,l),e.at?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:l}),this.Rn()}Yt(){this.Et=!1;let t=this.Kt;this.Kt=0;let n=0;if(!this.qt||this.zt?this.qn():t>0?n=t:1===(n=++this.D)&&setTimeout(this.qn,0),this.qt=this.zt=!1,n>100)101===n?this.po(41,100):this.Rn();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.Rn():this.po(11,32),this.yn=!0;break}let t=this.Ve;if(t.length>0){this.Ve=[];for(let e of t)e.Lt=!1,this.oo(e)}let l=this._e,r=this.We;this._e=[],this.We=[];let i=()=>{for(let e of l){e.te=!1;for(let t of[e.x,...e.B??[]])if(null!==t&&t.w)try{t.xt()}catch(n){this.Jt(n,e.o.t,t.S,"for")}}for(let e=0;e<2;e++)for(let t=0;t<r.length;t++){let n=r[t];!n.te||null===n.D==(0===e)||(n.te=!1,(null===n.An||n.An.w)&&this.qe(n))}this.gn||(this.ze(),this.Et&&(this.Kt=n+1))},s=l.length>0||r.some(e=>null!==e.D)?T("state",i):i();void 0!==s&&s.then(void 0,e=>console.error(e))}}finally{this.gn=!1}this.qt=this.zt=!1,this.ze(),e.he?.(this),this.zo(),t>0&&this.Et&&(this.Kt=n+1)}}Nt(e,t){this.kt.push([e,t])}Jt(e,t,n,l){this.Nt(e,{o:{t},a:n,on:()=>l})}qe(e){try{e.apply()}catch(t){return void this.kt.push([t,e])}null!==this.Be&&this.mo(e.o,e.r)}mo(e,t){let n=J(this.Be,e.t,G);null!==t&&n.push(this.H(t))}xn(){this.Be="function"==typeof this.target.$renderedCallback?new Map:null}ze(){let t=this.Be;if(null!==t&&t.size>0){this.Be=new Map;let e,n=[...t.keys()],l={};for(let[e,n]of t)n.length>0&&(l[e]=n);this.Ce++;try{e=this.$e("$renderedCallback",[n,l])}catch(e){console.error(e)}Q(e)?e.then(this.zn,e=>{this.zn(),console.error(e)}):this.Ce--}if(0===this.kt.length)return;let n=this.kt;this.kt=[];let l=this.target.$errorCallback;for(let[t,r]of n){e.Ye?.(this,t,r);let n=r.o.t,i=r.on();if("function"==typeof l)try{let e=this.$e("$errorCallback",[t,{path:n,bindingType:i,node:r.a}]);Q(e)&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}else console.error(`[@wcstack/state] ${$(12,r.name?[i,n,r.name,r.i]:[i,n])}`,t,r.a)}}$e(e,t=[]){let n=this.target[e];return"function"==typeof n?this.En(n,null,t):void 0}ho(e,t,n){if(0===e.n)return void n(null,[]);let l=[],r=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.Ue(s,o),u=t=>{l.push(t.y),i===e.n?n(t,l):r(i+1,t),l.pop()};for(let e of i-1<t.length?[a.f[t[i-1]]]:a.f)void 0!==e&&u(e)};r(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.bn("$getAll",e,n,t,!1);let l=t;if(void 0===l){l=[];let t=this.d;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let r=le(t,n,e);if(null===r)break;l.push(r.y)}0===l.length&&w(6,[e])}}let r=[];return this.ho(n,l,e=>r.push(this.read(n,e))),r}wn(e,t,n,l){Array.isArray(t)||w(9,[e]),this.Le>0&&w(8);let r=this.o(e,!0);this.bn("$setAll",e,r,t,!1);let i=[];this.ho(r,t,(e,t)=>i.push([e,t.slice()]));let s=!0===l?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&w(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,l]=i[e],a="function"==typeof n?n(this.v(r,t),...l):s?n[e]:n;void 0!==a&&(this.P(r,t,a),o++)}return o}bn(e,t,n,l,r){let i=l.length;(i>n.n||r&&i<n.n)&&w(r?901:902,[e,t,n.n,i])}},ie={bindAttributeName:"data-wcs",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:typeof document<"u"&&document.documentElement?.lang||"en",enableContractAnalyzer:!1},se=()=>ie,oe=new Map,ae=new Set(["if","elseif","else","for"]),ue=new Set([N,"if","elseif","for","..."]),ce=new Set([C,M,P,j,O,"state"]);function fe(e){let t=function(e){return L(e,";")}(e).map(R).filter(e=>e.length>0).map(e=>{let t=q(e,":");-1===t&&w(101,[e]);let n=e.slice(0,t).trim(),l=e.slice(t+1).trim(),r=n.split("#")[0].split("|")[0].trim();if(ue.has(r)){let t;return r!==n&&w(102,[e,r]),r===N?(l.length>0&&w(103,[e]),t={Ze:"#else",et:[]}):"..."===r?(0===l.length&&w(104,[e]),t=V(l),t.et.length>0&&w(105,[e])):(t=V(l),"for"===r&&t.et.length>0&&w(121,[e])),{xe:r,Ne:[r],rn:[],M:[],...t,b:"..."===r?"spread":r}}(r===C||r===M)&&w(122,[e,r]);let i=V(l),s=function(e){let[t,n]=z(e,"input",oe),l=t.split("#").map(R);l.length>2&&w(115,[t]);let[r,i]=l,s=r.split(".").map(R);return!(s.length>1&&""===s[0])&&(0===r.length||s.some(e=>0===e.length))&&w(116,[e]),{xe:r,Ne:s,rn:i?i.split(",").map(R):[],M:n}}(n),[o]=s.Ne;if(""===o&&s.Ne.length>1){let e=s.Ne.slice(1);return(e.includes("")||ce.has(e[0]))&&w(106,[n]),{...s,xe:e.join("."),Ne:e,...i,b:"prop"}}return{...s,...i,b:"radio"===r||"checkbox"===r?r:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ae.has(e.b))&&w(201,[e]),t}var he=["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"],de=new Map,pe=new Map;function me(e){for(let t of Object.keys(e))de.set(t,{...e[t]});pe.clear()}function ge(e){return de.has(e)}function ye(e){w(26,[e])}function be(e){w(27,[e])}function ve(e,t){w(28,[e,t])}function $e(e,t){w(29,[e,t])}function we(e){return!(!e||isNaN(Number(e)))}function Ae(e,t){return we(e)||be(t),Number(e)}function ke(e,t,n){return Ae(e?.[t]??ye(n),n)}function xe(e,t){return void 0!==t&&t.length>0?t[0]:e}var Se=(e,t)=>({factory:n=>{let l=ke(n,0,e);return n=>("number"!=typeof n&&ve(e,n),t(n,l))},arity:[1,1]}),Te={eq:{factory:(e,t)=>{let n=e?.[0]??ye("eq"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e===l:(we(n)||be("eq"),e===Number(n)):"string"==typeof e?e===n:e===l},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??ye("ne"),l=xe(n,t);return e=>"number"==typeof e?"string"!=typeof l?e!==l:(we(n)||be("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==l},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Se("lt",(e,t)=>e<t),le:Se("le",(e,t)=>e<=t),gt:Se("gt",(e,t)=>e>t),ge:Se("ge",(e,t)=>e>=t),falsy:{factory:()=>e=>!e,arity:[0,0]},truthy:{factory:()=>e=>!!e,arity:[0,0]},boolean:{factory:()=>e=>!!e,arity:[0,0]}},Ne=!1;function Oe(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function je(e){return 0===e.length?null:(Ne||(Ne=!0,me(Te)),e.map(e=>function(e,t,n){let l=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,r=pe.get(l);if(typeof r<"u")return r;let i=de.get(e);void 0===i&&function(e,t){he.includes(e)&&v(`[wcs/filter-unknown] filter not found: ${e}. "${e}" is in the formats add-on — install it with installFeatures([formats]) from "@wcstack/state/features/formats".`,e,t),w(501,[e],e,t)}(e,de.keys());let[s,o]=i.arity;t.length<s&&w(601,[e,s,t.length]),t.length>o&&w(602,[e,o,t.length]);let a=i.factory(t,n);return pe.set(l,a),a}(e.Hn,e.args,e.literals)))}var Ce=Symbol.for("wcstack.trustedTypes.policy");function Me(){let e=globalThis[Ce];return null!==e&&"object"==typeof e?e:null}function Pe(e){globalThis[Ce]=e}function Ee(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function We(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Me(),l=n?.createHTML;return"function"==typeof l?l.call(n,t):t}var Ie=Symbol.for("wcstack.state.view-transition-naming"),Re=new WeakSet;function De(){let e=S("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var qe=new WeakMap,Le=e=>e.customElementRegistry??customElements;function ze(e,t,n,l,r,i=!1){let s=n.localName;if(!s.includes("-"))return r(null);let o=Le(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>ze(e,t,n,l,r,!0));let a=()=>{let e=o.get(s);o.upgrade(n),r(e?function(e){if(qe.has(e))return qe.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 qe.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==l&&!l.w||function(e,t,n){let l=n;null!==t&&(t.Tt??=[]).push(()=>{l=null}),e.then(()=>l?.())}(o.whenDefined(s),l,()=>{try{a()}catch(l){He(e,l,t,n)}e.Se()})}function Ue(t,n,l,r,i=n.o,s,o,a){let u=a.properties.get(r)??null,c=a.inputs.has(r),f=t.Vt;f&&null===u&&!c&&w(38,[r]);let h=n.U;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&w(39,[h,r]),"connect"===n.G&&null===u&&w(40,[r]);let d=f&&null!==u&&!c,p=new Ye(t,_e,l,r,i,s,o,n.N,void 0);p.M=n.M,lt(t,p,!d),null!==u&&!n.ro&&l.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.go||e.detail?.(l,r,i)),(!p.Pn||!Object.is(i,p.value))&&(i=Oe(p.M,i),null===p.N&&(p.value=i),t.P(p.o,p.r,i,u.go,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.qe(p);else if("element"===m||"auto"===m){let e=()=>{if(null!==o&&!o.w)return;if("auto"===m&&void 0!==t.v(p.o,p.r))return void(d||t.qe(p));let e=l[r];null===p.N&&(p.value=e),t.P(p.o,p.r,e,!1,!0)};"connect"!==n.G||l.isConnected?e():Promise.resolve().then(e)}return p}function Fe(e,t,n){w(e,[t.localName,n])}var Ve=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),_e=11,Be=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],He=(e,t,n,l)=>e.Jt(t,n.o?.t??n.Rt,l,Be[n.i]),Ke=Symbol();function Je(e,t,n){let l=t.U;return null===l||"state"===l||"auto"===l&&void 0!==e.v(t.o,n)?t.K:Ke}var Ye=class{constructor(e,t,n,l,r,i,s,o,a,u=null){this.te=!1,this.M=null,this.Pn=!1,this.engine=e,this.i=t,this.a=n,this.name=l,this.o=r,this.r=i,this.An=s,this.N=o,this.value=a,this.D=u}on(){return Be[this.i]}apply(){if(null!==this.D)return void this.D.xt();let e=Oe(this.N,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===_e||8===this.i||Ee(this.name)))return;if(this.value===Ke)return void(this.value=e);let t=this.a;if(this.i!==_e)9===this.i?t.checked=void 0!==e&&this.sn()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.sn()):Xe(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.Pn=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.Pn=!1}}}sn(){return Oe(this.M,this.a.value)}ir(){let e,t=this.a,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.sn()}else if(10===this.i){let l=this.sn(),r=n.v(this.o,this.r),i=Array.isArray(r)?r:[],s=i.includes(l);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==l):[...i,l]}else e=Oe(this.M,t[this.name]),this.value=NaN;n.P(this.o,this.r,e,!1,!0)}},Ge=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Xe(e,t,n,l){switch(e){case 0:return void(t.data=null==l?"":String(l));case 1:return void(Ge(n)?t[n]="innerHTML"===n?We(l):null==l?"":String(l):Ee(n)?null==l&&"srcdoc"===n?t.removeAttribute(n):void 0!==l&&(t[n]=We(l)):void 0!==l&&(t[n]!==l&&!("value"===n&&t.value===String(l))&&(t[n]=l),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Qe]=[n,l])));case 8:return void(t.innerHTML=We(l));case 2:return null!=l&&"boolean"!=typeof l&&w(401,[n,typeof l]),void t.classList.toggle(n,!0===l);case 3:return void(null==l?t.removeAttribute(n):t.setAttribute(n,String(l)));case 4:return void(n.includes("-")?null==l?t.style.removeProperty(n):t.style.setProperty(n,String(l)):t.style[n]=null==l?"":String(l))}}var Qe=Symbol();function Ze(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Qe];void 0!==n&&(t[n[0]]=n[1])}var et=class{constructor(e,t,n,l){this.w=!0,this.be=null,this.u=null,this.Tt=null,this.On=null,this.r=e,this.ct=t,this.j=n,this.C=l}Qo(e,t){let n=t.target,l=this.C,r=[],i=null;for(let t of l.ue){if(t.name!==e)continue;let s=l.Cn[t.a],o=ht(null===this.j?this.ct:this.j[s[0]],s,1);o.contains(n)&&(o!==i&&r.unshift([]),r[0].push(t),i=o)}for(let e of r){for(let n of e)n.Fn(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.j?this.ct:this.j[this.j.length-1]}Re(){let e=this.On;return(null===e?null:e.In(this.ct))??this.ct}insertBefore(e,t){let n=this.s;for(let l=this.Re();;){let r=l.nextSibling;if(e.insertBefore(l,t),l===n)return;l=r}}bo(){null===this.j?this.ct.remove():dt(this.Re(),this.s)}Ae(e){if(this.w=!1,null!==this.Tt)for(let e of this.Tt)e();let t=this.be;if(null!==t)for(let n=0;n<t.length;n++)e.Tn(t[n]);if(null!==this.u)for(let e of this.u)e.Ae()}},tt=class extends et{constructor(e,t,n,l){super(e,t,n,l),this.vo=0,this.V=null,this.me=0===l.Xe.length?null:new Array(2*l.Xe.length)}So(e,t){let n=this.V??=new Array(this.C.Xe.length),l=n[t];if(void 0===l){let r=this.C.Xe[t],i=this.me;l=n[t]=new Ye(e,r.i,i[2*t],r.name,r.o,this.r,this,r.N,i[2*t+1])}return l}fo(e,t){let n=this.C.Xe;for(let l=0;l<n.length;l++)n[l].o.ee(t)&&e.tn(this.So(e,l))}Ae(e){let t=this.r;t.x===this&&(t.x=null),super.Ae(e)}};function nt(e,t,n,l){let r=ne(n,t.n);try{return e.Ue(r,t)}catch(n){return e.Jt(n,t.t,l,"for"),null===r?e.oe.get(t):r.u.get(t)}}function lt(e,t,n){n&&e.nr(t);let l=t.An;null!==l&&(l.be??=[]).push(t)}var rt=null;function it(){let e=rt;return rt=null,e}var st=-1;function ot(t,n,l,r,i=null){let s,o=n.Cn,a=n.build,u=n.ko,c=null,f=e.Pe?.(n,null===r?i:r.S,null!==r),h=!f&&n.Dn,d=f?document.createDocumentFragment():(h?n.root:n.ln).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=ht(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==r?(p=m=new tt(l,s,c,n),null===r.map?l.x=m:r.map.set(l,m)):p=new et(l,s,c,n),st>=0&&function(e,t,n,l){let r=null;if(null===t)r=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===r;e++)1===t[e].nodeType&&(r=t[e]);let i=r?.style;if(null===r||void 0===i||Re.has(r))return;let s=globalThis[Ie]??={counter:0,assigned:0,warned:!1};s.assigned>=l?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${$(25,[l])}`)):(Re.add(r),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==r?"row":"branch",st),n.ue.length>0){let e=t.Un;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.sr,y=t.Be,b=n.lr?u.slice(0,o.length):u,v=null===m?null:m.me;if(null!==v){let e=n.Xe;for(let t=0;t<e.length;t++)v[2*t]=b[e[t].a],v[2*t+1]=e[t].K}for(let e=0;e<g.length;e++){let n=g[e],r=b[n.a],i=n.F;if(i>=0&&null!==v){let e=m.V?.[i];if(void 0!==e){e.te=!1,t.qe(e);continue}try{let e=Oe(n.N,t.read(n.o,l));e!==n.K&&(Xe(n.i,r,n.name,e),v[2*i+1]=e),null!==y&&t.mo(n.o,l)}catch(e){t.Nt(e,m.So(t,i))}continue}switch(n.i){case 6:{let e=new ft(t,n.C,nt(t,n.o,l,r),r);(p.u??=[]).push(e),r===s&&(p.On=e),e.xt();break}case 7:{let e=ut(t,n.q.map(e=>({C:e.C,o:e.o,N:e.N,S:b[e.a]})),l,p);(p.u??=[]).push(e),r===s&&(p.On=e);break}default:try{at(t,n,r,l,p)}catch(e){He(t,e,n,r)}}}return rt=p,d}function at(t,n,l,r,i){let s=l;switch(n.i){case 5:return void function(e,t,n,l,r){let i=n.Fn,s=e=>i(e,l);if(n.nt){let l=e.co(n.name),r=t[l];t[l]=void 0===r?s:e=>{r(e),s(e)},n.Te&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.wo&&null!==r&&(r.Tt??=[]).push(()=>t.removeEventListener(n.name,s))}(t,l,n,r,i);case 12:return void ze(t,n,s,i,l=>function(t,n,l,r,i){let s=n.name,o=t.command(n.Rt.slice(9)),a=null===i?e.or?.(l,s):null;a||(null===i&&Fe(1202,l,`command.${s}`),i.commands.has(s)||w(1203,[l.localName,s]));let u=new WeakRef(l),c=o.subscribe((...e)=>{let t=u.deref();if(void 0!==t)return t.isConnected?a?a(t,e):t[s](...e):void 0;c()});null!==r&&(r.Tt??=[]).push(c)}(t,n,s,i,l));case 13:return void ze(t,n,s,i,e=>function(e,t,n,l,r){let i=t.name;null===r&&Fe(1202,n,`eventToken.${i}`);let s=r.properties.get(i);void 0===s&&w(1204,[n.localName,i]);let o=t.Rt;n.addEventListener(s.event,n=>{t.At&&n.preventDefault(),t.Pt&&n.stopPropagation();try{e.Zo(o,n,l)}catch(e){console.error(e)}})}(t,n,s,r,e))}let o=n.o,a=ne(r,o.n);if(14===n.i)return void ze(t,n,s,i,e=>function(e,t,n,l,r,i){null===i&&Fe(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.yo?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:l;Ue(e,{...t,U:null,G:null},n,o,s,a,r,i)}}(t,n,s,a,i,e));if(n.Te&&1===n.i)return void ze(t,n,s,i,l=>function(t,n,l,r,i,s){if(null!==s)return void Ue(t,n,l,n.name,n.o,r,i,s);let o=new Ye(t,1,l,n.name,n.o,r,i,n.N,Je(t,n,r));o.M=n.M,!e.ar?.(o,n.ro)&&(lt(t,o,!0),t.qe(o))}(t,n,s,a,i,l));let u=new Ye(t,n.i,l,n.name,o,a,i,n.N,Je(t,n,a));u.M=n.M,lt(t,u,!0),t.qe(u),null!==n.Ft&&l.addEventListener(n.Ft,()=>u.ir())}function ut(e,t,n,l){let r=new ct(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Ye(e,7,s.S,"if",t,ne(n,t.n),l,null,void 0,r);lt(e,o,!0),null===l&&r.de.push(o),i??=o}return e.qe(i),r}var ct=class{constructor(e,t,n){this.w=!0,this.I=null,this.y=-1,this.de=[],this.engine=e,this.q=t,this.r=n}In(e){return null!==this.I&&this.q[this.y].S===e?this.I.Re():null}xt(){let e=this.engine,t=-1;for(let n=0;n<this.q.length;n++){let l=this.q[n];if(null===l.o||Oe(l.N,e.read(l.o,ne(this.r,l.o.n)))){t=n;break}}if(t!==this.y&&(st=De(),null!==this.I&&(this.I.bo(),this.I.Ae(e),this.I=null),this.y=t,t>=0)){let n=this.q[t],l=ot(e,n.C,this.r,null,n.S);this.I=it();let r=n.S.parentNode;r.insertBefore(l,n.S),Ze(r)}}Ae(){this.w=!1;for(let e of this.de)this.engine.Tn(e);null!==this.I&&this.I.Ae(this.engine)}},ft=class{constructor(e,t,n,l){this.w=!0,this.Fe=[],this.engine=e,this.C=t,this.l=n,this.S=l,null===n.x?(n.x=this,this.map=null):((n.B??=[]).push(this),this.map=new Map)}In(e){return 0===this.Fe.length?null:this.Fe[0].Re()}Ot(e){return null===this.map?e.x:this.map.get(e)??null}jt(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ae(this.engine)}xt(){let e=this.engine,t=this.l.f,n=this.Fe;st=De();let l=t.length,r=n.length,i=this.S,s=i.parentNode;if(0===l){if(r>0){let e=n[0].Re(),t=n[r-1].s,l=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){l=null;break}l.push(n)}null!==l?s.replaceChildren(...l):dt(e,t);for(let e=0;e<r;e++)this.jt(n[e])}return void(this.Fe=[])}let o=new Array(l),a=0;for(;a<l&&a<r&&this.Ot(t[a])===n[a];)o[a]=n[a],a++;let u=r-1,c=l-1;for(;u>=a&&c>=a&&this.Ot(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],l=t.r;l.w&&this.Ot(l)===t?t.vo=e:(t.bo(),this.jt(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(r>0)for(let e=0;e<n;e++){let n=this.Ot(t[a+e]);null!==n&&n.w?(u[e]=n.vo,f=!0):u[e]=-1}let h=c+1<l?o[c+1].Re():i;if(f){let l=function(e){let t=e.length,n=new Uint8Array(t),l=new Int32Array(t).fill(-1),r=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=r.length;for(;i<s;){let n=i+s>>1;e[r[n]]<t?i=n+1:s=n}i>0&&(l[n]=r[i-1]),r[i]=n}let i=r.length>0?r[r.length-1]:-1;for(;i>=0;)n[i]=1,i=l[i];return n}(u),r=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Ot(n);null!==u&&u.w?0===l[i]&&u.insertBefore(s,r):(s.insertBefore(ot(e,this.C,n,this),r),u=it()),o[a+i]=u,r=u.Re()}}else{let n=document.createDocumentFragment();for(let l=a;l<=c;l++)n.appendChild(ot(e,this.C,t[l],this)),o[l]=it();s.insertBefore(n,h)}}this.Fe=o,Ze(s)}Ae(){this.w=!1;let e=this.l;if(e.x===this)e.x=null;else if(null!==e.B){let t=e.B.indexOf(this);t>=0&&e.B.splice(t,1),0===e.B.length&&(e.B=null)}for(let e of this.Fe)e.Ae(this.engine);this.map?.clear()}};function ht(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let l=t[n];l>0;l--)e=e.nextSibling}return e}function dt(e,t){for(let n,l=e;l!==t;l=n)n=l.nextSibling,l.remove();t.remove()}var pt=()=>ie.bindAttributeName;function mt(){return{a:0,i:1,name:"",o:null,N:null,K:c,Fn:null,C:null,q:null,M:null,Ft:null,Te:!1,U:null,G:null,ro:!1,At:!1,Pt:!1,Rt:null,yo:null,F:-1,nt:!1,wo:!1}}var gt=["state","element","auto","none"],yt=["call","connect"],bt="$command.";function vt(t,n,l){E.test(n)&&(null===l&&w(1401,[n,Number(n.slice(1))]),n=`${l.t}.*.${n}`);let r=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&w(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,l)),i=null===l?0:l.n+1;r.n>i&&w(1401,[r.t,r.n,i]);for(let e=1;e<=r.n;e++){let t=e===i?l:l.h[e];r.h[e]!==t&&w(1403,[r.t,r.h[e].t,t.t])}return e.Eo?.(t,r),r}var $t=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),wt=e=>8===e.i||$t(e)||1===e.i&&Ge(e.name);function At(e){w(202,[e])}function kt(t,n,l,r,i){let s=fe(n).map(n=>function(t,n,l,r,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),l=null,r=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Vt||w(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&w(33,[i,n]),null!==(o?l:r)&&w(34,[i]),(o?gt:yt).includes(s)||w(35,[i,s]),o?l=s:r=s}return{ro:t.includes("ro"),At:t.includes("prevent"),Pt:t.includes("stop"),event:n?n.slice(2):null,U:l,G:r}}(t,n.rn),o=r.localName.includes("-"),a=n.Ne,u=n.Ze;if("event"===n.b){if(null!==s.U&&"none"!==s.U&&w(36),"eventToken"===a[0])return{...mt(),a:i,i:13,name:a.slice(1).join("."),Rt:u,Te:o,At:s.At,Pt:s.Pt};let l=u.startsWith(bt)?u.slice(9):null,{At:r,Pt:c}=s,f=n.xe.slice(2),h=n.rn.includes("direct"),d=!h&&Ve.has(f);d&&t.co(f);let p=n=>{console.error(n),d&&e.handlerThrew?.(t,u,f)};return{...mt(),a:i,i:5,name:f,nt:d,Te:o,wo:h,Fn(e,n){r&&e.preventDefault(),c&&e.stopPropagation();try{if(null!==l)t.er(l,e,n);else{let l=t.tr(u,e,n);Q(l)&&l.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===n.b)return{...mt(),a:i,i:14,o:vt(t,u,l),Te:o};if("command"===a[0]&&a.length>1)return u.startsWith(bt)||w(1201,[n.xe,u]),{...mt(),a:i,i:12,name:a.slice(1).join("."),Rt:u,Te:o};let c=vt(t,u,l),f={...mt(),a:i,i:1,name:n.xe,o:c,N:je(n.et),M:je(n.M),ro:s.ro,U:s.U,G:s.G};if("radio"===n.b||"checkbox"===n.b)return("element"===s.U||"auto"===s.U)&&w(37,[n.b,s.U]),f.i="radio"===n.b?9:10,s.ro||(f.Ft=s.event??"input"),f;if(a.length>1){let e=a.slice(1).join("."),t=a[0];if("class"===t||"attr"===t||"style"===t)return f.U=null,f.name=e,"class"===t?(f.i=2,f.K=r.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===r.localName?1:3:4,f}return"html"===n.xe?(f.i=8,f):(f.name="text"===n.xe?"textContent":n.xe,f.Te=o&&!Ee(f.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,f.name)&&(f.Ft=s.event??("select"===r.localName?"change":"input")),f)}(t,n,l,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 xt=/\{\{([\s\S]+?)\}\}/g;function St(e){let t=e.data,n=[],l=0;xt.lastIndex=0;for(let r=xt.exec(t);null!==r;r=xt.exec(t)){let i=xt.lastIndex-r[0].length;i>l&&e.before(t.slice(l,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({a:s,cr:r[1].trim()}),l=xt.lastIndex}return 0===n.length||(l<t.length&&e.before(t.slice(l)),e.remove()),n}function Tt(e,t,n,l){let r=function(e){return{xe:"textContent",Ne:["textContent"],rn:[],M:[],...V(e),b:"text"}}(t);return{...mt(),a:l,i:0,o:vt(e,r.Ze,n),N:je(r.et),K:""}}function Nt(e){let t=e.getAttribute(pt());if(null===t)return null;let n=fe(t)[0];return void 0===n||"for"!==n.b&&"if"!==n.b&&"elseif"!==n.b&&"else"!==n.b?null:n}var Ot=(e,t)=>0===e?ie.commentIfPrefix:null===t.o?ie.commentElsePrefix:ie.commentElseIfPrefix;function jt(e,t,n){let l=(t,l)=>({el:t,o:"else"===l.b?null:vt(e,l.Ze,n),N:"else"===l.b?null:je(l.et)}),r=[l(t,Nt(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=Nt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(r.push(l(e,t)),"else"===t.b))break}return r}var Ct=new WeakSet;function Mt(t,n,l,r,i,s,o,a){let u=(n,l)=>{let i=document.createComment(l);return n.replaceWith(i),r&&e.Mn?.(t,i,n),i},c=n=>{for(let f=0;f<n.length;f++){let h=n[f];if(null!==h.parentNode)if(1===h.nodeType){let n=h,a=n.localName;if(n.hasAttribute(pt()+"-ignore"))continue;if(r){if("script"===a||"style"===a||Ct.has(n))continue;if(Ct.add(n),a===ie.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?Nt(n):null;if(null!==f){if("for"===f.b){let e=vt(t,f.Ze,l),r=Wt(t,n,e,!0);i(u(n,ie.commentForPrefix),e,r)}else"if"===f.b?s(jt(t,n,l).map((e,n)=>({C:Wt(t,e.el,l,!1),o:e.o,N:e.N,S:u(e.el,Ot(n,e))}))):At(f.b);continue}let d=n.getAttribute(pt()),p=null===d?null:kt(t,d,l,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some(wt)&&!e.$o?.(n);try{r&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!r&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t.Wt&&h.data.includes("{{")&&!Ct.has(h))for(let{a:e,cr:t}of St(h))a(e,t);else if(8===h.nodeType){let e=Pt.exec(h.data),t=e&&h.parentNode.localName;if(null!==t&&"textarea"!==t&&"title"!==t){let t=document.createTextNode("");h.replaceWith(t),a(t,e[1])}}}};c(n)}var Pt=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Et=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function Wt(e,t,n,l){let r=document.importNode(Et(t),!0),i=[],s=[],o=e=>i.push(e)-1;Mt(e,[...r.childNodes],n,!1,(e,t,n)=>{s.push({...mt(),a:o(e),i:6,o:t,C:n})},e=>{let t=e.map(e=>({a:o(e.S),C:e.C,o:e.o,N:e.N}));s.push({...mt(),a:t[0].a,i:7,q:t})},(e,t)=>{let n=o(e);for(let e of t)$t(e)&&w(203,[e.name]),e.a=n;s.push(...t),e.removeAttribute(pt())},(t,l)=>{s.push(Tt(e,l,n,o(t)))}),qt(r,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let l=t;l!==e;l=l.parentNode){let e=0;for(let t=l.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(r,e)),u=1===r.childNodes.length&&8!==r.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=l?n.n+1:-1;for(let e of s){if(5===e.i&&e.nt&&!e.Te&&!It(i[e.a],r)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Rt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.q)h.add(t.a);else h.add(e.a)}let g=[...h].sort((e,t)=>e-t);return{ln:r,root:u?r.firstChild:null,Cn:a,build:g,ue:d,sr:p,Dn:u,lr:c,ko:[],Xe:f}}function It(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 Rt(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.Te&&null===e.Ft;default:return!1}}var Dt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function qt(e,t,n){for(let l=e.firstChild;null!==l;){let e=l.nextSibling;3===l.nodeType?n&&!t.has(l)&&""===l.data.trim()&&l.remove():1===l.nodeType&&qt(l,t,Dt.has(l.localName)),l=e}}var Lt=new WeakMap;function zt(e,t){let n=9===t.nodeType?t.body:t;e.root=t,Lt.set(t,e),Ft(e,[...n.childNodes]),e.ze()}function Ut(e,t,n){try{let l="template"===t.localName?Nt(t):null;null!==l&&!n&&w(204,[l.b]),Ft(e,[t])}catch(e){console.error(e)}e.ze()}function Ft(t,n){Mt(t,n,null,!0,(e,n,l)=>{new ft(t,l,nt(t,n,null,e),e).xt()},e=>{ut(t,e,null,null)},(n,l)=>{e.Mn?.(t,n,l);for(let e of l)at(t,e,n,null,null)},(n,l)=>{e.Mn?.(t,n,l),at(t,Tt(t,l,null,0),n,null,null)})}var Vt=Symbol.for("wcstack.binder"),_t=Symbol.for("wcstack.binder.pending"),Bt=Symbol.for("wcstack.binder.taken");var Ht=new Map;function Kt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=Lt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Ht.set(e,t):Ut(n,e,t?.range)}function Jt(){let e=[...Ht];Ht.clear();for(let[t,n]of e)Kt(t,n);!function(){let e=function(){let e=globalThis[Vt];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[_t];return void 0===t&&(t=[],e[_t]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),l=function(){let e=globalThis,t=e[Bt];return void 0===t&&(t=new WeakSet,e[Bt]=t),t}();for(let t of n)l.add(t),e.bind(t)}()}var Yt=class{constructor(){this.name="dirty",this.Z=(e,t)=>{if(0===e.n){let t=e.Y;return t!==c&&t!==f&&(e.Y=f,!0)}let n=null===t?null:t.bt;if(null===n)return!1;let l=n[e.F];return l!==c&&l!==f&&(n[e.F]=f,!0)}}Jo(e,t,n){null!==t.getter&&this.Z(t,n),e.$t(t,n),e.Nn(t,n,this.Z)}Ho(e,t){let n=t.l.o.Mt;if(null!==n)for(let l of n)l.n===t.l.n?e.st(l,t,this.Z):e.en(t,l,t=>e.st(l,t,this.Z))}ke(t,n,l){this.Z(n,l),e.Ee?.(t,n,l),t.$t(n,l),t.Nn(n,l,this.Z)}Uo(e,t,n){let l=0===t.n;if(!l&&null===n)return;let r=l?null:n.bt??=new Array(e.je).fill(c),i=null===r?t.Y:r[t.F];if(i!==c&&i!==f&&i!==h&&(null===r||t.F in r))return i;i=h;try{return i=e.Ko(t,null===r?null:n)}finally{null===r?t.Y=i:r[t.F]=i}}Xt(e){e.bt=null}tt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.Y===f&&(t.Y=h):e.nn(t.h[t.n],e=>{let n=e.bt;null!==n&&n[t.F]===f&&(n[t.F]=h)}))}},Gt=0,Xt=new WeakMap;function Qt(e,t=e.getRootNode()){Xt.set(t,[...Xt.get(t)??[],e].filter((e,t,n)=>e.isConnected&&n.lastIndexOf(e)===t))}function Zt(e){let t=Xt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.V||e.connectedCallbackPromise))).then(()=>{},l=>n.length?Xt.get(e)!==t?Zt(e):Promise.reject(l.errors[0]):void 0)}var en=typeof HTMLElement>"u"?class{}:HTMLElement,tn=class extends en{constructor(){super(),this.engine=null,this.jn=!1,this.Ye=!1,this.K=null,this.Ge=null,this.loaded=!1,this.un=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.cn=e,this.xo=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.an=e})}static{this.getBindingsReady=Zt}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.jn){if(null!==this.Ge)return void this.Ge.Je();Qt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!Lt.has(n)&&Lt.set(n,t),Jt(),e.element?.(t,"back"),this.No("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.jn=!0;let t=this.getRootNode(),n=e.ut?.(this,t);if(n)return this.Ge=n,!n.To&&this.parentNode instanceof ShadowRoot&&Qt(this),void(void 0===n.It?this.Ro():n.It()).then(e=>(this.loaded=!0,n.start(e,()=>this.Ao()))).then(()=>{this.an(),this.cn()},e=>this.Nt(e,n.To));this.start(t),Qt(this)}disconnectedCallback(){if(null!==this.Ge)return void this.Ge.Ln();let t=this.engine;if(null===t)return;let n=t.root;Lt.get(n)===t&&Lt.delete(n),Qt(this,n),this.No("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.Ye&&w(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.K=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&w(15),"readonly"===e&&n.Le++;try{t(n.proxy)}finally{"readonly"===e&&n.Le--}}async createStateAsync(e,t){let n=this.engine;null===n&&w(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let l=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&w(8),l(...e)):l},set(){w(8)}}))}async Ro(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${$(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||w(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let l=this.querySelector('script[type="module"]');return null!==l?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let l="function"==typeof URL.createObjectURL,r=l?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Gt}`);try{return(await(import(r))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?$(42):$(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),l&&URL.revokeObjectURL(r)}}(l):null!==this.K?Promise.resolve(this.K):new Promise(e=>{this.un=e})}async start(t){try{let n=t.host;(this.hasAttribute("mount")||this.hasAttribute("bind-component")||n?.hasAttribute("data-wc-definition"))&&a("scopes","<wcs-state>");let l=await this.Ro(),r=o(l);if(r&&await r,this.getRootNode()!==t)return this.K=l,this.jn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=Lt.get(t)?.element;i?.isConnected&&(i.V||i.Ge)&&w(47);let s=new re(l,new Yt);s.element=this,this.engine=s,e.element?.(s,"mounting"),zt(s,t),Jt(),s.xn(),this.Ao(),await s.$e("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.cn()}catch(e){this.Ye=!this.V,this.Nt(e)}}Ao(){this.V=!0,this.an()}Nt(e,t){this.ze(this.V?50:49,e),this.an(),t?this.cn():this.xo(e)}ze(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);console.error(`[@wcstack/state] ${$(e,[this.localName,...n])}`,t)}No(e,t,n){(async()=>this.engine.$e(e))().then(n,e=>this.ze(t,e))}},nn=[];function ln(){return(nn=nn.filter(e=>e.deref())).map(e=>e.deref())}function rn(t,n){t&&function(e){let t=ie,n=ie.tagNames,l=Object.entries(e).filter(([,e])=>void 0!==e),r=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of l){let l=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof l||Array.isArray(n)!==Array.isArray(l))&&w(44,["bootstrapState",e])}for(let[e,t]of r)(!Object.hasOwn(n,e)||"string"!=typeof t)&&w(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of l)"tagNames"!==e&&(t[e]=n);for(let[e,t]of r)n[e]=t}(t),function(t=customElements){(function(){let e=globalThis;void 0===e[Vt]&&(e[Vt]={protocol:"wcs-binder",version:1,bind:Kt})})(),ln().includes(t)||nn.push(new WeakRef(t));let n=ie.tagNames.state;void 0===t.get(n)&&t.define(n,class extends tn{}),e.Po?.(t)}(n)}var sn,on=e=>Zt(e),an=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},un="en";function cn(){if(ie.locale!==sn){sn=ie.locale;try{un=Intl.getCanonicalLocales(sn)[0]}catch{console.warn(`[@wcstack/state] ${$(48,[sn])}`),un="en"}}return un}var fn=["full","long","medium","short"];function hn(e,t){let[n,l]=e??[];return void 0===l&&void 0!==n&&fn.includes(n)&&([n,l]=[void 0,n]),void 0!==l&&!fn.includes(l)&&function(e,t){w(52,[e,t])}(t,l),[n,l]}var{eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,falsy:$n,truthy:wn,boolean:An}=Te,kn={toFixed:{factory:e=>{let t=Ae(e?.[0]??"0","toFixed");return e=>("number"!=typeof e&&ve("toFixed",e),e.toFixed(t))},arity:[0,1]},locale:{factory:e=>{let t=e?.[0];return e=>("number"!=typeof e&&ve("locale",e),e.toLocaleString(t??cn()))},arity:[0,1]},upper:{factory:an(()=>e=>String(e).toUpperCase()),arity:[0,0]},lower:{factory:an(()=>e=>String(e).toLowerCase()),arity:[0,0]},capitalize:{factory:an(()=>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:an(()=>e=>String(e).trim()),arity:[0,0]},slice:{factory:an(e=>{let t=[ke(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(Ae(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:an(e=>{let t=ke(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:an(e=>{let t=ke(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:an(e=>{let t=ke(e,0,"repeat");return e=>String(e).repeat(t)}),arity:[1,1]},reverse:{factory:an(()=>e=>String(e).split("").reverse().join("")),arity:[0,0]},truncate:{factory:an(e=>{let t=ke(e,0,"truncate"),n=e?.[1]??"…";return e=>{let l=String(e);return l.length<=t?l:l.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||w(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","round"));return e=>("number"!=typeof e&&ve("round",e),Math.round(e*t)/t)},arity:[0,1]},floor:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","floor"));return e=>("number"!=typeof e&&ve("floor",e),Math.floor(e*t)/t)},arity:[0,1]},ceil:{factory:e=>{let t=Math.pow(10,Ae(e?.[0]??"0","ceil"));return e=>("number"!=typeof e&&ve("ceil",e),Math.ceil(e*t)/t)},arity:[0,1]},percent:{factory:e=>{let t=Ae(e?.[0]??"0","percent");return e=>("number"!=typeof e&&ve("percent",e),`${(100*e).toFixed(t)}%`)},arity:[0,1]},unit:{factory:an(e=>{let t=e?.[0]??ye("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:e=>{let[t,n]=hn(e,"date"),l=n&&{dateStyle:n};return e=>(e instanceof Date||$e("date",e),e.toLocaleDateString(t??cn(),l))},arity:[0,2]},time:{factory:e=>{let[t,n]=hn(e,"time"),l=n&&{timeStyle:n};return e=>(e instanceof Date||$e("time",e),e.toLocaleTimeString(t??cn(),l))},arity:[0,2]},datetime:{factory:e=>{let[t,n]=hn(e,"datetime"),l=n&&{dateStyle:n,timeStyle:n};return e=>(e instanceof Date||$e("datetime",e),e.toLocaleString(t??cn(),l))},arity:[0,2]},ymd:{factory:e=>{let t=e?.[0]??"-";return e=>{e instanceof Date||$e("ymd",e);let n=e.getFullYear().toString(),l=(e.getMonth()+1).toString().padStart(2,"0"),r=e.getDate().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},hms:{factory:e=>{let t=e?.[0]??":";return e=>{e instanceof Date||$e("hms",e);let n=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),r=e.getSeconds().toString().padStart(2,"0");return`${n}${t}${l}${t}${r}`}},arity:[0,1]},eq:dn,ne:pn,not:mn,lt:gn,le:yn,gt:bn,ge:vn,add:Se("add",(e,t)=>e+t),sub:Se("sub",(e,t)=>e-t),mul:Se("mul",(e,t)=>e*t),div:Se("div",(e,t)=>e/t),mod:Se("mod",(e,t)=>e%t),abs:{factory:()=>e=>("number"!=typeof e&&ve("abs",e),Math.abs(e)),arity:[0,0]},clamp:{factory:e=>{let t=ke(e,0,"clamp"),n=ke(e,1,"clamp");return e=>("number"!=typeof e&&ve("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:$n,truthy:wn,defaults:{factory:(e,t)=>{let n=xe(e?.[0]??ye("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=xe(e?.[0]??ye("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:An,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]??ye("currency"),n=e?.[1],l={style:"currency",currency:t};try{new Intl.NumberFormat("en",l);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){w(53,[e])}(t)}return e=>("number"!=typeof e&&ve("currency",e),e.toLocaleString(n??cn(),l))},arity:[1,2]}},xn=Object.fromEntries(Object.entries(kn).filter(([e])=>!(e in Te))),Sn=!1,Tn={name:"formats",install:function(){Sn||(Sn=!0,me(kn))}};function Nn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let l=new Array(t.length+1),r=new Array(t.length+1);for(let e=0;e<=t.length;e++)l[e]=e;for(let n=1;n<=e.length;n++){r[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;r[i]=Math.min(l[i]+1,r[i-1]+1,l[i-1]+s)}for(let e=0;e<=t.length;e++)l[e]=r[e]}return l[t.length]}function On(e,t){if(0===e.length)return"";let n=e.toLowerCase(),l=null,r=3;for(let e of t){let t=Nn(n,e.toLowerCase(),2);t<r&&(l=e,r=t)}return null!==l?` Did you mean "${l}"?`:""}var jn=" Validate statically: npx @wcstack/lint <file>.",Cn=["","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"],Mn=e=>{let t=Cn[e/100|0];return t?`[wcs/${t}] `:""},Pn=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],En=e=>null==e?String(e):e instanceof Date?"a Date":Array.isArray(e)?"an array":"string"==typeof e?`a string (${JSON.stringify(e.length>32?e.slice(0,32)+"…":e)})`:"object"==typeof e?"an object":`a ${typeof e} (${String(e)})`,Wn=["","","class.","attr.","style."],In=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Rn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Dn={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,l)=>`binding "${n?(Wn[l]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Rn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Rn}`,17:e=>`a subscriber of token "${e}" threw.`,18:e=>`${e} must be an array of strings.`,19:e=>`${e} entries must be non-empty strings.`,20:(e,t,n)=>`${e} entry "${t}" conflicts with the reserved namespace name "${n}".`,21:(e,t)=>`${e} entry "${t}" is duplicated.`,22:()=>"$on must be an object of handlers.",23:e=>`$on entry "${e}" is not declared in $eventTokens.`,24:e=>`$on entry "${e}" must be a function.`,25:e=>`view-transition naming-limit (${e}) reached.`,26:e=>`filter ${e} requires at least one option`,27:e=>`filter ${e} requires a number as option`,28:(e,t)=>`filter ${e} requires a number value, not ${En(t)}${"string"==typeof t?` — put |number before |${e}, or convert it where it is read`:""}`,29:(e,t)=>`filter ${e} requires a date value (a Date), not ${En(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}`,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&&Pn.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)=>`${In(e,t)} failed to initialize.`,50:(e,...t)=>`${In(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${In(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,l)=>`${e}("${t}") takes ${n} index(es), got ${l}.`,902:(e,t,n,l)=>`${e}("${t}") takes at most ${n} index(es), got ${l}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function qn(e,t){let n=Dn[e];return void 0===n?`${Mn(e)}#${e} ${t.join(" ")}`:Mn(e)+n(...t)}var Ln=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),zn=[[/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.']],Un={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Fn(e,t,n){let l=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(Un,e)?Un[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?On(t,n):"");for(let[t,n]of zn){let r=t.exec(e);null!==r&&(l+=n.replace(/\$(\d)/g,(e,t)=>r[Number(t)]))}let r=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==r&&(l+=` — write "${r[1]}#${r[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?l+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':he.some(ge)||(l+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&Ln.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(l+=jn),l}var Vn=new WeakMap,_n=new WeakMap,Bn=new WeakSet,Hn=new WeakSet;function Kn(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 Jn(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 Yn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let l=t=>null===t?null:function(e,t){let n=t.t.split("."),l=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return l<0||n.indexOf("*",l)>=0||void 0!==Kn(e.target,t.t)?.get?t:e.O.wt(m(t.t).o)}(e,t);return n.some(e=>null!=l(e)?.getter)?null:Gn(e,n,0,e.target,l)}function Gn(e,t,n,l,r){for(;n<t.length;n++){let i=t[n];if(null===l||"object"!=typeof l)return null;if("*"===i.s){if(!Array.isArray(l)||0===l.length)return null;let i=null;for(let s of l){let l=Gn(e,t,n+1,s,r);if(null===l)return null;if(null===i)i=l;else if(l.seg===i.seg)for(let e of l.names)i.names.includes(e)||i.names.push(e)}return i}if(Array.isArray(l)&&/^\d+$/.test(i.s)){if(Number(i.s)>=l.length)return null;l=l[Number(i.s)];continue}let s=Kn(l,i.s);if(void 0===s&&null===i.c&&e.tt.has(i.s))return null;if(void 0===s){let s=Jn(l),o=r(i.c);for(let t of e.O.all())t.c===o&&null!==t.getter&&s.push(t.s);return{seg:i.s,names:s,r:t.slice(0,n).some(e=>"*"===e.s)}}if(void 0!==s.get||void 0!==s.set)return null;l=s.value}return null}function Xn(t){Bn.has(t)||(Bn.add(t),setTimeout(()=>function(t){Bn.delete(t);let n=Vn.get(t);if(void 0===n)return;let l=_n.get(t);void 0===l&&_n.set(t,l=new Set);let r=new Map(n),i=new Map;for(let e of t.O.all()){let t=null===e.c||l.has(e)||n.has(e)?void 0:e.L.find(e=>!e.hn);void 0!==t&&(i.set(e,t),r.set(e,3))}for(let[n,s]of r){if(l.has(n))continue;l.add(n);let r=Yn(t,n);if(null===r)continue;let o=[...t.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].find(e=>!Hn.has(e)&&(n.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==o){l.delete(n),o.initializePromise.then(()=>{Hn.add(o),Xn(t)});continue}let a=t.O.wt(m(n.t).o),u="";if(void 0!==a&&a!==n&&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 c=On(r.seg,r.names);if((r.r||3===s)&&""===c&&""===u)continue;let[f,h,d]=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"];e.at?.(t,{type:"state:path-unresolved",source:d,path:n.t,missingSegment:r.seg}),console.warn(`[@wcstack/state] [wcs/${f}] ${h} "${n.t}"${3===s?` read by the getter "${i.get(n).t}"`:""} does not resolve on the state tree: "${r.seg}" is not declared.${c}${u} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${jn}`)}}(t),0))}function Qn(e,t,n=!1){Zn(e,t,n?1:0)}function Zn(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let l=Vn.get(e);void 0===l&&Vn.set(e,l=new Map),l.has(t)||l.set(t,n),Xn(e)}var el=new WeakSet,tl=!1,nl=new WeakMap;function ll(e,t){let n=nl.get(e),l=t.s;if(null!==t.c||tl||void 0===n||n.has(l)||"$"===l[0]||e.tt.has(l))return;let r=On(l,[...n]);n.add(l),""!==r&&![...e.root?.querySelectorAll(`${ie.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${l}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${l}" is not declared: writing it creates a new key.${r}${jn}`)}var rl=new WeakSet;function il(e){if(rl.has(e))return;rl.add(e);let t=e.emit,n=!1;e.emit=(...l)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${jn}`)),t.apply(e,l))}var sl=new WeakMap;function ol(e,t,n){let l=e.target;for(let e of t.split("."))l=null==l?void 0:Kn(l,e)?.value;if("function"!=typeof l||!String(l).includes("currentTarget"))return;let r=sl.get(e);void 0===r&&sl.set(e,r=new Set),!r.has(t)&&(r.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(…).${jn}`))}function al(e){Vn.has(e)&&e.He.length>0&&Xn(e)}var ul=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),cl=!1;function fl(e,t,n){let l="html"===n.name?"innerHTML":n.name;if(cl||!(t instanceof TypeError)||!Ee(l)||!("trustedTypes"in globalThis))return;cl=!0;let r="function"==typeof Me()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${l}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${r}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:n.a,property:l})}var hl=new WeakMap;function dl(e,t,n){let l=e[t],r=void 0===n?void 0===l?null:`the event carried no detail (undefined) while element.${t} is ${typeof l}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==l&&"object"==typeof l?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof l}`;if(null===r)return;let i=hl.get(e);void 0===i&&hl.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${r}. 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 pl=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],ml={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},gl={name:"diagnostics",install(){e.Lo=Fn,e.Bo=qn,e.Eo=Qn,e.detail=dl,e.Ye=t(e.Ye,fl);let l=e.pe;e.pe=(e,t)=>{(function(e){void 0!==e.$scan&&w(1);for(let[t,n]of pl)void 0!==e[t]&&w(1601,[t,n])})(t),l?.(e,t),function(e){let t=e.$recursion;if(null===t||"object"!=typeof t)return;let n=Object.entries(t);if(1!==n.length||"string"!=typeof n[0][1])return;let[l,r]=n[0];if(!l.endsWith(".*")||!r.endsWith(".*"))return;let i=l.slice(0,-2),s=r.slice(0,-2),o=`.${r}`,a=`${i}.**`,u=Jn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>v(`[wcs/recursion-declaration-invalid] ${e}`);for(let e of c){(e===`.${s}`||e.startsWith(`.${s}.`))&&f(`"${a}${e}" names the recursion structure itself (the "${s}" lists): recursive getters compute values over the nodes.`);for(let t of c)t.length>e.length&&t.endsWith(e)&&new RegExp(`^(?:${ul(o)})+$`).test(t.slice(0,t.length-e.length))&&f(`"${a}${e}" and "${a}${t}" expand to the same concrete path at different depths (they differ by whole repetitions of "${r}"). Rename one of them.`);let t=new RegExp(`^${ul(l)}(?:${ul(o)})*${ul(e)}$`);for(let n of u)!n.includes("**")&&t.test(n)&&f(`"${n}" is already defined on the state, so the recursive getter "${a}${e}" cannot expand to it.`)}}(t),function(e){_n.delete(e),Vn.has(e)&&Xn(e)}(e),function(e){if(el.has(e))return;el.add(e);let t=e.Xn,n=t.$postUpdate;t.$postUpdate=t=>{tl=!0;try{n(t)}finally{tl=!1}let l=e.O.wt(m(t).o);void 0!==l&&Zn(e,l,2)}}(e),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))il(t)}})}(e),nl.set(e,new Set(Jn(t)))},e.handlerThrew=ol,e.re=t(e.re,ll),e.he=t(e.he,al),e.rt=n(r,e.rt,(e,t)=>Object.hasOwn(ml,t)?w(1701,[t,ml[t]]):void 0)}},yl={},bl=/\.\d/,vl=new Set(Object.getOwnPropertyNames(Object.prototype)),$l=0,wl=!1,Al=null,kl=()=>{wl=!1,$l++};function xl(){if(null===Al)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=kl,e.port1.unref?.(),Al=()=>e.port2.postMessage(0)}else Al=()=>setTimeout(kl,0);return wl||(wl=!0,Al()),$l}function Sl(e,t){let n=new Set,l=[e];for(;l.length>0;){let e=l.pop();if(!n.has(e)){n.add(e);for(let n of e.Q){for(let l of t)if(n.ee(l)&&(n.n===l.n||!(l.n<e.n&&e.h[l.n+1].ee(l))))return!0;null!==n.getter&&l.push(n)}}}return!1}var Tl=class{constructor(e,t){this.active=!1,this.Oe=new Map,this.early=[],this.n=0,this.Fo=-1,this.Bn=new Set,this.Ke=null,this.engine=e,this.De=t}ur(){let e=this.engine;this.Oe.clear();let t=this.early;this.early=[];for(let t of this.De)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(yl,e.v(t.p,null)):this.Wn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[l,r,i,s]of t)if((null===r||r.w)&&Object.is(e.v(l,r),s)){n.add(l);for(let e of this.De)e.p===l&&this.dt(e,r,i,!0)}for(let e of this.De)e.getter&&0===e.p.n&&!this.Oe.has(e)&&Sl(Nl(e.p),n)&&this.dt(e,null,void 0,!0);this.Oe.size>0&&e.Se()}prime(t,n){try{n()}catch(n){console.error(`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`,n),e.at?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}Oo(){this.active=!1,this.Oe.clear(),this.early=[]}Wn(e,t,n,l){let r=this.engine.Ue(n,e.h[t]);for(let n of r.f)t===e.n?l(n):this.Wn(e,t+1,n,l)}dt(e,t,n,l){let r=this.Oe.get(e);void 0===r&&this.Oe.set(e,r=new Map);let i=r.get(t);void 0===i?r.set(t,[n,this.n,l]):(i[1]<this.n&&(i[1]=this.n),i[2]||=l)}re(e,t,n,l,r,i){if(this.active){(this.Ke??=new Set).add(e);for(let i of this.De){let s=i.p;s.n!==e.n||!s.ee(e)||this.dt(i,t,i.getter?i.s.get(t??yl):s===e&&r&&this.engine._t&&(null===l||"object"!=typeof l&&"function"!=typeof l)?n:void 0,!0)}}else i&&this.early.push([e,t,n,l])}Ee(e,t){if(this.active)for(let n of this.De)(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??yl),!1)}Qt(e,t){if(!this.active)return;let n=null;for(let l of this.De){let r=l.p;if(!(r.n<e.n||r.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.f)n.has(t)||(r.n===e.n?this.dt(l,t,void 0,!0):this.Wn(r,e.n+1,t,e=>this.dt(l,e,void 0,!0)))}}}he(){let t=this.Ke;if(this.Ke=null,!this.active||0===this.Oe.size)return;let n=this.Oe;this.Oe=new Map;let l=this.engine,r=[];for(let i of this.De){let s=n.get(i);if(void 0===s)continue;let o,a=[...s].filter(([e])=>null===e||e.w);a.length>1&&a.sort((e,t)=>Ol(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=l.d;this.n=u+1,l.Ce++;try{if(a=l.v(i.p,n),i.getter&&(i.s.set(n??yl,a),Object.is(a,s)&&(bl.test(i.t)||null!==n&&!c&&!(o??=null!==t&&Sl(Nl(i.p),t)))))continue;if(u>32){r.includes(i.t)||r.push(i.t);continue}l.d=n,e.at?.(l,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(l.proxy,a,s,...l.H(n))}catch(t){console.error(`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`,t),e.at?.(l,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{l.d=h,this.n=0,l.Ce--}}}r.length>0&&this.Co(r)}Co(t){let n=xl();n!==this.Fo&&(this.Fo=n,this.Bn.clear());let l=t.filter(e=>!this.Bn.has(e));if(0!==l.length){for(let e of l)this.Bn.add(e);console.error("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.at?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:l})}}};function Nl(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function Ol(e,t){let n=[],l=[];for(let t=e;null!==t;t=t.l.ce)n.unshift(t.y);for(let e=t;null!==e;e=e.l.ce)l.unshift(e.y);for(let e=0;e<n.length&&e<l.length;e++)if(n[e]!==l[e])return n[e]-l[e];return n.length-l.length}var jl="$streamStatus",Cl="$streamError",Ml=new Set(Object.getOwnPropertyNames(Object.prototype)),Pl=!1;function El(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 Wl=class{constructor(e,t,n){this.engine=e,this.entries=t,this.W=n}set(e,t,n){Pl=!0;try{this.engine.P(this.engine.o(`${e}.${t}`),null,n)}finally{Pl=!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(jl,e.name,"idle")}Ee(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)}he(){let e=this.engine,t=this.W,n=[];for(let l of this.entries){if(!l.ft)continue;let r=l.n;if(l.ft=!1,r>32)n.push(l.name),l.g.Y=h;else{t.n=r+1,e.Ce++;try{this.start(l,!1)}finally{e.Ce--,t.n=0}}}n.length>0&&t.Co(n)}start(e,t){let n,l=this.engine;if(null!==e.J&&e.J.abort(),e.J=null,null!==e.g){let r=e.g;r.getter=e.args;let i=r.Q.slice();Il(r);try{n=l.read(r,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&v(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Q)n.n>0&&v(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${jl}.${e}`||n.t===`${Cl}.${e}`)&&v(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,r,n)}catch(n){Il(r);for(let e of i)e._n(r);if(r.Y=h,t)throw n;return this.set(Cl,e.name,n),void this.set(jl,e.name,"error")}}let r=new AbortController;e.J=r,l.P(l.o(e.name),null,e.K),this.set(Cl,e.name,null),this.set(jl,e.name,"active"),this.mr(e,r,n)}async mr(e,t,n){let l=this.engine,r=t.signal,i=()=>!r.aborted&&e.J===t,s=l.o(e.name),o=this.W.n,a=xl(),u=e=>{xl()===a&&(this.W.n=o);try{e()}finally{this.W.n=0}},c=e.K;try{let t=await e.source(n,r);if(!i())return;let o=t=>{c=void 0!==e.Io?e.Io(c,t):t,u(()=>l.P(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(r.addEventListener("abort",()=>{e.cancel().catch(()=>{})});;){let t=await e.read();if(!i())return;if(t.done)break;o(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(r.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.J=null,u(()=>this.set(jl,e.name,"done"))}catch(n){if(!i())return;e.J=null,t.abort(),u(()=>{this.set(Cl,e.name,n),this.set(jl,e.name,"error")})}}};function Il(e){for(let t of e.Q){let n=t.L.indexOf(e);n>=0&&t.L.splice(n,1),t.ht.delete(e)}e.Q.length=0,e.Y=c}var Rl=new WeakMap;function Dl(e){let t=Rl.get(e);return t?.target===e.target?t:void 0}function ql(t,n){let l=new Tl(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$watch must be an object mapping paths to handler functions.");let l=[];for(let r of Object.keys(n)){let i=n[r];(""===r||"$"===r[0]||r.includes("@")||vl.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=t.o(r);e.Eo?.(t,s,!0),l.push({t:r,p:s,handler:i,getter:!1,s:new WeakMap})}return l}(t,n.$watch)),r=new Wl(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&v("$stream must be an object mapping stream names to definitions.");let l=[],r={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||Ml.has(s))&&v(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&v(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&v(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&v(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&v(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&v(`$stream entry "${s}": args must be a function.`),El(t,s)&&v(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),r[s]="idle",i[s]=null,l.push({name:s,source:a,Io:u,K:f,J:null,ft:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[jl]=r,t[Cl]=i,l}(t,n),l),i=Rl.get(t);void 0!==i&&(i.W.Oo(),i.Ct.fr()),Rl.set(t,{W:l,Ct:r,Je:i?.Je??!1,target:n})}function Ll(e,t){let n=Rl.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 zl=["$streamStatus","$streamError"],Ul={name:"temporal",install(){e.pe=t(e.pe,ql),e.element=t(e.element,Ll),e.re=t(e.re,(e,t,n,l,r,i,s)=>Dl(e)?.W.re(t,n,l,r,i,s)),e.Ee=t(e.Ee,(e,t,n)=>{let l=Dl(e);void 0!==l&&(l.W.Ee(t,n),l.Ct.Ee(t))}),e.Qt=t(e.Qt,(e,t,n)=>Dl(e)?.W.Qt(t,n)),e.he=t(e.he,e=>{let t=Dl(e);void 0!==t&&(t.W.he(),t.Ct.he())}),e.rt=n(r,e.rt,(e,t)=>{let n=t.split(".",1)[0];if(zl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Ie=n(l,e.Ie,(e,t)=>(!Pl&&36===t.t.charCodeAt(0)&&zl.includes(t.t.split(".",1)[0])&&v(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},Fl=new WeakMap,Vl=!1,_l=/^(?!prototype$)[^\d.*$][^.*]*$/;function Bl(e,t){let n=t.$listKeys,l=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&v("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let r=n[t];"string"==typeof r?l.set(e.o(t),e=>e[r]):"function"==typeof r?l.set(e.o(t),r):v(`$listKeys "${t}" must be a field name or a function.`)}}Fl.set(t,l)}function Hl(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Kl(e,t,n){let l=new Map;for(let r of t){Hl(r)||v(`$listKeys "${e}": rows must be plain objects.`);let t=n(r);null==t&&v(`$listKeys "${e}": a row has no key.`),l.has(t)&&v(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),l.set(t,r)}return l}function Jl(e,t,n,l){if(Vl||!Array.isArray(l))return!1;let r=Fl.get(e.target)?.get(t);if(void 0===r)return!1;let i=e.it(t,n);if(!Array.isArray(i)||i===l)return!1;let s=Kl(t.t,i,r);Kl(t.t,l,r);let o=[],a=[],u=i.length===l.length;for(let e=0;e<l.length;e++){let t=l[e],n=s.get(r(t));o.push(n??t),void 0!==n&&a.push([e,n,t]),o[e]!==i[e]&&(u=!1)}let c=[];for(let[e,t,n]of a){for(let l of Object.keys(n))Object.is(t[l],n[l])||c.push([e,l,n[l]]);for(let l of Object.keys(t))!(l in n)&&null!==t[l]&&c.push([e,l,null])}if(u&&0===c.length)return!0;if(!u){Vl=!0;try{e.P(t,n,o)}finally{Vl=!1}}if(c.length>0){let l=e.Ue(0===t.n?null:n,t);for(let[n,r,i]of c){if("__proto__"===r)continue;let s=l.f[n],o=_l.test(r)?e.o(`${t.t}.*.${r}`):null;null===o?.getter?e.P(o,s,i):(s.$[r]=i,e.P(e.o(`${t.t}.*`),s,s.$,!0))}}return!0}var Yl={name:"list-keys",install(){e.pe=t(e.pe,Bl),e.Ie=n(l,e.Ie,Jl)}},Gl=new WeakMap,Xl=new WeakMap,Ql="will not graft: the root state failed to initialize.",Zl=new WeakSet,er=new WeakMap,tr=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],nr=["$commandTokens","$eventTokens","$on","$errorCallback"],lr=e=>`[@wcstack/state] <${ie.tagNames.state} mount="${e}">`,rr=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),ir=e=>e?.element?.isConnected?e:void 0;function sr(e){let t=Xl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function or(e,t){let n=Xl.get(t);if(Xl.delete(t),Array.isArray(n))for(let t of n)fr(t,e)}function ar(e){let t=Gl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function ur(e,t){console.error(`${lr(e.t)} ${t}`),ar(e),e.Qe?.(),e.Qe=null}function cr(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 fr(e,t){if(Zl.has(t))return ur(e,"will not graft: its component is wired to its host.");let n=e.state,l=t.target,r=e.t.split("."),i=l;for(let e of r)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return ur(e,`will not graft: the root state already has "${e.t}".`);let s=function(e,t){let n=e=>`${t}.${e}`;return new Proxy({},{get(t,l){if("symbol"==typeof l)return;if(36!==l.charCodeAt(0))return e.proxy[n(l)];let r=e.proxy[l];return"$eqPath"===l?(e,t)=>r(n(e),n(t)):rr.has(l)&&"function"==typeof r?(e,...t)=>r(n(e),...t):r},set:(t,l,r)=>"symbol"!=typeof l&&(e.proxy[n(l)]=r,!0)})}(t,e.t);e.chroot=s;let o={},a={},u=new Set;for(let t=n;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let n of Object.getOwnPropertyNames(t)){if(u.has(n)||"constructor"===n)continue;u.add(n);let{get:l,set:r,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==l||void 0!==r)a[`${e.t}.${n}`]={get:l&&function(){return l.call(s)},set:r&&function(e){r.call(s,e)}};else{if("$"===n[0])continue;if("function"==typeof i){let t=i.bind(s);a[`${e.t}.${n}`]={get:()=>t}}else o[n]=i}}if(void 0===i){for(let e=1;e<r.length;e++){let n=t.o(r.slice(0,e).join("."));null==t.it(n,null)&&t.P(n,null,{})}t.P(t.o(e.t),null,o)}t.no(Object.defineProperties({},a));for(let e in a)t.Ke(t.o(e),null);e.engine=t;let c=er.get(t);void 0===c&&er.set(t,c=[]),c.push(e),e.el.isConnected&&cr(e,"$connectedCallback"),e.Qe?.(),e.Qe=null}function hr(e,t){let n=Xl.get(e);if(Array.isArray(n))for(let e of n)ur(e,Ql);Xl.set(e,t)}var dr=new WeakMap;function pr(e,t){let n=e.getAttribute("mount");if(null===n)return null;let l={el:e,root:t,t:n,state:null,engine:null,chroot:null,Qe:null},r=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(ie.bindAttributeName))r='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=Gl.get(t);void 0===e&&Gl.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==l&&(null===i.engine?i.el.isConnected:ir(i.engine)))r=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=Xl.get(t);Array.isArray(e)&&Xl.set(t,e.filter(e=>e!==i)),i.Qe?.(),i.Qe=null}e.set(n,l)}}else r='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{To:!0,start(e){if(null!==r)return ur(l,r);if(Gl.get(t).get(n)===l){for(let t of tr)if(void 0!==e[t])return ur(l,`${t} is not run in a volume — declare it on the root state.`);for(let t of nr)void 0!==e[t]&&console.warn(`${lr(n)} ${t} is not run in a volume (it belongs to the root).`);return l.state=e,new Promise(e=>{l.Qe=e;let n=ir(Lt.get(t)),r=Xl.get(t);void 0!==n?fr(l,n):sr(t)?ur(l,Ql):Xl.set(t,[...Array.isArray(r)?r:[],l])})}},Je(){null!==l.engine&&cr(l,"$connectedCallback")},Ln(){null!==l.engine&&cr(l,"$disconnectedCallback")},reset(){v(`re-setting a volume is not supported: its data was copied into the root tree at "${n}" — write the paths under it on the root instead.`)}}}var mr=new WeakMap,gr=new WeakMap;function yr(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||v(`${t} must be an array of state member names.`);let l=new Set;for(let e of n)("string"!=typeof e||""===e)&&v(`${t} entries must be non-empty strings.`),"$"===e[0]&&v(`${t} entry "${e}": internal ($) members are never exposed.`),l.has(e)&&v(`${t} entry "${e}" is duplicated.`),l.add(e);return n}function br(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let l=document.createDocumentFragment();for(let e of[...t.childNodes])l.appendChild(e.cloneNode(!0));let r=t.mode;return{start(t){e.hasAttribute("bind-component")&&v("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,l){e.includes("-")||v(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&v(`DCC: <${e}> is already defined.`);let r=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(l),i=yr(l,"$bindables"),s=yr(l,"$commands");for(let e of i){let t=r.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 s){let t=r.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 o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=l=>{if(a.has(l))return a.get(l);if(l.hasAttribute("data-wc-definition"))return null;let r=l.attachShadow({mode:n});r.appendChild(t.cloneNode(!0));let s=r.querySelector(ie.tagNames.state);return a.set(l,s),mr.set(l,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${ie.tagNames.state}>: no change events.`),s},f=e=>c(e)?.engine??null,h=e=>Promise.resolve(c(e)?.initializePromise).then(()=>{let t=u.get(e);u.delete(e);let n=f(e);if(void 0!==t&&null!==n)for(let[e,l]of t)n.proxy[e]=l});class d extends HTMLElement{static{this.wcBindable=0===i.length&&0===s.length?null:{protocol:"wc-bindable",version:1,properties:i.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:i.map(e=>({name:e})),...0===s.length?{}:{commands:s.map(e=>({name:e,async:!0}))}}}connectedCallback(){null!==c(this)&&h(this)}get stateElement(){return c(this)}}for(let[e,t]of r)"function"==typeof t.value?Object.defineProperty(d.prototype,e,{configurable:!0,value(...t){return h(this).then(()=>{let n=f(this);return null===n?void 0:n.proxy[e].apply(n.proxy,t)})}}):Object.defineProperty(d.prototype,e,{configurable:!0,get(){return f(this)?.proxy[e]},set(t){let n=f(this);if(null!==n)n.proxy[e]=t;else{let n=u.get(this);void 0===n&&u.set(this,n=[]),n.push([e,t])}}});customElements.define(e,d)}(n.localName,l,r,t)},Je(){},Ln(){},reset(){v("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var vr=new WeakMap,$r=new WeakSet,wr=new WeakMap,Ar=new WeakMap,kr="data-wcs-wired",xr=new WeakMap,Sr=new WeakMap,Tr=new WeakMap,Nr=0,Or=new Set,jr={},Cr=["$watch","$stream","$renderedCallback"],Mr=e=>e.split(".",1)[0];function Pr(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Er(e,t){let n=e.a,l=Mr(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(kr);else if(!Ir(n,l)){let e=n.getAttribute(kr)?.split(" ")??[];e.includes(l)||n.setAttribute(kr,[...e,l].join(" "))}xr.get(n)?.ye===l&&v(`<${n.localName}>.${l} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let r=vr.get(n);void 0===r&&vr.set(n,r=[]),r.push(e),t&&$r.add(e);let i=wr.get(n);return void 0===i&&wr.set(n,i=new Map),i.has(l)||i.set(l,n[l]),Ar.get(n)?.(),!1}function Wr(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`)}function Ir(e,t){let n=e.getAttribute(ie.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Rr(e){let t=e.parentElement;for(;null!==t&&!Wr(t);)t=t.parentElement;let n=Lt.get(t??e.getRootNode()),l=n?.element;(l?.isConnected?l.V:null===t)&&(null===t?Kt(e):Ut(n,e))}var Dr=new Set;function qr(e,t){Dr.has(e)||(Dr.add(e),console.warn(`[@wcstack/state] ${t}`))}var Lr=(e,t)=>t in e.state;function zr(e,t){let n=Ur(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function Ur(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 Fr(e,t,n){if(null!==n.getter)return;let l,r=e.host,i=r.engine,s=Mr(n.t),o=r.entries.find(e=>e.E===n.t);if(void 0===o&&null!==n.c)return function(e,t){let n,l=t.c;for(;null!==l&&void 0===(n=e.pt.get(l));)l=l.c;if(null===l||void 0===n)return;let r=e.T,i=e.host.engine,s=i.o(n.p.t+t.t.slice(l.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=Vr(e,o.r);return 0===t.n?n:(i.resolve(Pr(s.t,[...i.H(n),...r.H(ne(r.d,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.se&&(t.se=n=>{let l=a();_r(e,o.e,()=>i.P(s,l,n)),e.dn=t}),t.n>0&&(t.F=r.je++),e.pt.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.E!==s?Lr(r,s):zr(r,s))return;l=o.we}else{if(null===t||null!==n.c||"$"===s[0]||Lr(r,s))return;o=t,l=i.o(`${t.we.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(l,Vr(e,a)),n.se=t=>{_r(e,u,()=>i.P(l,a,t)),e.dn=n},e.pt.set(n,{e:o,p:l,r:a})}function Vr(e,t){return null!==t&&!t.w&&v(`The host row of <${e.host.el.localName}> was removed.`),t}function _r(e,t,n){let l=Or.has(e.T);Or.add(e.T),e.from=t;try{n()}finally{l||Or.delete(e.T),e.from=null}}var Br=(e,t)=>t||!Or.has(e.m.T)||null!==e.m.from&&e.m.from!==e.e;function Hr(e,t){if(e.fn===t||null===e.host.engine)return;e.fn=t,Nr+=t?1:-1;let n=e.host.engine,l=Tr.get(n);void 0===l&&Tr.set(n,l=new Map);for(let n of e.me){let e=l.get(n.e.we);void 0===e&&l.set(n.e.we,e=new Map);let r=e.get(n.e.r);void 0===r&&e.set(n.e.r,r=new Set),t?r.add(n):(r.delete(n),0===r.size&&e.delete(n.e.r))}let r=e.host.entries.find(e=>""===e.E);if(void 0!==r){null===e.ie&&function(e,t){let n=e.host,l=n.engine;e.ie=new Map;let r=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(r.has(s))continue;r.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=Mr(s);if(s!==a&&!Lr(n,a))continue;let u=l.o(`${t.we.t}.${s}`);if(null===u.getter)Yr(l,u,t.we);else if(!Kr.has(u.getter))continue;e.ie.set(u,e.T.o(s))}}(e,r);for(let l of e.ie.keys())t&&null===l.getter&&Yr(n,l,r.we),n.A.ke(n,l,r.r);e.ie.size>0&&n.Se(),t&&function(e,t){let n=e.host.engine;for(let[l,r]of e.ie){let i=n.v(l.c,t.r);if(null===i||"object"!=typeof i||!(l.s in i))continue;let s=e.host.el.localName;qr(`${s}|${l.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.ye}.${r.t} is exported at "${l.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,r)}}var Kr=new WeakSet;function Jr(e,t,n,l){let r=Tr.get(e)?.get(t)?.get(n);if(void 0===r)return null;let i=null;for(let e of r)""!==e.e.E||!0!==e.m.ie?.has(l)||e.m===i||(null!==i&&v(`[wcs/mount-export-ambiguous] "${l.t}" is exported by two mounted components on the same instance: <${i.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.`),i=e.m);return i}function Yr(e,t,n){let l=t.c,r=t.s,i=()=>{let t=e.read(l,e.d);return null!==t&&"object"==typeof t&&r in t?t:null};t.getter=()=>{let l=i();if(null!==l)return l[r];let s=Jr(e,n,e.d,t);return null===s?void 0:s.T.read(s.ie.get(t),null)},Kr.add(t.getter),t.se=s=>{let o=null===i()?Jr(e,n,e.d,t):null;if(null===o){let t=e.read(l,e.d);return void(null!==t&&"object"==typeof t&&(t[r]=s))}let a=o.ie.get(t);void 0===Ur(o.host.state,a.t)?.set&&v(`Cannot write to "${a.t}" on mounted <${o.host.el.localName}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),o.T.P(a,null,s)},t.n>0&&(t.F=e.je++)}function Gr(t,n,l,r,i,s){if(null!==n.getter)return t.A.ke(t,n,l),void t.Se();if("*"===n.s){if(null===l)return;if(l.$=l.l.R[l.y],t.A.Xt(l),null!==l.u)for(let e of l.u.values())t.G(e)}else t.$n(n,l);e.re?.(t,n,l,r,i,s),t.Ke(n,l)}function Xr(e){let t=e.m.T;for(let[n,l]of e.m.pt)l.e===e.e&&(0===n.n?t.A.ke(t,n,null):t.nn(n.h[n.n],e=>t.A.ke(t,n,e)));t.Se()}function Qr(e,t,n,l,r,i,s){let o=n.t.slice(t.t.length);if(""===o)return Xr(e);let a,u=e.m,c=u.T;if(""===e.e.E){a=o.slice(1);let e=Mr(a);if("$"===e[0]||Lr(u.host,e)||u.host.entries.some(e=>""!==e.E&&(a===e.E||a.startsWith(`${e.E}.`))))return}else a=e.e.E+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(ne(l,e).y);c.resolve(Pr(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||Gr(c,h,d,r,i,s)}function Zr(e,t,n,l,r,i,s){if(0===Nr)return;let o=Or.has(e);Or.add(e);try{let o=Sr.get(e);!s&&void 0!==o&&o.fn&&!Or.has(o.host.engine)&&function(e,t,n,l,r,i){let s,o=t;for(;null!==o&&void 0===(s=e.pt.get(o));)o=o.c;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.dn===t)return void(e.dn=null);if(null!==s.r&&!s.r.w)return;let u=[...a.H(s.r),...e.T.H(n)];a.resolve(Pr(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||_r(e,s.e,()=>Gr(a,c,f,l,r,i))}(o,t,n,l,r,i),s&&void 0!==o&&o.fn&&null!==o.ie&&function(e,t){let n=e.host.entries.find(e=>""===e.E),l=e.host.engine;for(let[r,i]of e.ie)i===t&&(l.A.ke(l,r,n.r),l.Se())}(o,t);let a=Tr.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.ee(e)){let a=o.get(0===e.n?null:ne(n,e.n));if(void 0!==a)for(let o of[...a])Br(o,s)&&Qr(o,e,t,n,l,r,i)}else if(e.ee(t))for(let[e,l]of[...o])if(0===t.n||ne(e,t.n)===n)for(let e of[...l])Br(e,s)&&Xr(e)}finally{o||Or.delete(e)}}async function ei(t,n,l,r,i){if(r===jr)return;let s=o(r);s&&await s;let a=xr.get(n);a.engine&&r.$recursion&&v(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.I;if(null!==u&&u.el!==t&&u.el.isConnected&&v(`<${n.localName}> already has a connected <${ie.tagNames.state} bind-component="${a.ye}">.`),null!==u&&Hr(u,!1),null!==u&&function(e,t,n){let l=e.T,r=`[${ie.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(r)||null!==e.querySelector(r)),s=new Set,o=e=>{for(;null!==e&&e.parentNode!==n;)e=e.parentNode;null!==e&&s.add(e)},a=(e,t)=>{for(let n=e.In(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of l.de.values())for(let t of e)if(null===t.D)o(t.a);else for(let e of t.D.q)a(t.D,e.S);for(let e of l.oe.values())for(let t of[e.x,...e.B??[]])null!==t&&a(t,t.S);for(let t of e.j)t.parentNode===n&&i(t)&&s.add(t);if(0===s.size)return!1;let u=[...n.childNodes].filter(n=>n!==t&&!s.has(n)&&!e.j.includes(n)&&(i(n)||l.Wt&&n.textContent.includes("{{")));return u.length>0&&console.warn(`[@wcstack/state] <${e.host.el.localName}>: ${u.length} node(s) added beside the content taken over are not bound.`),!0}(u,t,l))return async function(e,t,n,l){e.el.engine=null,e.el=t,e.T.element=t,t.engine=e.T,e.j=e.j.filter(e=>e.parentNode===n),t.isConnected?await ti(e,l):l()}(u,t,l,i);let c=new re(r,new Yt);c.element=t,t.engine=c,function(e,t){let n=new Map;for(let e=t;null!==e&&e!==Object.prototype;e=Object.getPrototypeOf(e))for(let t of Object.getOwnPropertyNames(e)){let l=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof l&&"constructor"!==t&&n.set(l,null)}let l=(t,n,l)=>Reflect.apply(t,e.proxy,l);e.V=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:l})),t}}(c,r);let f={el:t,j:[],T:c,host:a,me:[],pt:new Map,fn:!1,dn:null,from:null,ie:null};for(let e of a.entries)f.me.push({m:f,e});a.I=f,Sr.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.T,n=e.host,l=n.engine,r=n.el.localName,i=n.entries.find(e=>""===e.E)??null;for(let e of n.entries){if(""===e.E)continue;let t=Mr(e.E);Lr(n,t)&&(e.E!==t||zr(n,t))&&qr(`${r}.${e.E}`,`[wcs/mount-own-key-shadow] <${r}>: "${n.ye}.${e.E}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=l.v(i.we,i.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)&&qr(`${r}.${t}`,`[wcs/mount-own-key-shadow] <${r}>: its own "${t}" hides "${i.we.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=Cr.filter(e=>void 0!==n.state[e]);s.length>0&&qr(`${r}.${n.ye}$`,`[wcs/mount-dollar-declaration] <${r}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.ot;t.ot=n=>{Fr(e,i,n),o.call(t,n)};let a=[...t.O.all()];for(let t of a)Fr(e,i,t);for(let e of a)o.call(t,e);let u=t.Yt;t.Yt=()=>{(function(e){for(;void 0!==e;e=Sr.get(e.host.engine))if(e.host.entries.some(e=>null!==e.r&&!e.r.w))return!1;return!0})(e)&&u.call(t)}}(f),Hr(f,!0),Zl.add(c),or(c,l));let d=e.hr?.(l,c);zt(c,l),d?.(),f.j=[...l.childNodes],Jt(),h&&c.xn(),Object.defineProperty(n,a.ye,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.ye);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,e=>console.error(e))}catch(e){console.error(e)}i(),t.isConnected?(await c.$e("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):Hr(f,!1)}async function ti(t,n){Hr(t,!0);for(let e of t.me)Xr(e);n?.(),!t.broken&&(await t.T.$e("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.T,"connected"))}function ni(t,n){let l=t.getAttribute("bind-component");if(null===l)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=Lt.get(t)?.element;if(!(e.V||void 0!==n&&n!==e&&n.isConnected)){hr(t,e);for(let e of dr.get(t)??[])e()}}),null}(t,n);let r=t.parentNode,i=r instanceof ShadowRoot,s=i?r.host:r instanceof Element?r:null,o=()=>{let e=null===s?void 0:xr.get(s)?.I;return e?.el===t?e:null},a=e=>{throw i&&hr(r,t),e},u=!1;return{It:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,l){let r=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&v(`<${ie.tagNames.state} bind-component> takes its state from <${r}>.${t}: it cannot also load one (state / src / json / an inline script).`),await Le(n).whenDefined(r);let i=xr.get(n);if(void 0!==i)return i.ye!==t&&v(`<${r}> already has a <${ie.tagNames.state} bind-component="${i.ye}">.`),i.state;let s=()=>(vr.get(n)??[]).filter(e=>Mr(e.name)===t),o=Ir(n,t);if(o&&0===s().length&&Rr(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(kr)?.split(" ").includes(t))(n,t))){let e;await new Promise((l,i)=>{Ar.set(n,l),e=function(e,t){sr(e)&&t();let n=dr.get(e)??new Set;return dr.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${r}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Ar.delete(n);let a=s(),u=wr.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&v(`"bind-component": <${r}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&l){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${r}>, or mount it from the host (${ie.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),jr}let f=[];for(let e of a){let l=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.E===l)&&v(`<${r}> maps "${e.name}" twice.`);let i=l.split(".").indexOf("*");if(i>=0){let n=l.split(".").slice(0,i).join(".");v(`<${r}> maps "${e.name}": the component-side path of a mount cannot contain "*"${""===n?"":` — map the list itself ("${t}.${n}: <the host's list>")`}.`)}f.push({E:l,we:e.o,r:e.r,ro:$r.has(e)}),e.engine.Tn(e),""!==l&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return xr.set(n,i={el:n,ye:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,I:null}),h}(t,l,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${ie.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await ei(t,s,i?r:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Je(){let e=o();null!==e?ti(e).catch(e=>console.error(e)):u?Promise.resolve().then(()=>{if(t.parentNode===r)return ei(t,s,i?r:s,xr.get(s).state,()=>{})}).catch(e=>console.error(e)):Ar.has(s)&&Rr(s)},Ln(){let t=o();null!==t&&(Hr(t,!1),!t.broken&&(t.T.$e("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.T,"disconnected")))},reset(){v(`re-setting a component's state is not supported: write <${s?.localName}>.${l} instead.`)}}}var li={name:"scopes",install(){e.ut=n(i,e.ut,pr),e.ut=n(i,e.ut,br),e.ut=n(i,e.ut,ni),e.ar=Er,e.$o=Wr,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=er.get(e)??[];if("disconnected"===t)for(let e of n)ar(e);else if("reset"!==t&&ir(Lt.get(e.root))===e){or(e,e.root);for(let e of n)Gl.get(e.root).has(e.t)||Gl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();or(e,n),function(e,t){let n=t.host,l=void 0===n?void 0:mr.get(n);void 0!==l&&gr.set(e,{host:n,def:l})}(e,n)}),e.re=t(e.re,(e,t,n,l,r,i)=>{(function(e,t,n,l){let r=gr.get(e);if(void 0===r)return;let i=t.t.split(".",1)[0];if(!r.def.bindables.includes(i))return;let s=l&&t.t===i;r.host.dispatchEvent(new CustomEvent(`${r.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,r,i),Zr(e,t,n,l,r,i,!1)}),e.Ee=t(e.Ee,(e,t,n)=>Zr(e,t,n,void 0,void 0,!1,!0)),e.Ie=n(l,e.Ie,(e,t,n,l,r)=>(function(e,t){let n=er.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&v(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let l,r=Sr.get(e);if(void 0===r)return!1;for(let e=t;null!==e&&void 0===l;e=e.c)l=r.pt.get(e);if(void 0===l)return!1;let i=l.e;return!((null===i.r||i.r.w)&&!i.ro)&&(!!n||(Vr(r,i.r),void v(`[wcs/mount-readonly] <${r.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${r.host.ye}${""===i.E?"":`.${i.E}`}#ro: ${i.we.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,r)));let r=e.pe;e.pe=(e,t)=>{let n=er.get(e);void 0!==n&&n.length>0&&v(`re-setting a root state with grafted volumes (${n.map(e=>e.t).join(", ")}) is not supported: their data is part of the tree.`),function(e){let t=Tr.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&v("re-setting a root state with mounted components is not supported: they read its data."),r?.(e,t)}}},ri="$recursion",ii=new WeakMap,si=new WeakSet,oi=new WeakSet,ai=0,ui=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ci=e=>`[wcs/recursion-${e}]`;function fi(e,t){let n=n=>v(`${ci("declaration-invalid")} ${ri} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&v(`${ci("declaration-invalid")} ${ri} ${e} must be a non-empty string.`);let l=t.split(".");(l.length<2||"*"!==l[l.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<l.length-1;e++){let t=l[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var hi=(e,t)=>`${e.l}.*${e.step.repeat(t)}`;function di(e,t){let n=`${e.l}.**`,l=t.slice(n.length);return(!t.startsWith(n)||""!==l&&"."!==l[0]||l.includes("**"))&&v(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.l}.*".`),l}function pi(e,t,n){let l=di(e,t),r=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===r&&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.`),hi(e,r.k)+l}function mi(e,t,n){let l=new Set,r=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(l.has(e)&&v(`${ci("cycle")} "${n}" is reachable from itself: the data under "${t.l}" must be a tree.`),r.has(e)&&v(`${ci("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.l}" must be a tree.`),i+1>128&&v(`${ci("depth-exceeded")} Recursion on "${t.l}.*" reached depth ${i+1} (the limit is 128).`),r.add(e),0)),s=(r,o)=>{for(let a of r){n(o,a);let r=e.o(`${hi(t,o)}.${t.key}`),u=e.read(r,a);i(u,r.t,o+1)&&(l.add(u),s(e.Ue(a,r).f,o+1),l.delete(u))}},o=e.o(t.l),a=e.read(o,null);i(a,t.l,0)&&(l.add(a),s(e.Ue(null,o).f,0))}function gi(e,t){let n=function(e){let t=e[ri],n=[],l=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!l.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),l.add(e);if(void 0===t)return n.length>0&&F(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&v(`${ci("declaration-invalid")} ${ri} must be an object mapping one anchor path to its repeating sub-path.`);let r=Object.entries(t);1!==r.length&&v(`${ci("declaration-invalid")} ${ri} must declare exactly one anchor (it declares ${r.length}).`);let i=fi("anchor",r[0][0]),s=fi("repeat",r[0][1]),o=i.slice(0,-2),a=s.slice(0,-2),u=`.${s}`,c=new Map,f=[],h=`${o}.**`;for(let[e,t]of n){let n=e.slice(h.length);(!e.startsWith(h)||""!==n&&"."!==n[0]||n.includes("**"))&&v(`[wcs/recursion-anchor] "${e}": a recursive key is "${h}" followed by a path (the anchor is "${i}").`),(""===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(`${ci("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${ui(i)}((?:${ui(u)})*)${ui(n)}$`),n])}return{l:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${ui(o)}((?:${ui(`.*.${a}`)})*)$`)}}(t),l=ii.has(e);null!==n?(l||ai++,ii.set(e,n),oi.add(e),si.has(e)||function(e){si.add(e);let t=e,n=t.ot;t.ot=l=>{let r=ii.get(e);if(l.t.includes("**")){let t=e.O.wt(l.t)===l;return void(oi.has(e)||void 0===r&&t?l.getter=()=>F(l.t):t||n.call(e,l))}if(void 0!==r&&null===l.getter)for(let[e,n]of r.matchers)if(e.test(l.t)){l.getter=r.families.get(n),l.n>0&&(l.F=t.je++),r.owners.set(l,r.l+".**"+n);break}n.call(e,l)};let l=t.resolve;t.resolve=(t,n)=>{let r=ii.get(e);return l.call(e,void 0!==r&&t.includes("**")?pi(r,t,n):t,n)};let r=t.getAll;t.getAll=(n,l)=>{let i=ii.get(e);if(void 0===i||!n.includes("**"))return r.call(e,n,l);if(void 0===l)return r.call(e,pi(i,n,t.d));(!Array.isArray(l)||l.length>0)&&v(`${ci("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=di(i,n),o=[];return mi(e,i,(t,n)=>{for(let l of r.call(e,hi(i,t)+s,e.H(n)))o.push(l)}),o};let i=t.wn;t.wn=(n,l,r,s)=>{let o=ii.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,l,r,s);Array.isArray(l)||w(9,[n]),l.length>0&&v(`${ci("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof r||!0===s?.spread)&&v(`${ci("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Le>0&&w(8);let a=di(o,n),u=a.replace(/\.\d+(?=\.|$)/g,".*");for(;u.startsWith(o.step);)u=u.slice(o.step.length);let c=o.key.split(".");(""===u||u===`.${o.key}.length`||c.some((e,t)=>u===`.${c.slice(0,t+1).join(".")}`))&&v(`${ci("structural-write")} "${n}" writes the recursion structure itself (a node, its "${o.key}" list or that list's length, or an object on the way to it).`);for(let e of o.families.keys()){let t=e;for(;t.startsWith(o.step);)t=t.slice(o.step.length);(u===t||u.startsWith(`${t}.`))&&v(`${ci("readonly")} "${n}" writes into the recursive getter "${o.l}.**${e}".`)}let f=[];mi(e,o,(e,t)=>f.push([e,t]));let h=0;for(let[t,n]of f)h+=i.call(e,hi(o,t)+a,e.H(n),r);return h}}(e)):l&&(ii.delete(e),ai--)}function yi(e,t){if(0===ai)return!1;let n=ii.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let l=n.owners.get(e);void 0!==l&&v(`${ci("readonly")} "${t.t}" writes into the recursive getter "${l}".`)}return!1}var bi={name:"recursion",install(){e.pe=t(e.pe,gi),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){oi.delete(e)}(e)}),e.Ie=n(l,e.Ie,yi)}},vi="4.5.0",$i=e=>e.split(".").slice(0,2).join("."),wi=class extends en{static find(e){return e.querySelector?.(ie.tagNames.ssr)??null}get version(){return this.getAttribute("version")??""}get stateData(){let e=this.querySelector('script[type="application/json"]');return null===e?{}:JSON.parse(e.textContent||"{}")}get templates(){let e=new Map;for(let t of Array.from(this.children))"template"===t.localName&&e.set(t.id,t);return e}get hydrateProps(){return{}}getTemplate(e){return this.templates.get(e)??null}verifyVersion(){return $i(this.version)===$i(vi)}};function Ai(e){let t=ie.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends wi{})}var ki=()=>ie.tagNames.ssr,xi=Symbol.for("wcstack.ssr.snapshotBuilder"),Si=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Ti=e=>document.createComment(e),Ni=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,Oi=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),ji=new WeakMap,Ci=new WeakMap,Mi=new WeakMap,Pi=new WeakSet,Ei=new WeakMap;function Wi(e,t){let n=[];for(let l=e;null!==l&&(n.push(l),l!==t);l=l.nextSibling);return n}function Ii(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 Ri=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Di(e,t,n,l){let r=Ti(null===l?"wcs-[":`wcs-[:${l}`),i=Ti("wcs-]");n.length>0&&n[0].Re().before(...Wi(e,t)),t.after(r);for(let e of n)null===l&&e.Re().before(Ti("wcs-|"));let s=n.length>0?(e=>null===e.j?e.ct:e.j[e.j.length-1])(n[n.length-1]):r;(Ri(s)??s).after(i);for(let e of Wi(r,i))Pi.add(e)}function qi(e){if(e instanceof ft){Di(e.S,e.S,e.Fe,null);for(let t of e.Fe)Li(t);return}let t=e.I;null!==t&&(Di(e.q[e.y].S,e.q[e.q.length-1].S,[t],e.y),Li(t))}function Li(e){if(null!==e.u)for(let t of e.u)qi(t)}var zi=new Set(["script","style","template","textarea","title"]),Ui="data-wcs-raw",Fi=e=>zi.has(e.localName)||e.localName===ki();function Vi(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Ti("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Ti("wcs-s")):1===t.nodeType&&!Fi(t)&&Vi(t)}var _i=0;function Bi(e,t){let n=e.getRootNode(),l=[t];for(let e of Ci.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&l.push(e);let r=new Map;for(let e of l){let t=ji.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.oe.values())if(null!==t.x&&n.set(t.x.S,t.x),null!==t.B)for(let e of t.B)n.set(e.S,e);for(let t of e.de.values())for(let e of t)if(null!==e.D)for(let t of e.D.q)n.set(t.S,e.D);let l=new Set;for(let[e,i]of t){r.set(e,i);let t=n.get(e);void 0!==t&&!l.has(t)&&e.isConnected&&(l.add(t),qi(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Mi.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Pi.has(e)||1===e.nodeType&&t.has(e)&&Gi(e)?2:1}),l=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(Fi(e.parentNode)?Ei.has(e):t.has(n)&&Oi(n,"wcs-t:"))&&(Ei.has(e)||t.get(e)!==e.data):!t.has(e))&&l.push(e)}for(let e of l)e.remove()}let n=Array.from(e.childNodes);Fi(e)&&n.some(e=>Ei.has(e))&&e.setAttribute(Ui,n.map(e=>Ei.has(e)?`{{ ${Ei.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}Vi(9===n.nodeType?n.body:n);let i=document.createElement(ki());i.setAttribute("version",vi);let s=document.createElement("script");s.type="application/json",s.textContent=function(e){return JSON.stringify(e).replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`)}(function(e){let t={};for(let n of Object.keys(e)){if("$"===n[0])continue;let l=Object.getOwnPropertyDescriptor(e,n);void 0!==l.get||void 0!==l.set||"function"==typeof l.value||(t[n]=l.value)}return t}(t.target)),i.append(s);for(let[e,t]of r){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let l="svg"===n?.localName,r=`wcs-${l?"s":"t"}${_i++}`;e.replaceWith(Ti(`wcs-p:${r}`));let s=document.importNode(Et(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Ii(e,document.createElement("template"),...e.childNodes));if(l){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=r,i.append(Ii(t,o,s))}e.before(i)}function Hi(e){!function(e){if(null!==e.querySelector(ie.tagNames.state))for(let t of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===t.localName){let e=Array.from(t.options);if(t.multiple||e.some(e=>e.hasAttribute("selected"))||e[t.selectedIndex]!==e.find(e=>!e.disabled))for(let t of e)t.toggleAttribute("selected",t.selected)}else"textarea"===t.localName?t.value!==t.defaultValue&&!t.value.includes("{{")&&!Array.from(t.childNodes).some(e=>Ei.has(e))&&(t.textContent=t.value):"checkbox"===t.type||"radio"===t.type?t.toggleAttribute("checked",t.checked):"password"!==t.type&&t.value!==t.defaultValue&&t.setAttribute("value",t.value)}(e);for(let t of Array.from(e.querySelectorAll(`${ie.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===ki())continue;let e=t.engine;null!=e&&Bi(t,e)}}var Ki=Symbol.for("wcstack.state.ssr.impl"),Ji=new Map,Yi=new WeakMap,Gi=t=>!0===e.$o?.(t),Xi=e=>1===e.nodeType&&!Fi(e)&&!Gi(e),Qi=e=>e.f.flat().concat(e.z??[]),Zi=e=>{for(let t of Qi(e))t.remove()};function es(e,t,n){let l=/^wcs-\[(?::(\d+))?/.exec(e.data),r=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!Ni(o,"wcs-]");){let e=o.nextSibling;if(Ni(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];Oi(o,"wcs-[")?e=es(o,t,n):(n.push(o),Xi(o)&&ts(o,t))}o=e}let a={branch:void 0===l[1]?null:Number(l[1]),f:s,z:o??i.appendChild(Ti("wcs-]"))},u=Qi(a);o=a.z.nextSibling;for(let e of u)n?.push(e),t&&Ct.add(e);return t&&null!==r?Ji.set(r,a):Zi(a),o}function ts(e,t){for(let n=e.firstChild;null!==n;)Oi(n,"wcs-[")?n=es(n,t):(Xi(n)&&ts(n,t),n=n.nextSibling)}function ns(e,t,n){let l=e=>{for(let r of Array.from(e.childNodes))if(r.parentNode===e)if(8===r.nodeType){let e=r.data;try{if("wcs-s"===e)r.remove();else if("wcs-e"===e)r.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Ti(`@@:${decodeURIComponent(e.slice(6))}`),n=r.nextSibling;for(;null!==n&&!Ni(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),r.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=r.parentNode,l="s"===e[10]?Ii(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);l.removeAttribute("id"),t.replaceChild(l,r)}}}catch{}}else 1===r.nodeType&&!Fi(r)&&(Gi(r)?Yi.set(r,{ssr:t,Pe:n}):l(r))};l(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||cs(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,l=0;if(e.forEach((e,t)=>{Oi(e,"wcs-[")?l++:Ni(e,"wcs-]")&&--l<0&&(l=0,n=t+1)}),0===l)continue;let r=0;for(let l=t.firstChild;null!==l;l=l.nextSibling)if(Oi(l,"wcs-["))r++;else if(Ni(l,"wcs-]")&&0===r--){t.prepend(...e.slice(n));break}}}(e),ts(e,n)}function ls(t,n){let l=Yi.get(t);if(void 0===l)return null;Yi.delete(t);let r=e=>ns(e,l.ssr,l.Pe);if(l.Pe||os(n,t,t,r),r(t),!l.Pe)return null;let i=e.Pe;return e.Pe=ds,()=>{e.Pe=i,rs()}}function rs(){for(let e of Ji.values())Zi(e);Ji.clear()}function is(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function ss(e,t,n,l){let r=null;for(let l of e){let e=l[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===r||e.length>r[n].length)&&(r=l)}let i=r?.[l];if(null==i)return null;let s=r[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function os(e,t,n,l){let r=document.createElement("template").content;for(let e of n.childNodes)r.appendChild(r.ownerDocument.importNode(e,!0));l(r),e.root=t;let i=()=>{};Mt(e,[...r.childNodes],null,!0,i,i,i,(t,n)=>Tt(e,n,null,0))}function as(e,t,n){if(Si()){if(n instanceof Array){for(let e=n.length;e-- >0;)$t(n[e])&&n.splice(e,1);let e=t;if(n.some(wt))Pi.add(e);else if(e.localName.includes("-")&&!Gi(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Mi.set(e,t)}return}if("string"==typeof n){if(Ei.set(t,n),Fi(t.parentNode))return;let e=Ti(`wcs-t:${encodeURIComponent(n)}`),l=Ti("wcs-/t");return t.before(e),void t.after(l)}let l=ji.get(e);void 0===l&&ji.set(e,l=new Map),l.set(t,n);let r=t.getRootNode(),i=Ci.get(r);return void 0===i&&Ci.set(r,i=new Set),void i.add(e)}if("string"!=typeof n&&Ji.size>0){let e=Ji.get(n);void 0!==e&&(Ji.delete(n),Ji.set(t,e))}}var us=e=>null!==e&&8===e.nodeType&&[ie.commentIfPrefix,ie.commentElseIfPrefix,ie.commentElsePrefix].includes(e.data),cs=e=>3===e.nodeType&&""===e.data.trim(),fs=e=>{let t=Ji.get(e)?.z??e;return(Ri(t)??t).nextSibling};function hs(e,t){if(t.length!==e.ln.childNodes.length)return!1;let n=e.Cn;for(let l=0;l<n.length;l++){let r=n[l],i=e.ln,s=t[r[0]];for(let e=0;;){if(i=i.childNodes[r[e]],s?.nodeName!==i.nodeName)return!1;if(++e===r.length)break;s=(Ri(s)??s).firstChild;for(let t=r[e];t>0&&null!==s;t--)s=fs(s)}e.ko[l]=s}return!0}function ds(e,t,n){if(0===Ji.size)return null;let l=t,r=0;if(!n){let e=ie.commentIfPrefix;if(!Ni(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(us(n)&&r++,!Ni(n,e));n=n.previousSibling);for(let n=t.nextSibling;!Ji.has(l)&&null!==n&&!Ni(n,e)&&1!==n.nodeType;n=n.nextSibling)us(n)&&(l=n)}let i=Ji.get(l);if(void 0===i)return null;if(!n&&i.branch!==r)return Ji.delete(l),Zi(i),null;let s=i.f.shift();if(0===i.f.length&&Ji.delete(l),i.z?.replaceWith(...Wi(t,l)),i.z=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=Ji.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.z;)e++;else Ri(s[e])===s[e+1]&&e++}if(!hs(e,o)){let n=(e.Dn?e.root:e.ln).cloneNode(!0);o=e.Dn?[n]:[...n.childNodes],hs(e,o),(s[0]??i.f.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var ps={name:"ssr",install(){e.Mn=as,e.hr=ls;let n=e.element;e.element=(t,l)=>{"mounting"===l&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||Si())return;let l=n.previousElementSibling,r=l?.localName===ki(),i=r?l.getAttribute("version"):null,s=null===i||$i(i)===$i(vi);if(s){let e=t,n=e.$e;e.$e=(e,l)=>"$connectedCallback"===e?void 0:n.call(t,e,l)}if(!r)return;let o=!s&&parseInt(i)<4,a=/^3\.(\d+)\.(\d+)$/.exec(i),u=null!==a&&(+a[1]-5||+a[2]-3)>=0;s||console.warn(`[@wcstack/state] <${ki()} version="${i}"> does not match ${vi}: its snapshot is discarded, and the page renders on the client from its own state.${o&&!u?" 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 c=s?l.querySelector('script[type="application/json"]'):null;if(null!==c){let e=JSON.parse(c.textContent||"{}"),n=t.target;for(let t of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(n,t);void 0!==l&&(void 0!==l.get||void 0!==l.set||"function"==typeof l.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${Ui}]`)))e.textContent=e.getAttribute(Ui),e.removeAttribute(Ui);let h=9===f.nodeType?f.body:f;l.remove();let d=e=>o?function(e,t,n){let l=new Map,r=e=>{let t=e.parentElement;for(;null!==t&&!Gi(t);)t=t.parentElement;if(null===t)return null;let n=l.get(t);if(void 0===n){let e=r(t),i=t.querySelector(`:scope > ${ie.tagNames.state}[bind-component]`).getAttribute("bind-component");l.set(t,n=[]);for(let l of fe(t.getAttribute(ie.bindAttributeName)??"")){let t=l.Ze;l.Ne[0]===i&&n.push([e?ss(e,t,1,0):t,l.Ne.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let l=r(e);if(null===l)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:ss(l,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return l.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:ss(l,i[2],2,1)??i[2]};for(let t of is(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let l=t.nextSibling;for(;null!==l&&!Ni(l,`@@wcs-${e[1]}-end:${e[2]}`);)l=l.nextSibling;if(null!==l){for(;t.nextSibling!==l;)t.nextSibling.remove();l.remove(),t.replaceWith(..."text"===e[1]?[Ti(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let l of is(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(l.data)?.[1],r=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===r)continue;let o=document.importNode(r,!0),a=ie.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,r)=>t+i(n??l,r))),s(o.content,n??l);let u=o.content.firstChild;l.replaceWith(.../^\s*elseif\s*:/.test(u?.getAttribute?.(a)??"")?o.content.childNodes:[o])}};s(e);for(let t of Array.from(e.querySelectorAll("[data-wcs-ssr-id]")))t.removeAttribute("data-wcs-ssr-id")}(e,l,u):ns(e,l,s);s||os(t,f,h,d),queueMicrotask(function(e){let t=[];for(let n of Array.from(e.querySelectorAll("input,textarea,select")))if("select"===n.localName){let e=Array.from(n.options),l=e.map(e=>e.selected),r=e.map(e=>e.hasAttribute("selected")),i=r.lastIndexOf(!0);i<0&&(i=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>l[t]!==r[t]):n.selectedIndex!==i)&&t.push([n,()=>e.forEach((e,t)=>e.selected=l[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),s&&(e.Pe=ds,queueMicrotask(()=>{rs(),e.Pe=null}))}(t),n?.(t,l)},function(){let e=globalThis;e[Ki]={build:Hi,reset(){_i=0}},void 0===e[xi]&&(e[xi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[Ki].build(t),reset:()=>e[Ki].reset()})}(),e.Po=t(e.Po,Ai);for(let e of ln())Ai(e)}},ms="__WCSTACK_DEVTOOLS_HOOK__",gs=null,ys=new Set,bs=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.H(n)}}),vs=new WeakMap,$s=0;var ws=new WeakMap;function As(e){if(null===gs)return;let t=ws.get(e),n=ys.has(e)?function(e,t){let n=new Map,l=new Set,r=(l,r,i,s,o,a)=>{if(5===l)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(l,r),c=0===s.n?null:o,f=`${(e=>{let t=vs.get(e);return void 0===t&&vs.set(e,t=++$s),t})(i)}|${u}|${s.t}|${null===c?"":e.H(c).join(",")}`;if(n.has(f))return;let h=t?.get(f);n.set(f,h??{binding:{propName:u,statePathName:s.t,bindingType:a,node:i,replaceNode:i},absoluteAddress:bs(e,s,c)})},i=e=>r(e.i,e.name,e.a,e.o,e.r,e.on()),s=e=>{if(!l.has(e)){if(l.add(e),null!==e.be)for(let t of e.be)i(t);if(e instanceof tt&&null!==e.me){let t=e.C.Xe;for(let n=0;n<t.length;n++){let l=e.V?.[n];void 0!==l?i(l):r(t[n].i,t[n].name,e.me[2*n],t[n].o,e.r,0===t[n].i?"text":"prop")}}if(null!==e.u)for(let t of e.u)o(t)}},o=e=>{if(!l.has(e))if(l.add(e),e instanceof ft){r(-1,"for",e.S,e.l.o,e.l.ce,"for");for(let t of e.Fe)s(t)}else null!==e.I&&s(e.I)};for(let t of e.de.values())for(let e of t)i(e),null!==e.D&&o(e.D);for(let t of e.oe.values())if(null!==t.x&&o(t.x),null!==t.B)for(let e of t.B)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,l]of t)n.has(e)||gs({type:"state:binding-removed",...l});for(let[e,l]of n)(void 0===t||!t.has(e))&&gs({type:"state:binding-added",...l});ws.set(e,n)}function ks(e){let t=Lt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function xs(e){let t=new Set,n=new Set,l=new Set,r=new Set;for(let i of e.O.all()){for(let e=1;e<=i.n;e++)t.add(i.h[e].t);"*"===i.s&&n.add(i.t),null!==i.getter&&l.add(i.t),null!==i.se&&r.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:l,setter:r},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.ue.keys()),staticDependency:new Map,dynamicDependency:new Map,watchPaths:null!==i.$watch&&"object"==typeof i.$watch?new Set(Object.keys(i.$watch)):null,keyedListPaths:null!==i.$listKeys&&"object"==typeof i.$listKeys?new Set(Object.keys(i.$listKeys)):null}}var Ss=new WeakSet,Ts=new WeakMap;function Ns(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Ss.has(t))return;Ss.add(t);let l=t.emit;t.emit=(...r)=>(null!==gs&&gs({type:"state:token-emit",kind:n,tokenName:t.name,args:r,subscriberCount:t.size,stateElement:e.element}),l.apply(t,r))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.ue.values())t(n,"event")}(e),"connected"===t){if(ys.has(e))return;ys.add(e),gs?.({type:"state:element-registered",rootNode:e.root,element:e.element}),As(e)}else"disconnected"===t&&(ys.delete(e),As(e),gs?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function Os(e,t,n,l,r,i){if(null===gs)return;let s=bs(e,t,0===t.n?null:n),o=Ts.get(e);void 0===o&&Ts.set(e,o=new Set),o.add(s),i&&gs({type:"state:write",absoluteAddress:s,value:r,oldValue:l,hasOldValue:!0})}function js(e){if(null===gs)return;let t=Ts.get(e);Ts.delete(e),void 0!==t&&gs({type:"state:update-batch",addresses:t}),As(e)}function Cs(e,t,n){gs?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.on(),error:t})}var Ms={"*":["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 Ps(e,t){let n=e.localName;if(n.includes("-"))return null;let l=(e=>[...Ms["*"],...Object.hasOwn(Ms,e)?Ms[e]:[]])(n);return l.includes(t)||w(1205,[n,t,l.join(", ")],t,l),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var Es=[Tn,gl,Ul,Yl,li,bi,ps,{name:"devtools",install(){e.element=t(e.element,Ns),e.re=t(e.re,Os),e.he=t(e.he,js),e.Ye=t(e.Ye,Cs),function(){if(typeof document>"u"||document.documentElement?.hasAttribute("data-wcs-server"))return;let t=globalThis,n=t[ms]??(t[ms]=function(){let e=new Map,t=new Set,n=e=>{0===t.size?e._setSink(null):e._setSink(n=>{for(let l of t)l.onEvent?.(e.id,n)})};return{version:2,sources:e,register(l){if(!e.has(l.id)){e.set(l.id,l),n(l);for(let e of t)e.onSourceRegistered?.(l)}},unregister(n){let l=e.get(n);if(void 0!==l){l._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(l){t.add(l);for(let t of e.values())n(t),l.onSourceRegistered?.(t);return()=>{if(t.delete(l))for(let t of e.values())n(t)}}}}());2!==n.version&&console.warn(`[@wcstack/state] devtools hook registry version ${n.version}, expected 2: keeping the existing one.`),n.register({id:`state:${Math.random().toString(36).slice(2,10)}`,kind:"state",packageVersion:vi,getStateElements:()=>[...ys].map(xs),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let l=n._,r=n.Me?.length??0;if((null===l||0===l.size)&&0===r)continue;let i,s=0;if(null!==l)for(let e of l.values())s+=e.size;try{i=0===n.n?e.v(n,null):void 0}catch{i=void 0}t.push({path:n.t,tracked:!1,rows:s,keys:null===l?0:l.size,lists:r,lastValue:i})}return t}(ks(e)),keys(e){let t=ks(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let l;return ks(e).element.createState("readonly",e=>{l=e.$resolve(t,n??[])}),l},write(e,t,n,l){ks(e).element.createState("writable",e=>{e.$resolve(t,l??[],n)})},_setSink(t){let n=null===gs&&null!==t;gs=t,null===t&&(ws=new WeakMap),e.at=t&&((e,t)=>gs?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of ys)As(e)})}})}()}},{name:"native-commands",install(){e.or=Ps}}];function Ws(e){return e}var Is=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],Rs={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"真偽性を反転(falsy → true)",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},add:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},sub:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},abs:{description:"絶対値",hasArgs:!1,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:0},clamp:{description:"範囲内に丸める (min,max)",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:2,maxArgs:2,argTypes:["number","number"]},toFixed:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},upper:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lower:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},capitalize:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},padStart:{description:"先頭を埋める (length[,char]。char の既定は 0 — JS の既定は空白なので注意)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},padEnd:{description:"末尾を埋める (length[,char]。char の既定は空白 — JS と同じ)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},repeat:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},reverse:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},truncate:{description:"切り詰めて省略記号 (length[,suffix]。suffix の既定は … — U+2026 の 1 文字)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},join:{description:"配列を連結 ([separator]。既定はカンマ + 空白)",hasArgs:!0,resultType:"string",acceptTypes:["array"],minArgs:0,maxArgs:1,argTypes:["string"]},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},unit:{description:"単位(接尾辞)を付加",hasArgs:!0,resultType:"string",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["string"]},date:{description:"ロケール形式の日付 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style]。style は full / long / medium / short、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:2,argTypes:["string","string"]},ymd:{description:"YYYY-MM-DD 形式 ([separator]。既定は -)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},hms:{description:"HH:MM:SS 形式 ([separator]。既定は :)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},coalesce:{description:"null / undefined の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},nullIfEmpty:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0},currency:{description:"通貨の書式 (code[, locale]。code は ISO 4217 — JPY / USD / EUR、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:1,maxArgs:2,argTypes:["string","string"]}},Ds=2,qs=Object.freeze({}),Ls=Object.freeze({}),zs=Object.freeze({}),Us=Object.freeze(["prevent","stop","ro","direct"]),Fs=Object.freeze(["init","sync"]),Vs=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function _s(){return{version:2,syntax:{bindAttribute:ie.bindAttributeName,tagName:ie.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(ae),modifiers:{flags:Us,keyValue:Fs,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:N,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:j,class:C,attr:M,style:P}}},filters:[...Object.keys(Te),...Object.keys(xn)],filterMeta:Rs,filterAliases:qs,declarationAliases:Ls,apiAliases:zs,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(Vs.map(e=>[e,{type:"boolean",default:!0}])),features:[...Is],nativeCommands:Object.fromEntries(Object.entries(Ms).map(([e,t])=>[e,[...t]]))}}var Bs=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),Hs=Object.freeze([]);function Ks(e){if(!ie.enableContractAnalyzer)return Hs;let t=[],n=gs,l=e=>{t.push(e),n?.(e)},r=e.manifestExtensions;if(null===r||"object"!=typeof r)return t;for(let e of Object.keys(r))Bs.has(e)||l({type:"contract:unsupported-extension",namespace:e});let i=r["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=Js(e);if(l({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){l({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let r=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(r.observables??{})){let r=n.ue.get(t);if(void 0===r){l({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==r&&l({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:r})}for(let t of Object.keys(r.inputs??{}))n.inputs.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(r.commands??{}))n.commands.has(t)||l({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function Js(e){let t=customElements.get(e)?.wcBindable;if(null===t||"object"!=typeof t||"wc-bindable"!==t.protocol)return null;let n=e=>Array.isArray(e)?e:[],l=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&l.set(e.name,e.event);let r=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{ue:l,inputs:r(t.inputs),commands:r(t.commands)}}function Ys(e,t){(function(e){for(let t of e)s.has(t.name)||(s.add(t.name),t.install())})(Es),rn(e,t)}export{wi as Ssr,Ce as TRUSTED_TYPES_POLICY_SLOT,vi as VERSION,Ds as WCS_MANIFEST_VERSION,Ks as analyzeContract,Ys as bootstrapState,on as buildBindings,qs as builtinFilterAliases,Rs as builtinFilterMeta,Ws as defineState,Zt as getBindingsReady,se as getConfig,Me as getTrustedTypesPolicy,_s as getWcsManifest,Pe as setTrustedTypesPolicy};
2
2
  //# sourceMappingURL=index.esm.js.map