@wcstack/state 3.5.0 → 3.5.2

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.
@@ -1,2 +1,2 @@
1
- import{c as e,r as t,f as n,i as o,a as s}from"./filterRegistry.js";import{P as i,Q as r,T as a,D as l,g as d,U as c,X as u,Y as f,Z as p,_ as h,$ as g,a0 as m,a1 as b,a2 as w,V as y,a3 as v,d as N,W as x,n as I,a4 as S,a5 as k,w as A,a6 as $,a7 as T,a8 as M,a9 as P,I as E,G as C}from"./pathDiagnostics.js";import{r as _,L as W,d as R}from"./errorGuidance.js";const L=Symbol.for("wcstack.binder");const O=Symbol.for("wcstack.binder.pending"),B=Symbol.for("wcstack.binder.taken");function D(){const e=function(){const e=globalThis[L];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;const t=function(){const e=globalThis;let t=e[O];return void 0===t&&(t=[],e[O]=t),t}();if(0===t.length)return;const n=t.splice(0,t.length),o=function(){const e=globalThis;let t=e[B];return void 0===t&&(t=new WeakSet,e[B]=t),t}();for(const t of n)o.add(t),e.bind(t)}const F=/\{\{\s*(.+?)\s*\}\}/g,j=new Set(["SCRIPT","STYLE"]);function z(t){if(!e.enableMustache)return;!function(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[];for(;t.nextNode();)n.push(t.currentNode);for(const e of n)e.parentElement&&j.has(e.parentElement.tagName)||q(e)}(t);const n=Array.from(t.querySelectorAll("template"));for(const e of n)if(e.namespaceURI===i){const t=document.createElement("template"),n=Array.from(e.childNodes);for(let e=0;e<n.length;e++){const o=n[e];t.content.appendChild(o)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),z(t.content)}else z(e.content)}function q(e){const t=e.data;if(F.lastIndex=0,!F.test(t))return;F.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=F.exec(t));){o.index>s&&n.appendChild(document.createTextNode(t.slice(s,o.index)));const e=o[1];n.appendChild(document.createComment(`@@: ${e}`)),s=o.index+o[0].length}s<t.length&&n.appendChild(document.createTextNode(t.slice(s))),e.parentNode.replaceChild(n,e)}const V=new Set(["if","elseif","else","for"]);function H(e,t,n){const o=-1===t?e.length:t;let s=0;for(;s<o&&/\s/.test(e[s]);)s++;const i=-1===n?0:n;let r=e.length;for(;r>i&&/\s/.test(e[r-1]);)r--;return e.slice(s,r)}const U=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function G(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:U.test(e)?Number(e):e)}function X(e){const t=[],n=[];let o="",s=null,i=!1,r=-1,a=-1;const l=()=>{const e=H(o,r,a);t.push(e),n.push(G(e,i)),o="",i=!1,r=-1,a=-1};for(let t=0;t<e.length;t++){const n=e[t];s?n===s?s=null:(-1===r&&(r=o.length),o+=n,a=o.length):'"'===n||"'"===n?(s=n,i=!0):","===n?l():o+=n}null!==s&&_(`[wcs/binding-syntax] unterminated ${s} quote in the filter arguments "(${e})". Close the quote.${W}`);const d=H(o,r,a);return(d||i)&&(t.push(d),n.push(G(d,i))),{args:t,literals:n}}const K=e=>e.trim(),Q=e=>"'"===e||'"'===e;function Y(e,t){let n=null;for(let o=0;o<e.length;o++){const s=e[o];if(null!==n)s===n&&(n=null);else if(Q(s))n=s;else if(s===t)return o}return-1}function J(e,t){const n=[];let o=null,s=0;for(let i=0;i<e.length;i++){const r=e[i];null!==o?r===o&&(o=null):Q(r)?o=r:r===t&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}function Z(e,t,n){const o=n??e.join("|");return e.map(e=>{const n=Y(e,"(");let s=function(e,t){let n=null,o=-1;for(let s=0;s<e.length;s++){const i=e[s];null!==n?i===n&&(n=null):Q(i)?n=i:i===t&&(o=s)}return o}(e,")");if(-1===s&&(s=e.lastIndexOf(")")),-1!==n&&-1===s&&_(`[wcs/binding-syntax] Invalid filter format: missing closing parenthesis in "${e}".${W}`),-1!==s&&-1===n&&_(`[wcs/binding-syntax] Invalid filter format: missing opening parenthesis in "${e}".${W}`),-1!==s&&s<n&&_(`[wcs/binding-syntax] Invalid filter format: ")" comes before "(" in "${e}".${W}`),-1!==s&&e.slice(s+1).trim().length>0){const t=e.slice(s+1).trim();_(`[wcs/binding-syntax] "${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,s+1)}|${t}").${W}`)}const i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&_(`[wcs/binding-syntax] an empty filter in "${o}" — remove the extra "|" or name the filter.${W}`),i.includes(r)){const[e,n]=i.split(r);_("input"===t?`[wcs/binding-syntax] "${i}" is not a filter name: a modifier list "${r}${n}" comes before the input filters, not inside one — write "<property>${r}${n}|${e}".${W}`:`[wcs/binding-syntax] "${i}" is not a filter name: "${r}" cannot appear in one. Modifiers belong on the left side of the binding, before the ":" — write "${e}" here.${W}`)}if(-1===n)return{filterName:i,args:[],literals:[]};return{filterName:i,...X(e.substring(n+1,s))}})}const ee=new Map;function te(e){const t=Y(e,a);let n="",o=[],s="",i=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ee.has(s)?i=ee.get(s):(o=J(s,a).map(K),i=Z(o,"input",e),ee.set(s,i))):n=e.trim();const d=n.split(r).map(K);d.length>2&&_(`[wcs/binding-syntax] "${n}": a binding takes one modifier list after a single "${r}" — write "${d[0]}${r}${d.slice(1).join(",")}".${W}`);const[c,u]=d,f=c.split(l).map(K);f.length>1&&""===f[0]||0!==c.length&&!f.some(e=>0===e.length)||_(`[wcs/binding-syntax] "${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).${W}`);return{propName:c,propSegments:f,propModifiers:u?u.split(",").map(K):[],inFilters:i}}const ne=new Map;function oe(e){const t=Y(e,a);let n="",o=[],s="",i=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ne.has(s)?i=ne.get(s):(o=J(s,a).map(K),i=Z(o,"output",e),ne.set(s,i))):n=e.trim(),-1!==n.indexOf("@")&&_(`"${n}": 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.`);const r=n,c=r.startsWith(l),u=c?r.slice(l.length):r;(u.length>0&&u.split(l).some(e=>0===e.length)||!c&&0===u.length)&&_(`[wcs/binding-syntax] "${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).${W}`);return{statePathName:r,statePathInfo:d(r),outFilters:i}}const se=new Set([c,"if","elseif","for",u]),ie=new Set([g,m,b,w,f,y]);function re(e){const[...t]=function(e){return J(e,v)}(e).map(K).filter(e=>e.length>0),n=t.map(e=>{const t=Y(e,h);-1===t&&_(`[wcs/binding-syntax] Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.${W}`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),s=n.split(r)[0].split(a)[0].trim();if(s!==n&&se.has(s)&&_(`[wcs/binding-syntax] "${e}": "${s}" takes no modifiers or filters on its left side — write "${s}:".${W}`),n===c){o.length>0&&_(`[wcs/binding-syntax] "${e}": "else" takes no value — write "else:".${W}`);const t=d("#else");return{propName:c,propSegments:[c],propModifiers:[],statePathName:"#else",statePathInfo:t,inFilters:[],outFilters:[],bindingType:"else"}}if(n===u){0===o.length&&_(`[wcs/binding-syntax] Invalid spread binding "${e}": spread target path is required.${W}`);const t=oe(o);return t.outFilters.length>0&&_(`[wcs/binding-syntax] Invalid spread binding "${e}": filters are not allowed on spread targets.${W}`),{propName:u,propSegments:[u],propModifiers:[],inFilters:[],...t,bindingType:"spread"}}if("if"===n||"elseif"===n||"for"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...oe(o),bindingType:n}}if("radio"===s||"checkbox"===s){const e=oe(o);return{...te(n),...e,bindingType:s}}{const e=oe(o),t=te(n);if(""===t.propSegments[0]&&t.propSegments.length>1){const o=t.propSegments.slice(1);return(o.includes("")||ie.has(o[0]))&&_(`[wcs/binding-syntax] "${n}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (${[...ie].join(", ")}).${W}`),{...t,propName:o.join(l),propSegments:o,...e,bindingType:"prop"}}return t.propSegments[0]===f||t.propSegments[0].startsWith(p)?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>V.has(e.bindingType))&&_(`[wcs/template-syntax] Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${W}`)}return n}const ae=new WeakMap,le=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),de=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function ce(t){const n=ae.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=de.exec(o);if(null===s)return null;const i=s[1]||e.commentTextPrefix;return le.has(i)?(ae.set(t,s[2]),s[2]):null}function ue(e){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...oe(e),bindingType:"text"}}const fe=new WeakMap,pe=new WeakSet;let he=0;async function ge(e){const t=function(e){let t,n=fe.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++he,promise:o,resolve:t},fe.set(e,n),pe.has(e)&&n.resolve(),n}(e);await t.promise}function me(e){const t=fe.get(e);void 0===t?pe.add(e):t.resolve()}const be=new WeakMap;function we(e){const t=be.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,o=t.tagName.toLowerCase();if(o.includes("-"))return n=o;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{be.set(e,n)}}function ye(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined?null:t}function ve(e=null){if(null!=e){const{customElementRegistry:t,customElements:n}=e;if(null===t)return null;if(void 0!==t)return ye(t);if(void 0!==n)return ye(n)}return ye(globalThis.customElements)}function Ne(e,t){e.upgrade?.(t)}function xe(e){try{if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const t=e,n=t.addEventListener,o=t.removeEventListener,s=t.constructor?.wcBindable;if("function"!=typeof n||"function"!=typeof o)return null;if("wc-bindable"!==s?.protocol)return null;if(!Number.isInteger(s.version)||s.version<1)return null;const i=Ae(s.properties,Ie);if(null===i)return null;const r=void 0===s.inputs?new Map:Ae(s.inputs,Se);if(null===r)return null;const a=void 0===s.commands?new Map:Ae(s.commands,ke);return null===a?null:{target:e,liveDeclaration:s,knownProperties:i,declaredInputs:r,declaredCommands:a}}catch{return null}}function Ie(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&("string"==typeof t.event&&0!==t.event.length&&(void 0===t.getter||"function"==typeof t.getter))}function Se(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.attribute||"string"==typeof t.attribute)}function ke(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.async||"boolean"==typeof t.async)}function Ae(e,t){if(!Array.isArray(e))return null;const n=new Map;for(const o of e){if(!t(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function $e(e,t){const n="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:n,statePathInfo:d(n),inFilters:[],outFilters:[],bindingType:"prop"}}function Te(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function Me(t,n,o={}){const s=o.allowDeferred??!0;if(!n.some(e=>"spread"===e.bindingType))return n;const i=[],r=new WeakSet;for(const e of n){if("spread"!==e.bindingType){i.push(e);continue}t.nodeType!==Node.ELEMENT_NODE&&_("Spread binding requires an element node.");const n=t,o=we(n);null===o&&_(`Spread binding "${e.statePathName}" requires a custom element with wcBindable, but <${n.tagName.toLowerCase()}> is not a custom element.`);const a=ve(n);null===a&&_(`CustomElementRegistry is unavailable for <${o}>.`);if(void 0===a.get(o)){s||_(`Spread binding "${e.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),i.push(e);continue}Ne(a,n);const l=xe(n);null===l&&_(`Spread binding "${e.statePathName}" requires <${o}> to expose a valid wcBindable declaration.`);const d=e.statePathName,c=new Set;for(const e of l.knownProperties.keys()){if(c.has(e))continue;c.add(e);const t=$e(e,d);r.add(t),i.push(t)}for(const e of l.declaredInputs.keys()){if(c.has(e))continue;c.add(e);const t=$e(e,d);r.add(t),i.push(t)}}const a=new Map;for(let e=0;e<i.length;e++){const t=Te(i[e]);null!==t&&a.set(t,e)}const l=[];for(let n=0;n<i.length;n++){const o=Te(i[n]);if(null!==o){if(a.get(o)===n)l.push(i[n]);else if(e.debug&&r.has(i[n])){const e=i[a.get(o)],s=t.nodeType===Node.ELEMENT_NODE?`<${t.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${i[n].propName}" of ${s} overridden by explicit binding (statePath: "${e.statePathName}").`)}}else l.push(i[n])}return l}function Pe(e,t){let n=e;for(let e=0;e<t.length;e++){let o=t[e];for(n=n.firstChild;null!==n&&o>0;)n=n.nextSibling,o--;if(null===n)break}return n}function Ee(e,n){if(0===e.length)return e;const o=[];for(let s=0;s<e.length;s++){const i=e[s],r=i.literals??i.args;o.push({filterName:i.filterName,args:i.args,literals:r,filterFn:t(i.filterName,i.args,n,r)})}return o}function Ce(e){return{...e,inFilters:Ee(e.inFilters,"input"),outFilters:Ee(e.outFilters,"output")}}const _e=new WeakMap;function We(e){return _e.get(e)||null}function Re(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Le(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!Re(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function Oe(e,t){for(let n=0;n<t.length;n++){const o=t[n];if(o!==e&&o.contains(e))return!0}return!1}function Be(t){const n=[],o=Le(t),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(e.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==ce(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const e=s.currentNode;o.length>0&&Oe(e,o)||n.push(e)}return n}const De=new WeakSet;function Fe(e,t,n,o){const s=Me(e,t,{allowDeferred:n.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?we(e):null;return null===n&&_("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t,transform:o}}}De.add(e);const i=function(e,t){const n=[];for(const o of t){const t=Ee(o.inFilters,"input"),s=Ee(o.outFilters,"output");if("text"!==o.bindingType)n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:e});else{const i=e.nodeType===Node.TEXT_NODE?e:document.createTextNode("");n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:i})}}return n}(e,function(e,t){return void 0===t?e:e.map(e=>null!=e.uuid?e:t(e))}(s,o));return function(e,t){_e.set(e,t)}(e,i),me(e),{bindings:i,deferred:null}}function je(e,t){return ze(Be(e),t)}function ze(e,t){const n=[],o=[];for(const s of e){if(De.has(s))continue;const e=Fe(s,Ol(s),{allowDeferred:!0},t);null===e.deferred?n.push(...e.bindings):o.push(e.deferred)}return[e,n,o]}function qe(e){De.add(e)}function Ve(e){const{node:t,parseResults:n,transform:o}=e;!function(e){De.delete(e)}(t);return Fe(t,n,{allowDeferred:!1},o).bindings}const He=new WeakMap;let Ue=null;function Ge(e){Ue=e}function Xe(e){let t=e;for(;t;){const e=He.get(t);if(e)return e;let n=t.parentNode;null===n&&null!==Ue&&t instanceof ShadowRoot&&(n=Ue(t)),t=n}return null}function Ke(e,t){null!==t?He.set(e,t):He.delete(e)}let Qe=0;function Ye(){return`u${(Qe++).toString(36)}`}let Je=0,Ze=0;const et=Symbol("wcs.listIndex.noValue");class tt{uuid=Ye();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;_chainGeneration;_homeParentListIndex;_value;cacheStamp=0;ref;constructor(e,t,n){this.parentListIndex=e,this.position=e?e.position+1:0,this.length=this.position+1,this._homeParentListIndex=n,this._value=et,this._index=t,this._version=Je,this._chainGeneration=Ze}get index(){return this._index}set index(e){this._index=e,this._version=++Je,this.indexes[this.position]=e}get version(){return this._version}get homeParentListIndex(){return this._homeParentListIndex}set homeParentListIndex(e){this._homeParentListIndex=e}get value(){return this._value}set value(e){this._value=e}get dirty(){return null!==this.parentListIndex&&(this.parentListIndex.dirty||this.parentListIndex.version>this._version)}get indexes(){return null===this.parentListIndex?void 0===this._indexes&&(this._indexes=[this._index]):(void 0===this._indexes||this.dirty)&&(this._indexes=[...this.parentListIndex.indexes,this._index],this._version=Je),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0!==this._listIndexes&&this._chainGeneration===Ze||(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)],this._chainGeneration=Ze),this._listIndexes}get varName(){return`$${this.position+1}`}reparent(e){this.parentListIndex=e,this._indexes=void 0,this._listIndexes=void 0,this._version=++Je,Ze++}at(e){return e>=0?this.listIndexes[e]?.deref()||null:this.listIndexes[this.listIndexes.length+e]?.deref()||null}}function nt(e,t,n=e){return new tt(e,t,n)}function ot(e,t){e.reparent(t)}function st(e){return e.homeParentListIndex}function it(e,t){e.homeParentListIndex=t}function rt(e){return e?.cacheStamp}function at(e,t){const n=e,o=n.value,s=o!==et&&!Object.is(o,t);return o!==t&&(lt.get(o)?.delete(n.ref),function(e,t){if("object"!=typeof e||null===e||null===t.parentListIndex)return;let n=lt.get(e);void 0===n?(n=new Set,lt.set(e,n)):n.size>=(dt.get(n)??8)&&(ct(n,t,!0),dt.set(n,2*n.size+8));n.add(t.ref??=new WeakRef(t))}(t,n)),n.value=t,s}const lt=new WeakMap,dt=new WeakMap;function ct(e,t,n=!1){const o=[];return e?.forEach(s=>{const i=s.deref();void 0===i||n&&ft(i)?e.delete(s):i!==t&&o.push(i)}),o}const ut=new WeakSet;function ft(e){for(let t=e;null!==t;t=t.parentListIndex)if(ut.has(t))return!0;return!1}function pt(e){return e.value}function ht(e,t){const n=e.value;return n!==et&&n===t.value}let gt=0;const mt=new WeakSet;function bt(e){mt.add(e)}function wt(e){return mt.has(e)}const yt=new WeakMap;function vt(e){return ut.has(e)}const Nt=new WeakMap;function xt(e,t,n,o){if(!yt.has(e))return!1;let s=!1;for(const t in n)s||=t!==o&&n[t]===e;if(!s){let n=Nt.get(t);void 0===n&&(n=new WeakSet,Nt.set(t,n)),n.add(e)}const i=yt.get(e),r=St.get(e);if(i[0]?.parentListIndex===t&&(!s||r?.[0]!==t||r[1]!==gt))for(const n of _t.get(e)??[])if(n!==t&&n.position===t.position&&Ct(e,n)&&Object(pt(n))[o]===e){i.forEach(e=>ot(e,n)),It.set(e,[t,gt]);break}return s}const It=new WeakMap,St=new WeakMap;function kt(e,t){Nt.get(t)?.delete(e);const n=yt.get(e);if(void 0!==n){St.set(e,[t,gt]);const o=It.get(e);o?.[0]===t&&o[1]===gt&&n.forEach(e=>ot(e,t))}}function At(e,t){return!0===Nt.get(t)?.has(e)}function $t(e,t){return At(e,t)||ft(t)}const Tt=new WeakMap;function Mt(e){Tt.set(e,gt)}function Pt(e){Tt.delete(e)}function Et(e,t,n){const o=Object(pt(t)),s=pt(n);for(const t in s)if(s[t]===e&&o[t]!==e)return!1;return!0}function Ct(e,t){return!$t(e,t)&&Tt.get(t)!==gt}const _t=new WeakMap,Wt=new WeakMap;const Rt=new WeakSet;function Lt(e,t){const n=(o=e,ct(lt.get(o.value),o));var o;if(0===n.length)return n;const s=new Set(yt.get(t()));return n.filter(t=>t.position===e.position&&!s.has(t)&&!ft(t))}function Ot(e,t,n){const o=st(t),s=t.parentListIndex;return null!==o&&o!==s&&!$t(e,o)&&Et(e,o,s)?o:function(e,t,n,o){return null!==t&&null!==o&&o!==n&&!!ut.has(t)&&!(!Ct(e,o)||o.position!==t.position)&&!At(e,t)&&ht(o,t)}(e,o,s,n)||function(e,t,n){return t!==n&&null!==t&&null!==n&&t.position===n.position&&$t(e,t)&&Ct(e,n)}(e,s,n)?n:null}function Bt(e){const t=yt.get(e);return void 0===t?null:t}function Dt(e,t){const n=yt.get(e);if(void 0===n)return null;const o=n[0];if(void 0!==o&&!wt(e)){const s=null!==t&&o.parentListIndex!==t&&Tt.get(t)!==gt,i=Ot(e,o,t);if(null!==i&&Rt.has(e)){Rt.delete(e);const t=[...e];bt(t),yt.set(t,n),Gt(e,t);const o=n.map((t,n)=>{const o=nt(i,n);return at(o,e[n]),o});return yt.set(e,o),o}if(null!==i)for(const e of n)ot(e,i);else if(s){!function(e,t){let n=_t.get(e);void 0===n?(n=new Set,_t.set(e,n)):n.size>=(Wt.get(e)??8)&&(n.forEach(t=>{$t(e,t)&&n.delete(t)}),Wt.set(e,2*n.size+8));for(const e of t)n.add(e)}(e,[o.parentListIndex,t]);const s=o.parentListIndex;if(null!==s&&s.position===t.position&&!Et(e,s,t)&&Et(e,t,s))for(const e of n)ot(e,t)}}return n}const Ft=new WeakSet;function jt(e){return Ft.has(e)}function zt(e){Ft.delete(e)}function qt(e,t,n=!1){null!==t?(n?Ft.add(t):zt(t),yt.set(e,t)):yt.delete(e)}const Vt=new WeakMap;function Ht(e){let t=Vt.get(e);return void 0===t&&(t={value:e},Vt.set(e,t)),t}function Ut(e){return Vt.has(e)}function Gt(e,t){const n=Vt.get(e);void 0!==n&&(n.value=t,Vt.delete(e))}const Xt=new WeakMap,Kt=new WeakMap,Qt=new Set,Yt=new WeakMap,Jt=new WeakMap;function Zt(e){const t=e.absolutePathInfo.stateElement;let n=Kt.get(t);return void 0===n&&(n=new WeakMap,Kt.set(t,n)),n}function en(e){return Xt.get(e)??[]}function tn(e,t){const n=Xt.get(e);Xt.set(e,t),Jt.delete(e);const o=Zt(e);n!==t&&void 0!==n&&o.get(n).delete(e);const s=o.get(t);void 0===s?o.set(t,new Set([e])):s.has(e)||(s.size>=(Yt.get(s)??8)&&(s.forEach(e=>{nn(e.listIndex)&&s.delete(e)}),Yt.set(s,Math.max(8,2*s.size))),s.add(e))}function nn(e){for(let t=e;null!==t;t=t.parentListIndex)if(vt(t))return!0;return!1}function on(e,t){const n=Zt(e).get(t);return void 0===n?Qt:(n.forEach(e=>{nn(e.listIndex)&&n.delete(e)}),n)}function sn(e,t){return!Jt.has(e)&&(Jt.set(e,t),!0)}function rn(e){return Xt.has(e)}const an=new WeakMap;let ln=null,dn=0;function cn(e){return an.get(e)??[]}function un(e,t){null===ln?an.set(e,t):ln.set(e,t)}function fn(){dn++,null===ln&&(ln=new Map)}function pn(){if(0!==dn&&(dn--,!(dn>0||null===ln))){for(const[e,t]of ln)an.set(e,t);ln=null}}function hn(e){return(ln?.has(e)??!1)||an.has(e)}const gn=Symbol("$$setLoopContext"),mn=Symbol("$$getByAddress"),bn=Symbol("$$hasByAddress"),wn=Symbol("$$connectedCallback"),yn=Symbol("$$disconnectedCallback"),vn=Symbol("$$updatedCallback"),Nn=Symbol("$$errorCallback"),xn=new WeakMap,In=new WeakMap;class Sn{absolutePathInfo;listIndex;constructor(e,t){this.absolutePathInfo=e,this.listIndex=t}}function kn(e,t){if(null===t){let t=In.get(e);return void 0!==t||(t=new Sn(e,null),In.set(e,t)),t}{let n=xn.get(t);void 0===n&&(n=new WeakMap,xn.set(t,n));let o=n.get(e);return void 0!==o||(o=new Sn(e,t),n.set(e,o)),o}}const An=new WeakMap;function $n(e,t){let n=An.get(e);void 0===n&&(n=new Map,An.set(e,n));let o=n.get(t);return void 0===o&&(o=Object.freeze(new Tn(e,t)),n.set(t,o)),o}class Tn{pathInfo;stateElement;constructor(e,t){this.pathInfo=t,this.stateElement=e}}function Mn(e,t){return kn($n(e,t.pathInfo),t.listIndex)}function Pn(e,t,n){return kn($n(e,t),n)}const En=new WeakMap;function Cn(e,t){null===t?En.delete(e):En.set(e,t)}function _n(e){return En.get(e)||null}const Wn=new Map;function Rn(e,t){let n,o;if(0===e.wildcardCount||0===t.wildcardCount)return 0;if(1===e.wildcardCount&&t.wildcardCount>0&&t.wildcardPathSet.has(e.path))return 1;e.id<t.id?(n=e,o=t):(n=t,o=e);const s=`${n.path}\t${o.path}`;let i=Wn.get(s);if(void 0!==i)return i;return i=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Wn.set(s,i),i}function Ln(e,t,n){return t<0||t>=n?null:e.at(t-n)}function On(e,t){const n=e.indexes??[];return n.length===t?n:n.slice(n.length-t)}const Bn=new WeakMap;function Dn(e){const t=Xe(e.node);if(null===t)return null;let n=Bn.get(t);if(void 0===n)n=new WeakMap,Bn.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=Rn(t.pathInfo,e.statePathInfo);return n>0&&(o=Ln(t.listIndex,n-1,t.pathInfo.wildcardCount)),o}finally{n.set(e,o)}}const Fn=new WeakMap;function jn(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=_n(n);null===t?_(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function zn(e,t){let n=null;if(n=Fn.get(e)||null,null!==n)return n;const o=jn(e,t),s=Dn(e),i=kl(o);return null===i&&_("No state tree found on this root for binding."),n=Pn(i,e.statePathInfo,s),Fn.set(e,n),n}function qn(e){Fn.delete(e)}const Vn=new WeakMap;function Hn(e,t){const n=Vn.get(e);void 0===n?Vn.set(e,t):n instanceof Set?n.add(t):n!==t&&Vn.set(e,new Set([n,t])),null!==N&&N({type:"state:binding-added",absoluteAddress:e,binding:t})}function Un(e,t){const n=Vn.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&Vn.delete(e),null!==N&&N({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const Gn=new WeakMap;function Xn(e){const t=Vn.get(e);return void 0!==t?t:null!==e.listIndex?Gn.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const Kn=new WeakMap,Qn=new WeakMap;class Yn{pathInfo;listIndex;_parentAddress;_rowAddress;constructor(e,t){this.pathInfo=e,this.listIndex=t,this._rowAddress=null!==t&&e.lastSegment===x}get parentAddress(){const e=this._parentAddress;if(void 0!==e&&(!this._rowAddress||e.listIndex===this.listIndex.parentListIndex))return e;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let n=null;n=this.pathInfo.segments[this.pathInfo.segments.length-1]===x?this.listIndex?.parentListIndex??null:this.listIndex;const o=Zn(t,n);return void 0!==e&&!Jn(o,this.listIndex)&&Jn(e,this.listIndex)?e:this._parentAddress=o}}function Jn(e,t){const n=e.pathInfo;let o=pt(e.listIndex);for(const e of n.segments.slice(n.wildcardPositions[n.wildcardCount-1]+1))o=Object(o)[e];return Bt(o)?.[t.index]===t}function Zn(e,t){if(null===t){let t=Qn.get(e);return void 0!==t||(t=new Yn(e,null),Qn.set(e,t)),t}{let n=Kn.get(t);void 0===n&&(n=new WeakMap,Kn.set(t,n));let o=n.get(e);return void 0!==o||(o=new Yn(e,t),n.set(e,o)),o}}const eo=new WeakMap;function to(e){let t=null;if(t=eo.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=Dn(e);null===n&&_(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=Zn(e.statePathInfo,n)}else t=Zn(e.statePathInfo,null);return eo.set(e,t),t}function no(e){eo.delete(e)}function oo(){const e=new Map,t=new Map;return{add(n,o){let s=e.get(n);return void 0===s&&(s=new WeakSet,e.set(n,s)),!s.has(o)&&(s.add(o),t.set(n,(t.get(n)??0)+1),!0)},remove(n,o){const s=e.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const i=(t.get(n)??1)-1;return i<=0?(e.delete(n),t.delete(n),!0):(t.set(n,i),!1)},has:(t,n)=>e.get(t)?.has(n)??!1,countOf:e=>t.get(e)??0,get keyCount(){return t.size},clear(){e.clear(),t.clear()}}}const so=new Map,io=oo();function ro(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function ao(e){let t="input";for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}function lo(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const o=ao(e),s=ro(e,o);let i=so.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==o.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const s=o.checked;let i=o.value;for(const e of n)i=e.filterFn(i);const r=kl(o.getRootNode());null===r&&_("No state tree found on this root for two-way binding.");const a=Xe(o);r.createState("writable",e=>{e[gn](a,()=>{let n=e[t];if(Array.isArray(n))if(s)-1===n.indexOf(i)&&(e[t]=n.concat(i));else{const o=n.indexOf(i);-1!==o&&(e[t]=n.toSpliced(o,1))}else e[t]=s?[i]:[]})})},so.set(s,i)),e.node.addEventListener(o,i),io.add(s,e),!0}var t,n;return!1}function co(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function uo(e,t){console.error(`[wcstack/state] ${t} rejected.`,e)}function fo(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)co(e)&&Promise.resolve(e).catch(e=>uo(e,t))}class po{_name;_subscribers=new Set;constructor(e){this._name=e}get name(){return this._name}get size(){return this._subscribers.size}subscribe(e){return this._subscribers.add(e),()=>{this._subscribers.delete(e)}}unsubscribe(e){return this._subscribers.delete(e)}emit(...e){const t=[];for(const n of this._subscribers)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[wcstack/state] a subscriber of token "${this.name}" threw; the remaining subscribers still received it.`,e)}return t}}class ho extends po{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==N&&N({type:"state:token-emit",kind:"event",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}const go=new WeakMap;function mo(e,t){let n=go.get(e);void 0===n&&(n=new Map,go.set(e,n));let o=n.get(t);return void 0===o&&(o=new ho(t,e),n.set(t,o)),o}function bo(e){go.delete(e)}const wo=new WeakMap;function yo(e){if(e.propSegments[0]!==f)return!1;const t=e.node,n=we(t),o=ve(t);if(null!==n&&void 0===o?.get(n))return null===o&&_(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(wo.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||_('eventToken binding requires a property name (e.g., "eventToken.error").');const i=function(e){return null===we(e)?null:xe(e)}(t);null===i&&_(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=i.knownProperties.get(s);void 0===r&&_(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.${R(s,i.knownProperties.keys())}`);const a=r.event,l=e.statePathName,d=e.propModifiers,c=e=>{d.includes(S)&&e.preventDefault(),d.includes(k)&&e.stopPropagation();const n=kl(t.getRootNode());null===n&&_("No state tree found on this root for eventToken handler."),n.eventTokenNames.has(l)||_(`[wcs/token-undeclared] eventToken "${l}" is not declared in $eventTokens.${R(l,n.eventTokenNames)}${W}`);const o=Xe(t);n.createStateAsync("writable",async t=>{fo(t[gn](o,()=>{const s=null!==o?On(o.listIndex,o.pathInfo.wildcardCount):[];return mo(n,l).emit(t,e,...s)}),`$on."${l}"`)})};return t.addEventListener(a,c),wo.set(e,{eventName:a,handler:c}),!0}class vo extends po{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==N&&N({type:"state:token-emit",kind:"command",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}function No(e){return e instanceof vo}const xo=new Map,Io=oo();function So(e){const t=e.propModifiers.filter(e=>e===S||e===k).sort().join(",");return`${e.statePathName}::${t}`}const ko=(e,t,n)=>o=>{t.includes(S)&&o.preventDefault(),t.includes(k)&&o.stopPropagation();const s=o.target,i=s.getRootNode(),r=kl(i);null===r&&_("No state tree found on this root for event handler.");const a=Xe(s),l=e.startsWith(A+".");r.createStateAsync("writable",async t=>{fo(t[gn](a,()=>{let d=null!==a?a.pathInfo.wildcardCount:0;if(null!==a){const e=r.addressHooks;if(e){const t=e.handlerScope;for(let e=0;e<t.length;e++)d=t[e](r,s,i,a,d)}}const c=null!==a?On(a.listIndex,d):[];if(l){const s=t[mn](Zn(n,null));return No(s)||_(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),s.emit(o,...c)}const u=t[e];return"function"!=typeof u&&_(`Handler "${e}" is not a function on the state tree.`),Reflect.apply(u,t,[o,...c])}),`"${e}"`)}).catch(t=>uo(t,`"${e}"`))};function Ao(e){return"event"===e.bindingType&&e.propName.startsWith(p)}function $o(e){if(!Ao(e))return!1;const t=So(e);let n=xo.get(t);void 0===n&&(n=ko(e.statePathName,e.propModifiers,e.statePathInfo),xo.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),Io.add(t,e),!0}function To(e){if(!Ao(e))return!1;const t=So(e),n=xo.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);return e.node.removeEventListener(o,n),0!==Io.countOf(t)&&(Io.remove(t,e)&&xo.delete(t),!0)}const Mo=new Map,Po=oo();function Eo(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function Co(e){let t="input";for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}function _o(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const o=Co(e),s=Eo(e,o);let i=Mo.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==o.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===o.checked)return;let s=o.value;for(const e of n)s=e.filterFn(s);const i=kl(o.getRootNode());null===i&&_("No state tree found on this root for two-way binding.");const r=Xe(o);i.createState("writable",e=>{e[gn](r,()=>{e[t]=s})})},Mo.set(s,i)),e.node.addEventListener(o,i),Po.add(s,e),!0}var t,n;return!1}const Wo=new Set(["radio","checkbox"]),Ro=new Set(["value","valueAsNumber","valueAsDate"]);function Lo(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,o=n.tagName.toLowerCase();if("input"===o){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(Wo.has(e)&&"checked"===t)return!0;if(Ro.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=we(n);if(null!==s){const e=ve(n)?.get(s);void 0===e&&_(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=xe(n);if(o?.knownProperties.has(t))return!0}return!1}let Oo=1,Bo=1,Do=1;const Fo=new WeakMap;function jo(e,t,n){let o=Fo.get(e);void 0===o&&(o=new Map,Fo.set(e,o));const s=function(e,t){return`${t}::${e}`}(t,n);let i=o.get(s);return void 0===i&&(i=Oo++,o.set(s,i)),i}function zo(e,t){return"to-element"===t?2*e:2*e+1}const qo=new Set;function Vo(e){return{transactionId:Bo++,originBindingId:e,visitedEdges:qo,hop:0}}function Ho(e,t){const n=new Set(e.visitedEdges);return n.add(t),{transactionId:e.transactionId,originBindingId:e.originBindingId,visitedEdges:n,hop:e.hop+1}}let Uo=null;function Go(){return Uo}function Xo(e,t){const n=Uo;Uo=e;try{return t()}finally{Uo=n}}const Ko=[];let Qo=0;function Yo(e,t,n,o,s=!1){Qo=s?2:1;try{e.createState("writable",e=>{e[gn](t,()=>{e[n]=o})})}finally{Qo=0}}function Jo(){const e=Qo;return Qo=0,e}const Zo=new Map,es=oo(),ts=new WeakMap,ns=e=>e.detail,os=new WeakMap;const ss=new WeakMap;let is=0;const rs=new WeakMap;function as(e,t,o,s){const i=n(e.inFilters);return`${e.propName}::${e.statePathName}::${t}::${i}::${function(e){if(null===e)return"n";let t=ss.get(e);return void 0===t&&ss.set(e,t=++is),`g${t}`}(o)}::${s?"o":"s"}`}const ls=(t,n,o,s,i)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(r),s!==ns||i||function(e,t,n){const o=e[t];let s=null;if(void 0===n?void 0!==o&&(s=`the event carried no detail (undefined) while element.${t} is ${typeof o}`):null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==o&&"object"==typeof o||(s=`the event's detail is an object with a "${t}" key while element.${t} is ${typeof o}`),null===s)return;let i=os.get(e);void 0===i&&(i=new Set,os.set(e,i)),i.has(t)||(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.tagName.toLowerCase()}> "${t}": ${s}. 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.`))}(a,t,l);else{if(!(t in a))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);l=a[t]}let d=l;for(const e of o)d=e.filterFn(d);const c=ts.get(a)?.get(t);if(void 0!==c)for(const e of c)e(d);let u=null;if(e.enablePropagationContext){const o=jo(a,t,n),s=function(e,t){for(let n=Ko.length-1;n>=0;n--){const o=Ko[n];if(o.node===e&&o.receipt.member===t)return o.receipt}return null}(a,t);if(null!==s&&Object.is(s.writtenValue,l))return e.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:a,propName:t,statePathName:n,transactionId:s.transactionId,coveredBySameValueGuard:e.sameValueGuard&&(null===d||"object"!=typeof d)}),void(null!==N&&N({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:zo(o,"to-state"),node:a,member:t}));const i=zo(o,"to-state"),r=Go();if(null!==r&&r.visitedEdges.has(i))return void(null!==N&&N({type:"propagation:suppressed",reason:"visited-edge",transactionId:r.transactionId,edgeId:i,node:a,member:t}));u=Ho(r??Vo(o),i)}const f=kl(a.getRootNode());null===f&&_("No state tree found on this root for two-way binding.");const p=Xe(a),h=()=>Yo(f,p,n,d,i);null!==u?Xo(u,h):h()};function ds(e){const t=we(e.node);if(null!==t){const n=ve(e.node),o=n?.get(t);if(void 0===o)return void(null===n&&_(`CustomElementRegistry is unavailable for <${t}>.`))}if(Lo(e.node,e.propName)&&-1===e.propModifiers.indexOf(I)){const t=function(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=we(e.node);if(null!==n){const o=ve(e.node)?.get(n);void 0===o&&_(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=xe(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}(e),n=function(e){if(null!==we(e.node)){const t=xe(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??ns}return null}(e),o=function(e){if(null===we(e.node))return!1;const t=xe(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}(e),s=as(e,t,n,o);rs.set(e,{key:s,eventName:t});let i=Zo.get(s);void 0===i&&(i=ls(e.propName,e.statePathName,e.inFilters,n,o),Zo.set(s,i)),e.node.addEventListener(t,i),es.add(s,e)}}const cs=new WeakSet;function us(e){cs.add(e)}function fs(e){return!!cs.has(e)&&(cs.delete(e),!0)}const ps=new WeakMap;function hs(e,t){const n=ps.get(e);return!(void 0===n||n<t)&&(n===t?ps.delete(e):ps.set(e,n-t),!0)}const gs=new WeakSet;function ms(e){gs.add(e)}function bs(e){return!!gs.has(e)&&(gs.delete(e),!0)}let ws=0;function ys(){ws--}function vs(){return ws>0}class Ns{registry;entries=new Map;constructor(e){this.registry=e}wait(e,t,n=()=>{}){const o=e.toLowerCase();let s=this.entries.get(o);void 0===s&&(s={waiters:new Set},this.entries.set(o,s),this.registry.whenDefined(o).then(()=>this.settle(o,null),e=>this.settle(o,e)));const i={active:!0,resolve:t,reject:n};return s.waiters.add(i),()=>{i.active&&(i.active=!1,s?.waiters.delete(i))}}pendingCount(e){return this.entries.get(e.toLowerCase())?.waiters.size??0}settle(e,t){const n=this.entries.get(e);if(void 0===n)return;this.entries.delete(e);const o=Array.from(n.waiters);n.waiters.clear();for(const e of o)e.active&&(e.active=!1,null===t?e.resolve():e.reject(t))}}const xs=new WeakMap;function Is(e){let t=xs.get(e);return void 0===t&&(t=new Ns(e),xs.set(e,t)),t}const Ss=new Set([g,m,b,w]);function ks(e,t){let n=null;for(const o of e.propModifiers){const e=o.indexOf("=");if(e<0)continue;const s=o.slice(0,e).trim(),i=o.slice(e+1).trim();s!==$&&s!==T&&_(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&_(`Binding modifier "${t}" may only be specified once.`),n=i)}return n}function As(e){return e.propModifiers.some(e=>e.includes("="))}const $s=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),Ts=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function Ms(e,t){return"state"===e&&"call"===t?$s:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function Ps(t){if(!e.enableDirectionalInitialSync)return As(t)&&_("init=/sync= modifiers require enableDirectionalInitialSync."),$s;const n=null===(o=ks(t,$))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:_(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":_(`Invalid sync modifier value "${e}".`)}(ks(t,T));if("event"===t.bindingType)return null!==n&&"none"!==n&&_("Event bindings only allow init=none."),"call"===s?Ts:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if(Ss.has(t.propSegments[0]))return Ms("state",s);if("prop"!==t.bindingType)return null!==n&&"state"!==n&&"none"!==n&&_(`Binding type "${t.bindingType}" does not support init=${n}.`),Ms(n??"state",s);const i=xe(t.node);if(null===i)return Ms(n??"state",s);const r=i.knownProperties.has(t.propName),a=i.declaredInputs.has(t.propName);r||a||_(`Property "${t.propName}" is not declared by wcBindable.`);const l=n??(r&&!a?"element":"state");return(r&&a?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(l)||_(`init=${l} is incompatible with wcBindable member "${t.propName}".`),"connect"!==s||r||_(`sync=connect requires observable property "${t.propName}".`),{authority:l,syncOn:s,observable:r,outputOnly:r&&!a}}function Es(e){let t=e.getRootNode();return t instanceof DocumentFragment&&!(t instanceof ShadowRoot)&&(t=_n(t)),null===t?null:kl(t)}function Cs(e,t){return"auto"!==t?t:function(e){const t=Es(e.replaceNode);null===t&&_("No state tree found on this root for binding.");const n=to(e);let o=!1;return t.createState("readonly",e=>{o=e[bn](n)}),o}(e)?"state":"element"}let _s=0,Ws=null,Rs=0;const Ls=["active","disposed","failed"],Os=new WeakMap,Bs=new WeakMap,Ds=new WeakMap,Fs=new WeakMap,js=new WeakMap,zs=new WeakMap;function qs(e,t){const n=zs.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):zs.set(e,new Set([n,t]))):zs.set(e,t)}function Vs(e){return zs.has(e)}function Hs(e,t){const n=zs.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function Us(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))Us(n,t)}function Gs(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Xs{root;observer;constructor(e){this.root=e;const t=globalThis.MutationObserver;this.observer="function"==typeof t?new t(e=>this.handleMutations(e)):null,this.observer?.observe(e,{childList:!0,subtree:!0})}handleMutations(e){const t=[],n=[];for(let o=0;o<e.length;o++){const s=e[o],i=s.removedNodes;if(0===i.length||!hs(s.target,i.length))for(let e=0;e<i.length;e++)t.push(i[e]);const r=s.addedNodes;for(let e=0;e<r.length;e++)n.push(r[e])}const o=[];for(const e of t)fs(e)||Us(e,e=>{Hs(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)bs(e)&&!vs()||Us(e,e=>{Hs(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&ll(o)}}const Ks=new WeakMap;function Qs(e){let t=Ks.get(e);return void 0===t&&(t=new Xs(e),Ks.set(e,t)),t}function Ys(e){const t=n(e.inFilters),o=n(e.outFilters);return[e.bindingType,e.propName,e.propModifiers.join(","),e.statePathName,t,o,e.uuid??""].join("\0")}function Js(e,t,n){const o=kl(jn(e,n));null===o&&_("No state tree found on this root for binding.");const s=$n(o,e.statePathInfo);return function(e,t,n){let o=Gn.get(e);void 0===o&&(o=new WeakMap,Gn.set(e,o));const s=o.get(t);void 0===s?o.set(t,n):s instanceof Set?s.add(n):s!==n&&o.set(t,new Set([s,n])),null!==N&&N({type:"state:binding-added",absoluteAddress:kn(e,t),binding:n})}(s,t,e),s}function Zs(e,t){const n=zn(e,t);return Hn(n,e),n}function ei(e,t,n,o){null!==t?Un(t,e):function(e,t,n){const o=Gn.get(e);if(void 0===o)return;const s=o.get(t);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(t),null!==N&&N({type:"state:binding-removed",absoluteAddress:kn(e,t),binding:n}))}(n,o,e),no(e),qn(e)}function ti(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class ni{records=new Set;rowPlan=null;rows=new Set;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;disposedAt=0;constructor(e=null){null!==e&&this.observe(e)}initialize(e,t={},n){const o=t.registerAddress??!0,s={registerAddress:o,registerPathInfo:t.registerPathInfo??o,applyOnReconnect:t.applyOnReconnect??!0},i=[];for(const t of e){const e=this.remember(t,s),o=this.rowOf(e),r=null===o?-1:o.bindings.indexOf(e);if(null!==o&&0===o.phases[r]){const t=o;this.observe(e.replaceNode),s.registerAddress&&null===t.addresses[r]&&null===t.patternPathInfos[r]&&(t.registered=!0,this.registerRowSlot(t,r));continue}const a=Ds.get(e);void 0===a||"disposed"===a.phase||"failed"===a.phase?(this.start(e,s,n),i.push(e)):(this.observe(a.anchor),s.registerAddress&&null===a.address&&null===a.patternListIndex&&(a.options.registerAddress=!0,this.registerAddress(a)),"active"===a.phase&&this.settleInitialRecord(a),this.settleConnectedSnapshot(a))}return i.filter(e=>this.shouldApplyState(e))}activate(e,t){if(Gs(t)&&Qs(t),null===this.rowPlan)for(const n of e){const e=Ds.get(n);if(void 0!==e&&e.session===this&&"disposed"!==e.phase&&"failed"!==e.phase){null===e.address&&null===e.patternListIndex&&(e.options.registerAddress=!0,this.registerAddress(e,t)),"active"===e.phase&&this.settleInitialRecord(e),this.settleConnectedSnapshot(e);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,t)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,e,t)}shouldApplyState(t){if(!e.enableDirectionalInitialSync)return As(t)&&Ps(t),!0;const n=this.rowOf(t);if(null!==n){const e=n.bindings.indexOf(t);if(e>=0){if(!n.registered)return!0;if(2===n.phases[e])return!1;const t=n.plan.slots[e];return 1&n.flags[e]?"state"===t.authority||!t.policy.outputOnly:(n.flags[e]|=1,"state"===t.authority)}}const o=Ds.get(t);return void 0===o||o.session!==this||(!o.options.registerAddress||"waiting-definition"===o.phase||"failed"!==o.phase&&("active"===o.phase&&this.settleInitialRecord(o),o.initialApplyDone?"state"===o.resolvedAuthority||!o.outputOnlyMember&&!o.observationPending:(o.initialApplyDone=!0,"state"===o.resolvedAuthority)))}getRecord(e){const t=this.rowOf(e),n=null===t?-1:t.bindings.indexOf(e);if(null!==t&&n>=0){let o=Bs.get(t);void 0===o&&Bs.set(t,o=[]);return{id:o[n]??(o[n]=++_s),info:e,generation:t.generation,phase:Ls[t.phases[n]],teardowns:null}}const o=Ds.get(e);return o?.session===this?o:null}addTeardown(e,t){const n=Ds.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(ti(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=this.deferredByNode.get(e)??new Set,i=()=>s.delete(a)&&this.deferred.delete(a),r=()=>{const s=ve(e);null===s&&_(`CustomElementRegistry is unavailable for <${t}>.`),a.cancel=Is(s).wait(t,()=>{if(i())try{Ne(s,e),n()}catch(e){o(e)}},e=>{i()&&o(e)})},a={node:e,born:++Rs,cancel:null,arm:()=>{if(null===a.cancel&&this.deferred.has(a))try{r()}catch(e){i(),o(e)}}},l=e.getRootNode();if(null!==Ws||11===l.nodeType&&!Gs(l)){if(null===Ws){const e=Ws=[];queueMicrotask(()=>{Ws=null;for(let t=0;t<e.length;t++)e[t].arm()})}Ws.push(a)}else r();return Gs(l)&&Qs(l),qs(e,this),this.deferredByNode.set(e,s.add(a)),this.deferred.add(a),()=>{i(),a.cancel?.()}}disposeBinding(e){const t=this.rowOf(e);if(null!==t){const n=t.bindings.indexOf(e);if(n>=0)return void this.disposeRowSlot(t,n)}const n=Ds.get(e);void 0!==n&&n.session===this&&this.disposeRecord(n)}get isRowSession(){return null!==this.rowPlan}get currentRowPlan(){return this.rowPlan}disposeBindings(e){for(let t=0;t<e.length;t++)this.disposeBinding(e[t]);if(!(this.rows.size>0))for(const e of Array.from(this.deferred))e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}destroyRow(e){const t=e.length>0?this.rowOf(e[0]):null;null!==t?(this.destroyRowRecord(t),this.rows.delete(t)):this.destroyRecords()}destroyRowRecord(e){for(let t=0;t<e.bindings.length;t++){const n=e.addresses[t];null!==n&&(Un(n,e.bindings[t]),e.addresses[t]=null),e.phases[t]=1}}dispose(){this.disposedAt=Rs;for(const e of Array.from(this.rows))for(let t=0;t<e.bindings.length;t++)this.disposeRowSlot(e,t);for(const e of Array.from(this.records))this.disposeRecord(e);for(const e of Array.from(this.deferred))e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;if(0===this.records.size)return!0;for(const e of this.records)if(e.pendingDefinitions>0||e.observationPending)return!1;return!0}destroyRecords(){this.disposedAt=Rs;for(const e of this.rows)this.destroyRowRecord(e);this.rows.clear();for(const e of this.records)null!==e.address&&(Un(e.address,e.info),e.address=null),e.phase="disposed",e.teardowns=null;this.records.clear()}forEachActiveBindingNode(e){for(const t of this.rows)for(let n=0;n<t.bindings.length;n++)0===t.phases[n]&&e(t.bindings[n].node);for(const t of this.records)"active"===t.phase&&e(t.info.node)}rebindAddresses(){const e=[];for(const t of this.rows)for(let n=0;n<t.bindings.length;n++){if(0!==t.phases[n])continue;if(null===t.addresses[n]&&null===t.patternPathInfos[n])continue;const o=t.bindings[n];this.unregisterRowSlot(t,n),this.registerRowSlot(t,n),this.shouldApplyState(o)&&e.push(o)}for(const t of this.records){if("active"!==t.phase)continue;const n=t.info;if(null===t.address&&null===t.patternListIndex)continue;const o="for"===n.bindingType?zn(n):null;if(ei(n,t.address,t.patternPathInfo,t.patternListIndex),t.address=null,t.patternPathInfo=null,t.patternListIndex=null,this.registerAddress(t),null!==o){const e=zn(n);e!==o&&rn(o)&&tn(e,en(o)),e!==o&&hn(o)&&un(e,cn(o))}this.shouldApplyState(n)&&e.push(n)}return e}observe(e){const t=function(e){const t=e.getRootNode();return Gs(t)?t:null}(e);null!==t&&Qs(t)}handleMutations(e,t,n){for(const n of t)Us(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)Us(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&ll(o)}handleRemovedNode(e){const t=this.knownBindingsByNode.get(e);if(void 0!==t)if(t instanceof Map)for(const e of t.values())this.disposeBinding(e);else this.disposeBinding(t);this.deferredByNode.get(e)?.forEach(e=>{e.cancel?.(),e.cancel=null,this.deferred.delete(e)})}handleAddedNode(e,t){this.deferredByNode.get(e)?.forEach(e=>{e.born<=this.disposedAt||(this.deferred.add(e),e.arm())});const n=this.knownBindingsByNode.get(e);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const e of o){const n=Ds.get(e);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(e);if(void 0!==o)try{this.start(e,o),(o.applyOnReconnect||n.pendingDefinitions>0&&n.generation>this.disposedAt)&&this.shouldApplyState(e)&&t.push(e)}catch{}}}knownMapFor(e){const t=this.knownBindingsByNode.get(e);if(t instanceof Map)return t;const n=new Map;if(void 0!==t){let e=js.get(t);void 0===e&&(e=Ys(t),js.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;qs(n,this);const o=this.knownMapFor(n);let s=js.get(e);void 0===s&&(s=Ys(e),js.set(e,s));const i=o.get(s);if(void 0!==i){const e=this.optionsByBinding.get(i);return void 0!==e&&(e.registerAddress||=t.registerAddress,e.registerPathInfo||=t.registerPathInfo,e.applyOnReconnect||=t.applyOnReconnect),i}return o.set(s,e),this.optionsByBinding.set(e,{...t}),e}initializeRow(e,t){this.rowPlan=e;const n=e.slots,o=t.length,s={id:++_s,session:this,generation:++Rs,plan:e,bindings:t,registered:!1,phases:new Array(o).fill(0),flags:new Array(o).fill(0),addresses:new Array(o).fill(null),patternPathInfos:new Array(o).fill(null),patternListIndexes:new Array(o).fill(null)};this.rows.add(s);for(let e=0;e<o;e++){const o=t[e],i=o.replaceNode;if(qs(i,this),this.addKnownRowBinding(i,o,e),Os.set(o,s),n[e].isEvent){let t=!1;try{t=$o(o)}catch(t){throw s.phases[e]=2,t}t&&(s.flags[e]|=2)}}}activatePlanRows(e,t,n){const o=t.length>0?this.rowOf(t[0]):null;if(null===o||o.bindings!==t){for(const e of t)this.initialize([e],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});return}o.registered=!0;const s=e.slots;let i=!1;for(let e=0;e<t.length;e++)if(0===o.phases[e])null===o.addresses[e]&&null===o.patternPathInfos[e]&&this.registerRowSlot(o,e,n);else{if(i||(o.generation=++Rs,i=!0,this.rows.add(o)),o.phases[e]=0,o.flags[e]=0,s[e].isEvent){let n=!1;try{n=$o(t[e])}catch(t){throw o.phases[e]=2,this.runRowSlotTeardowns(o,e),t}n&&(o.flags[e]|=2)}this.registerRowSlot(o,e,n)}}rowOf(e){const t=Os.get(e);return void 0!==t&&t.session===this?t:null}registerRowSlot(e,t,n){if(null!==e.addresses[t]||null!==e.patternPathInfos[t])return;const o=e.bindings[t],s=Dn(o);null!==s?(e.patternPathInfos[t]=Js(o,s,n),e.patternListIndexes[t]=s):e.addresses[t]=Zs(o,n)}unregisterRowSlot(e,t){const n=e.addresses[t],o=e.patternPathInfos[t];null===n&&null===o||(ei(e.bindings[t],n,o,e.patternListIndexes[t]),e.addresses[t]=null,e.patternPathInfos[t]=null,e.patternListIndexes[t]=null)}disposeRowSlot(e,t){if(1!==e.phases[t]){e.phases[t]=1,this.runRowSlotTeardowns(e,t);for(let t=0;t<e.phases.length;t++)if(0===e.phases[t])return;this.rows.delete(e)}}runRowSlotTeardowns(e,t){try{this.unregisterRowSlot(e,t)}catch{}if(2&e.flags[t]){e.flags[t]&=-3;try{To(e.bindings[t])}catch{}}}addKnownRowBinding(e,t,n){const o=this.knownBindingsByNode.get(e);if(void 0===o)return void this.knownBindingsByNode.set(e,t);if(o instanceof Map)return void o.set("@plan:"+n,t);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,t),this.knownBindingsByNode.set(e,s)}start(e,t,n){!function(e){const t=e.node,n=e.replaceNode;t!==n&&null!==t.parentNode&&t.parentNode.replaceChild(n,t)}(e);const o=this.optionsByBinding.get(e)??{...t},s={id:++_s,info:e,generation:++Rs,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:null,resolvedAuthority:null,initialSettled:!1,initialApplyDone:!1,outputOnlyMember:!1,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};Ds.set(e,s),this.records.add(s),void 0===n&&this.observe(s.anchor);try{s.phase="attaching",this.attachListeners(s),s.options.registerAddress&&this.registerAddress(s,n),0===s.pendingDefinitions&&(s.phase="active")}catch(e){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),e}}attachListeners(t){const n=t.info;$o(n)?t.eventAttached=!0:n.propSegments[0]!==f?(_o(n)&&ti(t,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const t=Co(e),n=Eo(e,t),o=Mo.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Po.countOf(n)&&(Po.remove(n,e)&&Mo.delete(n),!0))}return!1}(n)),lo(n)&&ti(t,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const t=ao(e),n=ro(e,t),o=so.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==io.countOf(n)&&(io.remove(n,e)&&so.delete(n),!0))}return!1}(n)),this.attachAfterDefinition(t,()=>{if(e.enableDirectionalInitialSync&&Lo(n.node,n.propName)&&-1===n.propModifiers.indexOf(I)){const e=function(e,t,n){let o=ts.get(e);void 0===o&&(o=new Map,ts.set(e,o));let s=o.get(t);return void 0===s&&(s=new Set,o.set(t,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(t),0===o?.size&&ts.delete(e)}}(n.node,n.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});ti(t,e)}ds(n),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{yo(n)&&ti(t,()=>function(e){if(e.propSegments[0]!==f)return!1;const t=wo.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),wo.delete(e),!0)}(n))})}attachAfterDefinition(e,t){const n=we(e.info.node);if(null===n)return void t();const o=ve(e.info.node);if(null===o&&_(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation;ti(e,this.deferUntilDefined(e.info.node,n,()=>{this.isAlive(e,s)&&(t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e)))},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))}))}settleInitialRecord(t){if(e.enableDirectionalInitialSync&&!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=Ps(t.info),n=Cs(t.info,e.authority);if(t.initialPolicy=e,t.resolvedAuthority=n,t.initialSettled=!0,t.outputOnlyMember=e.outputOnly,t.phase="active",!e.observable)return;if("connect"===e.syncOn&&t.info.node instanceof HTMLElement&&!t.info.node.isConnected)return t.observationPending=!0,void ws++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(e,t){if(!this.isAlive(e,e.generation))return;const n=e.info.node,o=e.info.propName;if(!(o in n))return;const s=e.eventSequence,i=n[o];e.observationPending&&(e.observationPending=!1,ys()),t&&e.eventSequence!==s||(e.hasProducerValue=!0,e.producerValue=i,"element"===e.resolvedAuthority&&function(e,t){let n=t;for(const t of e.inFilters)n=t.filterFn(n);const o=Es(e.node);null===o&&_("No state tree found on this root for initial binding sync."),Yo(o,Xe(e.node),e.statePathName,n)}(e.info,i))}settleConnectedSnapshot(t){if(e.enableDirectionalInitialSync&&t.observationPending&&t.info.node instanceof HTMLElement&&t.info.node.isConnected)try{this.readProducerSnapshot(t,!1)}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}}registerAddress(e,t){if(null!==e.address||null!==e.patternListIndex)return;const n=e.info,o=Dn(n);if(null!==o?(e.patternPathInfo=Js(n,o,t),e.patternListIndex=o):e.address=Zs(n,t),!e.options.registerPathInfo)return;const s=kl(n.replaceNode.getRootNode());null===s&&_("No state tree found on this root for binding."),"event"!==n.bindingType&&s.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&Ds.get(e.info)===e&&"disposed"!==e.phase&&"failed"!==e.phase}disposeRecord(e){"disposed"!==e.phase&&(e.phase="disposed",this.runTeardowns(e),this.records.delete(e))}runTeardowns(e){e.observationPending&&(e.observationPending=!1,ys());const t=e.info;if(null!==e.address||null!==e.patternListIndex)try{ei(t,e.address,e.patternPathInfo,e.patternListIndex),e.address=null,e.patternPathInfo=null,e.patternListIndex=null}catch{}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=rs.get(e);if(void 0===t)return;rs.delete(e);const n=Zo.get(t.key);void 0!==n&&(e.node.removeEventListener(t.eventName,n),es.remove(t.key,e)&&Zo.delete(t.key))}(t)}catch{}}if(null!==e.teardowns){const t=Array.from(e.teardowns).reverse();e.teardowns=null;for(const e of t)try{e()}catch{}}if(e.eventAttached){e.eventAttached=!1;try{To(t)}catch{}}}}function oi(e){let t=Fs.get(e);return void 0===t&&(t=new ni(e),Fs.set(e,t)),t}function si(e){return Ds.get(e)?.session??Os.get(e)?.session??null}let ii=null;function ri(e){ii=e}function ai(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const li=Object.freeze([]);const di=new WeakMap;const ci=new WeakMap;function ui(e){return ci.get(e)??[]}function fi(e,t){ci.set(e,t)}const pi=new WeakMap;function hi(e){return pi.get(e)??[]}function gi(e,t){pi.set(e,t)}function mi(e,t){const n=hi(e);for(const e of n)Ke(e,t)}const bi=new WeakMap;function wi(e){return bi.get(e)??[]}function yi(e,t){bi.set(e,t)}Set.prototype.difference||(Set.prototype.difference=function(e){const t=new Set(this);for(const n of e)t.delete(n);return t}),Set.prototype.intersection||(Set.prototype.intersection=function(e){const t=new Set;for(const n of e)this.has(n)&&t.add(n);return t});const vi=new WeakMap,Ni=new WeakSet;function xi(e){return vi.get(e)??null}function Ii(e,t){if(null===t)vi.delete(e);else{vi.set(e,t);const{stateElement:n,pathInfo:o}=e.absolutePathInfo;if(o.wildcardCount>0){for(let e=o.parentPathInfo;null!==e&&e.wildcardCount===o.wildcardCount&&!Ni.has(e);e=e.parentPathInfo)Ni.add(e);n.setPathInfo(o.lastWildcardPath,"prop","internal")}}}function Si(e){const t=vi.get(e);t&&(t.dirty=!0),null!==e.listIndex&&Ni.has(e.absolutePathInfo.pathInfo)&&e.listIndex.cacheStamp++}const ki=Symbol.for("wcstack.transition-runner");function Ai(e){const t=globalThis[ki];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}function $i(e,t,n){const o=Ai(e);if(null!==o)return o.run(t,{source:e,types:n});t()}const Ti=[],Mi=[];let Pi=-1,Ei=0,Ci=!1;function _i(e){Mi.includes(e)||Mi.push(e)}function Wi(e,t=0){const n=Ti.findIndex(e=>e.priority>t),o={listener:e,priority:t};-1===n?Ti.push(o):Ti.splice(n,0,o)}function Ri(e){const t=Ti.findIndex(t=>t.listener===e);-1!==t&&Ti.splice(t,1)}function Li(e){queueMicrotask(()=>{throw e})}class Oi{_queueUpdateRecords=[];_queueRenderOnlyAddresses=[];constructor(){}enqueueAbsoluteAddress(e,t=null){for(let t=0;t<Mi.length;t++)Mi[t](e);Pi>Ei&&(Ei=Pi),Pi<0&&(Ci=!0);const n=this._isQueueEmpty();this._queueUpdateRecords.push({absoluteAddress:e,context:t}),n&&this._scheduleDrain()}enqueueRenderOnlyAddress(e){const t=this._isQueueEmpty();this._queueRenderOnlyAddresses.push(e),t&&this._scheduleDrain()}_isQueueEmpty(){return 0===this._queueUpdateRecords.length&&0===this._queueRenderOnlyAddresses.length}_scheduleDrain(){fn(),queueMicrotask(()=>{const e=this._queueUpdateRecords,t=this._queueRenderOnlyAddresses;this._queueUpdateRecords=[],this._queueRenderOnlyAddresses=[],gt++,this._applyChange(e,t)})}hasQueuedPath(e,t){return this._queueUpdateRecords.some(n=>n.absoluteAddress.absolutePathInfo.stateElement===e&&n.absoluteAddress.absolutePathInfo.pathInfo.path===t)}testApplyChange(e,t){this._applyChange(e.map((e,n)=>({absoluteAddress:e,context:t?.[n]??null})))}_applyChange(e,t=[]){let n=Ci?0:Ei;Ei=0,Ci=!1;const s=new Map,i=new Set;for(let t=0;t<e.length;t++){const n=e[t],o=s.get(n.absoluteAddress);null!==N&&null!=o&&null!==n.context&&o.transactionId!==n.context.transactionId&&N({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:o.transactionId,winnerTransactionId:n.context.transactionId}),s.set(n.absoluteAddress,n.context),i.add(n.absoluteAddress)}for(let e=0;e<t.length;e++){const n=t[e];s.has(n)||s.set(n,null)}const r=[],a=new Map;s.forEach((e,t)=>{if(null!==e&&e.hop>=M)return console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,transactionId:e.transactionId,hop:e.hop,maxHops:M}),void(null!==N&&N({type:"propagation:hop-limit",absoluteAddress:t,transactionId:e.transactionId,hop:e.hop}));const n=Xn(t);if(void 0!==n)if(n instanceof Set)for(const t of n)!1!==t.replaceNode.isConnected&&(r.push(t),null!==e&&a.set(t,e));else!1!==n.replaceNode.isConnected&&(r.push(n),null!==e&&a.set(n,e))});try{const e=()=>{Pi=n+1;try{a.size>0?ll(r,a):ll(r)}finally{Pi=-1}};if(n>P&&r.length>0){if(n++===P+1){const e=[...new Set(Array.from(i,e=>e.absolutePathInfo.pathInfo.path))];console.error("[@wcstack/state] render chain depth limit exceeded; bindings for this batch were not applied.",{maxDepth:P,paths:e}),null!==N&&N({type:"state:render-chain-limit",maxDepth:P,paths:e})}}else if(o()||0===r.length)e();else{const t=$i("state",e);void 0!==t&&t.catch(Li)}}finally{pn(),Pi=n,function(e){for(const t of Ti.slice())t.listener(e)}(i),Pi=-1}}}const Bi=new Oi;function Di(){return Bi}const Fi=new WeakMap,ji=new WeakMap,zi=new WeakMap,qi=new WeakMap;let Vi=!1;const Hi=new WeakMap;function Ui(e){const t=e.absolutePathInfo.stateElement;let n=Hi.get(t);void 0===n&&Hi.set(t,n=new Set),n.add(e)}function Gi(e){const t=Hi.get(e);return void 0===t?null:(Hi.delete(e),t)}const Xi=new WeakMap,Ki=new WeakMap,Qi=new WeakMap,Yi=new WeakMap,Ji=new WeakMap,Zi=[];function er(e,t){const n=tr(e);if(n.recorded.has(t))return;n.recorded.add(t);const o=d(t).cumulativePaths;if(o.length<2)return;let s=Ji.get(e);void 0===s&&Ji.set(e,s=new Map);for(let e=0;e<o.length-1;e++){let n=s.get(o[e]);void 0===n&&s.set(o[e],n=new Set),n.add(t)}}function tr(e){let t=Fi.get(e);return void 0===t&&Fi.set(e,t={byPath:new Map,lastValue:new Map,recorded:new Set,tracked:new Set}),t}function nr(e,t,n){let o=e.get(t);void 0===o&&e.set(t,o=new Set),o.add(n)}function or(e,t,n){const o=e.get(t);o.delete(n),0===o.size&&e.delete(t)}function sr(e,t,n,o){const s=function(e,t){let n=e.byPath.get(t);return void 0===n&&e.byPath.set(t,n=new Map),n}(e,t);let i=ji.get(o);if(void 0===i&&ji.set(o,i=new Map),i.has(t)){const e=i.get(t);return Object.is(e,n)||(or(s,e,o),i.set(t,n),nr(s,n,o)),!1}return i.set(t,n),nr(s,n,o),!0}function ir(e,t,n){const o=e.get(t);return void 0===o?(e.set(t,[n]),!0):(o.push(n),!1)}function rr(e,t,n,o,s,i){e.lastValue.set(t,n),s&&(null!==o.listIndex&&ir(zi,o.listIndex,i)&&function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){let n=Qi.get(t);void 0===n&&Qi.set(t,n=new Set),n.add(e)}}(o.listIndex),null!==i.levelListIndex&&ir(qi,i.levelListIndex,i))}function ar(e,t,n,o,s){Vi=!0;const i=tr(e);er(e,t);rr(i,t,s,o,sr(i,t,n,o),{stateElement:e,path:t,absAddress:o,levelListIndex:null})}function lr(e,t,n,o,s){Vi=!0;const i=tr(e);er(e,t);rr(i,t,s,o,sr(i,t,n.index,o),{stateElement:e,path:t,absAddress:o,levelListIndex:n})}function dr(e,t){tr(e).tracked.add(t)}function cr(e){const t=Fi.get(e);return void 0===t?null:{byPath:t.byPath,lastValue:t.lastValue,tracked:t.tracked,watchers:Xi.get(e)}}function ur(e,t){return!0===Fi.get(e)?.byPath.has(t)||!0===Xi.get(e)?.has(t)}function fr(e,t,n,o,s){Vi=!0,tr(e).lastValue.set(t,s),er(e,t);let i=Xi.get(e);void 0===i&&Xi.set(e,i=new Map);let r=i.get(t);void 0===r&&i.set(t,r=new Set);let a,l=Ki.get(o);if(void 0===l?(Ki.set(o,l=[]),zt(o)):a=l.find(n=>n.stateElement===e&&n.path===t),void 0===a){a={stateElement:e,path:t,indexes:o,getters:new Set},l.push(a),r.add(a);const n=o[0]?.parentListIndex??null;if(null!==n){let e=Yi.get(n);void 0===e&&Yi.set(n,e=new Set),e.add(a)}}a.getters.add(n)}function pr(e,t,n){if("number"!=typeof t)return;const o=e.indexes[t];if(void 0!==o)for(const t of e.getters)n.push(Mn(e.stateElement,Zn(t,o)))}function hr(e,t){if(!Vi||e===t)return;const n=Ki.get(e);if(void 0===n)return;Ki.delete(e);const o=Ki.get(t);Ki.set(t,void 0===o?n:o.concat(n)),zt(t);for(const o of n){o.indexes=t;const n=tr(o.stateElement).lastValue.get(o.path);if("number"!=typeof n)continue;const s=e[n],i=t[n];if(s!==i)for(const e of[s,i])if(void 0!==e&&!vt(e))for(const t of o.getters){const n=Mn(o.stateElement,Zn(t,e));Si(n),Di().enqueueAbsoluteAddress(n,null),Ui(n)}}}function gr(e,t){if(void 0!==e)for(const n of e)t.push(n)}function mr(e,t,n,o,s){const i=Fi.get(e),r=i?.byPath.get(t),a=Xi.get(e)?.get(t);if(void 0===i||void 0===r&&void 0===a)return Zi;const l=i.lastValue.has(t),d=i.lastValue.get(t);i.lastValue.set(t,s);const c=[],u=!n||!Object.is(o,s),f=l&&(!n||!Object.is(d,o))&&!Object.is(d,s);if(void 0!==r&&(n&&gr(r.get(o),c),f&&gr(r.get(d),c),u&&gr(r.get(s),c)),void 0!==a)for(const e of a)n&&pr(e,o,c),f&&pr(e,d,c),u&&pr(e,s,c);return c}function br(e,t){return!0===Ji.get(e)?.has(t)}function wr(e,t){let n=e;for(const e of t){if("object"!=typeof n||null===n)return;n=n[e]}return n}function yr(e,t,n,o,s=!0){const i=d(t).segments.length,r=[];for(const a of Ji.get(e).get(t)){const t=d(a).segments.slice(i);if(t.includes(x)){vr(e,a,r);continue}const l=s?wr(n,t):void 0;for(const n of mr(e,a,s,l,wr(o,t)))r.push(n)}return r}function vr(e,t,n){const o=Fi.get(e).byPath.get(t);if(void 0!==o)for(const e of o.values())gr(e,n);const s=Xi.get(e)?.get(t);if(void 0!==s)for(const e of s)for(let t=0;t<e.indexes.length;t++)pr(e,t,n)}function Nr(e){const t=qi.get(e.levelListIndex),n=t.indexOf(e);t.splice(n,1)}function xr(e){const t=zi.get(e);if(void 0!==t){zi.delete(e),function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){const n=Qi.get(t);void 0!==n&&(n.delete(e),0===n.size&&Qi.delete(t))}}(e);for(const e of t){const{stateElement:t,path:n,absAddress:o}=e,s=ji.get(o),i=s.get(n);s.delete(n),or(Fi.get(t).byPath.get(n),i,o),null!==e.levelListIndex&&Nr(e)}}}function Ir(e){const t=Yi.get(e);if(void 0!==t){Yi.delete(e);for(const e of t){const t=Xi.get(e.stateElement),n=t.get(e.path);n.delete(e),0===n.size&&t.delete(e.path);const o=Ki.get(e.indexes);o.splice(o.indexOf(e),1),0===o.length&&Ki.delete(e.indexes)}}}function Sr(e){if(!Vi)return;xr(e),Ir(e);const t=Qi.get(e);if(void 0!==t){Qi.delete(e);for(const e of t)xr(e),Ir(e),Qi.delete(e)}}function kr(e,t,n){if(!Vi)return;const o=qi.get(e);if(void 0!==o)for(const{stateElement:e,path:s,absAddress:i}of o){const o=Fi.get(e),r=o.byPath.get(s);or(r,t,i),nr(r,n,i),ji.get(i).set(s,n);const a=o.lastValue.get(s);(Object.is(a,t)||Object.is(a,n))&&(Si(i),Di().enqueueAbsoluteAddress(i,null),Ui(i))}}const Ar=new WeakMap,$r=Object.freeze([]),Tr=new Set,Mr=new WeakMap,Pr=new WeakMap;function Er(e,t){Pr.set(e,new WeakRef(Object(t)))}function Cr(e){return Pr.get(e)?.deref()}function _r(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Wr(e){!function(e){for(const t of e)ut.add(t)}(e);for(const t of e)Sr(t)}function Rr(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:$r,s=Array.isArray(n)&&n.length>0?n:$r,i=function(e,t){const n=Array.isArray(e)&&e.length>0?e:$r,o=Array.isArray(t)&&t.length>0?t:$r;let s=Ar.get(n);return s&&s.get(o)||null}(o,s);if(i&&i.newIndexes===Dt(s,e))return i;const r=Dt(o,e)||[];let a;try{if(0===s.length)return a={oldIndexes:r,newIndexes:[],changeIndexSet:Tr,deleteIndexSet:new Set(r),addIndexSet:Tr};let t=Dt(s,e);if(null===t&&null!==e&&function(e,t){const n=_t.get(e);for(const o of n??[])if($t(e,o))n.delete(o);else if(o!==t)return!0;return!1}(o,e)&&Er(s,o),0===o.length||null===t&&Cr(s)===o){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=nt(e,n);t.push(o)}}return a={oldIndexes:r,newIndexes:t,changeIndexSet:Tr,deleteIndexSet:new Set(r),addIndexSet:new Set(t)}}if(_r(o,s)&&(t??r)===r)return o!==s&&Lr(o,r,e),a={oldIndexes:r,newIndexes:r,changeIndexSet:Tr,deleteIndexSet:Tr,addIndexSet:Tr};if(null!==t)return Or(r,t);t=[];const n=new Map;for(let e=0;e<o.length;e++){const t=o[e];let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}const i=new Set,l=new Set;let d=!1;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),u=c&&c.length>0?c.shift():void 0;if(void 0===u){const n=nt(e,o);t.push(n),l.add(n)}else{const e=r[u];d=!0,u!==o&&i.add(e),t.push(e)}}d&&Lr(o,t,e);return a={oldIndexes:r,newIndexes:t,changeIndexSet:i,deleteIndexSet:new Set(r).difference(new Set(t)),addIndexSet:l}}finally{void 0!==a&&(!function(e,t,n){let o=Ar.get(e);o||(o=new WeakMap,Ar.set(e,o)),o.set(t,n)}(o,s,a),zt(r),qt(s,a.newIndexes))}}(e,t,n);return function(e,t){const n=e.newIndexes;let o;for(let e=0;e<n.length;e++){if(n[e].index!==e){const t=n[e].index;n[e].index=e,kr(n[e],t,e)}at(n[e],t[e])&&(o??=[]).push(n[e])}const s=Mr.get(t);s?.[0]===gt&&(o=o?s[1].concat(o):s[1]),o&&Mr.set(t,[gt,o]),e.valueChangeIndexes=o}(o,Array.isArray(n)&&n.length>0?n:$r),function(e){for(const t of e)ut.delete(t)}(o.newIndexes),Cr(n)!==t&&(Wr(o.deleteIndexSet),hr(o.oldIndexes,o.newIndexes)),o}function Lr(e,t,n){var o;if(o=e,Rt.add(o),null!==n)for(const e of t)it(e,n)}function Or(e,t){const n=new Set(t),o=new Set(e),s=new Set,i=n.difference(o),r=o.difference(n),a=new Map;for(let t=0;t<e.length;t++)a.set(e[t],t);for(let e=0;e<t.length;e++){const n=t[e];i.has(n)||a.get(n)!==e&&s.add(n)}return{oldIndexes:e,newIndexes:t,changeIndexSet:s,deleteIndexSet:r,addIndexSet:i}}function Br(e){if(0===e.changeIndexSet.size||e.addIndexSet.size===e.newIndexes.length)return null;const t=new Map;for(let n=0;n<e.oldIndexes.length;n++)t.set(e.oldIndexes[n],n);const n=[],o=[];let s=-1,i=!0;for(const r of e.newIndexes){if(e.addIndexSet.has(r))continue;const a=t.get(r);if(void 0===a)return null;a<s&&(i=!1),s=a,n.push(r),o.push(a)}if(i)return null;const r=function(e){const t=e.length,n=[],o=new Array(t).fill(-1);for(let s=0;s<t;s++){const t=e[s];let i=0,r=n.length;for(;i<r;){const o=i+r>>1;e[n[o]]<t?i=o+1:r=o}i>0&&(o[s]=n[i-1]),n[i]=s}const s=[];let i=n.length>0?n[n.length-1]:-1;for(;i>=0;)s.push(i),i=o[i];return s.reverse(),s}(o),a=new Set;for(const e of r)a.add(n[e]);return a}const Dr=new WeakMap;function Fr(e){return Dr.get(e)??null}function jr(e,t){Dr.set(e,t)}const zr=new WeakMap;const qr=new WeakMap;function Vr(e,t){for(let n=0;n<e.length;n++)if(t.has(e[n]))return!0;return!1}function Hr(e,t,n,o,s){const i=function(e,t,n){let o=qr.get(e);void 0===o&&qr.set(e,o=new Map);const s=o.get(n);if(void 0!==s)return s;const i=n+".",r=t.map((t,o)=>{const s=e.slots[o];if(s.isEvent||s.isIndexBinding)return null;const r=t.statePathInfo.path;if(!r.startsWith(i))return null;const a=r.slice(i.length).split("."),l=[];let d=n;for(const e of a){if("*"===e)return null;d+="."+e,l.push(d)}return{tail:a,prefixes:l}});return o.set(n,r),r}(e,t,o.pathInfo.path),r=s.stateElement.getterPaths,a=0!==(s.stateElement.addressHooks?.readMissing.length??0);let l,d=!1;for(let e=0;e<t.length;e++){const c=t[e];if(!n.shouldApplyState(c))continue;const u=i[e];if(null===u||Vr(u.prefixes,r)){rl(c,s);continue}if(s.appliedBindingSet.has(c))continue;d||(l=s.state[mn](o),d=!0);const f=u.tail;let p=l,h=!1;for(let e=0;e<f.length;e++){if(null==p){p=void 0;break}if(a&&!(f[e]in Object(p))){h=!0;break}p=p[f[e]]}h?rl(c,s):(s.appliedBindingSet.add(c),il(c,s,p))}}function Ur(e,t,n){mi(e,t);const o=ui(e),s=Fr(e);if(null!==s&&(s.activate(o,n.rootNode),null!==t&&!1===n.stateElement.hasUpdatedCallback&&!0!==n.stateElement.hasRecursion)){const i=function(e){return zr.get(e)??null}(e);if(null!==i)return void Hr(i,o,s,t,n)}for(const e of o){if(null===s){Hn(zn(e),e)}(null===s||s.shouldApplyState(e))&&rl(e,n)}e.spreads&&dl(e.spreads,t,s,o,wi(e))}function Gr(e){if(!e.mounted)return;const t=ui(e),n=Fr(e);for(let e=0;e<t.length;e++){const o=t[e];if(null!==n)n.disposeBinding(o);else{Un(zn(o),o)}}!function(e){const t=hi(e);for(let e=0;e<t.length;e++)Ke(t[e],null)}(e)}function Xr(){return Object.freeze(new Set)}const Kr=new WeakMap,Qr=Xr();function Yr(e,t){const n=Kr.get(e);n?n.add(t):Kr.set(e,new Set([t]))}function Jr(e){const t=Kr.get(e);return void 0!==t?t:Qr}function Zr(e,t){const n=Kr.get(e);n&&(n.delete(t),0===n.size&&Kr.delete(e))}const ea=new Set(["if","elseif","else","for"]);class ta{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(e,t=!1){this._content=e,this._ranged=t;const n=[];for(let t=e.firstChild;null!==t;t=t.nextSibling)n.push(t);this._childNodeArray=n,this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(e){const t=this._childNodeArray;for(let n=0;n<t.length;n++){const o=t[n];ms(o),e.appendChild(o)}this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const e=this._firstNode,t=this._lastNode;if(null===e||null===t||null===e.parentNode)return this._childNodeArray;const n=[];for(let o=e;null!==o;o=o.nextSibling)if(n.push(o),o===t)return n;return this._childNodeArray}mountAfter(e){const t=e.parentNode;if(t){let n=e;for(const e of this._movableNodes()){if(n.nextSibling!==e){ms(e);const o=t;e.parentNode===t&&"function"==typeof o.moveBefore?o.moveBefore(e,n.nextSibling):t.insertBefore(e,n.nextSibling)}n=e}}this._mounted=!0}tryDestroy(){const e=Fr(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRow(ui(this));const t=this._childNodeArray;for(let e=0;e<t.length;e++){const n=t[e];null!==n.parentNode&&(us(n),n.parentNode.removeChild(n))}const n=ui(this);for(let e=0;e<n.length;e++){const t=n[e];ea.has(t.bindingType)&&Jr(t.node).forEach(e=>{e.tryDestroy()||e.unmount()})}return this._mounted=!1,!0}unmountInPlace(){{const e=Fr(this);null!==e&&(e.isRowSession?e.disposeBindings(ui(this)):e.dispose())}this._teardownBindings()}_teardownBindings(){const e=ui(this);for(let t=0;t<e.length;t++){const n=e[t];ea.has(n.bindingType)&&Jr(n.node).forEach(e=>{e.unmount()}),no(n),qn(n)}}unmount(){{const e=Fr(this);null!==e&&(e.isRowSession?e.disposeBindings(ui(this)):e.dispose())}for(const e of this._childNodeArray)null!==e.parentNode&&(us(e),e.parentNode.removeChild(e));const e=ui(this);for(let t=0;t<e.length;t++){const n=e[t];ea.has(n.bindingType)&&Jr(n.node).forEach(e=>{e.unmount()}),no(n),qn(n)}this._mounted=!1}}function na(t){let n=t.topLevelStructural;return void 0===n&&(n=t.topLevelStructural=function(t){const n=new RegExp(`^@@(?:${e.commentForPrefix}|${e.commentIfPrefix}|${e.commentElseIfPrefix}|${e.commentElsePrefix}):`);for(let e=t.firstChild;null!==e;e=e.nextSibling)if(e.nodeType===Node.COMMENT_NODE&&n.test(e.data))return!0;return!1}(t.fragment)),n}function oa(e){return 1<<Math.min(e,31)}const sa=-1;function ia(e){let t=e.indexBits;if(void 0===t){t=0;for(const n of e.nodeInfos)for(const e of n.parseBindTextResults)e.statePathName in E&&(t|=oa(E[e.statePathName])),"string"==typeof e.uuid&&(t|=ia(Rl(e.uuid)));e.indexBits=t}return t}function ra(e){return ia(Rl(e.uuid))}function aa(e,t){return e.statePathName in E||ea.has(e.bindingType)&&0!==(ra(e)&t)}function la(e,t){const n=document.createDocumentFragment(),o=new ta(n,t);return o._childNodeArray=e,o._firstNode=e.length>0?e[0]:null,o._lastNode=e.length>0?e[e.length-1]:null,o._mounted=!0,o}function da(e,t,n){const o=document.importNode(t.fragment,!0),s=t.nodeInfos,i=new Array(s.length);for(let e=0;e<s.length;e++){const t=Pe(o,s[e].nodePath);null===t&&_(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),qe(t),me(t),i[e]=t}const r=n.slots,a=new Array(r.length),l=[];for(let e=0;e<r.length;e++){const t=r[e],n=i[t.nodeIndex],o={...t.template,node:n,replaceNode:n};a[e]=o,t.isIndexBinding&&l.push(o)}const d=function(e,t,n){let o=ul.get(n);void 0!==o&&o.currentRowPlan===e||(o=new ni,ul.set(n,o));return o.initializeRow(e,t),o}(n,a,e.node),c=new ta(o);return jr(c,d),fi(c,a),function(e,t){zr.set(e,t)}(c,n),yi(c,l),gi(c,i),Yr(e.node,c),c}function ca(t){void 0!==t.uuid&&null!==t.uuid||_("BindingInfo.uuid is null.");const n=Rl(t.uuid);n||_(`Fragment with UUID "${t.uuid}" not found.`);const s=!o()&&na(n);let i=n.rowPlan;if((void 0===i||null!==i&&i.directional!==e.enableDirectionalInitialSync)&&(i=n.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],i=Pe(t.fragment,n.nodePath);if(null===i)return null;for(const t of n.parseBindTextResults){const n=t.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=t.propSegments[0];if(s===w||s===f)return null;if("text"===n){if(i.nodeType!==Node.TEXT_NODE)return null}else if(null!==we(i))return null;if("prop"===n&&Lo(i,t.propName))return null;const r=Ce(t);let a;try{a=Ps({...r,node:i,replaceNode:i})}catch{return null}if(a.observable||"auto"===a.authority)return null;o.push({nodeIndex:e,template:r,isEvent:"event"===n,isIndexBinding:t.statePathName in E,policy:a,authority:a.authority})}}return 0===o.length?null:{directional:n,slots:o}}(n)),null!==i)return da(t,n,i);const r=document.importNode(n.fragment,!0),a=function(e,t){const[n,o,s]=function(e,t){const n=[],o=[],s=[];for(const i of t){const t=Pe(e,i.nodePath);if(null===t&&_(`Node not found by path [${i.nodePath.join(", ")}] in fragment.`),De.has(t))continue;const r=Fe(t,i.parseBindTextResults,{allowDeferred:!0});null!==r.deferred&&(s.push(r.deferred),De.add(t)),o.push(...r.bindings),n.push(t)}return[n,o,s]}(e,t),i=new ni,r=i.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:i,spreads:s}}(r,n.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(r,t.uuid);const l=new ta(r,s);a.spreads.length>0&&(l.spreads=a.spreads),jr(l,a.bindingSession),fi(l,a.bindingInfos);const d="for"===t.bindingType?(c=t.statePathInfo.wildcardCount+1,2**Math.min(c,32)-1):-1;var c;const u=[];for(const e of a.bindingInfos)aa(e,d)&&u.push(e);return yi(l,u),gi(l,a.nodes),Yr(t.node,l),l}const ua=new WeakSet,fa=Symbol.for("wcstack.state.view-transition-naming");function pa(){const e=Ai("state");return null===e||"auto"!==e.naming?null:{limit:e.namingLimit}}function ha(e,t,n){const o=function(e){const t=e.firstNode;if(null===t)return null;const n=e.lastNode;for(let e=t;null!==e;e=e.nextSibling){if(e.nodeType===Node.ELEMENT_NODE)return e;if(e===n)break}return null}(e);if(null===o||ua.has(o))return;const s=o.style;if(void 0===s)return;const i=function(){const e=globalThis;return e[fa]??={counter:0,assigned:0,warned:!1}}();i.assigned>=n.limit?i.warned||(i.warned=!0,console.warn(`[@wcstack/state] auto view-transition-name limit (${n.limit}) reached; further elements are left unnamed. Raise naming-limit on <wcs-view-transition>, or switch to naming="manual" and name only what should morph.`)):(ua.add(o),i.assigned+=1,i.counter+=1,s.setProperty("view-transition-name",`wcs-${t}-${i.counter}`),s.setProperty("view-transition-class",`wcs-${t}`))}const ga=new WeakMap,ma=new WeakMap,ba=new WeakMap,wa=new WeakMap,ya=new WeakMap,va=new WeakMap;function Na(e,t,n,o){let s=va.get(e);void 0===s&&(s=[document.createComment(""),document.createComment("")],va.set(e,s));const[i,r]=s;i.data=`@@wcs-for-start:${o}`,r.data=`@@wcs-for-end:${o}`,e.mounted||(i.remove(),r.remove());const a=null===n?null:n.nextSibling;if(null===i.parentNode)t.insertBefore(i,a),t.insertBefore(r,a),e.mountAfter(i);else if(a!==i){let e=i;for(;e!==r;){const n=e.nextSibling;t.insertBefore(e,a),e=n}t.insertBefore(r,a)}return r}function xa(e,t,n){!function(e,t,n){let o=ma.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,ma.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Ia(e,t){ga.set(e,t)}function Sa(e,t){ya.set(e,Ht(t))}function ka(e){return e.nodeType===Node.ELEMENT_NODE||(e.nodeType===Node.TEXT_NODE?""!==(e.textContent?.trim()??""):e.nodeType===Node.COMMENT_NODE&&e.data.startsWith("@@wcs-"))}function Aa(e,t){if(null===t)return!1;if(e.nextSibling===t)return!0;const n=e.compareDocumentPosition(t);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}const $a=new Set(["if","elseif","else","for"]);function Ta(e,t){for(const n of ui(e))if(t.appliedBindingSet.delete(n),$a.has(n.bindingType))for(const e of Jr(n.node))Ta(e,t)}function Ma(e,t,n){for(const o of wi(e))if($a.has(o.bindingType)){if(o.statePathName in E&&rl(o,t),0!==(ra(o)&n))for(const e of Jr(o.node))e.mounted&&Ma(e,t,n)}else rl(o,t)}function Pa(e){for(const t of ui(e)){if(!$a.has(t.bindingType))continue;const e="for"===t.bindingType;for(const n of Jr(t.node))Pa(n),e&&n.mounted&&(Gr(n),n.unmount(),Zr(t.node,n),ya.delete(t.node),ma.delete(t.node))}}function Ea(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function Ca(t,n,i){const r=Boolean(i);let a;const l=Jr(t.node);a=0===l.size?ca(t):l.values().next().value;const d=o(),c=t.uuid??"",u=t.bindingType;if(r||(e.debug&&console.log(`unmount if content : ${Ea(t)}`),d&&a.mounted&&(s.seen=!0),Gr(a),a.unmount()),r){e.debug&&console.log(`mount if content : ${Ea(t)}`);const o=Xe(t.node);if(mi(a,o),d){if(!a.mounted){const e=document.createComment(`@@wcs-${u}-start:${c}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),a.mountAfter(e);const n=document.createComment(`@@wcs-${u}-end:${c}:${t.statePathName}`),o=a.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}}else a.mountAfter(t.node);Ur(a,o,n);const s=pa();null!==s&&ha(a,"branch",s)}}const _a=new WeakMap;function Wa(e){return _a.get(e)??[]}function Ra(){return Array.from(La)}const La=new Set;function Oa(){La.clear()}const Ba=Symbol.for("wcstack.trustedTypes.policy");function Da(){const e=globalThis[Ba];return null===e||"object"!=typeof e?null:e}function Fa(e){globalThis[Ba]=e}let ja;let za=!1;function qa(e,t){if(za)return;if(!function(){if(void 0!==ja)return ja;if(!("trustedTypes"in globalThis))return ja=!1,ja;try{document.createElement("div").innerHTML="<i></i>",ja=!1}catch{ja=!0}return ja}())return;za=!0;const n="function"==typeof Da()?.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 "${t}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${n}\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:e,property:t})}const Va={value(e,t){"TEXTAREA"===e.tagName?e.textContent=String(t??""):e.setAttribute("value",String(t??""))},checked(e,t){t?e.setAttribute("checked",""):e.removeAttribute("checked")},selected(e,t){t?e.setAttribute("selected",""):e.removeAttribute("selected")},disabled(e,t){t?e.setAttribute("disabled",""):e.removeAttribute("disabled")},selectedIndex(e,t){const n=e.querySelectorAll("option"),o=Number(t);for(let e=0;e<n.length;e++)e===o?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function Ha(t,n,s){if(1===t.propSegments.length){const e=t.propSegments[0];"textContent"===e||"innerText"===e?s=null==s?"":String(s):void 0===s&&"innerHTML"===e&&(s="")}if(void 0===s)return void(e.debug&&console.debug("Skipped property write: state value is undefined.",{element:t.node,propSegments:t.propSegments,statePathName:t.statePathName}));const i=t.node,r=t.propSegments;if(1===r.length){const d=r[0],c=i[d];if(c!==s){null!==ii&&null!==c&&"object"==typeof c&&null!==s&&"object"==typeof s&&null!==we(i)&&ii.rememberOverwrittenObject(i,d,c);const o="innerHTML"===(l=d)||"outerHTML"===l||"srcdoc"===l,r=()=>{let t=!1;try{i[d]=o?function(e){if("string"!=typeof e)return e;const t=Da(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(s):s,t=!0}catch(t){o&&qa(i,d),e.debug&&console.warn(`Failed to set property '${d}' on element.`,{element:i,newValue:s,error:t})}if(t){const t=function(e,t){const n=we(e);if(null===n)return null;const o=ve(e)?.get(n);if(void 0===o)return null;const s=xe(e)?.declaredInputs.get(t);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(i,d);if(null!==t)try{!function(e,t,n){if(null==n)return void e.removeAttribute(t);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);e.setAttribute(t,o)}(i,t,s)}catch(n){e.debug&&console.warn(`Failed to mirror attribute '${t}' on element.`,{element:i,newValue:s,error:n})}}};if(e.enablePropagationContext&&Lo(i,d)){const e=jo(i,d,t.statePathName),o=zo(e,"to-element"),a=n?.propagationContextByBinding?.get(t)??Go()??Vo(e);if(a.visitedEdges.has(o))null!==N&&N({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:o,node:i,member:d});else{const t=Ho(a,o);Xo(t,()=>function(e,t,n,o,s,i){const r={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Do++,writtenValue:n};Ko.push({receipt:r,node:e});try{return i()}finally{Ko.pop()}}(i,d,s,e,t.transactionId,r))}}else r()}if(o()){const e=Va[d];e?e(i,s):(!function(e,t,n){let o=_a.get(e);o||(o=[],_a.set(e,o));const s=o.find(e=>e.propName===t);s?s.value=n:o.push({propName:t,value:n})}(i,d,s),a=i,La.add(a))}return}var a,l;const d=r[0];let c=i[d];for(let e=1;e<r.length-1;e++){const t=r[e];if(null==c)return;c=c[t]}const u=r[r.length-1],f=c[u];if(f!==s){if(Object.isFrozen(c))return void(e.debug&&console.warn("Attempting to set property on frozen object.",{element:i,propSegments:r,oldValue:f,newValue:s}));null!==ii&&2===r.length&&"object"==typeof c&&null!==c&&null!==we(i)&&(u in c?ii.rememberOverwrittenValue(i,d,u,c[u]):ii.recordInjectedKey(i,d,u));try{c[u]=s}catch(t){e.debug&&console.warn("Failed to set property on sub-object.",{element:i,propSegments:r,oldValue:f,newValue:s,error:t})}}}const Ua=new WeakSet;function Ga(e,t,n){}function Xa(e,t){const n=to(t);if(n.pathInfo.path in E){const e=Xe(t.node);return null===e&&_(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&_("ListIndex not found for loopContext:");const n=E[t];void 0===n&&_(`Invalid index name: ${t}`);const o=Ln(e.listIndex,n,e.pathInfo.wildcardCount);return null===o&&_(C(`"${t}"`,n+1,e.pathInfo.wildcardCount)),o.index}(e,n.pathInfo.path)}return e[mn](n)}const Ka=new WeakSet;function Qa(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const Ya=Object.freeze({[g]:function(e,t,n){const o=e.node,s=e.propSegments[1];null!=n?("boolean"!=typeof n&&_(`Invalid value for class application: expected boolean, got ${typeof n}. Write "|truthy" if you mean to coerce.`),o.classList.toggle(s,n)):o.classList.toggle(s,!1)},[m]:function(e,t,n){const o=e.node,s=e.propSegments[1];if(null==n)return void(o.hasAttribute(s)&&o.removeAttribute(s));const i=String(n);o.getAttribute(s)!==i&&o.setAttribute(s,i)},[b]:function(e,t,n){const o=e.propSegments[1],s=e.node.style;null==n&&(n=""),s[o]!==n&&(s[o]=n)},[w]:function(e,t,n){No(n)||_("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=di.get(e);if(s&&s.token===o)return;const i=e.node,r=e.propSegments[1];"string"==typeof r&&0!==r.length||_('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=we(e);if(null===t)return null;const n=ve(e)?.get(t);return void 0===n&&_(`Custom element <${t}> is not defined for command binding.`),xe(e)}(i);null===a&&_(`command binding requires a wc-bindable custom element. <${i.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(r)||_(`Command "${r}" is not declared in wcBindable.commands of <${i.tagName.toLowerCase()}>.${R(r,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),di.delete(e));const l=new WeakRef(i);let d=null;d=o.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return d?.(),void di.delete(e);const o=n[r];return"function"!=typeof o&&_(`Method "${r}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),di.set(e,{token:o,unsubscribe:d,elementRef:l})}}),Ja={text:function(e,t,n){const s=null==n?"":String(n);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),o()&&!Ua.has(e.replaceNode)){Ua.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(o,e.replaceNode),t.insertBefore(s,e.replaceNode.nextSibling)}}},for:function(e,t,n){const i=e.statePathInfo,r=Dn(e),a=zn(e),l=en(a),c=ya.get(e.node);let u,f;const p=void 0!==c&&function(e,t){const n=Jt.get(e);return void 0!==n&&(n===t||Bt(t)===Bt(n))}(a,n),h=p||void 0===c||c.value===l?null:Rr(r,l,n);p?(u=c.value,f=Or(Bt(u),Bt(n))):null!==h&&h.newIndexes.every(e=>e.parentListIndex===r||vt(e.parentListIndex)||!At(n,e.parentListIndex))?(u=c.value,f=Or(Bt(u)??[],h.newIndexes)):(u=l.length>0&&!ma.has(e.node)?[]:l,f=Rr(r,u,n));const g=Array.isArray(n)?n:[];t.newListValueByAbsAddress.set(a,g),ya.set(e.node,Ht(g));let m=ma.get(e.node);const b=void 0!==m?function(e,t,n){if(!wt(t))return null;let o=null;for(let t=0;t<n.newIndexes.length;t++){const s=n.newIndexes[t],i=n.oldIndexes[t],r=n.addIndexSet.has(s)&&n.deleteIndexSet.has(i)?e.get(i):void 0;void 0!==r&&(o??={byAddedIndex:new Map,reused:new Set},o.byAddedIndex.set(s,r),o.reused.add(r))}return o}(m,u,f):null,w=Array.isArray(u)&&u.length===f.deleteIndexSet.size&&f.deleteIndexSet.size>0;if(w&&null===b&&null!==e.node.parentNode){let t=wa.get(e.node);if(void 0===t){const n=ga.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(ka(n)){s=!1;break}n=n.previousSibling}for(;null!==o;){if(ka(o)){s=!1;break}o=o.nextSibling}return s}(e.node,n.parentNode===e.node.parentNode?n:e.node),wa.set(e.node,t)}if(t){const t=e.node.parentNode;!function(e,t){ps.set(e,(ps.get(e)??0)+t)}(t,t.childNodes.length),t.textContent="",t.appendChild(e.node)}}let y=w?1e3-function(e){return ba.get(e.node)||[]}(e).length:Number.POSITIVE_INFINITY;const v=o();if(void 0!==m){const t=m;f.deleteIndexSet.forEach(n=>{const o=t.get(n);void 0!==o&&(v&&(va.get(o)?.forEach(e=>e.remove()),s.seen=!0),null!==b&&b.reused.has(o)?(Gr(o),Pa(o),o.unmountInPlace()):y<=0&&o.tryDestroy()?Zr(e.node,o):(Gr(o),o.unmount(),function(e,t){let n=ba.get(e.node);void 0===n&&(n=[],ba.set(e.node,n)),n.length<1e3?n.push(t):Zr(e.node,t)}(e,o),y-=1),w||t.delete(n))}),w&&(ma.delete(e.node),m=void 0)}let N=e.node;const I=d(i.path+"."+x),S=t.stateElement.loopContextStack,k=Br(f);let A=null;f.newIndexes.length==f.addIndexSet.size&&f.newIndexes.length>0&&N.isConnected&&null===b&&(A=document.createDocumentFragment(),Cn(A,t.rootNode));const $=v?`${e.uuid}:${i.path}:`:"",T=pa(),M=ba.get(e.node);for(const n of f.newIndexes){let o;if(f.addIndexSet.has(n)){const s=Zn(I,n);if(S.createLoopContext(s,s=>{o=b?.byAddedIndex.get(n)??(void 0!==M?M.pop():void 0),void 0===o?o=ca(e):(Ta(o,t),mi(o,s)),v?N=null!==A?Na(o,A,null,$+n.index):Na(o,N.parentNode,N,$+n.index):null!==A?o.appendTo(A):N.nextSibling!==o.firstNode&&o.mountAfter(N),Ur(o,s,t),null!==T&&ha(o,"row",T)}),void 0===o&&_(`Content not found for ListIndex: ${n.index} at path "${i.path}"`),null!==b&&b.reused.has(o)){const e=t.stateElement.addressHooks;if(e){const n=e.rowReused;for(let e=0;e<n.length;e++)n[e](t.stateElement,o)}}}else{o=void 0!==m?m.get(n)??null:null,f.changeIndexSet.has(n)&&Ma(o,t,oa(i.wildcardCount)),null===o&&_(`Content not found for ListIndex: ${n.index} at path "${i.path}"`);const e=!o.mounted;if(v?N=Na(o,N.parentNode,N,$+n.index):null!==k&&k.has(n)&&Aa(N,o.firstNode)||N.nextSibling===o.firstNode||o.mountAfter(N),e){const e=o,s=Zn(I,n);S.createLoopContext(s,n=>{Ur(e,n,t)})}}v||(N=o.lastNode||N),void 0===m&&(m=new WeakMap,ma.set(e.node,m)),m.set(n,o)}ga.set(e.node,N),null!==A&&(e.node.parentNode.insertBefore(A,e.node.nextSibling),Cn(A,null))},if:Ca,else:Ca,elseif:Ca,radio:function(e,t,n){const o=e.node,s=ai(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=ai(o.value,e.inFilters),i=Array.isArray(n)?n:li;o.checked=i.includes(s)}},Za=new WeakMap,el=new WeakMap,tl=new WeakMap;function nl(){}function ol(e){const t=ii;if(null!==t){const n=e.replaceNode,o=e.propSegments[0];if(t.isComplete(n,o))return Ga;if(t.isDeclared(n,o))return nl}return Ha}function sl(e,t){il(e,t,Xa(t.state,e))}function il(e,t,n){const o=ai(n,e.outFilters);if(!0===el.get(e))return void t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement});let s=Za.get(e);if(void 0===s){if(Za.has(e))return s=ol(e),s===Ga&&Za.set(e,s),void s(e,t,o);if(s=Ja[e.bindingType],void 0===s){const t=e.propSegments[0];if(s=Ya[t],Za.set(e,s),void 0===s){we(e.replaceNode)?(s=ol(e),s===Ga&&Za.set(e,s)):(s=Ha,Za.set(e,s))}}if(s===Ha){if("SELECT"===e.node.tagName){const n=e.propSegments[0];if("value"===n||"selectedIndex"===n)return t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement}),void el.set(e,!0)}}s(e,t,o)}else s(e,t,o)}function rl(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=zn(e);if(t.updatedAbsAddressSetByStateElement.has(t.stateElement)){t.updatedAbsAddressSetByStateElement.get(t.stateElement).add(n)}else t.updatedAbsAddressSetByStateElement.set(t.stateElement,new Set([n]))}const n=si(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==tl.get(e)){const t=we(e.replaceNode);if(t&&(void 0===ve(e.replaceNode)?.get(t)||function(e){return"waiting-definition"===Ds.get(e)?.phase}(e)))return void function(e,t){if(Ka.has(e))return;Ka.add(e);const n=()=>{Ka.delete(e);const t=si(e);(null===t||t.shouldApplyState(e))&&ll([e])},o=n=>{Ka.delete(e),Qa(t,n)},s=si(e);if(null!==s){const i=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{Ka.delete(e),i()})||(Ka.delete(e),i()))}const i=ve(e.replaceNode);if(null===i)return Ka.delete(e),void Qa(t,new Error("CustomElementRegistry is unavailable."));Is(i).wait(t,()=>{e.replaceNode.isConnected?n():Ka.delete(e)},o)}(e,t);tl.set(e,!0)}if(!0===t.sameRootVerified)return void sl(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=_n(o),null===o&&_("Root node for fragment not found for binding.")),o!==t.rootNode){const n=kl(o);null===n&&_("No state tree found on this root for binding."),n.createState("readonly",s=>{const i={rootNode:o,stateElement:n,state:s,appliedBindingSet:t.appliedBindingSet,newListValueByAbsAddress:t.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:t.updatedAbsAddressSetByStateElement,deferredSelectBindings:t.deferredSelectBindings};sl(e,i)})}else sl(e,t)}function al(e,t,n,o){if(null!==n&&!0===n.hasErrorCallback){const s={path:e.statePathName,bindingType:e.bindingType,node:e.node},i=o.get(n);void 0===i?o.set(n,[{error:t,info:s}]):i.push({error:t,info:s})}else console.error(`[@wcstack/state] binding "${e.bindingType}: ${e.statePathName}" failed to apply; the rest of this batch continues.`,{node:e.node,error:t});null!==N&&N({type:"state:binding-apply-error",path:e.statePathName,bindingType:e.bindingType,error:t})}function ll(t,n,o){let s=0;const i=new Set,r=new Map,a=new Map,l=[],d=new Map;for(;s<t.length;){let o=t[s];if(!1===o.replaceNode.isConnected){e.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${o.bindingType} ${o.statePathName} on ${o.node.nodeName}`,o),s++;continue}let c=o.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=_n(c),null===c&&_("Root node for fragment not found for binding."));const u=kl(c);null===u&&_("No state tree found on this root for binding."),u.createState("readonly",e=>{const f={rootNode:c,stateElement:u,state:e,appliedBindingSet:i,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:a,deferredSelectBindings:l,sameRootVerified:!0,propagationContextByBinding:n};for(;;){try{rl(o,f)}catch(e){al(o,e,u,d)}s++;const e=t[s];if(!e)break;if(e.replaceNode.getRootNode()!==f.rootNode)break;o=e}})}for(const{binding:e,value:t,stateElement:o}of l)try{Ha(e,{propagationContextByBinding:n},t)}catch(t){al(e,t,o??null,d)}for(const[e,t]of r.entries())tn(e,t),un(e,t);if(!1!==o?.updatedCallback)for(const[e,t]of a.entries())e.createState("writable",e=>{e[vn](Array.from(t))});for(const[e,t]of d.entries())e.createState("writable",e=>{for(const{error:n,info:o}of t)try{e[Nn](n,o)}catch(e){console.error(`[@wcstack/state] $errorCallback threw while handling the failure of binding "${o.bindingType}: ${o.path}".`,{error:e,original:n,node:o.node})}})}function dl(e,t,n,o,s){for(const i of e)i.cancel?.(),i.cancel=n.deferUntilDefined(i.node,i.tagName,()=>{const r=Ve(i);if(o&&(e.splice(e.indexOf(i),1),o.push(...r),s.push(...r.filter(e=>e.statePathName in E))),0===r.length)return;Ke(i.node,t);ll(n.initialize(r,o&&{registerPathInfo:!1,applyOnReconnect:!1}))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${i.tagName}>.`,e)})}function cl(e,t,n){const[o,s,i]=je(e,n),r=oi(e);for(const e of o)Ke(e,t);ll(r.initialize(s)),dl(i,t,r)}const ul=new WeakMap;async function fl(t){const n=t.querySelectorAll(e.tagNames.state),o=[],s=ve(t);null===s&&_(`CustomElementRegistry is unavailable for <${e.tagNames.state}>.`),await s.whenDefined(e.tagNames.state);for(const e of n){if(Re(e))continue;const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function pl(t){if(t===document)await fl(document),z(document),td(document,document),cl(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await ge(n.host),await fl(n),z(n),td(n,n),cl(n,null)}}const hl={watch:"temporal",scan:"temporal",streams:"temporal",scopes:"scopes",dcc:"scopes",recursion:"recursion",ssr:"ssr",devtools:"devtools"};function gl(e,t){return`[wcs/feature-not-installed] ${t} needs the "${e}" feature: install it with installFeatures([...]) from "@wcstack/state/features/${hl[e]??e}" before the state is defined.`}let ml=null;function bl(e){ml=e}function wl(e){return null===ml&&_(gl("ssr",e)),ml}const yl=new WeakMap,vl=new WeakMap,Nl=new Set,xl=[];function Il(e){xl.includes(e)||xl.push(e)}function Sl(){return Nl}function kl(e){return yl.get(e)??null}function Al(e){return vl.get(e)??Promise.resolve()}function $l(e,t){const n=Promise.reject(t);n.catch(()=>{}),vl.set(e,n)}const Tl=new WeakSet;function Ml(e,t){const n=yl.get(e);if(void 0!==n){if(n===t)return;_("A state tree is already registered on this root.")}yl.set(e,t)}function Pl(e,t){vl.set(e,t),t.then(()=>El(e),()=>{})}function El(e){Tl.add(e)}function Cl(t,n){const s=yl.get(t);if(null===n){if(void 0===s)return;yl.delete(t),Nl.delete(s),null!==N&&N({type:"state:element-unregistered",rootNode:t,element:s}),e.debug&&console.debug("State element unregistered")}else{if(s===n)return;if(void 0===s){const e=!o()&&n.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const n=new Promise((n,o)=>{queueMicrotask(async()=>{try{if(e){await wl('the "enable-ssr" attribute').hydrate(t)||await pl(t)}else await pl(t);El(t),ad(),n()}catch(e){o(e)}})});vl.set(t,n)}else if("ShadowRoot"===t.constructor.name){const e=new Promise((e,n)=>{queueMicrotask(async()=>{try{await pl(t),El(t),ad(),e()}catch(e){n(e)}})});vl.set(t,e)}}void 0!==s&&_('A state tree is already registered on this root — one <wcs-state> per root in v2. This second element stays unregistered: it keeps the state it loaded and its declarations stay live, but nothing binds to it and disconnecting it runs no cleanup — remove it. Mount additional states onto the tree instead: <wcs-state mount="...">.'),yl.set(t,n),Nl.add(n);for(let e=0;e<xl.length;e++)xl[e](t,n);null!==N&&N({type:"state:element-registered",rootNode:t,element:n}),e.debug&&console.debug("State element registered",n)}}const _l=new Map;function Wl(e,t,n){if(null===n)_l.delete(e);else{_l.set(e,n);const o=kl(t);null===o&&_("No state tree found on this root for fragment info.");const s=n.parseBindTextResult;o.setPathInfo(s.statePathName,s.bindingType);for(const e of n.nodeInfos)for(const t of e.parseBindTextResults)o.setPathInfo(t.statePathName,t.bindingType)}}function Rl(e){return _l.get(e)||null}function Ll(){_l.clear()}function Ol(t){if(t.nodeType===Node.ELEMENT_NODE){const n=t,o=re(n.getAttribute(e.bindAttributeName)||"");if(n.localName===e.tagNames.state){if(n.hasAttribute("mount"))return o.filter(e=>e.propSegments[0]!==y);const t=o.find(e=>e.propSegments[0]===y);if(void 0!==t){const n=`on a volume element — a <${e.tagNames.state}> with a "mount" attribute`;_(1===t.propSegments.length?`[wcs/mount-path-invalid] "${t.propName}" is the reserved namespace for volume injection, so it cannot be bound as an element property. Write one key at a time ("${y}.<key>: <path>") ${n}.`:`[wcs/mount-path-invalid] "${t.propName}: ${t.statePathName}" is a volume injection declaration, and it can only be written ${n}. Add mount="<path>", or bind an element property instead.`)}}return o}if(t.nodeType===Node.COMMENT_NODE){const e=ce(t);null===e&&_("Comment node binding text not found.");const n=Rl(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=ue(e),s=null):s=e,[{...o,uuid:s}]}return[]}let Bl;function Dl(){return Bl??={filterName:"not",args:[]}}const Fl=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function jl(e,t){const n=t+l+x,o=Y(e,"|");let s,i;if(-1!==o?(s=e.slice(0,o).trim(),i=e.slice(o)):(s=e.trim(),i=""),"."===s)s=n;else{if(!s.startsWith("."))return e;s=n+l+s.slice(1)}return i.length>0?s+i:s}function zl(e,t){const n=Fl.exec(e);if(null===n)return e;const o=n[1],s=n[2],i=n[3];return o+jl(s,t)+i}function ql(e,t){const n=J(e,";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=Y(n,":");if(-1===s)return e;const i=n.slice(0,s).trim(),r=n.slice(s+1).trim(),a=jl(r,t);return a!==r?(o=!0,`${i}: ${a}`):e});return o?s.join(";"):e}function Vl(e,t){return ql(e,t)}function Hl(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const t=e;t.data=zl(t.data,n);continue}const t=e;if(t instanceof HTMLTemplateElement)continue;const i=t.getAttribute(o);if(null!==i){const e=ql(i,n);e!==i&&t.setAttribute(o,e)}}}function Ul(e){let t=e;const n=[];for(;null!==t.parentNode;){const e=Array.from(t.parentNode.childNodes).indexOf(t);n.unshift(e),t=t.parentNode}return n}const Gl=new WeakMap;function Xl(e){return Gl.get(e)??null}function Kl(e){const t=[],n=Be(e);for(const e of n){const n=Ol(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");Gl.set(t,e.data),e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:Ul(o),parseBindTextResults:n})}return t}function Ql(e){const t=Array.from(e.childNodes);for(const n of t)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&e.removeChild(n)}}const Yl=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),Jl=Dl();function Zl(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Jl],bindingType:e}}function ed(e,t,n,o,s,i=!0){Ql(t),"string"==typeof o&&Hl(t,o),td(e,t,o,s);const r={fragment:t,parseBindTextResult:void 0!==s&&i?s(n,o):n,nodeInfos:Kl(t)};return void 0!==s&&function(e,t,n){for(const o of e)for(let e=0;e<o.parseBindTextResults.length;e++){const s=o.parseBindTextResults[e];null==s.uuid&&(o.parseBindTextResults[e]=t(s,n))}}(r.nodeInfos,s,o),r}function td(t,n,o,s){const i=e.commentElsePrefix,r=Le(n),a=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const n=t;if(r.length>0&&-1!==r.indexOf(n))return NodeFilter.FILTER_REJECT;if("template"===n.tagName.toLowerCase()){if((n.getAttribute(e.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let l=null;const d=[],c=[];for(;a.nextNode();){const e=a.currentNode;c.push(e)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=Vl(r,o));let a=re(r)[0];const c=Yl.get(a.bindingType);if(void 0===c)continue;const u=a.bindingType,f=n.content,p=Ye();let h=null;const g="for"===u?a.statePathName:o;if("else"===u){null===l&&_("'else' binding found without preceding 'if' or 'elseif' binding."),a=Zl("else",l.parseBindTextResult),h=ed(t,f,a,g,s,!1),Wl(p,t,h);const e=d.at(-1),o=document.createComment(`@@${c}:${p}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:Ul(o),parseBindTextResults:Ol(o)})):n.replaceWith(o)}else if("elseif"===u){null===l&&_("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=ed(t,f,a,g,s),Wl(p,t,h);const e=document.createComment(`@@${c}:${p}`),o=Ye(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Zl("else",l.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:Ul(e),parseBindTextResults:Ol(e)}),Wl(o,t,r);const u=d.at(-1);d.push(r);const m=document.createComment(`@@${i}:${o}`);void 0!==u?(n.remove(),u.fragment.appendChild(m),u.nodeInfos.push({nodePath:Ul(m),parseBindTextResults:Ol(m)})):n.replaceWith(m)}else{h=ed(t,f,a,g,s),Wl(p,t,h);const e=document.createComment(`@@${c}:${p}`);n.replaceWith(e)}"if"===u?(d.length=0,l=h):"elseif"===u?l=h:"else"===u&&(l=null,d.length=0)}}const nd=()=>`[${e.bindAttributeName}]`;function od(t){if(Vs(t))return!0;if(!sd(t))return!1;if(t.hasAttribute(e.bindAttributeName))return!1;const n=t.querySelector(nd());return null!==n&&Vs(n)}function sd(e){return 1===e.nodeType}function id(t){if(od(t))return;z(t),td(t.getRootNode(),t);const n=t.hasAttribute(e.bindAttributeName),o=t.parentNode,s=null!==o&&(1===o.nodeType||9===o.nodeType||11===o.nodeType);cl(n&&s?o:t,null)}const rd=[];function ad(){const e=rd.splice(0,rd.length);for(const t of e)id(t);D()}const ld={protocol:"wcs-binder",version:1,bind:function(e){var t;sd(e)&&!od(e)&&(t=e.getRootNode(),Tl.has(t)?id(e):rd.push(e))}};function dd(){const e=globalThis;void 0===e[L]&&(e[L]=ld)}export{ai as $,Ml as A,Pl as B,z as C,td as D,cl as E,kl as F,We as G,ri as H,we as I,ge as J,re as K,Il as L,un as M,Rr as N,cn as O,Ra as P,Wa as Q,Oa as R,Rl as S,Ba as T,Xl as U,Pe as V,Ll as W,fl as X,je as Y,dl as Z,zn as _,Da as a,br as a$,qt as a0,tn as a1,Sa as a2,ii as a3,Le as a4,Dl as a5,Ql as a6,Hl as a7,Kl as a8,Wl as a9,vn as aA,yn as aB,wn as aC,bn as aD,$i as aE,Li as aF,pn as aG,Xn as aH,fn as aI,bo as aJ,wl as aK,Cl as aL,$l as aM,gl as aN,vo as aO,xi as aP,rt as aQ,Ii as aR,Er as aS,Dt as aT,zt as aU,Gi as aV,_r as aW,Rn as aX,xt as aY,kt as aZ,ur as a_,la as aa,jr as ab,fi as ac,gi as ad,aa as ae,sa as af,yi as ag,nt as ah,xa as ai,Ia as aj,Yr as ak,mi as al,Re as am,Be as an,ce as ao,ze as ap,ni as aq,Ee as ar,qe as as,bl as at,Si as au,dr as av,fr as aw,lr as ax,ar as ay,Nn as az,pl as b,mr as b0,yr as b1,st as b2,Ut as b3,Gt as b4,jt as b5,hr as b6,Wr as b7,Go as b8,Vo as b9,Lt as ba,on as bb,at as bc,gt as bd,Mt as be,Pt as bf,Jo as bg,bt as bh,en as bi,sn as bj,Me as bk,ue as bl,cr as bm,Sl as bn,Ri as bo,Di as c,mo as d,_i as e,Wi as f,Al as g,mn as h,vt as i,Zn as j,Bt as k,Mn as l,Ln as m,ht as n,On as o,Pn as p,ve as q,dd as r,Fa as s,Ge as t,Ne as u,Xe as v,gn as w,ll as x,oi as y,Ke as z};
1
+ import{c as e,r as t,f as n,i as o,a as s}from"./filterRegistry.js";import{P as i,Q as r,T as a,D as l,g as d,U as c,X as u,Y as f,Z as p,_ as h,$ as g,a0 as m,a1 as b,a2 as w,V as y,a3 as v,d as N,W as x,n as I,a4 as S,a5 as k,w as A,a6 as $,a7 as M,a8 as P,a9 as T,I as E,G as C}from"./pathDiagnostics.js";import{r as _,L as W,d as R}from"./errorGuidance.js";const L=Symbol.for("wcstack.binder");const O=Symbol.for("wcstack.binder.pending"),B=Symbol.for("wcstack.binder.taken");function D(){const e=function(){const e=globalThis[L];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;const t=function(){const e=globalThis;let t=e[O];return void 0===t&&(t=[],e[O]=t),t}();if(0===t.length)return;const n=t.splice(0,t.length),o=function(){const e=globalThis;let t=e[B];return void 0===t&&(t=new WeakSet,e[B]=t),t}();for(const t of n)o.add(t),e.bind(t)}const F=/\{\{\s*(.+?)\s*\}\}/g,j=new Set(["SCRIPT","STYLE"]);function z(t,n){if(!e.enableMustache)return;!function(e,t){const n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const e of o)e.parentElement&&j.has(e.parentElement.tagName)||q(e,t)}(t,n);const o=Array.from(t.querySelectorAll("template"));for(const e of o)if(e.namespaceURI===i){const t=document.createElement("template"),n=Array.from(e.childNodes);for(let e=0;e<n.length;e++){const o=n[e];t.content.appendChild(o)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),z(t.content)}else z(e.content)}function q(e,t){const n=e.data;if(F.lastIndex=0,!F.test(n)||t?.(e))return;F.lastIndex=0;const o=document.createDocumentFragment();let s,i=0;for(;null!==(s=F.exec(n));){s.index>i&&o.appendChild(document.createTextNode(n.slice(i,s.index)));const e=s[1];o.appendChild(document.createComment(`@@: ${e}`)),i=s.index+s[0].length}i<n.length&&o.appendChild(document.createTextNode(n.slice(i))),e.parentNode.replaceChild(o,e)}const V=new Set(["if","elseif","else","for"]);function H(e,t,n){const o=-1===t?e.length:t;let s=0;for(;s<o&&/\s/.test(e[s]);)s++;const i=-1===n?0:n;let r=e.length;for(;r>i&&/\s/.test(e[r-1]);)r--;return e.slice(s,r)}const U=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function G(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:U.test(e)?Number(e):e)}function X(e){const t=[],n=[];let o="",s=null,i=!1,r=-1,a=-1;const l=()=>{const e=H(o,r,a);t.push(e),n.push(G(e,i)),o="",i=!1,r=-1,a=-1};for(let t=0;t<e.length;t++){const n=e[t];s?n===s?s=null:(-1===r&&(r=o.length),o+=n,a=o.length):'"'===n||"'"===n?(s=n,i=!0):","===n?l():o+=n}null!==s&&_(`[wcs/binding-syntax] unterminated ${s} quote in the filter arguments "(${e})". Close the quote.${W}`);const d=H(o,r,a);return(d||i)&&(t.push(d),n.push(G(d,i))),{args:t,literals:n}}const K=e=>e.trim(),Q=e=>"'"===e||'"'===e;function Y(e,t){let n=null;for(let o=0;o<e.length;o++){const s=e[o];if(null!==n)s===n&&(n=null);else if(Q(s))n=s;else if(s===t)return o}return-1}function J(e,t){const n=[];let o=null,s=0;for(let i=0;i<e.length;i++){const r=e[i];null!==o?r===o&&(o=null):Q(r)?o=r:r===t&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}function Z(e,t,n){const o=n??e.join("|");return e.map(e=>{const n=Y(e,"(");let s=function(e,t){let n=null,o=-1;for(let s=0;s<e.length;s++){const i=e[s];null!==n?i===n&&(n=null):Q(i)?n=i:i===t&&(o=s)}return o}(e,")");if(-1===s&&(s=e.lastIndexOf(")")),-1!==n&&-1===s&&_(`[wcs/binding-syntax] Invalid filter format: missing closing parenthesis in "${e}".${W}`),-1!==s&&-1===n&&_(`[wcs/binding-syntax] Invalid filter format: missing opening parenthesis in "${e}".${W}`),-1!==s&&s<n&&_(`[wcs/binding-syntax] Invalid filter format: ")" comes before "(" in "${e}".${W}`),-1!==s&&e.slice(s+1).trim().length>0){const t=e.slice(s+1).trim();_(`[wcs/binding-syntax] "${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,s+1)}|${t}").${W}`)}const i=(-1===n?e:e.substring(0,n)).trim();if(0===i.length&&_(`[wcs/binding-syntax] an empty filter in "${o}" — remove the extra "|" or name the filter.${W}`),i.includes(r)){const[e,n]=i.split(r);_("input"===t?`[wcs/binding-syntax] "${i}" is not a filter name: a modifier list "${r}${n}" comes before the input filters, not inside one — write "<property>${r}${n}|${e}".${W}`:`[wcs/binding-syntax] "${i}" is not a filter name: "${r}" cannot appear in one. Modifiers belong on the left side of the binding, before the ":" — write "${e}" here.${W}`)}if(-1===n)return{filterName:i,args:[],literals:[]};return{filterName:i,...X(e.substring(n+1,s))}})}const ee=new Map;function te(e){const t=Y(e,a);let n="",o=[],s="",i=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ee.has(s)?i=ee.get(s):(o=J(s,a).map(K),i=Z(o,"input",e),ee.set(s,i))):n=e.trim();const d=n.split(r).map(K);d.length>2&&_(`[wcs/binding-syntax] "${n}": a binding takes one modifier list after a single "${r}" — write "${d[0]}${r}${d.slice(1).join(",")}".${W}`);const[c,u]=d,f=c.split(l).map(K);f.length>1&&""===f[0]||0!==c.length&&!f.some(e=>0===e.length)||_(`[wcs/binding-syntax] "${e}": the left side of a binding must name a property — write "<property>: <path>" (modifiers and input filters come after the name).${W}`);return{propName:c,propSegments:f,propModifiers:u?u.split(",").map(K):[],inFilters:i}}const ne=new Map;function oe(e){const t=Y(e,a);let n="",o=[],s="",i=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ne.has(s)?i=ne.get(s):(o=J(s,a).map(K),i=Z(o,"output",e),ne.set(s,i))):n=e.trim(),-1!==n.indexOf("@")&&_(`"${n}": 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.`);const r=n,c=r.startsWith(l),u=c?r.slice(l.length):r;(u.length>0&&u.split(l).some(e=>0===e.length)||!c&&0===u.length)&&_(`[wcs/binding-syntax] "${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).${W}`);return{statePathName:r,statePathInfo:d(r),outFilters:i}}const se=new Set([c,"if","elseif","for",u]),ie=new Set([g,m,b,w,f,y]);function re(e){const[...t]=function(e){return J(e,v)}(e).map(K).filter(e=>e.length>0),n=t.map(e=>{const t=Y(e,h);-1===t&&_(`[wcs/binding-syntax] Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.${W}`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),s=n.split(r)[0].split(a)[0].trim();if(s!==n&&se.has(s)&&_(`[wcs/binding-syntax] "${e}": "${s}" takes no modifiers or filters on its left side — write "${s}:".${W}`),n===c){o.length>0&&_(`[wcs/binding-syntax] "${e}": "else" takes no value — write "else:".${W}`);const t=d("#else");return{propName:c,propSegments:[c],propModifiers:[],statePathName:"#else",statePathInfo:t,inFilters:[],outFilters:[],bindingType:"else"}}if(n===u){0===o.length&&_(`[wcs/binding-syntax] Invalid spread binding "${e}": spread target path is required.${W}`);const t=oe(o);return t.outFilters.length>0&&_(`[wcs/binding-syntax] Invalid spread binding "${e}": filters are not allowed on spread targets.${W}`),{propName:u,propSegments:[u],propModifiers:[],inFilters:[],...t,bindingType:"spread"}}if("if"===n||"elseif"===n||"for"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...oe(o),bindingType:n}}if("radio"===s||"checkbox"===s){const e=oe(o);return{...te(n),...e,bindingType:s}}{const e=oe(o),t=te(n);if(""===t.propSegments[0]&&t.propSegments.length>1){const o=t.propSegments.slice(1);return(o.includes("")||ie.has(o[0]))&&_(`[wcs/binding-syntax] "${n}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (${[...ie].join(", ")}).${W}`),{...t,propName:o.join(l),propSegments:o,...e,bindingType:"prop"}}return t.propSegments[0]===f||t.propSegments[0].startsWith(p)?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>V.has(e.bindingType))&&_(`[wcs/template-syntax] Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${W}`)}return n}const ae=new WeakMap,le=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),de=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function ce(t){const n=ae.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=de.exec(o);if(null===s)return null;const i=s[1]||e.commentTextPrefix;return le.has(i)?(ae.set(t,s[2]),s[2]):null}function ue(e){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...oe(e),bindingType:"text"}}const fe=new WeakMap,pe=new WeakSet;let he=0;async function ge(e){const t=function(e){let t,n=fe.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++he,promise:o,resolve:t},fe.set(e,n),pe.has(e)&&n.resolve(),n}(e);await t.promise}function me(e){const t=fe.get(e);void 0===t?pe.add(e):t.resolve()}const be=new WeakMap;function we(e){const t=be.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,o=t.tagName.toLowerCase();if(o.includes("-"))return n=o;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{be.set(e,n)}}function ye(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined?null:t}function ve(e=null){if(null!=e){const{customElementRegistry:t,customElements:n}=e;if(null===t)return null;if(void 0!==t)return ye(t);if(void 0!==n)return ye(n)}return ye(globalThis.customElements)}function Ne(e,t){e.upgrade?.(t)}function xe(e){try{if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const t=e,n=t.addEventListener,o=t.removeEventListener,s=t.constructor?.wcBindable;if("function"!=typeof n||"function"!=typeof o)return null;if("wc-bindable"!==s?.protocol)return null;if(!Number.isInteger(s.version)||s.version<1)return null;const i=Ae(s.properties,Ie);if(null===i)return null;const r=void 0===s.inputs?new Map:Ae(s.inputs,Se);if(null===r)return null;const a=void 0===s.commands?new Map:Ae(s.commands,ke);return null===a?null:{target:e,liveDeclaration:s,knownProperties:i,declaredInputs:r,declaredCommands:a}}catch{return null}}function Ie(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&("string"==typeof t.event&&0!==t.event.length&&(void 0===t.getter||"function"==typeof t.getter))}function Se(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.attribute||"string"==typeof t.attribute)}function ke(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.async||"boolean"==typeof t.async)}function Ae(e,t){if(!Array.isArray(e))return null;const n=new Map;for(const o of e){if(!t(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function $e(e,t){const n="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:n,statePathInfo:d(n),inFilters:[],outFilters:[],bindingType:"prop"}}function Me(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function Pe(t,n,o={}){const s=o.allowDeferred??!0;if(!n.some(e=>"spread"===e.bindingType))return n;const i=[],r=new WeakSet;for(const e of n){if("spread"!==e.bindingType){i.push(e);continue}t.nodeType!==Node.ELEMENT_NODE&&_("Spread binding requires an element node.");const n=t,o=we(n);null===o&&_(`Spread binding "${e.statePathName}" requires a custom element with wcBindable, but <${n.tagName.toLowerCase()}> is not a custom element.`);const a=ve(n);null===a&&_(`CustomElementRegistry is unavailable for <${o}>.`);if(void 0===a.get(o)){s||_(`Spread binding "${e.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),i.push(e);continue}Ne(a,n);const l=xe(n);null===l&&_(`Spread binding "${e.statePathName}" requires <${o}> to expose a valid wcBindable declaration.`);const d=e.statePathName,c=new Set;for(const e of l.knownProperties.keys()){if(c.has(e))continue;c.add(e);const t=$e(e,d);r.add(t),i.push(t)}for(const e of l.declaredInputs.keys()){if(c.has(e))continue;c.add(e);const t=$e(e,d);r.add(t),i.push(t)}}const a=new Map;for(let e=0;e<i.length;e++){const t=Me(i[e]);null!==t&&a.set(t,e)}const l=[];for(let n=0;n<i.length;n++){const o=Me(i[n]);if(null!==o){if(a.get(o)===n)l.push(i[n]);else if(e.debug&&r.has(i[n])){const e=i[a.get(o)],s=t.nodeType===Node.ELEMENT_NODE?`<${t.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${i[n].propName}" of ${s} overridden by explicit binding (statePath: "${e.statePathName}").`)}}else l.push(i[n])}return l}function Te(e,t){let n=e;for(let e=0;e<t.length;e++){let o=t[e];for(n=n.firstChild;null!==n&&o>0;)n=n.nextSibling,o--;if(null===n)break}return n}function Ee(e,n){if(0===e.length)return e;const o=[];for(let s=0;s<e.length;s++){const i=e[s],r=i.literals??i.args;o.push({filterName:i.filterName,args:i.args,literals:r,filterFn:t(i.filterName,i.args,n,r)})}return o}function Ce(e){return{...e,inFilters:Ee(e.inFilters,"input"),outFilters:Ee(e.outFilters,"output")}}const _e=new WeakMap;function We(e){return _e.get(e)||null}function Re(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Le(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!Re(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function Oe(e,t){for(let n=0;n<t.length;n++){const o=t[n];if(o!==e&&o.contains(e))return!0}return!1}function Be(t){const n=[],o=Le(t),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(e.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==ce(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const e=s.currentNode;o.length>0&&Oe(e,o)||n.push(e)}return n}const De=new WeakSet;function Fe(e,t,n,o){const s=Pe(e,t,{allowDeferred:n.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?we(e):null;return null===n&&_("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t,transform:o}}}De.add(e);const i=function(e,t){const n=[];for(const o of t){const t=Ee(o.inFilters,"input"),s=Ee(o.outFilters,"output");if("text"!==o.bindingType)n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:e});else{const i=e.nodeType===Node.TEXT_NODE?e:document.createTextNode("");n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:i})}}return n}(e,function(e,t){return void 0===t?e:e.map(e=>null!=e.uuid?e:t(e))}(s,o));return function(e,t){_e.set(e,t)}(e,i),me(e),{bindings:i,deferred:null}}function je(e,t){return ze(Be(e),t)}function ze(e,t){const n=[],o=[];for(const s of e){if(De.has(s))continue;const e=Fe(s,Ol(s),{allowDeferred:!0},t);null===e.deferred?n.push(...e.bindings):o.push(e.deferred)}return[e,n,o]}function qe(e){De.add(e)}function Ve(e){const{node:t,parseResults:n,transform:o}=e;!function(e){De.delete(e)}(t);return Fe(t,n,{allowDeferred:!1},o).bindings}const He=new WeakMap;let Ue=null;function Ge(e){Ue=e}function Xe(e){let t=e;for(;t;){const e=He.get(t);if(e)return e;let n=t.parentNode;null===n&&null!==Ue&&t instanceof ShadowRoot&&(n=Ue(t)),t=n}return null}function Ke(e,t){null!==t?He.set(e,t):He.delete(e)}let Qe=0;function Ye(){return`u${(Qe++).toString(36)}`}let Je=0,Ze=0;const et=Symbol("wcs.listIndex.noValue");class tt{uuid=Ye();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;_chainGeneration;_homeParentListIndex;_value;cacheStamp=0;ref;constructor(e,t,n){this.parentListIndex=e,this.position=e?e.position+1:0,this.length=this.position+1,this._homeParentListIndex=n,this._value=et,this._index=t,this._version=Je,this._chainGeneration=Ze}get index(){return this._index}set index(e){this._index=e,this._version=++Je,this.indexes[this.position]=e}get version(){return this._version}get homeParentListIndex(){return this._homeParentListIndex}set homeParentListIndex(e){this._homeParentListIndex=e}get value(){return this._value}set value(e){this._value=e}get dirty(){return null!==this.parentListIndex&&(this.parentListIndex.dirty||this.parentListIndex.version>this._version)}get indexes(){return null===this.parentListIndex?void 0===this._indexes&&(this._indexes=[this._index]):(void 0===this._indexes||this.dirty)&&(this._indexes=[...this.parentListIndex.indexes,this._index],this._version=Je),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0!==this._listIndexes&&this._chainGeneration===Ze||(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)],this._chainGeneration=Ze),this._listIndexes}get varName(){return`$${this.position+1}`}reparent(e){this.parentListIndex=e,this._indexes=void 0,this._listIndexes=void 0,this._version=++Je,Ze++}at(e){return e>=0?this.listIndexes[e]?.deref()||null:this.listIndexes[this.listIndexes.length+e]?.deref()||null}}function nt(e,t,n=e){return new tt(e,t,n)}function ot(e,t){e.reparent(t)}function st(e){return e.homeParentListIndex}function it(e,t){e.homeParentListIndex=t}function rt(e){return e?.cacheStamp}function at(e,t){const n=e,o=n.value,s=o!==et&&!Object.is(o,t);return o!==t&&(lt.get(o)?.delete(n.ref),function(e,t){if("object"!=typeof e||null===e||null===t.parentListIndex)return;let n=lt.get(e);void 0===n?(n=new Set,lt.set(e,n)):n.size>=(dt.get(n)??8)&&(ct(n,t,!0),dt.set(n,2*n.size+8));n.add(t.ref??=new WeakRef(t))}(t,n)),n.value=t,s}const lt=new WeakMap,dt=new WeakMap;function ct(e,t,n=!1){const o=[];return e?.forEach(s=>{const i=s.deref();void 0===i||n&&ft(i)?e.delete(s):i!==t&&o.push(i)}),o}const ut=new WeakSet;function ft(e){for(let t=e;null!==t;t=t.parentListIndex)if(ut.has(t))return!0;return!1}function pt(e){return e.value}function ht(e,t){const n=e.value;return n!==et&&n===t.value}let gt=0;const mt=new WeakSet;function bt(e){mt.add(e)}function wt(e){return mt.has(e)}const yt=new WeakMap;function vt(e){return ut.has(e)}const Nt=new WeakMap;function xt(e,t,n,o){if(!yt.has(e))return!1;let s=!1;for(const t in n)s||=t!==o&&n[t]===e;if(!s){let n=Nt.get(t);void 0===n&&(n=new WeakSet,Nt.set(t,n)),n.add(e)}const i=yt.get(e),r=St.get(e);if(i[0]?.parentListIndex===t&&(!s||r?.[0]!==t||r[1]!==gt))for(const n of _t.get(e)??[])if(n!==t&&n.position===t.position&&Ct(e,n)&&Object(pt(n))[o]===e){i.forEach(e=>ot(e,n)),It.set(e,[t,gt]);break}return s}const It=new WeakMap,St=new WeakMap;function kt(e,t){Nt.get(t)?.delete(e);const n=yt.get(e);if(void 0!==n){St.set(e,[t,gt]);const o=It.get(e);o?.[0]===t&&o[1]===gt&&n.forEach(e=>ot(e,t))}}function At(e,t){return!0===Nt.get(t)?.has(e)}function $t(e,t){return At(e,t)||ft(t)}const Mt=new WeakMap;function Pt(e){Mt.set(e,gt)}function Tt(e){Mt.delete(e)}function Et(e,t,n){const o=Object(pt(t)),s=pt(n);for(const t in s)if(s[t]===e&&o[t]!==e)return!1;return!0}function Ct(e,t){return!$t(e,t)&&Mt.get(t)!==gt}const _t=new WeakMap,Wt=new WeakMap;const Rt=new WeakSet;function Lt(e,t){const n=(o=e,ct(lt.get(o.value),o));var o;if(0===n.length)return n;const s=new Set(yt.get(t()));return n.filter(t=>t.position===e.position&&!s.has(t)&&!ft(t))}function Ot(e,t,n){const o=st(t),s=t.parentListIndex;return null!==o&&o!==s&&!$t(e,o)&&Et(e,o,s)?o:function(e,t,n,o){return null!==t&&null!==o&&o!==n&&!!ut.has(t)&&!(!Ct(e,o)||o.position!==t.position)&&!At(e,t)&&ht(o,t)}(e,o,s,n)||function(e,t,n){return t!==n&&null!==t&&null!==n&&t.position===n.position&&$t(e,t)&&Ct(e,n)}(e,s,n)?n:null}function Bt(e){const t=yt.get(e);return void 0===t?null:t}function Dt(e,t){const n=yt.get(e);if(void 0===n)return null;const o=n[0];if(void 0!==o&&!wt(e)){const s=null!==t&&o.parentListIndex!==t&&Mt.get(t)!==gt,i=Ot(e,o,t);if(null!==i&&Rt.has(e)){Rt.delete(e);const t=[...e];bt(t),yt.set(t,n),Gt(e,t);const o=n.map((t,n)=>{const o=nt(i,n);return at(o,e[n]),o});return yt.set(e,o),o}if(null!==i)for(const e of n)ot(e,i);else if(s){!function(e,t){let n=_t.get(e);void 0===n?(n=new Set,_t.set(e,n)):n.size>=(Wt.get(e)??8)&&(n.forEach(t=>{$t(e,t)&&n.delete(t)}),Wt.set(e,2*n.size+8));for(const e of t)n.add(e)}(e,[o.parentListIndex,t]);const s=o.parentListIndex;if(null!==s&&s.position===t.position&&!Et(e,s,t)&&Et(e,t,s))for(const e of n)ot(e,t)}}return n}const Ft=new WeakSet;function jt(e){return Ft.has(e)}function zt(e){Ft.delete(e)}function qt(e,t,n=!1){null!==t?(n?Ft.add(t):zt(t),yt.set(e,t)):yt.delete(e)}const Vt=new WeakMap;function Ht(e){let t=Vt.get(e);return void 0===t&&(t={value:e},Vt.set(e,t)),t}function Ut(e){return Vt.has(e)}function Gt(e,t){const n=Vt.get(e);void 0!==n&&(n.value=t,Vt.delete(e))}const Xt=new WeakMap,Kt=new WeakMap,Qt=new Set,Yt=new WeakMap,Jt=new WeakMap;function Zt(e){const t=e.absolutePathInfo.stateElement;let n=Kt.get(t);return void 0===n&&(n=new WeakMap,Kt.set(t,n)),n}function en(e){return Xt.get(e)??[]}function tn(e,t){const n=Xt.get(e);Xt.set(e,t),Jt.delete(e);const o=Zt(e);n!==t&&void 0!==n&&o.get(n).delete(e);const s=o.get(t);void 0===s?o.set(t,new Set([e])):s.has(e)||(s.size>=(Yt.get(s)??8)&&(s.forEach(e=>{nn(e.listIndex)&&s.delete(e)}),Yt.set(s,Math.max(8,2*s.size))),s.add(e))}function nn(e){for(let t=e;null!==t;t=t.parentListIndex)if(vt(t))return!0;return!1}function on(e,t){const n=Zt(e).get(t);return void 0===n?Qt:(n.forEach(e=>{nn(e.listIndex)&&n.delete(e)}),n)}function sn(e,t){return!Jt.has(e)&&(Jt.set(e,t),!0)}function rn(e){return Xt.has(e)}const an=new WeakMap;let ln=null,dn=0;function cn(e){return an.get(e)??[]}function un(e,t){null===ln?an.set(e,t):ln.set(e,t)}function fn(){dn++,null===ln&&(ln=new Map)}function pn(){if(0!==dn&&(dn--,!(dn>0||null===ln))){for(const[e,t]of ln)an.set(e,t);ln=null}}function hn(e){return(ln?.has(e)??!1)||an.has(e)}const gn=Symbol("$$setLoopContext"),mn=Symbol("$$getByAddress"),bn=Symbol("$$hasByAddress"),wn=Symbol("$$connectedCallback"),yn=Symbol("$$disconnectedCallback"),vn=Symbol("$$updatedCallback"),Nn=Symbol("$$errorCallback"),xn=new WeakMap,In=new WeakMap;class Sn{absolutePathInfo;listIndex;constructor(e,t){this.absolutePathInfo=e,this.listIndex=t}}function kn(e,t){if(null===t){let t=In.get(e);return void 0!==t||(t=new Sn(e,null),In.set(e,t)),t}{let n=xn.get(t);void 0===n&&(n=new WeakMap,xn.set(t,n));let o=n.get(e);return void 0!==o||(o=new Sn(e,t),n.set(e,o)),o}}const An=new WeakMap;function $n(e,t){let n=An.get(e);void 0===n&&(n=new Map,An.set(e,n));let o=n.get(t);return void 0===o&&(o=Object.freeze(new Mn(e,t)),n.set(t,o)),o}class Mn{pathInfo;stateElement;constructor(e,t){this.pathInfo=t,this.stateElement=e}}function Pn(e,t){return kn($n(e,t.pathInfo),t.listIndex)}function Tn(e,t,n){return kn($n(e,t),n)}const En=new WeakMap;function Cn(e,t){null===t?En.delete(e):En.set(e,t)}function _n(e){return En.get(e)||null}const Wn=new Map;function Rn(e,t){let n,o;if(0===e.wildcardCount||0===t.wildcardCount)return 0;if(1===e.wildcardCount&&t.wildcardCount>0&&t.wildcardPathSet.has(e.path))return 1;e.id<t.id?(n=e,o=t):(n=t,o=e);const s=`${n.path}\t${o.path}`;let i=Wn.get(s);if(void 0!==i)return i;return i=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Wn.set(s,i),i}function Ln(e,t,n){return t<0||t>=n?null:e.at(t-n)}function On(e,t){const n=e.indexes??[];return n.length===t?n:n.slice(n.length-t)}const Bn=new WeakMap;function Dn(e){const t=Xe(e.node);if(null===t)return null;let n=Bn.get(t);if(void 0===n)n=new WeakMap,Bn.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=Rn(t.pathInfo,e.statePathInfo);return n>0&&(o=Ln(t.listIndex,n-1,t.pathInfo.wildcardCount)),o}finally{n.set(e,o)}}const Fn=new WeakMap;function jn(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=_n(n);null===t?_(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function zn(e,t){let n=null;if(n=Fn.get(e)||null,null!==n)return n;const o=jn(e,t),s=Dn(e),i=kl(o);return null===i&&_("No state tree found on this root for binding."),n=Tn(i,e.statePathInfo,s),Fn.set(e,n),n}function qn(e){Fn.delete(e)}const Vn=new WeakMap;function Hn(e,t){const n=Vn.get(e);void 0===n?Vn.set(e,t):n instanceof Set?n.add(t):n!==t&&Vn.set(e,new Set([n,t])),null!==N&&N({type:"state:binding-added",absoluteAddress:e,binding:t})}function Un(e,t){const n=Vn.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&Vn.delete(e),null!==N&&N({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const Gn=new WeakMap;function Xn(e){const t=Vn.get(e);return void 0!==t?t:null!==e.listIndex?Gn.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const Kn=new WeakMap,Qn=new WeakMap;class Yn{pathInfo;listIndex;_parentAddress;_rowAddress;constructor(e,t){this.pathInfo=e,this.listIndex=t,this._rowAddress=null!==t&&e.lastSegment===x}get parentAddress(){const e=this._parentAddress;if(void 0!==e&&(!this._rowAddress||e.listIndex===this.listIndex.parentListIndex))return e;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let n=null;n=this.pathInfo.segments[this.pathInfo.segments.length-1]===x?this.listIndex?.parentListIndex??null:this.listIndex;const o=Zn(t,n);return void 0!==e&&!Jn(o,this.listIndex)&&Jn(e,this.listIndex)?e:this._parentAddress=o}}function Jn(e,t){const n=e.pathInfo;let o=pt(e.listIndex);for(const e of n.segments.slice(n.wildcardPositions[n.wildcardCount-1]+1))o=Object(o)[e];return Bt(o)?.[t.index]===t}function Zn(e,t){if(null===t){let t=Qn.get(e);return void 0!==t||(t=new Yn(e,null),Qn.set(e,t)),t}{let n=Kn.get(t);void 0===n&&(n=new WeakMap,Kn.set(t,n));let o=n.get(e);return void 0!==o||(o=new Yn(e,t),n.set(e,o)),o}}const eo=new WeakMap;function to(e){let t=null;if(t=eo.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=Dn(e);null===n&&_(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=Zn(e.statePathInfo,n)}else t=Zn(e.statePathInfo,null);return eo.set(e,t),t}function no(e){eo.delete(e)}function oo(){const e=new Map,t=new Map;return{add(n,o){let s=e.get(n);return void 0===s&&(s=new WeakSet,e.set(n,s)),!s.has(o)&&(s.add(o),t.set(n,(t.get(n)??0)+1),!0)},remove(n,o){const s=e.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const i=(t.get(n)??1)-1;return i<=0?(e.delete(n),t.delete(n),!0):(t.set(n,i),!1)},has:(t,n)=>e.get(t)?.has(n)??!1,countOf:e=>t.get(e)??0,get keyCount(){return t.size},clear(){e.clear(),t.clear()}}}const so=new Map,io=oo();function ro(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function ao(e){let t="input";for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}function lo(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const o=ao(e),s=ro(e,o);let i=so.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==o.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const s=o.checked;let i=o.value;for(const e of n)i=e.filterFn(i);const r=kl(o.getRootNode());null===r&&_("No state tree found on this root for two-way binding.");const a=Xe(o);r.createState("writable",e=>{e[gn](a,()=>{let n=e[t];if(Array.isArray(n))if(s)-1===n.indexOf(i)&&(e[t]=n.concat(i));else{const o=n.indexOf(i);-1!==o&&(e[t]=n.toSpliced(o,1))}else e[t]=s?[i]:[]})})},so.set(s,i)),e.node.addEventListener(o,i),io.add(s,e),!0}var t,n;return!1}function co(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function uo(e,t){console.error(`[wcstack/state] ${t} rejected.`,e)}function fo(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)co(e)&&Promise.resolve(e).catch(e=>uo(e,t))}class po{_name;_subscribers=new Set;constructor(e){this._name=e}get name(){return this._name}get size(){return this._subscribers.size}subscribe(e){return this._subscribers.add(e),()=>{this._subscribers.delete(e)}}unsubscribe(e){return this._subscribers.delete(e)}emit(...e){const t=[];for(const n of this._subscribers)try{t.push(n(...e))}catch(e){t.push(void 0),console.error(`[wcstack/state] a subscriber of token "${this.name}" threw; the remaining subscribers still received it.`,e)}return t}}class ho extends po{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==N&&N({type:"state:token-emit",kind:"event",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}const go=new WeakMap;function mo(e,t){let n=go.get(e);void 0===n&&(n=new Map,go.set(e,n));let o=n.get(t);return void 0===o&&(o=new ho(t,e),n.set(t,o)),o}function bo(e){go.delete(e)}const wo=new WeakMap;function yo(e){if(e.propSegments[0]!==f)return!1;const t=e.node,n=we(t),o=ve(t);if(null!==n&&void 0===o?.get(n))return null===o&&_(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(wo.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||_('eventToken binding requires a property name (e.g., "eventToken.error").');const i=function(e){return null===we(e)?null:xe(e)}(t);null===i&&_(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=i.knownProperties.get(s);void 0===r&&_(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.${R(s,i.knownProperties.keys())}`);const a=r.event,l=e.statePathName,d=e.propModifiers,c=e=>{d.includes(S)&&e.preventDefault(),d.includes(k)&&e.stopPropagation();const n=kl(t.getRootNode());null===n&&_("No state tree found on this root for eventToken handler."),n.eventTokenNames.has(l)||_(`[wcs/token-undeclared] eventToken "${l}" is not declared in $eventTokens.${R(l,n.eventTokenNames)}${W}`);const o=Xe(t);n.createStateAsync("writable",async t=>{fo(t[gn](o,()=>{const s=null!==o?On(o.listIndex,o.pathInfo.wildcardCount):[];return mo(n,l).emit(t,e,...s)}),`$on."${l}"`)})};return t.addEventListener(a,c),wo.set(e,{eventName:a,handler:c}),!0}class vo extends po{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==N&&N({type:"state:token-emit",kind:"command",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}function No(e){return e instanceof vo}const xo=new Map,Io=oo();function So(e){const t=e.propModifiers.filter(e=>e===S||e===k).sort().join(",");return`${e.statePathName}::${t}`}const ko=(e,t,n)=>o=>{t.includes(S)&&o.preventDefault(),t.includes(k)&&o.stopPropagation();const s=o.target,i=s.getRootNode(),r=kl(i);null===r&&_("No state tree found on this root for event handler.");const a=Xe(s),l=e.startsWith(A+".");r.createStateAsync("writable",async t=>{fo(t[gn](a,()=>{let d=null!==a?a.pathInfo.wildcardCount:0;if(null!==a){const e=r.addressHooks;if(e){const t=e.handlerScope;for(let e=0;e<t.length;e++)d=t[e](r,s,i,a,d)}}const c=null!==a?On(a.listIndex,d):[];if(l){const s=t[mn](Zn(n,null));return No(s)||_(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),s.emit(o,...c)}const u=t[e];return"function"!=typeof u&&_(`Handler "${e}" is not a function on the state tree.`),Reflect.apply(u,t,[o,...c])}),`"${e}"`)}).catch(t=>uo(t,`"${e}"`))};function Ao(e){return"event"===e.bindingType&&e.propName.startsWith(p)}function $o(e){if(!Ao(e))return!1;const t=So(e);let n=xo.get(t);void 0===n&&(n=ko(e.statePathName,e.propModifiers,e.statePathInfo),xo.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),Io.add(t,e),!0}function Mo(e){if(!Ao(e))return!1;const t=So(e),n=xo.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);return e.node.removeEventListener(o,n),0!==Io.countOf(t)&&(Io.remove(t,e)&&xo.delete(t),!0)}const Po=new Map,To=oo();function Eo(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function Co(e){let t="input";for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}function _o(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const o=Co(e),s=Eo(e,o);let i=Po.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==o.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===o.checked)return;let s=o.value;for(const e of n)s=e.filterFn(s);const i=kl(o.getRootNode());null===i&&_("No state tree found on this root for two-way binding.");const r=Xe(o);i.createState("writable",e=>{e[gn](r,()=>{e[t]=s})})},Po.set(s,i)),e.node.addEventListener(o,i),To.add(s,e),!0}var t,n;return!1}const Wo=new Set(["radio","checkbox"]),Ro=new Set(["value","valueAsNumber","valueAsDate"]);function Lo(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,o=n.tagName.toLowerCase();if("input"===o){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(Wo.has(e)&&"checked"===t)return!0;if(Ro.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=we(n);if(null!==s){const e=ve(n)?.get(s);void 0===e&&_(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=xe(n);if(o?.knownProperties.has(t))return!0}return!1}let Oo=1,Bo=1,Do=1;const Fo=new WeakMap;function jo(e,t,n){let o=Fo.get(e);void 0===o&&(o=new Map,Fo.set(e,o));const s=function(e,t){return`${t}::${e}`}(t,n);let i=o.get(s);return void 0===i&&(i=Oo++,o.set(s,i)),i}function zo(e,t){return"to-element"===t?2*e:2*e+1}const qo=new Set;function Vo(e){return{transactionId:Bo++,originBindingId:e,visitedEdges:qo,hop:0}}function Ho(e,t){const n=new Set(e.visitedEdges);return n.add(t),{transactionId:e.transactionId,originBindingId:e.originBindingId,visitedEdges:n,hop:e.hop+1}}let Uo=null;function Go(){return Uo}function Xo(e,t){const n=Uo;Uo=e;try{return t()}finally{Uo=n}}const Ko=[];let Qo=0;function Yo(e,t,n,o,s=!1){Qo=s?2:1;try{e.createState("writable",e=>{e[gn](t,()=>{e[n]=o})})}finally{Qo=0}}function Jo(){const e=Qo;return Qo=0,e}const Zo=new Map,es=oo(),ts=new WeakMap,ns=e=>e.detail,os=new WeakMap;const ss=new WeakMap;let is=0;const rs=new WeakMap;function as(e,t,o,s){const i=n(e.inFilters);return`${e.propName}::${e.statePathName}::${t}::${i}::${function(e){if(null===e)return"n";let t=ss.get(e);return void 0===t&&ss.set(e,t=++is),`g${t}`}(o)}::${s?"o":"s"}`}const ls=(t,n,o,s,i)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(r),s!==ns||i||function(e,t,n){const o=e[t];let s=null;if(void 0===n?void 0!==o&&(s=`the event carried no detail (undefined) while element.${t} is ${typeof o}`):null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==o&&"object"==typeof o||(s=`the event's detail is an object with a "${t}" key while element.${t} is ${typeof o}`),null===s)return;let i=os.get(e);void 0===i&&(i=new Set,os.set(e,i)),i.has(t)||(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.tagName.toLowerCase()}> "${t}": ${s}. 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.`))}(a,t,l);else{if(!(t in a))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);l=a[t]}let d=l;for(const e of o)d=e.filterFn(d);const c=ts.get(a)?.get(t);if(void 0!==c)for(const e of c)e(d);let u=null;if(e.enablePropagationContext){const o=jo(a,t,n),s=function(e,t){for(let n=Ko.length-1;n>=0;n--){const o=Ko[n];if(o.node===e&&o.receipt.member===t)return o.receipt}return null}(a,t);if(null!==s&&Object.is(s.writtenValue,l))return e.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:a,propName:t,statePathName:n,transactionId:s.transactionId,coveredBySameValueGuard:e.sameValueGuard&&(null===d||"object"!=typeof d)}),void(null!==N&&N({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:zo(o,"to-state"),node:a,member:t}));const i=zo(o,"to-state"),r=Go();if(null!==r&&r.visitedEdges.has(i))return void(null!==N&&N({type:"propagation:suppressed",reason:"visited-edge",transactionId:r.transactionId,edgeId:i,node:a,member:t}));u=Ho(r??Vo(o),i)}const f=kl(a.getRootNode());null===f&&_("No state tree found on this root for two-way binding.");const p=Xe(a),h=()=>Yo(f,p,n,d,i);null!==u?Xo(u,h):h()};function ds(e){const t=we(e.node);if(null!==t){const n=ve(e.node),o=n?.get(t);if(void 0===o)return void(null===n&&_(`CustomElementRegistry is unavailable for <${t}>.`))}if(Lo(e.node,e.propName)&&-1===e.propModifiers.indexOf(I)){const t=function(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=we(e.node);if(null!==n){const o=ve(e.node)?.get(n);void 0===o&&_(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=xe(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith(p)&&(t=n.slice(p.length));return t}(e),n=function(e){if(null!==we(e.node)){const t=xe(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??ns}return null}(e),o=function(e){if(null===we(e.node))return!1;const t=xe(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}(e),s=as(e,t,n,o);rs.set(e,{key:s,eventName:t});let i=Zo.get(s);void 0===i&&(i=ls(e.propName,e.statePathName,e.inFilters,n,o),Zo.set(s,i)),e.node.addEventListener(t,i),es.add(s,e)}}const cs=new WeakSet;function us(e){cs.add(e)}function fs(e){return!!cs.has(e)&&(cs.delete(e),!0)}const ps=new WeakMap;function hs(e,t){const n=ps.get(e);return!(void 0===n||n<t)&&(n===t?ps.delete(e):ps.set(e,n-t),!0)}const gs=new WeakSet;function ms(e){gs.add(e)}function bs(e){return!!gs.has(e)&&(gs.delete(e),!0)}let ws=0;function ys(){ws--}function vs(){return ws>0}class Ns{registry;entries=new Map;constructor(e){this.registry=e}wait(e,t,n=()=>{}){const o=e.toLowerCase();let s=this.entries.get(o);void 0===s&&(s={waiters:new Set},this.entries.set(o,s),this.registry.whenDefined(o).then(()=>this.settle(o,null),e=>this.settle(o,e)));const i={active:!0,resolve:t,reject:n};return s.waiters.add(i),()=>{i.active&&(i.active=!1,s?.waiters.delete(i))}}pendingCount(e){return this.entries.get(e.toLowerCase())?.waiters.size??0}settle(e,t){const n=this.entries.get(e);if(void 0===n)return;this.entries.delete(e);const o=Array.from(n.waiters);n.waiters.clear();for(const e of o)e.active&&(e.active=!1,null===t?e.resolve():e.reject(t))}}const xs=new WeakMap;function Is(e){let t=xs.get(e);return void 0===t&&(t=new Ns(e),xs.set(e,t)),t}const Ss=new Set([g,m,b,w]);function ks(e,t){let n=null;for(const o of e.propModifiers){const e=o.indexOf("=");if(e<0)continue;const s=o.slice(0,e).trim(),i=o.slice(e+1).trim();s!==$&&s!==M&&_(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&_(`Binding modifier "${t}" may only be specified once.`),n=i)}return n}function As(e){return e.propModifiers.some(e=>e.includes("="))}const $s=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),Ms=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function Ps(e,t){return"state"===e&&"call"===t?$s:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function Ts(t){if(!e.enableDirectionalInitialSync)return As(t)&&_("init=/sync= modifiers require enableDirectionalInitialSync."),$s;const n=null===(o=ks(t,$))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:_(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":_(`Invalid sync modifier value "${e}".`)}(ks(t,M));if("event"===t.bindingType)return null!==n&&"none"!==n&&_("Event bindings only allow init=none."),"call"===s?Ms:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if(Ss.has(t.propSegments[0]))return Ps("state",s);if("prop"!==t.bindingType)return null!==n&&"state"!==n&&"none"!==n&&_(`Binding type "${t.bindingType}" does not support init=${n}.`),Ps(n??"state",s);const i=xe(t.node);if(null===i)return Ps(n??"state",s);const r=i.knownProperties.has(t.propName),a=i.declaredInputs.has(t.propName);r||a||_(`Property "${t.propName}" is not declared by wcBindable.`);const l=n??(r&&!a?"element":"state");return(r&&a?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(l)||_(`init=${l} is incompatible with wcBindable member "${t.propName}".`),"connect"!==s||r||_(`sync=connect requires observable property "${t.propName}".`),{authority:l,syncOn:s,observable:r,outputOnly:r&&!a}}function Es(e){let t=e.getRootNode();return t instanceof DocumentFragment&&!(t instanceof ShadowRoot)&&(t=_n(t)),null===t?null:kl(t)}function Cs(e,t){return"auto"!==t?t:function(e){const t=Es(e.replaceNode);null===t&&_("No state tree found on this root for binding.");const n=to(e);let o=!1;return t.createState("readonly",e=>{o=e[bn](n)}),o}(e)?"state":"element"}let _s=0,Ws=null,Rs=0;const Ls=["active","disposed","failed"],Os=new WeakMap,Bs=new WeakMap,Ds=new WeakMap,Fs=new WeakMap,js=new WeakMap,zs=new WeakMap;function qs(e,t){const n=zs.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):zs.set(e,new Set([n,t]))):zs.set(e,t)}function Vs(e){return zs.has(e)}function Hs(e,t){const n=zs.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function Us(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))Us(n,t)}function Gs(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Xs{root;observer;constructor(e){this.root=e;const t=globalThis.MutationObserver;this.observer="function"==typeof t?new t(e=>this.handleMutations(e)):null,this.observer?.observe(e,{childList:!0,subtree:!0})}handleMutations(e){const t=[],n=[];for(let o=0;o<e.length;o++){const s=e[o],i=s.removedNodes;if(0===i.length||!hs(s.target,i.length))for(let e=0;e<i.length;e++)t.push(i[e]);const r=s.addedNodes;for(let e=0;e<r.length;e++)n.push(r[e])}const o=[];for(const e of t)fs(e)||Us(e,e=>{Hs(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)bs(e)&&!vs()||Us(e,e=>{Hs(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&ll(o)}}const Ks=new WeakMap;function Qs(e){let t=Ks.get(e);return void 0===t&&(t=new Xs(e),Ks.set(e,t)),t}function Ys(e){const t=n(e.inFilters),o=n(e.outFilters);return[e.bindingType,e.propName,e.propModifiers.join(","),e.statePathName,t,o,e.uuid??""].join("\0")}function Js(e,t,n){const o=kl(jn(e,n));null===o&&_("No state tree found on this root for binding.");const s=$n(o,e.statePathInfo);return function(e,t,n){let o=Gn.get(e);void 0===o&&(o=new WeakMap,Gn.set(e,o));const s=o.get(t);void 0===s?o.set(t,n):s instanceof Set?s.add(n):s!==n&&o.set(t,new Set([s,n])),null!==N&&N({type:"state:binding-added",absoluteAddress:kn(e,t),binding:n})}(s,t,e),s}function Zs(e,t){const n=zn(e,t);return Hn(n,e),n}function ei(e,t,n,o){null!==t?Un(t,e):function(e,t,n){const o=Gn.get(e);if(void 0===o)return;const s=o.get(t);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(t),null!==N&&N({type:"state:binding-removed",absoluteAddress:kn(e,t),binding:n}))}(n,o,e),no(e),qn(e)}function ti(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class ni{records=new Set;rowPlan=null;rows=new Set;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;disposedAt=0;constructor(e=null){null!==e&&this.observe(e)}initialize(e,t={},n){const o=t.registerAddress??!0,s={registerAddress:o,registerPathInfo:t.registerPathInfo??o,applyOnReconnect:t.applyOnReconnect??!0},i=[];for(const t of e){const e=this.remember(t,s),o=this.rowOf(e),r=null===o?-1:o.bindings.indexOf(e);if(null!==o&&0===o.phases[r]){const t=o;this.observe(e.replaceNode),s.registerAddress&&null===t.addresses[r]&&null===t.patternPathInfos[r]&&(t.registered=!0,this.registerRowSlot(t,r));continue}const a=Ds.get(e);void 0===a||"disposed"===a.phase||"failed"===a.phase?(this.start(e,s,n),i.push(e)):(this.observe(a.anchor),s.registerAddress&&null===a.address&&null===a.patternListIndex&&(a.options.registerAddress=!0,this.registerAddress(a)),"active"===a.phase&&this.settleInitialRecord(a),this.settleConnectedSnapshot(a))}return i.filter(e=>this.shouldApplyState(e))}activate(e,t){if(Gs(t)&&Qs(t),null===this.rowPlan)for(const n of e){const e=Ds.get(n);if(void 0!==e&&e.session===this&&"disposed"!==e.phase&&"failed"!==e.phase){null===e.address&&null===e.patternListIndex&&(e.options.registerAddress=!0,this.registerAddress(e,t)),"active"===e.phase&&this.settleInitialRecord(e),this.settleConnectedSnapshot(e);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,t)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,e,t)}shouldApplyState(t){if(!e.enableDirectionalInitialSync)return As(t)&&Ts(t),!0;const n=this.rowOf(t);if(null!==n){const e=n.bindings.indexOf(t);if(e>=0){if(!n.registered)return!0;if(2===n.phases[e])return!1;const t=n.plan.slots[e];return 1&n.flags[e]?"state"===t.authority||!t.policy.outputOnly:(n.flags[e]|=1,"state"===t.authority)}}const o=Ds.get(t);return void 0===o||o.session!==this||(!o.options.registerAddress||"waiting-definition"===o.phase||"failed"!==o.phase&&("active"===o.phase&&this.settleInitialRecord(o),o.initialApplyDone?"state"===o.resolvedAuthority||!o.outputOnlyMember&&!o.observationPending:(o.initialApplyDone=!0,"state"===o.resolvedAuthority)))}getRecord(e){const t=this.rowOf(e),n=null===t?-1:t.bindings.indexOf(e);if(null!==t&&n>=0){let o=Bs.get(t);void 0===o&&Bs.set(t,o=[]);return{id:o[n]??(o[n]=++_s),info:e,generation:t.generation,phase:Ls[t.phases[n]],teardowns:null}}const o=Ds.get(e);return o?.session===this?o:null}addTeardown(e,t){const n=Ds.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(ti(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=this.deferredByNode.get(e)??new Set,i=()=>s.delete(a)&&this.deferred.delete(a),r=()=>{const s=ve(e);null===s&&_(`CustomElementRegistry is unavailable for <${t}>.`),a.cancel=Is(s).wait(t,()=>{if(i())try{Ne(s,e),n()}catch(e){o(e)}},e=>{i()&&o(e)})},a={node:e,born:++Rs,cancel:null,arm:()=>{if(null===a.cancel&&this.deferred.has(a))try{r()}catch(e){i(),o(e)}}},l=e.getRootNode();if(null!==Ws||11===l.nodeType&&!Gs(l)){if(null===Ws){const e=Ws=[];queueMicrotask(()=>{Ws=null;for(let t=0;t<e.length;t++)e[t].arm()})}Ws.push(a)}else r();return Gs(l)&&Qs(l),qs(e,this),this.deferredByNode.set(e,s.add(a)),this.deferred.add(a),()=>{i(),a.cancel?.()}}disposeBinding(e){const t=this.rowOf(e);if(null!==t){const n=t.bindings.indexOf(e);if(n>=0)return void this.disposeRowSlot(t,n)}const n=Ds.get(e);void 0!==n&&n.session===this&&this.disposeRecord(n)}get isRowSession(){return null!==this.rowPlan}get currentRowPlan(){return this.rowPlan}disposeBindings(e){for(let t=0;t<e.length;t++)this.disposeBinding(e[t]);if(!(this.rows.size>0))for(const e of Array.from(this.deferred))e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}destroyRow(e){const t=e.length>0?this.rowOf(e[0]):null;null!==t?(this.destroyRowRecord(t),this.rows.delete(t)):this.destroyRecords()}destroyRowRecord(e){for(let t=0;t<e.bindings.length;t++){const n=e.addresses[t];null!==n&&(Un(n,e.bindings[t]),e.addresses[t]=null),e.phases[t]=1}}dispose(){this.disposedAt=Rs;for(const e of Array.from(this.rows))for(let t=0;t<e.bindings.length;t++)this.disposeRowSlot(e,t);for(const e of Array.from(this.records))this.disposeRecord(e);for(const e of Array.from(this.deferred))e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;if(0===this.records.size)return!0;for(const e of this.records)if(e.pendingDefinitions>0||e.observationPending)return!1;return!0}destroyRecords(){this.disposedAt=Rs;for(const e of this.rows)this.destroyRowRecord(e);this.rows.clear();for(const e of this.records)null!==e.address&&(Un(e.address,e.info),e.address=null),e.phase="disposed",e.teardowns=null;this.records.clear()}forEachActiveBindingNode(e){for(const t of this.rows)for(let n=0;n<t.bindings.length;n++)0===t.phases[n]&&e(t.bindings[n].node);for(const t of this.records)"active"===t.phase&&e(t.info.node)}rebindAddresses(){const e=[];for(const t of this.rows)for(let n=0;n<t.bindings.length;n++){if(0!==t.phases[n])continue;if(null===t.addresses[n]&&null===t.patternPathInfos[n])continue;const o=t.bindings[n];this.unregisterRowSlot(t,n),this.registerRowSlot(t,n),this.shouldApplyState(o)&&e.push(o)}for(const t of this.records){if("active"!==t.phase)continue;const n=t.info;if(null===t.address&&null===t.patternListIndex)continue;const o="for"===n.bindingType?zn(n):null;if(ei(n,t.address,t.patternPathInfo,t.patternListIndex),t.address=null,t.patternPathInfo=null,t.patternListIndex=null,this.registerAddress(t),null!==o){const e=zn(n);e!==o&&rn(o)&&tn(e,en(o)),e!==o&&hn(o)&&un(e,cn(o))}this.shouldApplyState(n)&&e.push(n)}return e}observe(e){const t=function(e){const t=e.getRootNode();return Gs(t)?t:null}(e);null!==t&&Qs(t)}handleMutations(e,t,n){for(const n of t)Us(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)Us(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&ll(o)}handleRemovedNode(e){const t=this.knownBindingsByNode.get(e);if(void 0!==t)if(t instanceof Map)for(const e of t.values())this.disposeBinding(e);else this.disposeBinding(t);this.deferredByNode.get(e)?.forEach(e=>{e.cancel?.(),e.cancel=null,this.deferred.delete(e)})}handleAddedNode(e,t,n){this.deferredByNode.get(e)?.forEach(e=>{e.born<=this.disposedAt||(this.deferred.add(e),e.arm())});const o=this.knownBindingsByNode.get(e);if(void 0===o)return;const s=o instanceof Map?o.values():[o];for(const e of s){const o=Ds.get(e);if("active"===o?.phase){this.settleConnectedSnapshot(o);continue}if("disposed"!==o?.phase)continue;const s=this.optionsByBinding.get(e);if(void 0!==s)try{this.start(e,s),(s.applyOnReconnect||o.pendingDefinitions>0&&o.generation>this.disposedAt)&&this.shouldApplyState(e)&&t.push(e)}catch(e){n?.(e)}}}knownMapFor(e){const t=this.knownBindingsByNode.get(e);if(t instanceof Map)return t;const n=new Map;if(void 0!==t){let e=js.get(t);void 0===e&&(e=Ys(t),js.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;qs(n,this);const o=this.knownMapFor(n);let s=js.get(e);void 0===s&&(s=Ys(e),js.set(e,s));const i=o.get(s);if(void 0!==i){const e=this.optionsByBinding.get(i);return void 0!==e&&(e.registerAddress||=t.registerAddress,e.registerPathInfo||=t.registerPathInfo,e.applyOnReconnect||=t.applyOnReconnect),i}return o.set(s,e),this.optionsByBinding.set(e,{...t}),e}initializeRow(e,t){this.rowPlan=e;const n=e.slots,o=t.length,s={id:++_s,session:this,generation:++Rs,plan:e,bindings:t,registered:!1,phases:new Array(o).fill(0),flags:new Array(o).fill(0),addresses:new Array(o).fill(null),patternPathInfos:new Array(o).fill(null),patternListIndexes:new Array(o).fill(null)};this.rows.add(s);for(let e=0;e<o;e++){const o=t[e],i=o.replaceNode;if(qs(i,this),this.addKnownRowBinding(i,o,e),Os.set(o,s),n[e].isEvent){let t=!1;try{t=$o(o)}catch(t){throw s.phases[e]=2,t}t&&(s.flags[e]|=2)}}}activatePlanRows(e,t,n){const o=t.length>0?this.rowOf(t[0]):null;if(null===o||o.bindings!==t){for(const e of t)this.initialize([e],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});return}o.registered=!0;const s=e.slots;let i=!1;for(let e=0;e<t.length;e++)if(0===o.phases[e])null===o.addresses[e]&&null===o.patternPathInfos[e]&&this.registerRowSlot(o,e,n);else{if(i||(o.generation=++Rs,i=!0,this.rows.add(o)),o.phases[e]=0,o.flags[e]=0,s[e].isEvent){let n=!1;try{n=$o(t[e])}catch(t){throw o.phases[e]=2,this.runRowSlotTeardowns(o,e),t}n&&(o.flags[e]|=2)}this.registerRowSlot(o,e,n)}}rowOf(e){const t=Os.get(e);return void 0!==t&&t.session===this?t:null}registerRowSlot(e,t,n){if(null!==e.addresses[t]||null!==e.patternPathInfos[t])return;const o=e.bindings[t],s=Dn(o);null!==s?(e.patternPathInfos[t]=Js(o,s,n),e.patternListIndexes[t]=s):e.addresses[t]=Zs(o,n)}unregisterRowSlot(e,t){const n=e.addresses[t],o=e.patternPathInfos[t];null===n&&null===o||(ei(e.bindings[t],n,o,e.patternListIndexes[t]),e.addresses[t]=null,e.patternPathInfos[t]=null,e.patternListIndexes[t]=null)}disposeRowSlot(e,t){if(1!==e.phases[t]){e.phases[t]=1,this.runRowSlotTeardowns(e,t);for(let t=0;t<e.phases.length;t++)if(0===e.phases[t])return;this.rows.delete(e)}}runRowSlotTeardowns(e,t){try{this.unregisterRowSlot(e,t)}catch{}if(2&e.flags[t]){e.flags[t]&=-3;try{Mo(e.bindings[t])}catch{}}}addKnownRowBinding(e,t,n){const o=this.knownBindingsByNode.get(e);if(void 0===o)return void this.knownBindingsByNode.set(e,t);if(o instanceof Map)return void o.set("@plan:"+n,t);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,t),this.knownBindingsByNode.set(e,s)}start(e,t,n){!function(e){const t=e.node,n=e.replaceNode;t!==n&&null!==t.parentNode&&t.parentNode.replaceChild(n,t)}(e);const o=this.optionsByBinding.get(e)??{...t},s={id:++_s,info:e,generation:++Rs,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:null,resolvedAuthority:null,initialSettled:!1,initialApplyDone:!1,outputOnlyMember:!1,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};Ds.set(e,s),this.records.add(s),void 0===n&&this.observe(s.anchor);try{s.phase="attaching",this.attachListeners(s),s.options.registerAddress&&this.registerAddress(s,n),0===s.pendingDefinitions&&(s.phase="active")}catch(e){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),e}}attachListeners(t){const n=t.info;$o(n)?t.eventAttached=!0:n.propSegments[0]!==f?(_o(n)&&ti(t,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const t=Co(e),n=Eo(e,t),o=Po.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==To.countOf(n)&&(To.remove(n,e)&&Po.delete(n),!0))}return!1}(n)),lo(n)&&ti(t,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(I)){const t=ao(e),n=ro(e,t),o=so.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==io.countOf(n)&&(io.remove(n,e)&&so.delete(n),!0))}return!1}(n)),this.attachAfterDefinition(t,()=>{if(e.enableDirectionalInitialSync&&Lo(n.node,n.propName)&&-1===n.propModifiers.indexOf(I)){const e=function(e,t,n){let o=ts.get(e);void 0===o&&(o=new Map,ts.set(e,o));let s=o.get(t);return void 0===s&&(s=new Set,o.set(t,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(t),0===o?.size&&ts.delete(e)}}(n.node,n.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});ti(t,e)}ds(n),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{yo(n)&&ti(t,()=>function(e){if(e.propSegments[0]!==f)return!1;const t=wo.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),wo.delete(e),!0)}(n))})}attachAfterDefinition(e,t){const n=we(e.info.node);if(null===n)return void t();const o=ve(e.info.node);if(null===o&&_(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation;ti(e,this.deferUntilDefined(e.info.node,n,()=>{this.isAlive(e,s)&&(t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e)))},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))}))}settleInitialRecord(t){if(e.enableDirectionalInitialSync&&!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=Ts(t.info),n=Cs(t.info,e.authority);if(t.initialPolicy=e,t.resolvedAuthority=n,t.initialSettled=!0,t.outputOnlyMember=e.outputOnly,t.phase="active",!e.observable)return;if("connect"===e.syncOn&&t.info.node instanceof HTMLElement&&!t.info.node.isConnected)return t.observationPending=!0,void ws++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(e,t){if(!this.isAlive(e,e.generation))return;const n=e.info.node,o=e.info.propName;if(!(o in n))return;const s=e.eventSequence,i=n[o];e.observationPending&&(e.observationPending=!1,ys()),t&&e.eventSequence!==s||(e.hasProducerValue=!0,e.producerValue=i,"element"===e.resolvedAuthority&&function(e,t){let n=t;for(const t of e.inFilters)n=t.filterFn(n);const o=Es(e.node);null===o&&_("No state tree found on this root for initial binding sync."),Yo(o,Xe(e.node),e.statePathName,n)}(e.info,i))}settleConnectedSnapshot(t){if(e.enableDirectionalInitialSync&&t.observationPending&&t.info.node instanceof HTMLElement&&t.info.node.isConnected)try{this.readProducerSnapshot(t,!1)}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}}registerAddress(e,t){if(null!==e.address||null!==e.patternListIndex)return;const n=e.info,o=Dn(n);if(null!==o?(e.patternPathInfo=Js(n,o,t),e.patternListIndex=o):e.address=Zs(n,t),!e.options.registerPathInfo)return;const s=kl(n.replaceNode.getRootNode());null===s&&_("No state tree found on this root for binding."),"event"!==n.bindingType&&s.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&Ds.get(e.info)===e&&"disposed"!==e.phase&&"failed"!==e.phase}disposeRecord(e){"disposed"!==e.phase&&(e.phase="disposed",this.runTeardowns(e),this.records.delete(e))}runTeardowns(e){e.observationPending&&(e.observationPending=!1,ys());const t=e.info;if(null!==e.address||null!==e.patternListIndex)try{ei(t,e.address,e.patternPathInfo,e.patternListIndex),e.address=null,e.patternPathInfo=null,e.patternListIndex=null}catch{}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=rs.get(e);if(void 0===t)return;rs.delete(e);const n=Zo.get(t.key);void 0!==n&&(e.node.removeEventListener(t.eventName,n),es.remove(t.key,e)&&Zo.delete(t.key))}(t)}catch{}}if(null!==e.teardowns){const t=Array.from(e.teardowns).reverse();e.teardowns=null;for(const e of t)try{e()}catch{}}if(e.eventAttached){e.eventAttached=!1;try{Mo(t)}catch{}}}}function oi(e){let t=Fs.get(e);return void 0===t&&(t=new ni(e),Fs.set(e,t)),t}function si(e){return Ds.get(e)?.session??Os.get(e)?.session??null}let ii=null;function ri(e){ii=e}function ai(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const li=Object.freeze([]);const di=new WeakMap;const ci=new WeakMap;function ui(e){return ci.get(e)??[]}function fi(e,t){ci.set(e,t)}const pi=new WeakMap;function hi(e){return pi.get(e)??[]}function gi(e,t){pi.set(e,t)}function mi(e,t){const n=hi(e);for(const e of n)Ke(e,t)}const bi=new WeakMap;function wi(e){return bi.get(e)??[]}function yi(e,t){bi.set(e,t)}Set.prototype.difference||(Set.prototype.difference=function(e){const t=new Set(this);for(const n of e)t.delete(n);return t}),Set.prototype.intersection||(Set.prototype.intersection=function(e){const t=new Set;for(const n of e)this.has(n)&&t.add(n);return t});const vi=new WeakMap,Ni=new WeakSet;function xi(e){return vi.get(e)??null}function Ii(e,t){if(null===t)vi.delete(e);else{vi.set(e,t);const{stateElement:n,pathInfo:o}=e.absolutePathInfo;if(o.wildcardCount>0){for(let e=o.parentPathInfo;null!==e&&e.wildcardCount===o.wildcardCount&&!Ni.has(e);e=e.parentPathInfo)Ni.add(e);n.setPathInfo(o.lastWildcardPath,"prop","internal")}}}function Si(e){const t=vi.get(e);t&&(t.dirty=!0),null!==e.listIndex&&Ni.has(e.absolutePathInfo.pathInfo)&&e.listIndex.cacheStamp++}const ki=Symbol.for("wcstack.transition-runner");function Ai(e){const t=globalThis[ki];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}function $i(e,t,n){const o=Ai(e);if(null!==o)return o.run(t,{source:e,types:n});t()}const Mi=[],Pi=[];let Ti=-1,Ei=0,Ci=!1;function _i(e){Pi.includes(e)||Pi.push(e)}function Wi(e,t=0){const n=Mi.findIndex(e=>e.priority>t),o={listener:e,priority:t};-1===n?Mi.push(o):Mi.splice(n,0,o)}function Ri(e){const t=Mi.findIndex(t=>t.listener===e);-1!==t&&Mi.splice(t,1)}function Li(e){queueMicrotask(()=>{throw e})}class Oi{_queueUpdateRecords=[];_queueRenderOnlyAddresses=[];constructor(){}enqueueAbsoluteAddress(e,t=null){for(let t=0;t<Pi.length;t++)Pi[t](e);Ti>Ei&&(Ei=Ti),Ti<0&&(Ci=!0);const n=this._isQueueEmpty();this._queueUpdateRecords.push({absoluteAddress:e,context:t}),n&&this._scheduleDrain()}enqueueRenderOnlyAddress(e){const t=this._isQueueEmpty();this._queueRenderOnlyAddresses.push(e),t&&this._scheduleDrain()}_isQueueEmpty(){return 0===this._queueUpdateRecords.length&&0===this._queueRenderOnlyAddresses.length}_scheduleDrain(){fn(),queueMicrotask(()=>{const e=this._queueUpdateRecords,t=this._queueRenderOnlyAddresses;this._queueUpdateRecords=[],this._queueRenderOnlyAddresses=[],gt++,this._applyChange(e,t)})}hasQueuedPath(e,t){return this._queueUpdateRecords.some(n=>n.absoluteAddress.absolutePathInfo.stateElement===e&&n.absoluteAddress.absolutePathInfo.pathInfo.path===t)}testApplyChange(e,t){this._applyChange(e.map((e,n)=>({absoluteAddress:e,context:t?.[n]??null})))}_applyChange(e,t=[]){let n=Ci?0:Ei;Ei=0,Ci=!1;const s=new Map,i=new Set;for(let t=0;t<e.length;t++){const n=e[t],o=s.get(n.absoluteAddress);null!==N&&null!=o&&null!==n.context&&o.transactionId!==n.context.transactionId&&N({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:o.transactionId,winnerTransactionId:n.context.transactionId}),s.set(n.absoluteAddress,n.context),i.add(n.absoluteAddress)}for(let e=0;e<t.length;e++){const n=t[e];s.has(n)||s.set(n,null)}const r=[],a=new Map;s.forEach((e,t)=>{if(null!==e&&e.hop>=P)return console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,transactionId:e.transactionId,hop:e.hop,maxHops:P}),void(null!==N&&N({type:"propagation:hop-limit",absoluteAddress:t,transactionId:e.transactionId,hop:e.hop}));const n=Xn(t);if(void 0!==n)if(n instanceof Set)for(const t of n)!1!==t.replaceNode.isConnected&&(r.push(t),null!==e&&a.set(t,e));else!1!==n.replaceNode.isConnected&&(r.push(n),null!==e&&a.set(n,e))});try{const e=()=>{Ti=n+1;try{a.size>0?ll(r,a):ll(r)}finally{Ti=-1}};if(n>T&&r.length>0){if(n++===T+1){const e=[...new Set(Array.from(i,e=>e.absolutePathInfo.pathInfo.path))];console.error("[@wcstack/state] render chain depth limit exceeded; bindings for this batch were not applied.",{maxDepth:T,paths:e}),null!==N&&N({type:"state:render-chain-limit",maxDepth:T,paths:e})}}else if(o()||0===r.length)e();else{const t=$i("state",e);void 0!==t&&t.catch(Li)}}finally{pn(),Ti=n,function(e){for(const t of Mi.slice())t.listener(e)}(i),Ti=-1}}}const Bi=new Oi;function Di(){return Bi}const Fi=new WeakMap,ji=new WeakMap,zi=new WeakMap,qi=new WeakMap;let Vi=!1;const Hi=new WeakMap;function Ui(e){const t=e.absolutePathInfo.stateElement;let n=Hi.get(t);void 0===n&&Hi.set(t,n=new Set),n.add(e)}function Gi(e){const t=Hi.get(e);return void 0===t?null:(Hi.delete(e),t)}const Xi=new WeakMap,Ki=new WeakMap,Qi=new WeakMap,Yi=new WeakMap,Ji=new WeakMap,Zi=[];function er(e,t){const n=tr(e);if(n.recorded.has(t))return;n.recorded.add(t);const o=d(t).cumulativePaths;if(o.length<2)return;let s=Ji.get(e);void 0===s&&Ji.set(e,s=new Map);for(let e=0;e<o.length-1;e++){let n=s.get(o[e]);void 0===n&&s.set(o[e],n=new Set),n.add(t)}}function tr(e){let t=Fi.get(e);return void 0===t&&Fi.set(e,t={byPath:new Map,lastValue:new Map,recorded:new Set,tracked:new Set}),t}function nr(e,t,n){let o=e.get(t);void 0===o&&e.set(t,o=new Set),o.add(n)}function or(e,t,n){const o=e.get(t);o.delete(n),0===o.size&&e.delete(t)}function sr(e,t,n,o){const s=function(e,t){let n=e.byPath.get(t);return void 0===n&&e.byPath.set(t,n=new Map),n}(e,t);let i=ji.get(o);if(void 0===i&&ji.set(o,i=new Map),i.has(t)){const e=i.get(t);return Object.is(e,n)||(or(s,e,o),i.set(t,n),nr(s,n,o)),!1}return i.set(t,n),nr(s,n,o),!0}function ir(e,t,n){const o=e.get(t);return void 0===o?(e.set(t,[n]),!0):(o.push(n),!1)}function rr(e,t,n,o,s,i){e.lastValue.set(t,n),s&&(null!==o.listIndex&&ir(zi,o.listIndex,i)&&function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){let n=Qi.get(t);void 0===n&&Qi.set(t,n=new Set),n.add(e)}}(o.listIndex),null!==i.levelListIndex&&ir(qi,i.levelListIndex,i))}function ar(e,t,n,o,s){Vi=!0;const i=tr(e);er(e,t);rr(i,t,s,o,sr(i,t,n,o),{stateElement:e,path:t,absAddress:o,levelListIndex:null})}function lr(e,t,n,o,s){Vi=!0;const i=tr(e);er(e,t);rr(i,t,s,o,sr(i,t,n.index,o),{stateElement:e,path:t,absAddress:o,levelListIndex:n})}function dr(e,t){tr(e).tracked.add(t)}function cr(e){const t=Fi.get(e);return void 0===t?null:{byPath:t.byPath,lastValue:t.lastValue,tracked:t.tracked,watchers:Xi.get(e)}}function ur(e,t){return!0===Fi.get(e)?.byPath.has(t)||!0===Xi.get(e)?.has(t)}function fr(e,t,n,o,s){Vi=!0,tr(e).lastValue.set(t,s),er(e,t);let i=Xi.get(e);void 0===i&&Xi.set(e,i=new Map);let r=i.get(t);void 0===r&&i.set(t,r=new Set);let a,l=Ki.get(o);if(void 0===l?(Ki.set(o,l=[]),zt(o)):a=l.find(n=>n.stateElement===e&&n.path===t),void 0===a){a={stateElement:e,path:t,indexes:o,getters:new Set},l.push(a),r.add(a);const n=o[0]?.parentListIndex??null;if(null!==n){let e=Yi.get(n);void 0===e&&Yi.set(n,e=new Set),e.add(a)}}a.getters.add(n)}function pr(e,t,n){if("number"!=typeof t)return;const o=e.indexes[t];if(void 0!==o)for(const t of e.getters)n.push(Pn(e.stateElement,Zn(t,o)))}function hr(e,t){if(!Vi||e===t)return;const n=Ki.get(e);if(void 0===n)return;Ki.delete(e);const o=Ki.get(t);Ki.set(t,void 0===o?n:o.concat(n)),zt(t);for(const o of n){o.indexes=t;const n=tr(o.stateElement).lastValue.get(o.path);if("number"!=typeof n)continue;const s=e[n],i=t[n];if(s!==i)for(const e of[s,i])if(void 0!==e&&!vt(e))for(const t of o.getters){const n=Pn(o.stateElement,Zn(t,e));Si(n),Di().enqueueAbsoluteAddress(n,null),Ui(n)}}}function gr(e,t){if(void 0!==e)for(const n of e)t.push(n)}function mr(e,t,n,o,s){const i=Fi.get(e),r=i?.byPath.get(t),a=Xi.get(e)?.get(t);if(void 0===i||void 0===r&&void 0===a)return Zi;const l=i.lastValue.has(t),d=i.lastValue.get(t);i.lastValue.set(t,s);const c=[],u=!n||!Object.is(o,s),f=l&&(!n||!Object.is(d,o))&&!Object.is(d,s);if(void 0!==r&&(n&&gr(r.get(o),c),f&&gr(r.get(d),c),u&&gr(r.get(s),c)),void 0!==a)for(const e of a)n&&pr(e,o,c),f&&pr(e,d,c),u&&pr(e,s,c);return c}function br(e,t){return!0===Ji.get(e)?.has(t)}function wr(e,t){let n=e;for(const e of t){if("object"!=typeof n||null===n)return;n=n[e]}return n}function yr(e,t,n,o,s=!0){const i=d(t).segments.length,r=[];for(const a of Ji.get(e).get(t)){const t=d(a).segments.slice(i);if(t.includes(x)){vr(e,a,r);continue}const l=s?wr(n,t):void 0;for(const n of mr(e,a,s,l,wr(o,t)))r.push(n)}return r}function vr(e,t,n){const o=Fi.get(e).byPath.get(t);if(void 0!==o)for(const e of o.values())gr(e,n);const s=Xi.get(e)?.get(t);if(void 0!==s)for(const e of s)for(let t=0;t<e.indexes.length;t++)pr(e,t,n)}function Nr(e){const t=qi.get(e.levelListIndex),n=t.indexOf(e);t.splice(n,1)}function xr(e){const t=zi.get(e);if(void 0!==t){zi.delete(e),function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){const n=Qi.get(t);void 0!==n&&(n.delete(e),0===n.size&&Qi.delete(t))}}(e);for(const e of t){const{stateElement:t,path:n,absAddress:o}=e,s=ji.get(o),i=s.get(n);s.delete(n),or(Fi.get(t).byPath.get(n),i,o),null!==e.levelListIndex&&Nr(e)}}}function Ir(e){const t=Yi.get(e);if(void 0!==t){Yi.delete(e);for(const e of t){const t=Xi.get(e.stateElement),n=t.get(e.path);n.delete(e),0===n.size&&t.delete(e.path);const o=Ki.get(e.indexes);o.splice(o.indexOf(e),1),0===o.length&&Ki.delete(e.indexes)}}}function Sr(e){if(!Vi)return;xr(e),Ir(e);const t=Qi.get(e);if(void 0!==t){Qi.delete(e);for(const e of t)xr(e),Ir(e),Qi.delete(e)}}function kr(e,t,n){if(!Vi)return;const o=qi.get(e);if(void 0!==o)for(const{stateElement:e,path:s,absAddress:i}of o){const o=Fi.get(e),r=o.byPath.get(s);or(r,t,i),nr(r,n,i),ji.get(i).set(s,n);const a=o.lastValue.get(s);(Object.is(a,t)||Object.is(a,n))&&(Si(i),Di().enqueueAbsoluteAddress(i,null),Ui(i))}}const Ar=new WeakMap,$r=Object.freeze([]),Mr=new Set,Pr=new WeakMap,Tr=new WeakMap;function Er(e,t){Tr.set(e,new WeakRef(Object(t)))}function Cr(e){return Tr.get(e)?.deref()}function _r(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Wr(e){!function(e){for(const t of e)ut.add(t)}(e);for(const t of e)Sr(t)}function Rr(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:$r,s=Array.isArray(n)&&n.length>0?n:$r,i=function(e,t){const n=Array.isArray(e)&&e.length>0?e:$r,o=Array.isArray(t)&&t.length>0?t:$r;let s=Ar.get(n);return s&&s.get(o)||null}(o,s);if(i&&i.newIndexes===Dt(s,e))return i;const r=Dt(o,e)||[];let a;try{if(0===s.length)return a={oldIndexes:r,newIndexes:[],changeIndexSet:Mr,deleteIndexSet:new Set(r),addIndexSet:Mr};let t=Dt(s,e);if(null===t&&null!==e&&function(e,t){const n=_t.get(e);for(const o of n??[])if($t(e,o))n.delete(o);else if(o!==t)return!0;return!1}(o,e)&&Er(s,o),0===o.length||null===t&&Cr(s)===o){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=nt(e,n);t.push(o)}}return a={oldIndexes:r,newIndexes:t,changeIndexSet:Mr,deleteIndexSet:new Set(r),addIndexSet:new Set(t)}}if(_r(o,s)&&(t??r)===r)return o!==s&&Lr(o,r,e),a={oldIndexes:r,newIndexes:r,changeIndexSet:Mr,deleteIndexSet:Mr,addIndexSet:Mr};if(null!==t)return Or(r,t);t=[];const n=new Map;for(let e=0;e<o.length;e++){const t=o[e];let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}const i=new Set,l=new Set;let d=!1;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),u=c&&c.length>0?c.shift():void 0;if(void 0===u){const n=nt(e,o);t.push(n),l.add(n)}else{const e=r[u];d=!0,u!==o&&i.add(e),t.push(e)}}d&&Lr(o,t,e);return a={oldIndexes:r,newIndexes:t,changeIndexSet:i,deleteIndexSet:new Set(r).difference(new Set(t)),addIndexSet:l}}finally{void 0!==a&&(!function(e,t,n){let o=Ar.get(e);o||(o=new WeakMap,Ar.set(e,o)),o.set(t,n)}(o,s,a),zt(r),qt(s,a.newIndexes))}}(e,t,n);return function(e,t){const n=e.newIndexes;let o;for(let e=0;e<n.length;e++){if(n[e].index!==e){const t=n[e].index;n[e].index=e,kr(n[e],t,e)}at(n[e],t[e])&&(o??=[]).push(n[e])}const s=Pr.get(t);s?.[0]===gt&&(o=o?s[1].concat(o):s[1]),o&&Pr.set(t,[gt,o]),e.valueChangeIndexes=o}(o,Array.isArray(n)&&n.length>0?n:$r),function(e){for(const t of e)ut.delete(t)}(o.newIndexes),Cr(n)!==t&&(Wr(o.deleteIndexSet),hr(o.oldIndexes,o.newIndexes)),o}function Lr(e,t,n){var o;if(o=e,Rt.add(o),null!==n)for(const e of t)it(e,n)}function Or(e,t){const n=new Set(t),o=new Set(e),s=new Set,i=n.difference(o),r=o.difference(n),a=new Map;for(let t=0;t<e.length;t++)a.set(e[t],t);for(let e=0;e<t.length;e++){const n=t[e];i.has(n)||a.get(n)!==e&&s.add(n)}return{oldIndexes:e,newIndexes:t,changeIndexSet:s,deleteIndexSet:r,addIndexSet:i}}function Br(e){if(0===e.changeIndexSet.size||e.addIndexSet.size===e.newIndexes.length)return null;const t=new Map;for(let n=0;n<e.oldIndexes.length;n++)t.set(e.oldIndexes[n],n);const n=[],o=[];let s=-1,i=!0;for(const r of e.newIndexes){if(e.addIndexSet.has(r))continue;const a=t.get(r);if(void 0===a)return null;a<s&&(i=!1),s=a,n.push(r),o.push(a)}if(i)return null;const r=function(e){const t=e.length,n=[],o=new Array(t).fill(-1);for(let s=0;s<t;s++){const t=e[s];let i=0,r=n.length;for(;i<r;){const o=i+r>>1;e[n[o]]<t?i=o+1:r=o}i>0&&(o[s]=n[i-1]),n[i]=s}const s=[];let i=n.length>0?n[n.length-1]:-1;for(;i>=0;)s.push(i),i=o[i];return s.reverse(),s}(o),a=new Set;for(const e of r)a.add(n[e]);return a}const Dr=new WeakMap;function Fr(e){return Dr.get(e)??null}function jr(e,t){Dr.set(e,t)}const zr=new WeakMap;const qr=new WeakMap;function Vr(e,t){for(let n=0;n<e.length;n++)if(t.has(e[n]))return!0;return!1}function Hr(e,t,n,o,s){const i=function(e,t,n){let o=qr.get(e);void 0===o&&qr.set(e,o=new Map);const s=o.get(n);if(void 0!==s)return s;const i=n+".",r=t.map((t,o)=>{const s=e.slots[o];if(s.isEvent||s.isIndexBinding)return null;const r=t.statePathInfo.path;if(!r.startsWith(i))return null;const a=r.slice(i.length).split("."),l=[];let d=n;for(const e of a){if("*"===e)return null;d+="."+e,l.push(d)}return{tail:a,prefixes:l}});return o.set(n,r),r}(e,t,o.pathInfo.path),r=s.stateElement.getterPaths,a=0!==(s.stateElement.addressHooks?.readMissing.length??0);let l,d=!1;for(let e=0;e<t.length;e++){const c=t[e];if(!n.shouldApplyState(c))continue;const u=i[e];if(null===u||Vr(u.prefixes,r)){rl(c,s);continue}if(s.appliedBindingSet.has(c))continue;d||(l=s.state[mn](o),d=!0);const f=u.tail;let p=l,h=!1;for(let e=0;e<f.length;e++){if(null==p){p=void 0;break}if(a&&!(f[e]in Object(p))){h=!0;break}p=p[f[e]]}h?rl(c,s):(s.appliedBindingSet.add(c),il(c,s,p))}}function Ur(e,t,n){mi(e,t);const o=ui(e),s=Fr(e);if(null!==s&&(s.activate(o,n.rootNode),null!==t&&!1===n.stateElement.hasUpdatedCallback&&!0!==n.stateElement.hasRecursion)){const i=function(e){return zr.get(e)??null}(e);if(null!==i)return void Hr(i,o,s,t,n)}for(const e of o){if(null===s){Hn(zn(e),e)}(null===s||s.shouldApplyState(e))&&rl(e,n)}e.spreads&&dl(e.spreads,t,s,o,wi(e))}function Gr(e){if(!e.mounted)return;const t=ui(e),n=Fr(e);for(let e=0;e<t.length;e++){const o=t[e];if(null!==n)n.disposeBinding(o);else{Un(zn(o),o)}}!function(e){const t=hi(e);for(let e=0;e<t.length;e++)Ke(t[e],null)}(e)}function Xr(){return Object.freeze(new Set)}const Kr=new WeakMap,Qr=Xr();function Yr(e,t){const n=Kr.get(e);n?n.add(t):Kr.set(e,new Set([t]))}function Jr(e){const t=Kr.get(e);return void 0!==t?t:Qr}function Zr(e,t){const n=Kr.get(e);n&&(n.delete(t),0===n.size&&Kr.delete(e))}const ea=new Set(["if","elseif","else","for"]);class ta{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(e,t=!1){this._content=e,this._ranged=t;const n=[];for(let t=e.firstChild;null!==t;t=t.nextSibling)n.push(t);this._childNodeArray=n,this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(e){const t=this._childNodeArray;for(let n=0;n<t.length;n++){const o=t[n];ms(o),e.appendChild(o)}this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const e=this._firstNode,t=this._lastNode;if(null===e||null===t||null===e.parentNode)return this._childNodeArray;const n=[];for(let o=e;null!==o;o=o.nextSibling)if(n.push(o),o===t)return n;return this._childNodeArray}mountAfter(e){const t=e.parentNode;if(t){let n=e;for(const e of this._movableNodes()){if(n.nextSibling!==e){ms(e);const o=t;e.parentNode===t&&"function"==typeof o.moveBefore?o.moveBefore(e,n.nextSibling):t.insertBefore(e,n.nextSibling)}n=e}}this._mounted=!0}tryDestroy(){const e=Fr(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRow(ui(this));const t=this._childNodeArray;for(let e=0;e<t.length;e++){const n=t[e];null!==n.parentNode&&(us(n),n.parentNode.removeChild(n))}const n=ui(this);for(let e=0;e<n.length;e++){const t=n[e];ea.has(t.bindingType)&&Jr(t.node).forEach(e=>{e.tryDestroy()||e.unmount()})}return this._mounted=!1,!0}unmountInPlace(){{const e=Fr(this);null!==e&&(e.isRowSession?e.disposeBindings(ui(this)):e.dispose())}this._teardownBindings()}_teardownBindings(){const e=ui(this);for(let t=0;t<e.length;t++){const n=e[t];ea.has(n.bindingType)&&Jr(n.node).forEach(e=>{e.unmount()}),no(n),qn(n)}}unmount(){{const e=Fr(this);null!==e&&(e.isRowSession?e.disposeBindings(ui(this)):e.dispose())}for(const e of this._childNodeArray)null!==e.parentNode&&(us(e),e.parentNode.removeChild(e));const e=ui(this);for(let t=0;t<e.length;t++){const n=e[t];ea.has(n.bindingType)&&Jr(n.node).forEach(e=>{e.unmount()}),no(n),qn(n)}this._mounted=!1}}function na(t){let n=t.topLevelStructural;return void 0===n&&(n=t.topLevelStructural=function(t){const n=new RegExp(`^@@(?:${e.commentForPrefix}|${e.commentIfPrefix}|${e.commentElseIfPrefix}|${e.commentElsePrefix}):`);for(let e=t.firstChild;null!==e;e=e.nextSibling)if(e.nodeType===Node.COMMENT_NODE&&n.test(e.data))return!0;return!1}(t.fragment)),n}function oa(e){return 1<<Math.min(e,31)}const sa=-1;function ia(e){let t=e.indexBits;if(void 0===t){t=0;for(const n of e.nodeInfos)for(const e of n.parseBindTextResults)e.statePathName in E&&(t|=oa(E[e.statePathName])),"string"==typeof e.uuid&&(t|=ia(Rl(e.uuid)));e.indexBits=t}return t}function ra(e){return ia(Rl(e.uuid))}function aa(e,t){return e.statePathName in E||ea.has(e.bindingType)&&0!==(ra(e)&t)}function la(e,t){const n=document.createDocumentFragment(),o=new ta(n,t);return o._childNodeArray=e,o._firstNode=e.length>0?e[0]:null,o._lastNode=e.length>0?e[e.length-1]:null,o._mounted=!0,o}function da(e,t,n){const o=document.importNode(t.fragment,!0),s=t.nodeInfos,i=new Array(s.length);for(let e=0;e<s.length;e++){const t=Te(o,s[e].nodePath);null===t&&_(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),qe(t),me(t),i[e]=t}const r=n.slots,a=new Array(r.length),l=[];for(let e=0;e<r.length;e++){const t=r[e],n=i[t.nodeIndex],o={...t.template,node:n,replaceNode:n};a[e]=o,t.isIndexBinding&&l.push(o)}const d=function(e,t,n){let o=ul.get(n);void 0!==o&&o.currentRowPlan===e||(o=new ni,ul.set(n,o));return o.initializeRow(e,t),o}(n,a,e.node),c=new ta(o);return jr(c,d),fi(c,a),function(e,t){zr.set(e,t)}(c,n),yi(c,l),gi(c,i),Yr(e.node,c),c}function ca(t){void 0!==t.uuid&&null!==t.uuid||_("BindingInfo.uuid is null.");const n=Rl(t.uuid);n||_(`Fragment with UUID "${t.uuid}" not found.`);const s=!o()&&na(n);let i=n.rowPlan;if((void 0===i||null!==i&&i.directional!==e.enableDirectionalInitialSync)&&(i=n.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],i=Te(t.fragment,n.nodePath);if(null===i)return null;for(const t of n.parseBindTextResults){const n=t.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=t.propSegments[0];if(s===w||s===f)return null;if("text"===n){if(i.nodeType!==Node.TEXT_NODE)return null}else if(null!==we(i))return null;if("prop"===n&&Lo(i,t.propName))return null;const r=Ce(t);let a;try{a=Ts({...r,node:i,replaceNode:i})}catch{return null}if(a.observable||"auto"===a.authority)return null;o.push({nodeIndex:e,template:r,isEvent:"event"===n,isIndexBinding:t.statePathName in E,policy:a,authority:a.authority})}}return 0===o.length?null:{directional:n,slots:o}}(n)),null!==i)return da(t,n,i);const r=document.importNode(n.fragment,!0),a=function(e,t){const[n,o,s]=function(e,t){const n=[],o=[],s=[];for(const i of t){const t=Te(e,i.nodePath);if(null===t&&_(`Node not found by path [${i.nodePath.join(", ")}] in fragment.`),De.has(t))continue;const r=Fe(t,i.parseBindTextResults,{allowDeferred:!0});null!==r.deferred&&(s.push(r.deferred),De.add(t)),o.push(...r.bindings),n.push(t)}return[n,o,s]}(e,t),i=new ni,r=i.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:i,spreads:s}}(r,n.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(r,t.uuid);const l=new ta(r,s);a.spreads.length>0&&(l.spreads=a.spreads),jr(l,a.bindingSession),fi(l,a.bindingInfos);const d="for"===t.bindingType?(c=t.statePathInfo.wildcardCount+1,2**Math.min(c,32)-1):-1;var c;const u=[];for(const e of a.bindingInfos)aa(e,d)&&u.push(e);return yi(l,u),gi(l,a.nodes),Yr(t.node,l),l}const ua=new WeakSet,fa=Symbol.for("wcstack.state.view-transition-naming");function pa(){const e=Ai("state");return null===e||"auto"!==e.naming?null:{limit:e.namingLimit}}function ha(e,t,n){const o=function(e){const t=e.firstNode;if(null===t)return null;const n=e.lastNode;for(let e=t;null!==e;e=e.nextSibling){if(e.nodeType===Node.ELEMENT_NODE)return e;if(e===n)break}return null}(e);if(null===o||ua.has(o))return;const s=o.style;if(void 0===s)return;const i=function(){const e=globalThis;return e[fa]??={counter:0,assigned:0,warned:!1}}();i.assigned>=n.limit?i.warned||(i.warned=!0,console.warn(`[@wcstack/state] auto view-transition-name limit (${n.limit}) reached; further elements are left unnamed. Raise naming-limit on <wcs-view-transition>, or switch to naming="manual" and name only what should morph.`)):(ua.add(o),i.assigned+=1,i.counter+=1,s.setProperty("view-transition-name",`wcs-${t}-${i.counter}`),s.setProperty("view-transition-class",`wcs-${t}`))}const ga=new WeakMap,ma=new WeakMap,ba=new WeakMap,wa=new WeakMap,ya=new WeakMap,va=new WeakMap;function Na(e,t,n,o){let s=va.get(e);void 0===s&&(s=[document.createComment(""),document.createComment("")],va.set(e,s));const[i,r]=s;i.data=`@@wcs-for-start:${o}`,r.data=`@@wcs-for-end:${o}`,e.mounted||(i.remove(),r.remove());const a=null===n?null:n.nextSibling;if(null===i.parentNode)t.insertBefore(i,a),t.insertBefore(r,a),e.mountAfter(i);else if(a!==i){let e=i;for(;e!==r;){const n=e.nextSibling;t.insertBefore(e,a),e=n}t.insertBefore(r,a)}return r}function xa(e,t,n){!function(e,t,n){let o=ma.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,ma.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Ia(e,t){ga.set(e,t)}function Sa(e,t){ya.set(e,Ht(t))}function ka(e){return e.nodeType===Node.ELEMENT_NODE||(e.nodeType===Node.TEXT_NODE?""!==(e.textContent?.trim()??""):e.nodeType===Node.COMMENT_NODE&&e.data.startsWith("@@wcs-"))}function Aa(e,t){if(null===t)return!1;if(e.nextSibling===t)return!0;const n=e.compareDocumentPosition(t);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}const $a=new Set(["if","elseif","else","for"]);function Ma(e,t){for(const n of ui(e))if(t.appliedBindingSet.delete(n),$a.has(n.bindingType))for(const e of Jr(n.node))Ma(e,t)}function Pa(e,t,n){for(const o of wi(e))if($a.has(o.bindingType)){if(o.statePathName in E&&rl(o,t),0!==(ra(o)&n))for(const e of Jr(o.node))e.mounted&&Pa(e,t,n)}else rl(o,t)}function Ta(e){for(const t of ui(e)){if(!$a.has(t.bindingType))continue;const e="for"===t.bindingType;for(const n of Jr(t.node))Ta(n),e&&n.mounted&&(Gr(n),n.unmount(),Zr(t.node,n),ya.delete(t.node),ma.delete(t.node))}}function Ea(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function Ca(t,n,i){const r=Boolean(i);let a;const l=Jr(t.node);a=0===l.size?ca(t):l.values().next().value;const d=o(),c=t.uuid??"",u=t.bindingType;if(r||(e.debug&&console.log(`unmount if content : ${Ea(t)}`),d&&a.mounted&&(s.seen=!0),Gr(a),a.unmount()),r){e.debug&&console.log(`mount if content : ${Ea(t)}`);const o=Xe(t.node);if(mi(a,o),d){if(!a.mounted){const e=document.createComment(`@@wcs-${u}-start:${c}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),a.mountAfter(e);const n=document.createComment(`@@wcs-${u}-end:${c}:${t.statePathName}`),o=a.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}}else a.mountAfter(t.node);Ur(a,o,n);const s=pa();null!==s&&ha(a,"branch",s)}}const _a=new WeakMap;function Wa(e){return _a.get(e)??[]}function Ra(){return Array.from(La)}const La=new Set;function Oa(){La.clear()}const Ba=Symbol.for("wcstack.trustedTypes.policy");function Da(){const e=globalThis[Ba];return null===e||"object"!=typeof e?null:e}function Fa(e){globalThis[Ba]=e}let ja;let za=!1;function qa(e,t){if(za)return;if(!function(){if(void 0!==ja)return ja;if(!("trustedTypes"in globalThis))return ja=!1,ja;try{document.createElement("div").innerHTML="<i></i>",ja=!1}catch{ja=!0}return ja}())return;za=!0;const n="function"==typeof Da()?.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 "${t}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${n}\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:e,property:t})}const Va={value(e,t){"TEXTAREA"===e.tagName?e.textContent=String(t??""):e.setAttribute("value",String(t??""))},checked(e,t){t?e.setAttribute("checked",""):e.removeAttribute("checked")},selected(e,t){t?e.setAttribute("selected",""):e.removeAttribute("selected")},disabled(e,t){t?e.setAttribute("disabled",""):e.removeAttribute("disabled")},selectedIndex(e,t){const n=e.querySelectorAll("option"),o=Number(t);for(let e=0;e<n.length;e++)e===o?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function Ha(t,n,s){if(1===t.propSegments.length){const e=t.propSegments[0];"textContent"===e||"innerText"===e?s=null==s?"":String(s):void 0===s&&"innerHTML"===e&&(s="")}if(void 0===s)return void(e.debug&&console.debug("Skipped property write: state value is undefined.",{element:t.node,propSegments:t.propSegments,statePathName:t.statePathName}));const i=t.node,r=t.propSegments;if(1===r.length){const d=r[0],c=i[d];if(c!==s){null!==ii&&null!==c&&"object"==typeof c&&null!==s&&"object"==typeof s&&null!==we(i)&&ii.rememberOverwrittenObject(i,d,c);const o="innerHTML"===(l=d)||"outerHTML"===l||"srcdoc"===l,r=()=>{let t=!1;try{i[d]=o?function(e){if("string"!=typeof e)return e;const t=Da(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(s):s,t=!0}catch(t){o&&qa(i,d),e.debug&&console.warn(`Failed to set property '${d}' on element.`,{element:i,newValue:s,error:t})}if(t){const t=function(e,t){const n=we(e);if(null===n)return null;const o=ve(e)?.get(n);if(void 0===o)return null;const s=xe(e)?.declaredInputs.get(t);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(i,d);if(null!==t)try{!function(e,t,n){if(null==n)return void e.removeAttribute(t);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);e.setAttribute(t,o)}(i,t,s)}catch(n){e.debug&&console.warn(`Failed to mirror attribute '${t}' on element.`,{element:i,newValue:s,error:n})}}};if(e.enablePropagationContext&&Lo(i,d)){const e=jo(i,d,t.statePathName),o=zo(e,"to-element"),a=n?.propagationContextByBinding?.get(t)??Go()??Vo(e);if(a.visitedEdges.has(o))null!==N&&N({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:o,node:i,member:d});else{const t=Ho(a,o);Xo(t,()=>function(e,t,n,o,s,i){const r={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Do++,writtenValue:n};Ko.push({receipt:r,node:e});try{return i()}finally{Ko.pop()}}(i,d,s,e,t.transactionId,r))}}else r()}if(o()){const e=Va[d];e?e(i,s):(!function(e,t,n){let o=_a.get(e);o||(o=[],_a.set(e,o));const s=o.find(e=>e.propName===t);s?s.value=n:o.push({propName:t,value:n})}(i,d,s),a=i,La.add(a))}return}var a,l;const d=r[0];let c=i[d];for(let e=1;e<r.length-1;e++){const t=r[e];if(null==c)return;c=c[t]}const u=r[r.length-1],f=c[u];if(f!==s){if(Object.isFrozen(c))return void(e.debug&&console.warn("Attempting to set property on frozen object.",{element:i,propSegments:r,oldValue:f,newValue:s}));null!==ii&&2===r.length&&"object"==typeof c&&null!==c&&null!==we(i)&&(u in c?ii.rememberOverwrittenValue(i,d,u,c[u]):ii.recordInjectedKey(i,d,u));try{c[u]=s}catch(t){e.debug&&console.warn("Failed to set property on sub-object.",{element:i,propSegments:r,oldValue:f,newValue:s,error:t})}}}const Ua=new WeakSet;function Ga(e,t,n){}function Xa(e,t){const n=to(t);if(n.pathInfo.path in E){const e=Xe(t.node);return null===e&&_(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&_("ListIndex not found for loopContext:");const n=E[t];void 0===n&&_(`Invalid index name: ${t}`);const o=Ln(e.listIndex,n,e.pathInfo.wildcardCount);return null===o&&_(C(`"${t}"`,n+1,e.pathInfo.wildcardCount)),o.index}(e,n.pathInfo.path)}return e[mn](n)}const Ka=new WeakSet;function Qa(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const Ya=Object.freeze({[g]:function(e,t,n){const o=e.node,s=e.propSegments[1];null!=n?("boolean"!=typeof n&&_(`Invalid value for class application: expected boolean, got ${typeof n}. Write "|truthy" if you mean to coerce.`),o.classList.toggle(s,n)):o.classList.toggle(s,!1)},[m]:function(e,t,n){const o=e.node,s=e.propSegments[1];if(null==n)return void(o.hasAttribute(s)&&o.removeAttribute(s));const i=String(n);o.getAttribute(s)!==i&&o.setAttribute(s,i)},[b]:function(e,t,n){const o=e.propSegments[1],s=e.node.style;null==n&&(n=""),s[o]!==n&&(s[o]=n)},[w]:function(e,t,n){No(n)||_("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=di.get(e);if(s&&s.token===o)return;const i=e.node,r=e.propSegments[1];"string"==typeof r&&0!==r.length||_('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=we(e);if(null===t)return null;const n=ve(e)?.get(t);return void 0===n&&_(`Custom element <${t}> is not defined for command binding.`),xe(e)}(i);null===a&&_(`command binding requires a wc-bindable custom element. <${i.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(r)||_(`Command "${r}" is not declared in wcBindable.commands of <${i.tagName.toLowerCase()}>.${R(r,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),di.delete(e));const l=new WeakRef(i);let d=null;d=o.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return d?.(),void di.delete(e);const o=n[r];return"function"!=typeof o&&_(`Method "${r}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),di.set(e,{token:o,unsubscribe:d,elementRef:l})}}),Ja={text:function(e,t,n){const s=null==n?"":String(n);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),o()&&!Ua.has(e.replaceNode)){Ua.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(o,e.replaceNode),t.insertBefore(s,e.replaceNode.nextSibling)}}},for:function(e,t,n){const i=e.statePathInfo,r=Dn(e),a=zn(e),l=en(a),c=ya.get(e.node);let u,f;const p=void 0!==c&&function(e,t){const n=Jt.get(e);return void 0!==n&&(n===t||Bt(t)===Bt(n))}(a,n),h=p||void 0===c||c.value===l?null:Rr(r,l,n);p?(u=c.value,f=Or(Bt(u),Bt(n))):null!==h&&h.newIndexes.every(e=>e.parentListIndex===r||vt(e.parentListIndex)||!At(n,e.parentListIndex))?(u=c.value,f=Or(Bt(u)??[],h.newIndexes)):(u=l.length>0&&!ma.has(e.node)?[]:l,f=Rr(r,u,n));const g=Array.isArray(n)?n:[];t.newListValueByAbsAddress.set(a,g),ya.set(e.node,Ht(g));let m=ma.get(e.node);const b=void 0!==m?function(e,t,n){if(!wt(t))return null;let o=null;for(let t=0;t<n.newIndexes.length;t++){const s=n.newIndexes[t],i=n.oldIndexes[t],r=n.addIndexSet.has(s)&&n.deleteIndexSet.has(i)?e.get(i):void 0;void 0!==r&&(o??={byAddedIndex:new Map,reused:new Set},o.byAddedIndex.set(s,r),o.reused.add(r))}return o}(m,u,f):null,w=Array.isArray(u)&&u.length===f.deleteIndexSet.size&&f.deleteIndexSet.size>0;if(w&&null===b&&null!==e.node.parentNode){let t=wa.get(e.node);if(void 0===t){const n=ga.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(ka(n)){s=!1;break}n=n.previousSibling}for(;null!==o;){if(ka(o)){s=!1;break}o=o.nextSibling}return s}(e.node,n.parentNode===e.node.parentNode?n:e.node),wa.set(e.node,t)}if(t){const t=e.node.parentNode;!function(e,t){ps.set(e,(ps.get(e)??0)+t)}(t,t.childNodes.length),t.textContent="",t.appendChild(e.node)}}let y=w?1e3-function(e){return ba.get(e.node)||[]}(e).length:Number.POSITIVE_INFINITY;const v=o();if(void 0!==m){const t=m;f.deleteIndexSet.forEach(n=>{const o=t.get(n);void 0!==o&&(v&&(va.get(o)?.forEach(e=>e.remove()),s.seen=!0),null!==b&&b.reused.has(o)?(Gr(o),Ta(o),o.unmountInPlace()):y<=0&&o.tryDestroy()?Zr(e.node,o):(Gr(o),o.unmount(),function(e,t){let n=ba.get(e.node);void 0===n&&(n=[],ba.set(e.node,n)),n.length<1e3?n.push(t):Zr(e.node,t)}(e,o),y-=1),w||t.delete(n))}),w&&(ma.delete(e.node),m=void 0)}let N=e.node;const I=d(i.path+"."+x),S=t.stateElement.loopContextStack,k=Br(f);let A=null;f.newIndexes.length==f.addIndexSet.size&&f.newIndexes.length>0&&N.isConnected&&null===b&&(A=document.createDocumentFragment(),Cn(A,t.rootNode));const $=v?`${e.uuid}:${i.path}:`:"",M=pa(),P=ba.get(e.node);for(const n of f.newIndexes){let o;if(f.addIndexSet.has(n)){const s=Zn(I,n);if(S.createLoopContext(s,s=>{o=b?.byAddedIndex.get(n)??(void 0!==P?P.pop():void 0),void 0===o?o=ca(e):(Ma(o,t),mi(o,s)),v?N=null!==A?Na(o,A,null,$+n.index):Na(o,N.parentNode,N,$+n.index):null!==A?o.appendTo(A):N.nextSibling!==o.firstNode&&o.mountAfter(N),Ur(o,s,t),null!==M&&ha(o,"row",M)}),void 0===o&&_(`Content not found for ListIndex: ${n.index} at path "${i.path}"`),null!==b&&b.reused.has(o)){const e=t.stateElement.addressHooks;if(e){const n=e.rowReused;for(let e=0;e<n.length;e++)n[e](t.stateElement,o)}}}else{o=void 0!==m?m.get(n)??null:null,f.changeIndexSet.has(n)&&Pa(o,t,oa(i.wildcardCount)),null===o&&_(`Content not found for ListIndex: ${n.index} at path "${i.path}"`);const e=!o.mounted;if(v?N=Na(o,N.parentNode,N,$+n.index):null!==k&&k.has(n)&&Aa(N,o.firstNode)||N.nextSibling===o.firstNode||o.mountAfter(N),e){const e=o,s=Zn(I,n);S.createLoopContext(s,n=>{Ur(e,n,t)})}}v||(N=o.lastNode||N),void 0===m&&(m=new WeakMap,ma.set(e.node,m)),m.set(n,o)}ga.set(e.node,N),null!==A&&(e.node.parentNode.insertBefore(A,e.node.nextSibling),Cn(A,null))},if:Ca,else:Ca,elseif:Ca,radio:function(e,t,n){const o=e.node,s=ai(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=ai(o.value,e.inFilters),i=Array.isArray(n)?n:li;o.checked=i.includes(s)}},Za=new WeakMap,el=new WeakMap,tl=new WeakMap;function nl(){}function ol(e){const t=ii;if(null!==t){const n=e.replaceNode,o=e.propSegments[0];if(t.isComplete(n,o))return Ga;if(t.isDeclared(n,o))return nl}return Ha}function sl(e,t){il(e,t,Xa(t.state,e))}function il(e,t,n){const o=ai(n,e.outFilters);if(!0===el.get(e))return void t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement});let s=Za.get(e);if(void 0===s){if(Za.has(e))return s=ol(e),s===Ga&&Za.set(e,s),void s(e,t,o);if(s=Ja[e.bindingType],void 0===s){const t=e.propSegments[0];if(s=Ya[t],Za.set(e,s),void 0===s){we(e.replaceNode)?(s=ol(e),s===Ga&&Za.set(e,s)):(s=Ha,Za.set(e,s))}}if(s===Ha){if("SELECT"===e.node.tagName){const n=e.propSegments[0];if("value"===n||"selectedIndex"===n)return t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement}),void el.set(e,!0)}}s(e,t,o)}else s(e,t,o)}function rl(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=zn(e);if(t.updatedAbsAddressSetByStateElement.has(t.stateElement)){t.updatedAbsAddressSetByStateElement.get(t.stateElement).add(n)}else t.updatedAbsAddressSetByStateElement.set(t.stateElement,new Set([n]))}const n=si(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==tl.get(e)){const t=we(e.replaceNode);if(t&&(void 0===ve(e.replaceNode)?.get(t)||function(e){return"waiting-definition"===Ds.get(e)?.phase}(e)))return void function(e,t){if(Ka.has(e))return;Ka.add(e);const n=()=>{Ka.delete(e);const t=si(e);(null===t||t.shouldApplyState(e))&&ll([e])},o=n=>{Ka.delete(e),Qa(t,n)},s=si(e);if(null!==s){const i=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{Ka.delete(e),i()})||(Ka.delete(e),i()))}const i=ve(e.replaceNode);if(null===i)return Ka.delete(e),void Qa(t,new Error("CustomElementRegistry is unavailable."));Is(i).wait(t,()=>{e.replaceNode.isConnected?n():Ka.delete(e)},o)}(e,t);tl.set(e,!0)}if(!0===t.sameRootVerified)return void sl(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=_n(o),null===o&&_("Root node for fragment not found for binding.")),o!==t.rootNode){const n=kl(o);null===n&&_("No state tree found on this root for binding."),n.createState("readonly",s=>{const i={rootNode:o,stateElement:n,state:s,appliedBindingSet:t.appliedBindingSet,newListValueByAbsAddress:t.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:t.updatedAbsAddressSetByStateElement,deferredSelectBindings:t.deferredSelectBindings};sl(e,i)})}else sl(e,t)}function al(e,t,n,o){if(null!==n&&!0===n.hasErrorCallback){const s={path:e.statePathName,bindingType:e.bindingType,node:e.node},i=o.get(n);void 0===i?o.set(n,[{error:t,info:s}]):i.push({error:t,info:s})}else console.error(`[@wcstack/state] binding "${e.bindingType}: ${e.statePathName}" failed to apply; the rest of this batch continues.`,{node:e.node,error:t});null!==N&&N({type:"state:binding-apply-error",path:e.statePathName,bindingType:e.bindingType,error:t})}function ll(t,n,o){let s=0;const i=new Set,r=new Map,a=new Map,l=[],d=new Map;for(;s<t.length;){let o=t[s];if(!1===o.replaceNode.isConnected){e.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${o.bindingType} ${o.statePathName} on ${o.node.nodeName}`,o),s++;continue}let c=o.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=_n(c),null===c&&_("Root node for fragment not found for binding."));const u=kl(c);null===u&&_("No state tree found on this root for binding."),u.createState("readonly",e=>{const f={rootNode:c,stateElement:u,state:e,appliedBindingSet:i,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:a,deferredSelectBindings:l,sameRootVerified:!0,propagationContextByBinding:n};for(;;){try{rl(o,f)}catch(e){al(o,e,u,d)}s++;const e=t[s];if(!e)break;if(e.replaceNode.getRootNode()!==f.rootNode)break;o=e}})}for(const{binding:e,value:t,stateElement:o}of l)try{Ha(e,{propagationContextByBinding:n},t)}catch(t){al(e,t,o??null,d)}for(const[e,t]of r.entries())tn(e,t),un(e,t);if(!1!==o?.updatedCallback)for(const[e,t]of a.entries())e.createState("writable",e=>{e[vn](Array.from(t))});for(const[e,t]of d.entries())e.createState("writable",e=>{for(const{error:n,info:o}of t)try{e[Nn](n,o)}catch(e){console.error(`[@wcstack/state] $errorCallback threw while handling the failure of binding "${o.bindingType}: ${o.path}".`,{error:e,original:n,node:o.node})}})}function dl(e,t,n,o,s){for(const i of e)i.cancel?.(),i.cancel=n.deferUntilDefined(i.node,i.tagName,()=>{const r=Ve(i);if(o&&(e.splice(e.indexOf(i),1),o.push(...r),s.push(...r.filter(e=>e.statePathName in E))),0===r.length)return;Ke(i.node,t);ll(n.initialize(r,o&&{registerPathInfo:!1,applyOnReconnect:!1}))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${i.tagName}>.`,e)})}function cl(e,t,n,o=Be(e),s=oi(e)){const[i,r,a]=ze(function(e){return e.filter(e=>!De.has(e))}(o),n);for(const e of i)Ke(e,t);ll(s.initialize(r)),dl(a,t,s)}const ul=new WeakMap;async function fl(t){const n=t.querySelectorAll(e.tagNames.state),o=[],s=ve(t);null===s&&_(`CustomElementRegistry is unavailable for <${e.tagNames.state}>.`),await s.whenDefined(e.tagNames.state);for(const e of n){if(Re(e))continue;const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function pl(t){if(t===document)await fl(document),z(document),td(document,document),cl(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await ge(n.host),await fl(n),z(n),td(n,n),cl(n,null)}}const hl={watch:"temporal",scan:"temporal",streams:"temporal",scopes:"scopes",dcc:"scopes",recursion:"recursion",ssr:"ssr",devtools:"devtools"};function gl(e,t){return`[wcs/feature-not-installed] ${t} needs the "${e}" feature: install it with installFeatures([...]) from "@wcstack/state/features/${hl[e]??e}" before the state is defined.`}let ml=null;function bl(e){ml=e}function wl(e){return null===ml&&_(gl("ssr",e)),ml}const yl=new WeakMap,vl=new WeakMap,Nl=new Set,xl=[];function Il(e){xl.includes(e)||xl.push(e)}function Sl(){return Nl}function kl(e){return yl.get(e)??null}function Al(e){return vl.get(e)??Promise.resolve()}function $l(e,t){const n=Promise.reject(t);n.catch(()=>{}),vl.set(e,n)}const Ml=new WeakSet;function Pl(e,t){const n=yl.get(e);if(void 0!==n){if(n===t)return;_("A state tree is already registered on this root.")}yl.set(e,t)}function Tl(e,t){vl.set(e,t),t.then(()=>El(e),()=>{})}function El(e){Ml.add(e)}function Cl(t,n){const s=yl.get(t);if(null===n){if(void 0===s)return;yl.delete(t),Nl.delete(s),null!==N&&N({type:"state:element-unregistered",rootNode:t,element:s}),e.debug&&console.debug("State element unregistered")}else{if(s===n)return;if(void 0===s){const e=!o()&&n.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const n=new Promise((n,o)=>{queueMicrotask(async()=>{try{if(e){await wl('the "enable-ssr" attribute').hydrate(t)||await pl(t)}else await pl(t);El(t),ad(),n()}catch(e){o(e)}})});vl.set(t,n)}else if("ShadowRoot"===t.constructor.name){const e=new Promise((e,n)=>{queueMicrotask(async()=>{try{await pl(t),El(t),ad(),e()}catch(e){n(e)}})});vl.set(t,e)}}void 0!==s&&_('A state tree is already registered on this root — one <wcs-state> per root in v2. This second element stays unregistered: it keeps the state it loaded and its declarations stay live, but nothing binds to it and disconnecting it runs no cleanup — remove it. Mount additional states onto the tree instead: <wcs-state mount="...">.'),yl.set(t,n),Nl.add(n);for(let e=0;e<xl.length;e++)xl[e](t,n);null!==N&&N({type:"state:element-registered",rootNode:t,element:n}),e.debug&&console.debug("State element registered",n)}}const _l=new Map;function Wl(e,t,n){if(null===n)_l.delete(e);else{_l.set(e,n);const o=kl(t);null===o&&_("No state tree found on this root for fragment info.");const s=n.parseBindTextResult;o.setPathInfo(s.statePathName,s.bindingType);for(const e of n.nodeInfos)for(const t of e.parseBindTextResults)o.setPathInfo(t.statePathName,t.bindingType)}}function Rl(e){return _l.get(e)||null}function Ll(){_l.clear()}function Ol(t){if(t.nodeType===Node.ELEMENT_NODE){const n=t,o=re(n.getAttribute(e.bindAttributeName)||"");if(n.localName===e.tagNames.state){if(n.hasAttribute("mount"))return o.filter(e=>e.propSegments[0]!==y);const t=o.find(e=>e.propSegments[0]===y);if(void 0!==t){const n=`on a volume element — a <${e.tagNames.state}> with a "mount" attribute`;_(1===t.propSegments.length?`[wcs/mount-path-invalid] "${t.propName}" is the reserved namespace for volume injection, so it cannot be bound as an element property. Write one key at a time ("${y}.<key>: <path>") ${n}.`:`[wcs/mount-path-invalid] "${t.propName}: ${t.statePathName}" is a volume injection declaration, and it can only be written ${n}. Add mount="<path>", or bind an element property instead.`)}}return o}if(t.nodeType===Node.COMMENT_NODE){const e=ce(t);null===e&&_("Comment node binding text not found.");const n=Rl(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=ue(e),s=null):s=e,[{...o,uuid:s}]}return[]}let Bl;function Dl(){return Bl??={filterName:"not",args:[]}}const Fl=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function jl(e,t){const n=t+l+x,o=Y(e,"|");let s,i;if(-1!==o?(s=e.slice(0,o).trim(),i=e.slice(o)):(s=e.trim(),i=""),"."===s)s=n;else{if(!s.startsWith("."))return e;s=n+l+s.slice(1)}return i.length>0?s+i:s}function zl(e,t){const n=Fl.exec(e);if(null===n)return e;const o=n[1],s=n[2],i=n[3];return o+jl(s,t)+i}function ql(e,t){const n=J(e,";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=Y(n,":");if(-1===s)return e;const i=n.slice(0,s).trim(),r=n.slice(s+1).trim(),a=jl(r,t);return a!==r?(o=!0,`${i}: ${a}`):e});return o?s.join(";"):e}function Vl(e,t){return ql(e,t)}function Hl(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const t=e;t.data=zl(t.data,n);continue}const t=e;if(t instanceof HTMLTemplateElement)continue;const i=t.getAttribute(o);if(null!==i){const e=ql(i,n);e!==i&&t.setAttribute(o,e)}}}function Ul(e){let t=e;const n=[];for(;null!==t.parentNode;){const e=Array.from(t.parentNode.childNodes).indexOf(t);n.unshift(e),t=t.parentNode}return n}const Gl=new WeakMap;function Xl(e){return Gl.get(e)??null}function Kl(e){const t=[],n=Be(e);for(const e of n){const n=Ol(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");Gl.set(t,e.data),e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:Ul(o),parseBindTextResults:n})}return t}function Ql(e){const t=Array.from(e.childNodes);for(const n of t)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&e.removeChild(n)}}const Yl=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),Jl=Dl();function Zl(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Jl],bindingType:e}}function ed(e,t,n,o,s,i=!0){Ql(t),"string"==typeof o&&Hl(t,o),td(e,t,o,s);const r={fragment:t,parseBindTextResult:void 0!==s&&i?s(n,o):n,nodeInfos:Kl(t)};return void 0!==s&&function(e,t,n){for(const o of e)for(let e=0;e<o.parseBindTextResults.length;e++){const s=o.parseBindTextResults[e];null==s.uuid&&(o.parseBindTextResults[e]=t(s,n))}}(r.nodeInfos,s,o),r}function td(t,n,o,s){const i=e.commentElsePrefix,r=Le(n),a=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const n=t;if(r.length>0&&-1!==r.indexOf(n))return NodeFilter.FILTER_REJECT;if("template"===n.tagName.toLowerCase()){if((n.getAttribute(e.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let l=null;const d=[],c=[];for(;a.nextNode();){const e=a.currentNode;c.push(e)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=Vl(r,o));let a=re(r)[0];const c=Yl.get(a.bindingType);if(void 0===c)continue;const u=a.bindingType,f=n.content,p=Ye();let h=null;const g="for"===u?a.statePathName:o;if("else"===u){null===l&&_("'else' binding found without preceding 'if' or 'elseif' binding."),a=Zl("else",l.parseBindTextResult),h=ed(t,f,a,g,s,!1),Wl(p,t,h);const e=d.at(-1),o=document.createComment(`@@${c}:${p}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:Ul(o),parseBindTextResults:Ol(o)})):n.replaceWith(o)}else if("elseif"===u){null===l&&_("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=ed(t,f,a,g,s),Wl(p,t,h);const e=document.createComment(`@@${c}:${p}`),o=Ye(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Zl("else",l.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:Ul(e),parseBindTextResults:Ol(e)}),Wl(o,t,r);const u=d.at(-1);d.push(r);const m=document.createComment(`@@${i}:${o}`);void 0!==u?(n.remove(),u.fragment.appendChild(m),u.nodeInfos.push({nodePath:Ul(m),parseBindTextResults:Ol(m)})):n.replaceWith(m)}else{h=ed(t,f,a,g,s),Wl(p,t,h);const e=document.createComment(`@@${c}:${p}`);n.replaceWith(e)}"if"===u?(d.length=0,l=h):"elseif"===u?l=h:"else"===u&&(l=null,d.length=0)}}const nd=()=>`[${e.bindAttributeName}]`;function od(t){if(Vs(t))return!0;if(!sd(t))return!1;if(t.hasAttribute(e.bindAttributeName))return!1;const n=t.querySelector(nd());return null!==n&&Vs(n)}function sd(e){return 1===e.nodeType}function id(t){if(!t.isConnected||od(t))return;const n=t.hasAttribute(e.bindAttributeName)?[t]:[];Array.from(t.children).some(t=>t.localName===e.tagNames.state&&Re(t))||(z(t),td(t.getRootNode(),t),n.push(...Be(t))),cl(t,null,void 0,n,new ni)}const rd=[];function ad(){const e=rd.splice(0,rd.length);for(const t of e)id(t);D()}const ld={protocol:"wcs-binder",version:1,bind:function(e){var t;sd(e)&&e.isConnected&&!od(e)&&(t=e.getRootNode(),Ml.has(t)?id(e):rd.push(e))}};function dd(){const e=globalThis;void 0===e[L]&&(e[L]=ld)}export{zn as $,Pl as A,Tl as B,z as C,td as D,cl as E,Vs as F,kl as G,We as H,ri as I,we as J,ge as K,re as L,Il as M,un as N,Rr as O,cn as P,Ra as Q,Wa as R,Oa as S,Ba as T,Rl as U,Xl as V,Te as W,Ll as X,fl as Y,je as Z,dl as _,Da as a,ur as a$,ai as a0,qt as a1,tn as a2,Sa as a3,ii as a4,Le as a5,Dl as a6,Ql as a7,Hl as a8,Kl as a9,Nn as aA,vn as aB,yn as aC,wn as aD,bn as aE,$i as aF,Li as aG,pn as aH,Xn as aI,fn as aJ,bo as aK,wl as aL,Cl as aM,$l as aN,gl as aO,vo as aP,xi as aQ,rt as aR,Ii as aS,Er as aT,Dt as aU,zt as aV,Gi as aW,_r as aX,Rn as aY,xt as aZ,kt as a_,Wl as aa,la as ab,jr as ac,fi as ad,gi as ae,aa as af,sa as ag,yi as ah,nt as ai,xa as aj,Ia as ak,Yr as al,mi as am,Re as an,Be as ao,ce as ap,ze as aq,ni as ar,Ee as as,qe as at,bl as au,Si as av,dr as aw,fr as ax,lr as ay,ar as az,pl as b,br as b0,mr as b1,yr as b2,st as b3,Ut as b4,Gt as b5,jt as b6,hr as b7,Wr as b8,Go as b9,Vo as ba,Lt as bb,on as bc,at as bd,gt as be,Pt as bf,Tt as bg,Jo as bh,bt as bi,en as bj,sn as bk,Pe as bl,ue as bm,cr as bn,Sl as bo,Ri as bp,Di as c,mo as d,_i as e,Wi as f,Al as g,mn as h,vt as i,Zn as j,Bt as k,Pn as l,Ln as m,ht as n,On as o,Tn as p,ve as q,dd as r,Fa as s,Ge as t,Ne as u,Xe as v,gn as w,ll as x,oi as y,Ke as z};
2
2
  //# sourceMappingURL=binder.js.map