@wcstack/state 2.6.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +112 -45
- package/README.md +114 -45
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/define.d.ts +295 -0
- package/dist/define.js +1 -0
- package/dist/index.d.ts +254 -94
- package/dist/index.esm.js +1 -23477
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.esm.js +22 -37
- package/dist/parser.d.ts +37 -39
- package/dist/parser.esm.js +172 -1153
- package/dist/split/chunks/binder.js +2 -0
- package/dist/split/chunks/binder.js.map +1 -0
- package/dist/split/chunks/checkDependency.js +2 -0
- package/dist/split/chunks/checkDependency.js.map +1 -0
- package/dist/split/chunks/diagnosticsHooks.js +2 -0
- package/dist/split/chunks/diagnosticsHooks.js.map +1 -0
- package/dist/split/chunks/errorGuidance.js +2 -0
- package/dist/split/chunks/errorGuidance.js.map +1 -0
- package/dist/split/chunks/features.d.ts +29 -0
- package/dist/split/chunks/filterRegistry.js +2 -0
- package/dist/split/chunks/filterRegistry.js.map +1 -0
- package/dist/split/chunks/getAllPropertyDescriptors.js +2 -0
- package/dist/split/chunks/getAllPropertyDescriptors.js.map +1 -0
- package/dist/split/chunks/lifecycleHooks.js +2 -0
- package/dist/split/chunks/lifecycleHooks.js.map +1 -0
- package/dist/split/chunks/mount.js +2 -0
- package/dist/split/chunks/mount.js.map +1 -0
- package/dist/split/chunks/pathDiagnostics.js +2 -0
- package/dist/split/chunks/pathDiagnostics.js.map +1 -0
- package/dist/split/chunks/registerComponents.js +2 -0
- package/dist/split/chunks/registerComponents.js.map +1 -0
- package/dist/split/chunks/setAll.js +2 -0
- package/dist/split/chunks/setAll.js.map +1 -0
- package/dist/split/chunks/version.js +2 -0
- package/dist/split/chunks/version.js.map +1 -0
- package/dist/split/chunks/watchRuntime.js +2 -0
- package/dist/split/chunks/watchRuntime.js.map +1 -0
- package/dist/split/core.d.ts +1417 -0
- package/dist/split/core.js +2 -0
- package/dist/split/core.js.map +1 -0
- package/dist/split/features/devtools.d.ts +9 -0
- package/dist/split/features/devtools.js +2 -0
- package/dist/split/features/devtools.js.map +1 -0
- package/dist/split/features/diagnostics.d.ts +11 -0
- package/dist/split/features/diagnostics.js +2 -0
- package/dist/split/features/diagnostics.js.map +1 -0
- package/dist/split/features/formats.d.ts +10 -0
- package/dist/split/features/formats.js +2 -0
- package/dist/split/features/formats.js.map +1 -0
- package/dist/split/features/recursion.d.ts +9 -0
- package/dist/split/features/recursion.js +2 -0
- package/dist/split/features/recursion.js.map +1 -0
- package/dist/split/features/scopes.d.ts +10 -0
- package/dist/split/features/scopes.js +2 -0
- package/dist/split/features/scopes.js.map +1 -0
- package/dist/split/features/ssr.d.ts +9 -0
- package/dist/split/features/ssr.js +2 -0
- package/dist/split/features/ssr.js.map +1 -0
- package/dist/split/features/temporal.d.ts +9 -0
- package/dist/split/features/temporal.js +2 -0
- package/dist/split/features/temporal.js.map +1 -0
- package/dist/wcs-manifest.json +1 -0
- 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,X as c,Y as u,Z as f,_ as p,$ as h,a0 as g,a1 as m,a2 as b,p as w,W as y,j as v,a3 as N,a4 as x,w as S,a5 as I,a6 as A,a7 as T,I as $,F as k,V as P}from"./pathDiagnostics.js";import{r as M,L as E,d as C}from"./errorGuidance.js";const _=Symbol.for("wcstack.binder");const R=Symbol.for("wcstack.binder.pending"),O=Symbol.for("wcstack.binder.taken");function B(){const e=function(){const e=globalThis[_];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;const t=function(){const e=globalThis;let t=e[R];return void 0===t&&(t=[],e[R]=t),t}();if(0===t.length)return;const n=t.splice(0,t.length),o=function(){const e=globalThis;let t=e[O];return void 0===t&&(t=new WeakSet,e[O]=t),t}();for(const t of n)o.add(t),e.bind(t)}const L=/\{\{\s*(.+?)\s*\}\}/g,W=new Set(["SCRIPT","STYLE"]);function D(t){if(!e.enableMustache)return;!function(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[];for(;t.nextNode();)n.push(t.currentNode);for(const e of n)e.parentElement&&W.has(e.parentElement.tagName)||F(e)}(t);const n=Array.from(t.querySelectorAll("template"));for(const e of n)if(e.namespaceURI===o){const t=document.createElement("template"),n=Array.from(e.childNodes);for(let e=0;e<n.length;e++){const o=n[e];t.content.appendChild(o)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),D(t.content)}else D(e.content)}function F(e){const t=e.data;if(L.lastIndex=0,!L.test(t))return;L.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=L.exec(t));){o.index>s&&n.appendChild(document.createTextNode(t.slice(s,o.index)));const e=o[1];n.appendChild(document.createComment(`@@: ${e}`)),s=o.index+o[0].length}s<t.length&&n.appendChild(document.createTextNode(t.slice(s))),e.parentNode.replaceChild(n,e)}const j=new Set(["if","elseif","else","for"]);function q(e,t,n){const o=-1===t?e.length:t;let s=0;for(;s<o&&/\s/.test(e[s]);)s++;const i=-1===n?0:n;let r=e.length;for(;r>i&&/\s/.test(e[r-1]);)r--;return e.slice(s,r)}const z=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function V(e,t){return t?e:"true"===e||"false"!==e&&("null"===e?null:z.test(e)?Number(e):e)}function H(e){const t=[],n=[];let o="",s=null,i=!1,r=-1,a=-1;const l=()=>{const e=q(o,r,a);t.push(e),n.push(V(e,i)),o="",i=!1,r=-1,a=-1};for(let t=0;t<e.length;t++){const n=e[t];s?n===s?s=null:(-1===r&&(r=o.length),o+=n,a=o.length):'"'===n||"'"===n?(s=n,i=!0):","===n?l():o+=n}null!==s&&M(`[wcs/binding-syntax] unterminated ${s} quote in the filter arguments "(${e})". Close the quote.${E}`);const d=q(o,r,a);return(d||i)&&(t.push(d),n.push(V(d,i))),{args:t,literals:n}}function U(e,t){return e.map(t=>{const n=t.indexOf("("),o=t.lastIndexOf(")");-1!==n&&-1===o&&M(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==o&&-1===n&&M(`Invalid filter format: missing opening parenthesis in "${t}"`);const s=(-1===n?t:t.substring(0,n)).trim();if(0===s.length&&M(`[wcs/binding-syntax] an empty filter in "${e.join("|")}" — remove the extra "|" or name the filter.${E}`),-1===n)return{filterName:s,args:[],literals:[]};return{filterName:s,...H(t.substring(n+1,o))}})}const G=e=>e.trim(),K=e=>"'"===e||'"'===e;function X(e,t){let n=null;for(let o=0;o<e.length;o++){const s=e[o];if(null!==n)s===n&&(n=null);else if(K(s))n=s;else if(s===t)return o}return-1}function Q(e,t){const n=[];let o=null,s=0;for(let i=0;i<e.length;i++){const r=e[i];null!==o?r===o&&(o=null):K(r)?o=r:r===t&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}const J=new Map;function Y(e){const t=X(e,r);let n="",o=[],a="",l=[];-1!==t?(n=e.slice(0,t).trim(),a=e.slice(t+1).trim(),J.has(a)?l=J.get(a):(o=Q(a,r).map(G),l=U(o),J.set(a,l))):n=e.trim();const d=n.split(s).map(G);d.length>2&&M(`[wcs/binding-syntax] "${n}": a binding takes one modifier list after a single "${s}" — write "${d[0]}${s}${d.slice(1).join(",")}".${E}`);const[c,u]=d,f=c.split(i).map(G);return{propName:c,propSegments:f,propModifiers:u?u.split(",").map(G):[],inFilters:l}}const Z=new Map;function ee(e){const t=X(e,r);let n="",o=[],s="",i=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),Z.has(s)?i=Z.get(s):(o=Q(s,r).map(G),i=U(o),Z.set(s,i))):n=e.trim(),-1!==n.indexOf("@")&&M(`"${n}": the "@name" selector was removed in v2 — there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`);return{statePathName:n,statePathInfo:a(n),outFilters:i}}const te=new Set([d,"if","elseif","for",c]),ne=new Set([p,h,g,m,u]);function oe(e){const[...t]=function(e){return Q(e,b)}(e).map(G).filter(e=>e.length>0),n=t.map(e=>{const t=e.indexOf(l);-1===t&&M(`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),p=n.split(s)[0].split(r)[0].trim();if(p!==n&&te.has(p)&&M(`[wcs/binding-syntax] "${e}": "${p}" takes no modifiers or filters on its left side — write "${p}:".${E}`),n===d){o.length>0&&M(`[wcs/binding-syntax] "${e}": "else" takes no value — write "else:".${E}`);const t=a("#else");return{propName:d,propSegments:[d],propModifiers:[],statePathName:"#else",statePathInfo:t,inFilters:[],outFilters:[],bindingType:"else"}}if(n===c){const t=ee(o);return t.outFilters.length>0&&M(`Invalid spread binding "${e}": filters are not allowed on spread targets.`),0===t.statePathName.length&&M(`Invalid spread binding "${e}": spread target path is required.`),{propName:c,propSegments:[c],propModifiers:[],inFilters:[],...t,bindingType:"spread"}}if("if"===n||"elseif"===n||"for"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...ee(o),bindingType:n}}if("radio"===p||"checkbox"===p){const e=ee(o);return{...Y(n),...e,bindingType:p}}{const e=ee(o),t=Y(n);if(""===t.propSegments[0]&&t.propSegments.length>1){const o=t.propSegments.slice(1);return(o.includes("")||ne.has(o[0]))&&M(`[wcs/binding-syntax] "${n}": a leading "." binds an element property by name — write a non-empty property that is not a namespace (${[...ne].join(", ")}).${E}`),{...t,propName:o.join(i),propSegments:o,...e,bindingType:"prop"}}return t.propSegments[0]===u||t.propSegments[0].startsWith(f)?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>j.has(e.bindingType))&&M(`[wcs/template-syntax] Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${E}`)}return n}const se=new WeakMap,ie=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),re=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function ae(t){const n=se.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=re.exec(o);if(null===s)return null;const i=s[1]||e.commentTextPrefix;return ie.has(i)?(se.set(t,s[2]),s[2]):null}function le(e){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...ee(e),bindingType:"text"}}const de=new WeakMap,ce=new WeakSet;let ue=0;async function fe(e){const t=function(e){let t,n=de.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++ue,promise:o,resolve:t},de.set(e,n),ce.has(e)&&n.resolve(),n}(e);await t.promise}function pe(e){const t=de.get(e);void 0===t?ce.add(e):t.resolve()}const he=new WeakMap;function ge(e){const t=he.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,o=t.tagName.toLowerCase();if(o.includes("-"))return n=o;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{he.set(e,n)}}function me(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined?null:t}function be(e=null){if(null!=e){const{customElementRegistry:t,customElements:n}=e;if(null===t)return null;if(void 0!==t)return me(t);if(void 0!==n)return me(n)}return me(globalThis.customElements)}function we(e,t){e.upgrade?.(t)}function ye(e){try{if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const t=e,n=t.addEventListener,o=t.removeEventListener,s=t.constructor?.wcBindable;if("function"!=typeof n||"function"!=typeof o)return null;if("wc-bindable"!==s?.protocol)return null;if(!Number.isInteger(s.version)||s.version<1)return null;const i=Se(s.properties,ve);if(null===i)return null;const r=void 0===s.inputs?new Map:Se(s.inputs,Ne);if(null===r)return null;const a=void 0===s.commands?new Map:Se(s.commands,xe);return null===a?null:{target:e,liveDeclaration:s,knownProperties:i,declaredInputs:r,declaredCommands:a}}catch{return null}}function ve(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&("string"==typeof t.event&&0!==t.event.length&&(void 0===t.getter||"function"==typeof t.getter))}function Ne(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.attribute||"string"==typeof t.attribute)}function xe(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.async||"boolean"==typeof t.async)}function Se(e,t){if(!Array.isArray(e))return null;const n=new Map;for(const o of e){if(!t(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function Ie(e,t){const n="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:n,statePathInfo:a(n),inFilters:[],outFilters:[],bindingType:"prop"}}function Ae(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function Te(t,n,o={}){const s=o.allowDeferred??!0;if(!n.some(e=>"spread"===e.bindingType))return n;const i=[],r=new WeakSet;for(const e of n){if("spread"!==e.bindingType){i.push(e);continue}t.nodeType!==Node.ELEMENT_NODE&&M("Spread binding requires an element node.");const n=t,o=ge(n);null===o&&M(`Spread binding "${e.statePathName}" requires a custom element with wcBindable, but <${n.tagName.toLowerCase()}> is not a custom element.`);const a=be(n);null===a&&M(`CustomElementRegistry is unavailable for <${o}>.`);if(void 0===a.get(o)){s||M(`Spread binding "${e.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),i.push(e);continue}we(a,n);const l=ye(n);null===l&&M(`Spread binding "${e.statePathName}" requires <${o}> to expose a valid wcBindable declaration.`);const d=e.statePathName,c=new Set;for(const e of l.knownProperties.keys()){if(c.has(e))continue;c.add(e);const t=Ie(e,d);r.add(t),i.push(t)}for(const e of l.declaredInputs.keys()){if(c.has(e))continue;c.add(e);const t=Ie(e,d);r.add(t),i.push(t)}}const a=new Map;for(let e=0;e<i.length;e++){const t=Ae(i[e]);null!==t&&a.set(t,e)}const l=[];for(let n=0;n<i.length;n++){const o=Ae(i[n]);if(null!==o){if(a.get(o)===n)l.push(i[n]);else if(e.debug&&r.has(i[n])){const e=i[a.get(o)],s=t.nodeType===Node.ELEMENT_NODE?`<${t.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${i[n].propName}" of ${s} overridden by explicit binding (statePath: "${e.statePathName}").`)}}else l.push(i[n])}return l}function $e(e,t){let n=e;for(let e=0;e<t.length;e++){let o=t[e];for(n=n.firstChild;null!==n&&o>0;)n=n.nextSibling,o--;if(null===n)break}return n}function ke(e,n){if(0===e.length)return e;const o=[];for(let s=0;s<e.length;s++){const i=e[s];o.push({filterName:i.filterName,args:i.args,filterFn:t(i.filterName,i.args,n,i.literals??i.args)})}return o}const Pe=new WeakMap;function Me(e){return Pe.get(e)||null}function Ee(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Ce(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!Ee(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function _e(e,t){for(let n=0;n<t.length;n++){const o=t[n];if(o!==e&&o.contains(e))return!0}return!1}function Re(t){const n=[],o=Ce(t),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(e.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==ae(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const e=s.currentNode;o.length>0&&_e(e,o)||n.push(e)}return n}const Oe=new WeakSet;function Be(e,t,n,o){const s=Te(e,t,{allowDeferred:n.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?ge(e):null;return null===n&&M("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t,transform:o}}}Oe.add(e);const i=function(e,t){const n=[];for(const o of t){const t=ke(o.inFilters,"input"),s=ke(o.outFilters,"output");if("text"!==o.bindingType)n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:e});else{const i=e.nodeType===Node.TEXT_NODE?e:document.createTextNode("");n.push({...o,inFilters:t,outFilters:s,node:e,replaceNode:i})}}return n}(e,function(e,t){return void 0===t?e:e.map(e=>null!=e.uuid?e:t(e))}(s,o));return function(e,t){Pe.set(e,t)}(e,i),pe(e),{bindings:i,deferred:null}}function Le(e,t){const n=Re(e),o=[],s=[];for(const e of n){if(Oe.has(e))continue;const n=Be(e,ua(e),{allowDeferred:!0},t);null===n.deferred?o.push(...n.bindings):s.push(n.deferred)}return[n,o,s]}function We(e){Oe.add(e)}function De(e){const{node:t,parseResults:n,transform:o}=e;!function(e){Oe.delete(e)}(t);return Be(t,n,{allowDeferred:!1},o).bindings}const Fe=new WeakMap;let je=null;function qe(e){je=e}function ze(e){let t=e;for(;t;){const e=Fe.get(t);if(e)return e;let n=t.parentNode;null===n&&null!==je&&t instanceof ShadowRoot&&(n=je(t)),t=n}return null}function Ve(e,t){null!==t?Fe.set(e,t):Fe.delete(e)}const He=new WeakMap;function Ue(e){return He.get(e)??[]}function Ge(e,t){He.set(e,t)}function Ke(e){return He.has(e)}const Xe=new WeakMap;let Qe=null,Je=0;function Ye(e){return Xe.get(e)??[]}function Ze(e,t){null===Qe?Xe.set(e,t):Qe.set(e,t)}function et(){Je++,null===Qe&&(Qe=new Map)}function tt(){if(0!==Je&&(Je--,!(Je>0||null===Qe))){for(const[e,t]of Qe)Xe.set(e,t);Qe=null}}function nt(e){return(Qe?.has(e)??!1)||Xe.has(e)}const ot=Symbol("$$setLoopContext"),st=Symbol("$$getByAddress"),it=Symbol("$$hasByAddress"),rt=Symbol("$$setByAddress"),at=Symbol("$$connectedCallback"),lt=Symbol("$$disconnectedCallback"),dt=Symbol("$$updatedCallback"),ct=Symbol("$$errorCallback"),ut=new WeakMap,ft=new WeakMap;class pt{absolutePathInfo;listIndex;constructor(e,t){this.absolutePathInfo=e,this.listIndex=t}}function ht(e,t){if(null===t){let t=ft.get(e);return void 0!==t||(t=new pt(e,null),ft.set(e,t)),t}{let n=ut.get(t);void 0===n&&(n=new WeakMap,ut.set(t,n));let o=n.get(e);return void 0!==o||(o=new pt(e,t),n.set(e,o)),o}}const gt=new WeakMap;function mt(e,t){let n=gt.get(e);void 0===n&&(n=new Map,gt.set(e,n));let o=n.get(t);return void 0===o&&(o=Object.freeze(new bt(e,t)),n.set(t,o)),o}class bt{pathInfo;stateElement;constructor(e,t){this.pathInfo=t,this.stateElement=e}}function wt(e,t){return ht(mt(e,t.pathInfo),t.listIndex)}function yt(e,t,n){return ht(mt(e,t),n)}const vt=new WeakMap;function Nt(e,t){null===t?vt.delete(e):vt.set(e,t)}function xt(e){return vt.get(e)||null}const St=new Map;function It(e,t){let n,o;if(0===e.wildcardCount||0===t.wildcardCount)return 0;if(1===e.wildcardCount&&t.wildcardCount>0&&t.wildcardPathSet.has(e.path))return 1;e.id<t.id?(n=e,o=t):(n=t,o=e);const s=`${n.path}\t${o.path}`;let i=St.get(s);if(void 0!==i)return i;return i=n.wildcardPathSet.intersection(o.wildcardPathSet).size,St.set(s,i),i}function At(e,t,n){return t<0||t>=n?null:e.at(t-n)}function Tt(e,t){const n=e.indexes??[];return n.length===t?n:n.slice(n.length-t)}const $t=new WeakMap;function kt(e){const t=ze(e.node);if(null===t)return null;let n=$t.get(t);if(void 0===n)n=new WeakMap,$t.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=It(t.pathInfo,e.statePathInfo);return n>0&&(o=At(t.listIndex,n-1,t.pathInfo.wildcardCount)),o}finally{n.set(e,o)}}const Pt=new WeakMap;function Mt(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=xt(n);null===t?M(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function Et(e,t){let n=null;if(n=Pt.get(e)||null,null!==n)return n;const o=Mt(e,t),s=kt(e),i=Zr(o);return null===i&&M("No state tree found on this root for binding."),n=yt(i,e.statePathInfo,s),Pt.set(e,n),n}function Ct(e){Pt.delete(e)}const _t=new WeakMap;function Rt(e,t){const n=_t.get(e);void 0===n?_t.set(e,t):n instanceof Set?n.add(t):n!==t&&_t.set(e,new Set([n,t])),null!==w&&w({type:"state:binding-added",absoluteAddress:e,binding:t})}function Ot(e,t){const n=_t.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&_t.delete(e),null!==w&&w({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const Bt=new WeakMap;function Lt(e){const t=_t.get(e);return void 0!==t?t:null!==e.listIndex?Bt.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const Wt=new WeakMap,Dt=new WeakMap;class Ft{pathInfo;listIndex;_parentAddress;constructor(e,t){this.pathInfo=e,this.listIndex=t}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const e=this.pathInfo.parentPathInfo;if(null===e)return null;let t=null;return t=this.pathInfo.segments[this.pathInfo.segments.length-1]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=jt(e,t)}}function jt(e,t){if(null===t){let t=Dt.get(e);return void 0!==t||(t=new Ft(e,null),Dt.set(e,t)),t}{let n=Wt.get(t);void 0===n&&(n=new WeakMap,Wt.set(t,n));let o=n.get(e);return void 0!==o||(o=new Ft(e,t),n.set(e,o)),o}}const qt=new WeakMap;function zt(e){let t=null;if(t=qt.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=kt(e);null===n&&M(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=jt(e.statePathInfo,n)}else t=jt(e.statePathInfo,null);return qt.set(e,t),t}function Vt(e){qt.delete(e)}function Ht(){const e=new Map,t=new Map;return{add(n,o){let s=e.get(n);return void 0===s&&(s=new WeakSet,e.set(n,s)),!s.has(o)&&(s.add(o),t.set(n,(t.get(n)??0)+1),!0)},remove(n,o){const s=e.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const i=(t.get(n)??1)-1;return i<=0?(e.delete(n),t.delete(n),!0):(t.set(n,i),!1)},has:(t,n)=>e.get(t)?.has(n)??!1,countOf:e=>t.get(e)??0,get keyCount(){return t.size},clear(){e.clear(),t.clear()}}}const Ut=new Map,Gt=Ht();function Kt(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.statePathName}::${t}::${n}`}function Xt(e){let t="input";for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}function Qt(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(v)){const o=Xt(e),s=Kt(e,o);let i=Ut.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==o.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const s=o.checked;let i=o.value;for(const e of n)i=e.filterFn(i);const r=Zr(o.getRootNode());null===r&&M("No state tree found on this root for two-way binding.");const a=ze(o);r.createState("writable",e=>{e[ot](a,()=>{let n=e[t];if(Array.isArray(n))if(s)-1===n.indexOf(i)&&(e[t]=n.concat(i));else{const o=n.indexOf(i);-1!==o&&(e[t]=n.toSpliced(o,1))}else e[t]=s?[i]:[]})})},Ut.set(s,i)),e.node.addEventListener(o,i),Gt.add(s,e),!0}var t,n;return!1}function Jt(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function Yt(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)Jt(e)&&Promise.resolve(e).catch(e=>{console.error(`[wcstack/state] ${t} rejected.`,e)})}class Zt{_name;_subscribers=new Set;constructor(e){this._name=e}get name(){return this._name}get size(){return this._subscribers.size}subscribe(e){return this._subscribers.add(e),()=>{this._subscribers.delete(e)}}unsubscribe(e){return this._subscribers.delete(e)}emit(...e){const t=[];for(const n of this._subscribers)t.push(n(...e));return t}}class en extends Zt{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==w&&w({type:"state:token-emit",kind:"event",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}const tn=new WeakMap;function nn(e,t){let n=tn.get(e);void 0===n&&(n=new Map,tn.set(e,n));let o=n.get(t);return void 0===o&&(o=new en(t,e),n.set(t,o)),o}function on(e){tn.delete(e)}const sn=new WeakMap;function rn(e){if(e.propSegments[0]!==u)return!1;const t=e.node,n=ge(t),o=be(t);if(null!==n&&void 0===o?.get(n))return null===o&&M(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(sn.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||M('eventToken binding requires a property name (e.g., "eventToken.error").');const i=function(e){return null===ge(e)?null:ye(e)}(t);null===i&&M(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=i.knownProperties.get(s);void 0===r&&M(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.${C(s,i.knownProperties.keys())}`);const a=r.event,l=e.statePathName,d=e.propModifiers,c=e=>{d.includes(N)&&e.preventDefault(),d.includes(x)&&e.stopPropagation();const n=Zr(t.getRootNode());null===n&&M("No state tree found on this root for eventToken handler."),n.eventTokenNames.has(l)||M(`[wcs/token-undeclared] eventToken "${l}" is not declared in $eventTokens.${C(l,n.eventTokenNames)}${E}`);const o=ze(t);n.createStateAsync("writable",async t=>{Yt(t[ot](o,()=>{const s=null!==o?Tt(o.listIndex,o.pathInfo.wildcardCount):[];return nn(n,l).emit(t,e,...s)}),`$on."${l}"`)})};return t.addEventListener(a,c),sn.set(e,{eventName:a,handler:c}),!0}class an extends Zt{_stateElement;constructor(e,t){super(e),this._stateElement=t}emit(...e){return null!==w&&w({type:"state:token-emit",kind:"command",tokenName:this.name,args:e,subscriberCount:this.size,stateElement:this._stateElement}),super.emit(...e)}}function ln(e){return e instanceof an}const dn=new Map,cn=Ht();function un(e){const t=e.propModifiers.filter(e=>e===N||e===x).sort().join(",");return`${e.statePathName}::${t}`}const fn=(e,t,n)=>o=>{t.includes(N)&&o.preventDefault(),t.includes(x)&&o.stopPropagation();const s=o.target,i=s.getRootNode(),r=Zr(i);null===r&&M("No state tree found on this root for event handler.");const a=ze(s),l=e.startsWith(S+".");r.createStateAsync("writable",async t=>{Yt(t[ot](a,()=>{let d=null!==a?a.pathInfo.wildcardCount:0;if(null!==a){const e=r.addressHooks;if(e){const t=e.handlerScope;for(let e=0;e<t.length;e++)d=t[e](r,s,i,a,d)}}const c=null!==a?Tt(a.listIndex,d):[];if(l){const s=t[st](jt(n,null));return ln(s)||M(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),s.emit(o,...c)}const u=t[e];return"function"!=typeof u&&M(`Handler "${e}" is not a function on the state tree.`),Reflect.apply(u,t,[o,...c])}),`"${e}"`)})};function pn(e){if(!e.propName.startsWith(f))return!1;const t=un(e);let n=dn.get(t);void 0===n&&(n=fn(e.statePathName,e.propModifiers,e.statePathInfo),dn.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),cn.add(t,e),!0}function hn(e){if(!e.propName.startsWith(f))return!1;const t=un(e),n=dn.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);return e.node.removeEventListener(o,n),0!==cn.countOf(t)&&(cn.remove(t,e)&&dn.delete(t),!0)}const gn=new Map,mn=Ht();function bn(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.statePathName}::${t}::${n}`}function wn(e){let t="input";for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}function yn(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(v)){const o=wn(e),s=bn(e,o);let i=gn.get(s);return void 0===i&&(t=e.statePathName,n=e.inFilters,i=e=>{const o=e.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==o.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===o.checked)return;let s=o.value;for(const e of n)s=e.filterFn(s);const i=Zr(o.getRootNode());null===i&&M("No state tree found on this root for two-way binding.");const r=ze(o);i.createState("writable",e=>{e[ot](r,()=>{e[t]=s})})},gn.set(s,i)),e.node.addEventListener(o,i),mn.add(s,e),!0}var t,n;return!1}const vn=new Set(["radio","checkbox"]),Nn=new Set(["value","valueAsNumber","valueAsDate"]);function xn(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,o=n.tagName.toLowerCase();if("input"===o){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(vn.has(e)&&"checked"===t)return!0;if(Nn.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=ge(n);if(null!==s){const e=be(n)?.get(s);void 0===e&&M(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=ye(n);if(o?.knownProperties.has(t))return!0}return!1}let Sn=1,In=1,An=1;const Tn=new WeakMap;function $n(e,t,n){let o=Tn.get(e);void 0===o&&(o=new Map,Tn.set(e,o));const s=function(e,t){return`${t}::${e}`}(t,n);let i=o.get(s);return void 0===i&&(i=Sn++,o.set(s,i)),i}function kn(e,t){return"to-element"===t?2*e:2*e+1}const Pn=new Set;function Mn(e){return{transactionId:In++,originBindingId:e,visitedEdges:Pn,hop:0}}function En(e,t){const n=new Set(e.visitedEdges);return n.add(t),{transactionId:e.transactionId,originBindingId:e.originBindingId,visitedEdges:n,hop:e.hop+1}}let Cn=null;function _n(){return Cn}function Rn(e,t){const n=Cn;Cn=e;try{return t()}finally{Cn=n}}const On=[];let Bn=!1;function Ln(){return!!Bn&&(Bn=!1,!0)}const Wn=new Map,Dn=Ht(),Fn=new WeakMap,jn=e=>e.detail,qn=new WeakMap;function zn(e,t,n,o){const s=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.propName}::${e.statePathName}::${t}::${s}::${n?"g":"n"}::${o?"o":"s"}`}function Vn(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=ge(e.node);if(null!==n){const o=be(e.node)?.get(n);void 0===o&&M(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=ye(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith(f)&&(t=n.slice(f.length));return t}function Hn(e){if(null!==ge(e.node)){const t=ye(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??jn}return null}function Un(e){if(null===ge(e.node))return!1;const t=ye(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}const Gn=(t,n,o,s,i)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(r),s!==jn||i||function(e,t,n){const o=e[t];let s=null;if(void 0===n?void 0!==o&&(s=`the event carried no detail (undefined) while element.${t} is ${typeof o}`):null===n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,t)||null!==o&&"object"==typeof o||(s=`the event's detail is an object with a "${t}" key while element.${t} is ${typeof o}`),null===s)return;let i=qn.get(e);void 0===i&&(i=new Set,qn.set(e,i)),i.has(t)||(i.add(t),console.warn(`[@wcstack/state] [wcs/default-getter-mismatch] <${e.tagName.toLowerCase()}> "${t}": ${s}. With no getter, state receives e.detail as-is. Dispatch the value itself as detail, or declare getter (e.g. (e) => e.detail.${t}, or (e) => e.target.${t}) on that wcBindable property.`))}(a,t,l);else{if(!(t in a))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);l=a[t]}let d=l;for(const e of o)d=e.filterFn(d);const c=Fn.get(a)?.get(t);if(void 0!==c)for(const e of c)e(d);let u=null;if(e.enablePropagationContext){const o=$n(a,t,n),s=function(e,t){for(let n=On.length-1;n>=0;n--){const o=On[n];if(o.node===e&&o.receipt.member===t)return o.receipt}return null}(a,t);if(null!==s&&Object.is(s.writtenValue,l))return e.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:a,propName:t,statePathName:n,transactionId:s.transactionId,coveredBySameValueGuard:e.sameValueGuard&&(null===d||"object"!=typeof d)}),void(null!==w&&w({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:kn(o,"to-state"),node:a,member:t}));const i=kn(o,"to-state"),r=_n();if(null!==r&&r.visitedEdges.has(i))return void(null!==w&&w({type:"propagation:suppressed",reason:"visited-edge",transactionId:r.transactionId,edgeId:i,node:a,member:t}));u=En(r??Mn(o),i)}const f=Zr(a.getRootNode());null===f&&M("No state tree found on this root for two-way binding.");const p=ze(a),h=()=>{i&&(Bn=!0);try{f.createState("writable",e=>{e[ot](p,()=>{e[n]=d})})}finally{i&&(Bn=!1)}};null!==u?Rn(u,h):h()};const Kn=new WeakSet;function Xn(e){Kn.add(e)}function Qn(e){return!!Kn.has(e)&&(Kn.delete(e),!0)}const Jn=new WeakMap;function Yn(e,t){const n=Jn.get(e);return!(void 0===n||n<t)&&(n===t?Jn.delete(e):Jn.set(e,n-t),!0)}const Zn=new WeakSet;function eo(e){Zn.add(e)}function to(e){return!!Zn.has(e)&&(Zn.delete(e),!0)}let no=0;function oo(){no--}function so(){return no>0}class io{registry;entries=new Map;constructor(e){this.registry=e}wait(e,t,n=()=>{}){const o=e.toLowerCase();let s=this.entries.get(o);void 0===s&&(s={waiters:new Set},this.entries.set(o,s),this.registry.whenDefined(o).then(()=>this.settle(o,null),e=>this.settle(o,e)));const i={active:!0,resolve:t,reject:n};return s.waiters.add(i),()=>{i.active&&(i.active=!1,s?.waiters.delete(i))}}pendingCount(e){return this.entries.get(e.toLowerCase())?.waiters.size??0}settle(e,t){const n=this.entries.get(e);if(void 0===n)return;this.entries.delete(e);const o=Array.from(n.waiters);n.waiters.clear();for(const e of o)e.active&&(e.active=!1,null===t?e.resolve():e.reject(t))}}const ro=new WeakMap;function ao(e){let t=ro.get(e);return void 0===t&&(t=new io(e),ro.set(e,t)),t}function lo(e,t){let n=null;for(const o of e.propModifiers){const e=o.indexOf("=");if(e<0)continue;const s=o.slice(0,e).trim(),i=o.slice(e+1).trim();s!==I&&s!==A&&M(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&M(`Binding modifier "${t}" may only be specified once.`),n=i)}return n}function co(e){return e.propModifiers.some(e=>e.includes("="))}const uo=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),fo=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function po(e,t){return"state"===e&&"call"===t?uo:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function ho(t){if(!e.enableDirectionalInitialSync)return co(t)&&M("init=/sync= modifiers require enableDirectionalInitialSync."),uo;const n=null===(o=lo(t,I))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:M(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":M(`Invalid sync modifier value "${e}".`)}(lo(t,A));if("event"===t.bindingType)return null!==n&&"none"!==n&&M("Event bindings only allow init=none."),"call"===s?fo:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if(t.propSegments[0]===m)return po("state",s);if("prop"!==t.bindingType)return null!==n&&"state"!==n&&"none"!==n&&M(`Binding type "${t.bindingType}" does not support init=${n}.`),po(n??"state",s);const i=ye(t.node);if(null===i)return po(n??"state",s);const r=i.knownProperties.has(t.propName),a=i.declaredInputs.has(t.propName);r||a||M(`Property "${t.propName}" is not declared by wcBindable.`);const l=n??(r&&!a?"element":"state");return(r&&a?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(l)||M(`init=${l} is incompatible with wcBindable member "${t.propName}".`),"connect"!==s||r||M(`sync=connect requires observable property "${t.propName}".`),{authority:l,syncOn:s,observable:r,outputOnly:r&&!a}}function go(e,t){return"auto"!==t?t:function(e){const t=Zr(e.replaceNode.getRootNode());null===t&&M("No state tree found on this root for binding.");const n=zt(e);let o=!1;return t.createState("readonly",e=>{o=e[it](n)}),o}(e)?"state":"element"}let mo=0,bo=0;const wo=["active","disposed","failed"],yo=new WeakMap,vo=new WeakMap,No=new WeakMap,xo=new WeakMap,So=new WeakMap;function Io(e,t){const n=So.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):So.set(e,new Set([n,t]))):So.set(e,t)}function Ao(e){return So.has(e)}function To(e,t){const n=So.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function $o(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))$o(n,t)}function ko(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Po{root;observer;constructor(e){this.root=e;const t=globalThis.MutationObserver;this.observer="function"==typeof t?new t(e=>this.handleMutations(e)):null,this.observer?.observe(e,{childList:!0,subtree:!0})}handleMutations(e){const t=[],n=[];for(let o=0;o<e.length;o++){const s=e[o],i=s.removedNodes;if(0===i.length||!Yn(s.target,i.length))for(let e=0;e<i.length;e++)t.push(i[e]);const r=s.addedNodes;for(let e=0;e<r.length;e++)n.push(r[e])}const o=[];for(const e of t)Qn(e)||$o(e,e=>{To(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)to(e)&&!so()||$o(e,e=>{To(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&Lr(o)}}const Mo=new WeakMap;function Eo(e){let t=Mo.get(e);return void 0===t&&(t=new Po(e),Mo.set(e,t)),t}function Co(e){const t=e.inFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|"),n=e.outFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.bindingType,e.propName,e.propModifiers.join(","),e.statePathName,t,n,e.uuid??""].join("\0")}function _o(e,t,n){const o=Zr(Mt(e,n));null===o&&M("No state tree found on this root for binding.");const s=mt(o,e.statePathInfo);return function(e,t,n){let o=Bt.get(e);void 0===o&&(o=new WeakMap,Bt.set(e,o));const s=o.get(t);void 0===s?o.set(t,n):s instanceof Set?s.add(n):s!==n&&o.set(t,new Set([s,n])),null!==w&&w({type:"state:binding-added",absoluteAddress:ht(e,t),binding:n})}(s,t,e),s}function Ro(e,t){const n=Et(e,t);return Rt(n,e),n}function Oo(e,t,n,o){null!==t?Ot(t,e):function(e,t,n){const o=Bt.get(e);if(void 0===o)return;const s=o.get(t);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(t),null!==w&&w({type:"state:binding-removed",absoluteAddress:ht(e,t),binding:n}))}(n,o,e),Vt(e),Ct(e)}function Bo(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class Lo{records=new Set;rowPlan=null;rows=new Set;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(e=null){null!==e&&this.observe(e)}initialize(e,t={},n){const o=t.registerAddress??!0,s={registerAddress:o,registerPathInfo:t.registerPathInfo??o,applyOnReconnect:t.applyOnReconnect??!0},i=[];for(const t of e){const e=this.remember(t,s),o=this.rowOf(e),r=null===o?-1:o.bindings.indexOf(e);if(null!==o&&0===o.phases[r]){const t=o;this.observe(e.replaceNode),s.registerAddress&&null===t.addresses[r]&&null===t.patternPathInfos[r]&&(t.registered=!0,this.registerRowSlot(t,r));continue}const a=vo.get(e);void 0===a||"disposed"===a.phase||"failed"===a.phase?(this.start(e,s,n),i.push(e)):(this.observe(a.anchor),s.registerAddress&&null===a.address&&null===a.patternListIndex&&(a.options.registerAddress=!0,this.registerAddress(a)),"active"===a.phase&&this.settleInitialRecord(a),this.settleConnectedSnapshot(a))}return i.filter(e=>this.shouldApplyState(e))}activate(e,t){if(ko(t)&&Eo(t),null===this.rowPlan)for(const n of e){const e=vo.get(n);if(void 0!==e&&e.session===this&&"disposed"!==e.phase&&"failed"!==e.phase){null===e.address&&null===e.patternListIndex&&(e.options.registerAddress=!0,this.registerAddress(e,t)),"active"===e.phase&&this.settleInitialRecord(e),this.settleConnectedSnapshot(e);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,t)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,e,t)}shouldApplyState(t){if(!e.enableDirectionalInitialSync)return co(t)&&ho(t),!0;const n=this.rowOf(t);if(null!==n){const e=n.bindings.indexOf(t);if(e>=0){if(!n.registered)return!0;if(2===n.phases[e])return!1;const t=n.plan.slots[e];return 1&n.flags[e]?"state"===t.authority||!t.policy.outputOnly:(n.flags[e]|=1,"state"===t.authority)}}const o=vo.get(t);return void 0===o||o.session!==this||(!o.options.registerAddress||"waiting-definition"===o.phase||"failed"!==o.phase&&("active"===o.phase&&this.settleInitialRecord(o),o.initialApplyDone?"state"===o.resolvedAuthority||!o.outputOnlyMember&&!o.observationPending:(o.initialApplyDone=!0,"state"===o.resolvedAuthority)))}getRecord(e){const t=this.rowOf(e),n=null===t?-1:t.bindings.indexOf(e);if(null!==t&&n>=0)return{id:64*t.id+n,info:e,generation:t.generation,phase:wo[t.phases[n]],teardowns:null};const o=vo.get(e);return o?.session===this?o:null}addTeardown(e,t){const n=vo.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(Bo(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=be(e);null===s&&M(`CustomElementRegistry is unavailable for <${t}>.`),this.observe(e),Io(e,this);const i={node:e,active:!0,cancel:null};let r=this.deferredByNode.get(e);void 0===r&&(r=new Set,this.deferredByNode.set(e,r)),r.add(i),this.deferred.add(i);const a=()=>!!i.active&&(i.active=!1,r?.delete(i),this.deferred.delete(i),!0);return i.cancel=ao(s).wait(t,()=>{if(a())try{we(s,e),n()}catch(e){o(e)}},e=>{a()&&o(e)}),()=>{a()&&i.cancel?.()}}disposeBinding(e){const t=this.rowOf(e);if(null!==t){const n=t.bindings.indexOf(e);if(n>=0)return void this.disposeRowSlot(t,n)}const n=vo.get(e);void 0!==n&&n.session===this&&this.disposeRecord(n)}get isRowSession(){return null!==this.rowPlan}get currentRowPlan(){return this.rowPlan}disposeBindings(e){for(let t=0;t<e.length;t++)this.disposeBinding(e[t]);if(!(this.rows.size>0))for(const e of Array.from(this.deferred))e.active=!1,e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}destroyRow(e){const t=e.length>0?this.rowOf(e[0]):null;null!==t?(this.destroyRowRecord(t),this.rows.delete(t)):this.destroyRecords()}destroyRowRecord(e){for(let t=0;t<e.bindings.length;t++){const n=e.addresses[t];null!==n&&(Ot(n,e.bindings[t]),e.addresses[t]=null),e.phases[t]=1}}dispose(){for(const e of Array.from(this.rows))for(let t=0;t<e.bindings.length;t++)this.disposeRowSlot(e,t);for(const e of Array.from(this.records))this.disposeRecord(e);for(const e of Array.from(this.deferred))e.active=!1,e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;if(0===this.records.size)return!0;for(const e of this.records)if(e.pendingDefinitions>0||e.observationPending)return!1;return!0}destroyRecords(){for(const e of this.rows)this.destroyRowRecord(e);this.rows.clear();for(const e of this.records)null!==e.address&&(Ot(e.address,e.info),e.address=null),e.phase="disposed",e.teardowns=null;this.records.clear()}forEachActiveBindingNode(e){for(const t of this.rows)for(let n=0;n<t.bindings.length;n++)0===t.phases[n]&&e(t.bindings[n].node);for(const t of this.records)"active"===t.phase&&e(t.info.node)}rebindAddresses(){const e=[];for(const t of this.rows)for(let n=0;n<t.bindings.length;n++){if(0!==t.phases[n])continue;if(null===t.addresses[n]&&null===t.patternPathInfos[n])continue;const o=t.bindings[n];this.unregisterRowSlot(t,n),this.registerRowSlot(t,n),this.shouldApplyState(o)&&e.push(o)}for(const t of this.records){if("active"!==t.phase)continue;const n=t.info;if(null===t.address&&null===t.patternListIndex)continue;const o="for"===n.bindingType?Et(n):null;if(Oo(n,t.address,t.patternPathInfo,t.patternListIndex),t.address=null,t.patternPathInfo=null,t.patternListIndex=null,this.registerAddress(t),null!==o){const e=Et(n);e!==o&&Ke(o)&&Ge(e,Ue(o)),e!==o&&nt(o)&&Ze(e,Ye(o))}this.shouldApplyState(n)&&e.push(n)}return e}observe(e){const t=function(e){const t=e.getRootNode();return ko(t)?t:null}(e);null!==t&&Eo(t)}handleMutations(e,t,n){for(const n of t)$o(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)$o(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&Lr(o)}handleRemovedNode(e){const t=this.knownBindingsByNode.get(e);if(void 0!==t)if(t instanceof Map)for(const e of t.values())this.disposeBinding(e);else this.disposeBinding(t);const n=this.deferredByNode.get(e);if(void 0!==n)for(const e of Array.from(n))e.active=!1,e.cancel?.(),n.delete(e),this.deferred.delete(e)}handleAddedNode(e,t){const n=this.knownBindingsByNode.get(e);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const e of o){const n=vo.get(e);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(e);if(void 0!==o)try{this.start(e,o),o.applyOnReconnect&&this.shouldApplyState(e)&&t.push(e)}catch{}}}knownMapFor(e){const t=this.knownBindingsByNode.get(e);if(t instanceof Map)return t;const n=new Map;if(void 0!==t){let e=xo.get(t);void 0===e&&(e=Co(t),xo.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;Io(n,this);const o=this.knownMapFor(n);let s=xo.get(e);void 0===s&&(s=Co(e),xo.set(e,s));const i=o.get(s);if(void 0!==i){const e=this.optionsByBinding.get(i);return void 0!==e&&(e.registerAddress||=t.registerAddress,e.registerPathInfo||=t.registerPathInfo,e.applyOnReconnect||=t.applyOnReconnect),i}return o.set(s,e),this.optionsByBinding.set(e,{...t}),e}initializeRow(e,t){this.rowPlan=e;const n=e.slots,o=t.length,s={id:++mo,session:this,generation:++bo,plan:e,bindings:t,registered:!1,phases:new Array(o).fill(0),flags:new Array(o).fill(0),addresses:new Array(o).fill(null),patternPathInfos:new Array(o).fill(null),patternListIndexes:new Array(o).fill(null)};this.rows.add(s);for(let e=0;e<o;e++){const o=t[e],i=o.replaceNode;if(Io(i,this),this.addKnownRowBinding(i,o,e),yo.set(o,s),n[e].isEvent){try{pn(o)}catch(t){throw s.phases[e]=2,t}s.flags[e]|=2}}}activatePlanRows(e,t,n){const o=t.length>0?this.rowOf(t[0]):null;if(null===o||o.bindings!==t){for(const e of t)this.initialize([e],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});return}o.registered=!0;const s=e.slots;let i=!1;for(let e=0;e<t.length;e++)if(0===o.phases[e])null===o.addresses[e]&&null===o.patternPathInfos[e]&&this.registerRowSlot(o,e,n);else{if(i||(o.generation=++bo,i=!0,this.rows.add(o)),o.phases[e]=0,o.flags[e]=0,s[e].isEvent){try{pn(t[e])}catch(t){throw o.phases[e]=2,this.runRowSlotTeardowns(o,e),t}o.flags[e]|=2}this.registerRowSlot(o,e,n)}}rowOf(e){const t=yo.get(e);return void 0!==t&&t.session===this?t:null}registerRowSlot(e,t,n){if(null!==e.addresses[t]||null!==e.patternPathInfos[t])return;const o=e.bindings[t],s=kt(o);null!==s?(e.patternPathInfos[t]=_o(o,s,n),e.patternListIndexes[t]=s):e.addresses[t]=Ro(o,n)}unregisterRowSlot(e,t){const n=e.addresses[t],o=e.patternPathInfos[t];null===n&&null===o||(Oo(e.bindings[t],n,o,e.patternListIndexes[t]),e.addresses[t]=null,e.patternPathInfos[t]=null,e.patternListIndexes[t]=null)}disposeRowSlot(e,t){if(1!==e.phases[t]){e.phases[t]=1,this.runRowSlotTeardowns(e,t);for(let t=0;t<e.phases.length;t++)if(0===e.phases[t])return;this.rows.delete(e)}}runRowSlotTeardowns(e,t){try{this.unregisterRowSlot(e,t)}catch{}if(2&e.flags[t]){e.flags[t]&=-3;try{hn(e.bindings[t])}catch{}}}addKnownRowBinding(e,t,n){const o=this.knownBindingsByNode.get(e);if(void 0===o)return void this.knownBindingsByNode.set(e,t);if(o instanceof Map)return void o.set("@plan:"+n,t);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,t),this.knownBindingsByNode.set(e,s)}start(e,t,n){!function(e){const t=e.node,n=e.replaceNode;t!==n&&null!==t.parentNode&&t.parentNode.replaceChild(n,t)}(e);const o=this.optionsByBinding.get(e)??{...t},s={id:++mo,info:e,generation:++bo,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:null,resolvedAuthority:null,initialSettled:!1,initialApplyDone:!1,outputOnlyMember:!1,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};vo.set(e,s),this.records.add(s),void 0===n&&this.observe(s.anchor);try{s.phase="attaching",this.attachListeners(s),s.options.registerAddress&&this.registerAddress(s,n),0===s.pendingDefinitions&&(s.phase="active")}catch(e){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),e}}attachListeners(t){const n=t.info;pn(n)?t.eventAttached=!0:n.propSegments[0]!==u?(yn(n)&&Bo(t,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(v)){const t=wn(e),n=bn(e,t),o=gn.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==mn.countOf(n)&&(mn.remove(n,e)&&gn.delete(n),!0))}return!1}(n)),Qt(n)&&Bo(t,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(v)){const t=Xt(e),n=Kt(e,t),o=Ut.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Gt.countOf(n)&&(Gt.remove(n,e)&&Ut.delete(n),!0))}return!1}(n)),this.attachAfterDefinition(t,()=>{if(e.enableDirectionalInitialSync&&xn(n.node,n.propName)&&-1===n.propModifiers.indexOf(v)){const e=function(e,t,n){let o=Fn.get(e);void 0===o&&(o=new Map,Fn.set(e,o));let s=o.get(t);return void 0===s&&(s=new Set,o.set(t,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(t),0===o?.size&&Fn.delete(e)}}(n.node,n.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});Bo(t,e)}!function(e){const t=ge(e.node);if(null!==t){const n=be(e.node),o=n?.get(t);if(void 0===o)return void(null===n&&M(`CustomElementRegistry is unavailable for <${t}>.`))}if(xn(e.node,e.propName)&&-1===e.propModifiers.indexOf(v)){const t=Vn(e),n=Hn(e),o=Un(e),s=zn(e,t,null!==n,o);let i=Wn.get(s);void 0===i&&(i=Gn(e.propName,e.statePathName,e.inFilters,n,o),Wn.set(s,i)),e.node.addEventListener(t,i),Dn.add(s,e)}}(n),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{rn(n)&&Bo(t,()=>function(e){if(e.propSegments[0]!==u)return!1;const t=sn.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),sn.delete(e),!0)}(n))})}attachAfterDefinition(e,t){const n=ge(e.info.node);if(null===n)return void t();const o=be(e.info.node);if(null===o&&M(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation,i=ao(o).wait(n,()=>{if(this.isAlive(e,s))try{we(o,e.info.node),t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e))}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))});Bo(e,i)}settleInitialRecord(t){if(e.enableDirectionalInitialSync&&!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=ho(t.info),n=go(t.info,e.authority);if(t.initialPolicy=e,t.resolvedAuthority=n,t.initialSettled=!0,t.outputOnlyMember=e.outputOnly,t.phase="active",!e.observable)return;if("connect"===e.syncOn&&t.info.node instanceof HTMLElement&&!t.info.node.isConnected)return t.observationPending=!0,void no++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(e,t){if(!this.isAlive(e,e.generation))return;const n=e.info.node,o=e.info.propName;if(!(o in n))return;const s=e.eventSequence,i=n[o];e.observationPending&&(e.observationPending=!1,oo()),t&&e.eventSequence!==s||(e.hasProducerValue=!0,e.producerValue=i,"element"===e.resolvedAuthority&&function(e,t){let n=t;for(const t of e.inFilters)n=t.filterFn(n);const o=Zr(e.node.getRootNode());null===o&&M("No state tree found on this root for initial binding sync.");const s=ze(e.node);o.createState("writable",t=>{t[ot](s,()=>{t[e.statePathName]=n})})}(e.info,i))}settleConnectedSnapshot(t){if(e.enableDirectionalInitialSync&&t.observationPending&&t.info.node instanceof HTMLElement&&t.info.node.isConnected)try{this.readProducerSnapshot(t,!1)}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}}registerAddress(e,t){if(null!==e.address||null!==e.patternListIndex)return;const n=e.info,o=kt(n);if(null!==o?(e.patternPathInfo=_o(n,o,t),e.patternListIndex=o):e.address=Ro(n,t),!e.options.registerPathInfo)return;const s=Zr(n.replaceNode.getRootNode());null===s&&M("No state tree found on this root for binding."),"event"!==n.bindingType&&s.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&vo.get(e.info)===e&&"disposed"!==e.phase&&"failed"!==e.phase}disposeRecord(e){"disposed"!==e.phase&&(e.phase="disposed",this.runTeardowns(e),this.records.delete(e))}runTeardowns(e){e.observationPending&&(e.observationPending=!1,oo());const t=e.info;if(null!==e.address||null!==e.patternListIndex)try{Oo(t,e.address,e.patternPathInfo,e.patternListIndex),e.address=null,e.patternPathInfo=null,e.patternListIndex=null}catch{}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=ge(e.node);if(null!==t){const n=be(e.node),o=n?.get(t);if(void 0===o)return}if(xn(e.node,e.propName)&&-1===e.propModifiers.indexOf(v)){const t=Vn(e),n=zn(e,t,null!==Hn(e),Un(e)),o=Wn.get(n);if(void 0===o)return;e.node.removeEventListener(t,o),Dn.remove(n,e)&&Wn.delete(n)}}(t)}catch{}}if(null!==e.teardowns){const t=Array.from(e.teardowns).reverse();e.teardowns=null;for(const e of t)try{e()}catch{}}if(e.eventAttached){e.eventAttached=!1;try{hn(t)}catch{}}}}function Wo(e){let t=No.get(e);return void 0===t&&(t=new Lo(e),No.set(e,t)),t}function Do(e){return vo.get(e)?.session??yo.get(e)?.session??null}let Fo=null;function jo(e){Fo=e}function qo(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const zo=Object.freeze([]);const Vo=new WeakMap;const Ho=new WeakMap;function Uo(e){return Ho.get(e)??[]}function Go(e,t){Ho.set(e,t)}const Ko=new WeakMap;function Xo(e){return Ko.get(e)??[]}function Qo(e,t){Ko.set(e,t)}Set.prototype.difference||(Set.prototype.difference=function(e){const t=new Set(this);for(const n of e)t.delete(n);return t}),Set.prototype.intersection||(Set.prototype.intersection=function(e){const t=new Set;for(const n of e)this.has(n)&&t.add(n);return t});let Jo=0;function Yo(){return`u${(Jo++).toString(36)}`}let Zo=0,es=0;const ts=Symbol("wcs.listIndex.noValue");class ns{uuid=Yo();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;_chainGeneration;_homeParentListIndex;_value;constructor(e,t,n){this.parentListIndex=e,this.position=e?e.position+1:0,this.length=this.position+1,this._homeParentListIndex=n,this._value=ts,this._index=t,this._version=Zo,this._chainGeneration=es}get index(){return this._index}set index(e){this._index=e,this._version=++Zo,this.indexes[this.position]=e}get version(){return this._version}get homeParentListIndex(){return this._homeParentListIndex}get value(){return this._value}set value(e){this._value=e}get dirty(){return null!==this.parentListIndex&&(this.parentListIndex.dirty||this.parentListIndex.version>this._version)}get indexes(){return null===this.parentListIndex?void 0===this._indexes&&(this._indexes=[this._index]):(void 0===this._indexes||this.dirty)&&(this._indexes=[...this.parentListIndex.indexes,this._index],this._version=Zo),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0!==this._listIndexes&&this._chainGeneration===es||(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)],this._chainGeneration=es),this._listIndexes}get varName(){return`$${this.position+1}`}reparent(e){this.parentListIndex=e,this._indexes=void 0,this._listIndexes=void 0,this._version=++Zo,es++}at(e){return e>=0?this.listIndexes[e]?.deref()||null:this.listIndexes[this.listIndexes.length+e]?.deref()||null}}function os(e,t,n=e){return new ns(e,t,n)}function ss(e,t){e.reparent(t)}function is(e){return e.homeParentListIndex}function rs(e,t){e.value=t}function as(e,t){const n=e.value;return n!==ts&&n===t.value}const ls=new WeakMap,ds=new WeakSet;function cs(e){return ds.has(e)}function us(e,t){const n=is(e),o=e.parentListIndex;return null===n||n===o||ds.has(n)?function(e,t,n){return null!==e&&null!==n&&n!==t&&!!ds.has(e)&&!ds.has(n)&&n.position===e.position&&as(n,e)}(n,o,t)||function(e,t){return e!==t&&null!==e&&null!==t&&e.position===t.position&&ds.has(e)&&!ds.has(t)}(o,t)?t:null:n}function fs(e){const t=ls.get(e);return void 0===t?null:t}function ps(e,t){const n=ls.get(e);if(void 0===n)return null;const o=n[0];if(void 0!==o){const e=us(o,t);if(null!==e)for(const t of n)ss(t,e)}return n}function hs(e,t){null!==t?ls.set(e,t):ls.delete(e)}const gs=new WeakMap;function ms(e){return gs.get(e)??null}function bs(e,t){null===t?gs.delete(e):gs.set(e,t)}function ws(e){const t=gs.get(e);t&&(t.dirty=!0)}const ys=Symbol.for("wcstack.transition-runner");function vs(e){const t=globalThis[ys];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}function Ns(e,t,n){const o=vs(e);if(null!==o)return o.run(t,{source:e,types:n});t()}const xs=[],Ss=[];function Is(e){Ss.includes(e)||Ss.push(e)}function As(e,t=0){const n=xs.findIndex(e=>e.priority>t),o={listener:e,priority:t};-1===n?xs.push(o):xs.splice(n,0,o)}function Ts(e){const t=xs.findIndex(t=>t.listener===e);-1!==t&&xs.splice(t,1)}function $s(e){queueMicrotask(()=>{throw e})}class ks{_queueUpdateRecords=[];_queueRenderOnlyAddresses=[];constructor(){}enqueueAbsoluteAddress(e,t=null){for(let t=0;t<Ss.length;t++)Ss[t](e);const n=this._isQueueEmpty();this._queueUpdateRecords.push({absoluteAddress:e,context:t}),n&&this._scheduleDrain()}enqueueRenderOnlyAddress(e){const t=this._isQueueEmpty();this._queueRenderOnlyAddresses.push(e),t&&this._scheduleDrain()}_isQueueEmpty(){return 0===this._queueUpdateRecords.length&&0===this._queueRenderOnlyAddresses.length}_scheduleDrain(){et(),queueMicrotask(()=>{const e=this._queueUpdateRecords,t=this._queueRenderOnlyAddresses;this._queueUpdateRecords=[],this._queueRenderOnlyAddresses=[],this._applyChange(e,t)})}hasQueuedPath(e,t){return this._queueUpdateRecords.some(n=>n.absoluteAddress.absolutePathInfo.stateElement===e&&n.absoluteAddress.absolutePathInfo.pathInfo.path===t)}testApplyChange(e,t){this._applyChange(e.map((e,n)=>({absoluteAddress:e,context:t?.[n]??null})))}_applyChange(e,t=[]){const o=new Map,s=new Set;for(let t=0;t<e.length;t++){const n=e[t],i=o.get(n.absoluteAddress);null!==w&&null!=i&&null!==n.context&&i.transactionId!==n.context.transactionId&&w({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:i.transactionId,winnerTransactionId:n.context.transactionId}),o.set(n.absoluteAddress,n.context),s.add(n.absoluteAddress)}for(let e=0;e<t.length;e++){const n=t[e];o.has(n)||o.set(n,null)}const i=[],r=new Map;o.forEach((e,t)=>{if(null!==e&&e.hop>=T)return console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,transactionId:e.transactionId,hop:e.hop,maxHops:T}),void(null!==w&&w({type:"propagation:hop-limit",absoluteAddress:t,transactionId:e.transactionId,hop:e.hop}));const n=Lt(t);if(void 0!==n)if(n instanceof Set)for(const t of n)!1!==t.replaceNode.isConnected&&(i.push(t),null!==e&&r.set(t,e));else!1!==n.replaceNode.isConnected&&(i.push(n),null!==e&&r.set(n,e))});try{const e=()=>{r.size>0?Lr(i,r):Lr(i)};if(n()||0===i.length)e();else{const t=Ns("state",e);void 0!==t&&t.catch($s)}}finally{tt(),function(e){for(const t of xs.slice())t.listener(e)}(s)}}}const Ps=new ks;function Ms(){return Ps}const Es=new WeakMap,Cs=new WeakMap,_s=new WeakMap,Rs=new WeakMap;let Os=!1;const Bs=new WeakMap,Ls=new WeakMap,Ws=new WeakMap,Ds=[];function Fs(e,t){const n=js(e);if(n.recorded.has(t))return;n.recorded.add(t);const o=a(t).cumulativePaths;if(o.length<2)return;let s=Ws.get(e);void 0===s&&Ws.set(e,s=new Map);for(let e=0;e<o.length-1;e++){let n=s.get(o[e]);void 0===n&&s.set(o[e],n=new Set),n.add(t)}}function js(e){let t=Es.get(e);return void 0===t&&Es.set(e,t={byPath:new Map,lastValue:new Map,recorded:new Set,tracked:new Set}),t}function qs(e,t,n){let o=e.get(t);void 0===o&&e.set(t,o=new Set),o.add(n)}function zs(e,t,n){const o=e.get(t);o.delete(n),0===o.size&&e.delete(t)}function Vs(e,t,n,o){const s=function(e,t){let n=e.byPath.get(t);return void 0===n&&e.byPath.set(t,n=new Map),n}(e,t);let i=Cs.get(o);if(void 0===i&&Cs.set(o,i=new Map),i.has(t)){const e=i.get(t);return Object.is(e,n)||(zs(s,e,o),i.set(t,n),qs(s,n,o)),!1}return i.set(t,n),qs(s,n,o),!0}function Hs(e,t,n){const o=e.get(t);void 0===o?e.set(t,[n]):o.push(n)}function Us(e,t,n,o,s,i){e.lastValue.set(t,n),s&&(null!==o.listIndex&&Hs(_s,o.listIndex,i),null!==i.levelListIndex&&Hs(Rs,i.levelListIndex,i))}function Gs(e,t,n,o,s){Os=!0;const i=js(e);Fs(e,t);Us(i,t,s,o,Vs(i,t,n,o),{stateElement:e,path:t,absAddress:o,levelListIndex:null})}function Ks(e,t,n,o,s){Os=!0;const i=js(e);Fs(e,t);Us(i,t,s,o,Vs(i,t,n.index,o),{stateElement:e,path:t,absAddress:o,levelListIndex:n})}function Xs(e,t){js(e).tracked.add(t)}function Qs(e){const t=Es.get(e);return void 0===t?null:{byPath:t.byPath,lastValue:t.lastValue,tracked:t.tracked,watchers:Bs.get(e)}}function Js(e,t){return!0===Es.get(e)?.byPath.has(t)||!0===Bs.get(e)?.has(t)}function Ys(e,t,n,o,s){Os=!0,js(e).lastValue.set(t,s),Fs(e,t);let i=Bs.get(e);void 0===i&&Bs.set(e,i=new Map);let r=i.get(t);void 0===r&&i.set(t,r=new Set);let a,l=Ls.get(o);void 0===l?Ls.set(o,l=[]):a=l.find(n=>n.stateElement===e&&n.path===t),void 0===a&&(a={stateElement:e,path:t,indexes:o,getters:new Set},l.push(a),r.add(a)),a.getters.add(n)}function Zs(e,t,n){if("number"!=typeof t)return;const o=e.indexes[t];if(void 0!==o)for(const t of e.getters)n.push(wt(e.stateElement,jt(t,o)))}function ei(e,t){if(void 0!==e)for(const n of e)t.push(n)}function ti(e,t,n,o,s){const i=Es.get(e),r=i?.byPath.get(t),a=Bs.get(e)?.get(t);if(void 0===i||void 0===r&&void 0===a)return Ds;const l=i.lastValue.has(t),d=i.lastValue.get(t);i.lastValue.set(t,s);const c=[],u=!n||!Object.is(o,s),f=l&&(!n||!Object.is(d,o))&&!Object.is(d,s);if(void 0!==r&&(n&&ei(r.get(o),c),f&&ei(r.get(d),c),u&&ei(r.get(s),c)),void 0!==a)for(const e of a)n&&Zs(e,o,c),f&&Zs(e,d,c),u&&Zs(e,s,c);return c}function ni(e,t){return!0===Ws.get(e)?.has(t)}function oi(e,t){let n=e;for(const e of t){if("object"!=typeof n||null===n)return;n=n[e]}return n}function si(e,t,n,o){const s=a(t).segments.length,i=[];for(const r of Ws.get(e).get(t)){const t=a(r).segments.slice(s);if(t.includes(y))ii(e,r,i);else for(const s of ti(e,r,!0,oi(n,t),oi(o,t)))i.push(s)}return i}function ii(e,t,n){const o=Es.get(e).byPath.get(t);if(void 0!==o)for(const e of o.values())ei(e,n);const s=Bs.get(e)?.get(t);if(void 0!==s)for(const e of s)for(let t=0;t<e.indexes.length;t++)Zs(e,t,n)}function ri(e){const t=Rs.get(e.levelListIndex),n=t.indexOf(e);t.splice(n,1)}function ai(e){if(!Os)return;const t=_s.get(e);if(void 0!==t){_s.delete(e);for(const e of t){const{stateElement:t,path:n,absAddress:o}=e,s=Cs.get(o),i=s.get(n);s.delete(n),zs(Es.get(t).byPath.get(n),i,o),null!==e.levelListIndex&&ri(e)}}}function li(e,t,n){if(!Os)return;const o=Rs.get(e);if(void 0!==o)for(const{stateElement:e,path:s,absAddress:i}of o){const o=Es.get(e),r=o.byPath.get(s);zs(r,t,i),qs(r,n,i),Cs.get(i).set(s,n);const a=o.lastValue.get(s);(Object.is(a,t)||Object.is(a,n))&&(ws(i),Ms().enqueueAbsoluteAddress(i,null))}}const di=new WeakMap,ci=Object.freeze([]),ui=new Set;function fi(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:ci,s=Array.isArray(n)&&n.length>0?n:ci,i=function(e,t){const n=Array.isArray(e)&&e.length>0?e:ci,o=Array.isArray(t)&&t.length>0?t:ci;let s=di.get(n);return s&&s.get(o)||null}(o,s);if(i)return i;const r=ps(o,e)||[],a=r.length>0?is(r[0]):e;let l;try{if(0===s.length)return l={oldIndexes:r,newIndexes:[],changeIndexSet:ui,deleteIndexSet:new Set(r),addIndexSet:ui};let t=ps(s,e);if(0===o.length){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=os(e,n,a);t.push(o)}}return l={oldIndexes:r,newIndexes:t,changeIndexSet:ui,deleteIndexSet:ui,addIndexSet:new Set(t)}}if(function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,s))return l={oldIndexes:r,newIndexes:r,changeIndexSet:ui,deleteIndexSet:ui,addIndexSet:ui};if(null!==t)return function(e,t){const n=new Set(t),o=new Set(e),s=new Set,i=n.difference(o),r=o.difference(n),a=new Map;for(let t=0;t<e.length;t++)a.set(e[t],t);for(let e=0;e<t.length;e++){const n=t[e];i.has(n)||a.get(n)!==e&&s.add(n)}return{oldIndexes:e,newIndexes:t,changeIndexSet:s,deleteIndexSet:r,addIndexSet:i}}(r,t);t=[];const n=new Map;for(let e=0;e<o.length;e++){const t=o[e];let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}const i=new Set,d=new Set;for(let o=0;o<s.length;o++){const l=s[o],c=n.get(l),u=c&&c.length>0?c.shift():void 0;if(void 0===u){const n=os(e,o,a);t.push(n),d.add(n)}else{const e=r[u];u!==o&&i.add(e),t.push(e)}}return l={oldIndexes:r,newIndexes:t,changeIndexSet:i,deleteIndexSet:new Set(r).difference(new Set(t)),addIndexSet:d}}finally{void 0!==l&&(!function(e,t,n){let o=di.get(e);o||(o=new WeakMap,di.set(e,o)),o.set(t,n)}(o,s,l),hs(s,l.newIndexes))}}(e,t,n);!function(e,t){for(let n=0;n<e.length;n++){if(e[n].index!==n){const t=e[n].index;e[n].index=n,li(e[n],t,n)}rs(e[n],t[n])}}(o.newIndexes,Array.isArray(n)&&n.length>0?n:ci),function(e){for(const t of e)ds.add(t)}(o.deleteIndexSet);for(const e of o.deleteIndexSet)ai(e);return function(e){for(const t of e)ds.delete(t)}(o.newIndexes),function(e,t){if(!Os||e===t)return;const n=Ls.get(e);if(void 0===n)return;Ls.delete(e);const o=Ls.get(t);Ls.set(t,void 0===o?n:o.concat(n));for(const o of n){o.indexes=t;const n=js(o.stateElement).lastValue.get(o.path);if("number"!=typeof n)continue;const s=e[n],i=t[n];if(s!==i)for(const e of[s,i])if(void 0!==e&&!cs(e))for(const t of o.getters){const n=wt(o.stateElement,jt(t,e));ws(n),Ms().enqueueAbsoluteAddress(n,null)}}}(o.oldIndexes,o.newIndexes),o}function pi(e){if(0===e.changeIndexSet.size||e.addIndexSet.size===e.newIndexes.length)return null;const t=new Map;for(let n=0;n<e.oldIndexes.length;n++)t.set(e.oldIndexes[n],n);const n=[],o=[];let s=-1,i=!0;for(const r of e.newIndexes){if(e.addIndexSet.has(r))continue;const a=t.get(r);if(void 0===a)return null;a<s&&(i=!1),s=a,n.push(r),o.push(a)}if(i)return null;const r=function(e){const t=e.length,n=[],o=new Array(t).fill(-1);for(let s=0;s<t;s++){const t=e[s];let i=0,r=n.length;for(;i<r;){const o=i+r>>1;e[n[o]]<t?i=o+1:r=o}i>0&&(o[s]=n[i-1]),n[i]=s}const s=[];let i=n.length>0?n[n.length-1]:-1;for(;i>=0;)s.push(i),i=o[i];return s.reverse(),s}(o),a=new Set;for(const e of r)a.add(n[e]);return a}const hi=new WeakSet;function gi(e){hi.add(e)}const mi=new WeakMap;function bi(e){return mi.get(e)??null}function wi(e,t){mi.set(e,t)}const yi=new WeakMap;function vi(e){return yi.get(e)??[]}function Ni(e,t){yi.set(e,t)}function xi(e,t){const n=vi(e);for(const e of n)Ve(e,t)}const Si=new WeakMap;const Ii=new WeakMap;function Ai(e,t){for(let n=0;n<e.length;n++)if(t.has(e[n]))return!0;return!1}function Ti(e,t,n,o,s){const i=function(e,t,n){let o=Ii.get(e);void 0===o&&Ii.set(e,o=new Map);const s=o.get(n);if(void 0!==s)return s;const i=n+".",r=t.map((t,o)=>{const s=e.slots[o];if(s.isEvent||s.isIndexBinding)return null;const r=t.statePathInfo.path;if(!r.startsWith(i))return null;const a=r.slice(i.length).split("."),l=[];let d=n;for(const e of a){if("*"===e)return null;d+="."+e,l.push(d)}return{tail:a,prefixes:l}});return o.set(n,r),r}(e,t,o.pathInfo.path),r=s.stateElement.getterPaths;let a,l=!1;for(let e=0;e<t.length;e++){const d=t[e];if(!n.shouldApplyState(d))continue;const c=i[e];if(null===c||Ai(c.prefixes,r)){Or(d,s);continue}if(s.appliedBindingSet.has(d))continue;s.appliedBindingSet.add(d),l||(a=s.state[st](o),l=!0);const u=c.tail;let f=a;for(let e=0;e<u.length;e++){if(null==f){f=void 0;break}f=f[u[e]]}Rr(d,s,f)}}function $i(e,t,n){xi(e,t);const o=Uo(e),s=bi(e);if(null!==s&&(s.activate(o,n.rootNode),null!==t&&!1===n.stateElement.hasUpdatedCallback&&!0!==n.stateElement.hasRecursion)){const i=function(e){return Si.get(e)??null}(e);if(null!==i)return void Ti(i,o,s,t,n)}for(const e of o){if(null===s){Rt(Et(e),e)}(null===s||s.shouldApplyState(e))&&Or(e,n)}}function ki(e){if(!e.mounted)return;const t=Uo(e),n=bi(e);for(let e=0;e<t.length;e++){const o=t[e];if(null!==n)n.disposeBinding(o);else{Ot(Et(o),o)}}!function(e){const t=vi(e);for(let e=0;e<t.length;e++)Ve(t[e],null)}(e)}function Pi(){return Object.freeze(new Set)}const Mi=new WeakMap,Ei=Pi();function Ci(e,t){const n=Mi.get(e);n?n.add(t):Mi.set(e,new Set([t]))}function _i(e){const t=Mi.get(e);return void 0!==t?t:Ei}function Ri(e,t){const n=Mi.get(e);n&&(n.delete(t),0===n.size&&Mi.delete(e))}function Oi(e,n){if(0===e.length)return e;const o=[];for(let s=0;s<e.length;s++){const i=e[s];o.push({filterName:i.filterName,args:i.args,filterFn:t(i.filterName,i.args,n,i.literals??i.args)})}return o}function Bi(e){return{...e,inFilters:Oi(e.inFilters,"input"),outFilters:Oi(e.outFilters,"output")}}const Li=new Set(["if","elseif","else","for"]);class Wi{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(e,t=!1){this._content=e,this._ranged=t;const n=[];for(let t=e.firstChild;null!==t;t=t.nextSibling)n.push(t);this._childNodeArray=n,this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(e){const t=this._childNodeArray;for(let n=0;n<t.length;n++){const o=t[n];eo(o),e.appendChild(o)}this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const e=this._firstNode,t=this._lastNode;if(null===e||null===t||null===e.parentNode)return this._childNodeArray;const n=[];for(let o=e;null!==o;o=o.nextSibling)if(n.push(o),o===t)return n;return this._childNodeArray}mountAfter(e){const t=e.parentNode;if(t){let n=e;for(const e of this._movableNodes()){if(n.nextSibling!==e){eo(e);const o=t;e.parentNode===t&&"function"==typeof o.moveBefore?o.moveBefore(e,n.nextSibling):t.insertBefore(e,n.nextSibling)}n=e}}this._mounted=!0}tryDestroy(){const e=bi(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRow(Uo(this));const t=this._childNodeArray;for(let e=0;e<t.length;e++){const n=t[e];null!==n.parentNode&&(Xn(n),n.parentNode.removeChild(n))}const n=Uo(this);for(let e=0;e<n.length;e++){const t=n[e];Li.has(t.bindingType)&&_i(t.node).forEach(e=>{e.tryDestroy()||e.unmount()})}return this._mounted=!1,!0}unmountInPlace(){{const e=bi(this);null!==e&&(e.isRowSession?e.disposeBindings(Uo(this)):e.dispose())}this._teardownBindings()}_teardownBindings(){const e=Uo(this);for(let t=0;t<e.length;t++){const n=e[t];Li.has(n.bindingType)&&_i(n.node).forEach(e=>{e.unmount()}),Vt(n),Ct(n)}}unmount(){{const e=bi(this);null!==e&&(e.isRowSession?e.disposeBindings(Uo(this)):e.dispose())}for(const e of this._childNodeArray)null!==e.parentNode&&(Xn(e),e.parentNode.removeChild(e));const e=Uo(this);for(let t=0;t<e.length;t++){const n=e[t];Li.has(n.bindingType)&&_i(n.node).forEach(e=>{e.unmount()}),Vt(n),Ct(n)}this._mounted=!1}}function Di(t){let n=t.topLevelStructural;return void 0===n&&(n=t.topLevelStructural=function(t){const n=new RegExp(`^@@(?:${e.commentForPrefix}|${e.commentIfPrefix}|${e.commentElseIfPrefix}|${e.commentElsePrefix}):`);for(let e=t.firstChild;null!==e;e=e.nextSibling)if(e.nodeType===Node.COMMENT_NODE&&n.test(e.data))return!0;return!1}(t.fragment)),n}function Fi(e){const t=document.createDocumentFragment(),n=new Wi(t);return n._childNodeArray=e,n._firstNode=e.length>0?e[0]:null,n._lastNode=e.length>0?e[e.length-1]:null,n._mounted=!0,n}function ji(e,t,n){const o=document.importNode(t.fragment,!0),s=t.nodeInfos,i=new Array(s.length);for(let e=0;e<s.length;e++){const t=$e(o,s[e].nodePath);null===t&&M(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),We(t),pe(t),i[e]=t}const r=n.slots,a=new Array(r.length),l=[];for(let e=0;e<r.length;e++){const t=r[e],n=i[t.nodeIndex],o={...t.template,node:n,replaceNode:n};a[e]=o,t.isIndexBinding&&l.push(o)}const d=function(e,t,n){let o=Dr.get(n);void 0!==o&&o.currentRowPlan===e||(o=new Lo,Dr.set(n,o));return o.initializeRow(e,t),o}(n,a,e.node),c=new Wi(o);return wi(c,d),Go(c,a),function(e,t){Si.set(e,t)}(c,n),Qo(c,l),Ni(c,i),Ci(e.node,c),c}function qi(t){void 0!==t.uuid&&null!==t.uuid||M("BindingInfo.uuid is null.");const o=da(t.uuid);o||M(`Fragment with UUID "${t.uuid}" not found.`);const s=!n()&&Di(o);let i=o.rowPlan;if((void 0===i||null!==i&&i.directional!==e.enableDirectionalInitialSync)&&(i=o.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],i=$e(t.fragment,n.nodePath);if(null===i)return null;for(const t of n.parseBindTextResults){const n=t.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=t.propSegments[0];if(s===m||s===u)return null;if("text"===n){if(i.nodeType!==Node.TEXT_NODE)return null}else if(null!==ge(i))return null;if("prop"===n&&xn(i,t.propName))return null;const r=Bi(t);let a;try{a=ho({...r,node:i,replaceNode:i})}catch{return null}if(a.observable||"auto"===a.authority)return null;o.push({nodeIndex:e,template:r,isEvent:"event"===n,isIndexBinding:t.statePathName in $,policy:a,authority:a.authority})}}return{directional:n,slots:o}}(o)),null!==i)return ji(t,o,i);const r=document.importNode(o.fragment,!0),a=function(e,t){const[n,o]=function(e,t){const n=[],o=[];for(const s of t){const t=$e(e,s.nodePath);if(null===t&&M(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),Oe.has(t))continue;const i=Be(t,s.parseBindTextResults,{allowDeferred:!1});o.push(...i.bindings),n.push(t)}return[n,o]}(e,t),s=new Lo,i=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:i,bindingSession:s}}(r,o.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(r,t.uuid);const l=new Wi(r,s);wi(l,a.bindingSession),Go(l,a.bindingInfos);const d=[];for(const e of a.bindingInfos)e.statePathName in $&&d.push(e);return Qo(l,d),Ni(l,a.nodes),Ci(t.node,l),l}const zi=new WeakSet,Vi=Symbol.for("wcstack.state.view-transition-naming");function Hi(){const e=vs("state");return null===e||"auto"!==e.naming?null:{limit:e.namingLimit}}function Ui(e,t,n){const o=function(e){const t=e.firstNode;if(null===t)return null;const n=e.lastNode;for(let e=t;null!==e;e=e.nextSibling){if(e.nodeType===Node.ELEMENT_NODE)return e;if(e===n)break}return null}(e);if(null===o||zi.has(o))return;const s=o.style;if(void 0===s)return;const i=function(){const e=globalThis;return e[Vi]??={counter:0,assigned:0,warned:!1}}();i.assigned>=n.limit?i.warned||(i.warned=!0,console.warn(`[@wcstack/state] auto view-transition-name limit (${n.limit}) reached; further elements are left unnamed. Raise naming-limit on <wcs-view-transition>, or switch to naming="manual" and name only what should morph.`)):(zi.add(o),i.assigned+=1,i.counter+=1,s.setProperty("view-transition-name",`wcs-${t}-${i.counter}`),s.setProperty("view-transition-class",`wcs-${t}`))}const Gi=new WeakMap,Ki=new WeakMap,Xi=new WeakMap,Qi=new WeakMap;function Ji(e,t,n){!function(e,t,n){let o=Ki.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,Ki.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Yi(e,t){Gi.set(e,t)}function Zi(e){return e.nodeType===Node.ELEMENT_NODE||(e.nodeType===Node.TEXT_NODE?""!==(e.textContent?.trim()??""):e.nodeType===Node.COMMENT_NODE&&e.data.startsWith("@@wcs-"))}function er(e,t){if(null===t)return!1;if(e.nextSibling===t)return!0;const n=e.compareDocumentPosition(t);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}function tr(e,t,n){if(o=t,!hi.has(o))return null;var o;let s=null;for(let t=0;t<n.newIndexes.length;t++){const o=n.newIndexes[t],i=n.oldIndexes[t],r=n.addIndexSet.has(o)&&n.deleteIndexSet.has(i)?e.get(i):void 0;void 0!==r&&(s??={byAddedIndex:new Map,reused:new Set},s.byAddedIndex.set(o,r),s.reused.add(r))}return s}const nr=new Set(["if","elseif","else","for"]);function or(e,t){for(const n of Uo(e))if(t.appliedBindingSet.delete(n),nr.has(n.bindingType))for(const e of _i(n.node))or(e,t)}function sr(e){for(const t of Uo(e)){if(!nr.has(t.bindingType))continue;const e="for"===t.bindingType;for(const n of _i(t.node))sr(n),e&&n.mounted&&(ki(n),n.unmount(),Ri(t.node,n))}}function ir(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function rr(t,o,s){const i=Boolean(s);let r;const a=_i(t.node);r=0===a.size?qi(t):a.values().next().value;const l=n(),d=t.uuid??"",c=t.bindingType;if(i||(e.debug&&console.log(`unmount if content : ${ir(t)}`),ki(r),r.unmount()),i){if(e.debug&&console.log(`mount if content : ${ir(t)}`),l){const e=document.createComment(`@@wcs-${c}-start:${d}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),r.mountAfter(e);const n=document.createComment(`@@wcs-${c}-end:${d}:${t.statePathName}`),o=r.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else r.mountAfter(t.node);$i(r,ze(t.node),o);const n=Hi();null!==n&&Ui(r,"branch",n)}}const ar=new WeakMap;function lr(e){return ar.get(e)??[]}function dr(){return Array.from(cr)}const cr=new Set;function ur(){cr.clear()}const fr=Symbol.for("wcstack.trustedTypes.policy");function pr(){const e=globalThis[fr];return null===e||"object"!=typeof e?null:e}function hr(e){globalThis[fr]=e}let gr;let mr=!1;function br(e,t){if(mr)return;if(!function(){if(void 0!==gr)return gr;if(!("trustedTypes"in globalThis))return gr=!1,gr;try{document.createElement("div").innerHTML="<i></i>",gr=!1}catch{gr=!0}return gr}())return;mr=!0;const n="function"==typeof pr()?.createHTML?"The injected policy's createHTML() did not return a TrustedHTML.":"No sanitizing policy is installed, and @wcstack/state deliberately does not pass state values through an identity policy — that would defeat the CSP.";console.error(`[@wcstack/state] Writing to "${t}" was blocked by Trusted Types (require-trusted-types-for 'script'). ${n}\nInstall a sanitizing policy before the first binding is applied:\n globalThis[Symbol.for("wcstack.trustedTypes.policy")] =\n trustedTypes.createPolicy("my-app", { createHTML: (s) => DOMPurify.sanitize(s) });\nOr bind the value as text instead of HTML. See docs/csp.md section 7.`,{element:e,property:t})}const wr={value(e,t){"TEXTAREA"===e.tagName?e.textContent=String(t??""):e.setAttribute("value",String(t??""))},checked(e,t){t?e.setAttribute("checked",""):e.removeAttribute("checked")},selected(e,t){t?e.setAttribute("selected",""):e.removeAttribute("selected")},disabled(e,t){t?e.setAttribute("disabled",""):e.removeAttribute("disabled")},selectedIndex(e,t){const n=e.querySelectorAll("option"),o=Number(t);for(let e=0;e<n.length;e++)e===o?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}},yr=new Set(["textContent","innerText","innerHTML"]);function vr(t,o,s){if(void 0===s&&1===t.propSegments.length&&yr.has(t.propSegments[0])&&(s=""),void 0===s)return void(e.debug&&console.debug("Skipped property write: state value is undefined.",{element:t.node,propSegments:t.propSegments,statePathName:t.statePathName}));const i=t.node,r=t.propSegments;if(1===r.length){const d=r[0],c=i[d];if(c!==s){null!==Fo&&null!==c&&"object"==typeof c&&null!==s&&"object"==typeof s&&null!==ge(i)&&Fo.rememberOverwrittenObject(i,d,c);const n="innerHTML"===(l=d)||"outerHTML"===l||"srcdoc"===l,r=()=>{let t=!1;try{i[d]=n?function(e){if("string"!=typeof e)return e;const t=pr(),n=t?.createHTML;return"function"!=typeof n?e:n.call(t,e)}(s):s,t=!0}catch(t){n&&br(i,d),e.debug&&console.warn(`Failed to set property '${d}' on element.`,{element:i,newValue:s,error:t})}if(t){const t=function(e,t){const n=ge(e);if(null===n)return null;const o=be(e)?.get(n);if(void 0===o)return null;const s=ye(e)?.declaredInputs.get(t);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(i,d);if(null!==t)try{!function(e,t,n){if(null==n)return void e.removeAttribute(t);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);e.setAttribute(t,o)}(i,t,s)}catch(n){e.debug&&console.warn(`Failed to mirror attribute '${t}' on element.`,{element:i,newValue:s,error:n})}}};if(e.enablePropagationContext&&xn(i,d)){const e=$n(i,d,t.statePathName),n=kn(e,"to-element"),a=o?.propagationContextByBinding?.get(t)??_n()??Mn(e);if(a.visitedEdges.has(n))null!==w&&w({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:n,node:i,member:d});else{const t=En(a,n);Rn(t,()=>function(e,t,n,o,s,i){const r={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:An++,writtenValue:n};On.push({receipt:r,node:e});try{return i()}finally{On.pop()}}(i,d,s,e,t.transactionId,r))}}else r()}if(n()){const e=wr[d];e?e(i,s):(!function(e,t,n){let o=ar.get(e);o||(o=[],ar.set(e,o));const s=o.find(e=>e.propName===t);s?s.value=n:o.push({propName:t,value:n})}(i,d,s),a=i,cr.add(a))}return}var a,l;const d=r[0];let c=i[d];for(let e=1;e<r.length-1;e++){const t=r[e];if(null==c)return;c=c[t]}const u=r[r.length-1],f=c[u];if(f!==s){if(Object.isFrozen(c))return void(e.debug&&console.warn("Attempting to set property on frozen object.",{element:i,propSegments:r,oldValue:f,newValue:s}));null!==Fo&&2===r.length&&"object"==typeof c&&null!==c&&null!==ge(i)&&(u in c?Fo.rememberOverwrittenValue(i,d,u,c[u]):Fo.recordInjectedKey(i,d,u));try{c[u]=s}catch(t){e.debug&&console.warn("Failed to set property on sub-object.",{element:i,propSegments:r,oldValue:f,newValue:s,error:t})}}}const Nr=new WeakSet;function xr(e,t,n){}function Sr(e,t){const n=zt(t);if(n.pathInfo.path in $){const e=ze(t.node);return null===e&&M(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&M("ListIndex not found for loopContext:");const n=$[t];void 0===n&&M(`Invalid index name: ${t}`);const o=At(e.listIndex,n,e.pathInfo.wildcardCount);return null===o&&M(k(`"${t}"`,n+1,e.pathInfo.wildcardCount)),o.index}(e,n.pathInfo.path)}return e[st](n)}const Ir=new WeakSet;function Ar(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const Tr=Object.freeze({[p]:function(e,t,n){const o=e.node,s=e.propSegments[1];"boolean"!=typeof n&&M("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},[h]:function(e,t,n){const o=e.node,s=e.propSegments[1];null!=n?o.getAttribute(s)!==n&&o.setAttribute(s,n):o.hasAttribute(s)&&o.removeAttribute(s)},[g]:function(e,t,n){const o=e.propSegments[1],s=e.node.style;null==n&&(n=""),s[o]!==n&&(s[o]=n)},[m]:function(e,t,n){ln(n)||M("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Vo.get(e);if(s&&s.token===o)return;const i=e.node,r=e.propSegments[1];"string"==typeof r&&0!==r.length||M('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=ge(e);if(null===t)return null;const n=be(e)?.get(t);return void 0===n&&M(`Custom element <${t}> is not defined for command binding.`),ye(e)}(i);null===a&&M(`command binding requires a wc-bindable custom element. <${i.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(r)||M(`Command "${r}" is not declared in wcBindable.commands of <${i.tagName.toLowerCase()}>.${C(r,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),Vo.delete(e));const l=new WeakRef(i);let d=null;d=o.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return d?.(),void Vo.delete(e);const o=n[r];return"function"!=typeof o&&M(`Method "${r}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),Vo.set(e,{token:o,unsubscribe:d,elementRef:l})}}),$r={text:function(e,t,o){const s=null==o?"":String(o);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),n()&&!Nr.has(e.replaceNode)){Nr.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(o,e.replaceNode),t.insertBefore(s,e.replaceNode.nextSibling)}}},for:function(e,t,o){const s=e.statePathInfo,i=kt(e),r=Et(e),l=Ue(r),d=l.length>0&&!Ki.has(e.node)?[]:l,c=fi(i,d,o);t.newListValueByAbsAddress.set(r,Array.isArray(o)?o:[]);let u=Ki.get(e.node);const f=void 0!==u?tr(u,d,c):null,p=Array.isArray(d)&&d.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(p&&null===f&&null!==e.node.parentNode){let t=Qi.get(e.node);if(void 0===t){const n=Gi.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(Zi(n)){s=!1;break}n=n.previousSibling}for(;null!==o;){if(Zi(o)){s=!1;break}o=o.nextSibling}return s}(e.node,n),Qi.set(e.node,t)}if(t){const t=e.node.parentNode;!function(e,t){Jn.set(e,(Jn.get(e)??0)+t)}(t,t.childNodes.length),t.textContent="",t.appendChild(e.node)}}let h=p?1e3-function(e){return Xi.get(e.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){const t=u;c.deleteIndexSet.forEach(n=>{const o=t.get(n);void 0!==o&&(null!==f&&f.reused.has(o)?(ki(o),sr(o),o.unmountInPlace()):h<=0&&o.tryDestroy()?Ri(e.node,o):(ki(o),o.unmount(),function(e,t){let n=Xi.get(e.node);void 0===n&&(n=[],Xi.set(e.node,n)),n.length<1e3?n.push(t):Ri(e.node,t)}(e,o),h-=1),p||t.delete(n))}),p&&(Ki.delete(e.node),u=void 0)}let g=e.node;const m=a(s.path+"."+y),b=t.stateElement.loopContextStack,w=pi(c);let v=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&g.isConnected&&null===f&&(v=document.createDocumentFragment(),Nt(v,t.rootNode));const N=n(),x=Hi(),S=e.uuid??"",I=Xi.get(e.node);for(const n of c.newIndexes){let o;if(c.addIndexSet.has(n)){const i=jt(m,n);if(b.createLoopContext(i,i=>{if(o=f?.byAddedIndex.get(n)??(void 0!==I?I.pop():void 0),void 0===o?o=qi(e):or(o,t),null!==v)N&&v.appendChild(document.createComment(`@@wcs-for-start:${S}:${s.path}:${n.index}`)),o.appendTo(v),N&&v.appendChild(document.createComment(`@@wcs-for-end:${S}:${s.path}:${n.index}`));else{if(g.nextSibling!==o.firstNode){if(N){const e=document.createComment(`@@wcs-for-start:${S}:${s.path}:${n.index}`);g.parentNode.insertBefore(e,g.nextSibling),g=e}o.mountAfter(g)}if(N){const e=document.createComment(`@@wcs-for-end:${S}:${s.path}:${n.index}`),t=o.lastNode??g;t.parentNode.insertBefore(e,t.nextSibling)}}$i(o,i,t),null!==x&&Ui(o,"row",x)}),void 0===o&&M(`Content not found for ListIndex: ${n.index} at path "${s.path}"`),null!==f&&f.reused.has(o)){const e=t.stateElement.addressHooks;if(e){const n=e.rowReused;for(let e=0;e<n.length;e++)n[e](t.stateElement,o)}}}else{if(o=void 0!==u?u.get(n)??null:null,c.changeIndexSet.has(n)){const e=Xo(o);for(const n of e)Or(n,t)}null===o&&M(`Content not found for ListIndex: ${n.index} at path "${s.path}"`);const e=!o.mounted;if(null!==w&&w.has(n)&&er(g,o.firstNode)||g.nextSibling===o.firstNode||o.mountAfter(g),e){const e=o,s=jt(m,n);b.createLoopContext(s,n=>{$i(e,n,t)})}}g=o.lastNode||g,void 0===u&&(u=new WeakMap,Ki.set(e.node,u)),u.set(n,o)}Gi.set(e.node,g),null!==v&&(e.node.parentNode.insertBefore(v,e.node.nextSibling),Nt(v,null))},if:rr,else:rr,elseif:rr,radio:function(e,t,n){const o=e.node,s=qo(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=qo(o.value,e.inFilters),i=Array.isArray(n)?n:zo;o.checked=i.includes(s)}},kr=new WeakMap,Pr=new WeakMap,Mr=new WeakMap;function Er(){}function Cr(e){const t=Fo;if(null!==t){const n=e.replaceNode,o=e.propSegments[0];if(t.isComplete(n,o))return xr;if(t.isDeclared(n,o))return Er}return vr}function _r(e,t){Rr(e,t,Sr(t.state,e))}function Rr(e,t,n){const o=qo(n,e.outFilters);if(!0===Pr.get(e))return void t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement});let s=kr.get(e);if(void 0===s){if(kr.has(e))return s=Cr(e),s===xr&&kr.set(e,s),void s(e,t,o);if(s=$r[e.bindingType],void 0===s){const t=e.propSegments[0];if(s=Tr[t],kr.set(e,s),void 0===s){ge(e.replaceNode)?(s=Cr(e),s===xr&&kr.set(e,s)):(s=vr,kr.set(e,s))}}if(s===vr){if("SELECT"===e.node.tagName){const n=e.propSegments[0];if("value"===n||"selectedIndex"===n)return t.deferredSelectBindings.push({binding:e,value:o,stateElement:t.stateElement}),void Pr.set(e,!0)}}s(e,t,o)}else s(e,t,o)}function Or(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=Et(e);if(t.updatedAbsAddressSetByStateElement.has(t.stateElement)){t.updatedAbsAddressSetByStateElement.get(t.stateElement).add(n)}else t.updatedAbsAddressSetByStateElement.set(t.stateElement,new Set([n]))}const n=Do(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==Mr.get(e)){const t=ge(e.replaceNode);if(t&&void 0===be(e.replaceNode)?.get(t))return void function(e,t){if(Ir.has(e))return;Ir.add(e);const n=()=>{Ir.delete(e);const t=Do(e);(null===t||t.shouldApplyState(e))&&Lr([e])},o=n=>{Ir.delete(e),Ar(t,n)},s=Do(e);if(null!==s){const i=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{Ir.delete(e),i()})||(Ir.delete(e),i()))}const i=be(e.replaceNode);if(null===i)return Ir.delete(e),void Ar(t,new Error("CustomElementRegistry is unavailable."));ao(i).wait(t,()=>{e.replaceNode.isConnected?n():Ir.delete(e)},o)}(e,t);Mr.set(e,!0)}if(!0===t.sameRootVerified)return void _r(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=xt(o),null===o&&M("Root node for fragment not found for binding.")),o!==t.rootNode){const n=Zr(o);null===n&&M("No state tree found on this root for binding."),n.createState("readonly",s=>{const i={rootNode:o,stateElement:n,state:s,appliedBindingSet:t.appliedBindingSet,newListValueByAbsAddress:t.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:t.updatedAbsAddressSetByStateElement,deferredSelectBindings:t.deferredSelectBindings};_r(e,i)})}else _r(e,t)}function Br(e,t,n,o){if(null!==n&&!0===n.hasErrorCallback){const s={path:e.statePathName,bindingType:e.bindingType,node:e.node},i=o.get(n);void 0===i?o.set(n,[{error:t,info:s}]):i.push({error:t,info:s})}else console.error(`[@wcstack/state] binding "${e.bindingType}: ${e.statePathName}" failed to apply; the rest of this batch continues.`,{node:e.node,error:t});null!==w&&w({type:"state:binding-apply-error",path:e.statePathName,bindingType:e.bindingType,error:t})}function Lr(t,n,o){let s=0;const i=new Set,r=new Map,a=new Map,l=[],d=new Map;for(;s<t.length;){let o=t[s];if(!1===o.replaceNode.isConnected){e.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${o.bindingType} ${o.statePathName} on ${o.node.nodeName}`,o),s++;continue}let c=o.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=xt(c),null===c&&M("Root node for fragment not found for binding."));const u=Zr(c);null===u&&M("No state tree found on this root for binding."),u.createState("readonly",e=>{const f={rootNode:c,stateElement:u,state:e,appliedBindingSet:i,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:a,deferredSelectBindings:l,sameRootVerified:!0,propagationContextByBinding:n};for(;;){try{Or(o,f)}catch(e){Br(o,e,u,d)}s++;const e=t[s];if(!e)break;if(e.replaceNode.getRootNode()!==f.rootNode)break;o=e}})}for(const{binding:e,value:t,stateElement:o}of l)try{vr(e,{propagationContextByBinding:n},t)}catch(t){Br(e,t,o??null,d)}for(const[e,t]of r.entries())Ge(e,t),Ze(e,t);if(!1!==o?.updatedCallback)for(const[e,t]of a.entries())e.createState("writable",e=>{e[dt](Array.from(t))});for(const[e,t]of d.entries())e.createState("writable",e=>{for(const{error:n,info:o}of t)try{e[ct](n,o)}catch(e){console.error(`[@wcstack/state] $errorCallback threw while handling the failure of binding "${o.bindingType}: ${o.path}".`,{error:e,original:n,node:o.node})}})}function Wr(e,t,n){const[o,s,i]=Le(e,n),r=Wo(e);for(const e of o)Ve(e,t);Lr(r.initialize(s)),function(e,t,n){for(const o of e)n.deferUntilDefined(o.node,o.tagName,()=>{const e=De(o);0!==e.length&&(Ve(o.node,t),Lr(n.initialize(e)))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,e)})}(i,t,r)}const Dr=new WeakMap;async function Fr(t){const n=t.querySelectorAll(e.tagNames.state),o=[],s=be(t);null===s&&M(`CustomElementRegistry is unavailable for <${e.tagNames.state}>.`),await s.whenDefined(e.tagNames.state);for(const e of n){if(Ee(e))continue;const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function jr(t){if(t===document)await Fr(document),D(document),$a(document,document),Wr(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await fe(n.host),await Fr(n),D(n),$a(n,n),Wr(n,null)}}const qr={watch:"temporal",scan:"temporal",stream:"temporal",scopes:"scopes",dcc:"scopes",bindComponent:"scopes",recursion:"recursion",ssr:"ssr",devtools:"devtools"};function zr(e,t){return`[wcs/feature-not-installed] ${t} needs the "${e}" feature: install it with installFeatures([...]) from "@wcstack/state/features/${qr[e]??e}" before the state is defined.`}let Vr=null;function Hr(e){Vr=e}function Ur(e){return null===Vr&&M(zr("ssr",e)),Vr}const Gr=new WeakMap,Kr=new WeakMap,Xr=new Set,Qr=[];function Jr(e){Qr.includes(e)||Qr.push(e)}function Yr(){return Xr}function Zr(e){return Gr.get(e)??null}function ea(e){return Kr.get(e)??Promise.resolve()}function ta(e,t){const n=Promise.reject(t);n.catch(()=>{}),Kr.set(e,n)}const na=new WeakSet;function oa(e,t){const n=Gr.get(e);if(void 0!==n){if(n===t)return;M("A state tree is already registered on this root.")}Gr.set(e,t)}function sa(e,t){Kr.set(e,t),t.then(()=>ia(e),()=>{})}function ia(e){na.add(e)}function ra(t,o){const s=Gr.get(t);if(null===o){if(void 0===s)return;Gr.delete(t),Xr.delete(s),null!==w&&w({type:"state:element-unregistered",rootNode:t,element:s}),e.debug&&console.debug("State element unregistered")}else{if(s===o)return;if(void 0===s){const e=!n()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const n=new Promise((n,o)=>{queueMicrotask(async()=>{try{if(e){await Ur('the "enable-ssr" attribute').hydrate(t)||await jr(t)}else await jr(t);ia(t),_a(),n()}catch(e){o(e)}})});Kr.set(t,n)}else if("ShadowRoot"===t.constructor.name){const e=new Promise((e,n)=>{queueMicrotask(async()=>{try{await jr(t),ia(t),_a(),e()}catch(e){n(e)}})});Kr.set(t,e)}}void 0!==s&&M('A state tree is already registered on this root — one <wcs-state> per root in v2. This second element stays unregistered: it keeps the state it loaded and its declarations stay live, but nothing binds to it and disconnecting it runs no cleanup — remove it. Mount additional states onto the tree instead: <wcs-state mount="...">.'),Gr.set(t,o),Xr.add(o);for(let e=0;e<Qr.length;e++)Qr[e](t,o);null!==w&&w({type:"state:element-registered",rootNode:t,element:o}),e.debug&&console.debug("State element registered",o)}}const aa=new Map;function la(e,t,n){if(null===n)aa.delete(e);else{aa.set(e,n);const o=Zr(t);null===o&&M("No state tree found on this root for fragment info.");const s=n.parseBindTextResult;o.setPathInfo(s.statePathName,s.bindingType);for(const e of n.nodeInfos)for(const t of e.parseBindTextResults)o.setPathInfo(t.statePathName,t.bindingType)}}function da(e){return aa.get(e)||null}function ca(){return Array.from(aa.keys())}function ua(t){if(t.nodeType===Node.ELEMENT_NODE){const n=t,o=oe(n.getAttribute(e.bindAttributeName)||"");return n.localName===e.tagNames.state&&n.hasAttribute("mount")?o.filter(e=>e.propSegments[0]!==P):o}if(t.nodeType===Node.COMMENT_NODE){const e=ae(t);null===e&&M("Comment node binding text not found.");const n=da(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=le(e),s=null):s=e,[{...o,uuid:s}]}return[]}let fa;function pa(){return fa??={filterName:"not",args:[]}}const ha=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function ga(e,t){const n=t+i+y,o=e.indexOf("|");let s,r;if(-1!==o?(s=e.slice(0,o).trim(),r=e.slice(o)):(s=e.trim(),r=""),"."===s)s=n;else{if(!s.startsWith("."))return e;s=n+i+s.slice(1)}return r.length>0?s+r:s}function ma(e,t){const n=ha.exec(e);if(null===n)return e;const o=n[1],s=n[2],i=n[3];return o+ga(s,t)+i}function ba(e,t){const n=e.split(";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=n.indexOf(":");if(-1===s)return e;const i=n.slice(0,s).trim(),r=n.slice(s+1).trim(),a=ga(r,t);return a!==r?(o=!0,`${i}: ${a}`):e});return o?s.join(";"):e}function wa(e,t){return ba(e,t)}function ya(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const t=e;t.data=ma(t.data,n);continue}const t=e;if(t instanceof HTMLTemplateElement)continue;const i=t.getAttribute(o);if(null!==i){const e=ba(i,n);e!==i&&t.setAttribute(o,e)}}}function va(e){let t=e;const n=[];for(;null!==t.parentNode;){const e=Array.from(t.parentNode.childNodes).indexOf(t);n.unshift(e),t=t.parentNode}return n}function Na(e){const t=[],n=Re(e);for(const e of n){const n=ua(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:va(o),parseBindTextResults:n})}return t}function xa(e){const t=Array.from(e.childNodes);for(const n of t)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&e.removeChild(n)}}const Sa=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),Ia=pa();function Aa(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Ia],bindingType:e}}function Ta(e,t,n,o,s,i=!0){xa(t),"string"==typeof o&&ya(t,o),$a(e,t,o,s);const r={fragment:t,parseBindTextResult:void 0!==s&&i?s(n,o):n,nodeInfos:Na(t)};return void 0!==s&&function(e,t,n){for(const o of e)for(let e=0;e<o.parseBindTextResults.length;e++){const s=o.parseBindTextResults[e];null==s.uuid&&(o.parseBindTextResults[e]=t(s,n))}}(r.nodeInfos,s,o),r}function $a(t,n,o,s){const i=e.commentElsePrefix,r=Ce(n),a=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const n=t;if(r.length>0&&-1!==r.indexOf(n))return NodeFilter.FILTER_REJECT;if("template"===n.tagName.toLowerCase()){if((n.getAttribute(e.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let l=null;const d=[],c=[];for(;a.nextNode();){const e=a.currentNode;c.push(e)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=wa(r,o));let a=oe(r)[0];const c=Sa.get(a.bindingType);if(void 0===c)continue;const u=a.bindingType,f=n.content,p=Yo();let h=null;const g="for"===u?a.statePathName:o;if("else"===u){null===l&&M("'else' binding found without preceding 'if' or 'elseif' binding."),a=Aa("else",l.parseBindTextResult),h=Ta(t,f,a,g,s,!1),la(p,t,h);const e=d.at(-1),o=document.createComment(`@@${c}:${p}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:va(o),parseBindTextResults:ua(o)})):n.replaceWith(o)}else if("elseif"===u){null===l&&M("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Ta(t,f,a,g,s),la(p,t,h);const e=document.createComment(`@@${c}:${p}`),o=Yo(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Aa("else",l.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:va(e),parseBindTextResults:ua(e)}),la(o,t,r);const u=d.at(-1);d.push(r);const m=document.createComment(`@@${i}:${o}`);void 0!==u?(n.remove(),u.fragment.appendChild(m),u.nodeInfos.push({nodePath:va(m),parseBindTextResults:ua(m)})):n.replaceWith(m)}else{h=Ta(t,f,a,g,s),la(p,t,h);const e=document.createComment(`@@${c}:${p}`);n.replaceWith(e)}"if"===u?(d.length=0,l=h):"elseif"===u?l=h:"else"===u&&(l=null,d.length=0)}}const ka=()=>`[${e.bindAttributeName}]`;function Pa(t){if(Ao(t))return!0;if(!Ma(t))return!1;if(t.hasAttribute(e.bindAttributeName))return!1;const n=t.querySelector(ka());return null!==n&&Ao(n)}function Ma(e){return 1===e.nodeType}function Ea(t){if(Pa(t))return;D(t),$a(t.getRootNode(),t);const n=t.hasAttribute(e.bindAttributeName),o=t.parentNode,s=null!==o&&(1===o.nodeType||9===o.nodeType||11===o.nodeType);Wr(n&&s?o:t,null)}const Ca=[];function _a(){const e=Ca.splice(0,Ca.length);for(const t of e)Ea(t);B()}const Ra={protocol:"wcs-binder",version:1,bind:function(e){var t;Ma(e)&&!Pa(e)&&(t=e.getRootNode(),na.has(t)?Ea(e):Ca.push(e))}};function Oa(){const e=globalThis;void 0===e[_]&&(e[_]=Ra)}export{Na as $,jo as A,ge as B,fe as C,oe as D,Jr as E,cs as F,st as G,fs as H,At as I,as as J,yt as K,Ze as L,fi as M,Ye as N,bs as O,ca as P,da as Q,dr as R,lr as S,fr as T,ur as U,Fr as V,Le as W,Et as X,Ge as Y,xa as Z,ya as _,pr as a,la as a0,Fi as a1,wi as a2,Go as a3,Ni as a4,Qo as a5,os as a6,Ji as a7,Yi as a8,Ci as a9,an as aA,ms as aB,ps as aC,It as aD,Ln as aE,Js as aF,ni as aG,_n as aH,ti as aI,si as aJ,Mn as aK,Ue as aL,gi as aM,Te as aN,le as aO,Qs as aP,Yr as aQ,Ts as aR,qe as aS,xi as aa,hs as ab,Lo as ac,pa as ad,Hr as ae,ws as af,Xs as ag,Ys as ah,Ks as ai,Gs as aj,ct as ak,dt as al,lt as am,at as an,rt as ao,it as ap,Ns as aq,$s as ar,tt as as,Lt as at,et as au,on as av,Ur as aw,ra as ax,ta as ay,zr as az,jr as b,Ms as c,nn as d,Is as e,As as f,ea as g,be as h,ze as i,ot as j,jt as k,wt as l,Wo as m,Ve as n,Lr as o,oa as p,sa as q,Oa as r,hr as s,D as t,we as u,$a as v,Wr as w,Tt as x,Zr as y,Me as z};
|
|
2
|
+
//# sourceMappingURL=binder.js.map
|