@wcstack/state 3.3.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.ja.md +94 -27
  2. package/README.md +94 -27
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.d.ts +52 -1
  6. package/dist/index.esm.js +1 -1
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/split/chunks/binder.js +1 -1
  9. package/dist/split/chunks/binder.js.map +1 -1
  10. package/dist/split/chunks/checkDependency.js +1 -1
  11. package/dist/split/chunks/checkDependency.js.map +1 -1
  12. package/dist/split/chunks/declarationAliases.js.map +1 -1
  13. package/dist/split/chunks/diagnosticsHooks.js.map +1 -1
  14. package/dist/split/chunks/featureBridge.js +1 -1
  15. package/dist/split/chunks/filterRegistry.js +1 -1
  16. package/dist/split/chunks/filterRegistry.js.map +1 -1
  17. package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
  18. package/dist/split/chunks/lifecycleHooks.js +1 -1
  19. package/dist/split/chunks/lifecycleHooks.js.map +1 -1
  20. package/dist/split/chunks/pathDiagnostics.js +1 -1
  21. package/dist/split/chunks/pathDiagnostics.js.map +1 -1
  22. package/dist/split/chunks/registerComponents.js +1 -1
  23. package/dist/split/chunks/registerComponents.js.map +1 -1
  24. package/dist/split/chunks/setAll.js +1 -1
  25. package/dist/split/chunks/setAll.js.map +1 -1
  26. package/dist/split/chunks/version.js +1 -1
  27. package/dist/split/core.d.ts +77 -1
  28. package/dist/split/core.js +1 -1
  29. package/dist/split/features/devtools.js +1 -1
  30. package/dist/split/features/devtools.js.map +1 -1
  31. package/dist/split/features/diagnostics.js +1 -1
  32. package/dist/split/features/diagnostics.js.map +1 -1
  33. package/dist/split/features/formats.js +1 -1
  34. package/dist/split/features/formats.js.map +1 -1
  35. package/dist/split/features/recursion.js +1 -1
  36. package/dist/split/features/recursion.js.map +1 -1
  37. package/dist/split/features/scopes.js +1 -1
  38. package/dist/split/features/scopes.js.map +1 -1
  39. package/dist/split/features/ssr.js +1 -1
  40. package/dist/split/features/ssr.js.map +1 -1
  41. package/dist/split/features/temporal.js +1 -1
  42. package/dist/split/features/temporal.js.map +1 -1
  43. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import{c as e,r as t,f as n,i as o}from"./filterRegistry.js";import{O as s,P as i,Q as r,D as a,g as l,T as d,U as c,X as u,Y as f,Z as p,_ as h,$ as g,a0 as m,a1 as b,V as w,a2 as y,d as v,W as N,n as x,a3 as S,a4 as I,w as $,a5 as A,a6 as k,a7 as T,I as P,F as M}from"./pathDiagnostics.js";import{r as E,L as C,d as _}from"./errorGuidance.js";const R=Symbol.for("wcstack.binder");const O=Symbol.for("wcstack.binder.pending"),L=Symbol.for("wcstack.binder.taken");function B(){const e=function(){const e=globalThis[R];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[L];return void 0===t&&(t=new WeakSet,e[L]=t),t}();for(const t of n)o.add(t),e.bind(t)}const W=/\{\{\s*(.+?)\s*\}\}/g,D=new Set(["SCRIPT","STYLE"]);function F(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&&D.has(e.parentElement.tagName)||j(e)}(t);const n=Array.from(t.querySelectorAll("template"));for(const e of n)if(e.namespaceURI===s){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),F(t.content)}else F(e.content)}function j(e){const t=e.data;if(W.lastIndex=0,!W.test(t))return;W.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=W.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 z=new Set(["if","elseif","else","for"]);function q(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 V=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function H(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:V.test(e)?Number(e):e)}function U(e){const t=[],n=[];let o="",s=null,i=!1,r=-1,a=-1;const l=()=>{const e=q(o,r,a);t.push(e),n.push(H(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&&E(`[wcs/binding-syntax] unterminated ${s} quote in the filter arguments "(${e})". Close the quote.${C}`);const d=q(o,r,a);return(d||i)&&(t.push(d),n.push(H(d,i))),{args:t,literals:n}}const G=e=>e.trim(),K=e=>"'"===e||'"'===e;function X(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(K(s))n=s;else if(s===t)return o}return-1}function Q(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):K(r)?o=r:r===t&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}function J(e,t,n){const o=n??e.join("|");return e.map(e=>{const n=X(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):K(i)?n=i:i===t&&(o=s)}return o}(e,")");if(-1===s&&(s=e.lastIndexOf(")")),-1!==n&&-1===s&&E(`[wcs/binding-syntax] Invalid filter format: missing closing parenthesis in "${e}".${C}`),-1!==s&&-1===n&&E(`[wcs/binding-syntax] Invalid filter format: missing opening parenthesis in "${e}".${C}`),-1!==s&&s<n&&E(`[wcs/binding-syntax] Invalid filter format: ")" comes before "(" in "${e}".${C}`),-1!==s&&e.slice(s+1).trim().length>0){const t=e.slice(s+1).trim();E(`[wcs/binding-syntax] "${e}": unexpected "${t}" after the filter's closing ")" — separate filters with "|" (write "${e.slice(0,s+1)}|${t}").${C}`)}const r=(-1===n?e:e.substring(0,n)).trim();if(0===r.length&&E(`[wcs/binding-syntax] an empty filter in "${o}" — remove the extra "|" or name the filter.${C}`),r.includes(i)){const[e,n]=r.split(i);E("input"===t?`[wcs/binding-syntax] "${r}" is not a filter name: a modifier list "${i}${n}" comes before the input filters, not inside one — write "<property>${i}${n}|${e}".${C}`:`[wcs/binding-syntax] "${r}" is not a filter name: "${i}" cannot appear in one. Modifiers belong on the left side of the binding, before the ":" — write "${e}" here.${C}`)}if(-1===n)return{filterName:r,args:[],literals:[]};return{filterName:r,...U(e.substring(n+1,s))}})}const Y=new Map;function Z(e){const t=X(e,r);let n="",o=[],s="",l=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),Y.has(s)?l=Y.get(s):(o=Q(s,r).map(G),l=J(o,"input",e),Y.set(s,l))):n=e.trim();const d=n.split(i).map(G);d.length>2&&E(`[wcs/binding-syntax] "${n}": a binding takes one modifier list after a single "${i}" — write "${d[0]}${i}${d.slice(1).join(",")}".${C}`);const[c,u]=d,f=c.split(a).map(G);f.length>1&&""===f[0]||0!==c.length&&!f.some(e=>0===e.length)||E(`[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).${C}`);return{propName:c,propSegments:f,propModifiers:u?u.split(",").map(G):[],inFilters:l}}const ee=new Map;function te(e){const t=X(e,r);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=Q(s,r).map(G),i=J(o,"output",e),ee.set(s,i))):n=e.trim(),-1!==n.indexOf("@")&&E(`"${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 d=n,c=d.startsWith(a),u=c?d.slice(a.length):d;(u.length>0&&u.split(a).some(e=>0===e.length)||!c&&0===u.length)&&E(`[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).${C}`);return{statePathName:d,statePathInfo:l(d),outFilters:i}}const ne=new Set([d,"if","elseif","for",c]),oe=new Set([h,g,m,b,u,w]);function se(e){const[...t]=function(e){return Q(e,y)}(e).map(G).filter(e=>e.length>0),n=t.map(e=>{const t=X(e,p);-1===t&&E(`[wcs/binding-syntax] Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.${C}`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),s=n.split(i)[0].split(r)[0].trim();if(s!==n&&ne.has(s)&&E(`[wcs/binding-syntax] "${e}": "${s}" takes no modifiers or filters on its left side — write "${s}:".${C}`),n===d){o.length>0&&E(`[wcs/binding-syntax] "${e}": "else" takes no value — write "else:".${C}`);const t=l("#else");return{propName:d,propSegments:[d],propModifiers:[],statePathName:"#else",statePathInfo:t,inFilters:[],outFilters:[],bindingType:"else"}}if(n===c){0===o.length&&E(`[wcs/binding-syntax] Invalid spread binding "${e}": spread target path is required.${C}`);const t=te(o);return t.outFilters.length>0&&E(`[wcs/binding-syntax] Invalid spread binding "${e}": filters are not allowed on spread targets.${C}`),{propName:c,propSegments:[c],propModifiers:[],inFilters:[],...t,bindingType:"spread"}}if("if"===n||"elseif"===n||"for"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...te(o),bindingType:n}}if("radio"===s||"checkbox"===s){const e=te(o);return{...Z(n),...e,bindingType:s}}{const e=te(o),t=Z(n);if(""===t.propSegments[0]&&t.propSegments.length>1){const o=t.propSegments.slice(1);return(o.includes("")||oe.has(o[0]))&&E(`[wcs/binding-syntax] "${n}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (${[...oe].join(", ")}).${C}`),{...t,propName:o.join(a),propSegments:o,...e,bindingType:"prop"}}return t.propSegments[0]===u||t.propSegments[0].startsWith(f)?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>z.has(e.bindingType))&&E(`[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">).${C}`)}return n}const ie=new WeakMap,re=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),ae=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function le(t){const n=ie.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=ae.exec(o);if(null===s)return null;const i=s[1]||e.commentTextPrefix;return re.has(i)?(ie.set(t,s[2]),s[2]):null}function de(e){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...te(e),bindingType:"text"}}const ce=new WeakMap,ue=new WeakSet;let fe=0;async function pe(e){const t=function(e){let t,n=ce.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++fe,promise:o,resolve:t},ce.set(e,n),ue.has(e)&&n.resolve(),n}(e);await t.promise}function he(e){const t=ce.get(e);void 0===t?ue.add(e):t.resolve()}const ge=new WeakMap;function me(e){const t=ge.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{ge.set(e,n)}}function be(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined?null:t}function we(e=null){if(null!=e){const{customElementRegistry:t,customElements:n}=e;if(null===t)return null;if(void 0!==t)return be(t);if(void 0!==n)return be(n)}return be(globalThis.customElements)}function ye(e,t){e.upgrade?.(t)}function ve(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=Ie(s.properties,Ne);if(null===i)return null;const r=void 0===s.inputs?new Map:Ie(s.inputs,xe);if(null===r)return null;const a=void 0===s.commands?new Map:Ie(s.commands,Se);return null===a?null:{target:e,liveDeclaration:s,knownProperties:i,declaredInputs:r,declaredCommands:a}}catch{return null}}function Ne(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 xe(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 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.async||"boolean"==typeof t.async)}function Ie(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:l(n),inFilters:[],outFilters:[],bindingType:"prop"}}function Ae(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function ke(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&&E("Spread binding requires an element node.");const n=t,o=me(n);null===o&&E(`Spread binding "${e.statePathName}" requires a custom element with wcBindable, but <${n.tagName.toLowerCase()}> is not a custom element.`);const a=we(n);null===a&&E(`CustomElementRegistry is unavailable for <${o}>.`);if(void 0===a.get(o)){s||E(`Spread binding "${e.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),i.push(e);continue}ye(a,n);const l=ve(n);null===l&&E(`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=Ae(i[e]);null!==t&&a.set(t,e)}const l=[];for(let n=0;n<i.length;n++){const o=Ae(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 Pe(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 Me(e){return{...e,inFilters:Pe(e.inFilters,"input"),outFilters:Pe(e.outFilters,"output")}}const Ee=new WeakMap;function Ce(e){return Ee.get(e)||null}function _e(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Re(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!_e(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 Le(t){const n=[],o=Re(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!==le(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 Be=new WeakSet;function We(e,t,n,o){const s=ke(e,t,{allowDeferred:n.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?me(e):null;return null===n&&E("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t,transform:o}}}Be.add(e);const i=function(e,t){const n=[];for(const o of t){const t=Pe(o.inFilters,"input"),s=Pe(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){Ee.set(e,t)}(e,i),he(e),{bindings:i,deferred:null}}function De(e,t){const n=Le(e),o=[],s=[];for(const e of n){if(Be.has(e))continue;const n=We(e,xa(e),{allowDeferred:!0},t);null===n.deferred?o.push(...n.bindings):s.push(n.deferred)}return[n,o,s]}function Fe(e){Be.add(e)}function je(e){const{node:t,parseResults:n,transform:o}=e;!function(e){Be.delete(e)}(t);return We(t,n,{allowDeferred:!1},o).bindings}const ze=new WeakMap;let qe=null;function Ve(e){qe=e}function He(e){let t=e;for(;t;){const e=ze.get(t);if(e)return e;let n=t.parentNode;null===n&&null!==qe&&t instanceof ShadowRoot&&(n=qe(t)),t=n}return null}function Ue(e,t){null!==t?ze.set(e,t):ze.delete(e)}const Ge=new WeakMap;function Ke(e){return Ge.get(e)??[]}function Xe(e,t){Ge.set(e,t)}function Qe(e){return Ge.has(e)}const Je=new WeakMap;let Ye=null,Ze=0;function et(e){return Je.get(e)??[]}function tt(e,t){null===Ye?Je.set(e,t):Ye.set(e,t)}function nt(){Ze++,null===Ye&&(Ye=new Map)}function ot(){if(0!==Ze&&(Ze--,!(Ze>0||null===Ye))){for(const[e,t]of Ye)Je.set(e,t);Ye=null}}function st(e){return(Ye?.has(e)??!1)||Je.has(e)}const it=Symbol("$$setLoopContext"),rt=Symbol("$$getByAddress"),at=Symbol("$$hasByAddress"),lt=Symbol("$$connectedCallback"),dt=Symbol("$$disconnectedCallback"),ct=Symbol("$$updatedCallback"),ut=Symbol("$$errorCallback"),ft=new WeakMap,pt=new WeakMap;class ht{absolutePathInfo;listIndex;constructor(e,t){this.absolutePathInfo=e,this.listIndex=t}}function gt(e,t){if(null===t){let t=pt.get(e);return void 0!==t||(t=new ht(e,null),pt.set(e,t)),t}{let n=ft.get(t);void 0===n&&(n=new WeakMap,ft.set(t,n));let o=n.get(e);return void 0!==o||(o=new ht(e,t),n.set(e,o)),o}}const mt=new WeakMap;function bt(e,t){let n=mt.get(e);void 0===n&&(n=new Map,mt.set(e,n));let o=n.get(t);return void 0===o&&(o=Object.freeze(new wt(e,t)),n.set(t,o)),o}class wt{pathInfo;stateElement;constructor(e,t){this.pathInfo=t,this.stateElement=e}}function yt(e,t){return gt(bt(e,t.pathInfo),t.listIndex)}function vt(e,t,n){return gt(bt(e,t),n)}const Nt=new WeakMap;function xt(e,t){null===t?Nt.delete(e):Nt.set(e,t)}function St(e){return Nt.get(e)||null}const It=new Map;function $t(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=It.get(s);if(void 0!==i)return i;return i=n.wildcardPathSet.intersection(o.wildcardPathSet).size,It.set(s,i),i}function At(e,t,n){return t<0||t>=n?null:e.at(t-n)}function kt(e,t){const n=e.indexes??[];return n.length===t?n:n.slice(n.length-t)}const Tt=new WeakMap;function Pt(e){const t=He(e.node);if(null===t)return null;let n=Tt.get(t);if(void 0===n)n=new WeakMap,Tt.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=$t(t.pathInfo,e.statePathInfo);return n>0&&(o=At(t.listIndex,n-1,t.pathInfo.wildcardCount)),o}finally{n.set(e,o)}}const Mt=new WeakMap;function Et(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=St(n);null===t?E(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function Ct(e,t){let n=null;if(n=Mt.get(e)||null,null!==n)return n;const o=Et(e,t),s=Pt(e),i=ca(o);return null===i&&E("No state tree found on this root for binding."),n=vt(i,e.statePathInfo,s),Mt.set(e,n),n}function _t(e){Mt.delete(e)}const Rt=new WeakMap;function Ot(e,t){const n=Rt.get(e);void 0===n?Rt.set(e,t):n instanceof Set?n.add(t):n!==t&&Rt.set(e,new Set([n,t])),null!==v&&v({type:"state:binding-added",absoluteAddress:e,binding:t})}function Lt(e,t){const n=Rt.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&Rt.delete(e),null!==v&&v({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const Bt=new WeakMap;function Wt(e){const t=Rt.get(e);return void 0!==t?t:null!==e.listIndex?Bt.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const Dt=new WeakMap,Ft=new WeakMap;class jt{pathInfo;listIndex;_parentAddress;constructor(e,t){this.pathInfo=e,this.listIndex=t}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const e=this.pathInfo.parentPathInfo;if(null===e)return null;let t=null;return t=this.pathInfo.segments[this.pathInfo.segments.length-1]===N?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=zt(e,t)}}function zt(e,t){if(null===t){let t=Ft.get(e);return void 0!==t||(t=new jt(e,null),Ft.set(e,t)),t}{let n=Dt.get(t);void 0===n&&(n=new WeakMap,Dt.set(t,n));let o=n.get(e);return void 0!==o||(o=new jt(e,t),n.set(e,o)),o}}const qt=new WeakMap;function Vt(e){let t=null;if(t=qt.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=Pt(e);null===n&&E(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=zt(e.statePathInfo,n)}else t=zt(e.statePathInfo,null);return qt.set(e,t),t}function Ht(e){qt.delete(e)}function Ut(){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 Gt=new Map,Kt=Ut();function Xt(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function Qt(e){let t="input";for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}function Jt(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(x)){const o=Qt(e),s=Xt(e,o);let i=Gt.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=ca(o.getRootNode());null===r&&E("No state tree found on this root for two-way binding.");const a=He(o);r.createState("writable",e=>{e[it](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]:[]})})},Gt.set(s,i)),e.node.addEventListener(o,i),Kt.add(s,e),!0}var t,n;return!1}function Yt(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function Zt(e,t){console.error(`[wcstack/state] ${t} rejected.`,e)}function en(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)Yt(e)&&Promise.resolve(e).catch(e=>Zt(e,t))}class tn{_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 nn extends tn{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==v&&v({type:"state:token-emit",kind:"event",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}const on=new WeakMap;function sn(e,t){let n=on.get(e);void 0===n&&(n=new Map,on.set(e,n));let o=n.get(t);return void 0===o&&(o=new nn(t,e),n.set(t,o)),o}function rn(e){on.delete(e)}const an=new WeakMap;function ln(e){if(e.propSegments[0]!==u)return!1;const t=e.node,n=me(t),o=we(t);if(null!==n&&void 0===o?.get(n))return null===o&&E(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(an.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||E('eventToken binding requires a property name (e.g., "eventToken.error").');const i=function(e){return null===me(e)?null:ve(e)}(t);null===i&&E(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=i.knownProperties.get(s);void 0===r&&E(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.${_(s,i.knownProperties.keys())}`);const a=r.event,l=e.statePathName,d=e.propModifiers,c=e=>{d.includes(S)&&e.preventDefault(),d.includes(I)&&e.stopPropagation();const n=ca(t.getRootNode());null===n&&E("No state tree found on this root for eventToken handler."),n.eventTokenNames.has(l)||E(`[wcs/token-undeclared] eventToken "${l}" is not declared in $eventTokens.${_(l,n.eventTokenNames)}${C}`);const o=He(t);n.createStateAsync("writable",async t=>{en(t[it](o,()=>{const s=null!==o?kt(o.listIndex,o.pathInfo.wildcardCount):[];return sn(n,l).emit(t,e,...s)}),`$on."${l}"`)})};return t.addEventListener(a,c),an.set(e,{eventName:a,handler:c}),!0}class dn extends tn{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==v&&v({type:"state:token-emit",kind:"command",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}function cn(e){return e instanceof dn}const un=new Map,fn=Ut();function pn(e){const t=e.propModifiers.filter(e=>e===S||e===I).sort().join(",");return`${e.statePathName}::${t}`}const hn=(e,t,n)=>o=>{t.includes(S)&&o.preventDefault(),t.includes(I)&&o.stopPropagation();const s=o.target,i=s.getRootNode(),r=ca(i);null===r&&E("No state tree found on this root for event handler.");const a=He(s),l=e.startsWith($+".");r.createStateAsync("writable",async t=>{en(t[it](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?kt(a.listIndex,d):[];if(l){const s=t[rt](zt(n,null));return cn(s)||E(`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&&E(`Handler "${e}" is not a function on the state tree.`),Reflect.apply(u,t,[o,...c])}),`"${e}"`)}).catch(t=>Zt(t,`"${e}"`))};function gn(e){return"event"===e.bindingType&&e.propName.startsWith(f)}function mn(e){if(!gn(e))return!1;const t=pn(e);let n=un.get(t);void 0===n&&(n=hn(e.statePathName,e.propModifiers,e.statePathInfo),un.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),fn.add(t,e),!0}function bn(e){if(!gn(e))return!1;const t=pn(e),n=un.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);return e.node.removeEventListener(o,n),0!==fn.countOf(t)&&(fn.remove(t,e)&&un.delete(t),!0)}const wn=new Map,yn=Ut();function vn(e,t){const o=n(e.inFilters);return`${e.statePathName}::${t}::${o}`}function Nn(e){let t="input";for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}function xn(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(x)){const o=Nn(e),s=vn(e,o);let i=wn.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=ca(o.getRootNode());null===i&&E("No state tree found on this root for two-way binding.");const r=He(o);i.createState("writable",e=>{e[it](r,()=>{e[t]=s})})},wn.set(s,i)),e.node.addEventListener(o,i),yn.add(s,e),!0}var t,n;return!1}const Sn=new Set(["radio","checkbox"]),In=new Set(["value","valueAsNumber","valueAsDate"]);function $n(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(Sn.has(e)&&"checked"===t)return!0;if(In.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=me(n);if(null!==s){const e=we(n)?.get(s);void 0===e&&E(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=ve(n);if(o?.knownProperties.has(t))return!0}return!1}let An=1,kn=1,Tn=1;const Pn=new WeakMap;function Mn(e,t,n){let o=Pn.get(e);void 0===o&&(o=new Map,Pn.set(e,o));const s=function(e,t){return`${t}::${e}`}(t,n);let i=o.get(s);return void 0===i&&(i=An++,o.set(s,i)),i}function En(e,t){return"to-element"===t?2*e:2*e+1}const Cn=new Set;function _n(e){return{transactionId:kn++,originBindingId:e,visitedEdges:Cn,hop:0}}function Rn(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 On=null;function Ln(){return On}function Bn(e,t){const n=On;On=e;try{return t()}finally{On=n}}const Wn=[];let Dn=!1;function Fn(){return!!Dn&&(Dn=!1,!0)}const jn=new Map,zn=Ut(),qn=new WeakMap,Vn=e=>e.detail,Hn=new WeakMap;const Un=new WeakMap;let Gn=0;const Kn=new WeakMap;function Xn(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=Un.get(e);return void 0===t&&Un.set(e,t=++Gn),`g${t}`}(o)}::${s?"o":"s"}`}const Qn=(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!==Vn||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=Hn.get(e);void 0===i&&(i=new Set,Hn.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=qn.get(a)?.get(t);if(void 0!==c)for(const e of c)e(d);let u=null;if(e.enablePropagationContext){const o=Mn(a,t,n),s=function(e,t){for(let n=Wn.length-1;n>=0;n--){const o=Wn[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!==v&&v({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:En(o,"to-state"),node:a,member:t}));const i=En(o,"to-state"),r=Ln();if(null!==r&&r.visitedEdges.has(i))return void(null!==v&&v({type:"propagation:suppressed",reason:"visited-edge",transactionId:r.transactionId,edgeId:i,node:a,member:t}));u=Rn(r??_n(o),i)}const f=ca(a.getRootNode());null===f&&E("No state tree found on this root for two-way binding.");const p=He(a),h=()=>{i&&(Dn=!0);try{f.createState("writable",e=>{e[it](p,()=>{e[n]=d})})}finally{i&&(Dn=!1)}};null!==u?Bn(u,h):h()};function Jn(e){const t=me(e.node);if(null!==t){const n=we(e.node),o=n?.get(t);if(void 0===o)return void(null===n&&E(`CustomElementRegistry is unavailable for <${t}>.`))}if($n(e.node,e.propName)&&-1===e.propModifiers.indexOf(x)){const t=function(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=me(e.node);if(null!==n){const o=we(e.node)?.get(n);void 0===o&&E(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=ve(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}(e),n=function(e){if(null!==me(e.node)){const t=ve(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??Vn}return null}(e),o=function(e){if(null===me(e.node))return!1;const t=ve(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}(e),s=Xn(e,t,n,o);Kn.set(e,{key:s,eventName:t});let i=jn.get(s);void 0===i&&(i=Qn(e.propName,e.statePathName,e.inFilters,n,o),jn.set(s,i)),e.node.addEventListener(t,i),zn.add(s,e)}}const Yn=new WeakSet;function Zn(e){Yn.add(e)}function eo(e){return!!Yn.has(e)&&(Yn.delete(e),!0)}const to=new WeakMap;function no(e,t){const n=to.get(e);return!(void 0===n||n<t)&&(n===t?to.delete(e):to.set(e,n-t),!0)}const oo=new WeakSet;function so(e){oo.add(e)}function io(e){return!!oo.has(e)&&(oo.delete(e),!0)}let ro=0;function ao(){ro--}function lo(){return ro>0}class co{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 uo=new WeakMap;function fo(e){let t=uo.get(e);return void 0===t&&(t=new co(e),uo.set(e,t)),t}const po=new Set([h,g,m,b]);function ho(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!==A&&s!==k&&E(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&E(`Binding modifier "${t}" may only be specified once.`),n=i)}return n}function go(e){return e.propModifiers.some(e=>e.includes("="))}const mo=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),bo=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function wo(e,t){return"state"===e&&"call"===t?mo:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function yo(t){if(!e.enableDirectionalInitialSync)return go(t)&&E("init=/sync= modifiers require enableDirectionalInitialSync."),mo;const n=null===(o=ho(t,A))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:E(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":E(`Invalid sync modifier value "${e}".`)}(ho(t,k));if("event"===t.bindingType)return null!==n&&"none"!==n&&E("Event bindings only allow init=none."),"call"===s?bo:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if(po.has(t.propSegments[0]))return wo("state",s);if("prop"!==t.bindingType)return null!==n&&"state"!==n&&"none"!==n&&E(`Binding type "${t.bindingType}" does not support init=${n}.`),wo(n??"state",s);const i=ve(t.node);if(null===i)return wo(n??"state",s);const r=i.knownProperties.has(t.propName),a=i.declaredInputs.has(t.propName);r||a||E(`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)||E(`init=${l} is incompatible with wcBindable member "${t.propName}".`),"connect"!==s||r||E(`sync=connect requires observable property "${t.propName}".`),{authority:l,syncOn:s,observable:r,outputOnly:r&&!a}}function vo(e,t){return"auto"!==t?t:function(e){const t=ca(e.replaceNode.getRootNode());null===t&&E("No state tree found on this root for binding.");const n=Vt(e);let o=!1;return t.createState("readonly",e=>{o=e[at](n)}),o}(e)?"state":"element"}let No=0,xo=0;const So=["active","disposed","failed"],Io=new WeakMap,$o=new WeakMap,Ao=new WeakMap,ko=new WeakMap,To=new WeakMap,Po=new WeakMap;function Mo(e,t){const n=Po.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):Po.set(e,new Set([n,t]))):Po.set(e,t)}function Eo(e){return Po.has(e)}function Co(e,t){const n=Po.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function _o(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))_o(n,t)}function Ro(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Oo{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||!no(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)eo(e)||_o(e,e=>{Co(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)io(e)&&!lo()||_o(e,e=>{Co(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&Gr(o)}}const Lo=new WeakMap;function Bo(e){let t=Lo.get(e);return void 0===t&&(t=new Oo(e),Lo.set(e,t)),t}function Wo(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 Do(e,t,n){const o=ca(Et(e,n));null===o&&E("No state tree found on this root for binding.");const s=bt(o,e.statePathInfo);return function(e,t,n){let o=Bt.get(e);void 0===o&&(o=new WeakMap,Bt.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!==v&&v({type:"state:binding-added",absoluteAddress:gt(e,t),binding:n})}(s,t,e),s}function Fo(e,t){const n=Ct(e,t);return Ot(n,e),n}function jo(e,t,n,o){null!==t?Lt(t,e):function(e,t,n){const o=Bt.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!==v&&v({type:"state:binding-removed",absoluteAddress:gt(e,t),binding:n}))}(n,o,e),Ht(e),_t(e)}function zo(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class qo{records=new Set;rowPlan=null;rows=new Set;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;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=Ao.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(Ro(t)&&Bo(t),null===this.rowPlan)for(const n of e){const e=Ao.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 go(t)&&yo(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=Ao.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=$o.get(t);void 0===o&&$o.set(t,o=[]);return{id:o[n]??(o[n]=++No),info:e,generation:t.generation,phase:So[t.phases[n]],teardowns:null}}const o=Ao.get(e);return o?.session===this?o:null}addTeardown(e,t){const n=Ao.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(zo(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=we(e);null===s&&E(`CustomElementRegistry is unavailable for <${t}>.`),this.observe(e),Mo(e,this);const i={node:e,active:!0,cancel:null};let r=this.deferredByNode.get(e);void 0===r&&(r=new Set,this.deferredByNode.set(e,r)),r.add(i),this.deferred.add(i);const a=()=>!!i.active&&(i.active=!1,r?.delete(i),this.deferred.delete(i),!0);return i.cancel=fo(s).wait(t,()=>{if(a())try{ye(s,e),n()}catch(e){o(e)}},e=>{a()&&o(e)}),()=>{a()&&i.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=Ao.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.active=!1,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&&(Lt(n,e.bindings[t]),e.addresses[t]=null),e.phases[t]=1}}dispose(){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.active=!1,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(){for(const e of this.rows)this.destroyRowRecord(e);this.rows.clear();for(const e of this.records)null!==e.address&&(Lt(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?Ct(n):null;if(jo(n,t.address,t.patternPathInfo,t.patternListIndex),t.address=null,t.patternPathInfo=null,t.patternListIndex=null,this.registerAddress(t),null!==o){const e=Ct(n);e!==o&&Qe(o)&&Xe(e,Ke(o)),e!==o&&st(o)&&tt(e,et(o))}this.shouldApplyState(n)&&e.push(n)}return e}observe(e){const t=function(e){const t=e.getRootNode();return Ro(t)?t:null}(e);null!==t&&Bo(t)}handleMutations(e,t,n){for(const n of t)_o(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)_o(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&Gr(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);const n=this.deferredByNode.get(e);if(void 0!==n)for(const e of Array.from(n))e.active=!1,e.cancel?.(),n.delete(e),this.deferred.delete(e)}handleAddedNode(e,t){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=Ao.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&&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=To.get(t);void 0===e&&(e=Wo(t),To.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;Mo(n,this);const o=this.knownMapFor(n);let s=To.get(e);void 0===s&&(s=Wo(e),To.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:++No,session:this,generation:++xo,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(Mo(i,this),this.addKnownRowBinding(i,o,e),Io.set(o,s),n[e].isEvent){let t=!1;try{t=mn(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=++xo,i=!0,this.rows.add(o)),o.phases[e]=0,o.flags[e]=0,s[e].isEvent){let n=!1;try{n=mn(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=Io.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=Pt(o);null!==s?(e.patternPathInfos[t]=Do(o,s,n),e.patternListIndexes[t]=s):e.addresses[t]=Fo(o,n)}unregisterRowSlot(e,t){const n=e.addresses[t],o=e.patternPathInfos[t];null===n&&null===o||(jo(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{bn(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:++No,info:e,generation:++xo,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};Ao.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;mn(n)?t.eventAttached=!0:n.propSegments[0]!==u?(xn(n)&&zo(t,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(x)){const t=Nn(e),n=vn(e,t),o=wn.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==yn.countOf(n)&&(yn.remove(n,e)&&wn.delete(n),!0))}return!1}(n)),Jt(n)&&zo(t,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(x)){const t=Qt(e),n=Xt(e,t),o=Gt.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Kt.countOf(n)&&(Kt.remove(n,e)&&Gt.delete(n),!0))}return!1}(n)),this.attachAfterDefinition(t,()=>{if(e.enableDirectionalInitialSync&&$n(n.node,n.propName)&&-1===n.propModifiers.indexOf(x)){const e=function(e,t,n){let o=qn.get(e);void 0===o&&(o=new Map,qn.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&&qn.delete(e)}}(n.node,n.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});zo(t,e)}Jn(n),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{ln(n)&&zo(t,()=>function(e){if(e.propSegments[0]!==u)return!1;const t=an.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),an.delete(e),!0)}(n))})}attachAfterDefinition(e,t){const n=me(e.info.node);if(null===n)return void t();const o=we(e.info.node);if(null===o&&E(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation,i=fo(o).wait(n,()=>{if(this.isAlive(e,s))try{ye(o,e.info.node),t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e))}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))});zo(e,i)}settleInitialRecord(t){if(e.enableDirectionalInitialSync&&!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=yo(t.info),n=vo(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 ro++;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,ao()),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=ca(e.node.getRootNode());null===o&&E("No state tree found on this root for initial binding sync.");const s=He(e.node);o.createState("writable",t=>{t[it](s,()=>{t[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=Pt(n);if(null!==o?(e.patternPathInfo=Do(n,o,t),e.patternListIndex=o):e.address=Fo(n,t),!e.options.registerPathInfo)return;const s=ca(n.replaceNode.getRootNode());null===s&&E("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&&Ao.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,ao());const t=e.info;if(null!==e.address||null!==e.patternListIndex)try{jo(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=Kn.get(e);if(void 0===t)return;Kn.delete(e);const n=jn.get(t.key);void 0!==n&&(e.node.removeEventListener(t.eventName,n),zn.remove(t.key,e)&&jn.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{bn(t)}catch{}}}}function Vo(e){let t=ko.get(e);return void 0===t&&(t=new qo(e),ko.set(e,t)),t}function Ho(e){return Ao.get(e)?.session??Io.get(e)?.session??null}let Uo=null;function Go(e){Uo=e}function Ko(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const Xo=Object.freeze([]);const Qo=new WeakMap;const Jo=new WeakMap;function Yo(e){return Jo.get(e)??[]}function Zo(e,t){Jo.set(e,t)}const es=new WeakMap;function ts(e){return es.get(e)??[]}function ns(e,t){es.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});let os=0;function ss(){return`u${(os++).toString(36)}`}let is=0,rs=0;const as=Symbol("wcs.listIndex.noValue");class ls{uuid=ss();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;_chainGeneration;_homeParentListIndex;_value;constructor(e,t,n){this.parentListIndex=e,this.position=e?e.position+1:0,this.length=this.position+1,this._homeParentListIndex=n,this._value=as,this._index=t,this._version=is,this._chainGeneration=rs}get index(){return this._index}set index(e){this._index=e,this._version=++is,this.indexes[this.position]=e}get version(){return this._version}get homeParentListIndex(){return this._homeParentListIndex}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=is),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0!==this._listIndexes&&this._chainGeneration===rs||(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)],this._chainGeneration=rs),this._listIndexes}get varName(){return`$${this.position+1}`}reparent(e){this.parentListIndex=e,this._indexes=void 0,this._listIndexes=void 0,this._version=++is,rs++}at(e){return e>=0?this.listIndexes[e]?.deref()||null:this.listIndexes[this.listIndexes.length+e]?.deref()||null}}function ds(e,t,n=e){return new ls(e,t,n)}function cs(e,t){e.reparent(t)}function us(e){return e.homeParentListIndex}function fs(e,t){e.value=t}function ps(e,t){const n=e.value;return n!==as&&n===t.value}const hs=new WeakMap,gs=new WeakSet;function ms(e){return gs.has(e)}function bs(e,t){const n=us(e),o=e.parentListIndex;return null===n||n===o||gs.has(n)?function(e,t,n){return null!==e&&null!==n&&n!==t&&!!gs.has(e)&&!gs.has(n)&&n.position===e.position&&ps(n,e)}(n,o,t)||function(e,t){return e!==t&&null!==e&&null!==t&&e.position===t.position&&gs.has(e)&&!gs.has(t)}(o,t)?t:null:n}function ws(e){const t=hs.get(e);return void 0===t?null:t}function ys(e,t){const n=hs.get(e);if(void 0===n)return null;const o=n[0];if(void 0!==o){const e=bs(o,t);if(null!==e)for(const t of n)cs(t,e)}return n}function vs(e,t){null!==t?hs.set(e,t):hs.delete(e)}const Ns=new WeakMap;function xs(e){return Ns.get(e)??null}function Ss(e,t){null===t?Ns.delete(e):Ns.set(e,t)}function Is(e){const t=Ns.get(e);t&&(t.dirty=!0)}const $s=Symbol.for("wcstack.transition-runner");function As(e){const t=globalThis[$s];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 ks(e,t,n){const o=As(e);if(null!==o)return o.run(t,{source:e,types:n});t()}const Ts=[],Ps=[];function Ms(e){Ps.includes(e)||Ps.push(e)}function Es(e,t=0){const n=Ts.findIndex(e=>e.priority>t),o={listener:e,priority:t};-1===n?Ts.push(o):Ts.splice(n,0,o)}function Cs(e){const t=Ts.findIndex(t=>t.listener===e);-1!==t&&Ts.splice(t,1)}function _s(e){queueMicrotask(()=>{throw e})}class Rs{_queueUpdateRecords=[];_queueRenderOnlyAddresses=[];constructor(){}enqueueAbsoluteAddress(e,t=null){for(let t=0;t<Ps.length;t++)Ps[t](e);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(){nt(),queueMicrotask(()=>{const e=this._queueUpdateRecords,t=this._queueRenderOnlyAddresses;this._queueUpdateRecords=[],this._queueRenderOnlyAddresses=[],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=[]){const n=new Map,s=new Set;for(let t=0;t<e.length;t++){const o=e[t],i=n.get(o.absoluteAddress);null!==v&&null!=i&&null!==o.context&&i.transactionId!==o.context.transactionId&&v({type:"propagation:coalesced",absoluteAddress:o.absoluteAddress,droppedTransactionId:i.transactionId,winnerTransactionId:o.context.transactionId}),n.set(o.absoluteAddress,o.context),s.add(o.absoluteAddress)}for(let e=0;e<t.length;e++){const o=t[e];n.has(o)||n.set(o,null)}const i=[],r=new Map;n.forEach((e,t)=>{if(null!==e&&e.hop>=T)return console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,transactionId:e.transactionId,hop:e.hop,maxHops:T}),void(null!==v&&v({type:"propagation:hop-limit",absoluteAddress:t,transactionId:e.transactionId,hop:e.hop}));const n=Wt(t);if(void 0!==n)if(n instanceof Set)for(const t of n)!1!==t.replaceNode.isConnected&&(i.push(t),null!==e&&r.set(t,e));else!1!==n.replaceNode.isConnected&&(i.push(n),null!==e&&r.set(n,e))});try{const e=()=>{r.size>0?Gr(i,r):Gr(i)};if(o()||0===i.length)e();else{const t=ks("state",e);void 0!==t&&t.catch(_s)}}finally{ot(),function(e){for(const t of Ts.slice())t.listener(e)}(s)}}}const Os=new Rs;function Ls(){return Os}const Bs=new WeakMap,Ws=new WeakMap,Ds=new WeakMap,Fs=new WeakMap;let js=!1;const zs=new WeakMap;function qs(e){const t=e.absolutePathInfo.stateElement;let n=zs.get(t);void 0===n&&zs.set(t,n=new Set),n.add(e)}function Vs(e){const t=zs.get(e);return void 0===t?null:(zs.delete(e),t)}const Hs=new WeakMap,Us=new WeakMap,Gs=new WeakMap,Ks=new WeakMap,Xs=new WeakMap,Qs=[];function Js(e,t){const n=Ys(e);if(n.recorded.has(t))return;n.recorded.add(t);const o=l(t).cumulativePaths;if(o.length<2)return;let s=Xs.get(e);void 0===s&&Xs.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 Ys(e){let t=Bs.get(e);return void 0===t&&Bs.set(e,t={byPath:new Map,lastValue:new Map,recorded:new Set,tracked:new Set}),t}function Zs(e,t,n){let o=e.get(t);void 0===o&&e.set(t,o=new Set),o.add(n)}function ei(e,t,n){const o=e.get(t);o.delete(n),0===o.size&&e.delete(t)}function ti(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=Ws.get(o);if(void 0===i&&Ws.set(o,i=new Map),i.has(t)){const e=i.get(t);return Object.is(e,n)||(ei(s,e,o),i.set(t,n),Zs(s,n,o)),!1}return i.set(t,n),Zs(s,n,o),!0}function ni(e,t,n){const o=e.get(t);return void 0===o?(e.set(t,[n]),!0):(o.push(n),!1)}function oi(e,t,n,o,s,i){e.lastValue.set(t,n),s&&(null!==o.listIndex&&ni(Ds,o.listIndex,i)&&function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){let n=Gs.get(t);void 0===n&&Gs.set(t,n=new Set),n.add(e)}}(o.listIndex),null!==i.levelListIndex&&ni(Fs,i.levelListIndex,i))}function si(e,t,n,o,s){js=!0;const i=Ys(e);Js(e,t);oi(i,t,s,o,ti(i,t,n,o),{stateElement:e,path:t,absAddress:o,levelListIndex:null})}function ii(e,t,n,o,s){js=!0;const i=Ys(e);Js(e,t);oi(i,t,s,o,ti(i,t,n.index,o),{stateElement:e,path:t,absAddress:o,levelListIndex:n})}function ri(e,t){Ys(e).tracked.add(t)}function ai(e){const t=Bs.get(e);return void 0===t?null:{byPath:t.byPath,lastValue:t.lastValue,tracked:t.tracked,watchers:Hs.get(e)}}function li(e,t){return!0===Bs.get(e)?.byPath.has(t)||!0===Hs.get(e)?.has(t)}function di(e,t,n,o,s){js=!0,Ys(e).lastValue.set(t,s),Js(e,t);let i=Hs.get(e);void 0===i&&Hs.set(e,i=new Map);let r=i.get(t);void 0===r&&i.set(t,r=new Set);let a,l=Us.get(o);if(void 0===l?Us.set(o,l=[]):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=Ks.get(n);void 0===e&&Ks.set(n,e=new Set),e.add(a)}}a.getters.add(n)}function ci(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(yt(e.stateElement,zt(t,o)))}function ui(e,t){if(void 0!==e)for(const n of e)t.push(n)}function fi(e,t,n,o,s){const i=Bs.get(e),r=i?.byPath.get(t),a=Hs.get(e)?.get(t);if(void 0===i||void 0===r&&void 0===a)return Qs;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&&ui(r.get(o),c),f&&ui(r.get(d),c),u&&ui(r.get(s),c)),void 0!==a)for(const e of a)n&&ci(e,o,c),f&&ci(e,d,c),u&&ci(e,s,c);return c}function pi(e,t){return!0===Xs.get(e)?.has(t)}function hi(e,t){let n=e;for(const e of t){if("object"!=typeof n||null===n)return;n=n[e]}return n}function gi(e,t,n,o,s=!0){const i=l(t).segments.length,r=[];for(const a of Xs.get(e).get(t)){const t=l(a).segments.slice(i);if(t.includes(N)){mi(e,a,r);continue}const d=s?hi(n,t):void 0;for(const n of fi(e,a,s,d,hi(o,t)))r.push(n)}return r}function mi(e,t,n){const o=Bs.get(e).byPath.get(t);if(void 0!==o)for(const e of o.values())ui(e,n);const s=Hs.get(e)?.get(t);if(void 0!==s)for(const e of s)for(let t=0;t<e.indexes.length;t++)ci(e,t,n)}function bi(e){const t=Fs.get(e.levelListIndex),n=t.indexOf(e);t.splice(n,1)}function wi(e){const t=Ds.get(e);if(void 0!==t){Ds.delete(e),function(e){for(let t=e.parentListIndex;null!==t;t=t.parentListIndex){const n=Gs.get(t);void 0!==n&&(n.delete(e),0===n.size&&Gs.delete(t))}}(e);for(const e of t){const{stateElement:t,path:n,absAddress:o}=e,s=Ws.get(o),i=s.get(n);s.delete(n),ei(Bs.get(t).byPath.get(n),i,o),null!==e.levelListIndex&&bi(e)}}}function yi(e){const t=Ks.get(e);if(void 0!==t){Ks.delete(e);for(const e of t){const t=Hs.get(e.stateElement),n=t.get(e.path);n.delete(e),0===n.size&&t.delete(e.path);const o=Us.get(e.indexes);o.splice(o.indexOf(e),1),0===o.length&&Us.delete(e.indexes)}}}function vi(e){if(!js)return;wi(e),yi(e);const t=Gs.get(e);if(void 0!==t){Gs.delete(e);for(const e of t)wi(e),yi(e),Gs.delete(e)}}function Ni(e,t,n){if(!js)return;const o=Fs.get(e);if(void 0!==o)for(const{stateElement:e,path:s,absAddress:i}of o){const o=Bs.get(e),r=o.byPath.get(s);ei(r,t,i),Zs(r,n,i),Ws.get(i).set(s,n);const a=o.lastValue.get(s);(Object.is(a,t)||Object.is(a,n))&&(Is(i),Ls().enqueueAbsoluteAddress(i,null),qs(i))}}const xi=new WeakMap,Si=Object.freeze([]),Ii=new Set;function $i(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:Si,s=Array.isArray(n)&&n.length>0?n:Si,i=function(e,t){const n=Array.isArray(e)&&e.length>0?e:Si,o=Array.isArray(t)&&t.length>0?t:Si;let s=xi.get(n);return s&&s.get(o)||null}(o,s);if(i)return i;const r=ys(o,e)||[],a=r.length>0?us(r[0]):e;let l;try{if(0===s.length)return l={oldIndexes:r,newIndexes:[],changeIndexSet:Ii,deleteIndexSet:new Set(r),addIndexSet:Ii};let t=ys(s,e);if(0===o.length){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=ds(e,n,a);t.push(o)}}return l={oldIndexes:r,newIndexes:t,changeIndexSet:Ii,deleteIndexSet:Ii,addIndexSet:new Set(t)}}if(function(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}(o,s))return l={oldIndexes:r,newIndexes:r,changeIndexSet:Ii,deleteIndexSet:Ii,addIndexSet:Ii};if(null!==t)return function(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}}(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,d=new Set;for(let o=0;o<s.length;o++){const l=s[o],c=n.get(l),u=c&&c.length>0?c.shift():void 0;if(void 0===u){const n=ds(e,o,a);t.push(n),d.add(n)}else{const e=r[u];u!==o&&i.add(e),t.push(e)}}return l={oldIndexes:r,newIndexes:t,changeIndexSet:i,deleteIndexSet:new Set(r).difference(new Set(t)),addIndexSet:d}}finally{void 0!==l&&(!function(e,t,n){let o=xi.get(e);o||(o=new WeakMap,xi.set(e,o)),o.set(t,n)}(o,s,l),vs(s,l.newIndexes))}}(e,t,n);!function(e,t){for(let n=0;n<e.length;n++){if(e[n].index!==n){const t=e[n].index;e[n].index=n,Ni(e[n],t,n)}fs(e[n],t[n])}}(o.newIndexes,Array.isArray(n)&&n.length>0?n:Si),function(e){for(const t of e)gs.add(t)}(o.deleteIndexSet);for(const e of o.deleteIndexSet)vi(e);return function(e){for(const t of e)gs.delete(t)}(o.newIndexes),function(e,t){if(!js||e===t)return;const n=Us.get(e);if(void 0===n)return;Us.delete(e);const o=Us.get(t);Us.set(t,void 0===o?n:o.concat(n));for(const o of n){o.indexes=t;const n=Ys(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&&!ms(e))for(const t of o.getters){const n=yt(o.stateElement,zt(t,e));Is(n),Ls().enqueueAbsoluteAddress(n,null),qs(n)}}}(o.oldIndexes,o.newIndexes),o}function Ai(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 ki=new WeakSet;function Ti(e){ki.add(e)}const Pi=new WeakMap;function Mi(e){return Pi.get(e)??null}function Ei(e,t){Pi.set(e,t)}const Ci=new WeakMap;function _i(e){return Ci.get(e)??[]}function Ri(e,t){Ci.set(e,t)}function Oi(e,t){const n=_i(e);for(const e of n)Ue(e,t)}const Li=new WeakMap;const Bi=new WeakMap;function Wi(e,t){for(let n=0;n<e.length;n++)if(t.has(e[n]))return!0;return!1}function Di(e,t,n,o,s){const i=function(e,t,n){let o=Bi.get(e);void 0===o&&Bi.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||Wi(u.prefixes,r)){Hr(c,s);continue}if(s.appliedBindingSet.has(c))continue;d||(l=s.state[rt](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?Hr(c,s):(s.appliedBindingSet.add(c),Vr(c,s,p))}}function Fi(e,t,n){Oi(e,t);const o=Yo(e),s=Mi(e);if(null!==s&&(s.activate(o,n.rootNode),null!==t&&!1===n.stateElement.hasUpdatedCallback&&!0!==n.stateElement.hasRecursion)){const i=function(e){return Li.get(e)??null}(e);if(null!==i)return void Di(i,o,s,t,n)}for(const e of o){if(null===s){Ot(Ct(e),e)}(null===s||s.shouldApplyState(e))&&Hr(e,n)}}function ji(e){if(!e.mounted)return;const t=Yo(e),n=Mi(e);for(let e=0;e<t.length;e++){const o=t[e];if(null!==n)n.disposeBinding(o);else{Lt(Ct(o),o)}}!function(e){const t=_i(e);for(let e=0;e<t.length;e++)Ue(t[e],null)}(e)}function zi(){return Object.freeze(new Set)}const qi=new WeakMap,Vi=zi();function Hi(e,t){const n=qi.get(e);n?n.add(t):qi.set(e,new Set([t]))}function Ui(e){const t=qi.get(e);return void 0!==t?t:Vi}function Gi(e,t){const n=qi.get(e);n&&(n.delete(t),0===n.size&&qi.delete(e))}const Ki=new Set(["if","elseif","else","for"]);class Xi{_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];so(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){so(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=Mi(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRow(Yo(this));const t=this._childNodeArray;for(let e=0;e<t.length;e++){const n=t[e];null!==n.parentNode&&(Zn(n),n.parentNode.removeChild(n))}const n=Yo(this);for(let e=0;e<n.length;e++){const t=n[e];Ki.has(t.bindingType)&&Ui(t.node).forEach(e=>{e.tryDestroy()||e.unmount()})}return this._mounted=!1,!0}unmountInPlace(){{const e=Mi(this);null!==e&&(e.isRowSession?e.disposeBindings(Yo(this)):e.dispose())}this._teardownBindings()}_teardownBindings(){const e=Yo(this);for(let t=0;t<e.length;t++){const n=e[t];Ki.has(n.bindingType)&&Ui(n.node).forEach(e=>{e.unmount()}),Ht(n),_t(n)}}unmount(){{const e=Mi(this);null!==e&&(e.isRowSession?e.disposeBindings(Yo(this)):e.dispose())}for(const e of this._childNodeArray)null!==e.parentNode&&(Zn(e),e.parentNode.removeChild(e));const e=Yo(this);for(let t=0;t<e.length;t++){const n=e[t];Ki.has(n.bindingType)&&Ui(n.node).forEach(e=>{e.unmount()}),Ht(n),_t(n)}this._mounted=!1}}function Qi(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 Ji(e){const t=document.createDocumentFragment(),n=new Xi(t);return n._childNodeArray=e,n._firstNode=e.length>0?e[0]:null,n._lastNode=e.length>0?e[e.length-1]:null,n._mounted=!0,n}function Yi(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&&E(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),Fe(t),he(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=Qr.get(n);void 0!==o&&o.currentRowPlan===e||(o=new qo,Qr.set(n,o));return o.initializeRow(e,t),o}(n,a,e.node),c=new Xi(o);return Ei(c,d),Zo(c,a),function(e,t){Li.set(e,t)}(c,n),ns(c,l),Ri(c,i),Hi(e.node,c),c}function Zi(t){void 0!==t.uuid&&null!==t.uuid||E("BindingInfo.uuid is null.");const n=va(t.uuid);n||E(`Fragment with UUID "${t.uuid}" not found.`);const s=!o()&&Qi(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===b||s===u)return null;if("text"===n){if(i.nodeType!==Node.TEXT_NODE)return null}else if(null!==me(i))return null;if("prop"===n&&$n(i,t.propName))return null;const r=Me(t);let a;try{a=yo({...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 P,policy:a,authority:a.authority})}}return 0===o.length?null:{directional:n,slots:o}}(n)),null!==i)return Yi(t,n,i);const r=document.importNode(n.fragment,!0),a=function(e,t){const[n,o]=function(e,t){const n=[],o=[];for(const s of t){const t=Te(e,s.nodePath);if(null===t&&E(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),Be.has(t))continue;const i=We(t,s.parseBindTextResults,{allowDeferred:!1});o.push(...i.bindings),n.push(t)}return[n,o]}(e,t),s=new qo,i=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:i,bindingSession:s}}(r,n.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(r,t.uuid);const l=new Xi(r,s);Ei(l,a.bindingSession),Zo(l,a.bindingInfos);const d=[];for(const e of a.bindingInfos)e.statePathName in P&&d.push(e);return ns(l,d),Ri(l,a.nodes),Hi(t.node,l),l}const er=new WeakSet,tr=Symbol.for("wcstack.state.view-transition-naming");function nr(){const e=As("state");return null===e||"auto"!==e.naming?null:{limit:e.namingLimit}}function or(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||er.has(o))return;const s=o.style;if(void 0===s)return;const i=function(){const e=globalThis;return e[tr]??={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.`)):(er.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 sr=new WeakMap,ir=new WeakMap,rr=new WeakMap,ar=new WeakMap;function lr(e,t,n){!function(e,t,n){let o=ir.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,ir.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function dr(e,t){sr.set(e,t)}function cr(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 ur(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)}function fr(e,t,n){if(o=t,!ki.has(o))return null;var o;let s=null;for(let t=0;t<n.newIndexes.length;t++){const o=n.newIndexes[t],i=n.oldIndexes[t],r=n.addIndexSet.has(o)&&n.deleteIndexSet.has(i)?e.get(i):void 0;void 0!==r&&(s??={byAddedIndex:new Map,reused:new Set},s.byAddedIndex.set(o,r),s.reused.add(r))}return s}const pr=new Set(["if","elseif","else","for"]);function hr(e,t){for(const n of Yo(e))if(t.appliedBindingSet.delete(n),pr.has(n.bindingType))for(const e of Ui(n.node))hr(e,t)}function gr(e){for(const t of Yo(e)){if(!pr.has(t.bindingType))continue;const e="for"===t.bindingType;for(const n of Ui(t.node))gr(n),e&&n.mounted&&(ji(n),n.unmount(),Gi(t.node,n))}}function mr(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function br(t,n,s){const i=Boolean(s);let r;const a=Ui(t.node);r=0===a.size?Zi(t):a.values().next().value;const l=o(),d=t.uuid??"",c=t.bindingType;if(i||(e.debug&&console.log(`unmount if content : ${mr(t)}`),ji(r),r.unmount()),i){if(e.debug&&console.log(`mount if content : ${mr(t)}`),l){const e=document.createComment(`@@wcs-${c}-start:${d}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),r.mountAfter(e);const n=document.createComment(`@@wcs-${c}-end:${d}:${t.statePathName}`),o=r.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else r.mountAfter(t.node);Fi(r,He(t.node),n);const o=nr();null!==o&&or(r,"branch",o)}}const wr=new WeakMap;function yr(e){return wr.get(e)??[]}function vr(){return Array.from(Nr)}const Nr=new Set;function xr(){Nr.clear()}const Sr=Symbol.for("wcstack.trustedTypes.policy");function Ir(){const e=globalThis[Sr];return null===e||"object"!=typeof e?null:e}function $r(e){globalThis[Sr]=e}let Ar;let kr=!1;function Tr(e,t){if(kr)return;if(!function(){if(void 0!==Ar)return Ar;if(!("trustedTypes"in globalThis))return Ar=!1,Ar;try{document.createElement("div").innerHTML="<i></i>",Ar=!1}catch{Ar=!0}return Ar}())return;kr=!0;const n="function"==typeof Ir()?.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 Pr={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 Mr(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!==Uo&&null!==c&&"object"==typeof c&&null!==s&&"object"==typeof s&&null!==me(i)&&Uo.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=Ir(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(s):s,t=!0}catch(t){o&&Tr(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=me(e);if(null===n)return null;const o=we(e)?.get(n);if(void 0===o)return null;const s=ve(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&&$n(i,d)){const e=Mn(i,d,t.statePathName),o=En(e,"to-element"),a=n?.propagationContextByBinding?.get(t)??Ln()??_n(e);if(a.visitedEdges.has(o))null!==v&&v({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:o,node:i,member:d});else{const t=Rn(a,o);Bn(t,()=>function(e,t,n,o,s,i){const r={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Tn++,writtenValue:n};Wn.push({receipt:r,node:e});try{return i()}finally{Wn.pop()}}(i,d,s,e,t.transactionId,r))}}else r()}if(o()){const e=Pr[d];e?e(i,s):(!function(e,t,n){let o=wr.get(e);o||(o=[],wr.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,Nr.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!==Uo&&2===r.length&&"object"==typeof c&&null!==c&&null!==me(i)&&(u in c?Uo.rememberOverwrittenValue(i,d,u,c[u]):Uo.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 Er=new WeakSet;function Cr(e,t,n){}function _r(e,t){const n=Vt(t);if(n.pathInfo.path in P){const e=He(t.node);return null===e&&E(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&E("ListIndex not found for loopContext:");const n=P[t];void 0===n&&E(`Invalid index name: ${t}`);const o=At(e.listIndex,n,e.pathInfo.wildcardCount);return null===o&&E(M(`"${t}"`,n+1,e.pathInfo.wildcardCount)),o.index}(e,n.pathInfo.path)}return e[rt](n)}const Rr=new WeakSet;function Or(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const Lr=Object.freeze({[h]:function(e,t,n){const o=e.node,s=e.propSegments[1];null!=n?("boolean"!=typeof n&&E(`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)},[g]: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)},[m]:function(e,t,n){const o=e.propSegments[1],s=e.node.style;null==n&&(n=""),s[o]!==n&&(s[o]=n)},[b]:function(e,t,n){cn(n)||E("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Qo.get(e);if(s&&s.token===o)return;const i=e.node,r=e.propSegments[1];"string"==typeof r&&0!==r.length||E('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=me(e);if(null===t)return null;const n=we(e)?.get(t);return void 0===n&&E(`Custom element <${t}> is not defined for command binding.`),ve(e)}(i);null===a&&E(`command binding requires a wc-bindable custom element. <${i.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(r)||E(`Command "${r}" is not declared in wcBindable.commands of <${i.tagName.toLowerCase()}>.${_(r,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),Qo.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 Qo.delete(e);const o=n[r];return"function"!=typeof o&&E(`Method "${r}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),Qo.set(e,{token:o,unsubscribe:d,elementRef:l})}}),Br={text:function(e,t,n){const s=null==n?"":String(n);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),o()&&!Er.has(e.replaceNode)){Er.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 s=e.statePathInfo,i=Pt(e),r=Ct(e),a=Ke(r),d=a.length>0&&!ir.has(e.node)?[]:a,c=$i(i,d,n);t.newListValueByAbsAddress.set(r,Array.isArray(n)?n:[]);let u=ir.get(e.node);const f=void 0!==u?fr(u,d,c):null,p=Array.isArray(d)&&d.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(p&&null===f&&null!==e.node.parentNode){let t=ar.get(e.node);if(void 0===t){const n=sr.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(cr(n)){s=!1;break}n=n.previousSibling}for(;null!==o;){if(cr(o)){s=!1;break}o=o.nextSibling}return s}(e.node,n),ar.set(e.node,t)}if(t){const t=e.node.parentNode;!function(e,t){to.set(e,(to.get(e)??0)+t)}(t,t.childNodes.length),t.textContent="",t.appendChild(e.node)}}let h=p?1e3-function(e){return rr.get(e.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){const t=u;c.deleteIndexSet.forEach(n=>{const o=t.get(n);void 0!==o&&(null!==f&&f.reused.has(o)?(ji(o),gr(o),o.unmountInPlace()):h<=0&&o.tryDestroy()?Gi(e.node,o):(ji(o),o.unmount(),function(e,t){let n=rr.get(e.node);void 0===n&&(n=[],rr.set(e.node,n)),n.length<1e3?n.push(t):Gi(e.node,t)}(e,o),h-=1),p||t.delete(n))}),p&&(ir.delete(e.node),u=void 0)}let g=e.node;const m=l(s.path+"."+N),b=t.stateElement.loopContextStack,w=Ai(c);let y=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&g.isConnected&&null===f&&(y=document.createDocumentFragment(),xt(y,t.rootNode));const v=o(),x=nr(),S=e.uuid??"",I=rr.get(e.node);for(const n of c.newIndexes){let o;if(c.addIndexSet.has(n)){const i=zt(m,n);if(b.createLoopContext(i,i=>{if(o=f?.byAddedIndex.get(n)??(void 0!==I?I.pop():void 0),void 0===o?o=Zi(e):hr(o,t),null!==y)v&&y.appendChild(document.createComment(`@@wcs-for-start:${S}:${s.path}:${n.index}`)),o.appendTo(y),v&&y.appendChild(document.createComment(`@@wcs-for-end:${S}:${s.path}:${n.index}`));else{if(g.nextSibling!==o.firstNode){if(v){const e=document.createComment(`@@wcs-for-start:${S}:${s.path}:${n.index}`);g.parentNode.insertBefore(e,g.nextSibling),g=e}o.mountAfter(g)}if(v){const e=document.createComment(`@@wcs-for-end:${S}:${s.path}:${n.index}`),t=o.lastNode??g;t.parentNode.insertBefore(e,t.nextSibling)}}Fi(o,i,t),null!==x&&or(o,"row",x)}),void 0===o&&E(`Content not found for ListIndex: ${n.index} at path "${s.path}"`),null!==f&&f.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{if(o=void 0!==u?u.get(n)??null:null,c.changeIndexSet.has(n)){const e=ts(o);for(const n of e)Hr(n,t)}null===o&&E(`Content not found for ListIndex: ${n.index} at path "${s.path}"`);const e=!o.mounted;if(null!==w&&w.has(n)&&ur(g,o.firstNode)||g.nextSibling===o.firstNode||o.mountAfter(g),e){const e=o,s=zt(m,n);b.createLoopContext(s,n=>{Fi(e,n,t)})}}g=o.lastNode||g,void 0===u&&(u=new WeakMap,ir.set(e.node,u)),u.set(n,o)}sr.set(e.node,g),null!==y&&(e.node.parentNode.insertBefore(y,e.node.nextSibling),xt(y,null))},if:br,else:br,elseif:br,radio:function(e,t,n){const o=e.node,s=Ko(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=Ko(o.value,e.inFilters),i=Array.isArray(n)?n:Xo;o.checked=i.includes(s)}},Wr=new WeakMap,Dr=new WeakMap,Fr=new WeakMap;function jr(){}function zr(e){const t=Uo;if(null!==t){const n=e.replaceNode,o=e.propSegments[0];if(t.isComplete(n,o))return Cr;if(t.isDeclared(n,o))return jr}return Mr}function qr(e,t){Vr(e,t,_r(t.state,e))}function Vr(e,t,n){const o=Ko(n,e.outFilters);if(!0===Dr.get(e))return void t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement});let s=Wr.get(e);if(void 0===s){if(Wr.has(e))return s=zr(e),s===Cr&&Wr.set(e,s),void s(e,t,o);if(s=Br[e.bindingType],void 0===s){const t=e.propSegments[0];if(s=Lr[t],Wr.set(e,s),void 0===s){me(e.replaceNode)?(s=zr(e),s===Cr&&Wr.set(e,s)):(s=Mr,Wr.set(e,s))}}if(s===Mr){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 Dr.set(e,!0)}}s(e,t,o)}else s(e,t,o)}function Hr(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=Ct(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=Ho(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==Fr.get(e)){const t=me(e.replaceNode);if(t&&void 0===we(e.replaceNode)?.get(t))return void function(e,t){if(Rr.has(e))return;Rr.add(e);const n=()=>{Rr.delete(e);const t=Ho(e);(null===t||t.shouldApplyState(e))&&Gr([e])},o=n=>{Rr.delete(e),Or(t,n)},s=Ho(e);if(null!==s){const i=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{Rr.delete(e),i()})||(Rr.delete(e),i()))}const i=we(e.replaceNode);if(null===i)return Rr.delete(e),void Or(t,new Error("CustomElementRegistry is unavailable."));fo(i).wait(t,()=>{e.replaceNode.isConnected?n():Rr.delete(e)},o)}(e,t);Fr.set(e,!0)}if(!0===t.sameRootVerified)return void qr(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=St(o),null===o&&E("Root node for fragment not found for binding.")),o!==t.rootNode){const n=ca(o);null===n&&E("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};qr(e,i)})}else qr(e,t)}function Ur(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!==v&&v({type:"state:binding-apply-error",path:e.statePathName,bindingType:e.bindingType,error:t})}function Gr(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=St(c),null===c&&E("Root node for fragment not found for binding."));const u=ca(c);null===u&&E("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{Hr(o,f)}catch(e){Ur(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{Mr(e,{propagationContextByBinding:n},t)}catch(t){Ur(e,t,o??null,d)}for(const[e,t]of r.entries())Xe(e,t),tt(e,t);if(!1!==o?.updatedCallback)for(const[e,t]of a.entries())e.createState("writable",e=>{e[ct](Array.from(t))});for(const[e,t]of d.entries())e.createState("writable",e=>{for(const{error:n,info:o}of t)try{e[ut](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 Kr(e,t,n){for(const o of e)n.deferUntilDefined(o.node,o.tagName,()=>{const e=je(o);if(0===e.length)return;Ue(o.node,t);Gr(n.initialize(e))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,e)})}function Xr(e,t,n){const[o,s,i]=De(e,n),r=Vo(e);for(const e of o)Ue(e,t);Gr(r.initialize(s)),Kr(i,t,r)}const Qr=new WeakMap;async function Jr(t){const n=t.querySelectorAll(e.tagNames.state),o=[],s=we(t);null===s&&E(`CustomElementRegistry is unavailable for <${e.tagNames.state}>.`),await s.whenDefined(e.tagNames.state);for(const e of n){if(_e(e))continue;const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function Yr(t){if(t===document)await Jr(document),F(document),Fa(document,document),Xr(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await pe(n.host),await Jr(n),F(n),Fa(n,n),Xr(n,null)}}const Zr={watch:"temporal",scan:"temporal",streams:"temporal",scopes:"scopes",dcc:"scopes",recursion:"recursion",ssr:"ssr",devtools:"devtools"};function ea(e,t){return`[wcs/feature-not-installed] ${t} needs the "${e}" feature: install it with installFeatures([...]) from "@wcstack/state/features/${Zr[e]??e}" before the state is defined.`}let ta=null;function na(e){ta=e}function oa(e){return null===ta&&E(ea("ssr",e)),ta}const sa=new WeakMap,ia=new WeakMap,ra=new Set,aa=[];function la(e){aa.includes(e)||aa.push(e)}function da(){return ra}function ca(e){return sa.get(e)??null}function ua(e){return ia.get(e)??Promise.resolve()}function fa(e,t){const n=Promise.reject(t);n.catch(()=>{}),ia.set(e,n)}const pa=new WeakSet;function ha(e,t){const n=sa.get(e);if(void 0!==n){if(n===t)return;E("A state tree is already registered on this root.")}sa.set(e,t)}function ga(e,t){ia.set(e,t),t.then(()=>ma(e),()=>{})}function ma(e){pa.add(e)}function ba(t,n){const s=sa.get(t);if(null===n){if(void 0===s)return;sa.delete(t),ra.delete(s),null!==v&&v({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 oa('the "enable-ssr" attribute').hydrate(t)||await Yr(t)}else await Yr(t);ma(t),Ua(),n()}catch(e){o(e)}})});ia.set(t,n)}else if("ShadowRoot"===t.constructor.name){const e=new Promise((e,n)=>{queueMicrotask(async()=>{try{await Yr(t),ma(t),Ua(),e()}catch(e){n(e)}})});ia.set(t,e)}}void 0!==s&&E('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="...">.'),sa.set(t,n),ra.add(n);for(let e=0;e<aa.length;e++)aa[e](t,n);null!==v&&v({type:"state:element-registered",rootNode:t,element:n}),e.debug&&console.debug("State element registered",n)}}const wa=new Map;function ya(e,t,n){if(null===n)wa.delete(e);else{wa.set(e,n);const o=ca(t);null===o&&E("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 va(e){return wa.get(e)||null}function Na(){wa.clear()}function xa(t){if(t.nodeType===Node.ELEMENT_NODE){const n=t,o=se(n.getAttribute(e.bindAttributeName)||"");if(n.localName===e.tagNames.state){if(n.hasAttribute("mount"))return o.filter(e=>e.propSegments[0]!==w);const t=o.find(e=>e.propSegments[0]===w);if(void 0!==t){const n=`on a volume element — a <${e.tagNames.state}> with a "mount" attribute`;E(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 ("${w}.<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=le(t);null===e&&E("Comment node binding text not found.");const n=va(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=de(e),s=null):s=e,[{...o,uuid:s}]}return[]}let Sa;function Ia(){return Sa??={filterName:"not",args:[]}}const $a=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Aa(e,t){const n=t+a+N,o=X(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+a+s.slice(1)}return i.length>0?s+i:s}function ka(e,t){const n=$a.exec(e);if(null===n)return e;const o=n[1],s=n[2],i=n[3];return o+Aa(s,t)+i}function Ta(e,t){const n=Q(e,";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=X(n,":");if(-1===s)return e;const i=n.slice(0,s).trim(),r=n.slice(s+1).trim(),a=Aa(r,t);return a!==r?(o=!0,`${i}: ${a}`):e});return o?s.join(";"):e}function Pa(e,t){return Ta(e,t)}function Ma(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=ka(t.data,n);continue}const t=e;if(t instanceof HTMLTemplateElement)continue;const i=t.getAttribute(o);if(null!==i){const e=Ta(i,n);e!==i&&t.setAttribute(o,e)}}}function Ea(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 Ca=new WeakMap;function _a(e){return Ca.get(e)??null}function Ra(e){const t=[],n=Le(e);for(const e of n){const n=xa(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");Ca.set(t,e.data),e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:Ea(o),parseBindTextResults:n})}return t}function Oa(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 La=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),Ba=Ia();function Wa(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Ba],bindingType:e}}function Da(e,t,n,o,s,i=!0){Oa(t),"string"==typeof o&&Ma(t,o),Fa(e,t,o,s);const r={fragment:t,parseBindTextResult:void 0!==s&&i?s(n,o):n,nodeInfos:Ra(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 Fa(t,n,o,s){const i=e.commentElsePrefix,r=Re(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=Pa(r,o));let a=se(r)[0];const c=La.get(a.bindingType);if(void 0===c)continue;const u=a.bindingType,f=n.content,p=ss();let h=null;const g="for"===u?a.statePathName:o;if("else"===u){null===l&&E("'else' binding found without preceding 'if' or 'elseif' binding."),a=Wa("else",l.parseBindTextResult),h=Da(t,f,a,g,s,!1),ya(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:Ea(o),parseBindTextResults:xa(o)})):n.replaceWith(o)}else if("elseif"===u){null===l&&E("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Da(t,f,a,g,s),ya(p,t,h);const e=document.createComment(`@@${c}:${p}`),o=ss(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Wa("else",l.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:Ea(e),parseBindTextResults:xa(e)}),ya(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:Ea(m),parseBindTextResults:xa(m)})):n.replaceWith(m)}else{h=Da(t,f,a,g,s),ya(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 ja=()=>`[${e.bindAttributeName}]`;function za(t){if(Eo(t))return!0;if(!qa(t))return!1;if(t.hasAttribute(e.bindAttributeName))return!1;const n=t.querySelector(ja());return null!==n&&Eo(n)}function qa(e){return 1===e.nodeType}function Va(t){if(za(t))return;F(t),Fa(t.getRootNode(),t);const n=t.hasAttribute(e.bindAttributeName),o=t.parentNode,s=null!==o&&(1===o.nodeType||9===o.nodeType||11===o.nodeType);Xr(n&&s?o:t,null)}const Ha=[];function Ua(){const e=Ha.splice(0,Ha.length);for(const t of e)Va(t);B()}const Ga={protocol:"wcs-binder",version:1,bind:function(e){var t;qa(e)&&!za(e)&&(t=e.getRootNode(),pa.has(t)?Va(e):Ha.push(e))}};function Ka(){const e=globalThis;void 0===e[R]&&(e[R]=Ga)}export{Xe as $,ha as A,ga as B,F as C,Fa as D,Xr as E,ca as F,Ce as G,Go as H,me as I,pe as J,se as K,la as L,tt as M,$i as N,et as O,vr as P,yr as Q,xr as R,va as S,Sr as T,_a as U,Te as V,Na as W,Jr as X,De as Y,Kr as Z,Ct as _,Ir as a,Oa as a0,Ma as a1,Ra as a2,ya as a3,Ji as a4,Ei as a5,Zo as a6,Ri as a7,ns as a8,ds as a9,fa as aA,ea as aB,dn as aC,xs as aD,Ss as aE,ys as aF,Vs as aG,$t as aH,li as aI,pi as aJ,fi as aK,gi as aL,Fn as aM,Ln as aN,_n as aO,Ke as aP,Ti as aQ,ke as aR,de as aS,ai as aT,da as aU,Cs as aV,lr as aa,dr as ab,Hi as ac,Oi as ad,vs as ae,qo as af,Ia as ag,na as ah,Is as ai,ri as aj,di as ak,ii as al,si as am,ut as an,ct as ao,dt as ap,lt as aq,at as ar,ks as as,_s as at,ot as au,Wt as av,nt as aw,rn as ax,oa as ay,ba as az,Yr as b,Ls as c,sn as d,Ms as e,Es as f,ua as g,rt as h,ms as i,zt as j,ws as k,yt as l,At as m,ps as n,kt as o,vt as p,we as q,Ka as r,$r as s,Ve as t,ye as u,He as v,it as w,Vo as x,Ue as y,Gr 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 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};
2
2
  //# sourceMappingURL=binder.js.map