@wcstack/state 4.11.2 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +4 -4
- package/README.md +4 -4
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/split/chunks/chunk-XEMLOHP4.js +2 -0
- package/dist/split/chunks/{chunk-UFEQAPJE.js.map → chunk-XEMLOHP4.js.map} +1 -1
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/package.json +1 -1
- package/dist/split/chunks/chunk-UFEQAPJE.js +0 -2
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:(...r)=>{let l=t(...r);return e(l)?l:n(...r)}}var r=e=>!0===e,l=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.Mt&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.Mt(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.ce=null,this.ue=!1,this._=[],this.Z=[],this.yt=null,this.F=-1,this.G=c,this.je=null,this.Lt=null,this.Wt=null,this.V=null,this.mn=!1,this.hn=!1,this.gn=!1,this.ee=0,this.wt=new Set,this.t=e,this.c=n,this.s=t;let r=null===n?[null]:n.h.slice(),l="*"===t;l&&r.push(n),this.n=r.length-1,this.Y=l?[]:null===n?[t]:[...n.Y,t],this.h=r}Hn(e){this.wt.has(e)||(this.wt.add(e),this._.push(e),e.Z.push(this))}Wo(e){this.wt.delete(e);let t=this._;t.splice(t.indexOf(e),1)}_o(){this.getter=null,this.ce=null,this.F=-1,this.G=c,this._.length=0,this.wt.clear(),this.Z.length=0,this.yt=null,this.je=null,this.Lt=null,this.Wt=null,this.V=null}te(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.bt=new Map,this.Un=e}vt(e){return this.bt.get(e)}get(e){let t=this.bt.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),r=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),r),this.Un?.(t),this.bt.set(e,t),r&&r.u.push(t),t}all(){return this.bt.values()}_t(e){this.bt.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,r=e.split("."),l=[];for(let e=0;e<r.length;e++){let t=r[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,l.push(Number(t)),r[e]="*"):"*"===t&&l.push(-1)}if(!n)return{o:r.join("."),indexes:l};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.kt=null,this.S=null,this.Se=null,this.V=null,this.u=null,this.w=!0,this.a=e,this.y=t,this.N=n}},y=class{constructor(e,t){this.T=null,this.d=[],this.S=null,this.j=null,this.re=!1,this.Bt=!1,this.St=!1,this.o=e,this.oe=t,this.n=e.n+1}},b=[];function $(t,n,r){throw new Error(`[@wcstack/state] ${t}${e.Vo?.(t,n,r)??""}`)}function v(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function w(t,n=[]){return e.Ho?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function A(e,t,n,r){$(w(e,t),n,r)}var k=class{constructor(e){this.Et=new Set,this.name=e}get size(){return this.Et.size}subscribe(e){return this.Et.add(e),()=>{this.Et.delete(e)}}unsubscribe(e){return this.Et.delete(e)}emit(...e){let t=[];for(let n of this.Et)try{t.push(n(...e))}catch(e){t.push(void 0),v(e,`[@wcstack/state] ${w(17,[this.name])}`)}return t}};function x(e,t,n){if(void 0===e)return[];Array.isArray(e)||A(18,[t]);let r=new Set;for(let l of e)("string"!=typeof l||""===l)&&A(19,[t]),l===n&&A(20,[t,l,n]),r.has(l)&&A(21,[t,l]),r.add(l);return e}var S=Symbol.for("wcstack.transition-runner");function T(e){let t=globalThis[S];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function N(e,t,n){let r=T(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var j="else",O="eventToken",C="command",M="class",P="attr",E="style",W=/^\$[1-9]\d{0,2}$/,I=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function R(e){let t=[],n=[],r="",l=null,i=!1,s=-1,o=-1,a=e=>{let l=function(e,t,n){let r=-1===t?e.length:t,l=-1===n?0:n;return e.slice(r-e.slice(0,r).trimStart().length,l+e.slice(l).trimEnd().length)}(r,s,o);(!e||l||i)&&(t.push(l),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:I.test(e)?Number(e):e)}(l,i))),r="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];l?n===l?l=null:(-1===s&&(s=r.length),r+=n,o=r.length):'"'===n||"'"===n?(l=n,i=!0):","===n?a():r+=n}return null!==l&&A(107,[l,e]),a(!0),{args:t,literals:n}}var D=e=>e.trim();function L(e,t){let n=[],r=null;for(let l=0;l<e.length;l++){let i=e[l];null!==r?i===r&&(r=null):"'"===i||'"'===i?r=i:i===t&&n.push(l)}return n}var q=(e,t)=>L(e,t)[0]??-1;function z(e,t){let n=[],r=0;for(let l of L(e,t))n.push(e.slice(r,l)),r=l+1;return n.push(e.slice(r)),n}function U(e,t,n){let r=q(e,"|");if(-1===r)return[e.trim(),[]];let l=e.slice(r+1).trim(),i=n.get(l);return void 0===i&&(i=function(e,t,n){let r=n??e.join("|");return e.map(e=>{let n=q(e,"("),l=(e=>L(e,")").pop()??-1)(e);if(-1===l&&(l=e.lastIndexOf(")")),-1!==n&&-1===l&&A(108,[e]),-1!==l&&-1===n&&A(109,[e]),-1!==l&&l<n&&A(110,[e]),-1!==l&&e.slice(l+1).trim().length>0){let t=e.slice(l+1).trim();A(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&A(112,[r]),i.includes("#")){let[,e]=i.split("#");A("input"===t?113:114,[i,e])}return-1===n?{Kn:i,args:[],literals:[]}:{Kn:i,...R(e.substring(n+1,l))}})}(z(l,"|").map(D),t,e),n.set(l,i)),[e.slice(0,r).trim(),i]}var F=new Map;function V(e){A(1101,[e])}function _(e){let[t,n]=U(e,"output",F);t.includes("@")&&A(32,[t]);let r=t,l=r.startsWith("."),i=l?r.slice(1):r;return(i.length>0&&i.split(".").some(e=>0===e.length)||!l&&0===i.length)&&A(119,[e]),function(e){e.includes("**")&&V(e);let t=e.split(".").length;t>512&&A(117,[e,t])}(r),{et:r,tt:n}}var B=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],H=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function K(e){return e.includes("**")&&V(e),e}var J=0;function Y(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var G=()=>new Set,Z=()=>[],X=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function ee(e,t){return e===t||e!=e&&t!=t}function te(e,t,n){let r=e.V?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e.V.delete(t)}function ne(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function re(e,t){for(;null!==e&&e.a.n>t;)e=e.a.oe;return null!==e&&e.a.n===t?e:null}function le(e,t,n){let r=re(e,n);return null!==r&&r.a.o===t.h[n]?r:null}var ie=class{constructor(e,t){this.Me=0,this.f=null,this.Le=0,this.nt=new Set,this.ot=new Map,this.qn=Symbol("wcs.block"),this.element=null,this.$t=[],this.We=null,this.zn=[],this.qt=0,this.X=null,this.H=new Map,this.ie=new Map,this._e=[],this.Be=[],this.Ve=[],this.He=!1,this.yn=!1,this.zt=new WeakMap,this.I=0,this.Yt=0,this.wn=0,this.bn=0,this.vn=!1,this.Gt=!1,this.Xt=!1,this.Oe=0,this.Yn=()=>{this.I=0,this.vn=!1},this.Gn=()=>{this.Oe--},this.rp=null,this.rr=null,this.Uo=()=>{this.He&&this.xt()},this.Ko=(e,t)=>e(this.proxy,...t),this.Xn=[],this.Ue=[],this.Jn={$untracked:e=>{let t=this.X;if(null===t)return e();t.Ee++;try{return e()}finally{t.Ee--}},$eqIndex:(e,t=1)=>{let n=re(this.f,t);null===n&&A(7,[e]);let r=this.o(e);if(null!==r.getter||r.ue)return this.watchIndex(t),n.y===this.read(r,null);let l=this.X;if(null!==l){let e=l.getter,n=r.je??(r.je=[]);if(!n.some(n=>n.getter===e&&n.Qn===t)){n.push({getter:e,Qn:t});let l=e.h[t];(l.Lt??(l.Lt=[])).push({source:r,getter:e})}}return n.y===this.v(r,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,re(this.f,n.n)))},$dependOn:e=>{this.resolve(K(e),this.f),null!==this.X&&0===this.X.Ee&&this.Zn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,r)=>this.kn(e,t,n,r),$resolve:(...e)=>{let t=K(e[0]),n=e[1]??[],r=this.o(t,!0);this.Sn("$resolve",t,r,n,!0);let l=this.eo(r,n,null);if(e.length<3)return this.read(r,l);this.C(r,l,e[2])},$postUpdate:e=>{this.resolve(K(e),this.f);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.N=n.a.T[n.y],X.delete(n.a.T),this.P.Jt(n)),this.En(t,n),null!==n&&this.to(n,t,void 0,n.N,!1),0===t.n&&this.no(t,void 0,void 0,!0),this.Qt(t,n,void 0,void 0,!1)}},this.P=t,this.O=new d(e=>{this.Ue.push(e),this.rt(e)}),this.oo(e);let n=this,r={getOwnPropertyDescriptor(e,t){let r=Reflect.getOwnPropertyDescriptor(n.target,t);return r&&(r.configurable=!0),r},get(e,t,r){let l=n.target;if("symbol"==typeof t)return Reflect.get(l,t);if(36===t.charCodeAt(0))return n.it(t);if(t.indexOf(".")<0){let e=n.O.vt(t);if(void 0===e||null===e.getter){let e=l[t];if("function"==typeof e)return r===n.proxy&&n.U?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.f),n.read(n.rp,n.rr)},set:(e,t,r)=>"symbol"==typeof t?Reflect.set(n.target,t,r):(n.resolve(K(t),n.f),n.C(n.rp,n.rr,r),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])r[e]=(t,...r)=>Reflect[e](n.target,...r);this.proxy=new Proxy({},r)}o(e,t){let n=this.O.get(e);return t||(n.mn=!0),n}io(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let r=Object.getOwnPropertyDescriptor(n,e);if(void 0===r.get&&void 0===r.set)continue;let l=this.o(e);l.getter=r.get??null,l.ce=r.set??null,null!==l.getter&&l.n>0&&(l.F=this.Me++)}for(let e of this.O.all())this.rt(e)}rt(e){e.t.includes("**")&&V(e.t),("__proto__"===e.s||"prototype"===e.s)&&A(120,[e.t]);let t=e.c;e.ue=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ue),null===e.getter&&this.qo(e)}qo(e){let t=e.t,n=e.s;if(W.test(n))e.getter=function(){return this[n]};else{let r=t.split("."),l=r.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(l<0||r.indexOf("*",l)>=0)return;e.getter=()=>(this.resolve(t,this.f),this.rp!==e?this.read(this.rp,this.rr):this.read(e.c,this.f)?.[n]),e.ce=r=>{if(this.resolve(t,this.f),this.rp!==e)return this.C(this.rp,this.rr,r);let l=this.read(e.c,this.f);null==l&&A(4,[t,l]),l[n]=r}}e.gn=!0,e.n>0&&(e.F=this.Me++)}Ke(e,t){let n=null===e?this.H:e.u??=new Map,r=n.get(t);return void 0===r&&n.set(t,r=new y(t,e)),t.mn=!0,this.J(r),r}so(e){try{this.J(e)}catch(t){this.Zt(t,e.o.t,e.S?.E??null,"for")}}J(t){let n=this.v(t.o,t.oe);if(n===t.T)return;this.ao(t);let r=function(e,t,n){let r=Array.isArray(t)?t:b;if(r===e.T)return null;let l=e.d,i=r.length,s=l.length,o=new Array(i),a=0;for(;a<i&&a<s&&l[a].N===r[a];)o[a]=l[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&l[u].N===r[c];)o[c]=l[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,r[t]);else if(a>c)for(let e=a;e<=u;e++)n.Vt(l[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)l[e].N===r[e]&&(o[e]=l[e]);let i=new Map;for(let e=u;e>=a;e--){let n=l[e];if(e<=t&&o[e]===n)continue;let r=i.get(n.N);void 0===r?i.set(n.N,n):Array.isArray(r)?r.push(n):i.set(n.N,[r,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,l=r[t],s=i.get(l);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(l)):(n=s,i.delete(l))),o[t]=n??new g(e,t,l)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Vt(t);else n.Vt(e)}for(let e=a;e<i;e++){let t=o[e];t.y!==e&&(t.y=e,n.Bo(t))}return e.d=o,e.T=r,l}(t,n,this);if(null===r)return;if(t.T===n){let e=Y(this.zt,n,Z);if(e.push(t),e.length>1)for(let t of e)t.St=!0}e.st?.(this,t,r),(null!==t.S||null!==t.j)&&!t.re&&(t.re=!0,this.Be.push(t),this.$e());let l=t.o.Lt;if(null!==l)for(let{source:e,getter:n}of l){let l=this.v(e,null),i=r[l],s=t.d[l];i!==s&&(void 0!==i&&i.w&&this.$n(n,i),void 0!==s&&this.$n(n,s))}}Bo(e){this.P.zo(this,e)}Vt(e){e.w=!1;let t=e.V;if(null!==t){for(let e of t)te(e.source,e.key,e.sub);e.V=null}if(null!==e.u)for(let t of e.u.values()){this.ao(t);for(let e of t.d)this.Vt(e)}}ao(e){let t=this.zt.get(e.T);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.St=!1,1===t.length&&(t[0].St=!1))}resolve(e,t){let n=m(e),r=this.rp=this.o(n.o,!0),l=n.indexes;this.rr=0===r.n?null:null===l?le(t,r,r.n):this.eo(r,l,t,e)}eo(e,t,n,r){let l=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.Ke(l,a),c=t[o++];if(c<0)c=le(n,e,s)?.y??-1;else if(r&&u.T===b&&Object(i=this.v(a,l))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=r.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(l=u.d[c]??null,null===l)break}return this.rp=e,l}at(e,t){return 0===e.n?ne(this.target,e.Y):null===t?void 0:ne(t.N,e.Y)}read(e,t){let n=this.X;if(null!==n&&0===n.Ee&&this.Zn(e,t,n),null!==e.getter)return this.P.Yo(this,e,t);if(e.ue){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.nt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&A(301,[e.t],e.s,Object.keys(this.target)),this.at(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.Ee++;try{return this.read(e,t)}finally{n.Ee--}}Zn(e,t,n){let r=n.getter;e.Hn(r),0===r.n?e.ee!==n.fe&&(e.ee=n.fe,n.xn.push(e)):e.n>0&&re(t,Math.min(e.n,r.n))!==re(n.r,Math.min(e.n,r.n))&&(r.yt??(r.yt=new Set)).add(e)}Go(e,t){for(let n=0;n<this.qt;n++){let r=this.zn[n];r.getter===e&&r.r===t&&A(701,[e.t])}this.qt>=128&&A(801,[e.t]);let n=this.qt++;this.Le++;let r=this.zn[n]??={getter:e,r:t,Ee:0,fe:0,xn:[]};r.getter=e,r.r=t,r.Ee=0,r.fe=++J,r.xn.length=0;let l=this.X;this.X=r;let i=this.f;this.f=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Xo(e,r),t}finally{this.Le--,this.qt--,this.X=l,this.f=i,r.r=null}}Xo(e,t){let n=t.fe;for(let e of t.xn)e.ee=n;e.Z=e.Z.filter(t=>t.ee===n||t.n>0||!t.ue&&Array.isArray(null!==t.getter?t.G:this.at(t,null))||this.lo(t,e))}lo(e,t){return e.Wo(t),this.Ue.push(e),!1}Jo(){for(let e=this.Ue;e.length>0;e=this.Ue){this.Ue=[];let t=new Set;for(let n of e)if(!(n.mn||n.hn||null===n.c||n.u.length>0||n._.length>0)&&(null===n.getter||n.gn&&n.F<0)&&null===n.V){n.hn=!0,this.O._t(n),t.add(n.c);for(let e of n.Z)this.lo(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.hn)).length||this.Ue.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.Ee){let n=t.getter,r=n.h[e];if(r){let e=r.Wt??(r.Wt=[]);e.includes(n)||e.push(n)}}}it(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:W.test(t)?+t.slice(1):0;return(e<1||e>128)&&A(1001,[t]),this.watchIndex(e),re(this.f,e)?.y}let r=this.Jn[t];if(void 0!==r)return r;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.it?.(this,t)}eq(e,t){this.resolve(e,this.f);let n=this.rp,r=this.rr;if(null!==n.getter||n.ue||n.n>0)return ee(this.read(n,r),t);let l=this.X;return null!==l&&0===l.Ee&&this.Qo(n,t,l),ee(this.v(n,null),t)}Qo(e,t,n){let r=n.getter,l=n.r,i=null===l?this.Xn:l.V??(l.V=[]);for(let l=0;l<i.length;l++){let s=i[l];if(s.sub.getter===r&&s.source===e){if(ee(s.key,t))return void(s.fe=n.fe);s.fe!==n.fe&&(te(e,s.key,s.sub),i.splice(l--,1))}}let s={getter:r,r:l};Y(e.V??=new Map,t,G).add(s),i.push({source:e,key:t,sub:s,fe:n.fe})}no(e,t,n,r){this.en(e,l=>{let i=l.V;if(null===i&&null===l.je)return;let s=l===e?[]:l.t.slice(e.t.length+1).split("."),o=ne(t,s),a=ne(n,s);if(null!==l.je&&this.Zo(l,o,a,r),null!==i)for(let e of r?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.P.xe(this,n.getter,n.r):te(l,e,n)}})}C(t,n,r,l=!1,i=!1){if(this.Le>0&&A(8),i||this.Oe>0?this.Gt=!0:this.Xt=!0,e.Ie?.(this,t,n,r,i))return;if(null!==t.ce){try{this.Nn(t.ce,n,[r])}finally{this.Qt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&A(2,[t.t]),t.n>0&&null===n&&A(3,[t.t]);let s=t.ue?this.v(t,n):this.at(t,n);if(l||!this.Ut||!Object.is(s,r)||Object(r)===r){if("*"===t.s){let e=n;e.a.T[e.y]=r,X.delete(e.a.T),e.N=r,this.P.Jt(e)}else{let e=1===t.Y.length?0===t.n?this.target:n.N:this.v(t.c,n);null==e&&A(4,[t.t,e]),e[t.s]=r}this.Tn(t,n),null!==n&&this.to(n,t,s,r),0===t.n&&this.no(t,s,r),this.Qt(t,n,s,r,!0,i)}}co(e){return(this.zt.get(e.T)??[]).filter(t=>t.T===e.T&&(null===t.oe||t.oe.w))}to(e,t,n,r,l=!0){let i=e.a,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.T);if(!o&&!i.St&&null===i.o.getter&&!i.o._.length)return;let a=e.N,u=(t,i)=>{if(void 0===i||i===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(i.N=r,this.P.Jt(i)),l?this.Tn(o,i):this.En(o,i),this.Qt(o,i,n,r,l)};for(let t of this.co(i))if(u(t,t.d[e.y]),o)for(let n of t.d)n.N===a&&n.y!==e.y&&u(t,n);if(""===s)return;let c=new Set([i.T]),h=e=>Array.isArray(e)&&e.includes(a),d=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.zt.get(e)??[])for(let e of t.d)e.N===a&&u(t,e);for(let n of t){let t=n.G,r=t===f;r&&(t=this.H.get(n)?.T),(r||h(t))&&!c.has(n._)&&c.add(n._)&&(!r&&t!==e&&this.P.xe(this,n,null),d(t,n._))}},p=e=>{for(let t of e.Z)if(!c.has(t)&&c.add(t))if(null!==t.getter)p(t);else if(!t.ue){let e=this.at(t,null);h(e)&&d(e,t._)}};null!==i.o.getter?p(i.o):d(i.T,i.o._)}En(e,t){this.er(e,t,e=>{this.J(e);for(let t of e.St?this.co(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.d)this.Nt(e,n),this.En(e,n)}})}Tn(e,t){let n=null===t?this.H:t.u;if(null!==n)for(let t of n.values())t.o.te(e)&&this.J(t)}er(e,t,n){let r=null===t?this.H:t.u;if(null!==r)for(let t of r.values())t.o.te(e)&&n(t)}Zo(e,t,n,r){for(let{getter:l,Qn:i}of e.je)this.uo(l.h[i],e=>{for(let i of r?e.d.keys():[t,n]){let t="number"==typeof i?e.d[i]:void 0;void 0!==t&&this.$n(l,t)}})}$n(e,t){t.a.n===e.n?this.P.xe(this,e,t):this.tn(t,e,t=>this.P.xe(this,e,t))}Qt(t,n,r,l,i,s){e.se?.(this,t,n,r,l,i,s),this.qe(t,n)}qe(e,t){this.P.tr(this,e,t),this.$e()}fo(e){let t=this.ot.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.ot.set(e,n);let r=this.root,l=this.qn;return r.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==r;i=i.parentNode){let r=i[n];if(void 0!==r&&(r(t),t.cancelBubble))return;let s=i[l];if(void 0!==s&&s.w&&s.nr(e,t))return}}),n}reset(t){let n=this.target,r=this.nt;for(let e of this.O.all())null===e.c&&null!==e.getter&&r.add(e.s);this.oo(t);for(let e in n)"$"!==e[0]&&r.add(e);for(let e of r)e in t&&r.delete(e);for(let e of this.ie.values())for(let t of e)this.nn(t);for(let e of this.H.values())this.po(e);this.We=null;try{this.xt()}finally{this.Rn()}e.element?.(this,"reset")}oo(t){for(let[e,n]of B)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||A(46);for(let e of n)a(e,"$features")}let r=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof r||!r||Array.isArray(r))&&A(44,["state","$behavior"]);for(let e in r)(!H.includes(e)||"boolean"!=typeof r[e])&&A(44,["$behavior",e]);let[l,i,s]=H.map(e=>r[e]??!0);void 0!==this.target&&(l!==this.Ht||i!==this.Ut||s!==this.Kt)&&A(45);let o=function(e,t){let n={};for(let r of x(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new k(r);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of x(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let r=e.$on;if(void 0===r)return n;(null===r||"object"!=typeof r)&&A(22);for(let[e,l]of Object.entries(r)){let r=n.get(e);void 0===r&&A(23,[e]),"function"!=typeof l&&A(24,[e]),r.subscribe((...e)=>t(l,e))}return n}(t,this.Ko);this.Ht=l,this.Ut=i,this.Kt=s,e.pe?.(this,t),this.target=t,this.Me=0;for(let e of this.O.all())e._o();this.Xn.length=0,this.io(t),this.commands=o,this.de=u}po(e){this.so(e);let t=this.o(`${e.o.t}.*`);for(let n of e.d)if(n.kt=null,n.V=null,this.Nt(t,n),null!==n.u)for(let e of n.u.values())this.po(e)}K(e){let t=[];for(let n=e;null!==n;n=n.a.oe)t.unshift(n.y);return t}or(e,t,n){let r=this.de.get(e);void 0===r&&A(1301,[e],e,this.de.keys()),r.emit(t,...this.K(n))}command(e){let t=this.commands[e];return void 0===t&&A(1302,[e],e,Object.keys(this.commands)),t}ir(e,t,n){this.command(e).emit(t,...this.K(n))}sr(e,t,n){let r=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof r&&A(5,[e]),this.Nn(r,n,[t,...this.K(n)])}Nn(e,t,n){let r=this.f;this.f=t;try{return e.apply(this.proxy,n)}finally{this.f=r}}Nt(e,t){if(null!==e.getter){let n=null===t?this.H:t.u;if(null!==n)for(let t of n.values())!t.Bt&&t.o.te(e)&&(t.Bt=!0,this.Ve.push(t))}if(null===t)return void this.en(e,e=>{let t=this.ie.get(e);if(void 0!==t)for(let e of t)this.nn(e)});let n=t.Se;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.te(e)&&this.nn(n[t]);let r=t.S;null!==r&&null!==r.me&&r.mo(this,e);let l=t.a.j;if(null!==l)for(let n of l){let r=n.map.get(t);void 0!==r&&null!==r.me&&r.mo(this,e)}}An(e,t,n){this.en(e,e=>{let r=e._;for(let l=0;l<r.length;l++){let i=r[l];if(0===i.n)this.ct(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.yt&&i.yt.has(e))this.on(i.h[i.n],e=>this.ct(i,e,n));else if(i.n<=e.n){let e=re(t,i.n);null!==e&&this.ct(i,e,n)}else this.tn(t,i,e=>this.ct(i,e,n))}})}ct(t,n,r){r(t,n)&&(e.Ne?.(this,t,n),this.Nt(t,n),this.An(t,n,r))}en(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.en(n[e],t)}on(e,t){this.uo(e,e=>{for(let n of e.d)t(n)})}uo(e,t){if(0===e.n){let n=this.H.get(e);return void(void 0!==n&&t(n))}this.on(e.h[e.n],n=>{let r=n.u?.get(e);void 0!==r&&t(r)})}tn(e,t,n){if(e.a.n===t.n)return n(e);let r=e.u?.get(t.h[e.a.n+1]);if(void 0!==r)for(let e of r.d)this.tn(e,t,n)}ar(e){let t=e.r;null===t?Y(this.ie,e.o,G).add(e):(t.Se??(t.Se=[])).push(e)}Pn(e){let t=e.r;if(null===t)return void this.ie.get(e.o)?.delete(e);let n=t.Se;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}nn(e){e.re||(e.re=!0,this._e.push(e),this.$e())}$e(){this.He||(this.He=!0,queueMicrotask(this.Uo))}Cn(){for(let e of this._e)e.re=!1;for(let e of this.Be)e.re=!1;for(let e of this.Ve)e.Bt=!1;this._e=[],this.Be=[],this.Ve=[],this.P.nt(this)}ho(t,n){let r=[...new Set([...this._e,...this.Be,...this.Ve].map(e=>e.o.t))];v(r,`[@wcstack/state] ${w(t)}`),e.ut?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:r}),this.Cn()}xt(){this.He=!1;let e=this.Yt;this.Yt=0;let t=0;if(!this.Gt||this.Xt?this.Yn():e>0?t=e:1===(t=++this.I)&&setTimeout(this.Yn,0),this.Gt=this.Xt=!1,t>100)101===t?this.ho(41,100):this.Cn();else{this.yn=!0;try{for(let e=0;this._e.length>0||this.Be.length>0||this.Ve.length>0;e++){if(e>=32){this.vn?this.Cn():this.ho(11,32),this.vn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Bt=!1,this.so(e)}let r=this.Be,l=this._e;this.Be=[],this._e=[];let i=!1,s=()=>{i=!0;for(let e of r){e.re=!1;for(let t of[e.S,...e.j??[]])if(null!==t&&t.w)try{t.Tt()}catch(n){this.Zt(n,e.o.t,t.E,"for")}}for(let e=0;e<2;e++)for(let t=0;t<l.length;t++){let n=l[t];!n.re||null===n.I==(0===e)||(n.re=!1,(null===n.Fn||n.Fn.w)&&this.ze(n))}if(!this.yn&&(this.Ye(),0===--this.wn&&this.go(),this.He)){this.Yt=t+1,this.bn++;try{for(;this.He;)this.xt()}finally{this.bn--}}},o=(r.length>0||l.some(e=>null!==e.I))&&0===this.bn?N("state",s):s();i||this.wn++,void 0!==o&&o.then(void 0,v)}}finally{this.yn=!1}this.Gt=this.Xt=!1,this.Ye(),0===this.wn&&this.go(),e>0&&this.He&&(this.Yt=t+1)}}go(){e.he?.(this),this.Jo()}Rt(e,t){this.$t.push([e,t])}Zt(e,t,n,r){this.Rt(e,{o:{t},l:n,rn:()=>r})}ze(e){try{e.apply()}catch(t){return void this.$t.push([t,e])}null!==this.We&&this.yo(e.o,e.r)}yo(e,t){let n=Y(this.We,e.t,Z);null!==t&&n.push(this.K(t))}Rn(){this.We="function"==typeof this.target.$renderedCallback?new Map:null}Ye(){let t=this.We;if(null!==t&&t.size>0){this.We=new Map;let e,n=[...t.keys()],r={};for(let[e,n]of t)n.length>0&&(r[e]=n);this.Oe++;try{e=this.Te("$renderedCallback",[n,r])}catch(e){v(e)}Q(e)?e.then(this.Gn,e=>{this.Gn(),v(e)}):this.Oe--}if(0===this.$t.length)return;let n=this.$t;this.$t=[];let r=this.target.$errorCallback;for(let[t,l]of n){e.Ge?.(this,t,l);let n=l.o.t,i=l.rn();if("function"==typeof r)try{let e=this.Te("$errorCallback",[t,{path:n,bindingType:i,node:l.l}]);Q(e)&&e.then(void 0,v)}catch(e){v(e)}else v(t,`[@wcstack/state] ${w(12,l.name?[i,n,l.name,l.i]:[i,n])}`,l.l)}}Te(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Nn(n,null,t):void 0}wo(e,t,n){if(0===e.n)return void n(null,[]);let r=[],l=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.Ke(s,o),u=t=>{r.push(t.y),i===e.n?n(t,r):l(i+1,t),r.pop()};for(let e of i-1<t.length?[a.d[t[i-1]]]:a.d)void 0!==e&&u(e)};l(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.Sn("$getAll",e,n,t,!1);let r=t;if(void 0===r){r=[];let t=this.f;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let l=le(t,n,e);if(null===l)break;r.push(l.y)}0===r.length&&A(6,[e])}}let l=[];return this.wo(n,r,e=>l.push(this.read(n,e))),l}kn(e,t,n,r){Array.isArray(t)||A(9,[e]),this.Le>0&&A(8);let l=this.o(e,!0);this.Sn("$setAll",e,l,t,!1);let i=[];this.wo(l,t,(e,t)=>i.push([e,t.slice()]));let s=!0===r?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&A(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,r]=i[e],a="function"==typeof n?n(this.v(l,t),...r):s?n[e]:n;void 0!==a&&(this.C(l,t,a),o++)}return o}Sn(e,t,n,r,l){let i=r.length;(i>n.n||l&&i<n.n)&&A(l?901:902,[e,t,n.n,i])}},se={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},oe=()=>se,ae=new Map,ue=new Set(["if","elseif","else","for"]),ce=new Set([j,"if","elseif","for","..."]),fe=new Set([M,P,E,C,O,"state"]);function he(e){let t=function(e){return z(e,";")}(e).map(D).filter(e=>e.length>0).map(e=>{let t=q(e,":");-1===t&&A(101,[e]);let n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),l=n.split("#")[0].split("|")[0].trim();if(ce.has(l)){let t;return l!==n&&A(102,[e,l]),l===j?(r.length>0&&A(103,[e]),t={et:"#else",tt:[]}):"..."===l?(0===r.length&&A(104,[e]),t=_(r),t.tt.length>0&&A(105,[e])):(t=_(r),"for"===l&&t.tt.length>0&&A(121,[e])),{ye:l,we:[l],sn:[],M:[],...t,b:"..."===l?"spread":l}}(l===M||l===P)&&A(122,[e,l]);let i=_(r),s=function(e){let[t,n]=U(e,"input",ae),r=t.split("#").map(D);r.length>2&&A(115,[t]);let[l,i]=r,s=l.split(".").map(D);return!(s.length>1&&""===s[0])&&(0===l.length||s.some(e=>0===e.length))&&A(116,[e]),{ye:l,we:s,sn:i?i.split(",").map(D):[],M:n}}(n),[o]=s.we;if(""===o&&s.we.length>1){let e=s.we.slice(1);return(e.includes("")||fe.has(e[0]))&&A(106,[n]),{...s,ye:e.join("."),we:e,...i,b:"prop"}}return{...s,...i,b:"radio"===l||"checkbox"===l?l:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ue.has(e.b))&&A(201,[e]),t}var de=["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"],pe=new Map,me=new Map;function ge(e){for(let t of Object.keys(e))pe.set(t,{...e[t]});me.clear()}function ye(e){return pe.has(e)}function be(e){A(26,[e])}function $e(e){A(27,[e])}function ve(e,t){A(28,[e,t])}function we(e,t){A(29,[e,t])}function Ae(e){return!(!e||isNaN(Number(e)))}function ke(e,t){return Ae(e)||$e(t),Number(e)}function xe(e,t,n){return ke(e?.[t]??be(n),n)}function Se(e,t){return void 0!==t&&t.length>0?t[0]:e}var Te=(e,t)=>({factory:n=>{let r=xe(n,0,e);return n=>("number"!=typeof n&&ve(e,n),t(n,r))},arity:[1,1]}),Ne={eq:{factory:(e,t)=>{let n=e?.[0]??be("eq"),r=Se(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(Ae(n)||$e("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??be("ne"),r=Se(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(Ae(n)||$e("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Te("lt",(e,t)=>e<t),le:Te("le",(e,t)=>e<=t),gt:Te("gt",(e,t)=>e>t),ge:Te("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]}},je=!1;function Oe(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ce(e){return 0===e.length?null:(je||(je=!0,ge(Ne)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,l=me.get(r);if(typeof l<"u")return l;let i=pe.get(e);void 0===i&&function(e,t){de.includes(e)&&$(`[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),A(501,[e],e,t)}(e,pe.keys());let[s,o]=i.arity;t.length<s&&A(601,[e,s,t.length]),t.length>o&&A(602,[e,o,t.length]);let a=i.factory(t,n);return me.set(r,a),a}(e.Kn,e.args,e.literals)))}var Me=Symbol.for("wcstack.trustedTypes.policy");function Pe(){let e=globalThis[Me];return null!==e&&"object"==typeof e?e:null}function Ee(e){globalThis[Me]=e}function We(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ie(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Pe(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Re=Symbol.for("wcstack.state.view-transition-naming"),De=new WeakSet;function Le(){let e=T("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var qe=new WeakMap,ze=e=>e.customElementRegistry??customElements;function Ue(e,t,n,r,l,i=!1){let s=n.localName;if(!s.includes("-"))return l(null);let o=ze(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>Ue(e,t,n,r,l,!0));let a=()=>{let e=o.get(s);o.upgrade(n),l(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,bo:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return qe.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==r&&!r.w||function(e,t,n){let r=n;null!==t&&(t.At??=[]).push(()=>{r=null}),e.then(()=>r?.())}(o.whenDefined(s),r,()=>{try{a()}catch(r){Ke(e,r,t,n)}e.$e()})}function Fe(t,n,r,l,i=n.o,s,o,a){let u=a.properties.get(l)??null,c=a.inputs.has(l),f=t.Kt;f&&null===u&&!c&&A(38,[l]);let h=n.q;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&A(39,[h,l]),"connect"===n.J&&null===u&&A(40,[l]);let d=f&&null!==u&&!c,p=new Ge(t,Be,r,l,i,s,o,n.R,void 0);p.M=n.M,lt(t,p,!d),null!==u&&!n.ro&&r.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.bo||e.detail?.(r,l,i)),(!p.On||!Object.is(i,p.value))&&(i=Oe(p.M,i),null===p.R&&(p.value=i),t.C(p.o,p.r,i,u.bo,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.ze(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.ze(p));let e=r[l];null===p.R&&(p.value=e),t.C(p.o,p.r,e,!1,!0)};"connect"!==n.J||r.isConnected?e():Promise.resolve().then(e)}return p}function Ve(e,t,n){A(e,[t.localName,n])}var _e=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Be=11,He=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Ke=(e,t,n,r)=>e.Zt(t,n.o?.t??n.Pt,r,He[n.i]),Je=Symbol();function Ye(e,t,n){let r=t.q;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.z:Je}var Ge=class{constructor(e,t,n,r,l,i,s,o,a,u=null){this.re=!1,this.M=null,this.On=!1,this.engine=e,this.i=t,this.l=n,this.name=r,this.o=l,this.r=i,this.Fn=s,this.R=o,this.value=a,this.I=u}rn(){return He[this.i]}apply(){if(null!==this.I)return void this.I.Tt();let e=Oe(this.R,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Be||8===this.i||We(this.name)))return;if(this.value===Je)return void(this.value=e);let t=this.l;if(this.i!==Be)9===this.i?t.checked=void 0!==e&&this.an()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.an()):Xe(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.On=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.On=!1}}}an(){return Oe(this.M,this.l.value)}cr(){let e,t=this.l,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.an()}else if(10===this.i){let r=this.an(),l=n.v(this.o,this.r),i=Array.isArray(l)?l:[],s=i.includes(r);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==r):[...i,r]}else e=Oe(this.M,t[this.name]),this.value=NaN;n.C(this.o,this.r,e,!1,!0)}},Ze=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Xe(e,t,n,r){switch(e){case 0:return void(t.data=null==r?"":String(r));case 1:return void(Ze(n)?t[n]="innerHTML"===n?Ie(r):null==r?"":String(r):We(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Ie(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Qe]=[n,r])));case 8:return void(t.innerHTML=Ie(r));case 2:return null!=r&&"boolean"!=typeof r&&A(401,[n,typeof r]),void t.classList.toggle(n,!0===r);case 3:return void(null==r?t.removeAttribute(n):t.setAttribute(n,String(r)));case 4:return void(n.includes("-")?null==r?t.style.removeProperty(n):t.style.setProperty(n,String(r)):t.style[n]=null==r?"":String(r))}}var Qe=Symbol();function et(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Qe];void 0!==n&&(t[n[0]]=n[1])}var tt=class{constructor(e,t,n,r){this.w=!0,this.Se=null,this.u=null,this.At=null,this.Dn=null,this.r=e,this.dt=t,this.L=n,this.$=r}nr(e,t){let n=t.target,r=this.$,l=[],i=null;for(let t of r.de){if(t.name!==e)continue;let s=r.ln[t.l],o=dt(null===this.L?this.dt:this.L[s[0]],s,1);o.contains(n)&&(o!==i&&l.unshift([]),l[0].push(t),i=o)}for(let e of l){for(let n of e)n.In(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.dt:this.L[this.L.length-1]}Re(){let e=this.Dn;return(null===e?null:e.jn(this.dt))??this.dt}insertBefore(e,t){let n=this.s;for(let r=this.Re();;){let l=r.nextSibling;if(e.insertBefore(r,t),r===n)return;r=l}}So(){null===this.L?this.dt.remove():pt(this.Re(),this.s)}Ae(e){if(this.w=!1,null!==this.At)for(let e of this.At)e();let t=this.Se;if(null!==t)for(let n=0;n<t.length;n++)e.Pn(t[n]);if(null!==this.u)for(let e of this.u)e.Ae()}},nt=class extends tt{constructor(e,t,n,r){super(e,t,n,r),this.Eo=0,this.U=null,this.me=0===r.Xe.length?null:new Array(2*r.Xe.length)}$o(e,t){let n=this.U??=new Array(this.$.Xe.length),r=n[t];if(void 0===r){let l=this.$.Xe[t],i=this.me;r=n[t]=new Ge(e,l.i,i[2*t],l.name,l.o,this.r,this,l.R,i[2*t+1])}return r}mo(e,t){let n=this.$.Xe;for(let r=0;r<n.length;r++)n[r].o.te(t)&&e.nn(this.$o(e,r))}Ae(e){let t=this.r;t.S===this&&(t.S=null),super.Ae(e)}};function rt(e,t,n,r){let l=re(n,t.n);try{return e.Ke(l,t)}catch(n){return e.Zt(n,t.t,r,"for"),null===l?e.H.get(t):l.u.get(t)}}function lt(e,t,n){n&&e.ar(t);let r=t.Fn;null!==r&&(r.Se??=[]).push(t)}var it=null;function st(){let e=it;return it=null,e}var ot=-1;function at(t,n,r,l,i=null){let s,o=n.ln,a=n.build,u=n.xo,c=null,f=e.Pe?.(n,null===l?i:l.E,null!==l),h=!f&&n.Mn,d=f?document.createDocumentFragment():(h?n.root:n.Ot).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=dt(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==l?(p=m=new nt(r,s,c,n),null===l.map?r.S=m:l.map.set(r,m)):p=new tt(r,s,c,n),ot>=0&&function(e,t,n,r){let l=null;if(null===t)l=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===l;e++)1===t[e].nodeType&&(l=t[e]);let i=l?.style;if(null===l||void 0===i||De.has(l))return;let s=globalThis[Re]??={counter:0,assigned:0,warned:!1};s.assigned>=r?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${w(25,[r])}`)):(De.add(l),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==l?"row":"branch",ot),n.de.length>0){let e=t.qn;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.No,y=t.We,b=n.ur?u.slice(0,o.length):u,$=null===m?null:m.me;if(null!==$){let e=n.Xe;for(let t=0;t<e.length;t++)$[2*t]=b[e[t].l],$[2*t+1]=e[t].z}for(let e=0;e<g.length;e++){let n=g[e],l=b[n.l],i=n.F;if(i>=0&&null!==$){let e=m.U?.[i];if(void 0!==e){e.re=!1,t.ze(e);continue}try{let e=Oe(n.R,t.read(n.o,r));e!==n.z&&(Xe(n.i,l,n.name,e),$[2*i+1]=e),null!==y&&t.yo(n.o,r)}catch(e){t.Rt(e,m.$o(t,i))}continue}switch(n.i){case 6:{let e=new ht(t,n.$,rt(t,n.o,r,l),l);(p.u??=[]).push(e),l===s&&(p.Dn=e),e.Tt();break}case 7:{let e=ct(t,n.W.map(e=>({$:e.$,o:e.o,R:e.R,E:b[e.l]})),r,p);(p.u??=[]).push(e),l===s&&(p.Dn=e);break}default:try{ut(t,n,l,r,p)}catch(e){Ke(t,e,n,l)}}}return it=p,d}function ut(t,n,r,l,i){let s=r;switch(n.i){case 5:return void function(e,t,n,r,l){let i=n.In,s=e=>i(e,r);if(n.ot){let r=e.fo(n.name),l=t[r];t[r]=void 0===l?s:e=>{l(e),s(e)},n.be&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.ko&&null!==l&&(l.At??=[]).push(()=>t.removeEventListener(n.name,s))}(t,r,n,l,i);case 12:return void Ue(t,n,s,i,r=>function(t,n,r,l,i){let s=n.name,o=t.command(n.Pt.slice(9)),a=null===i?e.lr?.(r,s):null;a||(null===i&&Ve(1202,r,`command.${s}`),i.commands.has(s)||A(1203,[r.localName,s]));let u=new WeakRef(r),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!==l&&(l.At??=[]).push(c)}(t,n,s,i,r));case 13:return void Ue(t,n,s,i,e=>function(e,t,n,r,l){let i=t.name;null===l&&Ve(1202,n,`eventToken.${i}`);let s=l.properties.get(i);void 0===s&&A(1204,[n.localName,i]);let o=t.Pt;n.addEventListener(s.event,n=>{t.Ct&&n.preventDefault(),t.Ft&&n.stopPropagation();try{e.or(o,n,r)}catch(e){v(e)}})}(t,n,s,l,e))}let o=n.o,a=re(l,o.n);if(14===n.i)return void Ue(t,n,s,i,e=>function(e,t,n,r,l,i){null===i&&Ve(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.vo?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:r;Fe(e,{...t,q:null,J:null},n,o,s,a,l,i)}}(t,n,s,a,i,e));if(n.be&&1===n.i)return void Ue(t,n,s,i,r=>function(t,n,r,l,i,s){if(null!==s)return void Fe(t,n,r,n.name,n.o,l,i,s);let o=new Ge(t,1,r,n.name,n.o,l,i,n.R,Ye(t,n,l));o.M=n.M,!e.dr?.(o,n.ro)&&(lt(t,o,!0),t.ze(o))}(t,n,s,a,i,r));let u=new Ge(t,n.i,r,n.name,o,a,i,n.R,Ye(t,n,a));u.M=n.M,lt(t,u,!0),t.ze(u),null!==n.It&&r.addEventListener(n.It,()=>u.cr())}function ct(e,t,n,r){let l=new ft(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Ge(e,7,s.E,"if",t,re(n,t.n),r,null,void 0,l);lt(e,o,!0),null===r&&l.ie.push(o),i??=o}return e.ze(i),l}var ft=class{constructor(e,t,n){this.w=!0,this.D=null,this.y=-1,this.ie=[],this.engine=e,this.W=t,this.r=n}jn(e){return null!==this.D&&this.W[this.y].E===e?this.D.Re():null}Tt(){let e=this.engine,t=-1;for(let n=0;n<this.W.length;n++){let r=this.W[n];if(null===r.o||Oe(r.R,e.read(r.o,re(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(ot=Le(),null!==this.D&&(this.D.So(),this.D.Ae(e),this.D=null),this.y=t,t>=0)){let n=this.W[t],r=at(e,n.$,this.r,null,n.E);this.D=st();let l=n.E.parentNode;l.insertBefore(r,n.E),et(l)}}Ae(){this.w=!1;for(let e of this.ie)this.engine.Pn(e);null!==this.D&&this.D.Ae(this.engine)}},ht=class{constructor(e,t,n,r){this.w=!0,this.Ce=[],this.engine=e,this.$=t,this.a=n,this.E=r,null===n.S?(n.S=this,this.map=null):((n.j??=[]).push(this),this.map=new Map)}jn(e){return 0===this.Ce.length?null:this.Ce[0].Re()}Dt(e){return null===this.map?e.S:this.map.get(e)??null}_t(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ae(this.engine)}Tt(){let e=this.engine,t=this.a.d,n=this.Ce;ot=Le();let r=t.length,l=n.length,i=this.E,s=i.parentNode;if(0===r){if(l>0){let e=n[0].Re(),t=n[l-1].s,r=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){r=null;break}r.push(n)}null!==r?s.replaceChildren(...r):pt(e,t);for(let e=0;e<l;e++)this._t(n[e])}return void(this.Ce=[])}let o=new Array(r),a=0;for(;a<r&&a<l&&this.Dt(t[a])===n[a];)o[a]=n[a],a++;let u=l-1,c=r-1;for(;u>=a&&c>=a&&this.Dt(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],r=t.r;r.w&&this.Dt(r)===t?t.Eo=e:(t.So(),this._t(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(l>0)for(let e=0;e<n;e++){let n=this.Dt(t[a+e]);null!==n&&n.w?(u[e]=n.Eo,f=!0):u[e]=-1}let h=c+1<r?o[c+1].Re():i;if(f){let r=function(e){let t=e.length,n=new Uint8Array(t),r=new Int32Array(t).fill(-1),l=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=l.length;for(;i<s;){let n=i+s>>1;e[l[n]]<t?i=n+1:s=n}i>0&&(r[n]=l[i-1]),l[i]=n}let i=l.length>0?l[l.length-1]:-1;for(;i>=0;)n[i]=1,i=r[i];return n}(u),l=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Dt(n);null!==u&&u.w?0===r[i]&&u.insertBefore(s,l):(s.insertBefore(at(e,this.$,n,this),l),u=st()),o[a+i]=u,l=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(at(e,this.$,t[r],this)),o[r]=st();s.insertBefore(n,h)}}this.Ce=o,et(s)}Ae(){this.w=!1;let e=this.a;if(e.S===this)e.S=null;else if(null!==e.j){let t=e.j.indexOf(this);t>=0&&e.j.splice(t,1),0===e.j.length&&(e.j=null)}for(let e of this.Ce)e.Ae(this.engine);this.map?.clear()}};function dt(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function pt(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var mt=()=>se.bindAttributeName;function gt(){return{l:0,i:1,name:"",o:null,R:null,z:c,In:null,$:null,W:null,M:null,It:null,be:!1,q:null,J:null,ro:!1,Ct:!1,Ft:!1,Pt:null,vo:null,F:-1,ot:!1,ko:!1}}var yt=["state","element","auto","none"],bt=["call","connect"],$t="$command.";function vt(t,n,r){W.test(n)&&(null===r&&A(1401,[n,Number(n.slice(1))]),n=`${r.t}.*.${n}`);let l=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&A(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,r)),i=null===r?0:r.n+1;l.n>i&&A(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?r:r.h[e];l.h[e]!==t&&A(1403,[l.t,l.h[e].t,t.t])}return e.To?.(t,l),l}var wt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),At=e=>8===e.i||wt(e)||1===e.i&&Ze(e.name);function kt(e){A(202,[e])}function xt(t,n,r,l,i){let s=he(n).map(n=>function(t,n,r,l,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),r=null,l=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Kt||A(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&A(33,[i,n]),null!==(o?r:l)&&A(34,[i]),(o?yt:bt).includes(s)||A(35,[i,s]),o?r=s:l=s}return{ro:t.includes("ro"),Ct:t.includes("prevent"),Ft:t.includes("stop"),event:n?n.slice(2):null,q:r,J:l}}(t,n.sn),o=l.localName.includes("-"),a=n.we,u=n.et;if("event"===n.b){if(null!==s.q&&"none"!==s.q&&A(36),"eventToken"===a[0])return{...gt(),l:i,i:13,name:a.slice(1).join("."),Pt:u,be:o,Ct:s.Ct,Ft:s.Ft};let r=u.startsWith($t)?u.slice(9):null,{Ct:l,Ft:c}=s,f=n.ye.slice(2),h=n.sn.includes("direct"),d=!h&&_e.has(f);d&&t.fo(f);let p=n=>{v(n),d&&e.handlerThrew?.(t,u,f)};return{...gt(),l:i,i:5,name:f,ot:d,be:o,ko:h,In(e,n){l&&e.preventDefault(),c&&e.stopPropagation();try{if(null!==r)t.ir(r,e,n);else{let r=t.sr(u,e,n);Q(r)&&r.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===n.b)return{...gt(),l:i,i:14,o:vt(t,u,r),be:o};if("command"===a[0]&&a.length>1)return u.startsWith($t)||A(1201,[n.ye,u]),{...gt(),l:i,i:12,name:a.slice(1).join("."),Pt:u,be:o};let c=vt(t,u,r),f={...gt(),l:i,i:1,name:n.ye,o:c,R:Ce(n.tt),M:Ce(n.M),ro:s.ro,q:s.q,J:s.J};if("radio"===n.b||"checkbox"===n.b)return("element"===s.q||"auto"===s.q)&&A(37,[n.b,s.q]),f.i="radio"===n.b?9:10,s.ro||(f.It=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.q=null,f.name=e,"class"===t?(f.i=2,f.z=l.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,f}return"html"===n.ye?(f.i=8,f):(f.name="text"===n.ye?"textContent":n.ye,f.be=o&&!We(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}(l,f.name)&&(f.It=s.event??("select"===l.localName?"change":"input")),f)}(t,n,r,l,i));for(let e=0;e<s.length;e++)14===s[e].i&&(s[e].vo=s.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return s}var St=/\{\{([\s\S]+?)\}\}/g;function Tt(e){let t=e.data,n=[],r=0;St.lastIndex=0;for(let l=St.exec(t);null!==l;l=St.exec(t)){let i=St.lastIndex-l[0].length;i>r&&e.before(t.slice(r,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({l:s,fr:l[1].trim()}),r=St.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function Nt(e,t,n,r){let l=function(e){return{ye:"textContent",we:["textContent"],sn:[],M:[],..._(e),b:"text"}}(t);return{...gt(),l:r,i:0,o:vt(e,l.et,n),R:Ce(l.tt),z:""}}function jt(e){let t=e.getAttribute(mt());if(null===t)return null;let n=he(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?se.commentIfPrefix:null===t.o?se.commentElsePrefix:se.commentElseIfPrefix;function Ct(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:vt(e,r.et,n),R:"else"===r.b?null:Ce(r.tt)}),l=[r(t,jt(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=jt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(l.push(r(e,t)),"else"===t.b))break}return l}var Mt=new WeakSet;function Pt(t,n,r,l,i,s,o,a){let u=(n,r)=>{let i=document.createComment(r);return n.replaceWith(i),l&&e.Ln?.(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(mt()+"-ignore"))continue;if(l){if("script"===a||"style"===a||Mt.has(n))continue;if(Mt.add(n),a===se.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?jt(n):null;if(null!==f){if("for"===f.b){let e=vt(t,f.et,r),l=It(t,n,e,!0);i(u(n,se.commentForPrefix),e,l)}else"if"===f.b?s(Ct(t,n,r).map((e,n)=>({$:It(t,e.el,r,!1),o:e.o,R:e.R,E:u(e.el,Ot(n,e))}))):kt(f.b);continue}let d=n.getAttribute(mt()),p=null===d?null:xt(t,d,r,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some(At)&&!e.Ro?.(n);try{l&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!l&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t.Ht&&h.data.includes("{{")&&!Mt.has(h))for(let{l:e,fr:t}of Tt(h))a(e,t);else if(8===h.nodeType){let e=Et.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 Et=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Wt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function It(e,t,n,r){let l=document.importNode(Wt(t),!0),i=[],s=[],o=e=>i.push(e)-1;Pt(e,[...l.childNodes],n,!1,(e,t,n)=>{s.push({...gt(),l:o(e),i:6,o:t,$:n})},e=>{let t=e.map(e=>({l:o(e.E),$:e.$,o:e.o,R:e.R}));s.push({...gt(),l:t[0].l,i:7,W:t})},(e,t)=>{let n=o(e);for(let e of t)wt(e)&&A(203,[e.name]),e.l=n;s.push(...t),e.removeAttribute(mt())},(t,r)=>{s.push(Nt(e,r,n,o(t)))}),qt(l,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let r=t;r!==e;r=r.parentNode){let e=0;for(let t=r.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(l,e)),u=1===l.childNodes.length&&8!==l.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=r?n.n+1:-1;for(let e of s){if(5===e.i&&e.ot&&!e.be&&!Rt(i[e.l],l)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Dt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.W)h.add(t.l);else h.add(e.l)}let g=[...h].sort((e,t)=>e-t);return{Ot:l,root:u?l.firstChild:null,ln:a,build:g,de:d,No:p,Mn:u,ur:c,xo:[],Xe:f}}function Rt(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 Dt(e){if(null!==e.q)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.be&&null===e.It;default:return!1}}var Lt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function qt(e,t,n){for(let r=e.firstChild;null!==r;){let e=r.nextSibling;3===r.nodeType?n&&!t.has(r)&&""===r.data.trim()&&r.remove():1===r.nodeType&&qt(r,t,Lt.has(r.localName)),r=e}}var zt=new WeakMap;function Ut(e,t){let n=9===t.nodeType?t.body:t;e.root=t,zt.set(t,e),Vt(e,[...n.childNodes]),e.Ye()}function Ft(e,t,n){try{let r="template"===t.localName?jt(t):null;null!==r&&!n&&A(204,[r.b]),Vt(e,[t])}catch(e){v(e)}e.Ye()}function Vt(t,n){Pt(t,n,null,!0,(e,n,r)=>{new ht(t,r,rt(t,n,null,e),e).Tt()},e=>{ct(t,e,null,null)},(n,r)=>{e.Ln?.(t,n,r);for(let e of r)ut(t,e,n,null,null)},(n,r)=>{e.Ln?.(t,n,r),ut(t,Nt(t,r,null,0),n,null,null)})}var _t=Symbol.for("wcstack.binder"),Bt=Symbol.for("wcstack.binder.pending"),Ht=Symbol.for("wcstack.binder.taken");var Kt=new Map;function Jt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=zt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Kt.set(e,t):Ft(n,e,t?.range)}function Yt(){let e=[...Kt];Kt.clear();for(let[t,n]of e)Jt(t,n);!function(){let e=function(){let e=globalThis[_t];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[Bt];return void 0===t&&(t=[],e[Bt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),r=function(){let e=globalThis,t=e[Ht];return void 0===t&&(t=new WeakSet,e[Ht]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Gt=class{constructor(){this.name="dirty",this.ee=(e,t)=>{if(0===e.n){let t=e.G;return t!==c&&t!==f&&(e.G=f,!0)}let n=null===t?null:t.kt;if(null===n)return!1;let r=n[e.F];return r!==c&&r!==f&&(n[e.F]=f,!0)}}tr(e,t,n){null!==t.getter&&this.ee(t,n),e.Nt(t,n),e.An(t,n,this.ee)}zo(e,t){let n=t.a.o.Wt;if(null!==n)for(let r of n)r.n===t.a.n?e.ct(r,t,this.ee):e.tn(t,r,t=>e.ct(r,t,this.ee))}xe(t,n,r){this.ee(n,r),e.Ne?.(t,n,r),t.Nt(n,r),t.An(n,r,this.ee)}Yo(e,t,n){let r=0===t.n;if(!r&&null===n)return;let l=r?null:n.kt??=new Array(e.Me).fill(c),i=null===l?t.G:l[t.F];if(i!==c&&i!==f&&i!==h&&(null===l||t.F in l))return i;i=h;try{return i=e.Go(t,null===l?null:n)}finally{null===l?t.G=i:l[t.F]=i}}Jt(e){e.kt=null}nt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.G===f&&(t.G=h):e.on(t.h[t.n],e=>{let n=e.kt;null!==n&&n[t.F]===f&&(n[t.F]=h)}))}},Zt=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 en(e){let t=Xt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.U||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Xt.get(e)!==t?en(e):Promise.reject(r.errors[0]):void 0)}var tn=typeof HTMLElement>"u"?class{}:HTMLElement,nn=class extends tn{constructor(){super(),this.engine=null,this.Wn=!1,this.Ge=!1,this.z=null,this.Je=null,this.loaded=!1,this.dn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.un=e,this.Ao=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.cn=e})}static{this.getBindingsReady=en}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Wn){if(null!==this.Je)return void this.Je.Qe();Qt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!zt.has(n)&&zt.set(n,t),Yt(),e.element?.(t,"back"),this.Po("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.Wn=!0;let t=this.getRootNode(),n=e.ft?.(this,t);if(n)return this.Je=n,!n.Co&&this.parentNode instanceof ShadowRoot&&Qt(this),void(void 0===n.Mt?this.Fo():n.Mt()).then(e=>(this.loaded=!0,n.start(e,()=>this.Oo()))).then(()=>{this.cn(),this.un()},e=>this.Rt(e,n.Co));this.start(t),Qt(this)}disconnectedCallback(){if(null!==this.Je)return void this.Je._n();let t=this.engine;if(null===t)return;let n=t.root;zt.get(n)===t&&zt.delete(n),Qt(this,n),this.Po("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.Ge&&A(14),this.loaded)this.Je.reset(e);else if(null===this.engine)if(null!==this.dn){let t=this.dn;this.dn=null,t(e)}else this.z=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&A(15),"readonly"===e&&n.Le++;try{t(n.proxy)}finally{"readonly"===e&&n.Le--}}async createStateAsync(e,t){let n=this.engine;null===n&&A(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let r=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&A(8),r(...e)):r},set(){A(8)}}))}async Fo(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${w(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||A(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let r=this.querySelector('script[type="module"]');return null!==r?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let r="function"==typeof URL.createObjectURL,l=r?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Zt}`);try{return(await(import(l))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?w(42):w(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),r&&URL.revokeObjectURL(l)}}(r):null!==this.z?Promise.resolve(this.z):new Promise(e=>{this.dn=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 r=await this.Fo(),l=o(r);if(l&&await l,this.getRootNode()!==t)return this.z=r,this.Wn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=zt.get(t)?.element;i?.isConnected&&(i.U||i.Je)&&A(47);let s=new ie(r,new Gt);s.element=this,this.engine=s,e.element?.(s,"mounting"),Ut(s,t),Yt(),s.Rn(),this.Oo(),await s.Te("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.un()}catch(e){this.Ge=!this.U,this.Rt(e)}}Oo(){this.U=!0,this.cn()}Rt(e,t){this.Ye(this.U?50:49,e),this.cn(),t?this.un():this.Ao(e)}Ye(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);v(t,`[@wcstack/state] ${w(e,[this.localName,...n])}`)}Po(e,t,n){(async()=>this.engine.Te(e))().then(n,e=>this.Ye(t,e))}},rn=[];function ln(){return(rn=rn.filter(e=>e.deref())).map(e=>e.deref())}var sn,on=e=>en(e),an=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},un="en";function cn(){if(se.locale!==sn){sn=se.locale;try{un=Intl.getCanonicalLocales(sn)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[sn])}`),un="en"}}return un}var fn=["full","long","medium","short"];function hn(e,t){let[n,r,l]=(e??[]).map(e=>e||void 0);!r&&fn.includes(n)?[n,r]=[void 0,n]:!r&&!l&&/\/|^UTC$/.test(n)&&([n,l]=[void 0,n]),r&&!fn.includes(r)&&function(e,t){A(52,[e,t])}(t,r);try{l&&new Intl.DateTimeFormat(void 0,{timeZone:l})}catch{A(54,[t,l])}return[n,r,l]}var dn=e=>String(e).padStart(2,"0"),{eq:pn,ne:mn,not:gn,lt:yn,le:bn,gt:$n,ge:vn,falsy:wn,truthy:An,boolean:kn}=Ne,xn={toFixed:{factory:e=>{let t=ke(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 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=[xe(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ke(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:an(e=>{let t=xe(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:an(e=>{let t=xe(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:an(e=>{let t=xe(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=xe(e,0,"truncate"),n=e?.[1]??"…";return e=>{let r=String(e);return r.length<=t?r:r.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||A(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ke(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,ke(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,ke(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=ke(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]??be("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:an(e=>{let[t,n,r]=hn(e,"date"),l=(n||r)&&{dateStyle:n,timeZone:r};return e=>(e instanceof Date||we("date",e),e.toLocaleDateString(t??cn(),l))}),arity:[0,3]},time:{factory:an(e=>{let[t,n,r]=hn(e,"time"),l=(n||r)&&{timeStyle:n,timeZone:r};return e=>(e instanceof Date||we("time",e),e.toLocaleTimeString(t??cn(),l))}),arity:[0,3]},datetime:{factory:an(e=>{let[t,n,r]=hn(e,"datetime"),l=(n||r)&&{dateStyle:n,timeStyle:n,timeZone:r};return e=>(e instanceof Date||we("datetime",e),e.toLocaleString(t??cn(),l))}),arity:[0,3]},ymd:{factory:an(e=>{let t=e?.[0]??"-";return e=>(e instanceof Date||we("ymd",e),`${e.getFullYear()}${t}${dn(e.getMonth()+1)}${t}${dn(e.getDate())}`)}),arity:[0,1]},hms:{factory:an(e=>{let t=e?.[0]??":";return e=>(e instanceof Date||we("hms",e),`${dn(e.getHours())}${t}${dn(e.getMinutes())}${t}${dn(e.getSeconds())}`)}),arity:[0,1]},eq:pn,ne:mn,not:gn,lt:yn,le:bn,gt:$n,ge:vn,add:Te("add",(e,t)=>e+t),sub:Te("sub",(e,t)=>e-t),mul:Te("mul",(e,t)=>e*t),div:Te("div",(e,t)=>e/t),mod:Te("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=xe(e,0,"clamp"),n=xe(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:wn,truthy:An,defaults:{factory:(e,t)=>{let n=Se(e?.[0]??be("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=Se(e?.[0]??be("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:kn,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]??be("currency"),n=e?.[1],r={style:"currency",currency:t};try{new Intl.NumberFormat("en",r);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){A(53,[e])}(t)}return e=>("number"!=typeof e&&ve("currency",e),e.toLocaleString(n??cn(),r))},arity:[1,2]}},Sn=Object.fromEntries(Object.entries(xn).filter(([e])=>!(e in Ne))),Tn=!1,Nn={name:"formats",hooks:e,install:function(){Tn||(Tn=!0,ge(xn))}};function jn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let r=new Array(t.length+1),l=new Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let n=1;n<=e.length;n++){l[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;l[i]=Math.min(r[i]+1,l[i-1]+1,r[i-1]+s)}for(let e=0;e<=t.length;e++)r[e]=l[e]}return r[t.length]}function On(e,t){if(0===e.length)return"";let n=e.toLowerCase(),r=null,l=3;for(let e of t){let t=jn(n,e.toLowerCase(),2);t<l&&(r=e,l=t)}return null!==r?` Did you mean "${r}"?`:""}var Cn=" Validate statically: npx @wcstack/lint <file>.",Mn=["","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"],Pn=e=>{let t=Mn[e/100|0];return t?`[wcs/${t}] `:""},En=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Wn=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)})`,In=["","","class.","attr.","style."],Rn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Dn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Ln={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,r)=>`binding "${n?(In[r]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Dn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Dn}`,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 ${Wn(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 ${Wn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}${"string"==typeof t&&/^\d{4}-\d\d-\d\d$/.test(t)?`. A date-only string is a day, not a moment: new Date(${JSON.stringify(t)}) is midnight UTC, the day before west of Greenwich — new Date(y, m - 1, d) is that day where the page is`:""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"${/\/|^UTC$/.test(t)?` — a time zone is the third argument, after the locale and the style, and an empty argument keeps its default: ${e}(,,${t}), ${e}(en-US,long,${t})`:""}`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,54:(e,t)=>`filter ${e} takes an IANA time zone (Asia/Tokyo, America/New_York, UTC), not "${t}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&En.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)=>`${Rn(e,t)} failed to initialize.`,50:(e,...t)=>`${Rn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Rn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,r)=>`${e}("${t}") takes ${n} index(es), got ${r}.`,902:(e,t,n,r)=>`${e}("${t}") takes at most ${n} index(es), got ${r}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function qn(e,t){let n=Ln[e];return void 0===n?`${Pn(e)}#${e} ${t.join(" ")}`:Pn(e)+n(...t)}var zn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Un=[[/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.']],Fn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Vn(e,t,n){let r=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(Fn,e)?Fn[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 Un){let l=t.exec(e);null!==l&&(r+=n.replace(/\$(\d)/g,(e,t)=>l[Number(t)]))}let l=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==l&&(r+=` — write "${l[1]}#${l[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?r+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':de.some(ye)||(r+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&zn.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=Cn),r}var _n=new WeakMap,Bn=new WeakMap,Hn=new WeakSet,Kn=new WeakSet;function Jn(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 Yn(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 Gn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let r=t=>null===t?null:function(e,t){let n=t.t.split("."),r=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return r<0||n.indexOf("*",r)>=0||void 0!==Jn(e.target,t.t)?.get?t:e.O.vt(m(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:Zn(e,n,0,e.target,r)}function Zn(e,t,n,r,l){for(;n<t.length;n++){let i=t[n];if(null===r||"object"!=typeof r)return null;if("*"===i.s){if(!Array.isArray(r)||0===r.length)return null;let i=null;for(let s of r){let r=Zn(e,t,n+1,s,l);if(null===r)return null;if(null===i)i=r;else if(r.seg===i.seg)for(let e of r.names)i.names.includes(e)||i.names.push(e)}return i}if(Array.isArray(r)&&/^\d+$/.test(i.s)){if(Number(i.s)>=r.length)return null;r=r[Number(i.s)];continue}let s=Jn(r,i.s);if(void 0===s&&null===i.c&&e.nt.has(i.s))return null;if(void 0===s){let s=Yn(r),o=l(i.c);for(let t of e.O.all())t.c===o&&null!==t.getter&&s.push(t.s);return n>0&&0===s.length?null:{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;r=s.value}return null}function Xn(t){Hn.has(t)||(Hn.add(t),setTimeout(()=>function(t){Hn.delete(t);let n=_n.get(t);if(void 0===n)return;let r=Bn.get(t);void 0===r&&Bn.set(t,r=new Set);let l=new Map(n),i=new Map;for(let e of t.O.all()){let t=null===e.c||r.has(e)||n.has(e)?void 0:e._.find(e=>!e.gn);void 0!==t&&(i.set(e,t),l.set(e,3))}for(let[n,s]of l){if(r.has(n))continue;r.add(n);let l=Gn(t,n);if(null===l)continue;let o=lr.get(t),a=n.c;for(;null!==a&&!o?.has(a);)a=a.c;if(null!==a)continue;let u=[...t.root?.querySelectorAll(`${se.tagNames.state}[mount]`)??[]].find(e=>!Kn.has(e)&&(n.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==u){r.delete(n),u.initializePromise.then(()=>{Kn.add(u),Xn(t)});continue}let c=t.O.vt(m(n.t).o),f="";if(void 0!==c&&c!==n&&null!==c.getter){let e=c.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(c.h[t].t.length+2)}`);f=` The getter "${c.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let h=On(l.seg,l.names);if((l.r||3===s)&&""===h&&""===f)continue;let[d,p,g]=1===s?["watch-path-missing","$watch path","watch"]:2===s?["post-update-path-missing","$postUpdate path","postUpdate"]:3===s?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];e.ut?.(t,{type:"state:path-unresolved",source:g,path:n.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${d}] ${p} "${n.t}"${3===s?` read by the getter "${i.get(n).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${h}${f} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${Cn}`)}}(t),0))}function Qn(e,t,n=!1){er(e,t,n?1:0)}function er(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let r=_n.get(e);void 0===r&&_n.set(e,r=new Map),r.has(t)||r.set(t,n),Xn(e)}var tr=new WeakSet,nr=!1,rr=new WeakMap,lr=new WeakMap;function ir(e,t,n,r,l,i,s){if(!s)return;let o=lr.get(e);void 0===o&&lr.set(e,o=new Set),o.add(t)}function sr(e,t){let n=rr.get(e),r=t.s;if(null!==t.c||nr||void 0===n||n.has(r)||"$"===r[0]||e.nt.has(r))return;let l=On(r,[...n]);n.add(r),""!==l&&![...e.root?.querySelectorAll(`${se.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${r}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${r}" is not declared: writing it creates a new key.${l}${Cn}`)}var or=new WeakSet;function ar(e){if(or.has(e))return;or.add(e);let t=e.emit,n=!1;e.emit=(...r)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${Cn}`)),t.apply(e,r))}var ur=new WeakMap;function cr(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Jn(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let l=ur.get(e);void 0===l&&ur.set(e,l=new Set),!l.has(t)&&(l.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(…).${Cn}`))}var fr=new WeakSet,hr=/\bthis\s*[.[]|=\s*this\b/,dr=new WeakSet,pr=e=>{for(let t of["src","state","json"])if(e.hasAttribute(t))return`<${e.localName} ${t}${"json"===t?"":`="${e.getAttribute(t)}"`}>`;return`<${e.localName}>`};function mr(e,t){let n=e.element;if("mounting"!==t||!n)return;let r=n.getRootNode();if(dr.has(r))return;let l=[...r.querySelectorAll(se.tagNames.state)].filter(e=>e!==n&&!e.hasAttribute("mount")&&!e.hasAttribute("bind-component"));0!==l.length&&(dr.add(r),console.warn(`[@wcstack/state] [wcs/second-root] ${l.length+1} root <wcs-state> elements share one root, and there is one state tree per root: ${pr(n)} takes it — its state was ready first, whatever the order in the document — and ${l.map(pr).join(", ")} is refused (#47). Keep one, and graft the others with <wcs-state mount="path">.${Cn}`))}var gr=new Set,yr=new WeakSet,br=/^(?:(?:attr|class|style)\.|(?:html|innerHTML|outerHTML|srcdoc)$)/;function $r(e){try{return null!==e&&he(e).some(e=>"spread"===e.b||"eventToken"===e.we[0]||"prop"===e.b&&!br.test(e.ye))}catch{return!1}}function vr(e,t){for(let n of e.No){null!==n.$&&vr(n.$,t);for(let e of n.W??[])vr(e.$,t);if(n.be&&5!==n.i){let r=e.Ot;for(let t of e.ln[n.l])r=r.childNodes[t];t.add(r.localName)}}}function wr(e,t){if("connected"!==t||yr.has(e)||document.documentElement.hasAttribute("data-wcs-server"))return;yr.add(e);let n=new WeakRef(e),r=()=>{setTimeout(()=>{let e=n.deref();e?.element?.isConnected&&function(e){let t=new Set;for(let n of e.H.values())for(let e of[n.S,...n.j??[]])null!==e&&vr(e.$,t);for(let n of e.ie.values())for(let e of n)for(let n of e.I?.W??[])vr(n.$,t);let n=se.bindAttributeName;for(let r of e.root.querySelectorAll("*")){let e=r.localName;!e.includes("-")||gr.has(e)||void 0!==(r.customElementRegistry??customElements).get(e)||!t.has(e)&&!$r(r.getAttribute(n))||null!==r.closest(`[${n}-ignore]`)||(gr.add(e),console.warn(`[@wcstack/state] [wcs/element-undefined] <${e}> is not defined 5 s after the page was ready; its bindings wait for it (property bindings, textContent: included, spreads, commands, event tokens — attr.*, class.*, style.* and on*: apply at once). Load the ${e.startsWith("wcs-")?"wcstack package that defines it (its /auto)":"script that defines it"}.`))}}(e)},5e3)};"complete"===document.readyState?r():addEventListener("load",r,{once:!0})}var Ar=new WeakSet;function kr(e,t){let n,r=t.o;if(!(Ar.has(r)||t.d.length>0)){try{n=e.v(r,t.oe)}catch{return}null==n||Array.isArray(n)||queueMicrotask(()=>{null===t.S||Ar.has(r)||(Ar.add(r),console.warn(`[@wcstack/state] [wcs/binding-type-expectation] "for: ${r.t}" needs an array, not ${Wn(n)}: it renders no rows (null and undefined render none on purpose).${Cn}`))})}}function xr(e){_n.has(e)&&e.Ue.length>0&&Xn(e);for(let t of e.H.values())null!==t.S&&null!==t.T&&kr(e,t)}var Sr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Tr=!1;function Nr(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(Tr||!(t instanceof TypeError)||!We(r)||!("trustedTypes"in globalThis))return;Tr=!0;let l="function"==typeof Pe()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${r}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${l}\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.l,property:r})}var jr=new WeakMap;function Or(e,t,n){let r=e[t],l=void 0===n?void 0===r?null:`the event carried no detail (undefined) while element.${t} is ${typeof r}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==r&&"object"==typeof r?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof r}`;if(null===l)return;let i=jr.get(e);void 0===i&&jr.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${l}. 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 Cr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],Mr={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},Pr={name:"diagnostics",hooks:e,install(){e.Vo=Vn,e.Ho=qn,e.To=Qn,e.detail=Or,e.Ge=t(e.Ge,Nr);let r=e.pe;e.pe=(e,t)=>{(function(e){void 0!==e.$scan&&A(1);for(let[t,n]of Cr)void 0!==e[t]&&A(1601,[t,n])})(t),r?.(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[r,l]=n[0];if(!r.endsWith(".*")||!l.endsWith(".*"))return;let i=r.slice(0,-2),s=l.slice(0,-2),o=`.${l}`,a=`${i}.**`,u=Yn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>$(`[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(`^(?:${Sr(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 "${l}"). Rename one of them.`);let t=new RegExp(`^${Sr(r)}(?:${Sr(o)})*${Sr(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){let t=Jn(e,"$on")?.value;if(null!==t&&"object"==typeof t)for(let e of Object.keys(t)){let n=t[e];"function"!=typeof n||fr.has(n)||!hr.test(String(n))||(fr.add(n),console.warn(`[@wcstack/state] [wcs/on-handler-this] The $on handler "${e}" uses this. A $on handler is called as ${e}(state, event): this is undefined there, so it throws when the event arrives — write ${e}(state, event) { state.x = … }.${Cn}`))}}(t),function(e){Bn.delete(e),_n.has(e)&&Xn(e)}(e),function(e){if(tr.has(e))return;tr.add(e);let t=e.Jn,n=t.$postUpdate;t.$postUpdate=t=>{nr=!0;try{n(t)}finally{nr=!1}let r=e.O.vt(m(t).o);void 0!==r&&er(e,r,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))ar(t)}})}(e),rr.set(e,new Set(Yn(t)))},e.handlerThrew=cr,e.element=t(t(e.element,mr),wr),e.se=t(t(e.se,sr),ir),e.he=t(e.he,xr),e.st=t(e.st,kr),e.it=n(l,e.it,(e,t)=>Object.hasOwn(Mr,t)?A(1701,[t,Mr[t]]):void 0)}},Er={},Wr=/\.\d/,Ir=new Set(Object.getOwnPropertyNames(Object.prototype)),Rr=0,Dr=!1,Lr=null,qr=()=>{Dr=!1,Rr++};function zr(){if(null===Lr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=qr,e.port1.unref?.(),Lr=()=>e.port2.postMessage(0)}else Lr=()=>setTimeout(qr,0);return Dr||(Dr=!0,Lr()),Rr}function Ur(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of e.Z){for(let r of t)if(n.te(r)&&(n.n===r.n||!(r.n<e.n&&e.h[r.n+1].te(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var Fr=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Do=-1,this.Bn=new Set,this.qe=null,this.engine=e,this.De=t}pr(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.De)t.getter=null!==t.p.getter||t.p.ue,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(Er,e.v(t.p,null)):this.Vn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[r,l,i,s]of t)if((null===l||l.w)&&Object.is(e.v(r,l),s)){n.add(r);for(let e of this.De)e.p===r&&this.pt(e,l,i,!0)}for(let e of this.De)e.getter&&0===e.p.n&&!this.Fe.has(e)&&Ur(Vr(e.p),n)&&this.pt(e,null,void 0,!0);this.Fe.size>0&&e.$e()}prime(t,n){try{n()}catch(n){v(n,`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`),e.ut?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}jo(){this.active=!1,this.Fe.clear(),this.early=[]}Vn(e,t,n,r){let l=this.engine.Ke(n,e.h[t]);for(let n of l.d)t===e.n?r(n):this.Vn(e,t+1,n,r)}pt(e,t,n,r){let l=this.Fe.get(e);void 0===l&&this.Fe.set(e,l=new Map);let i=l.get(t);void 0===i?l.set(t,[n,this.n,r]):(i[1]<this.n&&(i[1]=this.n),i[2]||=r)}se(e,t,n,r,l,i){if(this.active){(this.qe??=new Set).add(e);for(let i of this.De){let s=i.p;s.n!==e.n||!s.te(e)||this.pt(i,t,i.getter?i.s.get(t??Er):s===e&&l&&this.engine.Ut&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else i&&this.early.push([e,t,n,r])}Ne(e,t){if(this.active)for(let n of this.De)(n.getter||=null!==n.p.getter||n.p.ue)&&n.p.n===e.n&&n.p.te(e)&&this.pt(n,t,n.s.get(t??Er),!1)}st(e,t){if(!this.active)return;let n=null;for(let r of this.De){let l=r.p;if(!(l.n<e.n||l.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.d)n.has(t)||(l.n===e.n?this.pt(r,t,void 0,!0):this.Vn(l,e.n+1,t,e=>this.pt(r,e,void 0,!0)))}}}he(){let t=this.qe;if(this.qe=null,!this.active||0===this.Fe.size)return;let n=this.Fe;this.Fe=new Map;let r=this.engine,l=[];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)=>_r(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=r.f;this.n=u+1,r.Oe++;try{if(a=r.v(i.p,n),i.getter&&(i.s.set(n??Er,a),Object.is(a,s)&&(Wr.test(i.t)||null!==n&&!c&&!(o??=null!==t&&Ur(Vr(i.p),t)))))continue;if(u>32){l.includes(i.t)||l.push(i.t);continue}r.f=n,e.ut?.(r,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(r.proxy,a,s,...r.K(n))}catch(t){v(t,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),e.ut?.(r,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{r.f=h,this.n=0,r.Oe--}}}l.length>0&&this.Mo(l)}Mo(t){let n=zr();n!==this.Do&&(this.Do=n,this.Bn.clear());let r=t.filter(e=>!this.Bn.has(e));if(0!==r.length){for(let e of r)this.Bn.add(e);v("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.ut?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:r})}}};function Vr(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function _r(e,t){let n=[],r=[];for(let t=e;null!==t;t=t.a.oe)n.unshift(t.y);for(let e=t;null!==e;e=e.a.oe)r.unshift(e.y);for(let e=0;e<n.length&&e<r.length;e++)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}var Br="$streamStatus",Hr="$streamError",Kr=new Set(Object.getOwnPropertyNames(Object.prototype)),Jr=!1;function Yr(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 Gr=class{constructor(e,t,n){this.engine=e,this.entries=t,this.B=n}set(e,t,n){Jr=!0;try{this.engine.C(this.engine.o(`${e}.${t}`),null,n)}finally{Jr=!1}}mr(){for(let e of this.entries)this.start(e,!0)}hr(){for(let e of this.entries)e.mt=!1,e.Q?.abort(),e.Q=null}gr(){for(let e of this.entries)e.mt=!1,null!==e.Q&&(e.Q.abort(),e.Q=null),this.set(Br,e.name,"idle")}Ne(e){let t=this.B.n;for(let n of this.entries)n.g===e&&(n.n=n.mt?Math.max(n.n,t):t,n.mt=!0)}he(){let e=this.engine,t=this.B,n=[];for(let r of this.entries){if(!r.mt)continue;let l=r.n;if(r.mt=!1,l>32)n.push(r.name),r.g.G=h;else{t.n=l+1,e.Oe++;try{this.start(r,!1)}finally{e.Oe--,t.n=0}}}n.length>0&&t.Mo(n)}start(e,t){let n,r=this.engine;if(null!==e.Q&&e.Q.abort(),e.Q=null,null!==e.g){let l=e.g;l.getter=e.args;let i=l.Z.slice();Zr(l);try{n=r.read(l,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&$(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Z)n.n>0&&$(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Br}.${e}`||n.t===`${Hr}.${e}`)&&$(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,l,n)}catch(n){Zr(l);for(let e of i)e.Hn(l);if(l.G=h,t)throw n;return this.set(Hr,e.name,n),void this.set(Br,e.name,"error")}}let l=new AbortController;e.Q=l,r.C(r.o(e.name),null,e.z),this.set(Hr,e.name,null),this.set(Br,e.name,"active"),this.yr(e,l,n)}async yr(e,t,n){let r=this.engine,l=t.signal,i=()=>!l.aborted&&e.Q===t,s=r.o(e.name),o=this.B.n,a=zr(),u=e=>{zr()===a&&(this.B.n=o);try{e()}finally{this.B.n=0}},c=e.z;try{let t=await e.source(n,l);if(!i())return;let o=t=>{c=void 0!==e.Lo?e.Lo(c,t):t,u(()=>r.C(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(l.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(l.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.Q=null,u(()=>this.set(Br,e.name,"done"))}catch(n){if(!i())return;e.Q=null,t.abort(),u(()=>{this.set(Hr,e.name,n),this.set(Br,e.name,"error")})}}};function Zr(e){for(let t of e.Z){let n=t._.indexOf(e);n>=0&&t._.splice(n,1),t.wt.delete(e)}e.Z.length=0,e.G=c}var Xr=new WeakMap;function Qr(e){let t=Xr.get(e);return t?.target===e.target?t:void 0}function el(t,n){let r=new Fr(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&$("$watch must be an object mapping paths to handler functions.");let r=[];for(let l of Object.keys(n)){let i=n[l];(""===l||"$"===l[0]||l.includes("@")||Ir.has(l))&&$(`$watch path "${l}" is not a path of the state tree.`),"function"!=typeof i&&$(`$watch entry "${l}" must be a function.`);let s=t.o(l);e.To?.(t,s,!0),r.push({t:l,p:s,handler:i,getter:!1,s:new WeakMap})}return r}(t,n.$watch)),l=new Gr(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&$("$stream must be an object mapping stream names to definitions.");let r=[],l={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||Kr.has(s))&&$(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&$(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&$(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&$(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&$(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&$(`$stream entry "${s}": args must be a function.`),Yr(t,s)&&$(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),l[s]="idle",i[s]=null,r.push({name:s,source:a,Lo:u,z:f,Q:null,mt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[Br]=l,t[Hr]=i,r}(t,n),r),i=Xr.get(t);void 0!==i&&(i.B.jo(),i.jt.hr()),Xr.set(t,{B:r,jt:l,Qe:i?.Qe??!1,target:n})}function tl(e,t){let n=Xr.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Qe="connected"===t),n.target===e.target)){if("disconnected"===t)return n.B.jo(),void n.jt.gr();n.Qe&&(n.B.pr(),n.jt.mr())}}var nl=["$streamStatus","$streamError"],rl={name:"temporal",hooks:e,install(){e.pe=t(e.pe,el),e.element=t(e.element,tl),e.se=t(e.se,(e,t,n,r,l,i,s)=>Qr(e)?.B.se(t,n,r,l,i,s)),e.Ne=t(e.Ne,(e,t,n)=>{let r=Qr(e);void 0!==r&&(r.B.Ne(t,n),r.jt.Ne(t))}),e.st=t(e.st,(e,t,n)=>Qr(e)?.B.st(t,n)),e.he=t(e.he,e=>{let t=Qr(e);void 0!==t&&(t.B.he(),t.jt.he())}),e.it=n(l,e.it,(e,t)=>{let n=t.split(".",1)[0];if(nl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Ie=n(r,e.Ie,(e,t)=>(!Jr&&36===t.t.charCodeAt(0)&&nl.includes(t.t.split(".",1)[0])&&$(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},ll=new WeakMap,il=!1,sl=/^(?!prototype$)[^\d.*$][^.*]*$/;function ol(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&$("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let l=n[t];"string"==typeof l?r.set(e.o(t),e=>e[l]):"function"==typeof l?r.set(e.o(t),l):$(`$listKeys "${t}" must be a field name or a function.`)}}ll.set(t,r)}function al(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function ul(e,t,n){let r=new Map;for(let l of t){al(l)||$(`$listKeys "${e}": rows must be plain objects.`);let t=n(l);null==t&&$(`$listKeys "${e}": a row has no key.`),r.has(t)&&$(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,l)}return r}function cl(e,t,n,r){if(il||!Array.isArray(r))return!1;let l=ll.get(e.target)?.get(t);if(void 0===l)return!1;let i=e.at(t,n);if(!Array.isArray(i)||i===r)return!1;let s=ul(t.t,i,l);ul(t.t,r,l);let o=[],a=[],u=i.length===r.length;for(let e=0;e<r.length;e++){let t=r[e],n=s.get(l(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 r of Object.keys(n))Object.is(t[r],n[r])||c.push([e,r,n[r]]);for(let r of Object.keys(t))!(r in n)&&null!==t[r]&&c.push([e,r,null])}if(u&&0===c.length)return!0;if(!u){il=!0;try{e.C(t,n,o)}finally{il=!1}}if(c.length>0){let r=e.Ke(0===t.n?null:n,t);for(let[n,l,i]of c){if("__proto__"===l)continue;let s=r.d[n],o=sl.test(l)?e.o(`${t.t}.*.${l}`):null;null===o?.getter?e.C(o,s,i):(s.N[l]=i,e.C(e.o(`${t.t}.*`),s,s.N,!0))}}return!0}var fl={name:"list-keys",hooks:e,install(){e.pe=t(e.pe,ol),e.Ie=n(r,e.Ie,cl)}},hl=new WeakMap,dl=new WeakMap,pl="will not graft: the root state failed to initialize.",ml=new WeakSet,gl=new WeakMap,yl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],bl=["$commandTokens","$eventTokens","$on","$errorCallback"],$l=e=>`[@wcstack/state] <${se.tagNames.state} mount="${e}">`,vl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),wl=e=>e?.element?.isConnected?e:void 0;function Al(e){let t=dl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function kl(e,t){let n=dl.get(t);if(dl.delete(t),Array.isArray(n))for(let t of n)Nl(t,e)}function xl(e){let t=hl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function Sl(e,t){v(`${$l(e.t)} ${t}`),xl(e),e.Ze?.(),e.Ze=null}function Tl(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,v)}catch(e){v(e)}}function Nl(e,t){if(ml.has(t))return Sl(e,"will not graft: its component is wired to its host.");let n=e.state,r=t.target,l=e.t.split("."),i=r;for(let e of l)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return Sl(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,r){if("symbol"==typeof r)return;if(36!==r.charCodeAt(0))return e.proxy[n(r)];let l=e.proxy[r];return"$eqPath"===r?(e,t)=>l(n(e),n(t)):vl.has(r)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,r,l)=>"symbol"!=typeof r&&(e.proxy[n(r)]=l,!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:r,set:l,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==r||void 0!==l)a[`${e.t}.${n}`]={get:r&&function(){return r.call(s)},set:l&&function(e){l.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<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.at(n,null)&&t.C(n,null,{})}t.C(t.o(e.t),null,o)}t.io(Object.defineProperties({},a));for(let e in a)t.qe(t.o(e),null);e.engine=t;let c=gl.get(t);void 0===c&&gl.set(t,c=[]),c.push(e),e.el.isConnected&&Tl(e,"$connectedCallback"),e.Ze?.(),e.Ze=null}function jl(e,t){let n=dl.get(e);if(Array.isArray(n))for(let e of n)Sl(e,pl);dl.set(e,t)}var Ol=new WeakMap;function Cl(e,t){let n=e.getAttribute("mount");if(null===n)return null;let r={el:e,root:t,t:n,state:null,engine:null,chroot:null,Ze:null},l=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(se.bindAttributeName))l='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=hl.get(t);void 0===e&&hl.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==r&&(null===i.engine?i.el.isConnected:wl(i.engine)))l=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=dl.get(t);Array.isArray(e)&&dl.set(t,e.filter(e=>e!==i)),i.Ze?.(),i.Ze=null}e.set(n,r)}}else l='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Co:!0,start(e){if(null!==l)return Sl(r,l);if(hl.get(t).get(n)===r){for(let t of yl)if(void 0!==e[t])return Sl(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of bl)void 0!==e[t]&&console.warn(`${$l(n)} ${t} is not run in a volume (it belongs to the root).`);return r.state=e,new Promise(e=>{r.Ze=e;let n=wl(zt.get(t)),l=dl.get(t);void 0!==n?Nl(r,n):Al(t)?Sl(r,pl):dl.set(t,[...Array.isArray(l)?l:[],r])})}},Qe(){null!==r.engine&&Tl(r,"$connectedCallback")},_n(){null!==r.engine&&Tl(r,"$disconnectedCallback")},reset(){$(`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 Ml=new WeakMap,Pl=new WeakMap;function El(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||$(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&$(`${t} entries must be non-empty strings.`),"$"===e[0]&&$(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&$(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function Wl(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let r=document.createDocumentFragment();for(let e of[...t.childNodes])r.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&$("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||$(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&$(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(r),i=El(r,"$bindables"),s=El(r,"$commands");for(let e of i){let t=l.get(e);void 0===t&&$(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&$(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of s){let t=l.get(e);void 0===t&&$(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&$(`$commands entry "${e}" is not a method: list it in $bindables.`)}let o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=r=>{if(a.has(r))return a.get(r);if(r.hasAttribute("data-wc-definition"))return null;let l=r.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let s=l.querySelector(se.tagNames.state);return a.set(r,s),Ml.set(r,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${se.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,r]of t)n.proxy[e]=r});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 l)"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,r,l,t)},Qe(){},_n(){},reset(){$("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Il=new WeakMap,Rl=new WeakSet,Dl=new WeakMap,Ll=new WeakMap,ql="data-wcs-wired",zl=new WeakMap,Ul=new WeakMap,Fl=new WeakMap,Vl=0,_l=new Set,Bl={},Hl=["$watch","$stream","$renderedCallback"],Kl=e=>e.split(".",1)[0];function Jl(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Yl(e,t){let n=e.l,r=Kl(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(ql);else if(!Zl(n,r)){let e=n.getAttribute(ql)?.split(" ")??[];e.includes(r)||n.setAttribute(ql,[...e,r].join(" "))}zl.get(n)?.ve===r&&$(`<${n.localName}>.${r} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=Il.get(n);void 0===l&&Il.set(n,l=[]),l.push(e),t&&Rl.add(e);let i=Dl.get(n);return void 0===i&&Dl.set(n,i=new Map),i.has(r)||i.set(r,n[r]),Ll.get(n)?.(),!1}function Gl(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${se.tagNames.state}[bind-component]`)}function Zl(e,t){let n=e.getAttribute(se.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Xl(e){let t=e.parentElement;for(;null!==t&&!Gl(t);)t=t.parentElement;let n=zt.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.U:null===t)&&(null===t?Jt(e):Ft(n,e))}var Ql=new Set;function ei(e,t){Ql.has(e)||(Ql.add(e),console.warn(`[@wcstack/state] ${t}`))}var ti=(e,t)=>t in e.state;function ni(e,t){let n=ri(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function ri(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 li(e,t,n){if(null!==n.getter)return;let r,l=e.host,i=l.engine,s=Kl(n.t),o=l.entries.find(e=>e.x===n.t);if(void 0===o&&null!==n.c)return function(e,t){let n,r=t.c;for(;null!==r&&void 0===(n=e.ht.get(r));)r=r.c;if(null===r||void 0===n)return;let l=e.A,i=e.host.engine,s=i.o(n.p.t+t.t.slice(r.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=ii(e,o.r);return 0===t.n?n:(i.resolve(Jl(s.t,[...i.K(n),...l.K(re(l.f,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.ce&&(t.ce=n=>{let r=a();si(e,o.e,()=>i.C(s,r,n)),e.fn=t}),t.n>0&&(t.F=l.Me++),e.ht.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.x!==s?ti(l,s):ni(l,s))return;r=o.ke}else{if(null===t||null!==n.c||"$"===s[0]||ti(l,s))return;o=t,r=i.o(`${t.ke.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(r,ii(e,a)),n.ce=t=>{si(e,u,()=>i.C(r,a,t)),e.fn=n},e.ht.set(n,{e:o,p:r,r:a})}function ii(e,t){return null!==t&&!t.w&&$(`The host row of <${e.host.el.localName}> was removed.`),t}function si(e,t,n){let r=_l.has(e.A);_l.add(e.A),e.from=t;try{n()}finally{r||_l.delete(e.A),e.from=null}}var oi=(e,t)=>t||!_l.has(e.m.A)||null!==e.m.from&&e.m.from!==e.e;function ai(e,t){if(e.pn===t||null===e.host.engine)return;e.pn=t,Vl+=t?1:-1;let n=e.host.engine,r=Fl.get(n);void 0===r&&Fl.set(n,r=new Map);for(let n of e.me){let e=r.get(n.e.ke);void 0===e&&r.set(n.e.ke,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.x);if(void 0!==l){null===e.ae&&function(e,t){let n=e.host,r=n.engine;e.ae=new Map;let l=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(l.has(s))continue;l.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=Kl(s);if(s!==a&&!ti(n,a))continue;let u=r.o(`${t.ke.t}.${s}`);if(null===u.getter)fi(r,u,t.ke);else if(!ui.has(u.getter))continue;e.ae.set(u,e.A.o(s))}}(e,l);for(let r of e.ae.keys())t&&null===r.getter&&fi(n,r,l.ke),n.P.xe(n,r,l.r);e.ae.size>0&&n.$e(),t&&function(e,t){let n=e.host.engine;for(let[r,l]of e.ae){let i=n.v(r.c,t.r);if(null===i||"object"!=typeof i||!(r.s in i))continue;let s=e.host.el.localName;ei(`${s}|${r.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.ve}.${l.t} is exported at "${r.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var ui=new WeakSet;function ci(e,t,n,r){let l=Fl.get(e)?.get(t)?.get(n);if(void 0===l)return null;let i=null;for(let e of l)""!==e.e.x||!0!==e.m.ae?.has(r)||e.m===i||(null!==i&&$(`[wcs/mount-export-ambiguous] "${r.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 fi(e,t,n){let r=t.c,l=t.s,i=()=>{let t=e.read(r,e.f);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let r=i();if(null!==r)return r[l];let s=ci(e,n,e.f,t);return null===s?void 0:s.A.read(s.ae.get(t),null)},ui.add(t.getter),t.ce=s=>{let o=null===i()?ci(e,n,e.f,t):null;if(null===o){let t=e.read(r,e.f);return void(null!==t&&"object"==typeof t&&(t[l]=s))}let a=o.ae.get(t);void 0===ri(o.host.state,a.t)?.set&&$(`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.A.C(a,null,s)},t.n>0&&(t.F=e.Me++)}function hi(t,n,r,l,i,s){if(null!==n.getter)return t.P.xe(t,n,r),void t.$e();if("*"===n.s){if(null===r)return;if(r.N=r.a.T[r.y],t.P.Jt(r),null!==r.u)for(let e of r.u.values())t.J(e)}else t.Tn(n,r);e.se?.(t,n,r,l,i,s),t.qe(n,r)}function di(e){let t=e.m.A;for(let[n,r]of e.m.ht)r.e===e.e&&(0===n.n?t.P.xe(t,n,null):t.on(n.h[n.n],e=>t.P.xe(t,n,e)));t.$e()}function pi(e,t,n,r,l,i,s){let o=n.t.slice(t.t.length);if(""===o)return di(e);let a,u=e.m,c=u.A;if(""===e.e.x){a=o.slice(1);let e=Kl(a);if("$"===e[0]||ti(u.host,e)||u.host.entries.some(e=>""!==e.x&&(a===e.x||a.startsWith(`${e.x}.`))))return}else a=e.e.x+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(re(r,e).y);c.resolve(Jl(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||hi(c,h,d,l,i,s)}function mi(e,t,n,r,l,i,s){if(0===Vl)return;let o=_l.has(e);_l.add(e);try{let o=Ul.get(e);!s&&void 0!==o&&o.pn&&!_l.has(o.host.engine)&&function(e,t,n,r,l,i){let s,o=t;for(;null!==o&&void 0===(s=e.ht.get(o));)o=o.c;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.fn===t)return void(e.fn=null);if(null!==s.r&&!s.r.w)return;let u=[...a.K(s.r),...e.A.K(n)];a.resolve(Jl(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||si(e,s.e,()=>hi(a,c,f,r,l,i))}(o,t,n,r,l,i),s&&void 0!==o&&o.pn&&null!==o.ae&&function(e,t){let n=e.host.entries.find(e=>""===e.x),r=e.host.engine;for(let[l,i]of e.ae)i===t&&(r.P.xe(r,l,n.r),r.$e())}(o,t);let a=Fl.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.te(e)){let a=o.get(0===e.n?null:re(n,e.n));if(void 0!==a)for(let o of[...a])oi(o,s)&&pi(o,e,t,n,r,l,i)}else if(e.te(t))for(let[e,r]of[...o])if(0===t.n||re(e,t.n)===n)for(let e of[...r])oi(e,s)&&di(e)}finally{o||_l.delete(e)}}async function gi(t,n,r,l,i){if(l===Bl)return;let s=o(l);s&&await s;let a=zl.get(n);a.engine&&l.$recursion&&$(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.D;if(null!==u&&u.el!==t&&u.el.isConnected&&$(`<${n.localName}> already has a connected <${se.tagNames.state} bind-component="${a.ve}">.`),null!==u&&ai(u,!1),null!==u&&function(e,t,n){let r=e.A,l=`[${se.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),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.jn(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of r.ie.values())for(let t of e)if(null===t.I)o(t.l);else for(let e of t.I.W)a(t.I,e.E);for(let e of r.H.values())for(let t of[e.S,...e.j??[]])null!==t&&a(t,t.E);for(let t of e.L)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.L.includes(n)&&(i(n)||r.Ht&&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,r))return async function(e,t,n,r){e.el.engine=null,e.el=t,e.A.element=t,t.engine=e.A,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await yi(e,r):r()}(u,t,r,i);let c=new ie(l,new Gt);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 r=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof r&&"constructor"!==t&&n.set(r,null)}let r=(t,n,r)=>Reflect.apply(t,e.proxy,r);e.U=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:r})),t}}(c,l);let f={el:t,L:[],A:c,host:a,me:[],ht:new Map,pn:!1,fn:null,from:null,ae:null};for(let e of a.entries)f.me.push({m:f,e});a.D=f,Ul.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.A,n=e.host,r=n.engine,l=n.el.localName,i=n.entries.find(e=>""===e.x)??null;for(let e of n.entries){if(""===e.x)continue;let t=Kl(e.x);ti(n,t)&&(e.x!==t||ni(n,t))&&ei(`${l}.${e.x}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.ve}.${e.x}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=r.v(i.ke,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.x===t)&&ei(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${i.ke.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=Hl.filter(e=>void 0!==n.state[e]);s.length>0&&ei(`${l}.${n.ve}$`,`[wcs/mount-dollar-declaration] <${l}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.rt;t.rt=n=>{li(e,i,n),o.call(t,n)};let a=[...t.O.all()];for(let t of a)li(e,i,t);for(let e of a)o.call(t,e);let u=t.xt;t.xt=()=>{(function(e){for(;void 0!==e;e=Ul.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),ai(f,!0),ml.add(c),kl(c,r));let d=e.wr?.(r,c);Ut(c,r),d?.(),f.L=[...r.childNodes],Yt(),h&&c.Rn(),Object.defineProperty(n,a.ve,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.ve);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,v)}catch(e){v(e)}i(),t.isConnected?(await c.Te("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):ai(f,!1)}async function yi(t,n){ai(t,!0);for(let e of t.me)di(e);n?.(),!t.broken&&(await t.A.Te("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.A,"connected"))}function bi(t,n){let r=t.getAttribute("bind-component");if(null===r)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=zt.get(t)?.element;if(!(e.U||void 0!==n&&n!==e&&n.isConnected)){jl(t,e);for(let e of Ol.get(t)??[])e()}}),null}(t,n);let l=t.parentNode,i=l instanceof ShadowRoot,s=i?l.host:l instanceof Element?l:null,o=()=>{let e=null===s?void 0:zl.get(s)?.D;return e?.el===t?e:null},a=e=>{throw i&&jl(l,t),e},u=!1;return{Mt:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,r){let l=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&$(`<${se.tagNames.state} bind-component> takes its state from <${l}>.${t}: it cannot also load one (state / src / json / an inline script).`),await ze(n).whenDefined(l);let i=zl.get(n);if(void 0!==i)return i.ve!==t&&$(`<${l}> already has a <${se.tagNames.state} bind-component="${i.ve}">.`),i.state;let s=()=>(Il.get(n)??[]).filter(e=>Kl(e.name)===t),o=Zl(n,t);if(o&&0===s().length&&Xl(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(ql)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,i)=>{Ll.set(n,r),e=function(e,t){Al(e)&&t();let n=Ol.get(e)??new Set;return Ol.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${l}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Ll.delete(n);let a=s(),u=Dl.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&$(`"bind-component": <${l}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&r){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${l}>, or mount it from the host (${se.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Bl}let f=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.x===r)&&$(`<${l}> maps "${e.name}" twice.`);let i=r.split(".").indexOf("*");if(i>=0){let n=r.split(".").slice(0,i).join(".");$(`<${l}> 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({x:r,ke:e.o,r:e.r,ro:Rl.has(e)}),e.engine.Pn(e),""!==r&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return zl.set(n,i={el:n,ve:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,D:null}),h}(t,r,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${se.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await gi(t,s,i?l:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Qe(){let e=o();null!==e?yi(e).catch(v):u?Promise.resolve().then(()=>{if(t.parentNode===l)return gi(t,s,i?l:s,zl.get(s).state,()=>{})}).catch(v):Ll.has(s)&&Xl(s)},_n(){let t=o();null!==t&&(ai(t,!1),!t.broken&&(t.A.Te("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.A,"disconnected")))},reset(){$(`re-setting a component's state is not supported: write <${s?.localName}>.${r} instead.`)}}}var $i={name:"scopes",hooks:e,install(){e.ft=n(i,e.ft,Cl),e.ft=n(i,e.ft,Wl),e.ft=n(i,e.ft,bi),e.dr=Yl,e.Ro=Gl,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=gl.get(e)??[];if("disconnected"===t)for(let e of n)xl(e);else if("reset"!==t&&wl(zt.get(e.root))===e){kl(e,e.root);for(let e of n)hl.get(e.root).has(e.t)||hl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();kl(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:Ml.get(n);void 0!==r&&Pl.set(e,{host:n,def:r})}(e,n)}),e.se=t(e.se,(e,t,n,r,l,i)=>{(function(e,t,n,r){let l=Pl.get(e);if(void 0===l)return;let i=t.t.split(".",1)[0];if(!l.def.bindables.includes(i))return;let s=r&&t.t===i;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,l,i),mi(e,t,n,r,l,i,!1)}),e.Ne=t(e.Ne,(e,t,n)=>mi(e,t,n,void 0,void 0,!1,!0)),e.Ie=n(r,e.Ie,(e,t,n,r,l)=>(function(e,t){let n=gl.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&$(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,l=Ul.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===r;e=e.c)r=l.ht.get(e);if(void 0===r)return!1;let i=r.e;return!((null===i.r||i.r.w)&&!i.ro)&&(!!n||(ii(l,i.r),void $(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.ve}${""===i.x?"":`.${i.x}`}#ro: ${i.ke.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let l=e.pe;e.pe=(e,t)=>{let n=gl.get(e);void 0!==n&&n.length>0&&$(`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=Fl.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&$("re-setting a root state with mounted components is not supported: they read its data."),l?.(e,t)}}},vi="$recursion",wi=new WeakMap,Ai=new WeakSet,ki=new WeakSet,xi=0,Si=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ti=e=>`[wcs/recursion-${e}]`;function Ni(e,t){let n=n=>$(`${Ti("declaration-invalid")} ${vi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&$(`${Ti("declaration-invalid")} ${vi} ${e} must be a non-empty string.`);let r=t.split(".");(r.length<2||"*"!==r[r.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<r.length-1;e++){let t=r[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var ji=(e,t)=>`${e.a}.*${e.step.repeat(t)}`;function Oi(e,t){let n=`${e.a}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&$(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.a}.*".`),r}function Ci(e,t,n){let r=Oi(e,t),l=function(e,t){for(let n=t;null!==n;n=n.a.oe){let t=e.nodeList.exec(n.a.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===l&&$(`[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.`),ji(e,l.k)+r}function Mi(e,t,n){let r=new Set,l=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&$(`${Ti("cycle")} "${n}" is reachable from itself: the data under "${t.a}" must be a tree.`),l.has(e)&&$(`${Ti("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.a}" must be a tree.`),i+1>128&&$(`${Ti("depth-exceeded")} Recursion on "${t.a}.*" reached depth ${i+1} (the limit is 128).`),l.add(e),0)),s=(l,o)=>{for(let a of l){n(o,a);let l=e.o(`${ji(t,o)}.${t.key}`),u=e.read(l,a);i(u,l.t,o+1)&&(r.add(u),s(e.Ke(a,l).d,o+1),r.delete(u))}},o=e.o(t.a),a=e.read(o,null);i(a,t.a,0)&&(r.add(a),s(e.Ke(null,o).d,0))}function Pi(e,t){let n=function(e){let t=e[vi],n=[],r=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!r.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),r.add(e);if(void 0===t)return n.length>0&&V(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&$(`${Ti("declaration-invalid")} ${vi} must be an object mapping one anchor path to its repeating sub-path.`);let l=Object.entries(t);1!==l.length&&$(`${Ti("declaration-invalid")} ${vi} must declare exactly one anchor (it declares ${l.length}).`);let i=Ni("anchor",l[0][0]),s=Ni("repeat",l[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("**"))&&$(`[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))&&$(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&$(`${Ti("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${Si(i)}((?:${Si(u)})*)${Si(n)}$`),n])}return{a:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${Si(o)}((?:${Si(`.*.${a}`)})*)$`)}}(t),r=wi.has(e);null!==n?(r||xi++,wi.set(e,n),ki.add(e),Ai.has(e)||function(e){Ai.add(e);let t=e,n=t.rt;t.rt=r=>{let l=wi.get(e);if(r.t.includes("**")){let t=e.O.vt(r.t)===r;return void(ki.has(e)||void 0===l&&t?r.getter=()=>V(r.t):t||n.call(e,r))}if(void 0!==l&&null===r.getter)for(let[e,n]of l.matchers)if(e.test(r.t)){r.getter=l.families.get(n),r.n>0&&(r.F=t.Me++),l.owners.set(r,l.a+".**"+n);break}n.call(e,r)};let r=t.resolve;t.resolve=(t,n)=>{let l=wi.get(e);return r.call(e,void 0!==l&&t.includes("**")?Ci(l,t,n):t,n)};let l=t.getAll;t.getAll=(n,r)=>{let i=wi.get(e);if(void 0===i||!n.includes("**"))return l.call(e,n,r);if(void 0===r)return l.call(e,Ci(i,n,t.f));(!Array.isArray(r)||r.length>0)&&$(`${Ti("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=Oi(i,n),o=[];return Mi(e,i,(t,n)=>{for(let r of l.call(e,ji(i,t)+s,e.K(n)))o.push(r)}),o};let i=t.kn;t.kn=(n,r,l,s)=>{let o=wi.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,r,l,s);Array.isArray(r)||A(9,[n]),r.length>0&&$(`${Ti("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof l||!0===s?.spread)&&$(`${Ti("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Le>0&&A(8);let a=Oi(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(".")}`))&&$(`${Ti("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}.`))&&$(`${Ti("readonly")} "${n}" writes into the recursive getter "${o.a}.**${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,ji(o,t)+a,e.K(n),l);return h}}(e)):r&&(wi.delete(e),xi--)}function Ei(e,t){if(0===xi)return!1;let n=wi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let r=n.owners.get(e);void 0!==r&&$(`${Ti("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var Wi={name:"recursion",hooks:e,install(){e.pe=t(e.pe,Pi),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ki.delete(e)}(e)}),e.Ie=n(r,e.Ie,Ei)}},Ii="4.11.2",Ri=e=>e.split(".").slice(0,2).join("."),Di=class extends tn{static find(e){return e.querySelector?.(se.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 Ri(this.version)===Ri(Ii)}};function Li(e){let t=se.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Di{})}var qi=()=>se.tagNames.ssr,zi=Symbol.for("wcstack.ssr.snapshotBuilder"),Ui=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Fi=e=>document.createComment(e),Vi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,_i=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),Bi=new WeakMap,Hi=new WeakMap,Ki=new WeakMap,Ji=new WeakSet,Yi=new WeakMap;function Gi(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function Zi(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 Xi=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Qi(e,t,n,r){let l=Fi(null===r?"wcs-[":`wcs-[:${r}`),i=Fi("wcs-]");n.length>0&&n[0].Re().before(...Gi(e,t)),t.after(l);for(let e of n)null===r&&e.Re().before(Fi("wcs-|"));let s=n.length>0?(e=>null===e.L?e.dt:e.L[e.L.length-1])(n[n.length-1]):l;(Xi(s)??s).after(i);for(let e of Gi(l,i))Ji.add(e)}function es(e){if(e instanceof ht){Qi(e.E,e.E,e.Ce,null);for(let t of e.Ce)ts(t);return}let t=e.D;null!==t&&(Qi(e.W[e.y].E,e.W[e.W.length-1].E,[t],e.y),ts(t))}function ts(e){if(null!==e.u)for(let t of e.u)es(t)}var ns=new Set(["script","style","template","textarea","title"]),rs="data-wcs-raw",ls=e=>ns.has(e.localName)||e.localName===qi();function is(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Fi("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Fi("wcs-s")):1===t.nodeType&&!ls(t)&&is(t)}var ss=0;function os(e,t){let n=e.getRootNode(),r=[t];for(let e of Hi.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let l=new Map;for(let e of r){let t=Bi.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.H.values())if(null!==t.S&&n.set(t.S.E,t.S),null!==t.j)for(let e of t.j)n.set(e.E,e);for(let t of e.ie.values())for(let e of t)if(null!==e.I)for(let t of e.I.W)n.set(t.E,e.I);let r=new Set;for(let[e,i]of t){l.set(e,i);let t=n.get(e);void 0!==t&&!r.has(t)&&e.isConnected&&(r.add(t),es(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ki.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ji.has(e)||1===e.nodeType&&t.has(e)&&hs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(ls(e.parentNode)?Yi.has(e):t.has(n)&&_i(n,"wcs-t:"))&&(Yi.has(e)||t.get(e)!==e.data):!t.has(e))&&r.push(e)}for(let e of r)e.remove()}let n=Array.from(e.childNodes);ls(e)&&n.some(e=>Yi.has(e))&&e.setAttribute(rs,n.map(e=>Yi.has(e)?`{{ ${Yi.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}is(9===n.nodeType?n.body:n);let i=document.createElement(qi());i.setAttribute("version",Ii);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 r=Object.getOwnPropertyDescriptor(e,n);void 0!==r.get||void 0!==r.set||"function"==typeof r.value||(t[n]=r.value)}return t}(t.target)),i.append(s);for(let[e,t]of l){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let r="svg"===n?.localName,l=`wcs-${r?"s":"t"}${ss++}`;e.replaceWith(Fi(`wcs-p:${l}`));let s=document.importNode(Wt(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Zi(e,document.createElement("template"),...e.childNodes));if(r){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=l,i.append(Zi(t,o,s))}e.before(i)}function as(e){!function(e){if(null!==e.querySelector(se.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=>Yi.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(`${se.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===qi())continue;let e=t.engine;null!=e&&os(t,e)}}var us=Symbol.for("wcstack.state.ssr.impl"),cs=new Map,fs=new WeakMap,hs=t=>!0===e.Ro?.(t),ds=e=>1===e.nodeType&&!ls(e)&&!hs(e),ps=e=>e.d.flat().concat(e.Y??[]),ms=e=>{for(let t of ps(e))t.remove()};function gs(e,t,n){let r=/^wcs-\[(?::(\d+))?/.exec(e.data),l=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!Vi(o,"wcs-]");){let e=o.nextSibling;if(Vi(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];_i(o,"wcs-[")?e=gs(o,t,n):(n.push(o),ds(o)&&ys(o,t))}o=e}let a={branch:void 0===r[1]?null:Number(r[1]),d:s,Y:o??i.appendChild(Fi("wcs-]"))},u=ps(a);o=a.Y.nextSibling;for(let e of u)n?.push(e),t&&Mt.add(e);return t&&null!==l?cs.set(l,a):ms(a),o}function ys(e,t){for(let n=e.firstChild;null!==n;)_i(n,"wcs-[")?n=gs(n,t):(ds(n)&&ys(n,t),n=n.nextSibling)}function bs(e,t,n){let r=e=>{for(let l of Array.from(e.childNodes))if(l.parentNode===e)if(8===l.nodeType){let e=l.data;try{if("wcs-s"===e)l.remove();else if("wcs-e"===e)l.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Fi(`@@:${decodeURIComponent(e.slice(6))}`),n=l.nextSibling;for(;null!==n&&!Vi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),l.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=l.parentNode,r="s"===e[10]?Zi(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);r.removeAttribute("id"),t.replaceChild(r,l)}}}catch{}}else 1===l.nodeType&&!ls(l)&&(hs(l)?fs.set(l,{ssr:t,Pe:n}):r(l))};r(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||Ts(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{_i(e,"wcs-[")?r++:Vi(e,"wcs-]")&&--r<0&&(r=0,n=t+1)}),0===r)continue;let l=0;for(let r=t.firstChild;null!==r;r=r.nextSibling)if(_i(r,"wcs-["))l++;else if(Vi(r,"wcs-]")&&0===l--){t.prepend(...e.slice(n));break}}}(e),ys(e,n)}function $s(t,n){let r=fs.get(t);if(void 0===r)return null;fs.delete(t);let l=e=>bs(e,r.ssr,r.Pe);if(r.Pe||ks(n,t,t,l),l(t),!r.Pe)return null;let i=e.Pe;return e.Pe=Os,()=>{e.Pe=i,vs()}}function vs(){for(let e of cs.values())ms(e);cs.clear()}function ws(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function As(e,t,n,r){let l=null;for(let r of e){let e=r[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===l||e.length>l[n].length)&&(l=r)}let i=l?.[r];if(null==i)return null;let s=l[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function ks(e,t,n,r){let l=document.createElement("template").content;for(let e of n.childNodes)l.appendChild(l.ownerDocument.importNode(e,!0));r(l),e.root=t;let i=()=>{};Pt(e,[...l.childNodes],null,!0,i,i,i,(t,n)=>Nt(e,n,null,0))}function xs(e,t,n){if(Ui()){if(n instanceof Array){for(let e=n.length;e-- >0;)wt(n[e])&&n.splice(e,1);let e=t;if(n.some(At))Ji.add(e);else if(e.localName.includes("-")&&!hs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ki.set(e,t)}return}if("string"==typeof n){if(Yi.set(t,n),ls(t.parentNode))return;let e=Fi(`wcs-t:${encodeURIComponent(n)}`),r=Fi("wcs-/t");return t.before(e),void t.after(r)}let r=Bi.get(e);void 0===r&&Bi.set(e,r=new Map),r.set(t,n);let l=t.getRootNode(),i=Hi.get(l);return void 0===i&&Hi.set(l,i=new Set),void i.add(e)}if("string"!=typeof n&&cs.size>0){let e=cs.get(n);void 0!==e&&(cs.delete(n),cs.set(t,e))}}var Ss=e=>null!==e&&8===e.nodeType&&[se.commentIfPrefix,se.commentElseIfPrefix,se.commentElsePrefix].includes(e.data),Ts=e=>3===e.nodeType&&""===e.data.trim(),Ns=e=>{let t=cs.get(e)?.Y??e;return(Xi(t)??t).nextSibling};function js(e,t){if(t.length!==e.Ot.childNodes.length)return!1;let n=e.ln;for(let r=0;r<n.length;r++){let l=n[r],i=e.Ot,s=t[l[0]];for(let e=0;;){if(i=i.childNodes[l[e]],s?.nodeName!==i.nodeName)return!1;if(++e===l.length)break;s=(Xi(s)??s).firstChild;for(let t=l[e];t>0&&null!==s;t--)s=Ns(s)}e.xo[r]=s}return!0}function Os(e,t,n){if(0===cs.size)return null;let r=t,l=0;if(!n){let e=se.commentIfPrefix;if(!Vi(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Ss(n)&&l++,!Vi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!cs.has(r)&&null!==n&&!Vi(n,e)&&1!==n.nodeType;n=n.nextSibling)Ss(n)&&(r=n)}let i=cs.get(r);if(void 0===i)return null;if(!n&&i.branch!==l)return cs.delete(r),ms(i),null;let s=i.d.shift();if(0===i.d.length&&cs.delete(r),i.Y?.replaceWith(...Gi(t,r)),i.Y=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=cs.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.Y;)e++;else Xi(s[e])===s[e+1]&&e++}if(!js(e,o)){let n=(e.Mn?e.root:e.Ot).cloneNode(!0);o=e.Mn?[n]:[...n.childNodes],js(e,o),(s[0]??i.d.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var Cs={name:"ssr",hooks:e,install(){e.Ln=xs,e.wr=$s;let n=e.element;e.element=(t,r)=>{"mounting"===r&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||Ui())return;let r=n.previousElementSibling,l=r?.localName===qi(),i=l?r.getAttribute("version"):null,s=null===i||Ri(i)===Ri(Ii);if(s){let e=t,n=e.Te;e.Te=(e,r)=>"$connectedCallback"===e?void 0:n.call(t,e,r)}if(!l)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] <${qi()} version="${i}"> does not match ${Ii}: 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?r.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 r=Object.getOwnPropertyDescriptor(n,t);void 0!==r&&(void 0!==r.get||void 0!==r.set||"function"==typeof r.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${rs}]`)))e.textContent=e.getAttribute(rs),e.removeAttribute(rs);let h=9===f.nodeType?f.body:f;r.remove();let d=e=>o?function(e,t,n){let r=new Map,l=e=>{let t=e.parentElement;for(;null!==t&&!hs(t);)t=t.parentElement;if(null===t)return null;let n=r.get(t);if(void 0===n){let e=l(t),i=t.querySelector(`:scope > ${se.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of he(t.getAttribute(se.bindAttributeName)??"")){let t=r.et;r.we[0]===i&&n.push([e?As(e,t,1,0):t,r.we.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let r=l(e);if(null===r)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:As(r,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return r.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:As(r,i[2],2,1)??i[2]};for(let t of ws(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!Vi(r,`@@wcs-${e[1]}-end:${e[2]}`);)r=r.nextSibling;if(null!==r){for(;t.nextSibling!==r;)t.nextSibling.remove();r.remove(),t.replaceWith(..."text"===e[1]?[Fi(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let r of ws(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(r.data)?.[1],l=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===l)continue;let o=document.importNode(l,!0),a=se.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,l)=>t+i(n??r,l))),s(o.content,n??r);let u=o.content.firstChild;r.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,r,u):bs(e,r,s);s||ks(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),r=e.map(e=>e.selected),l=e.map(e=>e.hasAttribute("selected")),i=l.lastIndexOf(!0);i<0&&(i=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>r[t]!==l[t]):n.selectedIndex!==i)&&t.push([n,()=>e.forEach((e,t)=>e.selected=r[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),s&&(e.Pe=Os,queueMicrotask(()=>{vs(),e.Pe=null}))}(t),n?.(t,r)},function(){let e=globalThis;e[us]={build:as,reset(){ss=0}},void 0===e[zi]&&(e[zi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[us].build(t),reset:()=>e[us].reset()})}(),e.Io=t(e.Io,Li);for(let e of ln())Li(e)}},Ms="__WCSTACK_DEVTOOLS_HOOK__",Ps=null,Es=new Set,Ws=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.K(n)}}),Is=new WeakMap,Rs=0;var Ds=new WeakMap;function Ls(e){if(null===Ps)return;let t=Ds.get(e),n=Es.has(e)?function(e,t){let n=new Map,r=new Set,l=(r,l,i,s,o,a)=>{if(5===r)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(r,l),c=0===s.n?null:o,f=`${(e=>{let t=Is.get(e);return void 0===t&&Is.set(e,t=++Rs),t})(i)}|${u}|${s.t}|${null===c?"":e.K(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:Ws(e,s,c)})},i=e=>l(e.i,e.name,e.l,e.o,e.r,e.rn()),s=e=>{if(!r.has(e)){if(r.add(e),null!==e.Se)for(let t of e.Se)i(t);if(e instanceof nt&&null!==e.me){let t=e.$.Xe;for(let n=0;n<t.length;n++){let r=e.U?.[n];void 0!==r?i(r):l(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(!r.has(e))if(r.add(e),e instanceof ht){l(-1,"for",e.E,e.a.o,e.a.oe,"for");for(let t of e.Ce)s(t)}else null!==e.D&&s(e.D)};for(let t of e.ie.values())for(let e of t)i(e),null!==e.I&&o(e.I);for(let t of e.H.values())if(null!==t.S&&o(t.S),null!==t.j)for(let e of t.j)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,r]of t)n.has(e)||Ps({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&Ps({type:"state:binding-added",...r});Ds.set(e,n)}function qs(e){let t=zt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function zs(e){let t=new Set,n=new Set,r=new Set,l=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&&r.add(i.t),null!==i.ce&&l.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:r,setter:l},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.de.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 Us=new WeakSet,Fs=new WeakMap;function Vs(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Us.has(t))return;Us.add(t);let r=t.emit;t.emit=(...l)=>(null!==Ps&&Ps({type:"state:token-emit",kind:n,tokenName:t.name,args:l,subscriberCount:t.size,stateElement:e.element}),r.apply(t,l))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.de.values())t(n,"event")}(e),"connected"===t){if(Es.has(e))return;Es.add(e),Ps?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Ls(e)}else"disconnected"===t&&(Es.delete(e),Ls(e),Ps?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function _s(e,t,n,r,l,i){if(null===Ps)return;let s=Ws(e,t,0===t.n?null:n),o=Fs.get(e);void 0===o&&Fs.set(e,o=new Set),o.add(s),i&&Ps({type:"state:write",absoluteAddress:s,value:l,oldValue:r,hasOldValue:!0})}function Bs(e){if(null===Ps)return;let t=Fs.get(e);Fs.delete(e),void 0!==t&&Ps({type:"state:update-batch",addresses:t}),Ls(e)}function Hs(e,t,n){Ps?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.rn(),error:t})}var Ks={"*":["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 Js(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...Ks["*"],...Object.hasOwn(Ks,e)?Ks[e]:[]])(n);return r.includes(t)||A(1205,[n,t,r.join(", ")],t,r),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var Ys=[Nn,Pr,rl,fl,$i,Wi,Cs,{name:"devtools",hooks:e,install(){e.element=t(e.element,Vs),e.se=t(e.se,_s),e.he=t(e.he,Bs),e.Ge=t(e.Ge,Hs),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 r of t)r.onEvent?.(e.id,n)})};return{version:2,sources:e,register(r){if(!e.has(r.id)){e.set(r.id,r),n(r);for(let e of t)e.onSourceRegistered?.(r)}},unregister(n){let r=e.get(n);if(void 0!==r){r._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(r){t.add(r);for(let t of e.values())n(t),r.onSourceRegistered?.(t);return()=>{if(t.delete(r))for(let t of e.values())n(t)}}}}());2!==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:Ii,getStateElements:()=>[...Es].map(zs),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let r=n.V,l=n.je?.length??0;if((null===r||0===r.size)&&0===l)continue;let i,s=0;if(null!==r)for(let e of r.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===r?0:r.size,lists:l,lastValue:i})}return t}(qs(e)),keys(e){let t=qs(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return qs(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){qs(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(t){let n=null===Ps&&null!==t;Ps=t,null===t&&(Ds=new WeakMap),e.ut=t&&((e,t)=>Ps?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of Es)Ls(e)})}})}()}},{name:"native-commands",hooks:e,install(){e.lr=Js}}],Gs=Symbol.for("wcstack.package"),Zs=new WeakSet;function Xs(e,t){Object.defineProperty(e,Gs,{value:t,configurable:!0})}function Qs(e,t,n,r,l){if(void 0!==r&&(n===r||n.prototype instanceof r))return;let i=n[Gs];if(i===l||Zs.has(e))return;Zs.add(e);let s=l.slice(0,l.lastIndexOf("@"));console.warn(`[${s}] [wcs/package-twice] <${t}> is already defined by ${i??`another copy of ${s} that does not name its version`}; this copy, ${l}, does nothing. Load each package once.`)}function eo(e){return e}var to=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],no={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][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","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"]}},ro=2,lo=Object.freeze({}),io=Object.freeze({}),so=Object.freeze({}),oo=Object.freeze(["prevent","stop","ro","direct"]),ao=Object.freeze(["init","sync"]),uo=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function co(){return{version:2,syntax:{bindAttribute:se.bindAttributeName,tagName:se.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(ue),modifiers:{flags:oo,keyValue:ao,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:j,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:C,class:M,attr:P,style:E}}},filters:[...Object.keys(Ne),...Object.keys(Sn)],filterMeta:no,filterAliases:lo,declarationAliases:io,apiAliases:so,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(uo.map(e=>[e,{type:"boolean",default:!0}])),features:[...to],nativeCommands:Object.fromEntries(Object.entries(Ks).map(([e,t])=>[e,[...t]]))}}var fo=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),ho=Object.freeze([]);function po(e){if(!se.enableContractAnalyzer)return ho;let t=[],n=Ps,r=e=>{t.push(e),n?.(e)},l=e.manifestExtensions;if(null===l||"object"!=typeof l)return t;for(let e of Object.keys(l))fo.has(e)||r({type:"contract:unsupported-extension",namespace:e});let i=l["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=mo(e);if(r({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){r({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let l=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(l.observables??{})){let l=n.de.get(t);if(void 0===l){r({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==l&&r({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:l})}for(let t of Object.keys(l.inputs??{}))n.inputs.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(l.commands??{}))n.commands.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function mo(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:[],r=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&r.set(e.name,e.event);let l=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{de:r,inputs:l(t.inputs),commands:l(t.commands)}}function go(t,n){(function(t){for(let n of t)if(!s.has(n.name)){if(n.hooks!==e)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${n.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);s.add(n.name),n.install()}})(Ys),t&&function(e){let t=se,n=se.tagNames,r=Object.entries(e).filter(([,e])=>void 0!==e),l=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of r){let r=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof r||Array.isArray(n)!==Array.isArray(r))&&A(44,["bootstrapState",e])}for(let[e,t]of l)(!Object.hasOwn(n,e)||"string"!=typeof t)&&A(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of r)"tagNames"!==e&&(t[e]=n);for(let[e,t]of l)n[e]=t}(t),function(e,t=customElements){let{state:n,ssr:r}=se.tagNames,l=t.get(n),i=t.get(r);e();let s=`@wcstack/state@${Ii}`;if(void 0!==l)return Qs(t,n,l,nn,s);Xs(t.get(n),s);let o=t.get(r);void 0!==i?Qs(t,r,i,void 0,s):void 0!==o&&Xs(o,s)}(()=>function(t=customElements){(function(){let e=globalThis;void 0===e[_t]&&(e[_t]={protocol:"wcs-binder",version:1,bind:Jt})})(),ln().includes(t)||rn.push(new WeakRef(t));let n=se.tagNames.state;void 0===t.get(n)&&t.define(n,class extends nn{}),e.Io?.(t)}(n),n)}export{Di as Ssr,Me as TRUSTED_TYPES_POLICY_SLOT,Ii as VERSION,ro as WCS_MANIFEST_VERSION,po as analyzeContract,go as bootstrapState,on as buildBindings,lo as builtinFilterAliases,no as builtinFilterMeta,eo as defineState,en as getBindingsReady,oe as getConfig,Pe as getTrustedTypesPolicy,co as getWcsManifest,Ee 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:(...r)=>{let l=t(...r);return e(l)?l:n(...r)}}var r=e=>!0===e,l=e=>void 0!==e,i=e=>null!=e,s=new Set;function o(t){let n=t.$features;if(null!=e.Mt&&Array.isArray(n)){let t=n.filter(e=>!s.has(e));if(t.length>0)return e.Mt(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.ce=null,this.ue=!1,this._=[],this.Z=[],this.yt=null,this.F=-1,this.G=c,this.je=null,this.Lt=null,this.Wt=null,this.V=null,this.mn=!1,this.hn=!1,this.gn=!1,this.ee=0,this.wt=new Set,this.t=e,this.c=n,this.s=t;let r=null===n?[null]:n.h.slice(),l="*"===t;l&&r.push(n),this.n=r.length-1,this.Y=l?[]:null===n?[t]:[...n.Y,t],this.h=r}Hn(e){this.wt.has(e)||(this.wt.add(e),this._.push(e),e.Z.push(this))}Wo(e){this.wt.delete(e);let t=this._;t.splice(t.indexOf(e),1)}_o(){this.getter=null,this.ce=null,this.F=-1,this.G=c,this._.length=0,this.wt.clear(),this.Z.length=0,this.yt=null,this.je=null,this.Lt=null,this.Wt=null,this.V=null}te(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.bt=new Map,this.Un=e}vt(e){return this.bt.get(e)}get(e){let t=this.bt.get(e);if(void 0!==t)return t;let n=e.lastIndexOf("."),r=n<0?null:this.get(e.slice(0,n));return t=new u(e,e.slice(n+1),r),this.Un?.(t),this.bt.set(e,t),r&&r.u.push(t),t}all(){return this.bt.values()}_t(e){this.bt.delete(e.t)}},p=new Map;function m(e){let t=p.get(e);if(void 0!==t)return t;let n=!0,r=e.split("."),l=[];for(let e=0;e<r.length;e++){let t=r[e],i=t.charCodeAt(0);e>0&&i>=48&&i<=57?(n=!1,l.push(Number(t)),r[e]="*"):"*"===t&&l.push(-1)}if(!n)return{o:r.join("."),indexes:l};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.kt=null,this.S=null,this.Se=null,this.V=null,this.u=null,this.w=!0,this.a=e,this.y=t,this.N=n}},y=class{constructor(e,t){this.T=null,this.d=[],this.S=null,this.j=null,this.re=!1,this.Bt=!1,this.St=!1,this.o=e,this.oe=t,this.n=e.n+1}},b=[];function $(t,n,r){throw new Error(`[@wcstack/state] ${t}${e.Vo?.(t,n,r)??""}`)}function v(e,t,...n){"function"!=typeof reportError?console.error(...void 0===t?[e]:[t,e],...n):reportError(void 0===t?e:new Error(`${t} ${e}`,{cause:e}))}function w(t,n=[]){return e.Ho?.(t,n)??`#${t}${n.map(e=>` ${"string"==typeof e?JSON.stringify(e):String(e)}`).join("")}`}function A(e,t,n,r){$(w(e,t),n,r)}var k=class{constructor(e){this.Et=new Set,this.name=e}get size(){return this.Et.size}subscribe(e){return this.Et.add(e),()=>{this.Et.delete(e)}}unsubscribe(e){return this.Et.delete(e)}emit(...e){let t=[];for(let n of this.Et)try{t.push(n(...e))}catch(e){t.push(void 0),v(e,`[@wcstack/state] ${w(17,[this.name])}`)}return t}};function x(e,t,n){if(void 0===e)return[];Array.isArray(e)||A(18,[t]);let r=new Set;for(let l of e)("string"!=typeof l||""===l)&&A(19,[t]),l===n&&A(20,[t,l,n]),r.has(l)&&A(21,[t,l]),r.add(l);return e}var S=Symbol.for("wcstack.transition-runner");function T(e){let t=globalThis[S];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run||"function"!=typeof t.accepts||!t.accepts(e)?null:t}function N(e,t,n){let r=T(e);if(null!==r)return r.run(t,{source:e,types:n});t()}var j="else",O="eventToken",C="command",M="class",P="attr",E="style",W=/^\$[1-9]\d{0,2}$/,I=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function R(e){let t=[],n=[],r="",l=null,i=!1,s=-1,o=-1,a=e=>{let l=function(e,t,n){let r=-1===t?e.length:t,l=-1===n?0:n;return e.slice(r-e.slice(0,r).trimStart().length,l+e.slice(l).trimEnd().length)}(r,s,o);(!e||l||i)&&(t.push(l),n.push(function(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:I.test(e)?Number(e):e)}(l,i))),r="",i=!1,s=-1,o=-1};for(let t=0;t<e.length;t++){let n=e[t];l?n===l?l=null:(-1===s&&(s=r.length),r+=n,o=r.length):'"'===n||"'"===n?(l=n,i=!0):","===n?a():r+=n}return null!==l&&A(107,[l,e]),a(!0),{args:t,literals:n}}var D=e=>e.trim();function L(e,t){let n=[],r=null;for(let l=0;l<e.length;l++){let i=e[l];null!==r?i===r&&(r=null):"'"===i||'"'===i?r=i:i===t&&n.push(l)}return n}var q=(e,t)=>L(e,t)[0]??-1;function z(e,t){let n=[],r=0;for(let l of L(e,t))n.push(e.slice(r,l)),r=l+1;return n.push(e.slice(r)),n}function U(e,t,n){let r=q(e,"|");if(-1===r)return[e.trim(),[]];let l=e.slice(r+1).trim(),i=n.get(l);return void 0===i&&(i=function(e,t,n){let r=n??e.join("|");return e.map(e=>{let n=q(e,"("),l=(e=>L(e,")").pop()??-1)(e);if(-1===l&&(l=e.lastIndexOf(")")),-1!==n&&-1===l&&A(108,[e]),-1!==l&&-1===n&&A(109,[e]),-1!==l&&l<n&&A(110,[e]),-1!==l&&e.slice(l+1).trim().length>0){let t=e.slice(l+1).trim();A(111,[e,t])}let i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&A(112,[r]),i.includes("#")){let[,e]=i.split("#");A("input"===t?113:114,[i,e])}return-1===n?{Kn:i,args:[],literals:[]}:{Kn:i,...R(e.substring(n+1,l))}})}(z(l,"|").map(D),t,e),n.set(l,i)),[e.slice(0,r).trim(),i]}var F=new Map;function V(e){A(1101,[e])}function _(e){let[t,n]=U(e,"output",F);t.includes("@")&&A(32,[t]);let r=t,l=r.startsWith("."),i=l?r.slice(1):r;return(i.length>0&&i.split(".").some(e=>0===e.length)||!l&&0===i.length)&&A(119,[e]),function(e){e.includes("**")&&V(e);let t=e.split(".").length;t>512&&A(117,[e,t])}(r),{et:r,tt:n}}var B=[["$watch","temporal"],["$stream","temporal"],["$listKeys","list-keys"],["$recursion","recursion"]],H=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function K(e){return e.includes("**")&&V(e),e}var J=0;function Y(e,t,n){let r=e.get(t);return void 0===r&&e.set(t,r=n()),r}var G=()=>new Set,Z=()=>[],X=new WeakMap;function Q(e){return null!==e&&"object"==typeof e&&"function"==typeof e.then}function ee(e,t){return e===t||e!=e&&t!=t}function te(e,t,n){let r=e.V?.get(t);void 0!==r&&r.delete(n)&&0===r.size&&e.V.delete(t)}function ne(e,t){for(let n=0;n<t.length;n++){if(null==e)return;e=e[t[n]]}return e}function re(e,t){for(;null!==e&&e.a.n>t;)e=e.a.oe;return null!==e&&e.a.n===t?e:null}function le(e,t,n){let r=re(e,n);return null!==r&&r.a.o===t.h[n]?r:null}var ie=class{constructor(e,t){this.Me=0,this.f=null,this.Le=0,this.nt=new Set,this.ot=new Map,this.qn=Symbol("wcs.block"),this.element=null,this.$t=[],this.We=null,this.zn=[],this.qt=0,this.X=null,this.H=new Map,this.ie=new Map,this._e=[],this.Be=[],this.Ve=[],this.He=!1,this.yn=!1,this.zt=new WeakMap,this.I=0,this.Yt=0,this.wn=0,this.bn=0,this.vn=!1,this.Gt=!1,this.Xt=!1,this.Oe=0,this.Yn=()=>{this.I=0,this.vn=!1},this.Gn=()=>{this.Oe--},this.rp=null,this.rr=null,this.Uo=()=>{this.He&&this.xt()},this.Ko=(e,t)=>e(this.proxy,...t),this.Xn=[],this.Ue=[],this.Jn={$untracked:e=>{let t=this.X;if(null===t)return e();t.Ee++;try{return e()}finally{t.Ee--}},$eqIndex:(e,t=1)=>{let n=re(this.f,t);null===n&&A(7,[e]);let r=this.o(e);if(null!==r.getter||r.ue)return this.watchIndex(t),n.y===this.read(r,null);let l=this.X;if(null!==l){let e=l.getter,n=r.je??(r.je=[]);if(!n.some(n=>n.getter===e&&n.Qn===t)){n.push({getter:e,Qn:t});let l=e.h[t];(l.Lt??(l.Lt=[])).push({source:r,getter:e})}}return n.y===this.v(r,null)},$eq:(e,t)=>this.eq(e,t),$eqPath:(e,t)=>{let n=this.o(t);return this.eq(e,this.v(n,re(this.f,n.n)))},$dependOn:e=>{this.resolve(K(e),this.f),null!==this.X&&0===this.X.Ee&&this.Zn(this.rp,this.rr,this.X)},$getAll:(e,t)=>this.getAll(e,t),$setAll:(e,t,n,r)=>this.kn(e,t,n,r),$resolve:(...e)=>{let t=K(e[0]),n=e[1]??[],r=this.o(t,!0);this.Sn("$resolve",t,r,n,!0);let l=this.eo(r,n,null);if(e.length<3)return this.read(r,l);this.C(r,l,e[2])},$postUpdate:e=>{this.resolve(K(e),this.f);let t=this.rp,n=this.rr;"*"===t.s&&null!==n&&(n.N=n.a.T[n.y],X.delete(n.a.T),this.P.Jt(n)),this.En(t,n),null!==n&&this.to(n,t,void 0,n.N,!1),0===t.n&&this.no(t,void 0,void 0,!0),this.Qt(t,n,void 0,void 0,!1)}},this.P=t,this.O=new d(e=>{this.Ue.push(e),this.rt(e)}),this.oo(e);let n=this,r={getOwnPropertyDescriptor(e,t){let r=Reflect.getOwnPropertyDescriptor(n.target,t);return r&&(r.configurable=!0),r},get(e,t,r){let l=n.target;if("symbol"==typeof t)return Reflect.get(l,t);if(36===t.charCodeAt(0))return n.it(t);if(t.indexOf(".")<0){let e=n.O.vt(t);if(void 0===e||null===e.getter){let e=l[t];if("function"==typeof e)return r===n.proxy&&n.U?.(e)||e}if(void 0!==e&&0===e.n)return n.read(e,null)}return n.resolve(t,n.f),n.read(n.rp,n.rr)},set:(e,t,r)=>"symbol"==typeof t?Reflect.set(n.target,t,r):(n.resolve(K(t),n.f),n.C(n.rp,n.rr,r),!0)};for(let e of["has","ownKeys","deleteProperty","defineProperty","getPrototypeOf"])r[e]=(t,...r)=>Reflect[e](n.target,...r);this.proxy=new Proxy({},r)}o(e,t){let n=this.O.get(e);return t||(n.mn=!0),n}io(e){let t=new Set;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n)){if(t.has(e))continue;t.add(e);let r=Object.getOwnPropertyDescriptor(n,e);if(void 0===r.get&&void 0===r.set)continue;let l=this.o(e);l.getter=r.get??null,l.ce=r.set??null,null!==l.getter&&l.n>0&&(l.F=this.Me++)}for(let e of this.O.all())this.rt(e)}rt(e){e.t.includes("**")&&V(e.t),("__proto__"===e.s||"prototype"===e.s)&&A(120,[e.t]);let t=e.c;e.ue=null!==t&&"*"!==e.s&&t.n===e.n&&(null!==t.getter||t.ue),null===e.getter&&this.qo(e)}qo(e){let t=e.t,n=e.s;if(W.test(n))e.getter=function(){return this[n]};else{let r=t.split("."),l=r.findIndex((e,t)=>t>0&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57);if(l<0||r.indexOf("*",l)>=0)return;e.getter=()=>(this.resolve(t,this.f),this.rp!==e?this.read(this.rp,this.rr):this.read(e.c,this.f)?.[n]),e.ce=r=>{if(this.resolve(t,this.f),this.rp!==e)return this.C(this.rp,this.rr,r);let l=this.read(e.c,this.f);null==l&&A(4,[t,l]),l[n]=r}}e.gn=!0,e.n>0&&(e.F=this.Me++)}Ke(e,t){let n=null===e?this.H:e.u??=new Map,r=n.get(t);return void 0===r&&n.set(t,r=new y(t,e)),t.mn=!0,this.J(r),r}so(e){try{this.J(e)}catch(t){this.Zt(t,e.o.t,e.S?.E??null,"for")}}J(t){let n=this.v(t.o,t.oe);if(n===t.T)return;this.ao(t);let r=function(e,t,n){let r=Array.isArray(t)?t:b;if(r===e.T)return null;let l=e.d,i=r.length,s=l.length,o=new Array(i),a=0;for(;a<i&&a<s&&l[a].N===r[a];)o[a]=l[a],a++;let u=s-1,c=i-1;for(;u>=a&&c>=a&&l[u].N===r[c];)o[c]=l[u],u--,c--;if(a>u)for(let t=a;t<=c;t++)o[t]=new g(e,t,r[t]);else if(a>c)for(let e=a;e<=u;e++)n.Vt(l[e]);else{let t=u<c?u:c;for(let e=a;e<=t;e++)l[e].N===r[e]&&(o[e]=l[e]);let i=new Map;for(let e=u;e>=a;e--){let n=l[e];if(e<=t&&o[e]===n)continue;let r=i.get(n.N);void 0===r?i.set(n.N,n):Array.isArray(r)?r.push(n):i.set(n.N,[r,n])}for(let t=a;t<=c;t++){if(void 0!==o[t])continue;let n,l=r[t],s=i.get(l);void 0!==s&&(Array.isArray(s)?(n=s.pop(),0===s.length&&i.delete(l)):(n=s,i.delete(l))),o[t]=n??new g(e,t,l)}for(let e of i.values())if(Array.isArray(e))for(let t of e)n.Vt(t);else n.Vt(e)}for(let e=a;e<i;e++){let t=o[e];t.y!==e&&(t.y=e,n.Bo(t))}return e.d=o,e.T=r,l}(t,n,this);if(null===r)return;if(t.T===n){let e=Y(this.zt,n,Z);if(e.push(t),e.length>1)for(let t of e)t.St=!0}e.st?.(this,t,r),(null!==t.S||null!==t.j)&&!t.re&&(t.re=!0,this.Be.push(t),this.$e());let l=t.o.Lt;if(null!==l)for(let{source:e,getter:n}of l){let l=this.v(e,null),i=r[l],s=t.d[l];i!==s&&(void 0!==i&&i.w&&this.$n(n,i),void 0!==s&&this.$n(n,s))}}Bo(e){this.P.zo(this,e)}Vt(e){e.w=!1;let t=e.V;if(null!==t){for(let e of t)te(e.source,e.key,e.sub);e.V=null}if(null!==e.u)for(let t of e.u.values()){this.ao(t);for(let e of t.d)this.Vt(e)}}ao(e){let t=this.zt.get(e.T);void 0!==t&&(t.splice(t.indexOf(e)>>>0,1),e.St=!1,1===t.length&&(t[0].St=!1))}resolve(e,t){let n=m(e),r=this.rp=this.o(n.o,!0),l=n.indexes;this.rr=0===r.n?null:null===l?le(t,r,r.n):this.eo(r,l,t,e)}eo(e,t,n,r){let l=null;for(let i,s=1,o=0;s<=e.n;s++){let a=e.h[s],u=this.Ke(l,a),c=t[o++];if(c<0)c=le(n,e,s)?.y??-1;else if(r&&u.T===b&&Object(i=this.v(a,l))===i){let t=e.t.split("."),n=a.t.split(".").length;t[n]=r.split(".")[n],e=this.o(t.join("."),!0),s--;continue}if(l=u.d[c]??null,null===l)break}return this.rp=e,l}at(e,t){return 0===e.n?ne(this.target,e.Y):null===t?void 0:ne(t.N,e.Y)}read(e,t){let n=this.X;if(null!==n&&0===n.Ee&&this.Zn(e,t,n),null!==e.getter)return this.P.Yo(this,e,t);if(e.ue){let n=this.read(e.c,t);return n?.[e.s]}return null===e.c&&!(e.s in this.target)&&!this.nt.has(e.s)&&"then"!==e.s&&"toJSON"!==e.s&&A(301,[e.t],e.s,Object.keys(this.target)),this.at(e,t)}v(e,t){let n=this.X;if(null===n)return this.read(e,t);n.Ee++;try{return this.read(e,t)}finally{n.Ee--}}Zn(e,t,n){let r=n.getter;e.Hn(r),0===r.n?e.ee!==n.fe&&(e.ee=n.fe,n.xn.push(e)):e.n>0&&re(t,Math.min(e.n,r.n))!==re(n.r,Math.min(e.n,r.n))&&(r.yt??(r.yt=new Set)).add(e)}Go(e,t){for(let n=0;n<this.qt;n++){let r=this.zn[n];r.getter===e&&r.r===t&&A(701,[e.t])}this.qt>=128&&A(801,[e.t]);let n=this.qt++;this.Le++;let r=this.zn[n]??={getter:e,r:t,Ee:0,fe:0,xn:[]};r.getter=e,r.r=t,r.Ee=0,r.fe=++J,r.xn.length=0;let l=this.X;this.X=r;let i=this.f;this.f=t;try{let t=e.getter.call(this.proxy);return 0===e.n&&this.Xo(e,r),t}finally{this.Le--,this.qt--,this.X=l,this.f=i,r.r=null}}Xo(e,t){let n=t.fe;for(let e of t.xn)e.ee=n;e.Z=e.Z.filter(t=>t.ee===n||t.n>0||!t.ue&&Array.isArray(null!==t.getter?t.G:this.at(t,null))||this.lo(t,e))}lo(e,t){return e.Wo(t),this.Ue.push(e),!1}Jo(){for(let e=this.Ue;e.length>0;e=this.Ue){this.Ue=[];let t=new Set;for(let n of e)if(!(n.mn||n.hn||null===n.c||n.u.length>0||n._.length>0)&&(null===n.getter||n.gn&&n.F<0)&&null===n.V){n.hn=!0,this.O._t(n),t.add(n.c);for(let e of n.Z)this.lo(e,n)}for(let e of t)(e.u=e.u.filter(e=>!e.hn)).length||this.Ue.push(e)}}watchIndex(e){let t=this.X;if(null!==t&&0===t.Ee){let n=t.getter,r=n.h[e];if(r){let e=r.Wt??(r.Wt=[]);e.includes(n)||e.push(n)}}}it(t){let n=t.charCodeAt(1);if(n>=48&&n<=57){let e=2===t.length?n-48:W.test(t)?+t.slice(1):0;return(e<1||e>128)&&A(1001,[t]),this.watchIndex(e),re(this.f,e)?.y}let r=this.Jn[t];if(void 0!==r)return r;switch(t){case"$stateElement":return this.element;case"$command":return this.commands}return e.it?.(this,t)}eq(e,t){this.resolve(e,this.f);let n=this.rp,r=this.rr;if(null!==n.getter||n.ue||n.n>0)return ee(this.read(n,r),t);let l=this.X;return null!==l&&0===l.Ee&&this.Qo(n,t,l),ee(this.v(n,null),t)}Qo(e,t,n){let r=n.getter,l=n.r,i=null===l?this.Xn:l.V??(l.V=[]);for(let l=0;l<i.length;l++){let s=i[l];if(s.sub.getter===r&&s.source===e){if(ee(s.key,t))return void(s.fe=n.fe);s.fe!==n.fe&&(te(e,s.key,s.sub),i.splice(l--,1))}}let s={getter:r,r:l};Y(e.V??=new Map,t,G).add(s),i.push({source:e,key:t,sub:s,fe:n.fe})}no(e,t,n,r){this.en(e,l=>{let i=l.V;if(null===i&&null===l.je)return;let s=l===e?[]:l.t.slice(e.t.length+1).split("."),o=ne(t,s),a=ne(n,s);if(null!==l.je&&this.Zo(l,o,a,r),null!==i)for(let e of r?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.P.xe(this,n.getter,n.r):te(l,e,n)}})}C(t,n,r,l=!1,i=!1){if(this.Le>0&&A(8),i||this.Oe>0?this.Gt=!0:this.Xt=!0,e.Ie?.(this,t,n,r,i))return;if(null!==t.ce){try{this.Nn(t.ce,n,[r])}finally{this.Qt(t,n,void 0,void 0,!1,i)}return}null!==t.getter&&A(2,[t.t]),t.n>0&&null===n&&A(3,[t.t]);let s=t.ue?this.v(t,n):this.at(t,n);if(l||!this.Ut||!Object.is(s,r)||Object(r)===r){if("*"===t.s){let e=n;e.a.T[e.y]=r,X.delete(e.a.T),e.N=r,this.P.Jt(e)}else{let e=1===t.Y.length?0===t.n?this.target:n.N:this.v(t.c,n);null==e&&A(4,[t.t,e]),e[t.s]=r}this.Tn(t,n),null!==n&&this.to(n,t,s,r),0===t.n&&this.no(t,s,r),this.Qt(t,n,s,r,!0,i)}}co(e){return(this.zt.get(e.T)??[]).filter(t=>t.T===e.T&&(null===t.oe||t.oe.w))}to(e,t,n,r,l=!0){let i=e.a,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.T);if(!o&&!i.St&&null===i.o.getter&&!i.o._.length)return;let a=e.N,u=(t,i)=>{if(void 0===i||i===e)return;let o=this.o(`${t.o.t}.*${s}`,!0);""===s&&(i.N=r,this.P.Jt(i)),l?this.Tn(o,i):this.En(o,i),this.Qt(o,i,n,r,l)};for(let t of this.co(i))if(u(t,t.d[e.y]),o)for(let n of t.d)n.N===a&&n.y!==e.y&&u(t,n);if(""===s)return;let c=new Set([i.T]),h=e=>Array.isArray(e)&&e.includes(a),d=(e,t)=>{if(!c.has(e)&&c.add(e))for(let t of this.zt.get(e)??[])for(let e of t.d)e.N===a&&u(t,e);for(let n of t){let t=n.G,r=t===f;r&&(t=this.H.get(n)?.T),(r||h(t))&&!c.has(n._)&&c.add(n._)&&(!r&&t!==e&&this.P.xe(this,n,null),d(t,n._))}},p=e=>{for(let t of e.Z)if(!c.has(t)&&c.add(t))if(null!==t.getter)p(t);else if(!t.ue){let e=this.at(t,null);h(e)&&d(e,t._)}};null!==i.o.getter?p(i.o):d(i.T,i.o._)}En(e,t){this.er(e,t,e=>{this.J(e);for(let t of e.St?this.co(e):[e]){let e=this.o(`${t.o.t}.*`);for(let n of t.d)this.Nt(e,n),this.En(e,n)}})}Tn(e,t){let n=null===t?this.H:t.u;if(null!==n)for(let t of n.values())t.o.te(e)&&this.J(t)}er(e,t,n){let r=null===t?this.H:t.u;if(null!==r)for(let t of r.values())t.o.te(e)&&n(t)}Zo(e,t,n,r){for(let{getter:l,Qn:i}of e.je)this.uo(l.h[i],e=>{for(let i of r?e.d.keys():[t,n]){let t="number"==typeof i?e.d[i]:void 0;void 0!==t&&this.$n(l,t)}})}$n(e,t){t.a.n===e.n?this.P.xe(this,e,t):this.tn(t,e,t=>this.P.xe(this,e,t))}Qt(t,n,r,l,i,s){e.se?.(this,t,n,r,l,i,s),this.qe(t,n)}qe(e,t){this.P.tr(this,e,t),this.$e()}fo(e){let t=this.ot.get(e);if(void 0!==t)return t;let n=Symbol(`wcs.on${e}`);this.ot.set(e,n);let r=this.root,l=this.qn;return r.addEventListener(e,t=>{for(let i=t.target;null!==i&&i!==r;i=i.parentNode){let r=i[n];if(void 0!==r&&(r(t),t.cancelBubble))return;let s=i[l];if(void 0!==s&&s.w&&s.nr(e,t))return}}),n}reset(t){let n=this.target,r=this.nt;for(let e of this.O.all())null===e.c&&null!==e.getter&&r.add(e.s);this.oo(t);for(let e in n)"$"!==e[0]&&r.add(e);for(let e of r)e in t&&r.delete(e);for(let e of this.ie.values())for(let t of e)this.nn(t);for(let e of this.H.values())this.po(e);this.We=null;try{this.xt()}finally{this.Rn()}e.element?.(this,"reset")}oo(t){for(let[e,n]of B)void 0!==t[e]&&a(n,e);let n=t.$features;if(void 0!==n){Array.isArray(n)||A(46);for(let e of n)a(e,"$features")}let r=void 0===t.$behavior?{}:t.$behavior;("object"!=typeof r||!r||Array.isArray(r))&&A(44,["state","$behavior"]);for(let e in r)(!H.includes(e)||"boolean"!=typeof r[e])&&A(44,["$behavior",e]);let[l,i,s]=H.map(e=>r[e]??!0);void 0!==this.target&&(l!==this.Ht||i!==this.Ut||s!==this.Kt)&&A(45);let o=function(e,t){let n={};for(let r of x(e.$commandTokens,"$commandTokens","$command"))n[r]=t?.[r]??new k(r);return Object.freeze(n)}(t,this.commands),u=function(e,t){let n=new Map;for(let t of x(e.$eventTokens,"$eventTokens"))n.set(t,new k(t));let r=e.$on;if(void 0===r)return n;(null===r||"object"!=typeof r)&&A(22);for(let[e,l]of Object.entries(r)){let r=n.get(e);void 0===r&&A(23,[e]),"function"!=typeof l&&A(24,[e]),r.subscribe((...e)=>t(l,e))}return n}(t,this.Ko);this.Ht=l,this.Ut=i,this.Kt=s,e.pe?.(this,t),this.target=t,this.Me=0;for(let e of this.O.all())e._o();this.Xn.length=0,this.io(t),this.commands=o,this.de=u}po(e){this.so(e);let t=this.o(`${e.o.t}.*`);for(let n of e.d)if(n.kt=null,n.V=null,this.Nt(t,n),null!==n.u)for(let e of n.u.values())this.po(e)}K(e){let t=[];for(let n=e;null!==n;n=n.a.oe)t.unshift(n.y);return t}or(e,t,n){let r=this.de.get(e);void 0===r&&A(1301,[e],e,this.de.keys()),r.emit(t,...this.K(n))}command(e){let t=this.commands[e];return void 0===t&&A(1302,[e],e,Object.keys(this.commands)),t}ir(e,t,n){this.command(e).emit(t,...this.K(n))}sr(e,t,n){let r=e.includes(".")?this.v(this.o(e),null):this.target[e];return"function"!=typeof r&&A(5,[e]),this.Nn(r,n,[t,...this.K(n)])}Nn(e,t,n){let r=this.f;this.f=t;try{return e.apply(this.proxy,n)}finally{this.f=r}}Nt(e,t){if(null!==e.getter){let n=null===t?this.H:t.u;if(null!==n)for(let t of n.values())!t.Bt&&t.o.te(e)&&(t.Bt=!0,this.Ve.push(t))}if(null===t)return void this.en(e,e=>{let t=this.ie.get(e);if(void 0!==t)for(let e of t)this.nn(e)});let n=t.Se;if(null!==n)for(let t=0;t<n.length;t++)n[t].o.te(e)&&this.nn(n[t]);let r=t.S;null!==r&&null!==r.me&&r.mo(this,e);let l=t.a.j;if(null!==l)for(let n of l){let r=n.map.get(t);void 0!==r&&null!==r.me&&r.mo(this,e)}}An(e,t,n){this.en(e,e=>{let r=e._;for(let l=0;l<r.length;l++){let i=r[l];if(0===i.n)this.ct(i,null,n);else if(null===t||0===e.n||i.h[1]!==e.h[1]||null!==i.yt&&i.yt.has(e))this.on(i.h[i.n],e=>this.ct(i,e,n));else if(i.n<=e.n){let e=re(t,i.n);null!==e&&this.ct(i,e,n)}else this.tn(t,i,e=>this.ct(i,e,n))}})}ct(t,n,r){r(t,n)&&(e.Ne?.(this,t,n),this.Nt(t,n),this.An(t,n,r))}en(e,t){t(e);let n=e.u;for(let e=0;e<n.length;e++)this.en(n[e],t)}on(e,t){this.uo(e,e=>{for(let n of e.d)t(n)})}uo(e,t){if(0===e.n){let n=this.H.get(e);return void(void 0!==n&&t(n))}this.on(e.h[e.n],n=>{let r=n.u?.get(e);void 0!==r&&t(r)})}tn(e,t,n){if(e.a.n===t.n)return n(e);let r=e.u?.get(t.h[e.a.n+1]);if(void 0!==r)for(let e of r.d)this.tn(e,t,n)}ar(e){let t=e.r;null===t?Y(this.ie,e.o,G).add(e):(t.Se??(t.Se=[])).push(e)}Pn(e){let t=e.r;if(null===t)return void this.ie.get(e.o)?.delete(e);let n=t.Se;t.w&&null!==n&&n.splice(n.indexOf(e)>>>0,1)}nn(e){e.re||(e.re=!0,this._e.push(e),this.$e())}$e(){this.He||(this.He=!0,queueMicrotask(this.Uo))}Cn(){for(let e of this._e)e.re=!1;for(let e of this.Be)e.re=!1;for(let e of this.Ve)e.Bt=!1;this._e=[],this.Be=[],this.Ve=[],this.P.nt(this)}ho(t,n){let r=[...new Set([...this._e,...this.Be,...this.Ve].map(e=>e.o.t))];v(r,`[@wcstack/state] ${w(t)}`),e.ut?.(this,{type:"state:render-chain-limit",maxDepth:n,paths:r}),this.Cn()}xt(){this.He=!1;let e=this.Yt;this.Yt=0;let t=0;if(!this.Gt||this.Xt?this.Yn():e>0?t=e:1===(t=++this.I)&&setTimeout(this.Yn,0),this.Gt=this.Xt=!1,t>100)101===t?this.ho(41,100):this.Cn();else{this.yn=!0;try{for(let e=0;this._e.length>0||this.Be.length>0||this.Ve.length>0;e++){if(e>=32){this.vn?this.Cn():this.ho(11,32),this.vn=!0;break}let n=this.Ve;if(n.length>0){this.Ve=[];for(let e of n)e.Bt=!1,this.so(e)}let r=this.Be,l=this._e;this.Be=[],this._e=[];let i=!1,s=()=>{i=!0;for(let e of r){e.re=!1;for(let t of[e.S,...e.j??[]])if(null!==t&&t.w)try{t.Tt()}catch(n){this.Zt(n,e.o.t,t.E,"for")}}for(let e=0;e<2;e++)for(let t=0;t<l.length;t++){let n=l[t];!n.re||null===n.I==(0===e)||(n.re=!1,(null===n.Fn||n.Fn.w)&&this.ze(n))}if(!this.yn&&(this.Ye(),0===--this.wn&&this.go(),this.He)){this.Yt=t+1,this.bn++;try{for(;this.He;)this.xt()}finally{this.bn--}}},o=(r.length>0||l.some(e=>null!==e.I))&&0===this.bn?N("state",s):s();i||this.wn++,void 0!==o&&o.then(void 0,v)}}finally{this.yn=!1}this.Gt=this.Xt=!1,this.Ye(),0===this.wn&&this.go(),e>0&&this.He&&(this.Yt=t+1)}}go(){e.he?.(this),this.Jo()}Rt(e,t){this.$t.push([e,t])}Zt(e,t,n,r){this.Rt(e,{o:{t},l:n,rn:()=>r})}ze(e){try{e.apply()}catch(t){return void this.$t.push([t,e])}null!==this.We&&this.yo(e.o,e.r)}yo(e,t){let n=Y(this.We,e.t,Z);null!==t&&n.push(this.K(t))}Rn(){this.We="function"==typeof this.target.$renderedCallback?new Map:null}Ye(){let t=this.We;if(null!==t&&t.size>0){this.We=new Map;let e,n=[...t.keys()],r={};for(let[e,n]of t)n.length>0&&(r[e]=n);this.Oe++;try{e=this.Te("$renderedCallback",[n,r])}catch(e){v(e)}Q(e)?e.then(this.Gn,e=>{this.Gn(),v(e)}):this.Oe--}if(0===this.$t.length)return;let n=this.$t;this.$t=[];let r=this.target.$errorCallback;for(let[t,l]of n){e.Ge?.(this,t,l);let n=l.o.t,i=l.rn();if("function"==typeof r)try{let e=this.Te("$errorCallback",[t,{path:n,bindingType:i,node:l.l}]);Q(e)&&e.then(void 0,v)}catch(e){v(e)}else v(t,`[@wcstack/state] ${w(12,l.name?[i,n,l.name,l.i]:[i,n])}`,l.l)}}Te(e,t=[]){let n=this.target[e];return"function"==typeof n?this.Nn(n,null,t):void 0}wo(e,t,n){if(0===e.n)return void n(null,[]);let r=[],l=(i,s)=>{let o=e.h[i];this.read(o,s);let a=this.Ke(s,o),u=t=>{r.push(t.y),i===e.n?n(t,r):l(i+1,t),r.pop()};for(let e of i-1<t.length?[a.d[t[i-1]]]:a.d)void 0!==e&&u(e)};l(1,null)}getAll(e,t){let n=this.o(e,!0);void 0!==t&&this.Sn("$getAll",e,n,t,!1);let r=t;if(void 0===r){r=[];let t=this.f;if(null!==t&&n.n>0){for(let e=1;e<=n.n;e++){let l=le(t,n,e);if(null===l)break;r.push(l.y)}0===r.length&&A(6,[e])}}let l=[];return this.wo(n,r,e=>l.push(this.read(n,e))),l}kn(e,t,n,r){Array.isArray(t)||A(9,[e]),this.Le>0&&A(8);let l=this.o(e,!0);this.Sn("$setAll",e,l,t,!1);let i=[];this.wo(l,t,(e,t)=>i.push([e,t.slice()]));let s=!0===r?.spread;s&&(!Array.isArray(n)||n.length!==i.length)&&A(10,[e,i.length]);let o=0;for(let e=0;e<i.length;e++){let[t,r]=i[e],a="function"==typeof n?n(this.v(l,t),...r):s?n[e]:n;void 0!==a&&(this.C(l,t,a),o++)}return o}Sn(e,t,n,r,l){let i=r.length;(i>n.n||l&&i<n.n)&&A(l?901:902,[e,t,n.n,i])}},se={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},oe=()=>se,ae=new Map,ue=new Set(["if","elseif","else","for"]),ce=new Set([j,"if","elseif","for","..."]),fe=new Set([M,P,E,C,O,"state"]);function he(e){let t=function(e){return z(e,";")}(e).map(D).filter(e=>e.length>0).map(e=>{let t=q(e,":");-1===t&&A(101,[e]);let n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),l=n.split("#")[0].split("|")[0].trim();if(ce.has(l)){let t;return l!==n&&A(102,[e,l]),l===j?(r.length>0&&A(103,[e]),t={et:"#else",tt:[]}):"..."===l?(0===r.length&&A(104,[e]),t=_(r),t.tt.length>0&&A(105,[e])):(t=_(r),"for"===l&&t.tt.length>0&&A(121,[e])),{ye:l,we:[l],sn:[],M:[],...t,b:"..."===l?"spread":l}}(l===M||l===P)&&A(122,[e,l]);let i=_(r),s=function(e){let[t,n]=U(e,"input",ae),r=t.split("#").map(D);r.length>2&&A(115,[t]);let[l,i]=r,s=l.split(".").map(D);return!(s.length>1&&""===s[0])&&(0===l.length||s.some(e=>0===e.length))&&A(116,[e]),{ye:l,we:s,sn:i?i.split(",").map(D):[],M:n}}(n),[o]=s.we;if(""===o&&s.we.length>1){let e=s.we.slice(1);return(e.includes("")||fe.has(e[0]))&&A(106,[n]),{...s,ye:e.join("."),we:e,...i,b:"prop"}}return{...s,...i,b:"radio"===l||"checkbox"===l?l:o===O||o.startsWith("on")?"event":"prop"}});return t.length>1&&t.some(e=>ue.has(e.b))&&A(201,[e]),t}var de=["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"],pe=new Map,me=new Map;function ge(e){for(let t of Object.keys(e))pe.set(t,{...e[t]});me.clear()}function ye(e){return pe.has(e)}function be(e){A(26,[e])}function $e(e){A(27,[e])}function ve(e,t){A(28,[e,t])}function we(e,t){A(29,[e,t])}function Ae(e){return!(!e||isNaN(Number(e)))}function ke(e,t){return Ae(e)||$e(t),Number(e)}function xe(e,t,n){return ke(e?.[t]??be(n),n)}function Se(e,t){return void 0!==t&&t.length>0?t[0]:e}var Te=(e,t)=>({factory:n=>{let r=xe(n,0,e);return n=>("number"!=typeof n&&ve(e,n),t(n,r))},arity:[1,1]}),Ne={eq:{factory:(e,t)=>{let n=e?.[0]??be("eq"),r=Se(n,t);return e=>"number"==typeof e?"string"!=typeof r?e===r:(Ae(n)||$e("eq"),e===Number(n)):"string"==typeof e?e===n:e===r},arity:[1,1]},ne:{factory:(e,t)=>{let n=e?.[0]??be("ne"),r=Se(n,t);return e=>"number"==typeof e?"string"!=typeof r?e!==r:(Ae(n)||$e("ne"),e!==Number(n)):"string"==typeof e?e!==n:e!==r},arity:[1,1]},not:{factory:()=>e=>!e,arity:[0,0]},lt:Te("lt",(e,t)=>e<t),le:Te("le",(e,t)=>e<=t),gt:Te("gt",(e,t)=>e>t),ge:Te("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]}},je=!1;function Oe(e,t){if(null!==e)for(let n=0;n<e.length;n++)t=e[n](t);return t}function Ce(e){return 0===e.length?null:(je||(je=!0,ge(Ne)),e.map(e=>function(e,t,n){let r=`${e}${function(e,t){return`${JSON.stringify(e)}${JSON.stringify(t)}`}(t,n)}`,l=me.get(r);if(typeof l<"u")return l;let i=pe.get(e);void 0===i&&function(e,t){de.includes(e)&&$(`[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),A(501,[e],e,t)}(e,pe.keys());let[s,o]=i.arity;t.length<s&&A(601,[e,s,t.length]),t.length>o&&A(602,[e,o,t.length]);let a=i.factory(t,n);return me.set(r,a),a}(e.Kn,e.args,e.literals)))}var Me=Symbol.for("wcstack.trustedTypes.policy");function Pe(){let e=globalThis[Me];return null!==e&&"object"==typeof e?e:null}function Ee(e){globalThis[Me]=e}function We(e){return"innerHTML"===e||"outerHTML"===e||"srcdoc"===e}function Ie(e){if(globalThis.trustedTypes?.isHTML(e))return e;let t=null==e?"":String(e),n=Pe(),r=n?.createHTML;return"function"==typeof r?r.call(n,t):t}var Re=Symbol.for("wcstack.state.view-transition-naming"),De=new WeakSet;function Le(){let e=T("state");return null!==e&&"auto"===e.naming?e.namingLimit:-1}var qe=new WeakMap,ze=e=>e.customElementRegistry??customElements;function Ue(e,t,n,r,l,i=!1){let s=n.localName;if(!s.includes("-"))return l(null);let o=ze(n);if(!i&&!n.isConnected&&void 0===o.get(s)&&"customElementRegistry"in n)return void queueMicrotask(()=>Ue(e,t,n,r,l,!0));let a=()=>{let e=o.get(s);o.upgrade(n),l(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,bo:"event"===e.semantics});for(let e of t.inputs??[])n.inputs.add(e.name);for(let e of t.commands??[])null!==e&&"object"==typeof e&&"string"==typeof e.name&&n.commands.add(e.name)}return qe.set(e,n),n}(e):null)};if(!i&&void 0!==o.get(s))return a();null!==r&&!r.w||function(e,t,n){let r=n;null!==t&&(t.At??=[]).push(()=>{r=null}),e.then(()=>r?.())}(o.whenDefined(s),r,()=>{try{a()}catch(r){Ke(e,r,t,n)}e.$e()})}function Fe(t,n,r,l,i=n.o,s,o,a){let u=a.properties.get(l)??null,c=a.inputs.has(l),f=t.Kt;f&&null===u&&!c&&A(38,[l]);let h=n.q;(null===u?"element"===h||"auto"===h:!c&&("state"===h||"auto"===h))&&A(39,[h,l]),"connect"===n.J&&null===u&&A(40,[l]);let d=f&&null!==u&&!c,p=new Ge(t,Be,r,l,i,s,o,n.R,void 0);p.M=n.M,lt(t,p,!d),null!==u&&!n.ro&&r.addEventListener(u.event,n=>{let i;null!==u.getter?i=u.getter(n):(i=n.detail,u.bo||e.detail?.(r,l,i)),(!p.On||!Object.is(i,p.value))&&(i=Oe(p.M,i),null===p.R&&(p.value=i),t.C(p.o,p.r,i,u.bo,!0))});let m=h??(d?"element":"state");if("state"===m)d||t.ze(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.ze(p));let e=r[l];null===p.R&&(p.value=e),t.C(p.o,p.r,e,!1,!0)};"connect"!==n.J||r.isConnected?e():Promise.resolve().then(e)}return p}function Ve(e,t,n){A(e,[t.localName,n])}var _e=new Set(["click","dblclick","input","change","submit","keydown","keyup","mousedown","mouseup","pointerdown","pointerup"]),Be=11,He=["text","prop","prop","prop","prop","event","for","if","prop","radio","checkbox","prop","prop","event","spread"],Ke=(e,t,n,r)=>e.Zt(t,n.o?.t??n.Pt,r,He[n.i]),Je=Symbol();function Ye(e,t,n){let r=t.q;return null===r||"state"===r||"auto"===r&&void 0!==e.v(t.o,n)?t.z:Je}var Ge=class{constructor(e,t,n,r,l,i,s,o,a,u=null){this.re=!1,this.M=null,this.On=!1,this.engine=e,this.i=t,this.l=n,this.name=r,this.o=l,this.r=i,this.Fn=s,this.R=o,this.value=a,this.I=u}rn(){return He[this.i]}apply(){if(null!==this.I)return void this.I.Tt();let e=Oe(this.R,this.engine.read(this.o,this.r));if(e===this.value&&9!==this.i&&("object"!=typeof e||null===e||this.i===Be||8===this.i||We(this.name)))return;if(this.value===Je)return void(this.value=e);let t=this.l;if(this.i!==Be)9===this.i?t.checked=void 0!==e&&this.an()===e:10===this.i?t.checked=Array.isArray(e)&&e.includes(this.an()):Xe(this.i,t,this.name,e),this.value=e;else{if(void 0===e)return void(this.value=e);this.value=e,this.On=!0;try{t[this.name]!==e&&(t[this.name]=e)}finally{this.On=!1}}}an(){return Oe(this.M,this.l.value)}cr(){let e,t=this.l,n=this.engine;if(9===this.i){if(!t.checked)return;e=this.an()}else if(10===this.i){let r=this.an(),l=n.v(this.o,this.r),i=Array.isArray(l)?l:[],s=i.includes(r);if(t.checked?s:!s)return;e=s?i.filter(e=>e!==r):[...i,r]}else e=Oe(this.M,t[this.name]),this.value=NaN;n.C(this.o,this.r,e,!1,!0)}},Ze=e=>"textContent"===e||"innerText"===e||"innerHTML"===e;function Xe(e,t,n,r){switch(e){case 0:return void(t.data=null==r?"":String(r));case 1:return void(Ze(n)?t[n]="innerHTML"===n?Ie(r):null==r?"":String(r):We(n)?null==r&&"srcdoc"===n?t.removeAttribute(n):void 0!==r&&(t[n]=Ie(r)):void 0!==r&&(t[n]!==r&&!("value"===n&&t.value===String(r))&&(t[n]=r),("value"===n||"selectedIndex"===n)&&"select"===t.localName&&(t[Qe]=[n,r])));case 8:return void(t.innerHTML=Ie(r));case 2:return null!=r&&"boolean"!=typeof r&&A(401,[n,typeof r]),void t.classList.toggle(n,!0===r);case 3:return void(null==r?t.removeAttribute(n):t.setAttribute(n,String(r)));case 4:return void(n.includes("-")?null==r?t.style.removeProperty(n):t.style.setProperty(n,String(r)):t.style[n]=null==r?"":String(r))}}var Qe=Symbol();function et(e){let t="optgroup"===e.localName?e.parentNode:e,n=t?.[Qe];void 0!==n&&(t[n[0]]=n[1])}var tt=class{constructor(e,t,n,r){this.w=!0,this.Se=null,this.u=null,this.At=null,this.Dn=null,this.r=e,this.dt=t,this.L=n,this.$=r}nr(e,t){let n=t.target,r=this.$,l=[],i=null;for(let t of r.de){if(t.name!==e)continue;let s=r.ln[t.l],o=dt(null===this.L?this.dt:this.L[s[0]],s,1);o.contains(n)&&(o!==i&&l.unshift([]),l[0].push(t),i=o)}for(let e of l){for(let n of e)n.In(t,this.r);if(t.cancelBubble)return!0}return!1}get s(){return null===this.L?this.dt:this.L[this.L.length-1]}Re(){let e=this.Dn;return(null===e?null:e.jn(this.dt))??this.dt}insertBefore(e,t){let n=this.s;for(let r=this.Re();;){let l=r.nextSibling;if(e.insertBefore(r,t),r===n)return;r=l}}So(){null===this.L?this.dt.remove():pt(this.Re(),this.s)}Ae(e){if(this.w=!1,null!==this.At)for(let e of this.At)e();let t=this.Se;if(null!==t)for(let n=0;n<t.length;n++)e.Pn(t[n]);if(null!==this.u)for(let e of this.u)e.Ae()}},nt=class extends tt{constructor(e,t,n,r){super(e,t,n,r),this.Eo=0,this.U=null,this.me=0===r.Xe.length?null:new Array(2*r.Xe.length)}$o(e,t){let n=this.U??=new Array(this.$.Xe.length),r=n[t];if(void 0===r){let l=this.$.Xe[t],i=this.me;r=n[t]=new Ge(e,l.i,i[2*t],l.name,l.o,this.r,this,l.R,i[2*t+1])}return r}mo(e,t){let n=this.$.Xe;for(let r=0;r<n.length;r++)n[r].o.te(t)&&e.nn(this.$o(e,r))}Ae(e){let t=this.r;t.S===this&&(t.S=null),super.Ae(e)}};function rt(e,t,n,r){let l=re(n,t.n);try{return e.Ke(l,t)}catch(n){return e.Zt(n,t.t,r,"for"),null===l?e.H.get(t):l.u.get(t)}}function lt(e,t,n){n&&e.ar(t);let r=t.Fn;null!==r&&(r.Se??=[]).push(t)}var it=null;function st(){let e=it;return it=null,e}var ot=-1;function at(t,n,r,l,i=null){let s,o=n.ln,a=n.build,u=n.xo,c=null,f=e.Pe?.(n,null===l?i:l.E,null!==l),h=!f&&n.Mn,d=f?document.createDocumentFragment():(h?n.root:n.Ot).cloneNode(!0);if(!f)for(let e=0;e<a.length;e++){let t=a[e];u[t]=dt(d,o[t],h?1:0)}h?s=d:(c=f||[...d.childNodes],s=c[0]);let p,m=null;if(null!==l?(p=m=new nt(r,s,c,n),null===l.map?r.S=m:l.map.set(r,m)):p=new tt(r,s,c,n),ot>=0&&function(e,t,n,r){let l=null;if(null===t)l=1===e.nodeType?e:null;else for(let e=0;e<t.length&&null===l;e++)1===t[e].nodeType&&(l=t[e]);let i=l?.style;if(null===l||void 0===i||De.has(l))return;let s=globalThis[Re]??={counter:0,assigned:0,warned:!1};s.assigned>=r?s.warned||(s.warned=!0,console.warn(`[@wcstack/state] ${w(25,[r])}`)):(De.add(l),s.assigned++,i.setProperty("view-transition-name",`wcs-${n}-${++s.counter}`),i.setProperty("view-transition-class",`wcs-${n}`))}(s,c,null!==l?"row":"branch",ot),n.de.length>0){let e=t.qn;if(null===c)s[e]=p;else for(let t of c)1===t.nodeType&&(t[e]=p)}let g=n.No,y=t.We,b=n.ur?u.slice(0,o.length):u,$=null===m?null:m.me;if(null!==$){let e=n.Xe;for(let t=0;t<e.length;t++)$[2*t]=b[e[t].l],$[2*t+1]=e[t].z}for(let e=0;e<g.length;e++){let n=g[e],l=b[n.l],i=n.F;if(i>=0&&null!==$){let e=m.U?.[i];if(void 0!==e){e.re=!1,t.ze(e);continue}try{let e=Oe(n.R,t.read(n.o,r));e!==n.z&&(Xe(n.i,l,n.name,e),$[2*i+1]=e),null!==y&&t.yo(n.o,r)}catch(e){t.Rt(e,m.$o(t,i))}continue}switch(n.i){case 6:{let e=new ht(t,n.$,rt(t,n.o,r,l),l);(p.u??=[]).push(e),l===s&&(p.Dn=e),e.Tt();break}case 7:{let e=ct(t,n.W.map(e=>({$:e.$,o:e.o,R:e.R,E:b[e.l]})),r,p);(p.u??=[]).push(e),l===s&&(p.Dn=e);break}default:try{ut(t,n,l,r,p)}catch(e){Ke(t,e,n,l)}}}return it=p,d}function ut(t,n,r,l,i){let s=r;switch(n.i){case 5:return void function(e,t,n,r,l){let i=n.In,s=e=>i(e,r);if(n.ot){let r=e.fo(n.name),l=t[r];t[r]=void 0===l?s:e=>{l(e),s(e)},n.be&&t.addEventListener(n.name,e=>e.bubbles||s(e))}else t.addEventListener(n.name,s),n.ko&&null!==l&&(l.At??=[]).push(()=>t.removeEventListener(n.name,s))}(t,r,n,l,i);case 12:return void Ue(t,n,s,i,r=>function(t,n,r,l,i){let s=n.name,o=t.command(n.Pt.slice(9)),a=null===i?e.lr?.(r,s):null;a||(null===i&&Ve(1202,r,`command.${s}`),i.commands.has(s)||A(1203,[r.localName,s]));let u=new WeakRef(r),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!==l&&(l.At??=[]).push(c)}(t,n,s,i,r));case 13:return void Ue(t,n,s,i,e=>function(e,t,n,r,l){let i=t.name;null===l&&Ve(1202,n,`eventToken.${i}`);let s=l.properties.get(i);void 0===s&&A(1204,[n.localName,i]);let o=t.Pt;n.addEventListener(s.event,n=>{t.Ct&&n.preventDefault(),t.Ft&&n.stopPropagation();try{e.or(o,n,r)}catch(e){v(e)}})}(t,n,s,l,e))}let o=n.o,a=re(l,o.n);if(14===n.i)return void Ue(t,n,s,i,e=>function(e,t,n,r,l,i){null===i&&Ve(1501,n,`"...: ${t.o.t}"`);let s=new Set([...i.properties.keys(),...i.inputs]);for(let o of s){if(t.vo?.includes(o))continue;let s=e.o(`${t.o.t}.${o}`),a=0===s.n?null:r;Fe(e,{...t,q:null,J:null},n,o,s,a,l,i)}}(t,n,s,a,i,e));if(n.be&&1===n.i)return void Ue(t,n,s,i,r=>function(t,n,r,l,i,s){if(null!==s)return void Fe(t,n,r,n.name,n.o,l,i,s);let o=new Ge(t,1,r,n.name,n.o,l,i,n.R,Ye(t,n,l));o.M=n.M,!e.dr?.(o,n.ro)&&(lt(t,o,!0),t.ze(o))}(t,n,s,a,i,r));let u=new Ge(t,n.i,r,n.name,o,a,i,n.R,Ye(t,n,a));u.M=n.M,lt(t,u,!0),t.ze(u),null!==n.It&&r.addEventListener(n.It,()=>u.cr())}function ct(e,t,n,r){let l=new ft(e,t,n),i=null;for(let s of t){if(null===s.o)continue;let t=s.o,o=new Ge(e,7,s.E,"if",t,re(n,t.n),r,null,void 0,l);lt(e,o,!0),null===r&&l.ie.push(o),i??=o}return e.ze(i),l}var ft=class{constructor(e,t,n){this.w=!0,this.D=null,this.y=-1,this.ie=[],this.engine=e,this.W=t,this.r=n}jn(e){return null!==this.D&&this.W[this.y].E===e?this.D.Re():null}Tt(){let e=this.engine,t=-1;for(let n=0;n<this.W.length;n++){let r=this.W[n];if(null===r.o||Oe(r.R,e.read(r.o,re(this.r,r.o.n)))){t=n;break}}if(t!==this.y&&(ot=Le(),null!==this.D&&(this.D.So(),this.D.Ae(e),this.D=null),this.y=t,t>=0)){let n=this.W[t],r=at(e,n.$,this.r,null,n.E);this.D=st();let l=n.E.parentNode;l.insertBefore(r,n.E),et(l)}}Ae(){this.w=!1;for(let e of this.ie)this.engine.Pn(e);null!==this.D&&this.D.Ae(this.engine)}},ht=class{constructor(e,t,n,r){this.w=!0,this.Ce=[],this.engine=e,this.$=t,this.a=n,this.E=r,null===n.S?(n.S=this,this.map=null):((n.j??=[]).push(this),this.map=new Map)}jn(e){return 0===this.Ce.length?null:this.Ce[0].Re()}Dt(e){return null===this.map?e.S:this.map.get(e)??null}_t(e){let t=this.map;null!==t&&t.get(e.r)===e&&t.delete(e.r),e.Ae(this.engine)}Tt(){let e=this.engine,t=this.a.d,n=this.Ce;ot=Le();let r=t.length,l=n.length,i=this.E,s=i.parentNode;if(0===r){if(l>0){let e=n[0].Re(),t=n[l-1].s,r=[];for(let n=s.firstChild;null!==n;n=n===e?t.nextSibling:n.nextSibling)if(n!==e){if(n!==i&&3!==n.nodeType){r=null;break}r.push(n)}null!==r?s.replaceChildren(...r):pt(e,t);for(let e=0;e<l;e++)this._t(n[e])}return void(this.Ce=[])}let o=new Array(r),a=0;for(;a<r&&a<l&&this.Dt(t[a])===n[a];)o[a]=n[a],a++;let u=l-1,c=r-1;for(;u>=a&&c>=a&&this.Dt(t[c])===n[u];)o[c]=n[u],u--,c--;for(let e=a;e<=u;e++){let t=n[e],r=t.r;r.w&&this.Dt(r)===t?t.Eo=e:(t.So(),this._t(t))}if(a<=c){let n=c-a+1,u=new Int32Array(n),f=!1;if(l>0)for(let e=0;e<n;e++){let n=this.Dt(t[a+e]);null!==n&&n.w?(u[e]=n.Eo,f=!0):u[e]=-1}let h=c+1<r?o[c+1].Re():i;if(f){let r=function(e){let t=e.length,n=new Uint8Array(t),r=new Int32Array(t).fill(-1),l=[];for(let n=0;n<t;n++){let t=e[n];if(t<0)continue;let i=0,s=l.length;for(;i<s;){let n=i+s>>1;e[l[n]]<t?i=n+1:s=n}i>0&&(r[n]=l[i-1]),l[i]=n}let i=l.length>0?l[l.length-1]:-1;for(;i>=0;)n[i]=1,i=r[i];return n}(u),l=h;for(let i=n-1;i>=0;i--){let n=t[a+i],u=this.Dt(n);null!==u&&u.w?0===r[i]&&u.insertBefore(s,l):(s.insertBefore(at(e,this.$,n,this),l),u=st()),o[a+i]=u,l=u.Re()}}else{let n=document.createDocumentFragment();for(let r=a;r<=c;r++)n.appendChild(at(e,this.$,t[r],this)),o[r]=st();s.insertBefore(n,h)}}this.Ce=o,et(s)}Ae(){this.w=!1;let e=this.a;if(e.S===this)e.S=null;else if(null!==e.j){let t=e.j.indexOf(this);t>=0&&e.j.splice(t,1),0===e.j.length&&(e.j=null)}for(let e of this.Ce)e.Ae(this.engine);this.map?.clear()}};function dt(e,t,n){for(;n<t.length;n++){e=e.firstChild;for(let r=t[n];r>0;r--)e=e.nextSibling}return e}function pt(e,t){for(let n,r=e;r!==t;r=n)n=r.nextSibling,r.remove();t.remove()}var mt=()=>se.bindAttributeName;function gt(){return{l:0,i:1,name:"",o:null,R:null,z:c,In:null,$:null,W:null,M:null,It:null,be:!1,q:null,J:null,ro:!1,Ct:!1,Ft:!1,Pt:null,vo:null,F:-1,ot:!1,ko:!1}}var yt=["state","element","auto","none"],bt=["call","connect"],$t="$command.";function vt(t,n,r){W.test(n)&&(null===r&&A(1401,[n,Number(n.slice(1))]),n=`${r.t}.*.${n}`);let l=t.o(function(e,t){return 46!==e.charCodeAt(0)?e:(null===t&&A(1402,[e]),"."===e?`${t.t}.*`:`${t.t}.*${e}`)}(n,r)),i=null===r?0:r.n+1;l.n>i&&A(1401,[l.t,l.n,i]);for(let e=1;e<=l.n;e++){let t=e===i?r:r.h[e];l.h[e]!==t&&A(1403,[l.t,l.h[e].t,t.t])}return e.To?.(t,l),l}var wt=e=>1===e.i&&("outerHTML"===e.name||"outerText"===e.name),At=e=>8===e.i||wt(e)||1===e.i&&Ze(e.name);function kt(e){A(202,[e])}function xt(t,n,r,l,i){let s=he(n).map(n=>function(t,n,r,l,i){let s=function(e,t){let n=t.find(e=>e.startsWith("on")),r=null,l=null;for(let n of t){let t=n.indexOf("=");if(t<0)continue;e.Kt||A(31);let i=n.slice(0,t).trim(),s=n.slice(t+1).trim(),o="init"===i;!o&&"sync"!==i&&A(33,[i,n]),null!==(o?r:l)&&A(34,[i]),(o?yt:bt).includes(s)||A(35,[i,s]),o?r=s:l=s}return{ro:t.includes("ro"),Ct:t.includes("prevent"),Ft:t.includes("stop"),event:n?n.slice(2):null,q:r,J:l}}(t,n.sn),o=l.localName.includes("-"),a=n.we,u=n.et;if("event"===n.b){if(null!==s.q&&"none"!==s.q&&A(36),"eventToken"===a[0])return{...gt(),l:i,i:13,name:a.slice(1).join("."),Pt:u,be:o,Ct:s.Ct,Ft:s.Ft};let r=u.startsWith($t)?u.slice(9):null,{Ct:l,Ft:c}=s,f=n.ye.slice(2),h=n.sn.includes("direct"),d=!h&&_e.has(f);d&&t.fo(f);let p=n=>{v(n),d&&e.handlerThrew?.(t,u,f)};return{...gt(),l:i,i:5,name:f,ot:d,be:o,ko:h,In(e,n){l&&e.preventDefault(),c&&e.stopPropagation();try{if(null!==r)t.ir(r,e,n);else{let r=t.sr(u,e,n);Q(r)&&r.then(void 0,p)}}catch(e){p(e)}}}}if("spread"===n.b)return{...gt(),l:i,i:14,o:vt(t,u,r),be:o};if("command"===a[0]&&a.length>1)return u.startsWith($t)||A(1201,[n.ye,u]),{...gt(),l:i,i:12,name:a.slice(1).join("."),Pt:u,be:o};let c=vt(t,u,r),f={...gt(),l:i,i:1,name:n.ye,o:c,R:Ce(n.tt),M:Ce(n.M),ro:s.ro,q:s.q,J:s.J};if("radio"===n.b||"checkbox"===n.b)return("element"===s.q||"auto"===s.q)&&A(37,[n.b,s.q]),f.i="radio"===n.b?9:10,s.ro||(f.It=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.q=null,f.name=e,"class"===t?(f.i=2,f.z=l.classList.contains(e)):f.i="attr"===t?"srcdoc"===e&&"iframe"===l.localName?1:3:4,f}return"html"===n.ye?(f.i=8,f):(f.name="text"===n.ye?"textContent":n.ye,f.be=o&&!We(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}(l,f.name)&&(f.It=s.event??("select"===l.localName?"change":"input")),f)}(t,n,r,l,i));for(let e=0;e<s.length;e++)14===s[e].i&&(s[e].vo=s.slice(e+1).filter(e=>1===e.i).map(e=>e.name));return s}var St=/\{\{([\s\S]+?)\}\}/g;function Tt(e){let t=e.data,n=[],r=0;St.lastIndex=0;for(let l=St.exec(t);null!==l;l=St.exec(t)){let i=St.lastIndex-l[0].length;i>r&&e.before(t.slice(r,i));let s=e.ownerDocument.createTextNode("");e.before(s),n.push({l:s,fr:l[1].trim()}),r=St.lastIndex}return 0===n.length||(r<t.length&&e.before(t.slice(r)),e.remove()),n}function Nt(e,t,n,r){let l=function(e){return{ye:"textContent",we:["textContent"],sn:[],M:[],..._(e),b:"text"}}(t);return{...gt(),l:r,i:0,o:vt(e,l.et,n),R:Ce(l.tt),z:""}}function jt(e){let t=e.getAttribute(mt());if(null===t)return null;let n=he(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?se.commentIfPrefix:null===t.o?se.commentElsePrefix:se.commentElseIfPrefix;function Ct(e,t,n){let r=(t,r)=>({el:t,o:"else"===r.b?null:vt(e,r.et,n),R:"else"===r.b?null:Ce(r.tt)}),l=[r(t,jt(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=jt(e);if(null===t||"elseif"!==t.b&&"else"!==t.b||(l.push(r(e,t)),"else"===t.b))break}return l}var Mt=new WeakSet;function Pt(t,n,r,l,i,s,o,a){let u=(n,r)=>{let i=document.createComment(r);return n.replaceWith(i),l&&e.Ln?.(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(mt()+"-ignore"))continue;if(l){if("script"===a||"style"===a||Mt.has(n))continue;if(Mt.add(n),a===se.tagNames.state){c([...n.childNodes]);continue}}let f="template"===a?jt(n):null;if(null!==f){if("for"===f.b){let e=vt(t,f.et,r),l=It(t,n,e,!0);i(u(n,se.commentForPrefix),e,l)}else"if"===f.b?s(Ct(t,n,r).map((e,n)=>({$:It(t,e.el,r,!1),o:e.o,R:e.R,E:u(e.el,Ot(n,e))}))):kt(f.b);continue}let d=n.getAttribute(mt()),p=null===d?null:xt(t,d,r,n,0),m="noscript"!==a&&"iframe"!==a&&!p?.some(At)&&!e.Ro?.(n);try{l&&m&&c([...n.childNodes])}finally{null!==p&&o(n,p)}!l&&m&&c([...n.childNodes])}else if(3===h.nodeType&&t.Ht&&h.data.includes("{{")&&!Mt.has(h))for(let{l:e,fr:t}of Tt(h))a(e,t);else if(8===h.nodeType){let e=Et.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 Et=/^\s*@@\s*(?:wcs-text)?\s*:\s*([\s\S]+?)\s*$/,Wt=e=>{let t=document.createRange();return t.selectNodeContents(e),e.content??t.cloneContents()};function It(e,t,n,r){let l=document.importNode(Wt(t),!0),i=[],s=[],o=e=>i.push(e)-1;Pt(e,[...l.childNodes],n,!1,(e,t,n)=>{s.push({...gt(),l:o(e),i:6,o:t,$:n})},e=>{let t=e.map(e=>({l:o(e.E),$:e.$,o:e.o,R:e.R}));s.push({...gt(),l:t[0].l,i:7,W:t})},(e,t)=>{let n=o(e);for(let e of t)wt(e)&&A(203,[e.name]),e.l=n;s.push(...t),e.removeAttribute(mt())},(t,r)=>{s.push(Nt(e,r,n,o(t)))}),qt(l,new Set(i),!0);let a=i.map(e=>function(e,t){let n=[];for(let r=t;r!==e;r=r.parentNode){let e=0;for(let t=r.previousSibling;null!==t;t=t.previousSibling)e++;n.unshift(e)}return n}(l,e)),u=1===l.childNodes.length&&8!==l.firstChild.nodeType,c=s.some(e=>6===e.i||7===e.i),f=[],h=new Set,d=[],p=[],m=r?n.n+1:-1;for(let e of s){if(5===e.i&&e.ot&&!e.be&&!Rt(i[e.l],l)){d.push(e);continue}p.push(e);let t=e.o;if(null!==t&&t.n===m&&t.h[m]===n&&Dt(e)&&(e.F=f.push(e)-1),7===e.i)for(let t of e.W)h.add(t.l);else h.add(e.l)}let g=[...h].sort((e,t)=>e-t);return{Ot:l,root:u?l.firstChild:null,ln:a,build:g,de:d,No:p,Mn:u,ur:c,xo:[],Xe:f}}function Rt(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 Dt(e){if(null!==e.q)return!1;switch(e.i){case 0:case 2:case 3:case 4:case 8:return!0;case 1:return!e.be&&null===e.It;default:return!1}}var Lt=new Set(["table","thead","tbody","tfoot","tr","colgroup","select","optgroup","datalist"]);function qt(e,t,n){for(let r=e.firstChild;null!==r;){let e=r.nextSibling;3===r.nodeType?n&&!t.has(r)&&""===r.data.trim()&&r.remove():1===r.nodeType&&qt(r,t,Lt.has(r.localName)),r=e}}var zt=new WeakMap;function Ut(e,t){let n=9===t.nodeType?t.body:t;e.root=t,zt.set(t,e),Vt(e,[...n.childNodes]),e.Ye()}function Ft(e,t,n){try{let r="template"===t.localName?jt(t):null;null!==r&&!n&&A(204,[r.b]),Vt(e,[t])}catch(e){v(e)}e.Ye()}function Vt(t,n){Pt(t,n,null,!0,(e,n,r)=>{new ht(t,r,rt(t,n,null,e),e).Tt()},e=>{ct(t,e,null,null)},(n,r)=>{e.Ln?.(t,n,r);for(let e of r)ut(t,e,n,null,null)},(n,r)=>{e.Ln?.(t,n,r),ut(t,Nt(t,r,null,0),n,null,null)})}var _t=Symbol.for("wcstack.binder"),Bt=Symbol.for("wcstack.binder.pending"),Ht=Symbol.for("wcstack.binder.taken");var Kt=new Map;function Jt(e,t){if(1!==e.nodeType||!e.isConnected)return;let n=zt.get(e.getRootNode());void 0===n||!1===n.element?.isConnected?Kt.set(e,t):Ft(n,e,t?.range)}function Yt(){let e=[...Kt];Kt.clear();for(let[t,n]of e)Jt(t,n);!function(){let e=function(){let e=globalThis[_t];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[Bt];return void 0===t&&(t=[],e[Bt]=t),t}();if(0===t.length)return;let n=t.splice(0,t.length),r=function(){let e=globalThis,t=e[Ht];return void 0===t&&(t=new WeakSet,e[Ht]=t),t}();for(let t of n)r.add(t),e.bind(t)}()}var Gt=class{constructor(){this.name="dirty",this.ee=(e,t)=>{if(0===e.n){let t=e.G;return t!==c&&t!==f&&(e.G=f,!0)}let n=null===t?null:t.kt;if(null===n)return!1;let r=n[e.F];return r!==c&&r!==f&&(n[e.F]=f,!0)}}tr(e,t,n){null!==t.getter&&this.ee(t,n),e.Nt(t,n),e.An(t,n,this.ee)}zo(e,t){let n=t.a.o.Wt;if(null!==n)for(let r of n)r.n===t.a.n?e.ct(r,t,this.ee):e.tn(t,r,t=>e.ct(r,t,this.ee))}xe(t,n,r){this.ee(n,r),e.Ne?.(t,n,r),t.Nt(n,r),t.An(n,r,this.ee)}Yo(e,t,n){let r=0===t.n;if(!r&&null===n)return;let l=r?null:n.kt??=new Array(e.Me).fill(c),i=null===l?t.G:l[t.F];if(i!==c&&i!==f&&i!==h&&(null===l||t.F in l))return i;i=h;try{return i=e.Go(t,null===l?null:n)}finally{null===l?t.G=i:l[t.F]=i}}Jt(e){e.kt=null}nt(e){for(let t of e.O.all())null!==t.getter&&(0===t.n?t.G===f&&(t.G=h):e.on(t.h[t.n],e=>{let n=e.kt;null!==n&&n[t.F]===f&&(n[t.F]=h)}))}},Zt=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 en(e){let t=Xt.get(e)??[],n=t.filter(t=>t.getRootNode()===e);return Promise.any(n.map(e=>e.initializePromise.then(()=>e.U||e.connectedCallbackPromise))).then(()=>{},r=>n.length?Xt.get(e)!==t?en(e):Promise.reject(r.errors[0]):void 0)}var tn=typeof HTMLElement>"u"?class{}:HTMLElement,nn=class extends tn{constructor(){super(),this.engine=null,this.Wn=!1,this.Ge=!1,this.z=null,this.Je=null,this.loaded=!1,this.dn=null,this.connectedCallbackPromise=new Promise((e,t)=>{this.un=e,this.Ao=t}),this.connectedCallbackPromise.catch(()=>{}),this.initializePromise=new Promise(e=>{this.cn=e})}static{this.getBindingsReady=en}static{this.hasConnectedCallbackPromise=!0}connectedCallback(){if(this.Wn){if(null!==this.Je)return void this.Je.Qe();Qt(this);let t=this.engine;if(null!==t){let n=t.root;n===this.getRootNode()&&!zt.has(n)&&zt.set(n,t),Yt(),e.element?.(t,"back"),this.Po("$connectedCallback",50,()=>{this.isConnected&&e.element?.(t,"connected")})}return}this.Wn=!0;let t=this.getRootNode(),n=e.ft?.(this,t);if(n)return this.Je=n,!n.Co&&this.parentNode instanceof ShadowRoot&&Qt(this),void(void 0===n.Mt?this.Fo():n.Mt()).then(e=>(this.loaded=!0,n.start(e,()=>this.Oo()))).then(()=>{this.cn(),this.un()},e=>this.Rt(e,n.Co));this.start(t),Qt(this)}disconnectedCallback(){if(null!==this.Je)return void this.Je._n();let t=this.engine;if(null===t)return;let n=t.root;zt.get(n)===t&&zt.delete(n),Qt(this,n),this.Po("$disconnectedCallback",51),e.element?.(t,"disconnected")}setInitialState(e){if(this.Ge&&A(14),this.loaded)this.Je.reset(e);else if(null===this.engine)if(null!==this.dn){let t=this.dn;this.dn=null,t(e)}else this.z=e;else this.engine.reset(e)}createState(e,t){let n=this.engine;null===n&&A(15),"readonly"===e&&n.Le++;try{t(n.proxy)}finally{"readonly"===e&&n.Le--}}async createStateAsync(e,t){let n=this.engine;null===n&&A(15),await t("writable"===e?n.proxy:new Proxy(n.proxy,{get(e,t,n){let r=Reflect.get(e,t,n);return"$setAll"===t||"$resolve"===t?(...e)=>(e.length>2&&A(8),r(...e)):r},set(){A(8)}}))}async Fo(){await 0;let e=this.getAttribute("state");if(null!==e){let t=t=>[...t.querySelectorAll('script[type="application/json"]')].find(t=>t.id===e),n=t(this.getRootNode())??t(document);return void 0===n?Promise.reject(new Error(`[@wcstack/state] ${w(16,[e])}`)):Promise.resolve(JSON.parse(n.textContent||"{}"))}let t=this.getAttribute("src");if(null!==t)return async function(e){let t=new URL(e,document.baseURI).href;if(/\.json(?:[?#]|$)/.test(t)){let n=await fetch(t);return n.ok||A(13,[e,n.status]),await n.json()}return(await(import(globalThis[Symbol.for("wcstack.ssr.resolveModule")]?.(t)??t))).default??{}}(t);let n=this.getAttribute("json");if(null!==n)return Promise.resolve(JSON.parse(n));let r=this.querySelector('script[type="module"]');return null!==r?async function(e){let t=!1,n=e=>{e.effectiveDirective.startsWith("script-src")&&(t=!0)};document.addEventListener("securitypolicyviolation",n);let r="function"==typeof URL.createObjectURL,l=r?URL.createObjectURL(new Blob([e.text],{type:"application/javascript"})):"data:text/javascript;charset=utf-8,"+encodeURIComponent(`${e.text}\n//${++Zt}`);try{return(await(import(l))).default??{}}catch(e){throw await new Promise(e=>setTimeout(e)),new Error(`[@wcstack/state] ${t?w(42):w(43,[e instanceof Error?e.message:String(e)])}`,{cause:e})}finally{document.removeEventListener("securitypolicyviolation",n),r&&URL.revokeObjectURL(l)}}(r):null!==this.z?Promise.resolve(this.z):new Promise(e=>{this.dn=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 r=await this.Fo(),l=o(r);if(l&&await l,this.getRootNode()!==t)return this.z=r,this.Wn=!1,void(this.isConnected&&this.connectedCallback());this.hasAttribute("enable-ssr")&&a("ssr","enable-ssr");let i=zt.get(t)?.element;i?.isConnected&&(i.U||i.Je)&&A(47);let s=new ie(r,new Gt);s.element=this,this.engine=s,e.element?.(s,"mounting"),Ut(s,t),Yt(),s.Rn(),this.Oo(),await s.Te("$connectedCallback"),this.isConnected&&e.element?.(s,"connected"),this.un()}catch(e){this.Ge=!this.U,this.Rt(e)}}Oo(){this.U=!0,this.cn()}Rt(e,t){this.Ye(this.U?50:49,e),this.cn(),t?this.un():this.Ao(e)}Ye(e,t){let n=["mount","bind-component","state","src"].flatMap(e=>this.hasAttribute(e)?[e,this.getAttribute(e)]:[]);v(t,`[@wcstack/state] ${w(e,[this.localName,...n])}`)}Po(e,t,n){(async()=>this.engine.Te(e))().then(n,e=>this.Ye(t,e))}},rn=[];function ln(){return(rn=rn.filter(e=>e.deref())).map(e=>e.deref())}var sn,on=e=>en(e),an=e=>t=>{let n=e(t);return e=>null==e?e:n(e)},un="en";function cn(){if(se.locale!==sn){sn=se.locale;try{un=Intl.getCanonicalLocales(sn)[0]}catch{console.warn(`[@wcstack/state] ${w(48,[sn])}`),un="en"}}return un}var fn=["full","long","medium","short"];function hn(e,t){let[n,r,l]=(e??[]).map(e=>e||void 0);!r&&fn.includes(n)?[n,r]=[void 0,n]:!r&&!l&&/\/|^UTC$/.test(n)&&([n,l]=[void 0,n]),r&&!fn.includes(r)&&function(e,t){A(52,[e,t])}(t,r);try{l&&new Intl.DateTimeFormat(void 0,{timeZone:l})}catch{A(54,[t,l])}return[n,r,l]}var dn=e=>String(e).padStart(2,"0"),{eq:pn,ne:mn,not:gn,lt:yn,le:bn,gt:$n,ge:vn,falsy:wn,truthy:An,boolean:kn}=Ne,xn={toFixed:{factory:e=>{let t=ke(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 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=[xe(e,0,"slice")],n=e?.[1];return typeof n<"u"&&t.push(ke(n,"slice")),e=>String(e).slice(...t)}),arity:[1,2]},padStart:{factory:an(e=>{let t=xe(e,0,"padStart"),n=e?.[1]??"0";return e=>String(e).padStart(t,n)}),arity:[1,2]},padEnd:{factory:an(e=>{let t=xe(e,0,"padEnd"),n=e?.[1]??" ";return e=>String(e).padEnd(t,n)}),arity:[1,2]},repeat:{factory:an(e=>{let t=xe(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=xe(e,0,"truncate"),n=e?.[1]??"…";return e=>{let r=String(e);return r.length<=t?r:r.slice(0,t)+n}}),arity:[1,2]},join:{factory:e=>{let t=e?.[0]??", ";return e=>(Array.isArray(e)||A(30,["join"]),e.join(t))},arity:[0,1]},round:{factory:e=>{let t=Math.pow(10,ke(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,ke(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,ke(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=ke(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]??be("unit");return e=>String(e)+t}),arity:[1,1]},date:{factory:an(e=>{let[t,n,r]=hn(e,"date"),l=(n||r)&&{dateStyle:n,timeZone:r};return e=>(e instanceof Date||we("date",e),e.toLocaleDateString(t??cn(),l))}),arity:[0,3]},time:{factory:an(e=>{let[t,n,r]=hn(e,"time"),l=(n||r)&&{timeStyle:n,timeZone:r};return e=>(e instanceof Date||we("time",e),e.toLocaleTimeString(t??cn(),l))}),arity:[0,3]},datetime:{factory:an(e=>{let[t,n,r]=hn(e,"datetime"),l=(n||r)&&{dateStyle:n,timeStyle:n,timeZone:r};return e=>(e instanceof Date||we("datetime",e),e.toLocaleString(t??cn(),l))}),arity:[0,3]},ymd:{factory:an(e=>{let t=e?.[0]??"-";return e=>(e instanceof Date||we("ymd",e),`${e.getFullYear()}${t}${dn(e.getMonth()+1)}${t}${dn(e.getDate())}`)}),arity:[0,1]},hms:{factory:an(e=>{let t=e?.[0]??":";return e=>(e instanceof Date||we("hms",e),`${dn(e.getHours())}${t}${dn(e.getMinutes())}${t}${dn(e.getSeconds())}`)}),arity:[0,1]},eq:pn,ne:mn,not:gn,lt:yn,le:bn,gt:$n,ge:vn,add:Te("add",(e,t)=>e+t),sub:Te("sub",(e,t)=>e-t),mul:Te("mul",(e,t)=>e*t),div:Te("div",(e,t)=>e/t),mod:Te("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=xe(e,0,"clamp"),n=xe(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:wn,truthy:An,defaults:{factory:(e,t)=>{let n=Se(e?.[0]??be("defaults"),t);return e=>e||n},arity:[1,1]},coalesce:{factory:(e,t)=>{let n=Se(e?.[0]??be("coalesce"),t);return e=>e??n},arity:[1,1]},boolean:kn,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]??be("currency"),n=e?.[1],r={style:"currency",currency:t};try{new Intl.NumberFormat("en",r);let e=Intl.supportedValuesOf?.("currency");if(e&&!e.includes(t.toUpperCase()))throw 0}catch{!function(e){A(53,[e])}(t)}return e=>("number"!=typeof e&&ve("currency",e),e.toLocaleString(n??cn(),r))},arity:[1,2]}},Sn=Object.fromEntries(Object.entries(xn).filter(([e])=>!(e in Ne))),Tn=!1,Nn={name:"formats",hooks:e,install:function(){Tn||(Tn=!0,ge(xn))}};function jn(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let r=new Array(t.length+1),l=new Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let n=1;n<=e.length;n++){l[0]=n;for(let i=1;i<=t.length;i++){let s=e[n-1]===t[i-1]?0:1;l[i]=Math.min(r[i]+1,l[i-1]+1,r[i-1]+s)}for(let e=0;e<=t.length;e++)r[e]=l[e]}return r[t.length]}function On(e,t){if(0===e.length)return"";let n=e.toLowerCase(),r=null,l=3;for(let e of t){let t=jn(n,e.toLowerCase(),2);t<l&&(r=e,l=t)}return null!==r?` Did you mean "${r}"?`:""}var Cn=" Validate statically: npx @wcstack/lint <file>.",Mn=["","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"],Pn=e=>{let t=Mn[e/100|0];return t?`[wcs/${t}] `:""},En=["enableMustache","sameValueGuard","enableDirectionalInitialSync"],Wn=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)})`,In=["","","class.","attr.","style."],Rn=(e,t)=>`<${e}${t.map((e,t)=>t%2?`="${e}"`:` ${e}`).join("")}>`,Dn="https://github.com/wcstack/wcstack/blob/main/docs/csp.md",Ln={1:()=>"$scan was removed (use $watch or $on)",2:e=>`"${e}" is a getter without a setter`,3:e=>`no row for "${e}"`,4:(e,t)=>`cannot write "${e}": its parent is ${t}`,5:e=>`"${e}" is not a method`,6:e=>`$getAll("${e}"): no loop level in common with the context`,7:e=>`$eqIndex("${e}") needs a list row scope.`,8:()=>"This state is readonly.",9:e=>`$setAll("${e}") needs indexes ([] for every match)`,10:(e,t)=>`$setAll("${e}", …, { spread: true }) needs an array of ${t} values`,11:()=>"updates did not settle after 32 passes",41:()=>"render chain depth limit exceeded (100 drains that rendering itself started); bindings for this batch were not applied.",12:(e,t,n,r)=>`binding "${n?(In[r]??"")+n:e}: ${t}" failed to apply.`,13:(e,t)=>`failed to load "${e}": ${t}`,14:()=>"this <wcs-state> failed to initialize; create a new one",15:()=>"state is not initialized",16:e=>`no <script> with id "${e}"`,42:()=>`The inline <script> of <wcs-state> was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${Dn}`,43:e=>`Failed to evaluate the inline <script> of <wcs-state>: ${e}. If this page sets a Content-Security-Policy, see ${Dn}`,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 ${Wn(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 ${Wn(t)}${"string"==typeof t||"number"==typeof t?" — make the Date where it is read: a getter returning new Date(…)":""}${"string"==typeof t&&/^\d{4}-\d\d-\d\d$/.test(t)?`. A date-only string is a day, not a moment: new Date(${JSON.stringify(t)}) is midnight UTC, the day before west of Greenwich — new Date(y, m - 1, d) is that day where the page is`:""}`,52:(e,t)=>`filter ${e} takes a style of full, long, medium or short, not "${t}"${/\/|^UTC$/.test(t)?` — a time zone is the third argument, after the locale and the style, and an empty argument keeps its default: ${e}(,,${t}), ${e}(en-US,long,${t})`:""}`,53:e=>`filter currency takes an ISO 4217 currency code (JPY, USD, EUR), not "${e}"`,54:(e,t)=>`filter ${e} takes an IANA time zone (Asia/Tokyo, America/New_York, UTC), not "${t}"`,30:e=>`filter ${e} requires an array value`,31:()=>"init=/sync= modifiers require enableDirectionalInitialSync.",33:(e,t)=>`Unknown binding modifier "${e}" in "${t}".`,34:e=>`Binding modifier "${e}" may only be specified once.`,35:(e,t)=>`Invalid ${e} modifier value "${t}".`,36:()=>"Event bindings only allow init=none.",37:(e,t)=>`Binding type "${e}" does not support init=${t}.`,38:e=>`Property "${e}" is not declared by wcBindable.`,39:(e,t)=>`init=${e} is incompatible with wcBindable member "${t}".`,40:e=>`sync=connect requires observable property "${e}".`,44:(e,t)=>`${e}: "${t}" is not one of its options, or not of the option's type.${"bootstrapState"===e&&En.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)=>`${Rn(e,t)} failed to initialize.`,50:(e,...t)=>`${Rn(e,t)} $connectedCallback failed.`,51:(e,...t)=>`${Rn(e,t)} $disconnectedCallback failed.`,101:e=>`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`,102:(e,t)=>`"${e}": "${t}" takes no modifiers or filters on its left side — write "${t}:".`,103:e=>`"${e}": "else" takes no value — write "else:".`,104:e=>`Invalid spread binding "${e}": spread target path is required.`,105:e=>`Invalid spread binding "${e}": filters are not allowed on spread targets.`,106:e=>`"${e}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (class, attr, style, command, eventToken, state).`,107:(e,t)=>`unterminated ${e} quote in the filter arguments "(${t})". Close the quote.`,108:e=>`Invalid filter format: missing closing parenthesis in "${e}".`,109:e=>`Invalid filter format: missing opening parenthesis in "${e}".`,110:e=>`Invalid filter format: ")" comes before "(" in "${e}".`,111:(e,t)=>`"${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,e.lastIndexOf(")")+1)}|${t}").`,112:e=>`an empty filter in "${e}" — remove the extra "|" or name the filter.`,113:(e,t)=>`"${e}" is not a filter name: a modifier list "#${t}" comes before the input filters, not inside one`,114:e=>`"${e}" is not a filter name: "#" cannot appear in one.`,115:e=>`"${e}": a binding takes one modifier list after a single "#"`,116:e=>`"${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).`,117:(e,t)=>`"${e}" has ${t} path segments — the limit is 512.`,32:e=>`"${e}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`,120:e=>`"${e}": a state path cannot go through "__proto__" or "prototype" (it would reach every object's prototype).`,121:e=>`"${e}": "for:" takes no filters — a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,122:(e,t)=>"class"===t?`"${e}": "class:" needs a class name — "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".`:`"${e}": "attr:" needs an attribute name — "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,119:e=>`"${e}": the right side of a binding must name a state path — write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).`,201:e=>`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`,202:e=>`"${e}:" must follow an "if:" template`,204:e=>`a "${e}:" template at the top of inserted content was not rendered, as it would render beside itself out of the inserter's reach: wrap it in an element.`,203:e=>`"${e}:" replaces its element, so it cannot be used inside a "for" / "if" template (a row or branch keeps its nodes by position): bind innerHTML: on a wrapper element instead.`,301:e=>`Path "${e}" does not exist on the state tree.`,401:(e,t)=>`class.${e} needs a boolean, got ${t}.`,501:e=>`filter not found: ${e}.`,601:(e,t,n)=>`filter "${e}" requires at least ${t} argument(s) (${n} given).`,602:(e,t,n)=>`filter "${e}" accepts at most ${t} argument(s) (${n} given).`,701:e=>`"${e}" depends on itself`,801:e=>`"${e}"`,901:(e,t,n,r)=>`${e}("${t}") takes ${n} index(es), got ${r}.`,902:(e,t,n,r)=>`${e}("${t}") takes at most ${n} index(es), got ${r}.`,1001:e=>`"${e}": list index parameters run from $1 to $128.`,1101:e=>`"${e}" uses "**", which is not accepted here.`,1201:(e,t)=>`"${e}: ${t}": the right-hand side must be $command.<name>`,1202:(e,t)=>`<${e}> declares no static wcBindable (${t}).${!e.includes("-")&&t.startsWith("command.")?" A native element's command needs the add-on @wcstack/state/features/native-commands.":""}`,1203:(e,t)=>`<${e}> declares no command "${t}".`,1204:(e,t)=>`<${e}> declares no property "${t}".`,1205:(e,t,n)=>`<${e}> has no command "${t}" (a native <${e}>'s commands: ${n}).`,1301:e=>`eventToken "${e}" is not declared in $eventTokens.`,1302:e=>`"$command.${e}" is not declared in $commandTokens.`,1401:(e,t,n=0)=>`"${e}" needs ${t} enclosing loop level(s); the scope provides ${n}.`,1402:e=>`"${e}" is relative: it needs an enclosing "for" template`,1403:(e,t,n)=>`"${e}" ranges over the rows of "${t}", but the enclosing "for" template at that level renders "${n}".`,1501:(e,t)=>`<${e}> declares no static wcBindable (${t}).`,1601:(e,t)=>`${e} was removed: write ${t}.`,1701:(e,t)=>`${e} was removed: write ${t}.`};function qn(e,t){let n=Ln[e];return void 0===n?`${Pn(e)}#${e} ${t.join(" ")}`:Pn(e)+n(...t)}var zn=new Set(["binding-syntax","template-syntax","filter-unknown","filter-arity","index-arity","wildcard-rank","token-undeclared","binding-path-missing","index-param-range"]),Un=[[/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.']],Fn={inc:"add",dec:"sub",fix:"toFixed",uc:"upper",lc:"lower",cap:"capitalize",rep:"repeat",rev:"reverse",pad:"padStart",null:"nullIfEmpty"};function Vn(e,t,n){let r=(void 0!==t&&e.includes("[wcs/filter-unknown]")?function(e){if("substr"===e)return' "substr" was removed in 4.0 — write slice(start, start + length): slice takes the end index, not a length.';let t=Object.hasOwn(Fn,e)?Fn[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 Un){let l=t.exec(e);null!==l&&(r+=n.replace(/\$(\d)/g,(e,t)=>l[Number(t)]))}let l=/"([^"#]+)#([^"]+)": a binding takes one modifier list/.exec(e);null!==l&&(r+=` — write "${l[1]}#${l[2].split("#").join(",")}".`),e.includes("[wcs/filter-unknown]")&&(e.includes("formats add-on")?r+=' On a split auto page: features="formats" on the root, or "$features": ["formats"].':de.some(ye)||(r+=' No formatting filters are installed — add the formats add-on: installFeatures([formats]) from "@wcstack/state/features/formats" (a split auto page: features="formats", or "$features").'));let i=/\[wcs\/([\w-]+)\]/.exec(e);return null!==i&&zn.has(i[1])&&!/ path segments — the limit is |inserted content was not rendered|formats add-on/.test(e)&&(r+=Cn),r}var _n=new WeakMap,Bn=new WeakMap,Hn=new WeakSet,Kn=new WeakSet;function Jn(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 Yn(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 Gn(e,t){let n=[];for(let e=t;null!==e;e=e.c)n.unshift(e);let r=t=>null===t?null:function(e,t){let n=t.t.split("."),r=n.findIndex((e,t)=>t>0&&/^\d/.test(e));return r<0||n.indexOf("*",r)>=0||void 0!==Jn(e.target,t.t)?.get?t:e.O.vt(m(t.t).o)}(e,t);return n.some(e=>null!=r(e)?.getter)?null:Zn(e,n,0,e.target,r)}function Zn(e,t,n,r,l){for(;n<t.length;n++){let i=t[n];if(null===r||"object"!=typeof r)return null;if("*"===i.s){if(!Array.isArray(r)||0===r.length)return null;let i=null;for(let s of r){let r=Zn(e,t,n+1,s,l);if(null===r)return null;if(null===i)i=r;else if(r.seg===i.seg)for(let e of r.names)i.names.includes(e)||i.names.push(e)}return i}if(Array.isArray(r)&&/^\d+$/.test(i.s)){if(Number(i.s)>=r.length)return null;r=r[Number(i.s)];continue}let s=Jn(r,i.s);if(void 0===s&&null===i.c&&e.nt.has(i.s))return null;if(void 0===s){let s=Yn(r),o=l(i.c);for(let t of e.O.all())t.c===o&&null!==t.getter&&s.push(t.s);return n>0&&0===s.length?null:{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;r=s.value}return null}function Xn(t){Hn.has(t)||(Hn.add(t),setTimeout(()=>function(t){Hn.delete(t);let n=_n.get(t);if(void 0===n)return;let r=Bn.get(t);void 0===r&&Bn.set(t,r=new Set);let l=new Map(n),i=new Map;for(let e of t.O.all()){let t=null===e.c||r.has(e)||n.has(e)?void 0:e._.find(e=>!e.gn);void 0!==t&&(i.set(e,t),l.set(e,3))}for(let[n,s]of l){if(r.has(n))continue;r.add(n);let l=Gn(t,n);if(null===l)continue;let o=lr.get(t),a=n.c;for(;null!==a&&!o?.has(a);)a=a.c;if(null!==a)continue;let u=[...t.root?.querySelectorAll(`${se.tagNames.state}[mount]`)??[]].find(e=>!Kn.has(e)&&(n.t+".").startsWith(e.getAttribute("mount")+"."));if(void 0!==u){r.delete(n),u.initializePromise.then(()=>{Kn.add(u),Xn(t)});continue}let c=t.O.vt(m(n.t).o),f="";if(void 0!==c&&c!==n&&null!==c.getter){let e=c.h.slice(1).map((e,t)=>`for: ${0===t?e.t:e.t.slice(c.h[t].t.length+2)}`);f=` The getter "${c.t}" is declared for the rows of ${e.join(" → ")}; a list named by an index has rows of its own.`}let h=On(l.seg,l.names);if((l.r||3===s)&&""===h&&""===f)continue;let[d,p,g]=1===s?["watch-path-missing","$watch path","watch"]:2===s?["post-update-path-missing","$postUpdate path","postUpdate"]:3===s?["read-path-missing","Path","getter"]:["binding-path-missing","Bound path","binding"];e.ut?.(t,{type:"state:path-unresolved",source:g,path:n.t,missingSegment:l.seg}),console.warn(`[@wcstack/state] [wcs/${d}] ${p} "${n.t}"${3===s?` read by the getter "${i.get(n).t}"`:""} does not resolve on the state tree: "${l.seg}" is not declared.${h}${f} ${2===s?"The call updates nothing.":3===s?"The getter reads undefined.":"Updates to this path will be silently dropped."}${Cn}`)}}(t),0))}function Qn(e,t,n=!1){er(e,t,n?1:0)}function er(e,t,n){if("$"===t.t[0]||t.t.includes("#")||0===n&&null===t.c)return;let r=_n.get(e);void 0===r&&_n.set(e,r=new Map),r.has(t)||r.set(t,n),Xn(e)}var tr=new WeakSet,nr=!1,rr=new WeakMap,lr=new WeakMap;function ir(e,t,n,r,l,i,s){if(!s)return;let o=lr.get(e);void 0===o&&lr.set(e,o=new Set),o.add(t)}function sr(e,t){let n=rr.get(e),r=t.s;if(null!==t.c||nr||void 0===n||n.has(r)||"$"===r[0]||e.nt.has(r))return;let l=On(r,[...n]);n.add(r),""!==l&&![...e.root?.querySelectorAll(`${se.tagNames.state}[mount]`)??[]].some(e=>`${e.getAttribute("mount")}.`.startsWith(`${r}.`))&&console.warn(`[@wcstack/state] [wcs/write-path-missing] "${r}" is not declared: writing it creates a new key.${l}${Cn}`)}var or=new WeakSet;function ar(e){if(or.has(e))return;or.add(e);let t=e.emit,n=!1;e.emit=(...r)=>(0===e.size&&!n&&(n=!0,console.warn(`[@wcstack/state] [wcs/command-token-unbound] "$command.${e.name}" was emitted with no subscriber and is lost: its element is not defined or rendered yet (emit from $renderedCallback), or no command. binding takes it.${Cn}`)),t.apply(e,r))}var ur=new WeakMap;function cr(e,t,n){let r=e.target;for(let e of t.split("."))r=null==r?void 0:Jn(r,e)?.value;if("function"!=typeof r||!String(r).includes("currentTarget"))return;let l=ur.get(e);void 0===l&&ur.set(e,l=new Set),!l.has(t)&&(l.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(…).${Cn}`))}var fr=new WeakSet,hr=/\bthis\s*[.[]|=\s*this\b/,dr=new WeakSet,pr=e=>{for(let t of["src","state","json"])if(e.hasAttribute(t))return`<${e.localName} ${t}${"json"===t?"":`="${e.getAttribute(t)}"`}>`;return`<${e.localName}>`};function mr(e,t){let n=e.element;if("mounting"!==t||!n)return;let r=n.getRootNode();if(dr.has(r))return;let l=[...r.querySelectorAll(se.tagNames.state)].filter(e=>e!==n&&!e.hasAttribute("mount")&&!e.hasAttribute("bind-component"));0!==l.length&&(dr.add(r),console.warn(`[@wcstack/state] [wcs/second-root] ${l.length+1} root <wcs-state> elements share one root, and there is one state tree per root: ${pr(n)} takes it — its state was ready first, whatever the order in the document — and ${l.map(pr).join(", ")} is refused (#47). Keep one, and graft the others with <wcs-state mount="path">.${Cn}`))}var gr=new Set,yr=new WeakSet,br=/^(?:(?:attr|class|style)\.|(?:html|innerHTML|outerHTML|srcdoc)$)/;function $r(e){try{return null!==e&&he(e).some(e=>"spread"===e.b||"eventToken"===e.we[0]||"prop"===e.b&&!br.test(e.ye))}catch{return!1}}function vr(e,t){for(let n of e.No){null!==n.$&&vr(n.$,t);for(let e of n.W??[])vr(e.$,t);if(n.be&&5!==n.i){let r=e.Ot;for(let t of e.ln[n.l])r=r.childNodes[t];t.add(r.localName)}}}function wr(e,t){if("connected"!==t||yr.has(e)||document.documentElement.hasAttribute("data-wcs-server"))return;yr.add(e);let n=new WeakRef(e),r=()=>{setTimeout(()=>{let e=n.deref();e?.element?.isConnected&&function(e){let t=new Set;for(let n of e.H.values())for(let e of[n.S,...n.j??[]])null!==e&&vr(e.$,t);for(let n of e.ie.values())for(let e of n)for(let n of e.I?.W??[])vr(n.$,t);let n=se.bindAttributeName;for(let r of e.root.querySelectorAll("*")){let e=r.localName;!e.includes("-")||gr.has(e)||void 0!==(r.customElementRegistry??customElements).get(e)||!t.has(e)&&!$r(r.getAttribute(n))||null!==r.closest(`[${n}-ignore]`)||(gr.add(e),console.warn(`[@wcstack/state] [wcs/element-undefined] <${e}> is not defined 5 s after the page was ready; its bindings wait for it (property bindings, textContent: included, spreads, commands, event tokens — attr.*, class.*, style.* and on*: apply at once). Load the ${e.startsWith("wcs-")?"wcstack package that defines it (its /auto)":"script that defines it"}.`))}}(e)},5e3)};"complete"===document.readyState?r():addEventListener("load",r,{once:!0})}var Ar=new WeakSet;function kr(e,t){let n,r=t.o;if(!(Ar.has(r)||t.d.length>0)){try{n=e.v(r,t.oe)}catch{return}null==n||Array.isArray(n)||queueMicrotask(()=>{null===t.S||Ar.has(r)||(Ar.add(r),console.warn(`[@wcstack/state] [wcs/binding-type-expectation] "for: ${r.t}" needs an array, not ${Wn(n)}: it renders no rows (null and undefined render none on purpose).${Cn}`))})}}function xr(e){_n.has(e)&&e.Ue.length>0&&Xn(e);for(let t of e.H.values())null!==t.S&&null!==t.T&&kr(e,t)}var Sr=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Tr=!1;function Nr(e,t,n){let r="html"===n.name?"innerHTML":n.name;if(Tr||!(t instanceof TypeError)||!We(r)||!("trustedTypes"in globalThis))return;Tr=!0;let l="function"==typeof Pe()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${r}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${l}\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.l,property:r})}var jr=new WeakMap;function Or(e,t,n){let r=e[t],l=void 0===n?void 0===r?null:`the event carried no detail (undefined) while element.${t} is ${typeof r}`:null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==r&&"object"==typeof r?null:`the event's detail is an object with a "${t}" key while element.${t} is ${typeof r}`;if(null===l)return;let i=jr.get(e);void 0===i&&jr.set(e,i=new Set),!i.has(t)&&(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.localName}> "${t}": ${l}. 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 Cr=[["$streams","$stream"],["$updatedCallback","$renderedCallback"]],Mr={$trackDependency:"$dependOn",$untrackDependency:"$untracked"},Pr={name:"diagnostics",hooks:e,install(){e.Vo=Vn,e.Ho=qn,e.To=Qn,e.detail=Or,e.Ge=t(e.Ge,Nr);let r=e.pe;e.pe=(e,t)=>{(function(e){void 0!==e.$scan&&A(1);for(let[t,n]of Cr)void 0!==e[t]&&A(1601,[t,n])})(t),r?.(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[r,l]=n[0];if(!r.endsWith(".*")||!l.endsWith(".*"))return;let i=r.slice(0,-2),s=l.slice(0,-2),o=`.${l}`,a=`${i}.**`,u=Yn(e),c=u.filter(e=>e.startsWith(a)).map(e=>e.slice(a.length)),f=e=>$(`[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(`^(?:${Sr(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 "${l}"). Rename one of them.`);let t=new RegExp(`^${Sr(r)}(?:${Sr(o)})*${Sr(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){let t=Jn(e,"$on")?.value;if(null!==t&&"object"==typeof t)for(let e of Object.keys(t)){let n=t[e];"function"!=typeof n||fr.has(n)||!hr.test(String(n))||(fr.add(n),console.warn(`[@wcstack/state] [wcs/on-handler-this] The $on handler "${e}" uses this. A $on handler is called as ${e}(state, event): this is undefined there, so it throws when the event arrives — write ${e}(state, event) { state.x = … }.${Cn}`))}}(t),function(e){Bn.delete(e),_n.has(e)&&Xn(e)}(e),function(e){if(tr.has(e))return;tr.add(e);let t=e.Jn,n=t.$postUpdate;t.$postUpdate=t=>{nr=!0;try{n(t)}finally{nr=!1}let r=e.O.vt(m(t).o);void 0!==r&&er(e,r,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))ar(t)}})}(e),rr.set(e,new Set(Yn(t)))},e.handlerThrew=cr,e.element=t(t(e.element,mr),wr),e.se=t(t(e.se,sr),ir),e.he=t(e.he,xr),e.st=t(e.st,kr),e.it=n(l,e.it,(e,t)=>Object.hasOwn(Mr,t)?A(1701,[t,Mr[t]]):void 0)}},Er={},Wr=/\.\d/,Ir=new Set(Object.getOwnPropertyNames(Object.prototype)),Rr=0,Dr=!1,Lr=null,qr=()=>{Dr=!1,Rr++};function zr(){if(null===Lr)if("function"==typeof MessageChannel){let e=new MessageChannel;e.port1.onmessage=qr,e.port1.unref?.(),Lr=()=>e.port2.postMessage(0)}else Lr=()=>setTimeout(qr,0);return Dr||(Dr=!0,Lr()),Rr}function Ur(e,t){let n=new Set,r=[e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of e.Z){for(let r of t)if(n.te(r)&&(n.n===r.n||!(r.n<e.n&&e.h[r.n+1].te(r))))return!0;null!==n.getter&&r.push(n)}}}return!1}var Fr=class{constructor(e,t){this.active=!1,this.Fe=new Map,this.early=[],this.n=0,this.Do=-1,this.Bn=new Set,this.qe=null,this.engine=e,this.De=t}pr(){let e=this.engine;this.Fe.clear();let t=this.early;this.early=[];for(let t of this.De)t.getter=null!==t.p.getter||t.p.ue,t.s=new WeakMap,this.prime(t,()=>{0===t.p.n?t.getter&&t.s.set(Er,e.v(t.p,null)):this.Vn(t.p,1,null,n=>{t.getter&&this.prime(t,()=>t.s.set(n,e.v(t.p,n)))})});this.active=!0;let n=new Set;for(let[r,l,i,s]of t)if((null===l||l.w)&&Object.is(e.v(r,l),s)){n.add(r);for(let e of this.De)e.p===r&&this.pt(e,l,i,!0)}for(let e of this.De)e.getter&&0===e.p.n&&!this.Fe.has(e)&&Ur(Vr(e.p),n)&&this.pt(e,null,void 0,!0);this.Fe.size>0&&e.$e()}prime(t,n){try{n()}catch(n){v(n,`[@wcstack/state] $watch initial evaluation of "${t.t}" threw.`),e.ut?.(this.engine,{type:"state:watch-error",phase:"prime",path:t.t,error:n})}}jo(){this.active=!1,this.Fe.clear(),this.early=[]}Vn(e,t,n,r){let l=this.engine.Ke(n,e.h[t]);for(let n of l.d)t===e.n?r(n):this.Vn(e,t+1,n,r)}pt(e,t,n,r){let l=this.Fe.get(e);void 0===l&&this.Fe.set(e,l=new Map);let i=l.get(t);void 0===i?l.set(t,[n,this.n,r]):(i[1]<this.n&&(i[1]=this.n),i[2]||=r)}se(e,t,n,r,l,i){if(this.active){(this.qe??=new Set).add(e);for(let i of this.De){let s=i.p;s.n!==e.n||!s.te(e)||this.pt(i,t,i.getter?i.s.get(t??Er):s===e&&l&&this.engine.Ut&&(null===r||"object"!=typeof r&&"function"!=typeof r)?n:void 0,!0)}}else i&&this.early.push([e,t,n,r])}Ne(e,t){if(this.active)for(let n of this.De)(n.getter||=null!==n.p.getter||n.p.ue)&&n.p.n===e.n&&n.p.te(e)&&this.pt(n,t,n.s.get(t??Er),!1)}st(e,t){if(!this.active)return;let n=null;for(let r of this.De){let l=r.p;if(!(l.n<e.n||l.h[e.n]!==e.o)){n??=new Set(t);for(let t of e.d)n.has(t)||(l.n===e.n?this.pt(r,t,void 0,!0):this.Vn(l,e.n+1,t,e=>this.pt(r,e,void 0,!0)))}}}he(){let t=this.qe;if(this.qe=null,!this.active||0===this.Fe.size)return;let n=this.Fe;this.Fe=new Map;let r=this.engine,l=[];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)=>_r(e[0],t[0]));for(let[n,[s,u,c]]of a){let a,f="evaluate",h=r.f;this.n=u+1,r.Oe++;try{if(a=r.v(i.p,n),i.getter&&(i.s.set(n??Er,a),Object.is(a,s)&&(Wr.test(i.t)||null!==n&&!c&&!(o??=null!==t&&Ur(Vr(i.p),t)))))continue;if(u>32){l.includes(i.t)||l.push(i.t);continue}r.f=n,e.ut?.(r,{type:"state:watch-fired",path:i.t}),f="handler",i.handler.call(r.proxy,a,s,...r.K(n))}catch(t){v(t,`[@wcstack/state] $watch "${i.t}" failed; the other watches still run.`),e.ut?.(r,{type:"state:watch-error",phase:f,path:i.t,error:t})}finally{r.f=h,this.n=0,r.Oe--}}}l.length>0&&this.Mo(l)}Mo(t){let n=zr();n!==this.Do&&(this.Do=n,this.Bn.clear());let r=t.filter(e=>!this.Bn.has(e));if(0!==r.length){for(let e of r)this.Bn.add(e);v("[@wcstack/state] $watch handlers / $stream restarts kept writing for 32 batches; the chain is cut (nothing is rolled back)."),e.ut?.(this.engine,{type:"state:watch-chain-limit",maxDepth:32,paths:r})}}};function Vr(e){for(;null===e.getter&&null!==e.c;)e=e.c;return e}function _r(e,t){let n=[],r=[];for(let t=e;null!==t;t=t.a.oe)n.unshift(t.y);for(let e=t;null!==e;e=e.a.oe)r.unshift(e.y);for(let e=0;e<n.length&&e<r.length;e++)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}var Br="$streamStatus",Hr="$streamError",Kr=new Set(Object.getOwnPropertyNames(Object.prototype)),Jr=!1;function Yr(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 Gr=class{constructor(e,t,n){this.engine=e,this.entries=t,this.B=n}set(e,t,n){Jr=!0;try{this.engine.C(this.engine.o(`${e}.${t}`),null,n)}finally{Jr=!1}}mr(){for(let e of this.entries)this.start(e,!0)}hr(){for(let e of this.entries)e.mt=!1,e.Q?.abort(),e.Q=null}gr(){for(let e of this.entries)e.mt=!1,null!==e.Q&&(e.Q.abort(),e.Q=null),this.set(Br,e.name,"idle")}Ne(e){let t=this.B.n;for(let n of this.entries)n.g===e&&(n.n=n.mt?Math.max(n.n,t):t,n.mt=!0)}he(){let e=this.engine,t=this.B,n=[];for(let r of this.entries){if(!r.mt)continue;let l=r.n;if(r.mt=!1,l>32)n.push(r.name),r.g.G=h;else{t.n=l+1,e.Oe++;try{this.start(r,!1)}finally{e.Oe--,t.n=0}}}n.length>0&&t.Mo(n)}start(e,t){let n,r=this.engine;if(null!==e.Q&&e.Q.abort(),e.Q=null,null!==e.g){let l=e.g;l.getter=e.args;let i=l.Z.slice();Zr(l);try{n=r.read(l,null),function(e,t,n){null!==n&&"function"==typeof n?.then&&$(`$stream "${e}": args must be synchronous (it returned a Promise).`);for(let n of t.Z)n.n>0&&$(`$stream "${e}": args must not read a wildcard path ("${n.t}").`),(n.t===e||n.t===`${Br}.${e}`||n.t===`${Hr}.${e}`)&&$(`$stream "${e}": args must not read the stream itself ("${n.t}").`)}(e.name,l,n)}catch(n){Zr(l);for(let e of i)e.Hn(l);if(l.G=h,t)throw n;return this.set(Hr,e.name,n),void this.set(Br,e.name,"error")}}let l=new AbortController;e.Q=l,r.C(r.o(e.name),null,e.z),this.set(Hr,e.name,null),this.set(Br,e.name,"active"),this.yr(e,l,n)}async yr(e,t,n){let r=this.engine,l=t.signal,i=()=>!l.aborted&&e.Q===t,s=r.o(e.name),o=this.B.n,a=zr(),u=e=>{zr()===a&&(this.B.n=o);try{e()}finally{this.B.n=0}},c=e.z;try{let t=await e.source(n,l);if(!i())return;let o=t=>{c=void 0!==e.Lo?e.Lo(c,t):t,u(()=>r.C(s,null,c))};if(null!==t&&"function"==typeof t?.getReader){let e=t.getReader();for(l.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(l.addEventListener("abort",()=>{e.return?.()});;){let t=await e.next();if(!i())return;if(t.done)break;o(t.value)}}}if(!i())return;e.Q=null,u(()=>this.set(Br,e.name,"done"))}catch(n){if(!i())return;e.Q=null,t.abort(),u(()=>{this.set(Hr,e.name,n),this.set(Br,e.name,"error")})}}};function Zr(e){for(let t of e.Z){let n=t._.indexOf(e);n>=0&&t._.splice(n,1),t.wt.delete(e)}e.Z.length=0,e.G=c}var Xr=new WeakMap;function Qr(e){let t=Xr.get(e);return t?.target===e.target?t:void 0}function el(t,n){let r=new Fr(t,function(t,n){if(void 0===n)return[];(null===n||"object"!=typeof n)&&$("$watch must be an object mapping paths to handler functions.");let r=[];for(let l of Object.keys(n)){let i=n[l];(""===l||"$"===l[0]||l.includes("@")||Ir.has(l))&&$(`$watch path "${l}" is not a path of the state tree.`),"function"!=typeof i&&$(`$watch entry "${l}" must be a function.`);let s=t.o(l);e.To?.(t,s,!0),r.push({t:l,p:s,handler:i,getter:!1,s:new WeakMap})}return r}(t,n.$watch)),l=new Gr(t,function(e,t){let n=t.$stream;if(void 0===n)return[];(null===n||"object"!=typeof n)&&$("$stream must be an object mapping stream names to definitions.");let r=[],l={},i={};for(let s of Object.keys(n)){let o=n[s];(""===s||"$"===s[0]||/[.*]/.test(s)||Kr.has(s))&&$(`$stream entry "${s}" must be a flat property name.`),(null===o||"object"!=typeof o)&&$(`$stream entry "${s}" must be an object.`);let a=o.source,u=o.fold,c=o.args,f=o.initial;"function"!=typeof a&&$(`$stream entry "${s}" needs a source function.`),void 0!==u&&"function"!=typeof u&&$(`$stream entry "${s}": fold must be a function.`),void 0!==u&&!("initial"in o)&&$(`$stream entry "${s}": fold needs an initial value.`),void 0!==c&&"function"!=typeof c&&$(`$stream entry "${s}": args must be a function.`),Yr(t,s)&&$(`$stream entry "${s}" collides with a getter, setter or method of the state.`),void 0===t[s]&&(t[s]=f),l[s]="idle",i[s]=null,r.push({name:s,source:a,Lo:u,z:f,Q:null,mt:!1,n:0,g:void 0===c?null:e.o(`$streamArgs.${s}`),args:void 0===c?null:function(){return c(this)}})}return t[Br]=l,t[Hr]=i,r}(t,n),r),i=Xr.get(t);void 0!==i&&(i.B.jo(),i.jt.hr()),Xr.set(t,{B:r,jt:l,Qe:i?.Qe??!1,target:n})}function tl(e,t){let n=Xr.get(e);if(void 0!==n&&"mounting"!==t&&!document.documentElement?.hasAttribute("data-wcs-server")&&("reset"!==t&&(n.Qe="connected"===t),n.target===e.target)){if("disconnected"===t)return n.B.jo(),void n.jt.gr();n.Qe&&(n.B.pr(),n.jt.mr())}}var nl=["$streamStatus","$streamError"],rl={name:"temporal",hooks:e,install(){e.pe=t(e.pe,el),e.element=t(e.element,tl),e.se=t(e.se,(e,t,n,r,l,i,s)=>Qr(e)?.B.se(t,n,r,l,i,s)),e.Ne=t(e.Ne,(e,t,n)=>{let r=Qr(e);void 0!==r&&(r.B.Ne(t,n),r.jt.Ne(t))}),e.st=t(e.st,(e,t,n)=>Qr(e)?.B.st(t,n)),e.he=t(e.he,e=>{let t=Qr(e);void 0!==t&&(t.B.he(),t.jt.he())}),e.it=n(l,e.it,(e,t)=>{let n=t.split(".",1)[0];if(nl.includes(n))return n===t?e.target[t]:e.read(e.o(t),null)}),e.Ie=n(r,e.Ie,(e,t)=>(!Jr&&36===t.t.charCodeAt(0)&&nl.includes(t.t.split(".",1)[0])&&$(`"${t.t}" is read-only (the stream runtime owns it).`),!1))}},ll=new WeakMap,il=!1,sl=/^(?!prototype$)[^\d.*$][^.*]*$/;function ol(e,t){let n=t.$listKeys,r=new Map;if(void 0!==n){(null===n||"object"!=typeof n)&&$("$listKeys must be an object mapping list paths to a key field or function.");for(let t of Object.keys(n)){let l=n[t];"string"==typeof l?r.set(e.o(t),e=>e[l]):"function"==typeof l?r.set(e.o(t),l):$(`$listKeys "${t}" must be a field name or a function.`)}}ll.set(t,r)}function al(e){if(null===e||"object"!=typeof e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function ul(e,t,n){let r=new Map;for(let l of t){al(l)||$(`$listKeys "${e}": rows must be plain objects.`);let t=n(l);null==t&&$(`$listKeys "${e}": a row has no key.`),r.has(t)&&$(`$listKeys "${e}": duplicate key ${JSON.stringify(t)}.`),r.set(t,l)}return r}function cl(e,t,n,r){if(il||!Array.isArray(r))return!1;let l=ll.get(e.target)?.get(t);if(void 0===l)return!1;let i=e.at(t,n);if(!Array.isArray(i)||i===r)return!1;let s=ul(t.t,i,l);ul(t.t,r,l);let o=[],a=[],u=i.length===r.length;for(let e=0;e<r.length;e++){let t=r[e],n=s.get(l(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 r of Object.keys(n))Object.is(t[r],n[r])||c.push([e,r,n[r]]);for(let r of Object.keys(t))!(r in n)&&null!==t[r]&&c.push([e,r,null])}if(u&&0===c.length)return!0;if(!u){il=!0;try{e.C(t,n,o)}finally{il=!1}}if(c.length>0){let r=e.Ke(0===t.n?null:n,t);for(let[n,l,i]of c){if("__proto__"===l)continue;let s=r.d[n],o=sl.test(l)?e.o(`${t.t}.*.${l}`):null;null===o?.getter?e.C(o,s,i):(s.N[l]=i,e.C(e.o(`${t.t}.*`),s,s.N,!0))}}return!0}var fl={name:"list-keys",hooks:e,install(){e.pe=t(e.pe,ol),e.Ie=n(r,e.Ie,cl)}},hl=new WeakMap,dl=new WeakMap,pl="will not graft: the root state failed to initialize.",ml=new WeakSet,gl=new WeakMap,yl=["$stream","$streams","$scan","$recursion","$watch","$listKeys","$renderedCallback","$updatedCallback","$behavior","$features"],bl=["$commandTokens","$eventTokens","$on","$errorCallback"],$l=e=>`[@wcstack/state] <${se.tagNames.state} mount="${e}">`,vl=new Set(["$getAll","$setAll","$resolve","$postUpdate","$dependOn","$eq","$eqIndex"]),wl=e=>e?.element?.isConnected?e:void 0;function Al(e){let t=dl.get(e);return void 0!==t&&!Array.isArray(t)&&t.isConnected}function kl(e,t){let n=dl.get(t);if(dl.delete(t),Array.isArray(n))for(let t of n)Nl(t,e)}function xl(e){let t=hl.get(e.root);t?.get(e.t)===e&&t.delete(e.t)}function Sl(e,t){v(`${$l(e.t)} ${t}`),xl(e),e.Ze?.(),e.Ze=null}function Tl(e,t){let n=e.state?.[t];if("function"==typeof n)try{let t=n.call(e.chroot);null!==t&&"object"==typeof t&&"function"==typeof t.then&&t.then(void 0,v)}catch(e){v(e)}}function Nl(e,t){if(ml.has(t))return Sl(e,"will not graft: its component is wired to its host.");let n=e.state,r=t.target,l=e.t.split("."),i=r;for(let e of l)i=i?.[e];if(void 0!==i&&!0!==t.hydrated)return Sl(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,r){if("symbol"==typeof r)return;if(36!==r.charCodeAt(0))return e.proxy[n(r)];let l=e.proxy[r];return"$eqPath"===r?(e,t)=>l(n(e),n(t)):vl.has(r)&&"function"==typeof l?(e,...t)=>l(n(e),...t):l},set:(t,r,l)=>"symbol"!=typeof r&&(e.proxy[n(r)]=l,!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:r,set:l,value:i}=Object.getOwnPropertyDescriptor(t,n);if(void 0!==r||void 0!==l)a[`${e.t}.${n}`]={get:r&&function(){return r.call(s)},set:l&&function(e){l.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<l.length;e++){let n=t.o(l.slice(0,e).join("."));null==t.at(n,null)&&t.C(n,null,{})}t.C(t.o(e.t),null,o)}t.io(Object.defineProperties({},a));for(let e in a)t.qe(t.o(e),null);e.engine=t;let c=gl.get(t);void 0===c&&gl.set(t,c=[]),c.push(e),e.el.isConnected&&Tl(e,"$connectedCallback"),e.Ze?.(),e.Ze=null}function jl(e,t){let n=dl.get(e);if(Array.isArray(n))for(let e of n)Sl(e,pl);dl.set(e,t)}var Ol=new WeakMap;function Cl(e,t){let n=e.getAttribute("mount");if(null===n)return null;let r={el:e,root:t,t:n,state:null,engine:null,chroot:null,Ze:null},l=null;if(function(e){return""!==e&&e.split(".").every(e=>""!==e&&!/[*$#@\s]/.test(e))}(n))if(e.hasAttribute(se.bindAttributeName))l='injections (data-wcs="state.<key>: …") are not supported — read the root path in a root getter.';else{let e=hl.get(t);void 0===e&&hl.set(t,e=new Map);let i=e.get(n);if(void 0!==i&&i!==r&&(null===i.engine?i.el.isConnected:wl(i.engine)))l=`will not graft: another volume already holds "${n}".`;else{if(null===i?.engine){let e=dl.get(t);Array.isArray(e)&&dl.set(t,e.filter(e=>e!==i)),i.Ze?.(),i.Ze=null}e.set(n,r)}}else l='has an invalid mount path: it must be a static path (no "*", "$", "#", "@").';return{Co:!0,start(e){if(null!==l)return Sl(r,l);if(hl.get(t).get(n)===r){for(let t of yl)if(void 0!==e[t])return Sl(r,`${t} is not run in a volume — declare it on the root state.`);for(let t of bl)void 0!==e[t]&&console.warn(`${$l(n)} ${t} is not run in a volume (it belongs to the root).`);return r.state=e,new Promise(e=>{r.Ze=e;let n=wl(zt.get(t)),l=dl.get(t);void 0!==n?Nl(r,n):Al(t)?Sl(r,pl):dl.set(t,[...Array.isArray(l)?l:[],r])})}},Qe(){null!==r.engine&&Tl(r,"$connectedCallback")},_n(){null!==r.engine&&Tl(r,"$disconnectedCallback")},reset(){$(`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 Ml=new WeakMap,Pl=new WeakMap;function El(e,t){let n=e[t];if(void 0===n)return[];Array.isArray(n)||$(`${t} must be an array of state member names.`);let r=new Set;for(let e of n)("string"!=typeof e||""===e)&&$(`${t} entries must be non-empty strings.`),"$"===e[0]&&$(`${t} entry "${e}": internal ($) members are never exposed.`),r.has(e)&&$(`${t} entry "${e}" is duplicated.`),r.add(e);return n}function Wl(e,t){let n=t.host;if(void 0===n||!n.hasAttribute("data-wc-definition"))return null;let r=document.createDocumentFragment();for(let e of[...t.childNodes])r.appendChild(e.cloneNode(!0));let l=t.mode;return{start(t){e.hasAttribute("bind-component")&&$("DCC: a <wcs-state bind-component> cannot define a component (use one mechanism)."),function(e,t,n,r){e.includes("-")||$(`DCC: <${e} data-wc-definition> is not a valid custom element name.`),void 0!==customElements.get(e)&&$(`DCC: <${e}> is already defined.`);let l=function(e){let t=new Map;for(let n=e;null!==n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let e of Object.getOwnPropertyNames(n))"constructor"===e||"$"===e[0]||t.has(e)||t.set(e,Object.getOwnPropertyDescriptor(n,e));let n=e.$stream;if(null!==n&&"object"==typeof n)for(let e of Object.keys(n))t.has(e)||t.set(e,{value:void 0});return t}(r),i=El(r,"$bindables"),s=El(r,"$commands");for(let e of i){let t=l.get(e);void 0===t&&$(`$bindables entry "${e}" does not exist on the state.`),"function"==typeof t.value&&$(`$bindables entry "${e}" is a method: list it in $commands.`)}for(let e of s){let t=l.get(e);void 0===t&&$(`$commands entry "${e}" does not exist on the state.`),"function"!=typeof t.value&&$(`$commands entry "${e}" is not a method: list it in $bindables.`)}let o={tag:e,bindables:i},a=new WeakMap,u=new WeakMap,c=r=>{if(a.has(r))return a.get(r);if(r.hasAttribute("data-wc-definition"))return null;let l=r.attachShadow({mode:n});l.appendChild(t.cloneNode(!0));let s=l.querySelector(se.tagNames.state);return a.set(r,s),Ml.set(r,o),null===s&&i.length>0&&console.warn(`[@wcstack/state] DCC: <${e}> declares $bindables but its content has no <${se.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,r]of t)n.proxy[e]=r});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 l)"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,r,l,t)},Qe(){},_n(){},reset(){$("re-setting a DCC definition is not supported: each instance loads its own state.")}}}var Il=new WeakMap,Rl=new WeakSet,Dl=new WeakMap,Ll=new WeakMap,ql="data-wcs-wired",zl=new WeakMap,Ul=new WeakMap,Fl=new WeakMap,Vl=0,_l=new Set,Bl={},Hl=["$watch","$stream","$renderedCallback"],Kl=e=>e.split(".",1)[0];function Jl(e,t){let n=0;return e.split(".").map(e=>"*"===e?String(t[n++]):e).join(".")}function Yl(e,t){let n=e.l,r=Kl(e.name);if(!0!==document.documentElement?.hasAttribute("data-wcs-server"))n.removeAttribute(ql);else if(!Zl(n,r)){let e=n.getAttribute(ql)?.split(" ")??[];e.includes(r)||n.setAttribute(ql,[...e,r].join(" "))}zl.get(n)?.ve===r&&$(`<${n.localName}>.${r} has loaded its state: the wiring "${e.name}" added afterwards cannot reach it — bind the host's wiring before the component loads.`);let l=Il.get(n);void 0===l&&Il.set(n,l=[]),l.push(e),t&&Rl.add(e);let i=Dl.get(n);return void 0===i&&Dl.set(n,i=new Map),i.has(r)||i.set(r,n[r]),Ll.get(n)?.(),!1}function Gl(e){return e.localName.includes("-")&&null!==e.querySelector(`:scope > ${se.tagNames.state}[bind-component]`)}function Zl(e,t){let n=e.getAttribute(se.bindAttributeName);return null!==n&&new RegExp(`(^|;)\\s*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*[.#:]`).test(n)}function Xl(e){let t=e.parentElement;for(;null!==t&&!Gl(t);)t=t.parentElement;let n=zt.get(t??e.getRootNode()),r=n?.element;(r?.isConnected?r.U:null===t)&&(null===t?Jt(e):Ft(n,e))}var Ql=new Set;function ei(e,t){Ql.has(e)||(Ql.add(e),console.warn(`[@wcstack/state] ${t}`))}var ti=(e,t)=>t in e.state;function ni(e,t){let n=ri(e.state,t);return void 0!==n&&(void 0!==n.get||void 0!==n.set||"function"==typeof n.value)}function ri(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 li(e,t,n){if(null!==n.getter)return;let r,l=e.host,i=l.engine,s=Kl(n.t),o=l.entries.find(e=>e.x===n.t);if(void 0===o&&null!==n.c)return function(e,t){let n,r=t.c;for(;null!==r&&void 0===(n=e.ht.get(r));)r=r.c;if(null===r||void 0===n)return;let l=e.A,i=e.host.engine,s=i.o(n.p.t+t.t.slice(r.t.length));if(null===s.getter)return;let o=n,a=()=>{let n=ii(e,o.r);return 0===t.n?n:(i.resolve(Jl(s.t,[...i.K(n),...l.K(re(l.f,t.n))]),null),i.rr)};t.getter=()=>{let e=a();return s.n>0&&null===e?void 0:i.v(s,e)},null!==s.ce&&(t.ce=n=>{let r=a();si(e,o.e,()=>i.C(s,r,n)),e.fn=t}),t.n>0&&(t.F=l.Me++),e.ht.set(t,{e:o.e,p:s,r:o.r})}(e,n);if(0!==n.n)return;if(void 0!==o){if(o.x!==s?ti(l,s):ni(l,s))return;r=o.ke}else{if(null===t||null!==n.c||"$"===s[0]||ti(l,s))return;o=t,r=i.o(`${t.ke.t}.${s}`)}let a=o.r,u=o;n.getter=()=>i.v(r,ii(e,a)),n.ce=t=>{si(e,u,()=>i.C(r,a,t)),e.fn=n},e.ht.set(n,{e:o,p:r,r:a})}function ii(e,t){return null!==t&&!t.w&&$(`The host row of <${e.host.el.localName}> was removed.`),t}function si(e,t,n){let r=_l.has(e.A);_l.add(e.A),e.from=t;try{n()}finally{r||_l.delete(e.A),e.from=null}}var oi=(e,t)=>t||!_l.has(e.m.A)||null!==e.m.from&&e.m.from!==e.e;function ai(e,t){if(e.pn===t||null===e.host.engine)return;e.pn=t,Vl+=t?1:-1;let n=e.host.engine,r=Fl.get(n);void 0===r&&Fl.set(n,r=new Map);for(let n of e.me){let e=r.get(n.e.ke);void 0===e&&r.set(n.e.ke,e=new Map);let l=e.get(n.e.r);void 0===l&&e.set(n.e.r,l=new Set),t?l.add(n):(l.delete(n),0===l.size&&e.delete(n.e.r))}let l=e.host.entries.find(e=>""===e.x);if(void 0!==l){null===e.ae&&function(e,t){let n=e.host,r=n.engine;e.ae=new Map;let l=new Set;for(let i=n.state;null!==i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let s of Object.getOwnPropertyNames(i)){if(l.has(s))continue;l.add(s);let o=Object.getOwnPropertyDescriptor(i,s);if(void 0===o.get&&void 0===o.set||"$"===s[0]||s.includes("*"))continue;let a=Kl(s);if(s!==a&&!ti(n,a))continue;let u=r.o(`${t.ke.t}.${s}`);if(null===u.getter)fi(r,u,t.ke);else if(!ui.has(u.getter))continue;e.ae.set(u,e.A.o(s))}}(e,l);for(let r of e.ae.keys())t&&null===r.getter&&fi(n,r,l.ke),n.P.xe(n,r,l.r);e.ae.size>0&&n.$e(),t&&function(e,t){let n=e.host.engine;for(let[r,l]of e.ae){let i=n.v(r.c,t.r);if(null===i||"object"!=typeof i||!(r.s in i))continue;let s=e.host.el.localName;ei(`${s}|${r.t}`,`[wcs/mount-export-shadowed] <${s}>.${e.host.ve}.${l.t} is exported at "${r.t}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`)}}(e,l)}}var ui=new WeakSet;function ci(e,t,n,r){let l=Fl.get(e)?.get(t)?.get(n);if(void 0===l)return null;let i=null;for(let e of l)""!==e.e.x||!0!==e.m.ae?.has(r)||e.m===i||(null!==i&&$(`[wcs/mount-export-ambiguous] "${r.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 fi(e,t,n){let r=t.c,l=t.s,i=()=>{let t=e.read(r,e.f);return null!==t&&"object"==typeof t&&l in t?t:null};t.getter=()=>{let r=i();if(null!==r)return r[l];let s=ci(e,n,e.f,t);return null===s?void 0:s.A.read(s.ae.get(t),null)},ui.add(t.getter),t.ce=s=>{let o=null===i()?ci(e,n,e.f,t):null;if(null===o){let t=e.read(r,e.f);return void(null!==t&&"object"==typeof t&&(t[l]=s))}let a=o.ae.get(t);void 0===ri(o.host.state,a.t)?.set&&$(`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.A.C(a,null,s)},t.n>0&&(t.F=e.Me++)}function hi(t,n,r,l,i,s){if(null!==n.getter)return t.P.xe(t,n,r),void t.$e();if("*"===n.s){if(null===r)return;if(r.N=r.a.T[r.y],t.P.Jt(r),null!==r.u)for(let e of r.u.values())t.J(e)}else t.Tn(n,r);e.se?.(t,n,r,l,i,s),t.qe(n,r)}function di(e){let t=e.m.A;for(let[n,r]of e.m.ht)r.e===e.e&&(0===n.n?t.P.xe(t,n,null):t.on(n.h[n.n],e=>t.P.xe(t,n,e)));t.$e()}function pi(e,t,n,r,l,i,s){let o=n.t.slice(t.t.length);if(""===o)return di(e);let a,u=e.m,c=u.A;if(""===e.e.x){a=o.slice(1);let e=Kl(a);if("$"===e[0]||ti(u.host,e)||u.host.entries.some(e=>""!==e.x&&(a===e.x||a.startsWith(`${e.x}.`))))return}else a=e.e.x+o;let f=[];for(let e=t.n+1;e<=n.n;e++)f.push(re(r,e).y);c.resolve(Jl(a,f),null);let h=c.rp,d=c.rr;h.n>0&&null===d||hi(c,h,d,l,i,s)}function mi(e,t,n,r,l,i,s){if(0===Vl)return;let o=_l.has(e);_l.add(e);try{let o=Ul.get(e);!s&&void 0!==o&&o.pn&&!_l.has(o.host.engine)&&function(e,t,n,r,l,i){let s,o=t;for(;null!==o&&void 0===(s=e.ht.get(o));)o=o.c;if(null===o||void 0===s)return;let a=e.host.engine;if(o===t&&e.fn===t)return void(e.fn=null);if(null!==s.r&&!s.r.w)return;let u=[...a.K(s.r),...e.A.K(n)];a.resolve(Jl(s.p.t+t.t.slice(o.t.length),u),null);let c=a.rp,f=a.rr;c.n>0&&null===f||si(e,s.e,()=>hi(a,c,f,r,l,i))}(o,t,n,r,l,i),s&&void 0!==o&&o.pn&&null!==o.ae&&function(e,t){let n=e.host.entries.find(e=>""===e.x),r=e.host.engine;for(let[l,i]of e.ae)i===t&&(r.P.xe(r,l,n.r),r.$e())}(o,t);let a=Fl.get(e);if(void 0===a)return;for(let[e,o]of a)if(t.te(e)){let a=o.get(0===e.n?null:re(n,e.n));if(void 0!==a)for(let o of[...a])oi(o,s)&&pi(o,e,t,n,r,l,i)}else if(e.te(t))for(let[e,r]of[...o])if(0===t.n||re(e,t.n)===n)for(let e of[...r])oi(e,s)&&di(e)}finally{o||_l.delete(e)}}async function gi(t,n,r,l,i){if(l===Bl)return;let s=o(l);s&&await s;let a=zl.get(n);a.engine&&l.$recursion&&$(`[wcs/mount-dollar-declaration] <${n.localName}>: $recursion is not run in a mounted component — declare it on the root state.`);let u=a.D;if(null!==u&&u.el!==t&&u.el.isConnected&&$(`<${n.localName}> already has a connected <${se.tagNames.state} bind-component="${a.ve}">.`),null!==u&&ai(u,!1),null!==u&&function(e,t,n){let r=e.A,l=`[${se.bindAttributeName}]`,i=e=>1===e.nodeType&&(e.matches(l)||null!==e.querySelector(l)),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.jn(t);null!==n&&n!==t;n=n.nextSibling)o(n);o(t)};for(let e of r.ie.values())for(let t of e)if(null===t.I)o(t.l);else for(let e of t.I.W)a(t.I,e.E);for(let e of r.H.values())for(let t of[e.S,...e.j??[]])null!==t&&a(t,t.E);for(let t of e.L)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.L.includes(n)&&(i(n)||r.Ht&&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,r))return async function(e,t,n,r){e.el.engine=null,e.el=t,e.A.element=t,t.engine=e.A,e.L=e.L.filter(e=>e.parentNode===n),t.isConnected?await yi(e,r):r()}(u,t,r,i);let c=new ie(l,new Gt);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 r=Object.getOwnPropertyDescriptor(e,t).value;"function"==typeof r&&"constructor"!==t&&n.set(r,null)}let r=(t,n,r)=>Reflect.apply(t,e.proxy,r);e.U=e=>{let t=n.get(e);return null===t&&n.set(e,t=new Proxy(e,{apply:r})),t}}(c,l);let f={el:t,L:[],A:c,host:a,me:[],ht:new Map,pn:!1,fn:null,from:null,ae:null};for(let e of a.entries)f.me.push({m:f,e});a.D=f,Ul.set(c,f);let h=null===a.engine;h?e.element?.(c,"mounting"):(function(e){let t=e.A,n=e.host,r=n.engine,l=n.el.localName,i=n.entries.find(e=>""===e.x)??null;for(let e of n.entries){if(""===e.x)continue;let t=Kl(e.x);ti(n,t)&&(e.x!==t||ni(n,t))&&ei(`${l}.${e.x}`,`[wcs/mount-own-key-shadow] <${l}>: "${n.ve}.${e.x}" is hidden by the component's own "${t}"; rename one side.`)}if(null!==i){let e=r.v(i.ke,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.x===t)&&ei(`${l}.${t}`,`[wcs/mount-own-key-shadow] <${l}>: its own "${t}" hides "${i.ke.t}.${t}" — remove the default to read the tree, or rename it to keep it private.`)}let s=Hl.filter(e=>void 0!==n.state[e]);s.length>0&&ei(`${l}.${n.ve}$`,`[wcs/mount-dollar-declaration] <${l}>: ${s.join(", ")} ${1===s.length?"is":"are"} not run in a mounted component — declare it on the root state.`);let o=t.rt;t.rt=n=>{li(e,i,n),o.call(t,n)};let a=[...t.O.all()];for(let t of a)li(e,i,t);for(let e of a)o.call(t,e);let u=t.xt;t.xt=()=>{(function(e){for(;void 0!==e;e=Ul.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),ai(f,!0),ml.add(c),kl(c,r));let d=e.wr?.(r,c);Ut(c,r),d?.(),f.L=[...r.childNodes],Yt(),h&&c.Rn(),Object.defineProperty(n,a.ve,{configurable:!0,enumerable:!0,get:()=>c.proxy});let p=n.$stateReadyCallback;if("function"==typeof p)try{let e=p.call(n,a.ve);null!==e&&"object"==typeof e&&"function"==typeof e.then&&e.then(void 0,v)}catch(e){v(e)}i(),t.isConnected?(await c.Te("$connectedCallback"),h&&t.isConnected&&e.element?.(c,"connected")):ai(f,!1)}async function yi(t,n){ai(t,!0);for(let e of t.me)di(e);n?.(),!t.broken&&(await t.A.Te("$connectedCallback"),null===t.host.engine&&t.el.isConnected&&e.element?.(t.A,"connected"))}function bi(t,n){let r=t.getAttribute("bind-component");if(null===r)return function(e,t){return e.connectedCallbackPromise.catch(()=>{let n=zt.get(t)?.element;if(!(e.U||void 0!==n&&n!==e&&n.isConnected)){jl(t,e);for(let e of Ol.get(t)??[])e()}}),null}(t,n);let l=t.parentNode,i=l instanceof ShadowRoot,s=i?l.host:l instanceof Element?l:null,o=()=>{let e=null===s?void 0:zl.get(s)?.D;return e?.el===t?e:null},a=e=>{throw i&&jl(l,t),e},u=!1;return{Mt:()=>(null!==s&&s.localName.includes("-")?async function(e,t,n,r){let l=n.localName;(["state","src","json"].some(t=>e.hasAttribute(t))||null!==e.querySelector('script[type="module"]'))&&$(`<${se.tagNames.state} bind-component> takes its state from <${l}>.${t}: it cannot also load one (state / src / json / an inline script).`),await ze(n).whenDefined(l);let i=zl.get(n);if(void 0!==i)return i.ve!==t&&$(`<${l}> already has a <${se.tagNames.state} bind-component="${i.ve}">.`),i.state;let s=()=>(Il.get(n)??[]).filter(e=>Kl(e.name)===t),o=Zl(n,t);if(o&&0===s().length&&Xl(n),0===s().length&&(o||((e,t)=>!0===e.getAttribute(ql)?.split(" ").includes(t))(n,t))){let e;await new Promise((r,i)=>{Ll.set(n,r),e=function(e,t){Al(e)&&t();let n=Ol.get(e)??new Set;return Ol.set(e,n.add(t)),()=>n.delete(t)}(n.getRootNode(),()=>i(new Error(`[@wcstack/state] <${l}>.${t} will not mount: the root state failed to initialize.`)))}).finally(()=>e())}Ll.delete(n);let a=s(),u=Dl.get(n),c=void 0!==u&&u.has(t)?u.get(t):n[t];if((null===c||"object"!=typeof c)&&$(`"bind-component": <${l}>.${t} must be an object (the component's state), got ${null===c?"null":typeof c}.`),0===a.length&&r){let e=new Error(`[@wcstack/state] A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${l}>, or mount it from the host (${se.bindAttributeName}="${t}: path").`);return queueMicrotask(()=>{throw e}),Bl}let f=[];for(let e of a){let r=e.name===t?"":e.name.slice(t.length+1);f.some(e=>e.x===r)&&$(`<${l}> maps "${e.name}" twice.`);let i=r.split(".").indexOf("*");if(i>=0){let n=r.split(".").slice(0,i).join(".");$(`<${l}> 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({x:r,ke:e.o,r:e.r,ro:Rl.has(e)}),e.engine.Pn(e),""!==r&&delete n[e.name]}let h=0===a.length?function(e){let t=Object.getOwnPropertyDescriptors(e),n=Object.isFrozen(e);for(let e of Object.values(t))"value"in e&&!1===e.writable&&(e.writable=!0,n=!0);return n?Object.create(Object.getPrototypeOf(e),t):e}(c):c;return zl.set(n,i={el:n,ve:t,state:h,engine:0===a.length?null:a[0].engine,entries:f,D:null}),h}(t,r,s,!i):Promise.reject(new Error(`[@wcstack/state] "bind-component" requires <${se.tagNames.state}> to be a direct child of a custom element.`))).catch(a),async start(e,n){await gi(t,s,i?l:s,e,()=>{u=!0,n()}).catch(e=>{let t=o();return!u&&null!==t&&(t.broken=!0),a(e)})},Qe(){let e=o();null!==e?yi(e).catch(v):u?Promise.resolve().then(()=>{if(t.parentNode===l)return gi(t,s,i?l:s,zl.get(s).state,()=>{})}).catch(v):Ll.has(s)&&Xl(s)},_n(){let t=o();null!==t&&(ai(t,!1),!t.broken&&(t.A.Te("$disconnectedCallback"),null===t.host.engine&&e.element?.(t.A,"disconnected")))},reset(){$(`re-setting a component's state is not supported: write <${s?.localName}>.${r} instead.`)}}}var $i={name:"scopes",hooks:e,install(){e.ft=n(i,e.ft,Cl),e.ft=n(i,e.ft,Wl),e.ft=n(i,e.ft,bi),e.dr=Yl,e.Ro=Gl,e.element=t(e.element,(e,t)=>{if("mounting"!==t)return function(e,t){let n=gl.get(e)??[];if("disconnected"===t)for(let e of n)xl(e);else if("reset"!==t&&wl(zt.get(e.root))===e){kl(e,e.root);for(let e of n)hl.get(e.root).has(e.t)||hl.get(e.root).set(e.t,e)}}(e,t);let n=e.element.getRootNode();kl(e,n),function(e,t){let n=t.host,r=void 0===n?void 0:Ml.get(n);void 0!==r&&Pl.set(e,{host:n,def:r})}(e,n)}),e.se=t(e.se,(e,t,n,r,l,i)=>{(function(e,t,n,r){let l=Pl.get(e);if(void 0===l)return;let i=t.t.split(".",1)[0];if(!l.def.bindables.includes(i))return;let s=r&&t.t===i;l.host.dispatchEvent(new CustomEvent(`${l.def.tag}:${i}-changed`,{detail:s?n:void 0,bubbles:!0}))})(e,t,l,i),mi(e,t,n,r,l,i,!1)}),e.Ne=t(e.Ne,(e,t,n)=>mi(e,t,n,void 0,void 0,!1,!0)),e.Ie=n(r,e.Ie,(e,t,n,r,l)=>(function(e,t){let n=gl.get(e);if(void 0!==n&&0===t.n)for(let{t:e}of n)e.startsWith(`${t.t}.`)&&$(`writing "${t.t}" would replace the volume grafted at "${e}"; write the paths under it instead.`)}(e,t),function(e,t,n){let r,l=Ul.get(e);if(void 0===l)return!1;for(let e=t;null!==e&&void 0===r;e=e.c)r=l.ht.get(e);if(void 0===r)return!1;let i=r.e;return!((null===i.r||i.r.w)&&!i.ro)&&(!!n||(ii(l,i.r),void $(`[wcs/mount-readonly] <${l.host.el.localName}> cannot write "${t.t}": it is mounted read-only ("${l.host.ve}${""===i.x?"":`.${i.x}`}#ro: ${i.ke.t}"). Write it on the host, or drop #ro from the mount.`)))}(e,t,l)));let l=e.pe;e.pe=(e,t)=>{let n=gl.get(e);void 0!==n&&n.length>0&&$(`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=Fl.get(e);if(void 0===t)return!1;for(let e of t.values())if(e.size>0)return!0;return!1}(e)&&$("re-setting a root state with mounted components is not supported: they read its data."),l?.(e,t)}}},vi="$recursion",wi=new WeakMap,Ai=new WeakSet,ki=new WeakSet,xi=0,Si=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ti=e=>`[wcs/recursion-${e}]`;function Ni(e,t){let n=n=>$(`${Ti("declaration-invalid")} ${vi} ${e} "${String(t)}" ${n}`);("string"!=typeof t||""===t)&&$(`${Ti("declaration-invalid")} ${vi} ${e} must be a non-empty string.`);let r=t.split(".");(r.length<2||"*"!==r[r.length-1])&&n('must end with ".*" (a list element).');for(let e=0;e<r.length-1;e++){let t=r[e];""===t&&n("must not contain empty path segments."),("*"===t||"**"===t||/^\d/.test(t))&&n('must have exactly one "*", at the end.'),t.includes("#")&&n('must not contain "#".')}return"$"===t[0]&&n('must not start with "$".'),t}var ji=(e,t)=>`${e.a}.*${e.step.repeat(t)}`;function Oi(e,t){let n=`${e.a}.**`,r=t.slice(n.length);return(!t.startsWith(n)||""!==r&&"."!==r[0]||r.includes("**"))&&$(`[wcs/recursion-anchor] "${t}" does not start at the recursion anchor "${e.a}.*".`),r}function Ci(e,t,n){let r=Oi(e,t),l=function(e,t){for(let n=t;null!==n;n=n.a.oe){let t=e.nodeList.exec(n.a.o.t);if(null!==t)return{k:t[1].length/(e.key.length+3),r:n}}return null}(e,n);return null===l&&$(`[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.`),ji(e,l.k)+r}function Mi(e,t,n){let r=new Set,l=new Set,i=(e,n,i)=>!(!Array.isArray(e)||0===e.length||(r.has(e)&&$(`${Ti("cycle")} "${n}" is reachable from itself: the data under "${t.a}" must be a tree.`),l.has(e)&&$(`${Ti("shared-list")} "${n}" is the same array instance as a list reached before: the data under "${t.a}" must be a tree.`),i+1>128&&$(`${Ti("depth-exceeded")} Recursion on "${t.a}.*" reached depth ${i+1} (the limit is 128).`),l.add(e),0)),s=(l,o)=>{for(let a of l){n(o,a);let l=e.o(`${ji(t,o)}.${t.key}`),u=e.read(l,a);i(u,l.t,o+1)&&(r.add(u),s(e.Ke(a,l).d,o+1),r.delete(u))}},o=e.o(t.a),a=e.read(o,null);i(a,t.a,0)&&(r.add(a),s(e.Ke(null,o).d,0))}function Pi(e,t){let n=function(e){let t=e[vi],n=[],r=new Set;for(let t=e;null!==t&&t!==Object.prototype;t=Object.getPrototypeOf(t))for(let e of Object.getOwnPropertyNames(t))!r.has(e)&&e.includes("**")&&n.push([e,Object.getOwnPropertyDescriptor(t,e)]),r.add(e);if(void 0===t)return n.length>0&&V(n[0][0]),null;(null===t||"object"!=typeof t||Array.isArray(t))&&$(`${Ti("declaration-invalid")} ${vi} must be an object mapping one anchor path to its repeating sub-path.`);let l=Object.entries(t);1!==l.length&&$(`${Ti("declaration-invalid")} ${vi} must declare exactly one anchor (it declares ${l.length}).`);let i=Ni("anchor",l[0][0]),s=Ni("repeat",l[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("**"))&&$(`[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))&&$(`[wcs/recursion-anchor] "${e}" needs a path after "**".`),(void 0===t.get||void 0!==t.set)&&$(`${Ti("declaration-invalid")} "${e}": a recursive key is a getter without a setter.`),c.set(n,t.get),f.push([new RegExp(`^${Si(i)}((?:${Si(u)})*)${Si(n)}$`),n])}return{a:o,step:u,key:a,families:c,matchers:f,owners:new Map,nodeList:new RegExp(`^${Si(o)}((?:${Si(`.*.${a}`)})*)$`)}}(t),r=wi.has(e);null!==n?(r||xi++,wi.set(e,n),ki.add(e),Ai.has(e)||function(e){Ai.add(e);let t=e,n=t.rt;t.rt=r=>{let l=wi.get(e);if(r.t.includes("**")){let t=e.O.vt(r.t)===r;return void(ki.has(e)||void 0===l&&t?r.getter=()=>V(r.t):t||n.call(e,r))}if(void 0!==l&&null===r.getter)for(let[e,n]of l.matchers)if(e.test(r.t)){r.getter=l.families.get(n),r.n>0&&(r.F=t.Me++),l.owners.set(r,l.a+".**"+n);break}n.call(e,r)};let r=t.resolve;t.resolve=(t,n)=>{let l=wi.get(e);return r.call(e,void 0!==l&&t.includes("**")?Ci(l,t,n):t,n)};let l=t.getAll;t.getAll=(n,r)=>{let i=wi.get(e);if(void 0===i||!n.includes("**"))return l.call(e,n,r);if(void 0===r)return l.call(e,Ci(i,n,t.f));(!Array.isArray(r)||r.length>0)&&$(`${Ti("getall-form")} $getAll("${n}", indexes) with "**" takes either no indexes (this depth) or [] (every depth).`);let s=Oi(i,n),o=[];return Mi(e,i,(t,n)=>{for(let r of l.call(e,ji(i,t)+s,e.K(n)))o.push(r)}),o};let i=t.kn;t.kn=(n,r,l,s)=>{let o=wi.get(e);if(void 0===o||!n.includes("**"))return i.call(e,n,r,l,s);Array.isArray(r)||A(9,[n]),r.length>0&&$(`${Ti("setall-form")} $setAll("${n}", indexes, …) with "**" takes no partial prefix: pass [] to write every node.`),("function"==typeof l||!0===s?.spread)&&$(`${Ti("setall-form")} $setAll("${n}", [], value) with "**" takes a plain value (no mapper, no spread).`),t.Le>0&&A(8);let a=Oi(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(".")}`))&&$(`${Ti("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}.`))&&$(`${Ti("readonly")} "${n}" writes into the recursive getter "${o.a}.**${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,ji(o,t)+a,e.K(n),l);return h}}(e)):r&&(wi.delete(e),xi--)}function Ei(e,t){if(0===xi)return!1;let n=wi.get(e);if(void 0===n)return!1;for(let e=t;null!==e;e=e.c){let r=n.owners.get(e);void 0!==r&&$(`${Ti("readonly")} "${t.t}" writes into the recursive getter "${r}".`)}return!1}var Wi={name:"recursion",hooks:e,install(){e.pe=t(e.pe,Pi),e.element=t(e.element,(e,t)=>{("mounting"===t||"reset"===t)&&function(e){ki.delete(e)}(e)}),e.Ie=n(r,e.Ie,Ei)}},Ii="4.12.0",Ri=e=>e.split(".").slice(0,2).join("."),Di=class extends tn{static find(e){return e.querySelector?.(se.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 Ri(this.version)===Ri(Ii)}};function Li(e){let t=se.tagNames.ssr;void 0===e.get(t)&&e.define(t,class extends Di{})}var qi=()=>se.tagNames.ssr,zi=Symbol.for("wcstack.ssr.snapshotBuilder"),Ui=()=>!0===document.documentElement?.hasAttribute("data-wcs-server"),Fi=e=>document.createComment(e),Vi=(e,t)=>null!==e&&8===e.nodeType&&e.data===t,_i=(e,t)=>null!==e&&8===e.nodeType&&e.data.startsWith(t),Bi=new WeakMap,Hi=new WeakMap,Ki=new WeakMap,Ji=new WeakSet,Yi=new WeakMap;function Gi(e,t){let n=[];for(let r=e;null!==r&&(n.push(r),r!==t);r=r.nextSibling);return n}function Zi(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 Xi=e=>{let t=e.nextSibling;return 1!==e.nodeType||"a"!==t?.localName||!t.hasAttribute("data-wcs-ssr-link")&&e.anchorElement!==t?null:t};function Qi(e,t,n,r){let l=Fi(null===r?"wcs-[":`wcs-[:${r}`),i=Fi("wcs-]");n.length>0&&n[0].Re().before(...Gi(e,t)),t.after(l);for(let e of n)null===r&&e.Re().before(Fi("wcs-|"));let s=n.length>0?(e=>null===e.L?e.dt:e.L[e.L.length-1])(n[n.length-1]):l;(Xi(s)??s).after(i);for(let e of Gi(l,i))Ji.add(e)}function es(e){if(e instanceof ht){Qi(e.E,e.E,e.Ce,null);for(let t of e.Ce)ts(t);return}let t=e.D;null!==t&&(Qi(e.W[e.y].E,e.W[e.W.length-1].E,[t],e.y),ts(t))}function ts(e){if(null!==e.u)for(let t of e.u)es(t)}var ns=new Set(["script","style","template","textarea","title"]),rs="data-wcs-raw",ls=e=>ns.has(e.localName)||e.localName===qi();function is(e){for(let t of Array.from(e.childNodes))3===t.nodeType?""===t.data?t.replaceWith(Fi("wcs-e")):null!==t.nextSibling&&3===t.nextSibling.nodeType&&t.after(Fi("wcs-s")):1===t.nodeType&&!ls(t)&&is(t)}var ss=0;function os(e,t){let n=e.getRootNode(),r=[t];for(let e of Hi.get(n)??[])e!==t&&!0===e.element?.hasAttribute("bind-component")&&r.push(e);let l=new Map;for(let e of r){let t=Bi.get(e);if(void 0===t)continue;let n=new Map;for(let t of e.H.values())if(null!==t.S&&n.set(t.S.E,t.S),null!==t.j)for(let e of t.j)n.set(e.E,e);for(let t of e.ie.values())for(let e of t)if(null!==e.I)for(let t of e.I.W)n.set(t.E,e.I);let r=new Set;for(let[e,i]of t){l.set(e,i);let t=n.get(e);void 0!==t&&!r.has(t)&&e.isConnected&&(r.add(t),es(t))}}for(let e of Array.from(n.querySelectorAll("*"))){let t=Ki.get(e);if(void 0!==t){let n=document.createTreeWalker(e,133,{acceptNode:e=>Ji.has(e)||1===e.nodeType&&t.has(e)&&hs(e)?2:1}),r=[];for(let e=n.nextNode();null!==e;e=n.nextNode()){let n=e.previousSibling;(3===e.nodeType?e.data.includes("{{")&&!(ls(e.parentNode)?Yi.has(e):t.has(n)&&_i(n,"wcs-t:"))&&(Yi.has(e)||t.get(e)!==e.data):!t.has(e))&&r.push(e)}for(let e of r)e.remove()}let n=Array.from(e.childNodes);ls(e)&&n.some(e=>Yi.has(e))&&e.setAttribute(rs,n.map(e=>Yi.has(e)?`{{ ${Yi.get(e)} }}`:8===e.nodeType?`\x3c!--${e.data}--\x3e`:e.textContent).join(""))}is(9===n.nodeType?n.body:n);let i=document.createElement(qi());i.setAttribute("version",Ii);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 r=Object.getOwnPropertyDescriptor(e,n);void 0!==r.get||void 0!==r.set||"function"==typeof r.value||(t[n]=r.value)}return t}(t.target)),i.append(s);for(let[e,t]of l){if(!e.isConnected)continue;let n=e.parentNode;for(;null!==n&&"svg"!==n.localName&&"foreignObject"!==n.localName;)n=n.parentElement;let r="svg"===n?.localName,l=`wcs-${r?"s":"t"}${ss++}`;e.replaceWith(Fi(`wcs-p:${l}`));let s=document.importNode(Wt(t),!0);for(let e of Array.from(s.querySelectorAll("template")))"http://www.w3.org/2000/svg"===e.namespaceURI&&e.replaceWith(Zi(e,document.createElement("template"),...e.childNodes));if(r){let e=document.createElementNS(n.namespaceURI,"svg");e.append(s),s=e}let o=document.createElement("template");o.id=l,i.append(Zi(t,o,s))}e.before(i)}function as(e){!function(e){if(null!==e.querySelector(se.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=>Yi.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(`${se.tagNames.state}[enable-ssr]`))){if(t.hasAttribute("mount")||t.hasAttribute("bind-component")||t.previousElementSibling?.localName===qi())continue;let e=t.engine;null!=e&&os(t,e)}}var us=Symbol.for("wcstack.state.ssr.impl"),cs=new Map,fs=new WeakMap,hs=t=>!0===e.Ro?.(t),ds=e=>1===e.nodeType&&!ls(e)&&!hs(e),ps=e=>e.d.flat().concat(e.Y??[]),ms=e=>{for(let t of ps(e))t.remove()};function gs(e,t,n){let r=/^wcs-\[(?::(\d+))?/.exec(e.data),l=e.previousSibling,i=e.parentNode,s=[],o=e.nextSibling;for(e.remove();null!==o&&!Vi(o,"wcs-]");){let e=o.nextSibling;if(Vi(o,"wcs-|"))s.push([]),o.remove();else{0===s.length&&s.push([]);let n=s[s.length-1];_i(o,"wcs-[")?e=gs(o,t,n):(n.push(o),ds(o)&&ys(o,t))}o=e}let a={branch:void 0===r[1]?null:Number(r[1]),d:s,Y:o??i.appendChild(Fi("wcs-]"))},u=ps(a);o=a.Y.nextSibling;for(let e of u)n?.push(e),t&&Mt.add(e);return t&&null!==l?cs.set(l,a):ms(a),o}function ys(e,t){for(let n=e.firstChild;null!==n;)_i(n,"wcs-[")?n=gs(n,t):(ds(n)&&ys(n,t),n=n.nextSibling)}function bs(e,t,n){let r=e=>{for(let l of Array.from(e.childNodes))if(l.parentNode===e)if(8===l.nodeType){let e=l.data;try{if("wcs-s"===e)l.remove();else if("wcs-e"===e)l.replaceWith("");else if(e.startsWith("wcs-t:")){let t=Fi(`@@:${decodeURIComponent(e.slice(6))}`),n=l.nextSibling;for(;null!==n&&!Vi(n,"wcs-/t");){let e=n.nextSibling;n.remove(),n=e}n?.remove(),l.replaceWith(t)}else if(e.startsWith("wcs-p:")){let n=t.querySelector(`template[id="${e.slice(6)}"]`);if(null!==n){let t=l.parentNode,r="s"===e[10]?Zi(n,document.createElementNS(t.namespaceURI,"template"),...document.importNode(n.content.firstChild,!0).childNodes):document.importNode(n,!0);r.removeAttribute("id"),t.replaceChild(r,l)}}}catch{}}else 1===l.nodeType&&!ls(l)&&(hs(l)?fs.set(l,{ssr:t,Pe:n}):r(l))};r(e),function(e){for(let t of Array.from(e.querySelectorAll("table > tbody"))){let e=[];for(let n=t.previousSibling;null!==n&&(8===n.nodeType||Ts(n)||"template"===n.localName);n=n.previousSibling)e.unshift(n);let n=0,r=0;if(e.forEach((e,t)=>{_i(e,"wcs-[")?r++:Vi(e,"wcs-]")&&--r<0&&(r=0,n=t+1)}),0===r)continue;let l=0;for(let r=t.firstChild;null!==r;r=r.nextSibling)if(_i(r,"wcs-["))l++;else if(Vi(r,"wcs-]")&&0===l--){t.prepend(...e.slice(n));break}}}(e),ys(e,n)}function $s(t,n){let r=fs.get(t);if(void 0===r)return null;fs.delete(t);let l=e=>bs(e,r.ssr,r.Pe);if(r.Pe||ks(n,t,t,l),l(t),!r.Pe)return null;let i=e.Pe;return e.Pe=Os,()=>{e.Pe=i,vs()}}function vs(){for(let e of cs.values())ms(e);cs.clear()}function ws(e){let t=[];for(let n=document.createTreeWalker(e,128);n.nextNode();)t.push(n.currentNode);return t}function As(e,t,n,r){let l=null;for(let r of e){let e=r[n];null!==e&&(""===e||t===e||t.startsWith(`${e}.`))&&(null===l||e.length>l[n].length)&&(l=r)}let i=l?.[r];if(null==i)return null;let s=l[n],o=""===s?t:t.slice(s.length+1);return""===i?o:""===o?i:`${i}.${o}`}function ks(e,t,n,r){let l=document.createElement("template").content;for(let e of n.childNodes)l.appendChild(l.ownerDocument.importNode(e,!0));r(l),e.root=t;let i=()=>{};Pt(e,[...l.childNodes],null,!0,i,i,i,(t,n)=>Nt(e,n,null,0))}function xs(e,t,n){if(Ui()){if(n instanceof Array){for(let e=n.length;e-- >0;)wt(n[e])&&n.splice(e,1);let e=t;if(n.some(At))Ji.add(e);else if(e.localName.includes("-")&&!hs(e)){let t=new Map;for(let n=document.createTreeWalker(e,133);n.nextNode();)t.set(n.currentNode,n.currentNode.data);Ki.set(e,t)}return}if("string"==typeof n){if(Yi.set(t,n),ls(t.parentNode))return;let e=Fi(`wcs-t:${encodeURIComponent(n)}`),r=Fi("wcs-/t");return t.before(e),void t.after(r)}let r=Bi.get(e);void 0===r&&Bi.set(e,r=new Map),r.set(t,n);let l=t.getRootNode(),i=Hi.get(l);return void 0===i&&Hi.set(l,i=new Set),void i.add(e)}if("string"!=typeof n&&cs.size>0){let e=cs.get(n);void 0!==e&&(cs.delete(n),cs.set(t,e))}}var Ss=e=>null!==e&&8===e.nodeType&&[se.commentIfPrefix,se.commentElseIfPrefix,se.commentElsePrefix].includes(e.data),Ts=e=>3===e.nodeType&&""===e.data.trim(),Ns=e=>{let t=cs.get(e)?.Y??e;return(Xi(t)??t).nextSibling};function js(e,t){if(t.length!==e.Ot.childNodes.length)return!1;let n=e.ln;for(let r=0;r<n.length;r++){let l=n[r],i=e.Ot,s=t[l[0]];for(let e=0;;){if(i=i.childNodes[l[e]],s?.nodeName!==i.nodeName)return!1;if(++e===l.length)break;s=(Xi(s)??s).firstChild;for(let t=l[e];t>0&&null!==s;t--)s=Ns(s)}e.xo[r]=s}return!0}function Os(e,t,n){if(0===cs.size)return null;let r=t,l=0;if(!n){let e=se.commentIfPrefix;if(!Vi(t,e))for(let n=t.previousSibling;null!==n&&1!==n.nodeType&&(Ss(n)&&l++,!Vi(n,e));n=n.previousSibling);for(let n=t.nextSibling;!cs.has(r)&&null!==n&&!Vi(n,e)&&1!==n.nodeType;n=n.nextSibling)Ss(n)&&(r=n)}let i=cs.get(r);if(void 0===i)return null;if(!n&&i.branch!==l)return cs.delete(r),ms(i),null;let s=i.d.shift();if(0===i.d.length&&cs.delete(r),i.Y?.replaceWith(...Gi(t,r)),i.Y=null,void 0===s)return null;let o=[];for(let e=0;e<s.length;e++){let t=cs.get(s[e]);if(o.push(s[e]),void 0!==t)for(;e<s.length&&s[e]!==t.Y;)e++;else Xi(s[e])===s[e+1]&&e++}if(!js(e,o)){let n=(e.Mn?e.root:e.Ot).cloneNode(!0);o=e.Mn?[n]:[...n.childNodes],js(e,o),(s[0]??i.d.find(e=>e.length>0)?.[0]??t).before(n);for(let e of s)e.remove()}return o}var Cs={name:"ssr",hooks:e,install(){e.Ln=xs,e.wr=$s;let n=e.element;e.element=(t,r)=>{"mounting"===r&&function(t){let n=t.element;if(!n.hasAttribute("enable-ssr")||Ui())return;let r=n.previousElementSibling,l=r?.localName===qi(),i=l?r.getAttribute("version"):null,s=null===i||Ri(i)===Ri(Ii);if(s){let e=t,n=e.Te;e.Te=(e,r)=>"$connectedCallback"===e?void 0:n.call(t,e,r)}if(!l)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] <${qi()} version="${i}"> does not match ${Ii}: 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?r.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 r=Object.getOwnPropertyDescriptor(n,t);void 0!==r&&(void 0!==r.get||void 0!==r.set||"function"==typeof r.value)||(n[t]=e[t])}t.hydrated=!0}let f=n.getRootNode();for(let e of Array.from(f.querySelectorAll(`[${rs}]`)))e.textContent=e.getAttribute(rs),e.removeAttribute(rs);let h=9===f.nodeType?f.body:f;r.remove();let d=e=>o?function(e,t,n){let r=new Map,l=e=>{let t=e.parentElement;for(;null!==t&&!hs(t);)t=t.parentElement;if(null===t)return null;let n=r.get(t);if(void 0===n){let e=l(t),i=t.querySelector(`:scope > ${se.tagNames.state}[bind-component]`).getAttribute("bind-component");r.set(t,n=[]);for(let r of he(t.getAttribute(se.bindAttributeName)??"")){let t=r.et;r.we[0]===i&&n.push([e?As(e,t,1,0):t,r.we.slice(1).join("."),e&&t])}}return n},i=(e,t,n)=>{let r=l(e);if(null===r)return t;let i=/^([^|]*)#m\d+\.([^|]*)$/.exec(t);if(null===i)return n?t:As(r,t,0,1)??t;let s=i[1].replace(/#m\d+\./g,"").slice(0,-1);return r.some(e=>""===e[1]&&(e[0]===s||e[2]===s))?i[2]:As(r,i[2],2,1)??i[2]};for(let t of ws(e).reverse()){let e=/^@@wcs-(\w+)-start:([\s\S]*)/.exec(t.data);if(null===e)continue;let r=t.nextSibling;for(;null!==r&&!Vi(r,`@@wcs-${e[1]}-end:${e[2]}`);)r=r.nextSibling;if(null!==r){for(;t.nextSibling!==r;)t.nextSibling.remove();r.remove(),t.replaceWith(..."text"===e[1]?[Fi(`@@:${i(t,e[2],n)}`)]:[])}}let s=(e,n)=>{for(let r of ws(e)){let e=/^@@wcs-(?:for|if|elseif|else):(\S+)$/.exec(r.data)?.[1],l=Array.from(t.querySelectorAll("template")).find(t=>t.id===e);if(void 0===l)continue;let o=document.importNode(l,!0),a=se.bindAttributeName;o.removeAttribute("id"),o.setAttribute(a,o.getAttribute(a).replace(/^(\s*\w+\s*:\s*)([^\s|]+)/,(e,t,l)=>t+i(n??r,l))),s(o.content,n??r);let u=o.content.firstChild;r.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,r,u):bs(e,r,s);s||ks(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),r=e.map(e=>e.selected),l=e.map(e=>e.hasAttribute("selected")),i=l.lastIndexOf(!0);i<0&&(i=e.findIndex(e=>!e.disabled)),(n.multiple?e.some((e,t)=>r[t]!==l[t]):n.selectedIndex!==i)&&t.push([n,()=>e.forEach((e,t)=>e.selected=r[t])])}else if("checkbox"===n.type||"radio"===n.type){let e=n.checked;e!==n.defaultChecked&&(e||"checkbox"===n.type)&&t.push([n,()=>n.checked=e])}else if("file"!==n.type&&n.value!==n.defaultValue){let e=n.value;t.push([n,()=>n.value=e])}return()=>{for(let[e,n]of t)e.isConnected&&(n(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}}(h)),d(h),s&&(e.Pe=Os,queueMicrotask(()=>{vs(),e.Pe=null}))}(t),n?.(t,r)},function(){let e=globalThis;e[us]={build:as,reset(){ss=0}},void 0===e[zi]&&(e[zi]={protocol:"wcs-ssr-snapshot",version:1,build:t=>e[us].build(t),reset:()=>e[us].reset()})}(),e.Io=t(e.Io,Li);for(let e of ln())Li(e)}},Ms="__WCSTACK_DEVTOOLS_HOOK__",Ps=null,Es=new Set,Ws=(e,t,n)=>({absolutePathInfo:{pathInfo:{path:t.t},stateElement:e.element},listIndex:null===n?null:{indexes:e.K(n)}}),Is=new WeakMap,Rs=0;var Ds=new WeakMap;function Ls(e){if(null===Ps)return;let t=Ds.get(e),n=Es.has(e)?function(e,t){let n=new Map,r=new Set,l=(r,l,i,s,o,a)=>{if(5===r)return;let u=function(e,t){return 0===e?"textContent":2===e?`class.${t}`:3===e?`attr.${t}`:4===e?`style.${t}`:t}(r,l),c=0===s.n?null:o,f=`${(e=>{let t=Is.get(e);return void 0===t&&Is.set(e,t=++Rs),t})(i)}|${u}|${s.t}|${null===c?"":e.K(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:Ws(e,s,c)})},i=e=>l(e.i,e.name,e.l,e.o,e.r,e.rn()),s=e=>{if(!r.has(e)){if(r.add(e),null!==e.Se)for(let t of e.Se)i(t);if(e instanceof nt&&null!==e.me){let t=e.$.Xe;for(let n=0;n<t.length;n++){let r=e.U?.[n];void 0!==r?i(r):l(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(!r.has(e))if(r.add(e),e instanceof ht){l(-1,"for",e.E,e.a.o,e.a.oe,"for");for(let t of e.Ce)s(t)}else null!==e.D&&s(e.D)};for(let t of e.ie.values())for(let e of t)i(e),null!==e.I&&o(e.I);for(let t of e.H.values())if(null!==t.S&&o(t.S),null!==t.j)for(let e of t.j)o(e);return n}(e,t):new Map;if(void 0!==t)for(let[e,r]of t)n.has(e)||Ps({type:"state:binding-removed",...r});for(let[e,r]of n)(void 0===t||!t.has(e))&&Ps({type:"state:binding-added",...r});Ds.set(e,n)}function qs(e){let t=zt.get(e);if(void 0===t)throw new Error("[@wcstack/state] devtools: no state tree on this root");return t}function zs(e){let t=new Set,n=new Set,r=new Set,l=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&&r.add(i.t),null!==i.ce&&l.add(i.t)}let i=e.target;return{rootNode:e.root,element:e.element,paths:{list:t,element:n,getter:r,setter:l},commandTokenNames:new Set(Object.keys(e.commands)),eventTokenNames:new Set(e.de.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 Us=new WeakSet,Fs=new WeakMap;function Vs(e,t){if(("mounting"===t||"reset"===t)&&function(e){let t=(t,n)=>{if(Us.has(t))return;Us.add(t);let r=t.emit;t.emit=(...l)=>(null!==Ps&&Ps({type:"state:token-emit",kind:n,tokenName:t.name,args:l,subscriberCount:t.size,stateElement:e.element}),r.apply(t,l))};for(let n of Object.values(e.commands))t(n,"command");for(let n of e.de.values())t(n,"event")}(e),"connected"===t){if(Es.has(e))return;Es.add(e),Ps?.({type:"state:element-registered",rootNode:e.root,element:e.element}),Ls(e)}else"disconnected"===t&&(Es.delete(e),Ls(e),Ps?.({type:"state:element-unregistered",rootNode:e.root,element:e.element}))}function _s(e,t,n,r,l,i){if(null===Ps)return;let s=Ws(e,t,0===t.n?null:n),o=Fs.get(e);void 0===o&&Fs.set(e,o=new Set),o.add(s),i&&Ps({type:"state:write",absoluteAddress:s,value:l,oldValue:r,hasOldValue:!0})}function Bs(e){if(null===Ps)return;let t=Fs.get(e);Fs.delete(e),void 0!==t&&Ps({type:"state:update-batch",addresses:t}),Ls(e)}function Hs(e,t,n){Ps?.({type:"state:binding-apply-error",path:n.o.t,bindingType:n.rn(),error:t})}var Ks={"*":["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 Js(e,t){let n=e.localName;if(n.includes("-"))return null;let r=(e=>[...Ks["*"],...Object.hasOwn(Ks,e)?Ks[e]:[]])(n);return r.includes(t)||A(1205,[n,t,r.join(", ")],t,r),(e,n)=>e[t](...n[0]instanceof Event?[]:n)}var Ys=[Nn,Pr,rl,fl,$i,Wi,Cs,{name:"devtools",hooks:e,install(){e.element=t(e.element,Vs),e.se=t(e.se,_s),e.he=t(e.he,Bs),e.Ge=t(e.Ge,Hs),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 r of t)r.onEvent?.(e.id,n)})};return{version:2,sources:e,register(r){if(!e.has(r.id)){e.set(r.id,r),n(r);for(let e of t)e.onSourceRegistered?.(r)}},unregister(n){let r=e.get(n);if(void 0!==r){r._setSink(null),e.delete(n);for(let e of t)e.onSourceUnregistered?.(n)}},addListener(r){t.add(r);for(let t of e.values())n(t),r.onSourceRegistered?.(t);return()=>{if(t.delete(r))for(let t of e.values())n(t)}}}}());2!==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:Ii,getStateElements:()=>[...Es].map(zs),overlays:()=>[],keyedSubscriptions:e=>function(e){let t=[];for(let n of e.O.all()){let r=n.V,l=n.je?.length??0;if((null===r||0===r.size)&&0===l)continue;let i,s=0;if(null!==r)for(let e of r.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===r?0:r.size,lists:l,lastValue:i})}return t}(qs(e)),keys(e){let t=qs(e).target;return Object.keys(t).filter(e=>{if(e.includes("*")||"$"===e[0])return!1;let n=Object.getOwnPropertyDescriptor(t,e);return void 0!==n.get||"function"!=typeof n.value})},read(e,t,n){let r;return qs(e).element.createState("readonly",e=>{r=e.$resolve(t,n??[])}),r},write(e,t,n,r){qs(e).element.createState("writable",e=>{e.$resolve(t,r??[],n)})},_setSink(t){let n=null===Ps&&null!==t;Ps=t,null===t&&(Ds=new WeakMap),e.ut=t&&((e,t)=>Ps?.({...t,stateElement:e.element})),n&&queueMicrotask(()=>{for(let e of Es)Ls(e)})}})}()}},{name:"native-commands",hooks:e,install(){e.lr=Js}}],Gs=Symbol.for("wcstack.package"),Zs=new WeakSet;function Xs(e,t){Object.defineProperty(e,Gs,{value:t,configurable:!0})}function Qs(e,t,n,r,l){if(void 0!==r&&(n===r||n.prototype instanceof r))return;let i=n[Gs];if(i===l||Zs.has(e))return;Zs.add(e);let s=l.slice(0,l.lastIndexOf("@"));console.warn(`[${s}] [wcs/package-twice] <${t}> is already defined by ${i??`another copy of ${s} that does not name its version`}; this copy, ${l}, does nothing. Load each package once.`)}function eo(e){return e}var to=["formats","diagnostics","temporal","list-keys","scopes","recursion","ssr","devtools","native-commands"],no={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][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","string","string"]},time:{description:"ロケール形式の時刻 ([locale][, style][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","string","string"]},datetime:{description:"ロケール形式の日時 ([locale][, style][, zone]。style は full / long / medium / short、zone は IANA のタイムゾーン(Asia/Tokyo — 無ければ読み手のゾーン)、空の引数は既定、既定のロケールは config.locale)",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:3,argTypes:["string","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"]}},ro=2,lo=Object.freeze({}),io=Object.freeze({}),so=Object.freeze({}),oo=Object.freeze(["prevent","stop","ro","direct"]),ao=Object.freeze(["init","sync"]),uo=["enableMustache","sameValueGuard","enableDirectionalInitialSync"];function co(){return{version:2,syntax:{bindAttribute:se.bindAttributeName,tagName:se.tagNames.state,pathDelimiter:".",wildcard:"*",delimiters:{binding:";",propValue:":",modifier:"#",filter:"|"},structuralDirectives:Array.from(ue),modifiers:{flags:oo,keyValue:ao,eventNamePrefix:"on"},indexParam:{prefix:"$",maxDepth:128},bindingTypes:{elseKeyword:j,spread:"...",eventPropertyPrefix:"on",explicitPropertyPrefix:".",propNamespaces:{eventToken:O,command:C,class:M,attr:P,style:E}}},filters:[...Object.keys(Ne),...Object.keys(Sn)],filterMeta:no,filterAliases:lo,declarationAliases:io,apiAliases:so,reservedLifecycle:["$connectedCallback","$disconnectedCallback","$renderedCallback","$errorCallback","$stateReadyCallback"],reservedStateApi:["$bindables","$commands","$commandTokens","$command","$eventTokens","$on","$stream","$watch","$listKeys","$recursion","$streamStatus","$streamError","$behavior","$features"],behaviorOptions:Object.fromEntries(uo.map(e=>[e,{type:"boolean",default:!0}])),features:[...to],nativeCommands:Object.fromEntries(Object.entries(Ks).map(([e,t])=>[e,[...t]]))}}var fo=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),ho=Object.freeze([]);function po(e){if(!se.enableContractAnalyzer)return ho;let t=[],n=Ps,r=e=>{t.push(e),n?.(e)},l=e.manifestExtensions;if(null===l||"object"!=typeof l)return t;for(let e of Object.keys(l))fo.has(e)||r({type:"contract:unsupported-extension",namespace:e});let i=l["wcstack.types"]?.components;if(null==i)return t;for(let[e,t]of Object.entries(i)){let n=mo(e);if(r({type:"contract:manifest-read",tag:e,loaded:null!==n}),null===n){r({type:"contract:drift",reason:"component-not-loaded",tag:e});continue}let l=null!==t&&"object"==typeof t?t:{};for(let[t,i]of Object.entries(l.observables??{})){let l=n.de.get(t);if(void 0===l){r({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}let s=i?.event;"string"==typeof s&&s!==l&&r({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:s,liveEvent:l})}for(let t of Object.keys(l.inputs??{}))n.inputs.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(let t of Object.keys(l.commands??{}))n.commands.has(t)||r({type:"contract:drift",reason:"missing-member",tag:e,member:t})}return t}function mo(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:[],r=new Map;for(let e of n(t.properties))"string"==typeof e?.name&&"string"==typeof e.event&&r.set(e.name,e.event);let l=e=>new Set(n(e).map(e=>e?.name).filter(e=>"string"==typeof e));return{de:r,inputs:l(t.inputs),commands:l(t.commands)}}function go(t,n){(function(t){for(let n of t)if(!s.has(n.name)){if(n.hooks!==e)throw new Error(`[@wcstack/state] [wcs/feature-foreign] The add-on "${n.name}" is from another copy of @wcstack/state (another version, or another URL): load the core and its add-ons from one build`);s.add(n.name),n.install()}})(Ys),t&&function(e){let t=se,n=se.tagNames,r=Object.entries(e).filter(([,e])=>void 0!==e),l=Object.entries(e.tagNames??{}).filter(([,e])=>void 0!==e);for(let[e,n]of r){let r=t[e];(!Object.hasOwn(t,e)||null===n||typeof n!=typeof r||Array.isArray(n)!==Array.isArray(r))&&A(44,["bootstrapState",e])}for(let[e,t]of l)(!Object.hasOwn(n,e)||"string"!=typeof t)&&A(44,["bootstrapState",`tagNames.${e}`]);for(let[e,n]of r)"tagNames"!==e&&(t[e]=n);for(let[e,t]of l)n[e]=t}(t),function(e,t=customElements){let{state:n,ssr:r}=se.tagNames,l=t.get(n),i=t.get(r);e();let s=`@wcstack/state@${Ii}`;if(void 0!==l)return Qs(t,n,l,nn,s);Xs(t.get(n),s);let o=t.get(r);void 0!==i?Qs(t,r,i,void 0,s):void 0!==o&&Xs(o,s)}(()=>function(t=customElements){(function(){let e=globalThis;void 0===e[_t]&&(e[_t]={protocol:"wcs-binder",version:1,bind:Jt})})(),ln().includes(t)||rn.push(new WeakRef(t));let n=se.tagNames.state;void 0===t.get(n)&&t.define(n,class extends nn{}),e.Io?.(t)}(n),n)}export{Di as Ssr,Me as TRUSTED_TYPES_POLICY_SLOT,Ii as VERSION,ro as WCS_MANIFEST_VERSION,po as analyzeContract,go as bootstrapState,on as buildBindings,lo as builtinFilterAliases,no as builtinFilterMeta,eo as defineState,en as getBindingsReady,oe as getConfig,Pe as getTrustedTypesPolicy,co as getWcsManifest,Ee as setTrustedTypesPolicy};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|