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