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