@wcstack/state 1.27.0 → 1.28.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/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +45 -3
- package/dist/index.esm.js +207 -61
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +35 -0
- package/dist/manifest.esm.js +54 -1
- package/dist/parser.d.ts +74 -0
- package/dist/parser.esm.js +1452 -0
- package/dist/wcs-manifest.json +29 -1
- package/package.json +5 -1
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(){const t=document.documentElement;return!!t&&t.hasAttribute("data-wcs-server")}const e={bindAttributeName:"data-wcs",commentTextPrefix:"wcs-text",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:"en",debug:!1,enableMustache:!0,enableDirectionalInitialSync:!0,enablePropagationContext:!0,enableContractAnalyzer:!1,sameValueGuard:!0},n=".",o="*",s=128,r="|",i={};for(let t=0;t<128;t++)i[`$${t+1}`]=t;const a=Object.freeze(i),l="$connectedCallback",c="$disconnectedCallback",d="$updatedCallback",u="$stateReadyCallback",f="$bindables",h="$commands",p="$commandTokens",m="$command",g="$eventTokens",y="$on",b="$streams",w="$watch",v="$listKeys",N="$streamStatus",S="$streamError",I="data-wc-definition",x=new WeakMap,$=new WeakSet;let _=0;async function P(t){const e=function(t){let e,n=x.get(t)||null;if(null!==n)return n;const o=new Promise(t=>{e=t});return n={id:++_,promise:o,resolve:e},x.set(t,n),$.has(t)&&n.resolve(),n}(t);await e.promise}function A(t){const e=x.get(t);void 0===e?$.add(t):e.resolve()}const k=new Map;let C=0;function E(t){let e=k.get(t);return void 0!==e||(e=Object.freeze(new M(t)),k.set(t,e)),e}class M{id=++C;path;segments;lastSegment;cumulativePaths;cumulativePathSet;cumulativePathInfos;cumulativePathInfoSet;parentPath;wildcardPaths;wildcardPathSet;indexByWildcardPath;wildcardPathInfos;wildcardPathInfoSet;wildcardParentPaths;wildcardParentPathSet;wildcardParentPathInfos;wildcardParentPathInfoSet;wildcardPositions;lastWildcardPath;lastWildcardInfo;wildcardCount;parentPathInfo;constructor(t){const e=e=>t===e?this:E(e),n=t.split("."),s=[],r=[],i=[],a={},l=[],c=[],d=[],u=[];let f="",h="",p=0;for(let t=0;t<n.length;t++)f+=n[t],n[t]===o&&(i.push(f),a[f]=p,l.push(e(f)),c.push(h),d.push(e(h)),u.push(t),p++),s.push(f),r.push(e(f)),h=f,f+=".";const m=i.length>0?i[i.length-1]:null,g=s.length>1?s[s.length-2]:null;this.path=t,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=s,this.cumulativePathSet=new Set(s),this.cumulativePathInfos=r,this.cumulativePathInfoSet=new Set(r),this.wildcardPaths=i,this.wildcardPathSet=new Set(i),this.indexByWildcardPath=a,this.wildcardPathInfos=l,this.wildcardPathInfoSet=new Set(l),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=d,this.wildcardParentPathInfoSet=new Set(d),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?e(m):null,this.parentPath=g,this.parentPathInfo=g?e(g):null,this.wildcardCount=p}}const T=new WeakMap;function O(t){const e=T.get(t);if(void 0!==e)return e;let n=null;try{if(t.nodeType!==Node.ELEMENT_NODE)return n;const e=t,o=e.tagName.toLowerCase();if(o.includes("-"))return n=o;if(e.hasAttribute("is")){const t=e.getAttribute("is");if(t.includes("-"))return n=t}return n}finally{T.set(t,n)}}function R(t=null){const e=globalThis.customElements,n=t?.customElements??e;if("object"!=typeof n||null===n)return null;const o=n;return"function"!=typeof o.get||"function"!=typeof o.whenDefined?null:o}function D(t,e){t.upgrade?.(e)}function L(t){try{if(null===t||"object"!=typeof t&&"function"!=typeof t)return null;const e=t,n=e.addEventListener,o=e.removeEventListener,s=e.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 r=F(s.properties,W);if(null===r)return null;const i=void 0===s.inputs?new Map:F(s.inputs,B);if(null===i)return null;const a=void 0===s.commands?new Map:F(s.commands,j);return null===a?null:{target:t,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function W(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&("string"==typeof e.event&&0!==e.event.length&&(void 0===e.getter||"function"==typeof e.getter))}function B(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.attribute||"string"==typeof e.attribute)}function j(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.async||"boolean"==typeof e.async)}function F(t,e){if(!Array.isArray(t))return null;const n=new Map;for(const o of t){if(!e(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function z(t){throw new Error(`[@wcstack/state] ${t}`)}function q(t,e,n){const o="."===e?`.${t}`:`${e}.${t}`;return{propName:t,propSegments:[t],propModifiers:[],statePathName:o,statePathInfo:E(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function U(t){switch(t.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${t.bindingType}::${t.propName}`;default:return null}}function V(t,e){let n=t;if(0===e.length)return n;for(let t=0;t<e.length&&(n=n?.childNodes[e[t]]??null,null!==n);t++);return n}const H=new WeakMap;const G=new Set(["if","elseif","else","for"]);function K(t){z(`filter ${t} requires at least one option`)}function J(t){z(`filter ${t} requires a number as option`)}function X(t){z(`filter ${t} requires a number value`)}function Y(t){z(`filter ${t} requires a date value`)}function Q(t){return!(!t||isNaN(Number(t)))}const Z={eq:t=>{const e=t?.[0]??K("eq");return t=>"number"==typeof t?(Q(e)||J("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??K("ne");return t=>"number"==typeof t?(Q(e)||J("ne"),t!==Number(e)):t!==e},not:t=>t=>("boolean"!=typeof t&&z(`filter ${"not"} requires a boolean value`),!t),lt:t=>{const e=t?.[0]??K("lt");return Q(e)||J("lt"),t=>("number"!=typeof t&&X("lt"),t<Number(e))},le:t=>{const e=t?.[0]??K("le");return Q(e)||J("le"),t=>("number"!=typeof t&&X("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??K("gt");return Q(e)||J("gt"),t=>("number"!=typeof t&&X("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??K("ge");return Q(e)||J("ge"),t=>("number"!=typeof t&&X("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??K("inc");return Q(e)||J("inc"),t=>("number"!=typeof t&&X("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??K("dec");return Q(e)||J("dec"),t=>("number"!=typeof t&&X("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??K("mul");return Q(e)||J("mul"),t=>("number"!=typeof t&&X("mul"),t*Number(e))},div:t=>{const e=t?.[0]??K("div");return Q(e)||J("div"),t=>("number"!=typeof t&&X("div"),t/Number(e))},mod:t=>{const e=t?.[0]??K("mod");return Q(e)||J("mod"),t=>("number"!=typeof t&&X("mod"),t%Number(e))},abs:t=>t=>("number"!=typeof t&&X("abs"),Math.abs(t)),clamp:t=>{const e=t?.[0]??K("clamp");Q(e)||J("clamp");const n=t?.[1]??K("clamp");Q(n)||J("clamp");const o=Number(e),s=Number(n);return t=>("number"!=typeof t&&X("clamp"),Math.min(Math.max(t,o),s))},fix:t=>{const e=t?.[0]??"0";return Q(e)||J("fix"),t=>("number"!=typeof t&&X("fix"),t.toFixed(Number(e)))},locale:t=>{const n=t?.[0]??e.locale;return t=>("number"!=typeof t&&X("locale"),t.toLocaleString(n))},uc:t=>t=>String(t).toUpperCase(),lc:t=>t=>String(t).toLowerCase(),cap:t=>t=>{const e=String(t);return 0===e.length?e:1===e.length?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)},trim:t=>t=>String(t).trim(),slice:t=>{const e=[],n=t?.[0]??K("slice");Q(n)||J("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(Q(o)||J("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??K("substr");Q(e)||J("substr");const n=t?.[1]??K("substr");return Q(n)||J("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??K("pad");Q(e)||J("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??K("rep");return Q(e)||J("rep"),t=>String(t).repeat(Number(e))},rev:t=>t=>String(t).split("").reverse().join(""),truncate:t=>{const e=t?.[0]??K("truncate");Q(e)||J("truncate");const n=Number(e),o=t?.[1]??"…";return t=>{const e=String(t);return e.length<=n?e:e.slice(0,n)+o}},join:t=>{const e=t?.[0]??", ";return t=>(Array.isArray(t)||z(`filter ${"join"} requires an array value`),t.join(e))},int:t=>t=>parseInt(String(t),10),float:t=>t=>parseFloat(String(t)),round:t=>{const e=t?.[0]??"0";return Q(e)||J("round"),t=>{"number"!=typeof t&&X("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return Q(e)||J("floor"),t=>{"number"!=typeof t&&X("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return Q(e)||J("ceil"),t=>{"number"!=typeof t&&X("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return Q(e)||J("percent"),t=>("number"!=typeof t&&X("percent"),`${(100*t).toFixed(Number(e))}%`)},unit:t=>{const e=t?.[0]??K("unit");return t=>null==t?t:String(t)+e},date:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||Y("date"),t.toLocaleDateString(n))},time:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||Y("time"),t.toLocaleTimeString(n))},datetime:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||Y("datetime"),t.toLocaleString(n))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||Y("ymd");const n=t.getFullYear().toString(),o=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},hms:t=>{const e=t?.[0]??":";return t=>{t instanceof Date||Y("hms");const n=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),s=t.getSeconds().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},falsy:t=>t=>!1===t||null==t||0===t||""===t||Number.isNaN(t),truthy:t=>t=>!1!==t&&null!=t&&0!==t&&""!==t&&!Number.isNaN(t),defaults:t=>{const e=t?.[0]??K("defaults");return t=>!1===t||null==t||0===t||""===t||Number.isNaN(t)?e:t},boolean:t=>t=>Boolean(t),number:t=>t=>Number(t),string:t=>t=>String(t),null:t=>t=>""===t?null:t},tt=Z,et={input:Z,output:tt},nt=(t,e)=>n=>{const o=n[t];return o||z(`filter not found: ${t}`),o(e)};function ot(t,e,n){const o=-1===e?t.length:e;let s=0;for(;s<o&&/\s/.test(t[s]);)s++;const r=-1===n?0:n;let i=t.length;for(;i>r&&/\s/.test(t[i-1]);)i--;return t.slice(s,i)}const st=new Map;function rt(t,e){const n=et[e];return t.map(t=>{const o=t.indexOf("("),s=t.lastIndexOf(")");if(-1!==o&&-1===s&&z(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==s&&-1===o&&z(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===o){const o=t.trim(),s=`${o}():${e}`;let r=st.get(s);return void 0===r&&(r=nt(o,[])(n),st.set(s,r)),{filterName:o,args:[],filterFn:r}}{const r=t.substring(o+1,s),i=t.substring(0,o).trim(),a=function(t){const e=[];let n="",o=null,s=!1,r=-1,i=-1;const a=()=>{e.push(ot(n,r,i)),n="",s=!1,r=-1,i=-1};for(let e=0;e<t.length;e++){const l=t[e];o?l===o?o=null:(-1===r&&(r=n.length),n+=l,i=n.length):'"'===l||"'"===l?(o=l,s=!0):","===l?a():n+=l}const l=ot(n,r,i);return(l||s)&&e.push(l),e}(r),l=`${i}(${a.join(",")}):${e}`;let c=st.get(l);return void 0===c&&(c=nt(i,a)(n),st.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const it=t=>t.trim(),at=new Map;const lt=new Map;function ct(t){const e=t.indexOf(r);let n="",o=[],s="",i=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),lt.has(s)?i=lt.get(s):(o=s.split(r).map(it),i=rt(o,"output"),lt.set(s,i))):n=t.trim();const[a,l="default"]=n.split("@").map(it);return{stateName:l,statePathName:a,statePathInfo:E(a),outFilters:i}}function dt(t){const[...e]=t.split(";").map(it).filter(t=>t.length>0),o=e.map(t=>{const e=t.indexOf(":");-1===e&&z(`Invalid bindText: "${t}". Missing ':' separator between propPart and statePart.`);const o=t.slice(0,e).trim(),s=t.slice(e+1).trim();if("else"===o){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:E("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("..."===o){const e=ct(s);return e.outFilters.length>0&&z(`Invalid spread binding "${t}": filters are not allowed on spread targets.`),0===e.statePathName.length&&z(`Invalid spread binding "${t}": spread target path is required.`),{propName:"...",propSegments:["..."],propModifiers:[],inFilters:[],...e,bindingType:"spread"}}if("if"===o||"elseif"===o||"for"===o||"radio"===o||"checkbox"===o){return{propName:o,propSegments:[o],propModifiers:[],inFilters:[],...ct(s),bindingType:o}}{const t=ct(s),e=function(t){const e=t.indexOf(r);let o="",s=[],i="",a=[];-1!==e?(o=t.slice(0,e).trim(),i=t.slice(e+1).trim(),at.has(i)?a=at.get(i):(s=i.split(r).map(it),a=rt(s,"input"),at.set(i,a))):o=t.trim();const[l,c]=o.split("#").map(it),d=l.split(n).map(it);return{propName:l,propSegments:d,propModifiers:c?c.split(",").map(it):[],inFilters:a}}(o);return"eventToken"===e.propSegments[0]||e.propSegments[0].startsWith("on")?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(o.length>1){o.some(t=>G.has(t.bindingType))&&z(`Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return o}const ut=new WeakMap,ft=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),ht=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function pt(t){const n=ut.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=ht.exec(o);if(null===s)return null;const r=s[1]||e.commentTextPrefix;return ft.has(r)?(ut.set(t,s[2]),s[2]):null}const mt=new Map;function gt(t,e,n){if(null===n)mt.delete(t);else{mt.set(t,n);const o=n.parseBindTextResult,s=xr(e,o.stateName);null===s&&z(`State element with name "${o.stateName}" not found for fragment info.`),s.setPathInfo(o.statePathName,o.bindingType);for(const t of n.nodeInfos)for(const n of t.parseBindTextResults){const t=xr(e,n.stateName);null===t&&z(`State element with name "${n.stateName}" not found for fragment info node.`),t.setPathInfo(n.statePathName,n.bindingType)}}}function yt(t){return mt.get(t)||null}function bt(t){if(t.nodeType===Node.ELEMENT_NODE){return dt(t.getAttribute(e.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=pt(t);null===e&&z("Comment node binding text not found.");const n=yt(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...ct(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function wt(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function vt(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!wt(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function Nt(t,e){for(let n=0;n<e.length;n++){const o=e[n];if(o!==t&&o.contains(t))return!0}return!1}function St(t){const n=[],o=vt(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!==pt(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const t=s.currentNode;o.length>0&&Nt(t,o)||n.push(t)}return n}const It=new WeakSet;function xt(t,e,n){const o=function(t,e,n={}){const o=n.allowDeferred??!0;if(!e.some(t=>"spread"===t.bindingType))return e;const s=[],r=new WeakSet;for(const n of e){if("spread"!==n.bindingType){s.push(n);continue}t.nodeType!==Node.ELEMENT_NODE&&z("Spread binding requires an element node.");const e=t,i=O(e);null===i&&z(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${e.tagName.toLowerCase()}> is not a custom element.`);const a=R();if(null===a&&z(`CustomElementRegistry is unavailable for <${i}>.`),void 0===a.get(i)){o||z(`Spread binding "${n.statePathName}" requires <${i}> to be registered. Define the custom element before initializing this binding.`),s.push(n);continue}D(a,e);const l=L(e);null===l&&z(`Spread binding "${n.statePathName}" requires <${i}> to expose a valid wcBindable declaration.`);const c=n.statePathName,d=n.stateName,u=new Set;for(const t of l.knownProperties.keys()){if(u.has(t))continue;u.add(t);const e=q(t,c,d);r.add(e),s.push(e)}for(const t of l.declaredInputs.keys()){if(u.has(t))continue;u.add(t);const e=q(t,c,d);r.add(e),s.push(e)}}const i=new Map;for(let t=0;t<s.length;t++){const e=U(s[t]);null!==e&&i.set(e,t)}const a=[];for(let t=0;t<s.length;t++){const e=U(s[t]);null!==e?i.get(e)===t&&a.push(s[t]):a.push(s[t])}return a}(t,e,{allowDeferred:n.allowDeferred});if(o.some(t=>"spread"===t.bindingType)){const n=t.nodeType===Node.ELEMENT_NODE?O(t):null;return null===n&&z("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:t,tagName:n,parseResults:e}}}It.add(t);const s=function(t,e){const n=[];for(const o of e)if("text"!==o.bindingType)n.push({...o,node:t,replaceNode:t});else{const e=t.nodeType===Node.TEXT_NODE?t:document.createTextNode("");n.push({...o,node:t,replaceNode:e})}return n}(t,o);return function(t,e){H.set(t,e)}(t,s),A(t),{bindings:s,deferred:null}}function $t(t){const e=St(t),n=[],o=[];for(const t of e){if(It.has(t))continue;const e=xt(t,bt(t),{allowDeferred:!0});null===e.deferred?n.push(...e.bindings):o.push(e.deferred)}return[e,n,o]}function _t(t){It.add(t)}function Pt(t){const{node:e,parseResults:n}=t;!function(t){It.delete(t)}(e);return xt(e,n,{allowDeferred:!1}).bindings}const At=new WeakMap;function kt(t){let e=t;for(;e;){const t=At.get(e);if(t)return t;e=e.parentNode}return null}function Ct(t,e){null!==e?At.set(t,e):At.delete(t)}const Et=new WeakMap;function Mt(t){return Et.get(t)??[]}function Tt(t,e){Et.set(t,e)}const Ot=Symbol("$$setLoopContext"),Rt=Symbol("$$getByAddress"),Dt=Symbol("$$hasByAddress"),Lt=Symbol("$$setByAddress"),Wt=Symbol("$$connectedCallback"),Bt=Symbol("$$disconnectedCallback"),jt=Symbol("$$updatedCallback"),Ft=new WeakMap;function zt(t,e){if(Ft.has(t)){const n=Ft.get(t);if(n.has(e))return n.get(e)}else Ft.set(t,new WeakMap);const n=Object.freeze(new qt(t,e));return Ft.get(t).set(e,n),n}class qt{pathInfo;stateName;stateElement;parentAbsolutePathInfo;constructor(t,e){this.pathInfo=e,this.stateName=t.name,this.stateElement=t,null===e.parentPathInfo?this.parentAbsolutePathInfo=null:this.parentAbsolutePathInfo=zt(t,e.parentPathInfo)}}const Ut=new WeakMap,Vt=new WeakMap;class Ht{absolutePathInfo;listIndex;_parentAbsoluteAddress;constructor(t,e){this.absolutePathInfo=t,this.listIndex=e}get parentAbsoluteAddress(){if(void 0!==this._parentAbsoluteAddress)return this._parentAbsoluteAddress;const t=this.absolutePathInfo.parentAbsolutePathInfo;if(null===t)return null;let e=null;return e=this.absolutePathInfo.pathInfo.segments[this.absolutePathInfo.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=Gt(t,e)}}function Gt(t,e){if(null===e){let e=Vt.get(t);return void 0!==e||(e=new Ht(t,null),Vt.set(t,e)),e}{let n=Ut.get(e);void 0===n&&(n=new WeakMap,Ut.set(e,n));let o=n.get(t);return void 0!==o||(o=new Ht(t,e),n.set(t,o)),o}}const Kt=new WeakMap;function Jt(t,e){null===e?Kt.delete(t):Kt.set(t,e)}function Xt(t){return Kt.get(t)||null}const Yt=new Map;function Qt(t,e){let n,o;if(0===t.wildcardCount||0===e.wildcardCount)return 0;if(1===t.wildcardCount&&e.wildcardCount>0&&e.wildcardPathSet.has(t.path))return 1;t.id<e.id?(n=t,o=e):(n=e,o=t);const s=`${n.path}\t${o.path}`;let r=Yt.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Yt.set(s,r),r}function Zt(t,e,n){return e<0||e>=n?null:t.at(e-n)}function te(t,e){const n=t.indexes??[];return n.length===e?n:n.slice(n.length-e)}const ee=new WeakMap;function ne(t){const e=kt(t.node);if(null===e)return null;let n=ee.get(e);if(void 0===n)n=new WeakMap,ee.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=Qt(e.pathInfo,t.statePathInfo);return n>0&&(o=Zt(e.listIndex,n-1,e.pathInfo.wildcardCount)),o}finally{n.set(t,o)}}const oe=new WeakMap;function se(t,e){if(null!=e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Xt(n);null===e?z(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}return n}function re(t,e){let n=null;if(n=oe.get(t)||null,null!==n)return n;const o=se(t,e),s=ne(t),r=xr(o,t.stateName);null===r&&z(`State element with name "${t.stateName}" not found for binding.`);return n=Gt(zt(r,t.statePathInfo),s),oe.set(t,n),n}function ie(t){oe.delete(t)}let ae=null;const le=new WeakMap;function ce(t,e){const n=le.get(t);void 0===n?le.set(t,e):n instanceof Set?n.add(e):n!==e&&le.set(t,new Set([n,e])),null!==ae&&ae({type:"state:binding-added",absoluteAddress:t,binding:e})}function de(t,e){const n=le.get(t);void 0!==n&&(n instanceof Set?n.delete(e):n===e&&le.delete(t),null!==ae&&ae({type:"state:binding-removed",absoluteAddress:t,binding:e}))}const ue=new WeakMap;function fe(t,e,n){let o=ue.get(t);void 0===o&&(o=new WeakMap,ue.set(t,o));const s=o.get(e);void 0===s?o.set(e,n):s instanceof Set?s.add(n):s!==n&&o.set(e,new Set([s,n])),null!==ae&&ae({type:"state:binding-added",absoluteAddress:Gt(t,e),binding:n})}function he(t,e,n){const o=ue.get(t);if(void 0===o)return;const s=o.get(e);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(e),null!==ae&&ae({type:"state:binding-removed",absoluteAddress:Gt(t,e),binding:n}))}function pe(t){const e=le.get(t);return void 0!==e?e:null!==t.listIndex?ue.get(t.absolutePathInfo)?.get(t.listIndex):void 0}const me=new WeakMap,ge=new WeakMap;class ye{pathInfo;listIndex;_parentAddress;constructor(t,e){this.pathInfo=t,this.listIndex=e}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let e=null;return e=this.pathInfo.segments[this.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=be(t,e)}}function be(t,e){if(null===e){let e=ge.get(t);return void 0!==e||(e=new ye(t,null),ge.set(t,e)),e}{let n=me.get(e);void 0===n&&(n=new WeakMap,me.set(e,n));let o=n.get(t);return void 0!==o||(o=new ye(t,e),n.set(t,o)),o}}const we=new WeakMap;function ve(t){let e=null;if(e=we.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=ne(t);null===n&&z(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=be(t.statePathInfo,n)}else e=be(t.statePathInfo,null);return we.set(t,e),e}function Ne(t){we.delete(t)}function Se(){const t=new Map,e=new Map;return{add(n,o){let s=t.get(n);return void 0===s&&(s=new WeakSet,t.set(n,s)),!s.has(o)&&(s.add(o),e.set(n,(e.get(n)??0)+1),!0)},remove(n,o){const s=t.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const r=(e.get(n)??1)-1;return r<=0?(t.delete(n),e.delete(n),!0):(e.set(n,r),!1)},has:(e,n)=>t.get(e)?.has(n)??!1,countOf:t=>e.get(t)??0,get keyCount(){return e.size},clear(){t.clear(),e.clear()}}}const Ie=new Map,xe=Se();function $e(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function _e(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}function Pe(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const s=_e(t),r=$e(t,s);let i=Ie.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==s.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=s.checked;let i=s.value;for(const t of o)i=t.filterFn(i);const a=xr(s.getRootNode(),e);null===a&&z(`State element with name "${e}" not found for two-way binding.`);const l=kt(s);a.createState("writable",t=>{t[Ot](l,()=>{let e=t[n];if(Array.isArray(e))if(r)-1===e.indexOf(i)&&(t[n]=e.concat(i));else{const o=e.indexOf(i);-1!==o&&(t[n]=e.toSpliced(o,1))}else t[n]=r?[i]:[]})})},Ie.set(r,i)),t.node.addEventListener(s,i),xe.add(r,t),!0}var e,n,o;return!1}function Ae(t){return("object"==typeof t||"function"==typeof t)&&null!==t&&"function"==typeof t.then}function ke(t,e){const n=Array.isArray(t)?t:[t];for(const t of n)Ae(t)&&Promise.resolve(t).catch(t=>{console.error(`[wcstack/state] ${e} rejected.`,t)})}class Ce{_name;_subscribers=new Set;constructor(t){this._name=t}get name(){return this._name}get size(){return this._subscribers.size}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}unsubscribe(t){return this._subscribers.delete(t)}emit(...t){const e=[];for(const n of this._subscribers)e.push(n(...t));return e}}class Ee extends Ce{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==ae&&ae({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}const Me=new WeakMap;function Te(t,e){let n=Me.get(t);void 0===n&&(n=new Map,Me.set(t,n));let o=n.get(e);return void 0===o&&(o=new Ee(e,t.name),n.set(e,o)),o}function Oe(t){Me.delete(t)}const Re=new WeakMap;function De(t){if("eventToken"!==t.propSegments[0])return!1;const e=t.node,n=O(e),o=R();if(null!==n&&void 0===o?.get(n))return null===o&&z(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(Re.has(t))return!0;const s=t.propSegments[1];"string"==typeof s&&0!==s.length||z('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(t){return null===O(t)?null:L(t)}(e);null===r&&z(`eventToken binding requires a wc-bindable custom element. <${e.tagName.toLowerCase()}> is not wc-bindable.`);const i=r.knownProperties.get(s);void 0===i&&z(`Property "${s}" is not declared in wcBindable.properties of <${e.tagName.toLowerCase()}>.`);const a=i.event,l=t.statePathName,c=t.stateName,d=t.propModifiers,u=t=>{d.includes("prevent")&&t.preventDefault(),d.includes("stop")&&t.stopPropagation();const n=xr(e.getRootNode(),c);null===n&&z(`State element with name "${c}" not found for eventToken handler.`),n.eventTokenNames.has(l)||z(`eventToken "${l}" is not declared in $eventTokens of state "${c}".`);const o=kt(e);n.createStateAsync("writable",async e=>{ke(e[Ot](o,()=>{const s=null!==o?te(o.listIndex,o.pathInfo.wildcardCount):[];return Te(n,l).emit(e,t,...s)}),`$on."${l}" of state "${c}"`)})};return e.addEventListener(a,u),Re.set(t,{eventName:a,handler:u}),!0}class Le extends Ce{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==ae&&ae({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}function We(t){return t instanceof Le}const Be=new Map,je=Se();function Fe(t){const e=t.propModifiers.filter(t=>"prevent"===t||"stop"===t).sort().join(",");return`${t.stateName}::${t.statePathName}::${e}`}const ze=(t,e,n,o)=>s=>{n.includes("prevent")&&s.preventDefault(),n.includes("stop")&&s.stopPropagation();const r=s.target,i=xr(r.getRootNode(),t);null===i&&z(`State element with name "${t}" not found for event handler.`);const a=kt(r),l=e.startsWith(m+".");i.createStateAsync("writable",async n=>{ke(n[Ot](a,()=>{const r=null!==a?te(a.listIndex,a.pathInfo.wildcardCount):[];if(l){const t=n[Rt](be(o,null));return We(t)||z(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),t.emit(s,...r)}const i=n[e];return"function"!=typeof i&&z(`Handler "${e}" is not a function on state "${t}".`),Reflect.apply(i,n,[s,...r])}),`"${e}" of state "${t}"`)})};function qe(t){if(!t.propName.startsWith("on"))return!1;const e=Fe(t);let n=Be.get(e);void 0===n&&(n=ze(t.stateName,t.statePathName,t.propModifiers,t.statePathInfo),Be.set(e,n));const o=t.propName.slice(2);return t.node.addEventListener(o,n),je.add(e,t),!0}const Ue=new Map,Ve=Se();function He(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function Ge(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}function Ke(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const s=Ge(t),r=He(t,s);let i=Ue.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==s.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===s.checked)return;let r=s.value;for(const t of o)r=t.filterFn(r);const i=xr(s.getRootNode(),e);null===i&&z(`State element with name "${e}" not found for two-way binding.`);const a=kt(s);i.createState("writable",t=>{t[Ot](a,()=>{t[n]=r})})},Ue.set(r,i)),t.node.addEventListener(s,i),Ve.add(r,t),!0}var e,n,o;return!1}const Je=new Set(["radio","checkbox"]),Xe=new Set(["value","valueAsNumber","valueAsDate"]);function Ye(t,e){if(t.nodeType!==Node.ELEMENT_NODE)return!1;const n=t,o=n.tagName.toLowerCase();if("input"===o){const t=(n.getAttribute("type")||"text").toLowerCase();if("button"===t)return!1;if(Je.has(t)&&"checked"===e)return!0;if(Xe.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=O(n);if(null!==s){const t=R()?.get(s);void 0===t&&z(`Custom element <${s}> is not defined. Cannot determine if property "${e}" is suitable for two-way binding.`);const o=L(n);if(o?.knownProperties.has(e))return!0}return!1}let Qe=1,Ze=1,tn=1;const en=new WeakMap;function nn(t,e,n,o){let s=en.get(t);void 0===s&&(s=new Map,en.set(t,s));const r=function(t,e,n){return`${e}::${n}::${t}`}(e,n,o);let i=s.get(r);return void 0===i&&(i=Qe++,s.set(r,i)),i}function on(t,e){return"to-element"===e?2*t:2*t+1}const sn=new Set;function rn(t){return{transactionId:Ze++,originBindingId:t,visitedEdges:sn,hop:0}}function an(t,e){const n=new Set(t.visitedEdges);return n.add(e),{transactionId:t.transactionId,originBindingId:t.originBindingId,visitedEdges:n,hop:t.hop+1}}let ln=null;function cn(){return ln}function dn(t,e){const n=ln;ln=t;try{return e()}finally{ln=n}}const un=[];let fn=!1;const hn=new Map,pn=Se(),mn=new WeakMap,gn=t=>t.detail;function yn(t,e,n,o){const s=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${s}::${n?"g":"n"}::${o?"o":"s"}`}function bn(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";const n=O(t.node);if(null!==n){const o=R()?.get(n);void 0===o&&z(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=L(t.node)?.knownProperties.get(t.propName);s&&(e=s.event)}for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}function wn(t){if(null!==O(t.node)){const e=L(t.node)?.knownProperties.get(t.propName);if(e)return e.getter??gn}return null}function vn(t){if(null===O(t.node))return!1;const e=L(t.node)?.knownProperties.get(t.propName);return"event"===e?.semantics}const Nn=(t,e,n,o,s,r)=>i=>{const a=i.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(i);else{if(!(e in a))return void console.warn(`[@wcstack/state] Property "${e}" does not exist on target element.`);l=a[e]}let c=l;for(const t of o)c=t.filterFn(c);const d=mn.get(a)?.get(e);if(void 0!==d)for(const t of d)t(c);let u=null;{const o=nn(a,e,t,n),s=function(t,e){for(let n=un.length-1;n>=0;n--){const o=un[n];if(o.node===t&&o.receipt.member===e)return o.receipt}return null}(a,e);if(null!==s&&Object.is(s.writtenValue,l))return void(null!==ae&&ae({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:on(o,"to-state"),node:a,member:e}));const r=on(o,"to-state"),i=cn();if(null!==i&&i.visitedEdges.has(r))return void(null!==ae&&ae({type:"propagation:suppressed",reason:"visited-edge",transactionId:i.transactionId,edgeId:r,node:a,member:e}));u=an(i??rn(o),r)}const f=xr(a.getRootNode(),t);null===f&&z(`State element with name "${t}" not found for two-way binding.`);const h=kt(a),p=()=>{r&&(fn=!0);try{f.createState("writable",t=>{t[Ot](h,()=>{t[n]=c})})}finally{r&&(fn=!1)}};null!==u?dn(u,p):p()};const Sn=new WeakMap;function In(t,e){const n=Sn.get(t);return n?n.get(e)??null:null}const xn=new WeakMap;function $n(t,e){xn.set(t,e)}function _n(t){return xn.get(t)??null}function Pn(t){let e=t;for(;;){if(null==e||!0!==e.hasMappedComponentState)return null;const t=e.boundComponent;if(null==t)return null;const n=kt(t)?.listIndex;if(null!=n)return n;e=_n(t)}}function An(t){return Pn(t)?.length??0}function kn(t,e){return e.wildcardCount+An(t)}function Cn(t,e){return e??Pn(t)}const En=new WeakMap,Mn=new WeakMap,Tn=new WeakMap,On=new WeakMap;function Rn(t,e){return{innerAbsPathInfo:zt(t,E(e.propSegments.slice(1).join(n))),outerAbsPathInfo:re(e).absolutePathInfo}}function Dn(t,e,o=!0){let s=En.get(t);if(void 0===s&&(s=new Map,En.set(t,s)),s.has(e))return s.get(e);let r=Mn.get(t);void 0===r&&(r=new Map,Mn.set(t,r));const i=Tn.get(t);if(void 0===i)return null;let a=null;for(const t of i)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&z("Duplicate mapping rule for web component."),a=t;break}if(null===a)return null;const l=On.get(a);void 0===l&&z("Binding not found for primary mapping rule on web component.");const c=e.pathInfo.segments.slice(a.innerAbsPathInfo.pathInfo.segments.length),d=E(a.outerAbsPathInfo.pathInfo.segments.concat(c).join(n)),u=xr(t.getRootNode(),l.stateName);null===u&&z(`State element with name "${l.stateName}" not found for web component.`);const f=zt(u,d);if(!o)return f;s.set(e,f),r.set(f,e);const h=[l.propSegments[0],...e.pathInfo.segments],p={...l,propName:h.join(n),propSegments:h,statePathName:f.pathInfo.path,statePathInfo:f.pathInfo},m=No(l);return null===m||f.pathInfo.wildcardCount>0&&null===ne(p)||m.initialize([p],{registerAddress:!0}),f}function Ln(t,e){const n=Wn(t,e);if(null===n||n.stateElement===t)return null;return kn(t,e)!==kn(n.stateElement,n.pathInfo)?null:n}function Wn(t,e){if(!0!==t.hasMappedComponentState)return null;const n=t.boundComponent;if(null==n)return null;return Dn(n,zt(t,e),!1)}const Bn=new WeakSet;function jn(t){Bn.add(t)}function Fn(t){return!!Bn.has(t)&&(Bn.delete(t),!0)}const zn=new WeakSet;function qn(t){zn.add(t)}function Un(t){return!!zn.has(t)&&(zn.delete(t),!0)}let Vn=0;function Hn(){Vn--}function Gn(){return Vn>0}class Kn{registry;entries=new Map;constructor(t){this.registry=t}wait(t,e,n=()=>{}){const o=t.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),t=>this.settle(o,t)));const r={active:!0,resolve:e,reject:n};return s.waiters.add(r),()=>{r.active&&(r.active=!1,s?.waiters.delete(r))}}pendingCount(t){return this.entries.get(t.toLowerCase())?.waiters.size??0}settle(t,e){const n=this.entries.get(t);if(void 0===n)return;this.entries.delete(t);const o=Array.from(n.waiters);n.waiters.clear();for(const t of o)t.active&&(t.active=!1,null===e?t.resolve():t.reject(e))}}const Jn=new WeakMap;function Xn(t){let e=Jn.get(t);return void 0===e&&(e=new Kn(t),Jn.set(t,e)),e}function Yn(t,e){let n=null;for(const o of t.propModifiers){const t=o.indexOf("=");if(t<0)continue;const s=o.slice(0,t).trim(),r=o.slice(t+1).trim();"init"!==s&&"sync"!==s&&z(`Unknown binding modifier "${s}" in "${o}".`),s===e&&(null!==n&&z(`Binding modifier "${e}" may only be specified once.`),n=r)}return n}const Qn=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),Zn=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function to(t,e){return"state"===t&&"call"===e?Qn:{authority:t,syncOn:e,observable:!1,outputOnly:!1}}function eo(t){const e=null===(n=Yn(t,"init"))?null:"state"===n||"element"===n||"auto"===n||"none"===n?n:z(`Invalid init modifier value "${n}".`);var n;const o=function(t){return null===t||"call"===t?"call":"connect"===t?"connect":z(`Invalid sync modifier value "${t}".`)}(Yn(t,"sync"));if("event"===t.bindingType)return null!==e&&"none"!==e&&z("Event bindings only allow init=none."),"call"===o?Zn:{authority:"none",syncOn:o,observable:!1,outputOnly:!1};if("command"===t.propSegments[0])return to("state",o);if("prop"!==t.bindingType)return null!==e&&"state"!==e&&"none"!==e&&z(`Binding type "${t.bindingType}" does not support init=${e}.`),to(e??"state",o);const s=L(t.node);if(null===s)return to(e??"state",o);const r=s.knownProperties.has(t.propName),i=s.declaredInputs.has(t.propName);r||i||z(`Property "${t.propName}" is not declared by wcBindable.`);const a=e??(r&&!i?"element":"state");return(r&&i?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(a)||z(`init=${a} is incompatible with wcBindable member "${t.propName}".`),"connect"!==o||r||z(`sync=connect requires observable property "${t.propName}".`),{authority:a,syncOn:o,observable:r,outputOnly:r&&!i}}function no(t,e){return"auto"!==e?e:function(t){const e=xr(t.replaceNode.getRootNode(),t.stateName);null===e&&z(`State element with name "${t.stateName}" not found for binding.`);const n=ve(t);let o=!1;return e.createState("readonly",t=>{o=t[Dt](n)}),o}(t)?"state":"element"}let oo=0,so=0;const ro=new WeakMap,io=new WeakMap,ao=new WeakMap,lo=new WeakMap;function co(t,e){const n=lo.get(t);void 0!==n?n!==e&&(n instanceof Set?n.add(e):lo.set(t,new Set([n,e]))):lo.set(t,e)}function uo(t,e){const n=lo.get(t);if(void 0!==n)if(n instanceof Set)for(const t of Array.from(n))e(t);else e(n)}function fo(t,e){if(e(t),null!==t.firstChild)for(const n of Array.from(t.childNodes))fo(n,e)}function ho(t){if("object"!=typeof t||null===t)return!1;const e=t;return 9===e.nodeType||11===e.nodeType&&"host"in e}class po{root;observer;constructor(t){this.root=t;const e=globalThis.MutationObserver;this.observer="function"==typeof e?new e(t=>this.handleMutations(t)):null,this.observer?.observe(t,{childList:!0,subtree:!0})}handleMutations(t){const e=[],n=[];for(const o of t)e.push(...Array.from(o.removedNodes)),n.push(...Array.from(o.addedNodes));const o=[];for(const t of e)Fn(t)||fo(t,t=>{uo(t,e=>{this.root.contains(t)||e.handleRemovedNode(t)})});for(const t of n)Un(t)&&!Gn()||fo(t,t=>{uo(t,e=>{this.root.contains(t)&&e.handleAddedNode(t,o)})});o.length>0&&Ws(o)}}const mo=new WeakMap;function go(t){let e=mo.get(t);return void 0===e&&(e=new po(t),mo.set(t,e)),e}function yo(t){const e=t.inFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|"),n=t.outFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|");return[t.bindingType,t.propName,t.propModifiers.join(","),t.stateName,t.statePathName,e,n,t.uuid??""].join("\0")}function bo(t,e){null===t.teardowns&&(t.teardowns=new Set),t.teardowns.add(e)}class wo{records=new Set;rowPlan=null;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(t=null){null!==t&&this.observe(t)}initialize(t,e={},n){const o=e.registerAddress??!0,s={registerAddress:o,registerPathInfo:e.registerPathInfo??o,applyOnReconnect:e.applyOnReconnect??!0},r=[];for(const e of t){const t=this.remember(e,s),o=ro.get(t);void 0===o||"disposed"===o.phase||"failed"===o.phase?(this.start(t,s,n),r.push(t)):(this.observe(o.anchor),s.registerAddress&&null===o.address&&null===o.patternListIndex&&(o.options.registerAddress=!0,this.registerAddress(o)),"active"===o.phase&&this.settleInitialRecord(o),this.settleConnectedSnapshot(o))}return r.filter(t=>this.shouldApplyState(t))}activate(t,e){if(ho(e)&&go(e),null===this.rowPlan)for(const n of t){const t=ro.get(n);if(void 0!==t&&t.session===this&&"disposed"!==t.phase&&"failed"!==t.phase){null===t.address&&null===t.patternListIndex&&(t.options.registerAddress=!0,this.registerAddress(t,e)),"active"===t.phase&&this.settleInitialRecord(t),this.settleConnectedSnapshot(t);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,e)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,t,e)}shouldApplyState(t){const e=ro.get(t);return void 0===e||e.session!==this||(!e.options.registerAddress||"waiting-definition"===e.phase||"failed"!==e.phase&&("active"===e.phase&&this.settleInitialRecord(e),e.initialApplyDone?"state"===e.resolvedAuthority||!e.outputOnlyMember&&!e.observationPending:(e.initialApplyDone=!0,"state"===e.resolvedAuthority)))}getRecord(t){const e=ro.get(t);return e?.session===this?e:null}addTeardown(t,e){const n=ro.get(t);return!(void 0===n||!this.isAlive(n,n.generation))&&(bo(n,e),!0)}deferUntilDefined(t,e,n,o=()=>{}){const s=R();null===s&&z(`CustomElementRegistry is unavailable for <${e}>.`),this.observe(t),co(t,this);const r={node:t,active:!0,cancel:null};let i=this.deferredByNode.get(t);void 0===i&&(i=new Set,this.deferredByNode.set(t,i)),i.add(r),this.deferred.add(r);const a=()=>!!r.active&&(r.active=!1,i?.delete(r),this.deferred.delete(r),!0);return r.cancel=Xn(s).wait(e,()=>{if(a())try{D(s,t),n()}catch(t){o(t)}},t=>{a()&&o(t)}),()=>{a()&&r.cancel?.()}}disposeBinding(t){const e=ro.get(t);void 0!==e&&e.session===this&&this.disposeRecord(e)}dispose(){for(const t of Array.from(this.records))this.disposeRecord(t);for(const t of Array.from(this.deferred))t.active=!1,t.cancel?.(),this.deferred.delete(t),this.deferredByNode.get(t.node)?.delete(t)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;for(const t of this.records)if(t.pendingDefinitions>0||t.observationPending)return!1;return!0}destroyRecords(){for(const t of this.records)null!==t.address&&(de(t.address,t.info),t.address=null),t.phase="disposed",t.teardowns=null;this.records.clear()}observe(t){const e=function(t){const e=t.getRootNode();return ho(e)?e:null}(t);null!==e&&go(e)}handleMutations(t,e,n){for(const n of e)fo(n,e=>{t.contains(e)||this.handleRemovedNode(e)});const o=[];for(const e of n)fo(e,e=>{t.contains(e)&&this.handleAddedNode(e,o)});o.length>0&&Ws(o)}handleRemovedNode(t){const e=this.knownBindingsByNode.get(t);if(void 0!==e)if(e instanceof Map)for(const t of e.values())this.disposeBinding(t);else this.disposeBinding(e);const n=this.deferredByNode.get(t);if(void 0!==n)for(const t of Array.from(n))t.active=!1,t.cancel?.(),n.delete(t),this.deferred.delete(t)}handleAddedNode(t,e){const n=this.knownBindingsByNode.get(t);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const t of o){const n=ro.get(t);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(t);if(void 0!==o)try{this.start(t,o),o.applyOnReconnect&&this.shouldApplyState(t)&&e.push(t)}catch{}}}knownMapFor(t){const e=this.knownBindingsByNode.get(t);if(e instanceof Map)return e;const n=new Map;if(void 0!==e){let t=ao.get(e);void 0===t&&(t=yo(e),ao.set(e,t)),n.set(t,e)}return this.knownBindingsByNode.set(t,n),n}remember(t,e){const n=t.replaceNode;co(n,this);const o=this.knownMapFor(n);let s=ao.get(t);void 0===s&&(s=yo(t),ao.set(t,s));const r=o.get(s);if(void 0!==r){const t=this.optionsByBinding.get(r);return void 0!==t&&(t.registerAddress||=e.registerAddress,t.registerPathInfo||=e.registerPathInfo,t.applyOnReconnect||=e.applyOnReconnect),r}return o.set(s,t),this.optionsByBinding.set(t,{...e}),t}initializeRow(t,e){this.rowPlan=t;const n={registerAddress:!1,registerPathInfo:!1,applyOnReconnect:!1},o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=o[t],i=s.replaceNode;co(i,this),this.addKnownRowBinding(i,s,t),this.optionsByBinding.set(s,n);const a={id:++oo,info:s,generation:++so,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest:null,pendingDefinitions:0,initialPolicy:r.policy,resolvedAuthority:r.authority,initialSettled:!0,initialApplyDone:!1,outputOnlyMember:r.policy.outputOnly,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};if(ro.set(s,a),this.records.add(a),r.isEvent){try{qe(s)}catch(t){throw a.phase="failed",this.runTeardowns(a),this.records.delete(a),t}a.eventAttached=!0}}}activatePlanRows(t,e,n){const o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=ro.get(s);if(void 0!==r&&r.session===this){if(r.options.registerAddress=!0,"disposed"===r.phase||"failed"===r.phase){const e=o[t];if(r.generation=++so,r.phase="active",r.initialPolicy=e.policy,r.resolvedAuthority=e.authority,r.initialSettled=!0,r.initialApplyDone=!1,r.outputOnlyMember=e.policy.outputOnly,this.records.add(r),e.isEvent){try{qe(s)}catch(t){throw r.phase="failed",this.runTeardowns(r),this.records.delete(r),t}r.eventAttached=!0}this.registerAddress(r,n);continue}null===r.address&&null===r.patternListIndex&&this.registerAddress(r,n)}else this.initialize([s],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}}addKnownRowBinding(t,e,n){const o=this.knownBindingsByNode.get(t);if(void 0===o)return void this.knownBindingsByNode.set(t,e);if(o instanceof Map)return void o.set("@plan:"+n,e);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,e),this.knownBindingsByNode.set(t,s)}start(t,e,n){!function(t){const e=t.node,n=t.replaceNode;e!==n&&null!==e.parentNode&&e.parentNode.replaceChild(n,e)}(t);const o=this.optionsByBinding.get(t)??{...e},s={id:++oo,info:t,generation:++so,phase:"discovered",teardowns:null,session:this,anchor:t.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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};ro.set(t,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(t){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),t}}attachListeners(t){const e=t.info;qe(e)?t.eventAttached=!0:"eventToken"!==e.propSegments[0]?(Ke(e)&&bo(t,()=>function(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=Ge(t),n=He(t,e),o=Ue.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==Ve.countOf(n)&&(Ve.remove(n,t)&&Ue.delete(n),!0))}return!1}(e)),Pe(e)&&bo(t,()=>function(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=_e(t),n=$e(t,e),o=Ie.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==xe.countOf(n)&&(xe.remove(n,t)&&Ie.delete(n),!0))}return!1}(e)),this.attachAfterDefinition(t,()=>{if(Ye(e.node,e.propName)&&-1===e.propModifiers.indexOf("ro")){const n=function(t,e,n){let o=mn.get(t);void 0===o&&(o=new Map,mn.set(t,o));let s=o.get(e);return void 0===s&&(s=new Set,o.set(e,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(e),0===o?.size&&mn.delete(t)}}(e.node,e.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});bo(t,n)}!function(t){const e=O(t.node);if(null!==e){const t=R(),n=t?.get(e);if(void 0===n)return void(null===t&&z(`CustomElementRegistry is unavailable for <${e}>.`))}if(Ye(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const e=bn(t),n=wn(t),o=vn(t),s=yn(t,e,null!==n,o);let r=hn.get(s);void 0===r&&(r=Nn(t.stateName,t.propName,t.statePathName,t.inFilters,n,o),hn.set(s,r)),t.node.addEventListener(e,r),pn.add(s,t)}}(e),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{De(e)&&bo(t,()=>function(t){if("eventToken"!==t.propSegments[0])return!1;const e=Re.get(t);return void 0!==e&&(t.node.removeEventListener(e.eventName,e.handler),Re.delete(t),!0)}(e))})}attachAfterDefinition(t,e){const n=O(t.info.node);if(null===n)return void e();const o=R();if(null===o&&z(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void e();t.phase="waiting-definition",t.pendingDefinitions+=1;const s=t.generation,r=Xn(o).wait(n,()=>{if(this.isAlive(t,s))try{D(o,t.info.node),e(),t.pendingDefinitions-=1,0===t.pendingDefinitions&&(t.phase="active",this.settleInitialRecord(t))}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}},()=>{this.isAlive(t,s)&&(t.phase="failed",this.runTeardowns(t),this.records.delete(t))});bo(t,r)}settleInitialRecord(t){if(!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=eo(t.info),n=no(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 Vn++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(t,e){if(!this.isAlive(t,t.generation))return;const n=t.info.node,o=t.info.propName;if(!(o in n))return;const s=t.eventSequence,r=n[o];t.observationPending&&(t.observationPending=!1,Hn()),e&&t.eventSequence!==s||(t.hasProducerValue=!0,t.producerValue=r,"element"===t.resolvedAuthority&&function(t,e){let n=e;for(const e of t.inFilters)n=e.filterFn(n);const o=xr(t.node.getRootNode(),t.stateName);null===o&&z(`State element with name "${t.stateName}" not found for initial binding sync.`);const s=kt(t.node);o.createState("writable",e=>{e[Ot](s,()=>{e[t.statePathName]=n})})}(t.info,r))}settleConnectedSnapshot(t){if(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(t,e){if(null!==t.address||null!==t.patternListIndex)return;const n=t.info,o=ne(n);if(null!==o){const i=xr(se(n,e),n.stateName);null===i&&z(`State element with name "${n.stateName}" not found for binding.`);const a=zt(i,n.statePathInfo);fe(a,o,n),t.patternPathInfo=a,t.patternListIndex=o;const l=(s=i,0===(r=n.statePathInfo).wildcardCount?null:Ln(s,r));if(null!==l){fe(l,o,n),t.outerPatternPathInfo=l;const e=function(t){let e=null,n=t.stateElement,o=t.pathInfo;for(;;){const t=Ln(n,o);if(null===t)return e;(e??=[]).push(t),n=t.stateElement,o=t.pathInfo}}(l);if(null!==e){for(let t=0;t<e.length;t++)fe(e[t],o,n);t.outerPatternPathInfosRest=e}}}else{const o=re(n,e);ce(o,n),t.address=o}var s,r;if(!t.options.registerPathInfo)return;const i=xr(n.replaceNode.getRootNode(),n.stateName);null===i&&z(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&i.setPathInfo(n.statePathName,n.bindingType)}isAlive(t,e){return t.generation===e&&ro.get(t.info)===t&&"disposed"!==t.phase&&"failed"!==t.phase}disposeRecord(t){"disposed"!==t.phase&&(t.phase="disposed",this.runTeardowns(t),this.records.delete(t))}runTeardowns(t){t.observationPending&&(t.observationPending=!1,Hn());const e=t.info;if(null!==t.address)try{de(t.address,e),t.address=null,Ne(e),ie(e)}catch{}else if(null!==t.patternListIndex){if(null!==t.outerPatternPathInfo){try{he(t.outerPatternPathInfo,t.patternListIndex,e)}catch{}t.outerPatternPathInfo=null}if(null!==t.outerPatternPathInfosRest){const n=t.outerPatternPathInfosRest;for(let o=0;o<n.length;o++)try{he(n[o],t.patternListIndex,e)}catch{}t.outerPatternPathInfosRest=null}try{he(t.patternPathInfo,t.patternListIndex,e),t.patternPathInfo=null,t.patternListIndex=null,Ne(e),ie(e)}catch{}}if(t.twowayAttached){t.twowayAttached=!1;try{!function(t){const e=O(t.node);if(null!==e){const t=R(),n=t?.get(e);if(void 0===n)return}if(Ye(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const e=bn(t),n=yn(t,e,null!==wn(t),vn(t)),o=hn.get(n);if(void 0===o)return;t.node.removeEventListener(e,o),pn.remove(n,t)&&hn.delete(n)}}(e)}catch{}}if(null!==t.teardowns){const e=Array.from(t.teardowns).reverse();t.teardowns=null;for(const t of e)try{t()}catch{}}if(t.eventAttached){t.eventAttached=!1;try{!function(t){if(!t.propName.startsWith("on"))return!1;const e=Fe(t),n=Be.get(e);if(void 0===n)return!1;const o=t.propName.slice(2);t.node.removeEventListener(o,n),0!==je.countOf(e)&&(je.remove(e,t)&&Be.delete(e))}(e)}catch{}}}}function vo(t){let e=io.get(t);return void 0===e&&(e=new wo(t),io.set(t,e)),e}function No(t){return ro.get(t)?.session??null}const So=new WeakMap;function Io(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const xo=Object.freeze([]);const $o=new WeakMap;const _o=new WeakMap;function Po(t){return _o.get(t)??[]}function Ao(t,e){_o.set(t,e)}Set.prototype.difference||(Set.prototype.difference=function(t){const e=new Set(this);for(const n of t)e.delete(n);return e}),Set.prototype.intersection||(Set.prototype.intersection=function(t){const e=new Set;for(const n of t)this.has(n)&&e.add(n);return e});let ko=0;function Co(){return`u${(ko++).toString(36)}`}let Eo=0;class Mo{uuid=Co();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;constructor(t,e){this.parentListIndex=t,this.position=t?t.position+1:0,this.length=this.position+1,this._index=e,this._version=Eo}get index(){return this._index}set index(t){this._index=t,this._version=++Eo,this.indexes[this.position]=t}get version(){return this._version}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=Eo),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0===this._listIndexes&&(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)]),this._listIndexes}get varName(){return`$${this.position+1}`}at(t){return t>=0?this.listIndexes[t]?.deref()||null:this.listIndexes[this.listIndexes.length+t]?.deref()||null}}function To(t,e){return new Mo(t,e)}const Oo=new WeakMap;function Ro(t){return Oo.get(t)||null}function Do(t,e){null!==e?Oo.set(t,e):Oo.delete(t)}const Lo=new WeakMap,Wo=Object.freeze([]),Bo=new Set;function jo(t,e,n){const o=function(t,e,n){const o=Array.isArray(e)&&e.length>0?e:Wo,s=Array.isArray(n)&&n.length>0?n:Wo,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:Wo,o=Array.isArray(e)&&e.length>0?e:Wo;let s=Lo.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=Ro(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:Bo,deleteIndexSet:new Set(i),addIndexSet:Bo};let e=Ro(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=To(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:Bo,deleteIndexSet:Bo,addIndexSet:new Set(e)}}if(function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(o,s))return a={oldIndexes:i,newIndexes:i,changeIndexSet:Bo,deleteIndexSet:Bo,addIndexSet:Bo};if(null!==e)return function(t,e){const n=new Set(e),o=new Set(t),s=new Set,r=n.difference(o),i=o.difference(n),a=new Map;for(let e=0;e<t.length;e++)a.set(t[e],e);for(let t=0;t<e.length;t++){const n=e[t];r.has(n)||a.get(n)!==t&&s.add(n)}return{oldIndexes:t,newIndexes:e,changeIndexSet:s,deleteIndexSet:i,addIndexSet:r}}(i,e);e=[];const n=new Map;for(let t=0;t<o.length;t++){const e=o[t];let s=n.get(e);s||(s=[],n.set(e,s)),s.push(t)}const r=new Set,l=new Set;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),d=c&&c.length>0?c.shift():void 0;if(void 0===d){const n=To(t,o);e.push(n),l.add(n)}else{const t=i[d];d!==o&&r.add(t),e.push(t)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(e)),addIndexSet:l}}finally{void 0!==a&&(!function(t,e,n){let o=Lo.get(t);o||(o=new WeakMap,Lo.set(t,o)),o.set(e,n)}(o,s,a),Do(s,a.newIndexes))}}(t,e,n);return function(t){for(let e=0;e<t.length;e++)t[e].index!==e&&(t[e].index=e)}(o.newIndexes),o}function Fo(t){if(0===t.changeIndexSet.size||t.addIndexSet.size===t.newIndexes.length)return null;const e=new Map;for(let n=0;n<t.oldIndexes.length;n++)e.set(t.oldIndexes[n],n);const n=[],o=[];let s=-1,r=!0;for(const i of t.newIndexes){if(t.addIndexSet.has(i))continue;const a=e.get(i);if(void 0===a)return null;a<s&&(r=!1),s=a,n.push(i),o.push(a)}if(r)return null;const i=function(t){const e=t.length,n=[],o=new Array(e).fill(-1);for(let s=0;s<e;s++){const e=t[s];let r=0,i=n.length;for(;r<i;){const o=r+i>>1;t[n[o]]<e?r=o+1:i=o}r>0&&(o[s]=n[r-1]),n[r]=s}const s=[];let r=n.length>0?n[n.length-1]:-1;for(;r>=0;)s.push(r),r=o[r];return s.reverse(),s}(o),a=new Set;for(const t of i)a.add(n[t]);return a}const zo=new WeakMap;function qo(t){return zo.get(t)??[]}function Uo(t,e){zo.set(t,e)}const Vo=new WeakMap;function Ho(t){return Vo.get(t)??null}function Go(t,e){Vo.set(t,e)}const Ko=new WeakMap;function Jo(t){return Ko.get(t)??[]}function Xo(t,e){Ko.set(t,e)}function Yo(t,e){const n=Jo(t);for(const t of n)Ct(t,e)}function Qo(t,e,n){Yo(t,e);const o=qo(t),s=Ho(t);null!==s&&s.activate(o,n.rootNode);for(const t of o){if(null===s){ce(re(t),t)}(null===s||s.shouldApplyState(t))&&Ls(t,n)}}function Zo(t){if(!t.mounted)return;const e=qo(t),n=Ho(t);for(const t of e)if(null!==n)n.disposeBinding(t);else{de(re(t),t)}!function(t){const e=Jo(t);for(const t of e)Ct(t,null)}(t)}const ts=new WeakMap,es=Object.freeze(new Set);function ns(t,e){const n=ts.get(t);n?n.add(e):ts.set(t,new Set([e]))}function os(t){const e=ts.get(t);return void 0!==e?e:es}function ss(t,e){const n=ts.get(t);n&&(n.delete(e),0===n.size&&ts.delete(t))}const rs=new Set(["if","elseif","else","for"]);class is{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(t,e=!1){this._content=t,this._ranged=e,this._childNodeArray=Array.from(this._content.childNodes),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(t){for(const e of this._childNodeArray)qn(e),t.appendChild(e);this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const t=this._firstNode,e=this._lastNode;if(null===t||null===e||null===t.parentNode)return this._childNodeArray;const n=[];for(let o=t;null!==o;o=o.nextSibling)if(n.push(o),o===e)return n;return this._childNodeArray}mountAfter(t){const e=t.parentNode;if(e){let n=t;for(const t of this._movableNodes())n.nextSibling!==t&&(qn(t),e.insertBefore(t,n.nextSibling)),n=t}this._mounted=!0}tryDestroy(){const t=Ho(this);if(null===t||!t.canWholesaleDestroy())return!1;t.destroyRecords();for(const t of this._childNodeArray)jn(t),null!==t.parentNode&&t.parentNode.removeChild(t);const e=qo(this);for(const t of e)if(rs.has(t.bindingType)){const e=os(t.node);for(const t of e)t.tryDestroy()||t.unmount()}return this._mounted=!1,!0}unmount(){Ho(this)?.dispose();for(const t of this._childNodeArray)jn(t),null!==t.parentNode&&t.parentNode.removeChild(t);const t=qo(this);for(const e of t){if(rs.has(e.bindingType)){const t=os(e.node);for(const e of t)e.unmount()}Ne(e),ie(e)}this._mounted=!1}}function as(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 ls(t){const e=document.createDocumentFragment(),n=new is(e);return n._childNodeArray=t,n._firstNode=t.length>0?t[0]:null,n._lastNode=t.length>0?t[t.length-1]:null,n._mounted=!0,n}function cs(t,e,n){const o=document.importNode(e.fragment,!0),s=e.nodeInfos,r=new Array(s.length);for(let t=0;t<s.length;t++){const e=V(o,s[t].nodePath);null===e&&z(`Node not found by path [${s[t].nodePath.join(", ")}] in fragment.`),_t(e),A(e),r[t]=e}const i=n.slots,a=new Array(i.length),l=[];for(let t=0;t<i.length;t++){const e=i[t],n=r[e.nodeIndex],o={...e.template,node:n,replaceNode:n};a[t]=o,e.isIndexBinding&&l.push(o)}const c=function(t,e){const n=new wo;return n.initializeRow(t,e),n}(n,a),d=new is(o);return Go(d,c),Uo(d,a),Ao(d,l),Xo(d,r),ns(t.node,d),d}function ds(n){void 0!==n.uuid&&null!==n.uuid||z("BindingInfo.uuid is null.");const o=yt(n.uuid);o||z(`Fragment with UUID "${n.uuid}" not found.`);const s=!t()&&as(o);let r=o.rowPlan;if((void 0===r||null!==r&&r.directional!==e.enableDirectionalInitialSync)&&(r=o.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],r=V(t.fragment,n.nodePath);if(null===r)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("command"===s||"eventToken"===s)return null;if("text"===n){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==O(r))return null;if("prop"===n&&Ye(r,t.propName))return null;let i;try{i=eo({...t,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;o.push({nodeIndex:e,template:t,isEvent:"event"===n,isIndexBinding:t.statePathName in a,policy:i,authority:i.authority})}}return{directional:n,slots:o}}(o)),null!==r)return cs(n,o,r);const i=document.importNode(o.fragment,!0),l=function(t,e){const[n,o]=function(t,e){const n=[],o=[];for(const s of e){const e=V(t,s.nodePath);if(null===e&&z(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),It.has(e))continue;const r=xt(e,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(e)}return[n,o]}(t,e),s=new wo,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,o.nodeInfos);s&&function(t,e){t.appendChild(document.createComment(`wcs-row-end:${e}`))}(i,n.uuid);const c=new is(i,s);Go(c,l.bindingSession),Uo(c,l.bindingInfos);const d=[];for(const t of l.bindingInfos)t.statePathName in a&&d.push(t);return Ao(c,d),Xo(c,l.nodes),ns(n.node,c),c}const us=new WeakMap,fs=new WeakMap,hs=new WeakMap,ps=new WeakMap;function ms(t,e,n){!function(t,e,n){let o=fs.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,fs.set(t,o)}null===n?o.delete(e):o.set(e,n)}(t,e,n)}function gs(t,e){us.set(t,e)}function ys(t,e){let n=hs.get(t.node);void 0===n&&(n=[],hs.set(t.node,n)),n.length<1e3?n.push(e):ss(t.node,e)}function bs(t,e){if(null===e)return!1;if(t.nextSibling===e)return!0;const n=t.compareDocumentPosition(e);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}function ws(e,n,o){const s=Boolean(o);let r;const i=os(e.node);r=0===i.size?ds(e):i.values().next().value;const a=t(),l=e.uuid??"",c=e.bindingType;if(s||(Zo(r),r.unmount()),s){if(a){const t=document.createComment(`@@wcs-${c}-start:${l}:${e.statePathName}`);e.node.parentNode.insertBefore(t,e.node.nextSibling),r.mountAfter(t);const n=document.createComment(`@@wcs-${c}-end:${l}:${e.statePathName}`),o=r.lastNode??t;o.parentNode.insertBefore(n,o.nextSibling)}else r.mountAfter(e.node);Qo(r,kt(e.node),n)}}const vs=new WeakMap;function Ns(t){return vs.get(t)??[]}const Ss=new Set;const Is={value(t,e){"TEXTAREA"===t.tagName?t.textContent=String(e??""):t.setAttribute("value",String(e??""))},checked(t,e){e?t.setAttribute("checked",""):t.removeAttribute("checked")},selected(t,e){e?t.setAttribute("selected",""):t.removeAttribute("selected")},disabled(t,e){e?t.setAttribute("disabled",""):t.removeAttribute("disabled")},selectedIndex(t,e){const n=t.querySelectorAll("option"),o=Number(e);for(let t=0;t<n.length;t++)t===o?n[t].setAttribute("selected",""):n[t].removeAttribute("selected")}};function xs(e,n,o){if(void 0===o)return;const s=e.node,r=e.propSegments;if(1===r.length){const a=r[0];if(s[a]!==o){const t=()=>{let t=!1;try{s[a]=o,t=!0}catch(t){}if(t){const t=function(t,e){const n=O(t);if(null===n)return null;const o=R()?.get(n);if(void 0===o)return null;const s=L(t)?.declaredInputs.get(e);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(s,a);if(null!==t)try{!function(t,e,n){if(null==n)return void t.removeAttribute(e);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);t.setAttribute(e,o)}(s,t,o)}catch(t){}}};if(Ye(s,a)){const r=nn(s,a,e.stateName,e.statePathName),i=on(r,"to-element"),l=n?.propagationContextByBinding?.get(e)??cn()??rn(r);if(l.visitedEdges.has(i))null!==ae&&ae({type:"propagation:suppressed",reason:"visited-edge",transactionId:l.transactionId,edgeId:i,node:s,member:a});else{const e=an(l,i);dn(e,()=>function(t,e,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:e,transactionId:s,synchronousScopeId:tn++,writtenValue:n};un.push({receipt:i,node:t});try{return r()}finally{un.pop()}}(s,a,o,r,e.transactionId,t))}}else t()}if(t()){const t=Is[a];t?t(s,o):(!function(t,e,n){let o=vs.get(t);o||(o=[],vs.set(t,o));const s=o.find(t=>t.propName===e);s?s.value=n:o.push({propName:e,value:n})}(s,a,o),i=s,Ss.add(i))}return}var i;const a=r[0];let l=s[a];for(let t=1;t<r.length-1;t++){const e=r[t];if(null==l)return;l=l[e]}if(l[r[r.length-1]]!==o){if(Object.isFrozen(l))return;try{l[r[r.length-1]]=o}catch(t){}}}const $s=new WeakSet;function _s(t,e,o){const s=t.node,r=t.propSegments;r.length<=1&&z(`Invalid propSegments for web component binding: ${r.join(n)}`);const[i,...a]=r,l=In(s,i);null===l&&z(`State element not bound to "${i}" on web component.`),!1!==l.hasRootNode&&l.createState("readonly",t=>{t.$postUpdate(a.join(n))})}function Ps(t,e){const n=ve(e);if(n.pathInfo.path in a){const t=kt(e.node);return null===t&&z(`ListIndex not found for binding: ${e.statePathName}`),function(t,e){null===t.listIndex&&z("ListIndex not found for loopContext:");const n=a[e];void 0===n&&z(`Invalid index name: ${e}`);const o=Zt(t.listIndex,n,t.pathInfo.wildcardCount);return null===o&&z(`Index not found at position ${n} for loopContext:`),o.index}(t,n.pathInfo.path)}return t[Rt](n)}const As=new WeakSet;function ks(t,e){console.error(`[@wcstack/state] deferred apply failed for <${t}>.`,e)}const Cs={class:function(t,e,n){const o=t.node,s=t.propSegments[1];"boolean"!=typeof n&&z("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},attr:function(t,e,n){const o=t.node,s=t.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},style:function(t,e,n){const o=t.propSegments[1],s=t.node.style;s[o]!==n&&(s[o]=n)},command:function(t,e,n){We(n)||z("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=$o.get(t);if(s&&s.token===o)return;const r=t.node,i=t.propSegments[1];"string"==typeof i&&0!==i.length||z('command binding requires a method name (e.g., "command.fetch").');const a=function(t){const e=O(t);if(null===e)return null;const n=R()?.get(e);return void 0===n&&z(`Custom element <${e}> is not defined for command binding.`),L(t)}(r);null===a&&z(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||z(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),s&&(s.unsubscribe(),$o.delete(t));const l=new WeakRef(r);let c=null;c=o.subscribe((...e)=>{const n=l.deref();if(!n||!n.isConnected)return c?.(),void $o.delete(t);const o=n[i];return"function"!=typeof o&&z(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,e)}),$o.set(t,{token:o,unsubscribe:c,elementRef:l})}},Es={text:function(e,n,o){const s=null==o?"":String(o);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),t()&&!$s.has(e.replaceNode)){$s.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,n,s){const r=e.statePathInfo,i=ne(e),a=re(e),l=Mt(a),c=jo(Cn(n.stateElement,i),l,s);n.newListValueByAbsAddress.set(a,Array.isArray(s)?s:[]);const d=Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(d&&null!==e.node.parentNode){let t=ps.get(e.node);if(void 0===t){const n=us.get(e.node)||e.node;t=function(t,e){let n=t.previousSibling,o=e.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(e.node,n),ps.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}let u=fs.get(e.node),f=d?1e3-function(t){return hs.get(t.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const t of c.deleteIndexSet){const n=u.get(t);void 0!==n&&(f<=0&&n.tryDestroy()?ss(e.node,n):(Zo(n),n.unmount(),ys(e,n),f-=1),d||u.delete(t))}d&&(fs.delete(e.node),u=void 0)}let h=e.node;const p=E(r.path+"."+o),m=n.stateElement.loopContextStack,g=Fo(c);let y=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&h.isConnected&&(y=document.createDocumentFragment(),Jt(y,n.rootNode));const b=t(),w=e.uuid??"",v=hs.get(e.node);for(const t of c.newIndexes){let o;if(c.addIndexSet.has(t)){const s=be(p,t);m.createLoopContext(s,s=>{if(o=void 0!==v?v.pop():void 0,void 0===o&&(o=ds(e)),null!==y)b&&y.appendChild(document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`)),o.appendTo(y),b&&y.appendChild(document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`));else{if(h.nextSibling!==o.firstNode){if(b){const e=document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`);h.parentNode.insertBefore(e,h.nextSibling),h=e}o.mountAfter(h)}if(b){const e=document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`),n=o.lastNode??h;n.parentNode.insertBefore(e,n.nextSibling)}}Qo(o,s,n)}),void 0===o&&z(`Content not found for ListIndex: ${t.index} at path "${r.path}"`)}else{if(o=void 0!==u?u.get(t)??null:null,c.changeIndexSet.has(t)){const t=Po(o);for(const e of t)Ls(e,n)}null===o&&z(`Content not found for ListIndex: ${t.index} at path "${r.path}"`);const e=!o.mounted;if(null!==g&&g.has(t)&&bs(h,o.firstNode)||h.nextSibling===o.firstNode||o.mountAfter(h),e){const e=o,s=be(p,t);m.createLoopContext(s,t=>{Qo(e,t,n)})}}h=o.lastNode||h,void 0===u&&(u=new WeakMap,fs.set(e.node,u)),u.set(t,o)}us.set(e.node,h),null!==y&&(e.node.parentNode.insertBefore(y,e.node.nextSibling),Jt(y,null))},if:ws,else:ws,elseif:ws,radio:function(t,e,n){const o=t.node,s=Io(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Io(o.value,t.inFilters),r=Array.isArray(n)?n:xo;o.checked=r.includes(s)}},Ms=new WeakMap,Ts=new WeakMap,Os=new WeakMap;function Rs(t){return t.propSegments.length>1&&(e=t.replaceNode,n=t.propSegments[0],!0===So.get(e)?.has(n));var e,n}function Ds(t,e){const n=Io(Ps(e.state,t),t.outFilters);if(!0===Ts.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=Ms.get(t);if(void 0===o){if(Ms.has(t))return Rs(t)?(o=_s,Ms.set(t,o)):o=xs,void o(t,e,n);if(o=Es[t.bindingType],void 0===o){const e=t.propSegments[0];if(o=Cs[e],Ms.set(t,o),void 0===o){O(t.replaceNode)?Rs(t)?(o=_s,Ms.set(t,o)):o=xs:(o=xs,Ms.set(t,o))}}if(o===xs){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void Ts.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function Ls(t,e){if(e.appliedBindingSet.has(t))return;if(e.appliedBindingSet.add(t),!1!==e.stateElement.hasUpdatedCallback){const n=re(t);if(e.updatedAbsAddressSetByStateElement.has(e.stateElement)){e.updatedAbsAddressSetByStateElement.get(e.stateElement).add(n)}else e.updatedAbsAddressSetByStateElement.set(e.stateElement,new Set([n]))}const n=No(t);if(null!==n&&!n.shouldApplyState(t))return;if("event"===t.bindingType)return;if(!0!==Os.get(t)){const e=O(t.replaceNode);if(e&&void 0===R()?.get(e))return void function(t,e){if(As.has(t))return;As.add(t);const n=()=>{As.delete(t);const e=No(t);(null===e||e.shouldApplyState(t))&&Ws([t])},o=n=>{As.delete(t),ks(e,n)},s=No(t);if(null!==s){const r=s.deferUntilDefined(t.replaceNode,e,n,o);return void(s.addTeardown(t,()=>{As.delete(t),r()})||(As.delete(t),r()))}const r=R();if(null===r)return As.delete(t),void ks(e,new Error("CustomElementRegistry is unavailable."));Xn(r).wait(e,()=>{t.replaceNode.isConnected?n():As.delete(t)},o)}(t,e);Os.set(t,!0)}if(!0===e.sameRootVerified&&t.stateName===e.stateName)return void Ds(t,e);let o=t.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=Xt(o),null===o&&z("Root node for fragment not found for binding.")),t.stateName!==e.stateName||o!==e.rootNode){const n=xr(o,t.stateName);null===n&&z(`State element with name "${t.stateName}" not found for binding.`),n.createState("readonly",s=>{const r={stateName:t.stateName,rootNode:o,stateElement:n,state:s,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};Ds(t,r)})}else Ds(t,e)}function Ws(t,e){let n=0;const o=new Set,s=new Map,r=new Map,i=[];for(;n<t.length;){let a=t[n];const l=a.stateName;if(!1===a.replaceNode.isConnected){n++;continue}let c=a.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=Xt(c),null===c&&z("Root node for fragment not found for binding."));const d=xr(c,l);null===d&&z(`State element with name "${l}" not found for binding.`),d.createState("readonly",u=>{const f={rootNode:c,stateName:l,stateElement:d,state:u,appliedBindingSet:o,newListValueByAbsAddress:s,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:i,sameRootVerified:!0,propagationContextByBinding:e};for(;;){Ls(a,f),n++;const e=t[n];if(!e)break;const o=e.replaceNode.getRootNode();if(e.stateName!==l||o!==f.rootNode)break;a=e}})}for(const{binding:t,value:n}of i)xs(t,{propagationContextByBinding:e},n);for(const[t,e]of s.entries())Tt(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[jt](Array.from(e))})}function Bs(t,e){const[n,o,s]=$t(t),r=vo(t);for(const t of n)Ct(t,e);Ws(r.initialize(o)),function(t,e,n){for(const o of t)n.deferUntilDefined(o.node,o.tagName,()=>{const t=Pt(o);0!==t.length&&(Ct(o.node,e),Ws(n.initialize(t)))},t=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,t)})}(s,e,r)}const js=/\{\{\s*(.+?)\s*\}\}/g,Fs=new Set(["SCRIPT","STYLE"]);function zs(t){!function(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=[];for(;e.nextNode();)n.push(e.currentNode);for(const t of n)t.parentElement&&Fs.has(t.parentElement.tagName)||qs(t)}(t);const e=Array.from(t.querySelectorAll("template"));for(const t of e)if("http://www.w3.org/2000/svg"===t.namespaceURI){const e=document.createElement("template"),n=Array.from(t.childNodes);for(let t=0;t<n.length;t++){const o=n[t];e.content.appendChild(o)}for(const n of t.attributes)e.setAttribute(n.name,n.value);t.replaceWith(e),zs(e.content)}else zs(t.content)}function qs(t){const e=t.data;if(js.lastIndex=0,!js.test(e))return;js.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=js.exec(e));){o.index>s&&n.appendChild(document.createTextNode(e.slice(s,o.index)));const t=o[1];n.appendChild(document.createComment(`@@: ${t}`)),s=o.index+o[0].length}s<e.length&&n.appendChild(document.createTextNode(e.slice(s))),t.parentNode.replaceChild(n,t)}let Us;function Vs(){if(Us)return Us;const t=[],e=nt("not",t)(tt);return Us={filterName:"not",args:t,filterFn:e},Us}const Hs=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Gs(t,e){const s=e+n+o,r=t.indexOf("|"),i=t.indexOf("@");let a,l;if(-1!==r?(a=t.slice(0,r).trim(),l=t.slice(r)):-1!==i?(a=t.slice(0,i).trim(),l=t.slice(i)):(a=t.trim(),l=""),"."===a)a=s;else{if(!a.startsWith("."))return t;a=s+n+a.slice(1)}return l.length>0?a+l:a}function Ks(t,e){const n=Hs.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+Gs(s,e)+r}function Js(t,e){const n=t.split(";");let o=!1;const s=n.map(t=>{const n=t.trim();if(0===n.length)return t;const s=n.indexOf(":");if(-1===s)return t;const r=n.slice(0,s).trim(),i=n.slice(s+1).trim(),a=Gs(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function Xs(t,e){return Js(t,e)}function Ys(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const t=s.currentNode;if(t.nodeType===Node.COMMENT_NODE){const e=t;e.data=Ks(e.data,n);continue}const e=t;if(e instanceof HTMLTemplateElement)continue;const r=e.getAttribute(o);if(null!==r){const t=Js(r,n);t!==r&&e.setAttribute(o,t)}}}function Qs(t){let e=t;const n=[];for(;null!==e.parentNode;){const t=Array.from(e.parentNode.childNodes).indexOf(e);n.unshift(t),e=e.parentNode}return n}function Zs(t){const e=[],n=St(t);for(const t of n){const n=bt(t);let o=t;if(t.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==t.parentNode){const e=document.createTextNode("");t.parentNode.replaceChild(e,t),o=e}e.push({nodePath:Qs(o),parseBindTextResults:n})}return e}function tr(t){const e=Array.from(t.childNodes);for(const n of e)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&t.removeChild(n)}}const er=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),nr=Vs();function or(t,e){const n=e.outFilters;return{...e,outFilters:[...n,nr],bindingType:t}}function sr(t,e,n,o){tr(e),"string"==typeof o&&Ys(e,o),rr(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:Zs(e)}}function rr(t,n,o){const s=e.commentElsePrefix,r=vt(n),i=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 a=null;const l=[],c=[];for(;i.nextNode();){const t=i.currentNode;c.push(t)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=Xs(r,o));let i=dt(r)[0];const c=er.get(i.bindingType);if(void 0===c)continue;const d=i.bindingType,u=n.content,f=Co();let h=null;const p="for"===d?i.statePathName:o;if("else"===d){null===a&&z("'else' binding found without preceding 'if' or 'elseif' binding."),i=or("else",a.parseBindTextResult),h=sr(t,u,i,p),gt(f,t,h);const e=l.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:Qs(o),parseBindTextResults:bt(o)})):n.replaceWith(o)}else if("elseif"===d){null===a&&z("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=sr(t,u,i,p),gt(f,t,h);const e=document.createComment(`@@${c}:${f}`),o=Co(),r={fragment:document.createDocumentFragment(),parseBindTextResult:or("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:Qs(e),parseBindTextResults:bt(e)}),gt(o,t,r);const d=l.at(-1);l.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(n.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:Qs(m),parseBindTextResults:bt(m)})):n.replaceWith(m)}else{h=sr(t,u,i,p),gt(f,t,h);const e=document.createComment(`@@${c}:${f}`);n.replaceWith(e)}"if"===d?(l.length=0,a=h):"elseif"===d?a=h:"else"===d&&(a=null,l.length=0)}}async function ir(t){const n=t.querySelectorAll(e.tagNames.state),o=[];await customElements.whenDefined(e.tagNames.state);for(const t of n){if(wt(t))continue;const e=t;o.push(e.initializePromise)}await Promise.all(o)}async function ar(t){if(t===document)await ir(document),zs(document),rr(document,document),Bs(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await P(n.host),await ir(n),zs(n),rr(n,n),Bs(n,null)}}const lr="1.27.0",cr="undefined"==typeof HTMLElement?class{}:HTMLElement,dr=/^@@wcs-(?:for|if|elseif|else):[^-]/,ur=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,fr=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,hr=/^@@wcs-text-start:(.+)$/;function pr(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class mr extends cr{_stateData=null;_templates=null;_hydrateProps=null;get name(){return this.getAttribute("name")||"default"}get version(){return this.getAttribute("version")||""}get stateData(){return null===this._stateData&&(this._stateData=this._loadStateData()),this._stateData}get templates(){return null===this._templates&&(this._templates=this._loadTemplates()),this._templates}get hydrateProps(){return null===this._hydrateProps&&(this._hydrateProps=this._loadHydrateProps()),this._hydrateProps}getTemplate(t){return this.templates.get(t)??null}verifyVersion(){const t=this.version;if(!t)return!0;const e=t.split("."),n=lr.split(".");return e[0]===n[0]&&e[1]===n[1]}setStateData(t){this._stateData=t}setHydrateProps(t){this._hydrateProps=t}_loadStateData(){const t=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}_loadTemplates(){const t=new Map,e=this.querySelectorAll("template[id]");for(const n of e){const e=n.getAttribute("id");e&&t.set(e,n)}return t}_loadHydrateProps(){const t=this.querySelector("script[data-wcs-ssr-props]");if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}static findByName(t,n){const o=e.tagNames.ssr,s=t instanceof Element?t:t instanceof Document?t.documentElement:null;if(!s)return null;return s.querySelector(`${o}[name="${n}"]`)}static extractStateData(t){const e=t.__state;if(!e||"object"!=typeof e)return{};const n={};for(const[t,o]of Object.entries(e))t.startsWith("$")||"function"==typeof o||(n[t]=o);return n}static buildContent(t,n){const o=document.createElement("script");o.setAttribute("type","application/json"),o.textContent=pr(JSON.stringify(n)),t.appendChild(o);const s=Array.from(mt.keys());for(const n of s){const o=yt(n);if(!o)continue;const s=document.createElement("template");s.setAttribute("id",n);const r=o.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(e.bindAttributeName,i);const a=o.fragment.cloneNode(!0);s.content.appendChild(a),t.appendChild(s)}const r=Array.from(Ss);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=Ns(n);if(0===o.length)continue;const s=`wcs-ssr-${t}`;n.setAttribute("data-wcs-ssr-id",s);const i={};for(const t of o)i[t.propName]=t.value;e[s]=i}if(Object.keys(e).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=pr(JSON.stringify(e)),t.appendChild(n)}}Ss.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(ur.test(t.data)||fr.test(t.data))&&n.push(t)}for(const t of n)t.remove()}static removeStructuralComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;dr.test(t.data)&&n.push(t)}for(const t of n)t.remove()}static restoreTextBindings(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode,o=hr.exec(t.data);o&&n.push({comment:t,path:o[1]})}for(const{comment:t,path:e}of n){const n=document.createComment(`@@: ${e}`);t.parentNode.insertBefore(n,t);let o=t.nextSibling;t.remove();const s=`@@wcs-text-end:${e}`;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=t}}}static cleanupDom(t){const n=document.body,o=t.querySelectorAll(e.tagNames.ssr),s=new Map;for(const t of o){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&s.set(e,t)}}const r=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const t=r.currentNode;ur.test(t.data)&&i.push(t)}for(const t of i){const e=ur.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let o=t.nextSibling;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=t}t.remove()}mr.restoreTextBindings(n);const a=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(dr.test(t.data)){const e=t.data.split(":")[1];l.push({comment:t,uuid:e})}}for(const{comment:t,uuid:n}of l){const o=s.get(n);if(o){const n=document.createElement("template"),s=o.getAttribute(e.bindAttributeName);s&&n.setAttribute(e.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)n.content.appendChild(r);else for(const t of Array.from(o.childNodes))n.content.appendChild(document.importNode(t,!0));t.parentNode.replaceChild(n,t)}}const c=t.querySelectorAll("[data-wcs-ssr-id]");for(const t of c)t.removeAttribute("data-wcs-ssr-id");for(const t of o)t.remove()}}const gr=new Set(["for","if","elseif","else"]);function yr(t){const e=new wo;if(0===t.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:e};const n=t[0].parentNode,o=t[t.length-1].nextSibling,s=document.createElement("div");for(const e of t)s.appendChild(e);const[r,i]=$t(s),a=e.initialize(i,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:a,subscriberNodes:r,bindingSession:e}}function br(t,n,o){const s={for:e.commentForPrefix,if:e.commentIfPrefix,elseif:e.commentElseIfPrefix,else:e.commentElsePrefix}[n];if(!s)return null;const r=`@@${s}:${o}`,i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const t=i.currentNode;if(t.data===r)return t}return null}function wr(t,n){const o=t;let s=null;for(const[t,r]of n.templates){let n=dt(r.getAttribute(e.bindAttributeName)||"")[0];const i=n.bindingType;"else"===i&&s?n={...s,outFilters:[...s.outFilters,Vs()],bindingType:"else"}:"elseif"===i&&s&&(n={...n,stateName:s.stateName}),"if"===i||"elseif"===i?s=n:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?n.statePathName:void 0;tr(a),"string"==typeof l&&Ys(a,l),rr(o,a,l);gt(t,o,{fragment:a,parseBindTextResult:n,nodeInfos:Zs(a)})}}async function vr(t){await ir(t);const n=t.querySelectorAll(e.tagNames.ssr);for(const e of n){const n=e;if(!n.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${n.version}", client="${lr}". Falling back to full render.`),mr.cleanupDom(t),!1}for(const e of n)wr(t,e);const s=function(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o){const n=ur.exec(t.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let i,a,l=null;"for"===o?(i=r[0],a=r[1],l=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const c=[];let d=t.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)c.push(d),d=d.nextSibling;e.push({type:o,uuid:i,path:a,index:l,nodes:c})}return e}(document.body);!function(t,e){const n=new Map;for(const s of e){if(0===s.nodes.length)continue;const e=ls(s.nodes),{bindingInfos:r,subscriberNodes:i,bindingSession:l}=yr(s.nodes);Go(e,l);for(const t of i)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");Uo(e,r),Xo(e,i);const c=[];for(const t of r)t.statePathName in a&&c.push(t);if(Ao(e,c),"for"===s.type&&null!==s.index){const i=br(t,"for",s.uuid);if(i){const t=To(null,s.index);ms(i,t,e),gs(i,s.nodes[s.nodes.length-1]),ns(i,e),Yo(e,be(E(s.path+"."+o),t)),l.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let a=n.get(s.uuid);a||(a=[],n.set(s.uuid,a)),a.push(t)}}else{const n=br(t,s.type,s.uuid);n&&(ns(n,e),l.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[e,o]of n){const n=br(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=yt(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=xr(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&Do(e,o)})}}(document.body,s),mr.removeBlockBoundaryComments(document.body);const r=[];for(const t of n)t.parentNode&&(r.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());mr.restoreTextBindings(document.body);const[i,l]=$t(document.body);for(const t of i)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(Ct(t,null),e.setAttribute("data-wcs-completed",""))}else Ct(t,null);const c=[],d=[],u=vo(document.body).initialize(l);for(const t of u)if("event"!==t.bindingType)if(gr.has(t.bindingType))d.push(t);else{if(t.statePathName.includes(o))continue;c.push(t)}for(const t of d)if("for"===t.bindingType){const e=re(t),n=xr(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&Tt(e,o)})}Ws(c);for(const{el:t,parent:e,next:n}of r)e.insertBefore(t,n);const f=t.querySelectorAll(e.tagNames.ssr);for(const e of f){const n=e.hydrateProps;for(const[e,o]of Object.entries(n)){const n=t.querySelector(`[data-wcs-ssr-id="${e}"]`);if(n)for(const[t,e]of Object.entries(o))n[t]=e}}const h=t.querySelectorAll("[data-wcs-completed]");for(const t of h)t.removeAttribute("data-wcs-completed");return!0}const Nr=new WeakMap,Sr=new WeakMap,Ir=new Set;function xr(t,e){let n=Nr.get(t);return n&&n.get(e)||null}function $r(t){return Sr.get(t)??Promise.resolve()}function _r(e,n,o){let s=Nr.get(e);if(null===o){if(!s)return;const t=s.get(n);s.delete(n),0===s.size&&Nr.delete(e),void 0!==t&&(Ir.delete(t),null!==ae&&ae({type:"state:element-unregistered",name:n,rootNode:e,element:t}))}else{if(!s){s=new Map,Nr.set(e,s);const n=!t()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise((t,o)=>{queueMicrotask(async()=>{try{if(n){await vr(e)||await ar(e)}else await ar(e);t()}catch(t){o(t)}})});Sr.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise((t,n)=>{queueMicrotask(async()=>{try{await ar(e),t()}catch(t){n(t)}})});Sr.set(e,t)}}s.has(n)&&z(`State element with name "${n}" is already registered.`),s.set(n,o),Ir.add(o),null!==ae&&ae({type:"state:element-registered",name:n,rootNode:e,element:o})}}let Pr=0,Ar=0;const kr=[];function Cr(t,e=0){const n=kr.findIndex(t=>t.priority>e),o={listener:t,priority:e};-1===n?kr.push(o):kr.splice(n,0,o)}const Er=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(t,e=null){Pr>Ar&&(Ar=Pr);const n=0===this._queueUpdateRecords.length;this._queueUpdateRecords.push({absoluteAddress:t,context:e}),n&&queueMicrotask(()=>{const t=this._queueUpdateRecords;this._queueUpdateRecords=[],this._applyChange(t)})}testApplyChange(t,e){this._applyChange(t.map((t,n)=>({absoluteAddress:t,context:e?.[n]??null})))}_applyChange(t){const e=new Map;for(const n of t){const t=e.get(n.absoluteAddress);null!==ae&&null!=t&&null!==n.context&&t.transactionId!==n.context.transactionId&&ae({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:t.transactionId,winnerTransactionId:n.context.transactionId}),e.set(n.absoluteAddress,n.context)}const n=[],o=new Map;for(const[t,s]of e){if(null!==s&&s.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,stateName:t.absolutePathInfo.stateName,transactionId:s.transactionId,hop:s.hop,maxHops:32}),null!==ae&&ae({type:"propagation:hop-limit",absoluteAddress:t,transactionId:s.transactionId,hop:s.hop});continue}const e=pe(t);if(void 0!==e)if(e instanceof Set)for(const t of e)!1!==t.replaceNode.isConnected&&(n.push(t),null!==s&&o.set(t,s));else!1!==e.replaceNode.isConnected&&(n.push(e),null!==s&&o.set(e,s))}o.size>0?Ws(n,o):Ws(n),function(t){for(const e of kr.slice())e.listener(t)}(new Set(e.keys()))}};function Mr(){return Er}const Tr="__WCSTACK_DEVTOOLS_HOOK__";function Or(){const t=globalThis,e=t[Tr];if(void 0!==e)return 1!==e.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${e.version}, expected 1. Keeping the existing registry (first-wins).`),e;const n=function(){const t=new Map,e=new Set,n=t=>{if(0===e.size)return void t._setSink(null);const n=t.id;t._setSink(t=>{for(const o of e)o.onEvent?.(n,t)})};return{version:1,sources:t,register(o){if(!t.has(o.id)){t.set(o.id,o),n(o);for(const t of e)t.onSourceRegistered?.(o)}},unregister(n){const o=t.get(n);if(void 0!==o){o._setSink(null),t.delete(n);for(const t of e)t.onSourceUnregistered?.(n)}},addListener(o){e.add(o);for(const e of t.values())n(e),o.onSourceRegistered?.(e);return()=>{if(e.delete(o))for(const e of t.values())n(e)}}}}();return t[Tr]=n,n}const Rr=t=>{null!==ae&&ae({type:"state:update-batch",addresses:t})};function Dr(t){const e=null!==ae;!function(t){ae=t}(t);const n=null!==t;n&&!e?Cr(Rr,0):!n&&e&&function(t){const e=kr.findIndex(e=>e.listener===t);-1!==e&&kr.splice(e,1)}(Rr)}function Lr(t){return{name:t.name,rootNode:t.rootNode,element:t,paths:{list:t.listPaths,element:t.elementPaths,getter:t.getterPaths,setter:t.setterPaths},commandTokenNames:t.commandTokenNames,eventTokenNames:t.eventTokenNames,staticDependency:t.staticDependency,dynamicDependency:t.dynamicDependency}}function Wr(t,e){return xr(e,t)??z(`devtools: state element not found: name="${t}"`)}let Br=null;function jr(){if(t())return;if(null!==Br)return;const e={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:lr,getStateElements(){const t=[];for(const e of Ir)t.push(Lr(e));return t},keys(t,e){const n=Wr(t,e),o=[];return n.createState("readonly",t=>{for(const e of Object.keys(t))if(!e.includes("*")&&!e.startsWith("$")){try{if("function"==typeof t[e])continue}catch{}o.push(e)}}),o},read(t,e,n,o){let s;return Wr(t,e).createState("readonly",t=>{s=t.$resolve(n,o??[])}),s},write(t,e,n,o,s){Wr(t,e).createState("writable",t=>{void 0!==s&&s.length>0?t.$resolve(n,s,o):t[n]=o})},_setSink:Dr};Br=e,Or().register(e)}const Fr="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";async function zr(t,e){let n=null;const o=`\n//# sourceURL=${e}\n`;let s=!1;const r=t=>{t.effectiveDirective.startsWith("script-src")&&(s=!0)};document.addEventListener("securitypolicyviolation",r);try{if("function"==typeof URL.createObjectURL){const e=new Blob([t.text+o],{type:"application/javascript"}),s=URL.createObjectURL(e);try{n=await import(s)}finally{URL.revokeObjectURL(s)}}else{const e=btoa(String.fromCodePoint(...(new TextEncoder).encode(t.text+o)));n=await import(`data:application/javascript;base64,${e}`)}}catch(t){throw new Error(function(t,e,n){const o=e?.message??String(e);return n?`The inline <script> of state "${t}" was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL, so script-src must allow blob:. Prefer moving the state into an external file and loading it with src="./state.js", which requires no extra CSP directive. See ${Fr}`:`Failed to evaluate the inline <script> of state "${t}": ${o}. If this page sets a Content-Security-Policy, see ${Fr}`}(e,t,s),{cause:t})}finally{document.removeEventListener("securitypolicyviolation",r)}return n&&"object"==typeof n.default?n.default:{}}async function qr(t){try{return(await import(t)).default||{}}catch(t){z(`Failed to load script file: ${t}`)}}class Ur{_loopContextStack=Array(s).fill(void 0);_length=0;_getBaseDepth;constructor(t){this._getBaseDepth=t}createLoopContext(t,e){null===t.listIndex&&z("Cannot create loop context for a state address that does not have a list index.");const n=t;this._length>=s&&z("Exceeded maximum loop context stack depth of 128. Possible infinite loop.");const o=this._loopContextStack[this._length-1];if(void 0!==o){o.pathInfo.wildcardCount+1!==n.pathInfo.wildcardCount&&z("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const t=n.pathInfo.wildcardPathInfos[n.pathInfo.wildcardPathInfos.length-2];o.pathInfo!==t&&z("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else if(n.listIndex.length!==n.pathInfo.wildcardCount){const t=this._getBaseDepth();n.listIndex.length!==n.pathInfo.wildcardCount+t&&z(`Cannot push loop context when there is no active loop context: the list index chain (length ${n.listIndex.length}) does not cover the wildcard path (wildcard count ${n.pathInfo.wildcardCount}, base depth ${t}).`)}let r;this._loopContextStack[this._length]=n,this._length++;try{r=e(n)}finally{r instanceof Promise?r.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return r}}const Vr=new WeakMap;function Hr(t,e){let n=Vr.get(t);void 0===n&&(n=new Map,Vr.set(t,n));let o=n.get(e);return void 0===o&&(o=new Le(e,t.name),n.set(e,o)),o}const Gr=new WeakMap;function Kr(t){const e=Gr.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return Hr(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:Hr(t,n)}},set(){z("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){z("$command namespace is read-only; deleting from it is not allowed.")}});return Gr.set(t,n),n}const Jr=Symbol("wcs-stream-last-notified-uncertain"),Xr=new WeakMap;function Yr(t,e){const n=Xr.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function Qr(t,e){const n=Xr.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:Jr,error:Object.is(o.error,null)?null:Jr})}const Zr=new Set;function ti(t){Zr.delete(t)}const ei=new WeakMap;function ni(t){return ei.get(t)??new Map}function oi(t){ti(t);const e=ei.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,Qr(t,n.name)}const si=(t,e)=>e,ri=new Set;function ii(t,e){const s=e[b];if(void 0===s)return void Yr(t,ri);"object"==typeof s&&null!==s||z(`${b} must be an object mapping stream names to stream definitions.`);const r=new Map;for(const[i,a]of Object.entries(s)){0===i.length&&z(`${b} entry name must be a non-empty string.`),i.includes(n)&&z(`${b} entry "${i}" must be a flat property name ("${n}" is not allowed).`),i.includes(o)&&z(`${b} entry "${i}" must be a flat property name ("${o}" is not allowed).`),i.startsWith("$")&&z(`${b} entry "${i}" must not start with "$" (reserved namespace).`),i in Object.prototype&&z(`${b} entry "${i}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),t.getterPaths.has(i)&&z(`${b} entry "${i}" conflicts with a getter declared on the state.`),t.setterPaths.has(i)&&z(`${b} entry "${i}" conflicts with a setter declared on the state.`),"object"==typeof a&&null!==a||z(`${b} entry "${i}" must be an object ({ args?, source, fold?, initial? }).`);const s=a;"function"!=typeof s.source&&z(`${b} entry "${i}" source must be a function.`);const l=void 0!==s.fold;l&&"function"!=typeof s.fold&&z(`${b} entry "${i}" fold must be a function.`),l&&!("initial"in s)&&z(`${b} entry "${i}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==s.args&&"function"!=typeof s.args&&z(`${b} entry "${i}" args must be a function.`);const c={name:i,definition:{args:s.args??null,source:s.source,fold:s.fold??si,initial:s.initial},status:"idle",error:null,controller:null,depAddresses:new Set};i in e||(e[i]=c.definition.initial),r.set(i,c)}!function(t,e){ei.set(t,e)}(t,r),Yr(t,new Set(r.keys()))}const ai=new WeakMap,li=new WeakMap;function ci(t,e,n){return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;const s=ni(t).get(o);return void 0!==s?n(s):void 0},has:(e,n)=>"string"==typeof n&&ni(t).has(n),ownKeys:()=>Array.from(ni(t).keys()),getOwnPropertyDescriptor(e,o){if("string"!=typeof o)return;const s=ni(t).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){z(`${e} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){z(`${e} namespace is read-only; deleting from it is not allowed.`)}})}function di(t){const e=ai.get(t);if(void 0!==e)return e;const n=ci(t,N,t=>t.status);return ai.set(t,n),n}function ui(t){const e=li.get(t);if(void 0!==e)return e;const n=ci(t,S,t=>t.error);return li.set(t,n),n}function fi(t){ai.delete(t),li.delete(t)}let hi=null;async function pi(t,e,n,o){let s=null,r=null;const i=()=>{if(s&&s!==r){r=s;try{s.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",i,{once:!0});try{const r=await t(e,n);if(s=function(t,e){if("function"==typeof t?.getReader)return async function*(t,e){const n=t.getReader(),o=()=>{n.cancel().catch(()=>{})};e.addEventListener("abort",o,{once:!0});try{for(;;){const{done:t,value:e}=await n.read();if(t)return;yield e}}finally{e.removeEventListener("abort",o),n.releaseLock()}}(t,e);if("function"==typeof t?.[Symbol.asyncIterator])return t;throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).")}(r,n)[Symbol.asyncIterator](),n.aborted)return void i();for(;;){const t=await s.next();if(t.done)break;if(n.aborted)return;o.fold(t.value)}if(n.aborted)return;o.done()}catch(t){if(n.aborted)return;o.fail(t)}finally{n.removeEventListener("abort",i)}}function mi(t){const e=ni(t);if(0!==e.size){!function(t){Zr.add(t)}(t);for(const n of e.values())gi(t,n)}}function gi(t,e){e.controller?.abort();const o=new AbortController;e.controller=o;const s=function(t,e){const o=e.definition.args;if(null===o)return void e.depAddresses.clear();const s=hi,r=new Set;let i;hi=r;try{t.createState("readonly",t=>{i=o(t)})}finally{hi=s}i instanceof Promise&&z(`${b} entry "${e.name}" args must be synchronous (it returned a Promise).`);const a=`${N}${n}${e.name}`,l=`${S}${n}${e.name}`;for(const n of r){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==t||o.path!==e.name&&o.path!==a&&o.path!==l||z(`${b} entry "${e.name}" args must not read the stream itself ("${o.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),o.wildcardCount>0&&z(`${b} entry "${e.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return e.depAddresses=r,i}(t,e);t.createState("writable",t=>{t[e.name]=e.definition.initial}),yi(t,e,"active",null);const r=e.definition,i={fold(n){t.createState("writable",t=>{t[e.name]=r.fold(t[e.name],n)})},done(){yi(t,e,"done",null)},fail(n){yi(t,e,"error",n),o.abort()}};pi(r.source,s,o.signal,i)}function yi(t,e,o,s){e.status=o,e.error=s;const r=function(t,e){return Xr.get(t)?.get(e)??{status:"idle",error:null}}(t,e.name),i=r.status!==o,a=!Object.is(r.error,s);(i||a)&&(!function(t,e,n,o){let s=Xr.get(t);void 0===s&&(s=new Map,Xr.set(t,s)),s.set(e,{status:n,error:o})}(t,e.name,o,s),t.createState("writable",t=>{i&&t.$postUpdate(`${N}${n}${e.name}`),a&&t.$postUpdate(`${S}${n}${e.name}`)}))}Cr(function(t){const e=Zr;if(0===e.size)return;const n=[];for(const o of e)for(const e of ni(o).values())for(const s of e.depAddresses)if(t.has(s)){n.push({stateElement:o,entry:e});break}for(const{stateElement:t,entry:o}of n)if(e.has(t)&&ni(t).get(o.name)===o)try{gi(t,o)}catch(n){o.controller?.abort(),e.has(t)&&ni(t).get(o.name)===o&&yi(t,o,"error",n)}},20);const bi=new WeakMap,wi=new Set,vi=new Map;function Ni(t){return bi.get(t)??vi}function Si(){return wi}function Ii(t,e){const n=e[w];if(void 0===n)return null;"object"==typeof n&&null!==n||z(`${w} must be an object mapping state paths to handler functions.`);const o=new Map,s=new Set;let r=0;for(const[e,i]of Object.entries(n)){"function"!=typeof i&&z(`${w} entry "${e}" must be a function.`),0===e.length&&z(`${w} entry name must be a non-empty state path.`),e.startsWith("$")&&z(`${w} entry "${e}" must not start with "$" (reserved namespace).`),e.includes("@")&&z(`${w} entry "${e}" must not target another state ("@" is not allowed); watch only paths of its own state.`),e in Object.prototype&&z(`${w} entry "${e}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const n=E(e);for(const t of n.segments)0===t.length&&z(`${w} entry "${e}" has an empty path segment.`);n.wildcardCount>128&&z(`${w} entry "${e}" exceeds the maximum wildcard depth (128).`),o.set(e,{path:e,pathInfo:n,handler:i,order:r++}),s.add(e),t.setPathInfo(e,"prop")}return function(t,e){bi.set(t,e)}(t,o),s.size>0?s:null}const xi=new WeakMap;function $i(t,e,n){let o=xi.get(t);void 0===o&&(o=new Map,xi.set(t,o)),o.set(e,n)}const _i=new Map;function Pi(t){0!==Ni(t).size&&(function(t){wi.add(t)}(t),function(t){const e=[];for(const n of Ni(t).values())ki(t,n)&&e.push(n);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{$i(t,Ai(t,o),n[o.path])}catch(e){Ei(t,o.path,"prime",e)}})}(t))}function Ai(t,e){return Gt(zt(t,e.pathInfo),null)}function ki(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const Ci={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Ei(t,e,n,o){console.error(`[@wcstack/state] $watch ${Ci[n]} "${e}" threw.`,o),null!==ae&&ae({type:"state:watch-error",phase:n,stateName:t.name,path:e,error:o})}function Mi(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function Ti(t){const{stateElement:e,entry:n,absAddress:o,indexes:s}=t,r=ki(e,n);try{e.createState("writable",t=>{let i;try{i=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,s)}catch(t){return void Ei(e,n.path,"evaluate",t)}const a=r?function(t,e){return xi.get(t)?.get(e)}(e,o):function(t){return _i.get(t)}(o);r&&$i(e,o,i),n.handler.call(t,i,a,...s)})}catch(t){Ei(e,n.path,"handler",t)}}function Oi(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function Ri(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function Di(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function Li(t){return t.startsWith("$")}function Wi(t){const e=[];let n=t;for(;n&&n!==Object.prototype;)e.push(n),n=Object.getPrototypeOf(n);const o={};for(let t=e.length-1;t>=0;t--)Object.assign(o,Object.getOwnPropertyDescriptors(e[t]));return o}function Bi(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||z(`${e} must be an array of strings.`);const o=[],s=new Set;for(const t of n)"string"==typeof t&&0!==t.length||z(`${e} entries must be non-empty strings.`),t.startsWith("$")&&z(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),s.has(t)&&z(`${e} entry "${t}" is duplicated.`),s.add(t),o.push(t);return o}function ji(t){const e=Bi(t,f)??[],n=Bi(t,h)??[],o=Wi(t),s=function(t){const e=t[b];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),r=[];for(const t of e){const e=o[t];if(void 0===e){if(s.has(t)){r.push(t);continue}z(`${f} entry "${t}" is not declared on the state.`)}"function"==typeof e.value&&z(`${f} entry "${t}" is a method. Declare it in ${h} instead.`)}for(const t of n){const e=o[t];void 0===e&&z(`${h} entry "${t}" is not declared on the state.`),"function"!=typeof e.value&&z(`${h} entry "${t}" is not a method. Declare it in ${f} instead.`)}return{bindables:e,commands:n,streamBackedBindables:r}}Cr(function(t){const e=Si();try{if(0===e.size)return;const n=function(){const t=Ar;return Ar=0,t}();if(n>32){const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; watch handlers for this batch were skipped.",{maxDepth:32,paths:e}),void(null!==ae&&ae({type:"state:watch-chain-limit",maxDepth:32,paths:e}))}const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const s=Ni(t).get(n.absolutePathInfo.pathInfo.path);if(void 0===s)continue;let r=[];if(s.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=te(n.listIndex,s.pathInfo.wildcardCount)}o.push({stateElement:t,entry:s,absAddress:n,indexes:r})}if(0===o.length)return;o.sort(Mi),function(t){Pr=t+1}(n);try{for(const t of o)e.has(t.stateElement)&&Ni(t.stateElement).get(t.entry.path)===t.entry&&Ti(t)}finally{Pr=0}}finally{_i.clear()}},10);const Fi=new Map;class zi{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice();let o=0,s=0,r=0,i="none";const a=[];for(let t=0;t<e.length;t++){const i=e[t];if("*"===i)n[t]="*",a.push(null),o++,r++;else{const e=Number(i);Number.isNaN(e)||(n[t]="*",a.push(e),s++,r++)}}const l=E(n.join("."));(o>0||s>0)&&(i=o===r?"context":s===r?"all":"partial"),this.path=t,this.segments=e,this.wildcardCount=r,this.wildcardType=i,this.wildcardIndexes=a,this.pathInfo=l}}function qi(t){let e;return Fi.get(t)??(Fi.set(t,e=new zi(t)),e)}const Ui=new WeakMap;function Vi(t,e){null===e?Ui.delete(t):Ui.set(t,e)}function Hi(t){const e=Ui.get(t);e&&(e.dirty=!0)}const Gi=[],Ki=[];let Ji=0;function Xi(t,e){Gi[Ji]=t,Ki[Ji]=e,Ji++}function Yi(){Ji--,Gi[Ji]=void 0,Ki[Ji]=void 0}function Qi(t,e){return!0!==t.hasMappedComponentState&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function Zi(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}function ta(t,e,n,s,r){const i=e.pathInfo.segments[0];if(i===m)return Zi(Kr(r),e.pathInfo.segments);if(i===N)return Zi(di(r),e.pathInfo.segments);if(i===S)return Zi(ui(r),e.pathInfo.segments);if(!(e.pathInfo.path in t)){const r=na(t,e.parentAddress??z(`address.parentAddress is undefined path: ${e.pathInfo.path}`),n,s);if(null==r)return;const i=e.pathInfo.segments[e.pathInfo.segments.length-1];if(i===o){const t=e.listIndex?.index??z(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(r,t)}return Reflect.get(r,i)}if(r.getterPaths.has(e.pathInfo.path)){s.pushAddress(e);try{return Reflect.get(t,e.pathInfo.path,n)}finally{s.popAddress()}}else{if(!0!==r.hasMappedComponentState)return Reflect.get(t,e.pathInfo.path);Xi(r,e);try{return Reflect.get(t,e.pathInfo.path)}finally{Yi()}}}function ea(t,e,n,o,s){const r=Gt(zt(s,e.pathInfo),e.listIndex),i=function(t){return Ui.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=ta(t,e,n,o,s);return Vi(r,{value:a,dirty:!1}),a}function na(t,e,n,o){!function(t,e){if(!t.untracking&&t.addressStackLength>0){const n=t.lastAddressStack,o=n?.pathInfo??null,s=t.stateElement;if(null!==o&&s.getterPaths.has(o.path)&&o.path!==e.pathInfo.path&&(s.addDynamicDependency(e.pathInfo.path,o.path),e.pathInfo.wildcardCount>0&&o.wildcardCount>0)){const t=Qt(e.pathInfo,o);if(t>0){let r=!1;const i=e.listIndex??null,a=n.listIndex??null;for(let n=0;n<t;n++)if((null!==i?Zt(i,n,e.pathInfo.wildcardCount):null)!==(null!==a?Zt(a,n,o.wildcardCount):null)){r=!0;break}if(r)for(let n=0;n<t;n++)s.addCrossRowListPath?.(e.pathInfo.wildcardParentPaths[n])}}}}(o,e),function(t,e){if(null===hi)return;const n=zt(t,e.pathInfo);hi.add(Gt(n,e.listIndex))}(o.stateElement,e);const s=o.stateElement;return Qi(s,e)?ea(t,e,n,o,s):ta(t,e,n,o,s)}function oa(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const o=n.pathInfo.indexByWildcardPath[e];return void 0===o||null===n.listIndex?null:Zt(n.listIndex,o,n.pathInfo.wildcardCount)}function sa(t,e,n){const o=t.bindableEventMap,s=o[e.path],r="string"==typeof s,i=r?s:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof i)return;const a=t.rootNode;a instanceof ShadowRoot&&a.host.dispatchEvent(new CustomEvent(i,{detail:r&&void 0!==n?n.value:void 0,bubbles:!0}))}function ra(t,e,n,o){"object"==typeof t&&null!==t||z(`${v} list "${e}": ${n} row at index ${o} must be a plain object (got ${null===t?"null":typeof t}).`);const s=Object.getPrototypeOf(t);s!==Object.prototype&&null!==s&&z(`${v} list "${e}": ${n} row at index ${o} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function ia(t,e,n,o,s){const r="function"==typeof e?e(t):t[e];return null==r&&z(`${v} list "${n}": ${o} row at index ${s} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(r)}).`),r}function aa(t,e,n,o){const s=new Array(t.length),r=new Set;for(let i=0;i<t.length;i++){const a=t[i];ra(a,n,o,i);const l=ia(a,e,n,o,i);r.has(l)&&z(`${v} list "${n}": duplicate key ${JSON.stringify(l)} in ${o} list.`),r.add(l),s[i]=l}return s}function la(t,e){const n=[];for(const o of Object.keys(e))Object.is(t[o],e[o])||n.push({field:o,value:e[o]});for(const o of Object.keys(t))Object.hasOwn(e,o)||null==t[o]||n.push({field:o,value:null});return n}function ca(t,e,n,s){if(e.pathInfo.path in t)return!0;const r=e.parentAddress;if(null===r)return!1;const i=na(t,r,n,s);if(null===i||"object"!=typeof i&&"function"!=typeof i)return!1;const a=e.pathInfo.lastSegment;if(a===o){const t=e.listIndex?.index;return"number"==typeof t&&t in i}return a in i}const da=new WeakMap;function ua(t,e){null===e?da.delete(t):da.set(t,e)}function fa(t,e,n){const o=E(t.wildcardParentPaths[e]),s=zt(t.stateElement,o),r=be(o,n),i=Mt(Gt(s,n)),a=t.stateProxy[Rt](r),l=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return[]}}(jo(Cn(t.stateElement,r.listIndex),i,a),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...l);else for(const n of l)fa(t,e+1,n)}const ha=[];function pa(t,e,n,o,s){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:s.newIndexes,movedRows:null}:0===s.addIndexSet.size&&0===s.changeIndexSet.size?0===s.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:ha,movedRows:null}:{fullRows:s.newIndexes,movedRows:null}:{fullRows:ha,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const ma=[];function ga(t,e,o){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return ma;let r=null;const i=e+n;for(const t of s){if(t!==e&&!t.startsWith(i))continue;const n=E(t);if(n.wildcardCount!==o.wildcardCount)return null;(r??=[]).push(n)}return r??ma}function ya(t,e,n){const s=e.pathInfo.path,r=t.staticMap.get(s);if(r)for(const i of r){const r=E(i);if(t.listPathSet.has(s)&&r.lastSegment===o){const o=t.stateProxy[Rt](e),a=Mt(Gt(zt(t.stateElement,e.pathInfo),e.listIndex)),l=pa(t,s,0,0,jo(Cn(t.stateElement,e.listIndex),a,o));for(const e of l.fullRows){const o=be(r,e);t.result.add(o),n.push(o)}if(null!==l.movedRows){const e=ga(t,i,r);if(null===e)for(const e of l.movedRows){const o=be(r,e);t.result.add(o),n.push(o)}else if(e.length>0)for(const o of l.movedRows)for(const s of e){const e=be(s,o);t.result.add(e),n.push(e)}}}else{const o=be(r,e.listIndex);t.result.add(o),n.push(o)}}const i=t.dynamicMap.get(s);if(i)for(const o of i){const s=E(o),r=[];if(s.wildcardCount>0){const n=Qt(e.pathInfo,s);if(s.wildcardCount-n>=1){let o;n>0?(null===e.listIndex&&z(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),o=Zt(e.listIndex,n-1,e.pathInfo.wildcardCount)):o=null;const i={stateName:t.stateName,stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};fa(i,n,o),r.push(...i.targetListIndexes)}else{null===e.listIndex&&z(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`);const t=Zt(e.listIndex,n-1,e.pathInfo.wildcardCount);r.push(t)}}else r.push(null);for(const e of r){const o=be(s,e);t.result.add(o),n.push(o)}}}function ba(t,e,n,o,s,r,i,a,l,c){const d=n.pathInfo.path;if(!o.has(d)&&!s.has(d))return l(n),[];const u=function(t,e,n,o){const s=new Map,r=new Map,i=[t];for(r.set(t,0);i.length>0;){const t=i.pop();if(s.has(t))continue;const o=e.get(t),a=n.get(t);let l;l=void 0===o?a??[]:void 0===a?o:o.concat(a),s.set(t,l);for(let t=0;t<l.length;t++){const e=l[t];r.set(e,(r.get(e)??0)+1),s.has(e)||i.push(e)}}const a=new Map,l=new Set,c=[];for(const[t,e]of r)0===e&&(a.set(t,0),l.add(t),c.push(t));for(let t=0;t<c.length;t++){const e=c[t],n=a.get(e)+1;n>o&&z(`Maximum dependency depth of ${o} exceeded. Possible circular dependency detected at path: ${e}`);const i=s.get(e);for(let t=0;t<i.length;t++){const e=i[t];n>(a.get(e)??-1)&&a.set(e,n);const o=r.get(e)-1;r.set(e,o),0===o&&(l.add(e),c.push(e))}}if(l.size!==s.size){let t=-1;for(const e of l){const n=a.get(e);n>t&&(t=n)}const e=t+1;for(const t of s.keys())l.has(t)||a.set(t,e)}return a}(d,o,s,1e3),f={ranks:u,stateName:t,stateElement:e,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:a,listExpansion:c?.listExpansion??"full",keyedMergePath:c?.keyedMergePath??null};return function(t,e,n){const o=[],s=t.ranks,r=(t,e)=>{let n=s.get(t.pathInfo.path)??e;n<e&&(n=e),(o[n]??=[]).push(t)};r(e,0);const i=[];for(let e=0;e<o.length;e++){const s=o[e];if(void 0!==s)for(let o=0;o<s.length;o++){const a=s[o];if(!t.visited.has(a)){t.visited.add(a),n(a),i.length=0,ya(t,a,i);for(let t=0;t<i.length;t++)r(i[t],e+1)}}}}(f,n,l),Array.from(f.result)}function wa(t,e,n,o,s){const r=t.watchPaths;null!=r&&s&&r.has(e)&&function(t,e){_i.has(t)||_i.set(t,e)}(n,o)}function va(t,e,n,o,s){const r=cn()??rn(-1),i=Mr();i.enqueueAbsoluteAddress(e,r),ba(o.stateName,o.stateElement,t,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=Gt(zt(o.stateElement,e.pathInfo),e.listIndex);Hi(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:"diff",keyedMergePath:s})}function Na(t,e,n,s,r,i,a){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,s);const a=na(t,n,r,i),l=e.pathInfo.segments[e.pathInfo.segments.length-1];if(l===o){const t=e.listIndex?.index??z(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.set(a,t,s)}return Reflect.set(a,l,s)}if(i.stateElement.setterPaths.has(e.pathInfo.path)){i.pushAddress(e),i.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,s,r)}finally{i.endUntrack(),i.popAddress()}}else{if(!0!==i.stateElement.hasMappedComponentState)return Reflect.set(t,e.pathInfo.path,s);Xi(i.stateElement,e);try{return Reflect.set(t,e.pathInfo.path,s)}finally{Yi()}}}finally{va(e,n,r,i,a)}}function Sa(t,e,n,o,s,r,i){let a=e.parentAddress??z(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return da.get(t)??null}(a);if(null===l){const e=na(t,a,s,r)??[],n=Ro(e)??[];l={value:[...e],listIndexes:[...n]},ua(a,l)}try{return Na(t,e,n,o,s,r,i)}finally{const n=l.value.indexOf(o),i=na(t,a,s,r)??[],c=Array.isArray(i)?Ro(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:To(a.listIndex,-1);c[d]=u;if(new Set(i).size===l.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ua(a,null)}}}function Ia(t,e,s,r,i){const a=i.stateElement.listKeys;if(null!=a&&Array.isArray(s)){const l=a.get(e.pathInfo.path);if(void 0!==l){const a=na(t,e,r,i),c=function(t,e,n,o){const s=aa(o,e,t,"new");if(!Array.isArray(n)||0===n.length||0===o.length)return null;const r=n,i=aa(r,e,t,"current"),a=new Map;for(let t=0;t<r.length;t++)a.set(i[t],r[t]);const l=new Array(o.length),c=[];for(let t=0;t<o.length;t++){const e=o[t],n=a.get(s[t]);void 0!==n&&n!==e?(l[t]=n,c.push({position:t,oldRow:n,newRow:e})):l[t]=e}return c.length>0?{list:l,matched:c}:null}(e.pathInfo.path,l,a,s);if(null!==c)return function(t,e,s,r,i,a){const l=e.pathInfo.path,c=Cn(a.stateElement,e.listIndex);null===Ro(r)&&jo(c,null,r);const d=jo(c,r,s.list),u=xa(t,e,s.list,i,a,l),f=E(l+n+o);for(const e of s.matched){const o=la(e.oldRow,e.newRow);if(0===o.length)continue;const s=d.newIndexes[e.position];for(const r of o)void 0!==s?Ia(t,be(E(f.path+n+r.field),s),r.value,i,a):e.oldRow[r.field]=r.value}return u}(t,e,c,a,r,i)}}return xa(t,e,s,r,i,null)}function xa(t,n,s,r,i,a){const l=i.stateElement,c=n.pathInfo.path,d=!!fn&&(fn=!1,!0);if(!(c in t)&&null!==n.parentAddress&&!l.elementPaths.has(c)){const u=na(t,n.parentAddress,r,i);if("object"==typeof u&&null!==u){const t=n.pathInfo.lastSegment,f=t===o?n.listIndex?.index:t;let h,p=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const t=void 0!==f&&f in u,e=void 0!==f?u[f]:void 0;if(t&&Object.is(e,s))return!0;h=e,p=!0}const m=Qi(l,n),g=Gt(zt(l,n.pathInfo),n.listIndex);null!==ae&&ae({type:"state:write",absoluteAddress:g,value:s,oldValue:h,hasOldValue:p}),wa(l,c,g,h,p);try{return void 0===f&&z(`address.listIndex?.index is undefined path: ${c}`),Reflect.set(u,f,s)}finally{va(n,g,r,i,a),m&&Vi(g,{value:s,dirty:!1}),sa(l,n.pathInfo,{value:s})}}}let u,f=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const e=na(t,n,r,i);if(ca(t,n,r,i)&&Object.is(e,s))return!0;u=e,f=!0}const h=l.elementPaths.has(n.pathInfo.path),p=Qi(l,n),m=Gt(zt(l,n.pathInfo),n.listIndex);null!==ae&&ae({type:"state:write",absoluteAddress:m,value:s,oldValue:u,hasOldValue:f}),wa(l,c,m,u,f);try{return h?Sa(t,n,m,s,r,i,a):Na(t,n,m,s,r,i,a)}finally{p&&Vi(m,{value:s,dirty:!1}),sa(l,n.pathInfo,{value:s})}}function $a(t,e,n,o){return(e,s,r)=>{const i=E(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==i.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(i.path,t.path)}i.wildcardParentPathInfos.length>s.length&&z(`indexes length is insufficient: ${e}`);let a=null;for(let e=0;e<i.wildcardParentPathInfos.length;e++){const r=i.wildcardParentPathInfos[e],l=be(r,a),c=Ro(na(t,l,n,o));null==c&&z(`ListIndexes not found: ${r.path}`);const d=s[e];a=c[d]??z(`ListIndex not found at index ${d} of ${r.path}`)}const l=be(i,a);if(!(void 0!==r))return na(t,l,n,o);Ia(t,l,r,n,o)}}const _a=new WeakMap;function Pa(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return oa(o,s.wildcardPaths.at(-1)??z(`lastWildcardPath is null: ${e.pathInfo.path}`))??z(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<e.pathInfo.wildcardCount;r++){const i=e.pathInfo.wildcardParentPathInfos[r]??z(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),a=Ro(na(t,be(i,s),n,o))??z(`ListIndex not found: ${i.path}`),l=e.wildcardIndexes[r]??z(`wildcardIndex is null: ${e.pathInfo.path}`);s=a[l]??z(`ListIndex not found at index ${l} of ${i.path}`)}return s}case"partial":z(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}const Aa=`${N}${n}`,ka=`${S}${n}`,Ca=new WeakMap;function Ea(t,e,n,o){const s=a[e];if(void 0!==s){0===o.addressStackLength&&z(`No active state reference to get list index for "${e.toString()}".`);const t=o.lastAddressStack,n=t?.pathInfo;n&&!o.untracking&&o.stateElement?.getterPaths.has(n.path)&&o.stateElement.addIndexDependentGetterPath?.(n.path);const r=t?.listIndex;null==r&&z(`ListIndex not found: ${e.toString()}`);const i=Zt(r,s,t.pathInfo.wildcardCount);return i?.index??z(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"===e[0]){switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=$a(t,0,n,o);return(e,r)=>{const i=new Map,a=E(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==a.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(a.path,t.path)}if(void 0===r){for(let t=0;t<a.wildcardParentPathInfos.length;t++){const e=a.wildcardParentPathInfos[t],n=oa(o,e.path);if(n){r=te(n,n.length-An(o.stateElement));break}}void 0===r&&(r=[])}const l=(e,s,r,a,c,d,u)=>{const f=e[s]??null;if(null===f)return void u.push(d);const h=be(f,r),p=_a.get(h),m=na(t,h,n,o),g=jo(Cn(o.stateElement,r),p,m).newIndexes,y=a[c]??null;if(i.set(h,m),null===y)for(let t=0;t<g.length;t++){const n=g[t];l(e,s+1,n,a,c+1,d.concat(n.index),u)}else{const t=g[y]??z(`ListIndex not found at index ${y} of ${f.path}`);s+1<e.length?l(e,s+1,t,a,c+1,d.concat(t.index),u):u.push(d.concat(t.index))}},c=[];l(a.wildcardParentPathInfos,0,null,r,0,[],c);const d=[];for(let t=0;t<c.length;t++)d.push(s(a.path,c[t]));for(const[t,e]of i.entries())_a.set(t,e);return d}}(t,0,n,o)(e,s);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const r=qi(e),i=Pa(t,r,n,o),a=be(r.pathInfo,i),l=Gt(zt(s,a.pathInfo),a.listIndex),c=Mr();c.enqueueAbsoluteAddress(l),ba(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=Gt(zt(s,t.pathInfo),t.listIndex);Hi(e),c.enqueueAbsoluteAddress(e)}),sa(s,a.pathInfo)}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>$a(t,0,n,o)(e,s,r);case"$trackDependency":return t=>function(t,e,n,o){return t=>{0===o.addressStackLength&&z(`No active state reference to track dependency for path "${t}".`);const e=o.lastAddressStack?.pathInfo??z("Internal error: lastAddressStack is null"),n=o.stateElement;o.stateElement.getterPaths.has(e.path)&&e.path!==t&&n.addDynamicDependency(t,e.path)}}(0,0,0,o)(t);case"$untrackDependency":return t=>function(t,e,n,o){return t=>{o.beginUntrack();try{return t()}finally{o.endUntrack()}}}(0,0,0,o)(t);case m:return Kr(o.stateElement);case N:return di(o.stateElement);case S:return ui(o.stateElement)}if(!e.startsWith(Aa)&&!e.startsWith(ka))return}const s=qi(e),r=Pa(t,s,n,o),i=be(s.pathInfo,r);return na(t,i,n,o)}if("symbol"==typeof e){const s=function(t){let e=Ca.get(t);return void 0===e&&(e=new Map,Ca.set(t,e)),e}(o),r=s.get(e);if(void 0!==r)return r;let i;switch(e){case Ot:i=(t,e=()=>{})=>function(t,e,n){void 0!==t.loopContext&&z("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return n()}finally{t.popAddress()}}finally{t.clearLoopContext()}}(o,t,e);break;case Rt:i=e=>na(t,e,n,o);break;case Dt:i=e=>ca(t,e,n,o);break;case Lt:i=(e,s)=>Ia(t,e,s,n,o);break;case Wt:i=()=>async function(t,e,n){const o=Reflect.get(t,l);"function"==typeof o&&await o.call(n)}(t,0,n);break;case Bt:i=()=>function(t,e,n){const o=Reflect.get(t,c);"function"==typeof o&&o.call(n)}(t,0,n);break;case jt:i=e=>function(t,e,n,o){const s=Reflect.get(t,d);if("function"==typeof s){const t=new Set,r={};for(const n of e){const e=n.absolutePathInfo.pathInfo;let s;if(s=n.absolutePathInfo.stateName===o.stateName?e.path:e.path+"@"+n.absolutePathInfo.stateName,t.add(s),e.wildcardCount>0){const t=te(n.listIndex,e.wildcardCount),o=r[s];void 0===o?r[s]=[t]:o.push(t)}}return s.call(n,Array.from(t),r)}}(t,e,n,o);break;default:return Reflect.get(t,e,n)}return s.set(e,i),i}}class Ma{_stateElement;_stateName;_addressStack=Array(s).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(t,e,n){this._stateName=e;const o=xr(t,this._stateName);null===o&&z(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=o,this._mutability=n}get stateName(){return this._stateName}get stateElement(){return this._stateElement}get lastAddressStack(){let t;return this._addressStackIndex>=0&&(t=this._addressStack[this._addressStackIndex]),void 0===t&&z("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex++,this._addressStackIndex>=s&&z("Exceeded maximum address stack depth of 128. Possible infinite loop."),this._addressStack[this._addressStackIndex]=t}popAddress(){if(this._addressStackIndex<0)return null;const t=this._addressStack[this._addressStackIndex];return void 0===t&&z(`Address stack at index ${this._addressStackIndex} is undefined.`),this._addressStack[this._addressStackIndex]=void 0,this._addressStackIndex--,t}setLoopContext(t){this._loopContext=t}clearLoopContext(){this._loopContext=void 0}get untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(t,e,n){return Ea(t,e,n,this)}set(t,e,n,o){return"readonly"===this._mutability&&z(`State "${this._stateName}" is readonly.`),function(t,e,n,o,s){if("string"==typeof e){const r=qi(e),i=Pa(t,r,o,s);return Ia(t,be(r.pathInfo,i),n,o,s)}return Reflect.set(t,e,n,o)}(t,e,n,o,this)}has(t,e){return Reflect.has(t,e)}}function Ta(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}class Oa{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=In(t,e)??z("State element not found for web component.")}_outerLoopContext(t,e){const n=e.pathInfo.wildcardCount,o=kn(e.stateElement,e.pathInfo),s=kt(this._webComponent);if(null!==s&&s.listIndex.length===o)return s;if(n>0){const s=function(t,e){if(0===Ji)return null;const n=Ji-1,o=Ki[n];return Gi[n]!==t||o?.pathInfo.path!==e?null:o}(this._innerStateElement,t.path),r=s?.listIndex??null;if(null!==r&&r.length===o){return be(E(e.pathInfo.wildcardPaths[n-1]),r)}}return s}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e,n);{if("then"===e)return;if("$"===e[0])return;if(this._innerStateElement.getterPaths.has(e)&&e in t)return Reflect.get(t,e,n);const o=E(e),s=zt(this._innerStateElement,o),r=Dn(this._webComponent,s);if(null!==r){const t=this._outerLoopContext(o,r);let e;return r.stateElement.createState("readonly",n=>{n[Ot](t,()=>{e=n[r.pathInfo.path]})}),e}if(e in t)return Reflect.get(t,e,n);z(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n,o);{if(this._innerStateElement.setterPaths.has(e)&&e in t)return Reflect.set(t,e,n,o);const s=E(e),r=zt(this._innerStateElement,s),i=Dn(this._webComponent,r);if(null!==i){const t=this._outerLoopContext(s,i);return i.stateElement.createState("writable",e=>{e[Ot](t,()=>{e[i.pathInfo.path]=n})}),!0}if(e in t)return Reflect.set(t,e,n,o);z(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}has(t,e){if("string"==typeof e){if("$"===e[0])return!1;if((this._innerStateElement.getterPaths.has(e)||this._innerStateElement.setterPaths.has(e))&&e in t)return!0;const n=E(e),o=zt(this._innerStateElement,n);return null!==Dn(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class Ra{_innerStateElement;constructor(t,e){this._innerStateElement=In(t,e)??z("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const Da=t=>()=>t;function La(t,n,o,s){!function(t,e,n){let o=Sn.get(t);o||(o=new Map,Sn.set(t,o)),o.set(e,n)}(n,o,t);const r=n.hasAttribute(e.bindAttributeName)?(i=n,(H.get(i)||null)??[]).filter(t=>t.propSegments[0]===o):[];var i;r.length>0?(!function(t,e,n){if(0===n.length)return;const o=In(t,e);null===o&&z("State element not found for web component.");const s=new Map,r=new Map;for(const e of n){const n=Rn(o,e);let i=Tn.get(t);void 0===i?Tn.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;On.set(n,e),s.set(a,l),r.set(l,a),$n(t,l.stateElement)}En.set(t,s),Mn.set(t,r)}(n,o,r),t.markComponentStateMapped?.(),t.setInitialState(function(t,e){const n=new Oa(t,e),o=In(t,e);null===o&&z("State element not found for web component."),null===o.boundComponentStateProp&&z("State element is not bound to any component state prop."),o.boundComponentStateProp in t||z(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=t[o.boundComponentStateProp];return"object"==typeof s&&null!==s||z(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Ta(s),n)}(n,o))):t.setInitialState(Ta(s));const a=function(t,e){const n=new Ra(t,e);return new Proxy({},n)}(n,o);if(Object.defineProperty(n,o,{get:Da(a),enumerable:!0,configurable:!0}),function(t,e){let n=So.get(t);n||(n=new Set,So.set(t,n)),n.add(e)}(n,o),u in n){const t=n[u];"function"==typeof t?t.call(n,o).catch(t=>{z(`Error in ${u}: ${t instanceof Error?t.message:String(t)}`)}):z(`${u} is not a function.`)}}class Wa extends cr{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return $r(t)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(t=()=>0){return new Ur(t)}(()=>An(this));_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_watchPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMappedComponentState=!1;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_dcc=!1;_connectGeneration=0;_streamsStartedGeneration=0;constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise((t,e)=>{this._resolveConnectedCallback=t,this._rejectConnectedCallback=e}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&z(`${e.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(t){const e=new Set,n=t[p];if(void 0===n)return e;Array.isArray(n)||z(`${p} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||z(`${p} entries must be non-empty strings.`),t===m&&z(`${p} entry "${t}" conflicts with the reserved namespace name "${m}".`),e.has(t)&&z(`${p} entry "${t}" is duplicated.`),e.add(t);return e}(e),this._eventTokenNames=function(t){const e=new Set,n=t[g];if(void 0===n)return e;Array.isArray(n)||z(`${g} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||z(`${g} entries must be non-empty strings.`),e.has(t)&&z(`${g} entry "${t}" is duplicated.`),e.add(t);return e}(e),this.__state=e,this._hasUpdatedCallback=d in e,Oe(this),function(t,e,n){const o=e[y];if(void 0!==o){"object"==typeof o&&null!==o||z(`${y} must be an object mapping event-token names to handler functions.`);for(const[e,s]of Object.entries(o))n.has(e)||z(`${y} entry "${e}" is not declared in $eventTokens.`),"function"!=typeof s&&z(`${y} entry "${e}" must be a function.`),Te(t,e).subscribe(s)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const s=function(t){const e=new Set,n=new Set,o=Wi(t);for(const[t,s]of Object.entries(o))"function"==typeof s.get&&e.add(t),"function"==typeof s.set&&n.add(t);return{getterPaths:e,setterPaths:n}}(e);for(const t of s.getterPaths)this._getterPaths.add(t);for(const t of s.setterPaths)this._setterPaths.add(t);var r;fi(this),oi(r=this),ti(r),ei.delete(r),ii(this,e),this._listKeys=function(t){const e=t[v];if(void 0===e)return null;"object"==typeof e&&null!==e||z(`${v} must be an object mapping list paths to key specs.`);const s=new Map;for(const[t,r]of Object.entries(e)){0===t.length&&z(`${v} entry path must be a non-empty string.`);const e=t.split(n);e.some(t=>0===t.length)&&z(`${v} entry "${t}" must not contain empty path segments.`),e[e.length-1]===o&&z(`${v} entry "${t}" must be the list path itself, not the element path (drop the trailing "${n}${o}").`),"function"!=typeof r?("string"!=typeof r&&z(`${v} entry "${t}" key spec must be a field name (string) or a function.`),0===r.length&&z(`${v} entry "${t}" key field name must be a non-empty string.`),(r.includes(n)||r.includes(o))&&z(`${v} entry "${t}" key field name "${r}" must be a flat property name ("${n}" / "${o}" are not allowed).`),r in Object.prototype&&z(`${v} entry "${t}" key field name "${r}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),s.set(t,r)):s.set(t,r)}return s.size>0?s:null}(e),function(t){wi.delete(t),bi.delete(t)}(this),function(t){xi.delete(t)}(this),this._watchPaths=Ii(this,e),this._initialized&&null!==this._rootNode&&!t()&&(Pi(this),mi(this),this._streamsStartedGeneration=this._connectGeneration),this._resolveLoading?.()}get name(){return this._name}_loadFromSsrElement(){if(!this.hasAttribute("enable-ssr"))return null;const t=this.getAttribute("name")||"default",e=this.parentNode;if(!e)return null;const n=mr.findByName(e,t);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const n=t()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const t=this.getAttribute("state");this._state=function(t){const e=document.getElementById(t);if(e&&"application/json"===e.type)try{return JSON.parse(e.textContent||"{}")}catch(t){z("Failed to parse JSON from script element:"+t)}return{}}(t)}else if(this.hasAttribute("src")){const t=this.getAttribute("src");t&&t.endsWith(".json")?this._state=await async function(t){try{const e=await fetch(t);return e.ok||z(`Failed to fetch JSON file: ${e.statusText}`),await e.json()}catch(t){return console.error("Failed to load JSON file:",t),{}}}(t):t&&t.endsWith(".js")?this._state=await qr(t):z(`Unsupported src file type: ${t}`)}else if(this.hasAttribute("json")){const t=this.getAttribute("json");this._state=JSON.parse(t)}else{const t=this.querySelector('script[type="module"]');if(t)this._state=await zr(t,`${this._name}`);else{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${e.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(t)}}}catch(t){z(`Failed to initialize state: ${t}`)}if(null!==n&&this.__state)for(const[t,e]of Object.entries(n)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=e}await this._loadingPromise,this._name=this.getAttribute("name")||"default",_r(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const t=this.parentNode,n=t instanceof ShadowRoot?t.host:t instanceof Element?t:null,o=n?O(n):null;null!==n&&null!==o||z(`"bind-component" requires <${e.tagNames.state}> to be a direct child of a custom element.`),t instanceof ShadowRoot||this.hasAttribute("name")||z('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=["state","src","json"].filter(t=>this.hasAttribute(t));null!==this.querySelector('script[type="module"]')&&s.push('<script type="module">'),s.length>0&&z(`"bind-component" cannot be combined with ${s.join(", ")}. The component's "${this.getAttribute("bind-component")}" property is the only state source.`);const r=this.getAttribute("bind-component");await customElements.whenDefined(o.toLowerCase()),n.hasAttribute(e.bindAttributeName)&&await P(n),r in n||z(`Component does not have property "${r}" for state binding.`);const i=n[r];"object"==typeof i&&null!==i||z(`Component property "${r}" is not an object for state binding.`),this._boundComponent=n,this._boundComponentStateProp=r,La(this,this._boundComponent,this._boundComponentStateProp,i)}}_initializeLightDomComponentScope(){const t=this._boundComponent;null!==t&&this.parentNode===t&&t.hasAttribute(e.bindAttributeName)&&(rr(this._rootNode,t),Bs(t,null))}_reloadMappedPathsAfterReconnect(){if(!this._hasMappedComponentState||null===this._boundComponent)return;const t=function(t){const e=Tn.get(t);if(void 0===e)return[];const n=[];for(const t of e)n.push(t.innerAbsPathInfo.pathInfo.path);return n}(this._boundComponent);!function(t){const e=Tn.get(t);if(void 0===e)return;const n=new Map,o=new Map;for(const t of e)n.set(t.innerAbsPathInfo,t.outerAbsPathInfo),o.set(t.outerAbsPathInfo,t.innerAbsPathInfo);En.set(t,n),Mn.set(t,o)}(this._boundComponent),this.createState("readonly",e=>{for(const n of t)e.$postUpdate(n)})}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{l in t&&await t[Wt]()})}async _initializeDCC(t,n){let o;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?o=await qr(t):z(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?o=await zr(e,t.tagName.toLowerCase()):z(`DCC: No state source found for "${t.tagName.toLowerCase()}".`)}}catch(t){z(`DCC: Failed to load state: ${t}`)}!function(t,n,o){const s=t.tagName.toLowerCase();s.includes("-")||z(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s)&&z(`DCC: "${s}" is already registered. A custom element name can only be defined once.`);const r=document.createElement("template");r.innerHTML=n.innerHTML;const i=n.mode,{bindables:a,commands:l,streamBackedBindables:c}=ji(o),d=a.length>0||l.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const s=n.map(t=>({name:t,async:!0}));return{...o,commands:s}}(s,a,l):null,u=a.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(s,a):{},h=`${e.tagNames.state}:not([name])`,p=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=d;static bindableEventMap=u;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(I))return null;this._shadow=this.attachShadow({mode:p.shadowRootMode}),this._shadow.appendChild(p.template.content.cloneNode(!0));const t=R();return null!==t&&D(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(p.bindableEventMap).length>0){const n=t.querySelector(h);n?n.setBindableEventMap(p.bindableEventMap):console.warn(`[@wcstack/state] DCC: "${s}" declares ${f} but its template has no <${e.tagNames.state}> without a "name" attribute. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(h)??null}},m=Wi(o);for(const[t,e]of Object.entries(m)){if(Li(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=Di(t,o)}else n.get=Oi(t),n.set=Ri(t);Object.defineProperty(p.prototype,t,n)}for(const t of c)Object.defineProperty(p.prototype,t,{configurable:!0,enumerable:!0,get:Oi(t),set:Ri(t)});customElements.define(s,p)}(t,n,o),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",t=>{c in t&&t[Bt]()})}async connectedCallback(){this._rootNode=this.getRootNode();const n=++this._connectGeneration;if(this._initialized)this._dcc||xr(this._rootNode,this._name)===this||(_r(this._rootNode,this._name,this),this._reloadMappedPathsAfterReconnect());else{const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(I))return this.hasAttribute("bind-component")&&z(`"bind-component" cannot be used inside a [${I}] host. DCC state comes from the template, not from a component property.`),void await this._initializeDCC(t.host,t);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._initializeLightDomComponentScope(),this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!t()||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr"))try{await $r(this.rootNode);const t=this.getAttribute("name")||"default",n=mr.extractStateData(this),o=document.createElement(e.tagNames.ssr);o.setAttribute("name",t),o.setAttribute("version",lr),mr.buildContent(o,n),this.parentNode?.insertBefore(o,this)}catch(t){throw this._rejectConnectedCallback?.(t),t}t()||null===this._rootNode||n!==this._connectGeneration||Pi(this),t()||null===this._rootNode||n!==this._connectGeneration||this._streamsStartedGeneration===n||mi(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{_r(this.rootNode,this._name,null),t=this,Vr.delete(t),function(t){Gr.delete(t)}(this),Oe(this),oi(this),fi(this),function(t){wi.delete(t)}(this),this._rootNode=null}var t}get initialized(){return this._initialized}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get watchPaths(){return this._watchPaths}get elementPaths(){return this._elementPaths}get getterPaths(){return this._getterPaths}get setterPaths(){return this._setterPaths}get loopContextStack(){return this._loopContextStack}get dynamicDependency(){return this._dynamicDependency}get staticDependency(){return this._staticDependency}get version(){return this._version}get rootNode(){return null===this._rootNode&&z("State rootNode is not available."),this._rootNode}get hasRootNode(){return null!==this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get boundComponent(){return this._boundComponent}get hasMappedComponentState(){return this._hasMappedComponentState}markComponentStateMapped(){this._hasMappedComponentState=!0}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(t){this._bindableEventMap=t}_addDependency(t,e,n){const o=t.get(e);return void 0===o?(t.set(e,[n]),!0):!o.includes(n)&&(o.push(n),!0)}addDynamicDependency(t,e){return this._addDependency(this._dynamicDependency,t,e)}addStaticDependency(t,e){return this._addDependency(this._staticDependency,t,e)}setPathInfo(t,e){if("for"===e){const e=!this._listPaths.has(t);this._listPaths.add(t),this._elementPaths.add(t+"."+o),e&&this._hasMappedComponentState&&function(t,e){const n=Wn(t,E(e));null!==n&&n.stateElement!==t&&n.stateElement.setPathInfo(n.pathInfo.path,"for")}(this,t)}if(!this._pathSet.has(t)){const e=E(t);if(this._pathSet.add(t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=E(t.parentPath)}}}_createState(t,e,n){try{const o=function(t,e,n,o){const s=new Ma(t,n,o);return new Proxy(e,s)}(t,this._state,this._name,e);return n(o)}finally{}}async createStateAsync(t,e){return await this._createState(this.rootNode,t,e)}createState(t,e){this._createState(this.rootNode,t,e)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(t){this._crossRowListPaths.add(t)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(t){this._indexDependentGetterPaths.add(t)}bindProperty(t,e){Object.defineProperty(this._state,t,e),t===d&&(this._hasUpdatedCallback=!0)}setInitialState(t){this._initialized?this._state=t:this._resolveSetState?.(t)}}function Ba(){customElements.get(e.tagNames.ssr)||customElements.define(e.tagNames.ssr,mr),customElements.get(e.tagNames.state)||customElements.define(e.tagNames.state,Wa)}await(Ba(),void jr());
|
|
1
|
+
function t(){const t=document.documentElement;return!!t&&t.hasAttribute("data-wcs-server")}const e={bindAttributeName:"data-wcs",commentTextPrefix:"wcs-text",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:"en",debug:!1,enableMustache:!0,enableDirectionalInitialSync:!0,enablePropagationContext:!0,enableContractAnalyzer:!1,sameValueGuard:!0},n=".",o="*",s=128,r="|",i="prevent",a="stop",l="ro",c="init",d="sync",u="else",f="...",h="on",p="eventToken",m="command",g="class",y="attr",b="style",w={};for(let t=0;t<128;t++)w[`$${t+1}`]=t;const v=Object.freeze(w),N="$connectedCallback",S="$disconnectedCallback",I="$updatedCallback",x="$stateReadyCallback",$="$bindables",P="$commands",_="$commandTokens",A="$command",k="$eventTokens",C="$on",E="$streams",M="$watch",T="$listKeys",O="$streamStatus",R="$streamError",D="data-wc-definition",L=new WeakMap,W=new WeakSet;let j=0;async function B(t){const e=function(t){let e,n=L.get(t)||null;if(null!==n)return n;const o=new Promise(t=>{e=t});return n={id:++j,promise:o,resolve:e},L.set(t,n),W.has(t)&&n.resolve(),n}(t);await e.promise}function F(t){const e=L.get(t);void 0===e?W.add(t):e.resolve()}const z=new Map;let q=0;function U(t){let e=z.get(t);return void 0!==e||(e=Object.freeze(new V(t)),z.set(t,e)),e}class V{id=++q;path;segments;lastSegment;cumulativePaths;cumulativePathSet;cumulativePathInfos;cumulativePathInfoSet;parentPath;wildcardPaths;wildcardPathSet;indexByWildcardPath;wildcardPathInfos;wildcardPathInfoSet;wildcardParentPaths;wildcardParentPathSet;wildcardParentPathInfos;wildcardParentPathInfoSet;wildcardPositions;lastWildcardPath;lastWildcardInfo;wildcardCount;parentPathInfo;constructor(t){const e=e=>t===e?this:U(e),n=t.split("."),s=[],r=[],i=[],a={},l=[],c=[],d=[],u=[];let f="",h="",p=0;for(let t=0;t<n.length;t++)f+=n[t],n[t]===o&&(i.push(f),a[f]=p,l.push(e(f)),c.push(h),d.push(e(h)),u.push(t),p++),s.push(f),r.push(e(f)),h=f,f+=".";const m=i.length>0?i[i.length-1]:null,g=s.length>1?s[s.length-2]:null;this.path=t,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=s,this.cumulativePathSet=new Set(s),this.cumulativePathInfos=r,this.cumulativePathInfoSet=new Set(r),this.wildcardPaths=i,this.wildcardPathSet=new Set(i),this.indexByWildcardPath=a,this.wildcardPathInfos=l,this.wildcardPathInfoSet=new Set(l),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=d,this.wildcardParentPathInfoSet=new Set(d),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?e(m):null,this.parentPath=g,this.parentPathInfo=g?e(g):null,this.wildcardCount=p}}const H=new WeakMap;function G(t){const e=H.get(t);if(void 0!==e)return e;let n=null;try{if(t.nodeType!==Node.ELEMENT_NODE)return n;const e=t,o=e.tagName.toLowerCase();if(o.includes("-"))return n=o;if(e.hasAttribute("is")){const t=e.getAttribute("is");if(t.includes("-"))return n=t}return n}finally{H.set(t,n)}}function K(t=null){const e=globalThis.customElements,n=t?.customElements??e;if("object"!=typeof n||null===n)return null;const o=n;return"function"!=typeof o.get||"function"!=typeof o.whenDefined?null:o}function J(t,e){t.upgrade?.(e)}function X(t){try{if(null===t||"object"!=typeof t&&"function"!=typeof t)return null;const e=t,n=e.addEventListener,o=e.removeEventListener,s=e.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 r=tt(s.properties,Y);if(null===r)return null;const i=void 0===s.inputs?new Map:tt(s.inputs,Q);if(null===i)return null;const a=void 0===s.commands?new Map:tt(s.commands,Z);return null===a?null:{target:t,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function Y(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&("string"==typeof e.event&&0!==e.event.length&&(void 0===e.getter||"function"==typeof e.getter))}function Q(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.attribute||"string"==typeof e.attribute)}function Z(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.async||"boolean"==typeof e.async)}function tt(t,e){if(!Array.isArray(t))return null;const n=new Map;for(const o of t){if(!e(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function et(t){throw new Error(`[@wcstack/state] ${t}`)}function nt(t,e,n){const o="."===e?`.${t}`:`${e}.${t}`;return{propName:t,propSegments:[t],propModifiers:[],statePathName:o,statePathInfo:U(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function ot(t){switch(t.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${t.bindingType}::${t.propName}`;default:return null}}function st(t,e){let n=t;if(0===e.length)return n;for(let t=0;t<e.length&&(n=n?.childNodes[e[t]]??null,null!==n);t++);return n}const rt=new WeakMap;const it=new Set(["if","elseif","else","for"]);function at(t,e,n){if(Math.abs(t.length-e.length)>n)return n+1;const o=new Array(e.length+1),s=new Array(e.length+1);for(let t=0;t<=e.length;t++)o[t]=t;for(let n=1;n<=t.length;n++){s[0]=n;for(let r=1;r<=e.length;r++){const i=t[n-1]===e[r-1]?0:1;s[r]=Math.min(o[r]+1,s[r-1]+1,o[r-1]+i)}for(let t=0;t<=e.length;t++)o[t]=s[t]}return o[e.length]}function lt(t,e){if(0===t.length)return"";const n=t.toLowerCase();let o=null,s=3;for(const t of e){const e=at(n,t.toLowerCase(),2);e<s&&(o=t,s=e)}return null!==o?` Did you mean "${o}"?`:""}const ct=" Validate statically: npx @wcstack/lint <file>.";function dt(t){et(`filter ${t} requires at least one option`)}function ut(t){et(`filter ${t} requires a number as option`)}function ft(t){et(`filter ${t} requires a number value`)}function ht(t){et(`filter ${t} requires a date value`)}function pt(t){return!(!t||isNaN(Number(t)))}const mt={eq:t=>{const e=t?.[0]??dt("eq");return t=>"number"==typeof t?(pt(e)||ut("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??dt("ne");return t=>"number"==typeof t?(pt(e)||ut("ne"),t!==Number(e)):t!==e},not:t=>t=>("boolean"!=typeof t&&et(`filter ${"not"} requires a boolean value`),!t),lt:t=>{const e=t?.[0]??dt("lt");return pt(e)||ut("lt"),t=>("number"!=typeof t&&ft("lt"),t<Number(e))},le:t=>{const e=t?.[0]??dt("le");return pt(e)||ut("le"),t=>("number"!=typeof t&&ft("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??dt("gt");return pt(e)||ut("gt"),t=>("number"!=typeof t&&ft("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??dt("ge");return pt(e)||ut("ge"),t=>("number"!=typeof t&&ft("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??dt("inc");return pt(e)||ut("inc"),t=>("number"!=typeof t&&ft("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??dt("dec");return pt(e)||ut("dec"),t=>("number"!=typeof t&&ft("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??dt("mul");return pt(e)||ut("mul"),t=>("number"!=typeof t&&ft("mul"),t*Number(e))},div:t=>{const e=t?.[0]??dt("div");return pt(e)||ut("div"),t=>("number"!=typeof t&&ft("div"),t/Number(e))},mod:t=>{const e=t?.[0]??dt("mod");return pt(e)||ut("mod"),t=>("number"!=typeof t&&ft("mod"),t%Number(e))},abs:t=>t=>("number"!=typeof t&&ft("abs"),Math.abs(t)),clamp:t=>{const e=t?.[0]??dt("clamp");pt(e)||ut("clamp");const n=t?.[1]??dt("clamp");pt(n)||ut("clamp");const o=Number(e),s=Number(n);return t=>("number"!=typeof t&&ft("clamp"),Math.min(Math.max(t,o),s))},fix:t=>{const e=t?.[0]??"0";return pt(e)||ut("fix"),t=>("number"!=typeof t&&ft("fix"),t.toFixed(Number(e)))},locale:t=>{const n=t?.[0]??e.locale;return t=>("number"!=typeof t&&ft("locale"),t.toLocaleString(n))},uc:t=>t=>String(t).toUpperCase(),lc:t=>t=>String(t).toLowerCase(),cap:t=>t=>{const e=String(t);return 0===e.length?e:1===e.length?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)},trim:t=>t=>String(t).trim(),slice:t=>{const e=[],n=t?.[0]??dt("slice");pt(n)||ut("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(pt(o)||ut("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??dt("substr");pt(e)||ut("substr");const n=t?.[1]??dt("substr");return pt(n)||ut("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??dt("pad");pt(e)||ut("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??dt("rep");return pt(e)||ut("rep"),t=>String(t).repeat(Number(e))},rev:t=>t=>String(t).split("").reverse().join(""),truncate:t=>{const e=t?.[0]??dt("truncate");pt(e)||ut("truncate");const n=Number(e),o=t?.[1]??"…";return t=>{const e=String(t);return e.length<=n?e:e.slice(0,n)+o}},join:t=>{const e=t?.[0]??", ";return t=>(Array.isArray(t)||et(`filter ${"join"} requires an array value`),t.join(e))},int:t=>t=>parseInt(String(t),10),float:t=>t=>parseFloat(String(t)),round:t=>{const e=t?.[0]??"0";return pt(e)||ut("round"),t=>{"number"!=typeof t&&ft("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return pt(e)||ut("floor"),t=>{"number"!=typeof t&&ft("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return pt(e)||ut("ceil"),t=>{"number"!=typeof t&&ft("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return pt(e)||ut("percent"),t=>("number"!=typeof t&&ft("percent"),`${(100*t).toFixed(Number(e))}%`)},unit:t=>{const e=t?.[0]??dt("unit");return t=>null==t?t:String(t)+e},date:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||ht("date"),t.toLocaleDateString(n))},time:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||ht("time"),t.toLocaleTimeString(n))},datetime:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||ht("datetime"),t.toLocaleString(n))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||ht("ymd");const n=t.getFullYear().toString(),o=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},hms:t=>{const e=t?.[0]??":";return t=>{t instanceof Date||ht("hms");const n=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),s=t.getSeconds().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},falsy:t=>t=>!1===t||null==t||0===t||""===t||Number.isNaN(t),truthy:t=>t=>!1!==t&&null!=t&&0!==t&&""!==t&&!Number.isNaN(t),defaults:t=>{const e=t?.[0]??dt("defaults");return t=>!1===t||null==t||0===t||""===t||Number.isNaN(t)?e:t},boolean:t=>t=>Boolean(t),number:t=>t=>Number(t),string:t=>t=>String(t),null:t=>t=>""===t?null:t},gt=mt,yt={input:mt,output:gt},bt=(t,e)=>n=>{const o=n[t];return o||et(`[wcs/filter-unknown] filter not found: ${t}.${lt(t,Object.keys(n))}${ct}`),o(e)};function wt(t,e,n){const o=-1===e?t.length:e;let s=0;for(;s<o&&/\s/.test(t[s]);)s++;const r=-1===n?0:n;let i=t.length;for(;i>r&&/\s/.test(t[i-1]);)i--;return t.slice(s,i)}const vt=new Map;function Nt(t,e){const n=yt[e];return t.map(t=>{const o=t.indexOf("("),s=t.lastIndexOf(")");if(-1!==o&&-1===s&&et(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==s&&-1===o&&et(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===o){const o=t.trim(),s=`${o}():${e}`;let r=vt.get(s);return void 0===r&&(r=bt(o,[])(n),vt.set(s,r)),{filterName:o,args:[],filterFn:r}}{const r=t.substring(o+1,s),i=t.substring(0,o).trim(),a=function(t){const e=[];let n="",o=null,s=!1,r=-1,i=-1;const a=()=>{e.push(wt(n,r,i)),n="",s=!1,r=-1,i=-1};for(let e=0;e<t.length;e++){const l=t[e];o?l===o?o=null:(-1===r&&(r=n.length),n+=l,i=n.length):'"'===l||"'"===l?(o=l,s=!0):","===l?a():n+=l}const l=wt(n,r,i);return(l||s)&&e.push(l),e}(r),l=`${i}(${a.join(",")}):${e}`;let c=vt.get(l);return void 0===c&&(c=bt(i,a)(n),vt.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const St=t=>t.trim(),It=new Map;const xt=new Map;function $t(t){const e=t.indexOf(r);let n="",o=[],s="",i=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),xt.has(s)?i=xt.get(s):(o=s.split(r).map(St),i=Nt(o,"output"),xt.set(s,i))):n=t.trim();const[a,l="default"]=n.split("@").map(St);return{stateName:l,statePathName:a,statePathInfo:U(a),outFilters:i}}function Pt(t){const[...e]=t.split(";").map(St).filter(t=>t.length>0),o=e.map(t=>{const e=t.indexOf(":");-1===e&&et(`Invalid bindText: "${t}". Missing ':' separator between propPart and statePart.`);const o=t.slice(0,e).trim(),s=t.slice(e+1).trim();if(o===u){const t=U("#else");return{propName:u,propSegments:[u],propModifiers:[],statePathName:"#else",statePathInfo:t,stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if(o===f){const e=$t(s);return e.outFilters.length>0&&et(`Invalid spread binding "${t}": filters are not allowed on spread targets.`),0===e.statePathName.length&&et(`Invalid spread binding "${t}": spread target path is required.`),{propName:f,propSegments:[f],propModifiers:[],inFilters:[],...e,bindingType:"spread"}}if("if"===o||"elseif"===o||"for"===o||"radio"===o||"checkbox"===o){return{propName:o,propSegments:[o],propModifiers:[],inFilters:[],...$t(s),bindingType:o}}{const t=$t(s),e=function(t){const e=t.indexOf(r);let o="",s=[],i="",a=[];-1!==e?(o=t.slice(0,e).trim(),i=t.slice(e+1).trim(),It.has(i)?a=It.get(i):(s=i.split(r).map(St),a=Nt(s,"input"),It.set(i,a))):o=t.trim();const[l,c]=o.split("#").map(St),d=l.split(n).map(St);return{propName:l,propSegments:d,propModifiers:c?c.split(",").map(St):[],inFilters:a}}(o);return e.propSegments[0]===p||e.propSegments[0].startsWith(h)?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(o.length>1){o.some(t=>it.has(t.bindingType))&&et(`[wcs/template-syntax] Invalid bindText: "${t}". '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">).`)}return o}const _t=new WeakMap,At=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),kt=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function Ct(t){const n=_t.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=kt.exec(o);if(null===s)return null;const r=s[1]||e.commentTextPrefix;return At.has(r)?(_t.set(t,s[2]),s[2]):null}const Et=new Map;function Mt(t,e,n){if(null===n)Et.delete(t);else{Et.set(t,n);const o=n.parseBindTextResult,s=Br(e,o.stateName);null===s&&et(`State element with name "${o.stateName}" not found for fragment info.`),s.setPathInfo(o.statePathName,o.bindingType);for(const t of n.nodeInfos)for(const n of t.parseBindTextResults){const t=Br(e,n.stateName);null===t&&et(`State element with name "${n.stateName}" not found for fragment info node.`),t.setPathInfo(n.statePathName,n.bindingType)}}}function Tt(t){return Et.get(t)||null}function Ot(t){if(t.nodeType===Node.ELEMENT_NODE){return Pt(t.getAttribute(e.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=Ct(t);null===e&&et("Comment node binding text not found.");const n=Tt(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...$t(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function Rt(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Dt(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!Rt(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function Lt(t,e){for(let n=0;n<e.length;n++){const o=e[n];if(o!==t&&o.contains(t))return!0}return!1}function Wt(t){const n=[],o=Dt(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!==Ct(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const t=s.currentNode;o.length>0&&Lt(t,o)||n.push(t)}return n}const jt=new WeakSet;function Bt(t,e,n){const o=function(t,e,n={}){const o=n.allowDeferred??!0;if(!e.some(t=>"spread"===t.bindingType))return e;const s=[],r=new WeakSet;for(const n of e){if("spread"!==n.bindingType){s.push(n);continue}t.nodeType!==Node.ELEMENT_NODE&&et("Spread binding requires an element node.");const e=t,i=G(e);null===i&&et(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${e.tagName.toLowerCase()}> is not a custom element.`);const a=K();if(null===a&&et(`CustomElementRegistry is unavailable for <${i}>.`),void 0===a.get(i)){o||et(`Spread binding "${n.statePathName}" requires <${i}> to be registered. Define the custom element before initializing this binding.`),s.push(n);continue}J(a,e);const l=X(e);null===l&&et(`Spread binding "${n.statePathName}" requires <${i}> to expose a valid wcBindable declaration.`);const c=n.statePathName,d=n.stateName,u=new Set;for(const t of l.knownProperties.keys()){if(u.has(t))continue;u.add(t);const e=nt(t,c,d);r.add(e),s.push(e)}for(const t of l.declaredInputs.keys()){if(u.has(t))continue;u.add(t);const e=nt(t,c,d);r.add(e),s.push(e)}}const i=new Map;for(let t=0;t<s.length;t++){const e=ot(s[t]);null!==e&&i.set(e,t)}const a=[];for(let t=0;t<s.length;t++){const e=ot(s[t]);null!==e?i.get(e)===t&&a.push(s[t]):a.push(s[t])}return a}(t,e,{allowDeferred:n.allowDeferred});if(o.some(t=>"spread"===t.bindingType)){const n=t.nodeType===Node.ELEMENT_NODE?G(t):null;return null===n&&et("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:t,tagName:n,parseResults:e}}}jt.add(t);const s=function(t,e){const n=[];for(const o of e)if("text"!==o.bindingType)n.push({...o,node:t,replaceNode:t});else{const e=t.nodeType===Node.TEXT_NODE?t:document.createTextNode("");n.push({...o,node:t,replaceNode:e})}return n}(t,o);return function(t,e){rt.set(t,e)}(t,s),F(t),{bindings:s,deferred:null}}function Ft(t){const e=Wt(t),n=[],o=[];for(const t of e){if(jt.has(t))continue;const e=Bt(t,Ot(t),{allowDeferred:!0});null===e.deferred?n.push(...e.bindings):o.push(e.deferred)}return[e,n,o]}function zt(t){jt.add(t)}function qt(t){const{node:e,parseResults:n}=t;!function(t){jt.delete(t)}(e);return Bt(e,n,{allowDeferred:!1}).bindings}const Ut=new WeakMap;function Vt(t){let e=t;for(;e;){const t=Ut.get(e);if(t)return t;e=e.parentNode}return null}function Ht(t,e){null!==e?Ut.set(t,e):Ut.delete(t)}const Gt=new WeakMap;function Kt(t){return Gt.get(t)??[]}function Jt(t,e){Gt.set(t,e)}const Xt=Symbol("$$setLoopContext"),Yt=Symbol("$$getByAddress"),Qt=Symbol("$$hasByAddress"),Zt=Symbol("$$setByAddress"),te=Symbol("$$connectedCallback"),ee=Symbol("$$disconnectedCallback"),ne=Symbol("$$updatedCallback"),oe=new WeakMap;function se(t,e){if(oe.has(t)){const n=oe.get(t);if(n.has(e))return n.get(e)}else oe.set(t,new WeakMap);const n=Object.freeze(new re(t,e));return oe.get(t).set(e,n),n}class re{pathInfo;stateName;stateElement;parentAbsolutePathInfo;constructor(t,e){this.pathInfo=e,this.stateName=t.name,this.stateElement=t,null===e.parentPathInfo?this.parentAbsolutePathInfo=null:this.parentAbsolutePathInfo=se(t,e.parentPathInfo)}}const ie=new WeakMap,ae=new WeakMap;class le{absolutePathInfo;listIndex;_parentAbsoluteAddress;constructor(t,e){this.absolutePathInfo=t,this.listIndex=e}get parentAbsoluteAddress(){if(void 0!==this._parentAbsoluteAddress)return this._parentAbsoluteAddress;const t=this.absolutePathInfo.parentAbsolutePathInfo;if(null===t)return null;let e=null;return e=this.absolutePathInfo.pathInfo.segments[this.absolutePathInfo.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=ce(t,e)}}function ce(t,e){if(null===e){let e=ae.get(t);return void 0!==e||(e=new le(t,null),ae.set(t,e)),e}{let n=ie.get(e);void 0===n&&(n=new WeakMap,ie.set(e,n));let o=n.get(t);return void 0!==o||(o=new le(t,e),n.set(t,o)),o}}const de=new WeakMap;function ue(t,e){null===e?de.delete(t):de.set(t,e)}function fe(t){return de.get(t)||null}const he=new Map;function pe(t,e){let n,o;if(0===t.wildcardCount||0===e.wildcardCount)return 0;if(1===t.wildcardCount&&e.wildcardCount>0&&e.wildcardPathSet.has(t.path))return 1;t.id<e.id?(n=t,o=e):(n=e,o=t);const s=`${n.path}\t${o.path}`;let r=he.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,he.set(s,r),r}function me(t,e,n){return e<0||e>=n?null:t.at(e-n)}function ge(t,e){const n=t.indexes??[];return n.length===e?n:n.slice(n.length-e)}const ye=new WeakMap;function be(t){const e=Vt(t.node);if(null===e)return null;let n=ye.get(e);if(void 0===n)n=new WeakMap,ye.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=pe(e.pathInfo,t.statePathInfo);return n>0&&(o=me(e.listIndex,n-1,e.pathInfo.wildcardCount)),o}finally{n.set(t,o)}}const we=new WeakMap;function ve(t,e){if(null!=e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=fe(n);null===e?et(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}return n}function Ne(t,e){let n=null;if(n=we.get(t)||null,null!==n)return n;const o=ve(t,e),s=be(t),r=Br(o,t.stateName);null===r&&et(`State element with name "${t.stateName}" not found for binding.`);return n=ce(se(r,t.statePathInfo),s),we.set(t,n),n}function Se(t){we.delete(t)}let Ie=null;const xe=new WeakMap;function $e(t,e){const n=xe.get(t);void 0===n?xe.set(t,e):n instanceof Set?n.add(e):n!==e&&xe.set(t,new Set([n,e])),null!==Ie&&Ie({type:"state:binding-added",absoluteAddress:t,binding:e})}function Pe(t,e){const n=xe.get(t);void 0!==n&&(n instanceof Set?n.delete(e):n===e&&xe.delete(t),null!==Ie&&Ie({type:"state:binding-removed",absoluteAddress:t,binding:e}))}const _e=new WeakMap;function Ae(t,e,n){let o=_e.get(t);void 0===o&&(o=new WeakMap,_e.set(t,o));const s=o.get(e);void 0===s?o.set(e,n):s instanceof Set?s.add(n):s!==n&&o.set(e,new Set([s,n])),null!==Ie&&Ie({type:"state:binding-added",absoluteAddress:ce(t,e),binding:n})}function ke(t,e,n){const o=_e.get(t);if(void 0===o)return;const s=o.get(e);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(e),null!==Ie&&Ie({type:"state:binding-removed",absoluteAddress:ce(t,e),binding:n}))}function Ce(t){const e=xe.get(t);return void 0!==e?e:null!==t.listIndex?_e.get(t.absolutePathInfo)?.get(t.listIndex):void 0}const Ee=new WeakMap,Me=new WeakMap;class Te{pathInfo;listIndex;_parentAddress;constructor(t,e){this.pathInfo=t,this.listIndex=e}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let e=null;return e=this.pathInfo.segments[this.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=Oe(t,e)}}function Oe(t,e){if(null===e){let e=Me.get(t);return void 0!==e||(e=new Te(t,null),Me.set(t,e)),e}{let n=Ee.get(e);void 0===n&&(n=new WeakMap,Ee.set(e,n));let o=n.get(t);return void 0!==o||(o=new Te(t,e),n.set(t,o)),o}}const Re=new WeakMap;function De(t){let e=null;if(e=Re.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=be(t);null===n&&et(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=Oe(t.statePathInfo,n)}else e=Oe(t.statePathInfo,null);return Re.set(t,e),e}function Le(t){Re.delete(t)}function We(){const t=new Map,e=new Map;return{add(n,o){let s=t.get(n);return void 0===s&&(s=new WeakSet,t.set(n,s)),!s.has(o)&&(s.add(o),e.set(n,(e.get(n)??0)+1),!0)},remove(n,o){const s=t.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const r=(e.get(n)??1)-1;return r<=0?(t.delete(n),e.delete(n),!0):(e.set(n,r),!1)},has:(e,n)=>t.get(e)?.has(n)??!1,countOf:t=>e.get(t)??0,get keyCount(){return e.size},clear(){t.clear(),e.clear()}}}const je=new Map,Be=We();function Fe(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function ze(t){let e="input";for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function qe(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const s=ze(t),r=Fe(t,s);let i=je.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==s.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=s.checked;let i=s.value;for(const t of o)i=t.filterFn(i);const a=Br(s.getRootNode(),e);null===a&&et(`State element with name "${e}" not found for two-way binding.`);const l=Vt(s);a.createState("writable",t=>{t[Xt](l,()=>{let e=t[n];if(Array.isArray(e))if(r)-1===e.indexOf(i)&&(t[n]=e.concat(i));else{const o=e.indexOf(i);-1!==o&&(t[n]=e.toSpliced(o,1))}else t[n]=r?[i]:[]})})},je.set(r,i)),t.node.addEventListener(s,i),Be.add(r,t),!0}var e,n,o;return!1}function Ue(t){return("object"==typeof t||"function"==typeof t)&&null!==t&&"function"==typeof t.then}function Ve(t,e){const n=Array.isArray(t)?t:[t];for(const t of n)Ue(t)&&Promise.resolve(t).catch(t=>{console.error(`[wcstack/state] ${e} rejected.`,t)})}class He{_name;_subscribers=new Set;constructor(t){this._name=t}get name(){return this._name}get size(){return this._subscribers.size}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}unsubscribe(t){return this._subscribers.delete(t)}emit(...t){const e=[];for(const n of this._subscribers)e.push(n(...t));return e}}class Ge extends He{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==Ie&&Ie({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}const Ke=new WeakMap;function Je(t,e){let n=Ke.get(t);void 0===n&&(n=new Map,Ke.set(t,n));let o=n.get(e);return void 0===o&&(o=new Ge(e,t.name),n.set(e,o)),o}function Xe(t){Ke.delete(t)}const Ye=new WeakMap;function Qe(t){if(t.propSegments[0]!==p)return!1;const e=t.node,n=G(e),o=K();if(null!==n&&void 0===o?.get(n))return null===o&&et(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(Ye.has(t))return!0;const s=t.propSegments[1];"string"==typeof s&&0!==s.length||et('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(t){return null===G(t)?null:X(t)}(e);null===r&&et(`eventToken binding requires a wc-bindable custom element. <${e.tagName.toLowerCase()}> is not wc-bindable.`);const l=r.knownProperties.get(s);void 0===l&&et(`Property "${s}" is not declared in wcBindable.properties of <${e.tagName.toLowerCase()}>.${lt(s,r.knownProperties.keys())}`);const c=l.event,d=t.statePathName,u=t.stateName,f=t.propModifiers,h=t=>{f.includes(i)&&t.preventDefault(),f.includes(a)&&t.stopPropagation();const n=Br(e.getRootNode(),u);null===n&&et(`State element with name "${u}" not found for eventToken handler.`),n.eventTokenNames.has(d)||et(`[wcs/token-undeclared] eventToken "${d}" is not declared in $eventTokens of state "${u}".${lt(d,n.eventTokenNames)}${ct}`);const o=Vt(e);n.createStateAsync("writable",async e=>{Ve(e[Xt](o,()=>{const s=null!==o?ge(o.listIndex,o.pathInfo.wildcardCount):[];return Je(n,d).emit(e,t,...s)}),`$on."${d}" of state "${u}"`)})};return e.addEventListener(c,h),Ye.set(t,{eventName:c,handler:h}),!0}class Ze extends He{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==Ie&&Ie({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}function tn(t){return t instanceof Ze}const en=new Map,nn=We();function on(t){const e=t.propModifiers.filter(t=>t===i||t===a).sort().join(",");return`${t.stateName}::${t.statePathName}::${e}`}const sn=(t,e,n,o)=>s=>{n.includes(i)&&s.preventDefault(),n.includes(a)&&s.stopPropagation();const r=s.target,l=Br(r.getRootNode(),t);null===l&&et(`State element with name "${t}" not found for event handler.`);const c=Vt(r),d=e.startsWith(A+".");l.createStateAsync("writable",async n=>{Ve(n[Xt](c,()=>{const r=null!==c?ge(c.listIndex,c.pathInfo.wildcardCount):[];if(d){const t=n[Yt](Oe(o,null));return tn(t)||et(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),t.emit(s,...r)}const i=n[e];return"function"!=typeof i&&et(`Handler "${e}" is not a function on state "${t}".`),Reflect.apply(i,n,[s,...r])}),`"${e}" of state "${t}"`)})};function rn(t){if(!t.propName.startsWith(h))return!1;const e=on(t);let n=en.get(e);void 0===n&&(n=sn(t.stateName,t.statePathName,t.propModifiers,t.statePathInfo),en.set(e,n));const o=t.propName.slice(2);return t.node.addEventListener(o,n),nn.add(e,t),!0}const an=new Map,ln=We();function cn(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function dn(t){let e="input";for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function un(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const s=dn(t),r=cn(t,s);let i=an.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==s.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===s.checked)return;let r=s.value;for(const t of o)r=t.filterFn(r);const i=Br(s.getRootNode(),e);null===i&&et(`State element with name "${e}" not found for two-way binding.`);const a=Vt(s);i.createState("writable",t=>{t[Xt](a,()=>{t[n]=r})})},an.set(r,i)),t.node.addEventListener(s,i),ln.add(r,t),!0}var e,n,o;return!1}const fn=new Set(["radio","checkbox"]),hn=new Set(["value","valueAsNumber","valueAsDate"]);function pn(t,e){if(t.nodeType!==Node.ELEMENT_NODE)return!1;const n=t,o=n.tagName.toLowerCase();if("input"===o){const t=(n.getAttribute("type")||"text").toLowerCase();if("button"===t)return!1;if(fn.has(t)&&"checked"===e)return!0;if(hn.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=G(n);if(null!==s){const t=K()?.get(s);void 0===t&&et(`Custom element <${s}> is not defined. Cannot determine if property "${e}" is suitable for two-way binding.`);const o=X(n);if(o?.knownProperties.has(e))return!0}return!1}let mn=1,gn=1,yn=1;const bn=new WeakMap;function wn(t,e,n,o){let s=bn.get(t);void 0===s&&(s=new Map,bn.set(t,s));const r=function(t,e,n){return`${e}::${n}::${t}`}(e,n,o);let i=s.get(r);return void 0===i&&(i=mn++,s.set(r,i)),i}function vn(t,e){return"to-element"===e?2*t:2*t+1}const Nn=new Set;function Sn(t){return{transactionId:gn++,originBindingId:t,visitedEdges:Nn,hop:0}}function In(t,e){const n=new Set(t.visitedEdges);return n.add(e),{transactionId:t.transactionId,originBindingId:t.originBindingId,visitedEdges:n,hop:t.hop+1}}let xn=null;function $n(){return xn}function Pn(t,e){const n=xn;xn=t;try{return e()}finally{xn=n}}const _n=[];let An=!1;const kn=new Map,Cn=We(),En=new WeakMap,Mn=t=>t.detail;function Tn(t,e,n,o){const s=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${s}::${n?"g":"n"}::${o?"o":"s"}`}function On(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";const n=G(t.node);if(null!==n){const o=K()?.get(n);void 0===o&&et(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=X(t.node)?.knownProperties.get(t.propName);s&&(e=s.event)}for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function Rn(t){if(null!==G(t.node)){const e=X(t.node)?.knownProperties.get(t.propName);if(e)return e.getter??Mn}return null}function Dn(t){if(null===G(t.node))return!1;const e=X(t.node)?.knownProperties.get(t.propName);return"event"===e?.semantics}const Ln=(t,e,n,o,s,r)=>i=>{const a=i.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(i);else{if(!(e in a))return void console.warn(`[@wcstack/state] Property "${e}" does not exist on target element.`);l=a[e]}let c=l;for(const t of o)c=t.filterFn(c);const d=En.get(a)?.get(e);if(void 0!==d)for(const t of d)t(c);let u=null;{const o=wn(a,e,t,n),s=function(t,e){for(let n=_n.length-1;n>=0;n--){const o=_n[n];if(o.node===t&&o.receipt.member===e)return o.receipt}return null}(a,e);if(null!==s&&Object.is(s.writtenValue,l))return void(null!==Ie&&Ie({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:vn(o,"to-state"),node:a,member:e}));const r=vn(o,"to-state"),i=$n();if(null!==i&&i.visitedEdges.has(r))return void(null!==Ie&&Ie({type:"propagation:suppressed",reason:"visited-edge",transactionId:i.transactionId,edgeId:r,node:a,member:e}));u=In(i??Sn(o),r)}const f=Br(a.getRootNode(),t);null===f&&et(`State element with name "${t}" not found for two-way binding.`);const h=Vt(a),p=()=>{r&&(An=!0);try{f.createState("writable",t=>{t[Xt](h,()=>{t[n]=c})})}finally{r&&(An=!1)}};null!==u?Pn(u,p):p()};const Wn=new WeakMap;function jn(t,e){const n=Wn.get(t);return n?n.get(e)??null:null}const Bn=new WeakMap;function Fn(t,e){Bn.set(t,e)}function zn(t){return Bn.get(t)??null}function qn(t){let e=t;for(;;){if(null==e||!0!==e.hasMappedComponentState)return null;const t=e.boundComponent;if(null==t)return null;const n=Vt(t)?.listIndex;if(null!=n)return n;e=zn(t)}}function Un(t){return qn(t)?.length??0}function Vn(t,e){return e.wildcardCount+Un(t)}function Hn(t,e){return e??qn(t)}const Gn=new WeakMap,Kn=new WeakMap,Jn=new WeakMap,Xn=new WeakMap;function Yn(t,e){return{innerAbsPathInfo:se(t,U(e.propSegments.slice(1).join(n))),outerAbsPathInfo:Ne(e).absolutePathInfo}}function Qn(t,e,o=!0){let s=Gn.get(t);if(void 0===s&&(s=new Map,Gn.set(t,s)),s.has(e))return s.get(e);let r=Kn.get(t);void 0===r&&(r=new Map,Kn.set(t,r));const i=Jn.get(t);if(void 0===i)return null;let a=null;for(const t of i)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&et("Duplicate mapping rule for web component."),a=t;break}if(null===a)return null;const l=Xn.get(a);void 0===l&&et("Binding not found for primary mapping rule on web component.");const c=e.pathInfo.segments.slice(a.innerAbsPathInfo.pathInfo.segments.length),d=U(a.outerAbsPathInfo.pathInfo.segments.concat(c).join(n)),u=Br(t.getRootNode(),l.stateName);null===u&&et(`State element with name "${l.stateName}" not found for web component.`);const f=se(u,d);if(!o)return f;s.set(e,f),r.set(f,e);const h=[l.propSegments[0],...e.pathInfo.segments],p={...l,propName:h.join(n),propSegments:h,statePathName:f.pathInfo.path,statePathInfo:f.pathInfo},m=Lo(l);return null===m||f.pathInfo.wildcardCount>0&&null===be(p)||m.initialize([p],{registerAddress:!0}),f}function Zn(t,e){const n=to(t,e);if(null===n||n.stateElement===t)return null;return Vn(t,e)!==Vn(n.stateElement,n.pathInfo)?null:n}function to(t,e){if(!0!==t.hasMappedComponentState)return null;const n=t.boundComponent;if(null==n)return null;return Qn(n,se(t,e),!1)}const eo=new WeakSet;function no(t){eo.add(t)}function oo(t){return!!eo.has(t)&&(eo.delete(t),!0)}const so=new WeakSet;function ro(t){so.add(t)}function io(t){return!!so.has(t)&&(so.delete(t),!0)}let ao=0;function lo(){ao--}function co(){return ao>0}class uo{registry;entries=new Map;constructor(t){this.registry=t}wait(t,e,n=()=>{}){const o=t.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),t=>this.settle(o,t)));const r={active:!0,resolve:e,reject:n};return s.waiters.add(r),()=>{r.active&&(r.active=!1,s?.waiters.delete(r))}}pendingCount(t){return this.entries.get(t.toLowerCase())?.waiters.size??0}settle(t,e){const n=this.entries.get(t);if(void 0===n)return;this.entries.delete(t);const o=Array.from(n.waiters);n.waiters.clear();for(const t of o)t.active&&(t.active=!1,null===e?t.resolve():t.reject(e))}}const fo=new WeakMap;function ho(t){let e=fo.get(t);return void 0===e&&(e=new uo(t),fo.set(t,e)),e}function po(t,e){let n=null;for(const o of t.propModifiers){const t=o.indexOf("=");if(t<0)continue;const s=o.slice(0,t).trim(),r=o.slice(t+1).trim();s!==c&&s!==d&&et(`Unknown binding modifier "${s}" in "${o}".`),s===e&&(null!==n&&et(`Binding modifier "${e}" may only be specified once.`),n=r)}return n}const mo=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),go=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function yo(t,e){return"state"===t&&"call"===e?mo:{authority:t,syncOn:e,observable:!1,outputOnly:!1}}function bo(t){const e=null===(n=po(t,c))?null:"state"===n||"element"===n||"auto"===n||"none"===n?n:et(`Invalid init modifier value "${n}".`);var n;const o=function(t){return null===t||"call"===t?"call":"connect"===t?"connect":et(`Invalid sync modifier value "${t}".`)}(po(t,d));if("event"===t.bindingType)return null!==e&&"none"!==e&&et("Event bindings only allow init=none."),"call"===o?go:{authority:"none",syncOn:o,observable:!1,outputOnly:!1};if(t.propSegments[0]===m)return yo("state",o);if("prop"!==t.bindingType)return null!==e&&"state"!==e&&"none"!==e&&et(`Binding type "${t.bindingType}" does not support init=${e}.`),yo(e??"state",o);const s=X(t.node);if(null===s)return yo(e??"state",o);const r=s.knownProperties.has(t.propName),i=s.declaredInputs.has(t.propName);r||i||et(`Property "${t.propName}" is not declared by wcBindable.`);const a=e??(r&&!i?"element":"state");return(r&&i?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(a)||et(`init=${a} is incompatible with wcBindable member "${t.propName}".`),"connect"!==o||r||et(`sync=connect requires observable property "${t.propName}".`),{authority:a,syncOn:o,observable:r,outputOnly:r&&!i}}function wo(t,e){return"auto"!==e?e:function(t){const e=Br(t.replaceNode.getRootNode(),t.stateName);null===e&&et(`State element with name "${t.stateName}" not found for binding.`);const n=De(t);let o=!1;return e.createState("readonly",t=>{o=t[Qt](n)}),o}(t)?"state":"element"}let vo=0,No=0;const So=new WeakMap,Io=new WeakMap,xo=new WeakMap,$o=new WeakMap;function Po(t,e){const n=$o.get(t);void 0!==n?n!==e&&(n instanceof Set?n.add(e):$o.set(t,new Set([n,e]))):$o.set(t,e)}function _o(t,e){const n=$o.get(t);if(void 0!==n)if(n instanceof Set)for(const t of Array.from(n))e(t);else e(n)}function Ao(t,e){if(e(t),null!==t.firstChild)for(const n of Array.from(t.childNodes))Ao(n,e)}function ko(t){if("object"!=typeof t||null===t)return!1;const e=t;return 9===e.nodeType||11===e.nodeType&&"host"in e}class Co{root;observer;constructor(t){this.root=t;const e=globalThis.MutationObserver;this.observer="function"==typeof e?new e(t=>this.handleMutations(t)):null,this.observer?.observe(t,{childList:!0,subtree:!0})}handleMutations(t){const e=[],n=[];for(const o of t)e.push(...Array.from(o.removedNodes)),n.push(...Array.from(o.addedNodes));const o=[];for(const t of e)oo(t)||Ao(t,t=>{_o(t,e=>{this.root.contains(t)||e.handleRemovedNode(t)})});for(const t of n)io(t)&&!co()||Ao(t,t=>{_o(t,e=>{this.root.contains(t)&&e.handleAddedNode(t,o)})});o.length>0&&tr(o)}}const Eo=new WeakMap;function Mo(t){let e=Eo.get(t);return void 0===e&&(e=new Co(t),Eo.set(t,e)),e}function To(t){const e=t.inFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|"),n=t.outFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|");return[t.bindingType,t.propName,t.propModifiers.join(","),t.stateName,t.statePathName,e,n,t.uuid??""].join("\0")}function Oo(t,e){null===t.teardowns&&(t.teardowns=new Set),t.teardowns.add(e)}class Ro{records=new Set;rowPlan=null;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(t=null){null!==t&&this.observe(t)}initialize(t,e={},n){const o=e.registerAddress??!0,s={registerAddress:o,registerPathInfo:e.registerPathInfo??o,applyOnReconnect:e.applyOnReconnect??!0},r=[];for(const e of t){const t=this.remember(e,s),o=So.get(t);void 0===o||"disposed"===o.phase||"failed"===o.phase?(this.start(t,s,n),r.push(t)):(this.observe(o.anchor),s.registerAddress&&null===o.address&&null===o.patternListIndex&&(o.options.registerAddress=!0,this.registerAddress(o)),"active"===o.phase&&this.settleInitialRecord(o),this.settleConnectedSnapshot(o))}return r.filter(t=>this.shouldApplyState(t))}activate(t,e){if(ko(e)&&Mo(e),null===this.rowPlan)for(const n of t){const t=So.get(n);if(void 0!==t&&t.session===this&&"disposed"!==t.phase&&"failed"!==t.phase){null===t.address&&null===t.patternListIndex&&(t.options.registerAddress=!0,this.registerAddress(t,e)),"active"===t.phase&&this.settleInitialRecord(t),this.settleConnectedSnapshot(t);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,e)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,t,e)}shouldApplyState(t){const e=So.get(t);return void 0===e||e.session!==this||(!e.options.registerAddress||"waiting-definition"===e.phase||"failed"!==e.phase&&("active"===e.phase&&this.settleInitialRecord(e),e.initialApplyDone?"state"===e.resolvedAuthority||!e.outputOnlyMember&&!e.observationPending:(e.initialApplyDone=!0,"state"===e.resolvedAuthority)))}getRecord(t){const e=So.get(t);return e?.session===this?e:null}addTeardown(t,e){const n=So.get(t);return!(void 0===n||!this.isAlive(n,n.generation))&&(Oo(n,e),!0)}deferUntilDefined(t,e,n,o=()=>{}){const s=K();null===s&&et(`CustomElementRegistry is unavailable for <${e}>.`),this.observe(t),Po(t,this);const r={node:t,active:!0,cancel:null};let i=this.deferredByNode.get(t);void 0===i&&(i=new Set,this.deferredByNode.set(t,i)),i.add(r),this.deferred.add(r);const a=()=>!!r.active&&(r.active=!1,i?.delete(r),this.deferred.delete(r),!0);return r.cancel=ho(s).wait(e,()=>{if(a())try{J(s,t),n()}catch(t){o(t)}},t=>{a()&&o(t)}),()=>{a()&&r.cancel?.()}}disposeBinding(t){const e=So.get(t);void 0!==e&&e.session===this&&this.disposeRecord(e)}dispose(){for(const t of Array.from(this.records))this.disposeRecord(t);for(const t of Array.from(this.deferred))t.active=!1,t.cancel?.(),this.deferred.delete(t),this.deferredByNode.get(t.node)?.delete(t)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;for(const t of this.records)if(t.pendingDefinitions>0||t.observationPending)return!1;return!0}destroyRecords(){for(const t of this.records)null!==t.address&&(Pe(t.address,t.info),t.address=null),t.phase="disposed",t.teardowns=null;this.records.clear()}observe(t){const e=function(t){const e=t.getRootNode();return ko(e)?e:null}(t);null!==e&&Mo(e)}handleMutations(t,e,n){for(const n of e)Ao(n,e=>{t.contains(e)||this.handleRemovedNode(e)});const o=[];for(const e of n)Ao(e,e=>{t.contains(e)&&this.handleAddedNode(e,o)});o.length>0&&tr(o)}handleRemovedNode(t){const e=this.knownBindingsByNode.get(t);if(void 0!==e)if(e instanceof Map)for(const t of e.values())this.disposeBinding(t);else this.disposeBinding(e);const n=this.deferredByNode.get(t);if(void 0!==n)for(const t of Array.from(n))t.active=!1,t.cancel?.(),n.delete(t),this.deferred.delete(t)}handleAddedNode(t,e){const n=this.knownBindingsByNode.get(t);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const t of o){const n=So.get(t);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(t);if(void 0!==o)try{this.start(t,o),o.applyOnReconnect&&this.shouldApplyState(t)&&e.push(t)}catch{}}}knownMapFor(t){const e=this.knownBindingsByNode.get(t);if(e instanceof Map)return e;const n=new Map;if(void 0!==e){let t=xo.get(e);void 0===t&&(t=To(e),xo.set(e,t)),n.set(t,e)}return this.knownBindingsByNode.set(t,n),n}remember(t,e){const n=t.replaceNode;Po(n,this);const o=this.knownMapFor(n);let s=xo.get(t);void 0===s&&(s=To(t),xo.set(t,s));const r=o.get(s);if(void 0!==r){const t=this.optionsByBinding.get(r);return void 0!==t&&(t.registerAddress||=e.registerAddress,t.registerPathInfo||=e.registerPathInfo,t.applyOnReconnect||=e.applyOnReconnect),r}return o.set(s,t),this.optionsByBinding.set(t,{...e}),t}initializeRow(t,e){this.rowPlan=t;const n={registerAddress:!1,registerPathInfo:!1,applyOnReconnect:!1},o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=o[t],i=s.replaceNode;Po(i,this),this.addKnownRowBinding(i,s,t),this.optionsByBinding.set(s,n);const a={id:++vo,info:s,generation:++No,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest:null,pendingDefinitions:0,initialPolicy:r.policy,resolvedAuthority:r.authority,initialSettled:!0,initialApplyDone:!1,outputOnlyMember:r.policy.outputOnly,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};if(So.set(s,a),this.records.add(a),r.isEvent){try{rn(s)}catch(t){throw a.phase="failed",this.runTeardowns(a),this.records.delete(a),t}a.eventAttached=!0}}}activatePlanRows(t,e,n){const o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=So.get(s);if(void 0!==r&&r.session===this){if(r.options.registerAddress=!0,"disposed"===r.phase||"failed"===r.phase){const e=o[t];if(r.generation=++No,r.phase="active",r.initialPolicy=e.policy,r.resolvedAuthority=e.authority,r.initialSettled=!0,r.initialApplyDone=!1,r.outputOnlyMember=e.policy.outputOnly,this.records.add(r),e.isEvent){try{rn(s)}catch(t){throw r.phase="failed",this.runTeardowns(r),this.records.delete(r),t}r.eventAttached=!0}this.registerAddress(r,n);continue}null===r.address&&null===r.patternListIndex&&this.registerAddress(r,n)}else this.initialize([s],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}}addKnownRowBinding(t,e,n){const o=this.knownBindingsByNode.get(t);if(void 0===o)return void this.knownBindingsByNode.set(t,e);if(o instanceof Map)return void o.set("@plan:"+n,e);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,e),this.knownBindingsByNode.set(t,s)}start(t,e,n){!function(t){const e=t.node,n=t.replaceNode;e!==n&&null!==e.parentNode&&e.parentNode.replaceChild(n,e)}(t);const o=this.optionsByBinding.get(t)??{...e},s={id:++vo,info:t,generation:++No,phase:"discovered",teardowns:null,session:this,anchor:t.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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};So.set(t,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(t){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),t}}attachListeners(t){const e=t.info;rn(e)?t.eventAttached=!0:e.propSegments[0]!==p?(un(e)&&Oo(t,()=>function(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const e=dn(t),n=cn(t,e),o=an.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==ln.countOf(n)&&(ln.remove(n,t)&&an.delete(n),!0))}return!1}(e)),qe(e)&&Oo(t,()=>function(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const e=ze(t),n=Fe(t,e),o=je.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==Be.countOf(n)&&(Be.remove(n,t)&&je.delete(n),!0))}return!1}(e)),this.attachAfterDefinition(t,()=>{if(pn(e.node,e.propName)&&-1===e.propModifiers.indexOf(l)){const n=function(t,e,n){let o=En.get(t);void 0===o&&(o=new Map,En.set(t,o));let s=o.get(e);return void 0===s&&(s=new Set,o.set(e,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(e),0===o?.size&&En.delete(t)}}(e.node,e.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});Oo(t,n)}!function(t){const e=G(t.node);if(null!==e){const t=K(),n=t?.get(e);if(void 0===n)return void(null===t&&et(`CustomElementRegistry is unavailable for <${e}>.`))}if(pn(t.node,t.propName)&&-1===t.propModifiers.indexOf(l)){const e=On(t),n=Rn(t),o=Dn(t),s=Tn(t,e,null!==n,o);let r=kn.get(s);void 0===r&&(r=Ln(t.stateName,t.propName,t.statePathName,t.inFilters,n,o),kn.set(s,r)),t.node.addEventListener(e,r),Cn.add(s,t)}}(e),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{Qe(e)&&Oo(t,()=>function(t){if(t.propSegments[0]!==p)return!1;const e=Ye.get(t);return void 0!==e&&(t.node.removeEventListener(e.eventName,e.handler),Ye.delete(t),!0)}(e))})}attachAfterDefinition(t,e){const n=G(t.info.node);if(null===n)return void e();const o=K();if(null===o&&et(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void e();t.phase="waiting-definition",t.pendingDefinitions+=1;const s=t.generation,r=ho(o).wait(n,()=>{if(this.isAlive(t,s))try{J(o,t.info.node),e(),t.pendingDefinitions-=1,0===t.pendingDefinitions&&(t.phase="active",this.settleInitialRecord(t))}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}},()=>{this.isAlive(t,s)&&(t.phase="failed",this.runTeardowns(t),this.records.delete(t))});Oo(t,r)}settleInitialRecord(t){if(!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=bo(t.info),n=wo(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 ao++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(t,e){if(!this.isAlive(t,t.generation))return;const n=t.info.node,o=t.info.propName;if(!(o in n))return;const s=t.eventSequence,r=n[o];t.observationPending&&(t.observationPending=!1,lo()),e&&t.eventSequence!==s||(t.hasProducerValue=!0,t.producerValue=r,"element"===t.resolvedAuthority&&function(t,e){let n=e;for(const e of t.inFilters)n=e.filterFn(n);const o=Br(t.node.getRootNode(),t.stateName);null===o&&et(`State element with name "${t.stateName}" not found for initial binding sync.`);const s=Vt(t.node);o.createState("writable",e=>{e[Xt](s,()=>{e[t.statePathName]=n})})}(t.info,r))}settleConnectedSnapshot(t){if(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(t,e){if(null!==t.address||null!==t.patternListIndex)return;const n=t.info,o=be(n);if(null!==o){const i=Br(ve(n,e),n.stateName);null===i&&et(`State element with name "${n.stateName}" not found for binding.`);const a=se(i,n.statePathInfo);Ae(a,o,n),t.patternPathInfo=a,t.patternListIndex=o;const l=(s=i,0===(r=n.statePathInfo).wildcardCount?null:Zn(s,r));if(null!==l){Ae(l,o,n),t.outerPatternPathInfo=l;const e=function(t){let e=null,n=t.stateElement,o=t.pathInfo;for(;;){const t=Zn(n,o);if(null===t)return e;(e??=[]).push(t),n=t.stateElement,o=t.pathInfo}}(l);if(null!==e){for(let t=0;t<e.length;t++)Ae(e[t],o,n);t.outerPatternPathInfosRest=e}}}else{const o=Ne(n,e);$e(o,n),t.address=o}var s,r;if(!t.options.registerPathInfo)return;const i=Br(n.replaceNode.getRootNode(),n.stateName);null===i&&et(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&i.setPathInfo(n.statePathName,n.bindingType)}isAlive(t,e){return t.generation===e&&So.get(t.info)===t&&"disposed"!==t.phase&&"failed"!==t.phase}disposeRecord(t){"disposed"!==t.phase&&(t.phase="disposed",this.runTeardowns(t),this.records.delete(t))}runTeardowns(t){t.observationPending&&(t.observationPending=!1,lo());const e=t.info;if(null!==t.address)try{Pe(t.address,e),t.address=null,Le(e),Se(e)}catch{}else if(null!==t.patternListIndex){if(null!==t.outerPatternPathInfo){try{ke(t.outerPatternPathInfo,t.patternListIndex,e)}catch{}t.outerPatternPathInfo=null}if(null!==t.outerPatternPathInfosRest){const n=t.outerPatternPathInfosRest;for(let o=0;o<n.length;o++)try{ke(n[o],t.patternListIndex,e)}catch{}t.outerPatternPathInfosRest=null}try{ke(t.patternPathInfo,t.patternListIndex,e),t.patternPathInfo=null,t.patternListIndex=null,Le(e),Se(e)}catch{}}if(t.twowayAttached){t.twowayAttached=!1;try{!function(t){const e=G(t.node);if(null!==e){const t=K(),n=t?.get(e);if(void 0===n)return}if(pn(t.node,t.propName)&&-1===t.propModifiers.indexOf(l)){const e=On(t),n=Tn(t,e,null!==Rn(t),Dn(t)),o=kn.get(n);if(void 0===o)return;t.node.removeEventListener(e,o),Cn.remove(n,t)&&kn.delete(n)}}(e)}catch{}}if(null!==t.teardowns){const e=Array.from(t.teardowns).reverse();t.teardowns=null;for(const t of e)try{t()}catch{}}if(t.eventAttached){t.eventAttached=!1;try{!function(t){if(!t.propName.startsWith(h))return!1;const e=on(t),n=en.get(e);if(void 0===n)return!1;const o=t.propName.slice(2);t.node.removeEventListener(o,n),0!==nn.countOf(e)&&(nn.remove(e,t)&&en.delete(e))}(e)}catch{}}}}function Do(t){let e=Io.get(t);return void 0===e&&(e=new Ro(t),Io.set(t,e)),e}function Lo(t){return So.get(t)?.session??null}const Wo=new WeakMap;function jo(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Bo=Object.freeze([]);const Fo=new WeakMap;const zo=new WeakMap;function qo(t){return zo.get(t)??[]}function Uo(t,e){zo.set(t,e)}Set.prototype.difference||(Set.prototype.difference=function(t){const e=new Set(this);for(const n of t)e.delete(n);return e}),Set.prototype.intersection||(Set.prototype.intersection=function(t){const e=new Set;for(const n of t)this.has(n)&&e.add(n);return e});let Vo=0;function Ho(){return`u${(Vo++).toString(36)}`}let Go=0;class Ko{uuid=Ho();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;constructor(t,e){this.parentListIndex=t,this.position=t?t.position+1:0,this.length=this.position+1,this._index=e,this._version=Go}get index(){return this._index}set index(t){this._index=t,this._version=++Go,this.indexes[this.position]=t}get version(){return this._version}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=Go),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0===this._listIndexes&&(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)]),this._listIndexes}get varName(){return`$${this.position+1}`}at(t){return t>=0?this.listIndexes[t]?.deref()||null:this.listIndexes[this.listIndexes.length+t]?.deref()||null}}function Jo(t,e){return new Ko(t,e)}const Xo=new WeakMap;function Yo(t){return Xo.get(t)||null}function Qo(t,e){null!==e?Xo.set(t,e):Xo.delete(t)}const Zo=new WeakMap,ts=Object.freeze([]),es=new Set;function ns(t,e,n){const o=function(t,e,n){const o=Array.isArray(e)&&e.length>0?e:ts,s=Array.isArray(n)&&n.length>0?n:ts,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:ts,o=Array.isArray(e)&&e.length>0?e:ts;let s=Zo.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=Yo(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:es,deleteIndexSet:new Set(i),addIndexSet:es};let e=Yo(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=Jo(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:es,deleteIndexSet:es,addIndexSet:new Set(e)}}if(function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(o,s))return a={oldIndexes:i,newIndexes:i,changeIndexSet:es,deleteIndexSet:es,addIndexSet:es};if(null!==e)return function(t,e){const n=new Set(e),o=new Set(t),s=new Set,r=n.difference(o),i=o.difference(n),a=new Map;for(let e=0;e<t.length;e++)a.set(t[e],e);for(let t=0;t<e.length;t++){const n=e[t];r.has(n)||a.get(n)!==t&&s.add(n)}return{oldIndexes:t,newIndexes:e,changeIndexSet:s,deleteIndexSet:i,addIndexSet:r}}(i,e);e=[];const n=new Map;for(let t=0;t<o.length;t++){const e=o[t];let s=n.get(e);s||(s=[],n.set(e,s)),s.push(t)}const r=new Set,l=new Set;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),d=c&&c.length>0?c.shift():void 0;if(void 0===d){const n=Jo(t,o);e.push(n),l.add(n)}else{const t=i[d];d!==o&&r.add(t),e.push(t)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(e)),addIndexSet:l}}finally{void 0!==a&&(!function(t,e,n){let o=Zo.get(t);o||(o=new WeakMap,Zo.set(t,o)),o.set(e,n)}(o,s,a),Qo(s,a.newIndexes))}}(t,e,n);return function(t){for(let e=0;e<t.length;e++)t[e].index!==e&&(t[e].index=e)}(o.newIndexes),o}function os(t){if(0===t.changeIndexSet.size||t.addIndexSet.size===t.newIndexes.length)return null;const e=new Map;for(let n=0;n<t.oldIndexes.length;n++)e.set(t.oldIndexes[n],n);const n=[],o=[];let s=-1,r=!0;for(const i of t.newIndexes){if(t.addIndexSet.has(i))continue;const a=e.get(i);if(void 0===a)return null;a<s&&(r=!1),s=a,n.push(i),o.push(a)}if(r)return null;const i=function(t){const e=t.length,n=[],o=new Array(e).fill(-1);for(let s=0;s<e;s++){const e=t[s];let r=0,i=n.length;for(;r<i;){const o=r+i>>1;t[n[o]]<e?r=o+1:i=o}r>0&&(o[s]=n[r-1]),n[r]=s}const s=[];let r=n.length>0?n[n.length-1]:-1;for(;r>=0;)s.push(r),r=o[r];return s.reverse(),s}(o),a=new Set;for(const t of i)a.add(n[t]);return a}const ss=new WeakMap;function rs(t){return ss.get(t)??[]}function is(t,e){ss.set(t,e)}const as=new WeakMap;function ls(t){return as.get(t)??null}function cs(t,e){as.set(t,e)}const ds=new WeakMap;function us(t){return ds.get(t)??[]}function fs(t,e){ds.set(t,e)}function hs(t,e){const n=us(t);for(const t of n)Ht(t,e)}function ps(t,e,n){hs(t,e);const o=rs(t),s=ls(t);null!==s&&s.activate(o,n.rootNode);for(const t of o){if(null===s){$e(Ne(t),t)}(null===s||s.shouldApplyState(t))&&Zs(t,n)}}function ms(t){if(!t.mounted)return;const e=rs(t),n=ls(t);for(const t of e)if(null!==n)n.disposeBinding(t);else{Pe(Ne(t),t)}!function(t){const e=us(t);for(const t of e)Ht(t,null)}(t)}const gs=new WeakMap,ys=Object.freeze(new Set);function bs(t,e){const n=gs.get(t);n?n.add(e):gs.set(t,new Set([e]))}function ws(t){const e=gs.get(t);return void 0!==e?e:ys}function vs(t,e){const n=gs.get(t);n&&(n.delete(e),0===n.size&&gs.delete(t))}const Ns=new Set(["if","elseif","else","for"]);class Ss{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(t,e=!1){this._content=t,this._ranged=e,this._childNodeArray=Array.from(this._content.childNodes),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(t){for(const e of this._childNodeArray)ro(e),t.appendChild(e);this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const t=this._firstNode,e=this._lastNode;if(null===t||null===e||null===t.parentNode)return this._childNodeArray;const n=[];for(let o=t;null!==o;o=o.nextSibling)if(n.push(o),o===e)return n;return this._childNodeArray}mountAfter(t){const e=t.parentNode;if(e){let n=t;for(const t of this._movableNodes())n.nextSibling!==t&&(ro(t),e.insertBefore(t,n.nextSibling)),n=t}this._mounted=!0}tryDestroy(){const t=ls(this);if(null===t||!t.canWholesaleDestroy())return!1;t.destroyRecords();for(const t of this._childNodeArray)no(t),null!==t.parentNode&&t.parentNode.removeChild(t);const e=rs(this);for(const t of e)if(Ns.has(t.bindingType)){const e=ws(t.node);for(const t of e)t.tryDestroy()||t.unmount()}return this._mounted=!1,!0}unmount(){ls(this)?.dispose();for(const t of this._childNodeArray)no(t),null!==t.parentNode&&t.parentNode.removeChild(t);const t=rs(this);for(const e of t){if(Ns.has(e.bindingType)){const t=ws(e.node);for(const e of t)e.unmount()}Le(e),Se(e)}this._mounted=!1}}function Is(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 xs(t){const e=document.createDocumentFragment(),n=new Ss(e);return n._childNodeArray=t,n._firstNode=t.length>0?t[0]:null,n._lastNode=t.length>0?t[t.length-1]:null,n._mounted=!0,n}function $s(t,e,n){const o=document.importNode(e.fragment,!0),s=e.nodeInfos,r=new Array(s.length);for(let t=0;t<s.length;t++){const e=st(o,s[t].nodePath);null===e&&et(`Node not found by path [${s[t].nodePath.join(", ")}] in fragment.`),zt(e),F(e),r[t]=e}const i=n.slots,a=new Array(i.length),l=[];for(let t=0;t<i.length;t++){const e=i[t],n=r[e.nodeIndex],o={...e.template,node:n,replaceNode:n};a[t]=o,e.isIndexBinding&&l.push(o)}const c=function(t,e){const n=new Ro;return n.initializeRow(t,e),n}(n,a),d=new Ss(o);return cs(d,c),is(d,a),Uo(d,l),fs(d,r),bs(t.node,d),d}function Ps(n){void 0!==n.uuid&&null!==n.uuid||et("BindingInfo.uuid is null.");const o=Tt(n.uuid);o||et(`Fragment with UUID "${n.uuid}" not found.`);const s=!t()&&Is(o);let r=o.rowPlan;if((void 0===r||null!==r&&r.directional!==e.enableDirectionalInitialSync)&&(r=o.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],r=st(t.fragment,n.nodePath);if(null===r)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===p)return null;if("text"===n){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==G(r))return null;if("prop"===n&&pn(r,t.propName))return null;let i;try{i=bo({...t,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;o.push({nodeIndex:e,template:t,isEvent:"event"===n,isIndexBinding:t.statePathName in v,policy:i,authority:i.authority})}}return{directional:n,slots:o}}(o)),null!==r)return $s(n,o,r);const i=document.importNode(o.fragment,!0),a=function(t,e){const[n,o]=function(t,e){const n=[],o=[];for(const s of e){const e=st(t,s.nodePath);if(null===e&&et(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),jt.has(e))continue;const r=Bt(e,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(e)}return[n,o]}(t,e),s=new Ro,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,o.nodeInfos);s&&function(t,e){t.appendChild(document.createComment(`wcs-row-end:${e}`))}(i,n.uuid);const l=new Ss(i,s);cs(l,a.bindingSession),is(l,a.bindingInfos);const c=[];for(const t of a.bindingInfos)t.statePathName in v&&c.push(t);return Uo(l,c),fs(l,a.nodes),bs(n.node,l),l}const _s=new WeakMap,As=new WeakMap,ks=new WeakMap,Cs=new WeakMap;function Es(t,e,n){!function(t,e,n){let o=As.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,As.set(t,o)}null===n?o.delete(e):o.set(e,n)}(t,e,n)}function Ms(t,e){_s.set(t,e)}function Ts(t,e){let n=ks.get(t.node);void 0===n&&(n=[],ks.set(t.node,n)),n.length<1e3?n.push(e):vs(t.node,e)}function Os(t,e){if(null===e)return!1;if(t.nextSibling===e)return!0;const n=t.compareDocumentPosition(e);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}function Rs(e,n,o){const s=Boolean(o);let r;const i=ws(e.node);r=0===i.size?Ps(e):i.values().next().value;const a=t(),l=e.uuid??"",c=e.bindingType;if(s||(ms(r),r.unmount()),s){if(a){const t=document.createComment(`@@wcs-${c}-start:${l}:${e.statePathName}`);e.node.parentNode.insertBefore(t,e.node.nextSibling),r.mountAfter(t);const n=document.createComment(`@@wcs-${c}-end:${l}:${e.statePathName}`),o=r.lastNode??t;o.parentNode.insertBefore(n,o.nextSibling)}else r.mountAfter(e.node);ps(r,Vt(e.node),n)}}const Ds=new WeakMap;function Ls(t){return Ds.get(t)??[]}const Ws=new Set;const js={value(t,e){"TEXTAREA"===t.tagName?t.textContent=String(e??""):t.setAttribute("value",String(e??""))},checked(t,e){e?t.setAttribute("checked",""):t.removeAttribute("checked")},selected(t,e){e?t.setAttribute("selected",""):t.removeAttribute("selected")},disabled(t,e){e?t.setAttribute("disabled",""):t.removeAttribute("disabled")},selectedIndex(t,e){const n=t.querySelectorAll("option"),o=Number(e);for(let t=0;t<n.length;t++)t===o?n[t].setAttribute("selected",""):n[t].removeAttribute("selected")}};function Bs(e,n,o){if(void 0===o)return;const s=e.node,r=e.propSegments;if(1===r.length){const a=r[0];if(s[a]!==o){const t=()=>{let t=!1;try{s[a]=o,t=!0}catch(t){}if(t){const t=function(t,e){const n=G(t);if(null===n)return null;const o=K()?.get(n);if(void 0===o)return null;const s=X(t)?.declaredInputs.get(e);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(s,a);if(null!==t)try{!function(t,e,n){if(null==n)return void t.removeAttribute(e);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);t.setAttribute(e,o)}(s,t,o)}catch(t){}}};if(pn(s,a)){const r=wn(s,a,e.stateName,e.statePathName),i=vn(r,"to-element"),l=n?.propagationContextByBinding?.get(e)??$n()??Sn(r);if(l.visitedEdges.has(i))null!==Ie&&Ie({type:"propagation:suppressed",reason:"visited-edge",transactionId:l.transactionId,edgeId:i,node:s,member:a});else{const e=In(l,i);Pn(e,()=>function(t,e,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:e,transactionId:s,synchronousScopeId:yn++,writtenValue:n};_n.push({receipt:i,node:t});try{return r()}finally{_n.pop()}}(s,a,o,r,e.transactionId,t))}}else t()}if(t()){const t=js[a];t?t(s,o):(!function(t,e,n){let o=Ds.get(t);o||(o=[],Ds.set(t,o));const s=o.find(t=>t.propName===e);s?s.value=n:o.push({propName:e,value:n})}(s,a,o),i=s,Ws.add(i))}return}var i;const a=r[0];let l=s[a];for(let t=1;t<r.length-1;t++){const e=r[t];if(null==l)return;l=l[e]}if(l[r[r.length-1]]!==o){if(Object.isFrozen(l))return;try{l[r[r.length-1]]=o}catch(t){}}}const Fs=new WeakSet;function zs(t,e,o){const s=t.node,r=t.propSegments;r.length<=1&&et(`Invalid propSegments for web component binding: ${r.join(n)}`);const[i,...a]=r,l=jn(s,i);null===l&&et(`State element not bound to "${i}" on web component.`),!1!==l.hasRootNode&&l.createState("readonly",t=>{t.$postUpdate(a.join(n))})}function qs(t,e){const n=De(e);if(n.pathInfo.path in v){const t=Vt(e.node);return null===t&&et(`ListIndex not found for binding: ${e.statePathName}`),function(t,e){null===t.listIndex&&et("ListIndex not found for loopContext:");const n=v[e];void 0===n&&et(`Invalid index name: ${e}`);const o=me(t.listIndex,n,t.pathInfo.wildcardCount);return null===o&&et(`Index not found at position ${n} for loopContext:`),o.index}(t,n.pathInfo.path)}return t[Yt](n)}const Us=new WeakSet;function Vs(t,e){console.error(`[@wcstack/state] deferred apply failed for <${t}>.`,e)}const Hs=Object.freeze({[g]:function(t,e,n){const o=t.node,s=t.propSegments[1];"boolean"!=typeof n&&et("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},[y]:function(t,e,n){const o=t.node,s=t.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},[b]:function(t,e,n){const o=t.propSegments[1],s=t.node.style;s[o]!==n&&(s[o]=n)},[m]:function(t,e,n){tn(n)||et("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Fo.get(t);if(s&&s.token===o)return;const r=t.node,i=t.propSegments[1];"string"==typeof i&&0!==i.length||et('command binding requires a method name (e.g., "command.fetch").');const a=function(t){const e=G(t);if(null===e)return null;const n=K()?.get(e);return void 0===n&&et(`Custom element <${e}> is not defined for command binding.`),X(t)}(r);null===a&&et(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||et(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.${lt(i,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),Fo.delete(t));const l=new WeakRef(r);let c=null;c=o.subscribe((...e)=>{const n=l.deref();if(!n||!n.isConnected)return c?.(),void Fo.delete(t);const o=n[i];return"function"!=typeof o&&et(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,e)}),Fo.set(t,{token:o,unsubscribe:c,elementRef:l})}}),Gs={text:function(e,n,o){const s=null==o?"":String(o);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),t()&&!Fs.has(e.replaceNode)){Fs.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,n,s){const r=e.statePathInfo,i=be(e),a=Ne(e),l=Kt(a),c=ns(Hn(n.stateElement,i),l,s);n.newListValueByAbsAddress.set(a,Array.isArray(s)?s:[]);const d=Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(d&&null!==e.node.parentNode){let t=Cs.get(e.node);if(void 0===t){const n=_s.get(e.node)||e.node;t=function(t,e){let n=t.previousSibling,o=e.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(e.node,n),Cs.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}let u=As.get(e.node),f=d?1e3-function(t){return ks.get(t.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const t of c.deleteIndexSet){const n=u.get(t);void 0!==n&&(f<=0&&n.tryDestroy()?vs(e.node,n):(ms(n),n.unmount(),Ts(e,n),f-=1),d||u.delete(t))}d&&(As.delete(e.node),u=void 0)}let h=e.node;const p=U(r.path+"."+o),m=n.stateElement.loopContextStack,g=os(c);let y=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&h.isConnected&&(y=document.createDocumentFragment(),ue(y,n.rootNode));const b=t(),w=e.uuid??"",v=ks.get(e.node);for(const t of c.newIndexes){let o;if(c.addIndexSet.has(t)){const s=Oe(p,t);m.createLoopContext(s,s=>{if(o=void 0!==v?v.pop():void 0,void 0===o&&(o=Ps(e)),null!==y)b&&y.appendChild(document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`)),o.appendTo(y),b&&y.appendChild(document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`));else{if(h.nextSibling!==o.firstNode){if(b){const e=document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`);h.parentNode.insertBefore(e,h.nextSibling),h=e}o.mountAfter(h)}if(b){const e=document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`),n=o.lastNode??h;n.parentNode.insertBefore(e,n.nextSibling)}}ps(o,s,n)}),void 0===o&&et(`Content not found for ListIndex: ${t.index} at path "${r.path}"`)}else{if(o=void 0!==u?u.get(t)??null:null,c.changeIndexSet.has(t)){const t=qo(o);for(const e of t)Zs(e,n)}null===o&&et(`Content not found for ListIndex: ${t.index} at path "${r.path}"`);const e=!o.mounted;if(null!==g&&g.has(t)&&Os(h,o.firstNode)||h.nextSibling===o.firstNode||o.mountAfter(h),e){const e=o,s=Oe(p,t);m.createLoopContext(s,t=>{ps(e,t,n)})}}h=o.lastNode||h,void 0===u&&(u=new WeakMap,As.set(e.node,u)),u.set(t,o)}_s.set(e.node,h),null!==y&&(e.node.parentNode.insertBefore(y,e.node.nextSibling),ue(y,null))},if:Rs,else:Rs,elseif:Rs,radio:function(t,e,n){const o=t.node,s=jo(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=jo(o.value,t.inFilters),r=Array.isArray(n)?n:Bo;o.checked=r.includes(s)}},Ks=new WeakMap,Js=new WeakMap,Xs=new WeakMap;function Ys(t){return t.propSegments.length>1&&(e=t.replaceNode,n=t.propSegments[0],!0===Wo.get(e)?.has(n));var e,n}function Qs(t,e){const n=jo(qs(e.state,t),t.outFilters);if(!0===Js.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=Ks.get(t);if(void 0===o){if(Ks.has(t))return Ys(t)?(o=zs,Ks.set(t,o)):o=Bs,void o(t,e,n);if(o=Gs[t.bindingType],void 0===o){const e=t.propSegments[0];if(o=Hs[e],Ks.set(t,o),void 0===o){G(t.replaceNode)?Ys(t)?(o=zs,Ks.set(t,o)):o=Bs:(o=Bs,Ks.set(t,o))}}if(o===Bs){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void Js.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function Zs(t,e){if(e.appliedBindingSet.has(t))return;if(e.appliedBindingSet.add(t),!1!==e.stateElement.hasUpdatedCallback){const n=Ne(t);if(e.updatedAbsAddressSetByStateElement.has(e.stateElement)){e.updatedAbsAddressSetByStateElement.get(e.stateElement).add(n)}else e.updatedAbsAddressSetByStateElement.set(e.stateElement,new Set([n]))}const n=Lo(t);if(null!==n&&!n.shouldApplyState(t))return;if("event"===t.bindingType)return;if(!0!==Xs.get(t)){const e=G(t.replaceNode);if(e&&void 0===K()?.get(e))return void function(t,e){if(Us.has(t))return;Us.add(t);const n=()=>{Us.delete(t);const e=Lo(t);(null===e||e.shouldApplyState(t))&&tr([t])},o=n=>{Us.delete(t),Vs(e,n)},s=Lo(t);if(null!==s){const r=s.deferUntilDefined(t.replaceNode,e,n,o);return void(s.addTeardown(t,()=>{Us.delete(t),r()})||(Us.delete(t),r()))}const r=K();if(null===r)return Us.delete(t),void Vs(e,new Error("CustomElementRegistry is unavailable."));ho(r).wait(e,()=>{t.replaceNode.isConnected?n():Us.delete(t)},o)}(t,e);Xs.set(t,!0)}if(!0===e.sameRootVerified&&t.stateName===e.stateName)return void Qs(t,e);let o=t.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=fe(o),null===o&&et("Root node for fragment not found for binding.")),t.stateName!==e.stateName||o!==e.rootNode){const n=Br(o,t.stateName);null===n&&et(`State element with name "${t.stateName}" not found for binding.`),n.createState("readonly",s=>{const r={stateName:t.stateName,rootNode:o,stateElement:n,state:s,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};Qs(t,r)})}else Qs(t,e)}function tr(t,e){let n=0;const o=new Set,s=new Map,r=new Map,i=[];for(;n<t.length;){let a=t[n];const l=a.stateName;if(!1===a.replaceNode.isConnected){n++;continue}let c=a.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=fe(c),null===c&&et("Root node for fragment not found for binding."));const d=Br(c,l);null===d&&et(`State element with name "${l}" not found for binding.`),d.createState("readonly",u=>{const f={rootNode:c,stateName:l,stateElement:d,state:u,appliedBindingSet:o,newListValueByAbsAddress:s,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:i,sameRootVerified:!0,propagationContextByBinding:e};for(;;){Zs(a,f),n++;const e=t[n];if(!e)break;const o=e.replaceNode.getRootNode();if(e.stateName!==l||o!==f.rootNode)break;a=e}})}for(const{binding:t,value:n}of i)Bs(t,{propagationContextByBinding:e},n);for(const[t,e]of s.entries())Jt(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[ne](Array.from(e))})}function er(t,e){const[n,o,s]=Ft(t),r=Do(t);for(const t of n)Ht(t,e);tr(r.initialize(o)),function(t,e,n){for(const o of t)n.deferUntilDefined(o.node,o.tagName,()=>{const t=qt(o);0!==t.length&&(Ht(o.node,e),tr(n.initialize(t)))},t=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,t)})}(s,e,r)}const nr=/\{\{\s*(.+?)\s*\}\}/g,or=new Set(["SCRIPT","STYLE"]);function sr(t){!function(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=[];for(;e.nextNode();)n.push(e.currentNode);for(const t of n)t.parentElement&&or.has(t.parentElement.tagName)||rr(t)}(t);const e=Array.from(t.querySelectorAll("template"));for(const t of e)if("http://www.w3.org/2000/svg"===t.namespaceURI){const e=document.createElement("template"),n=Array.from(t.childNodes);for(let t=0;t<n.length;t++){const o=n[t];e.content.appendChild(o)}for(const n of t.attributes)e.setAttribute(n.name,n.value);t.replaceWith(e),sr(e.content)}else sr(t.content)}function rr(t){const e=t.data;if(nr.lastIndex=0,!nr.test(e))return;nr.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=nr.exec(e));){o.index>s&&n.appendChild(document.createTextNode(e.slice(s,o.index)));const t=o[1];n.appendChild(document.createComment(`@@: ${t}`)),s=o.index+o[0].length}s<e.length&&n.appendChild(document.createTextNode(e.slice(s))),t.parentNode.replaceChild(n,t)}let ir;function ar(){if(ir)return ir;const t=[],e=bt("not",t)(gt);return ir={filterName:"not",args:t,filterFn:e},ir}const lr=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function cr(t,e){const s=e+n+o,r=t.indexOf("|"),i=t.indexOf("@");let a,l;if(-1!==r?(a=t.slice(0,r).trim(),l=t.slice(r)):-1!==i?(a=t.slice(0,i).trim(),l=t.slice(i)):(a=t.trim(),l=""),"."===a)a=s;else{if(!a.startsWith("."))return t;a=s+n+a.slice(1)}return l.length>0?a+l:a}function dr(t,e){const n=lr.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+cr(s,e)+r}function ur(t,e){const n=t.split(";");let o=!1;const s=n.map(t=>{const n=t.trim();if(0===n.length)return t;const s=n.indexOf(":");if(-1===s)return t;const r=n.slice(0,s).trim(),i=n.slice(s+1).trim(),a=cr(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function fr(t,e){return ur(t,e)}function hr(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const t=s.currentNode;if(t.nodeType===Node.COMMENT_NODE){const e=t;e.data=dr(e.data,n);continue}const e=t;if(e instanceof HTMLTemplateElement)continue;const r=e.getAttribute(o);if(null!==r){const t=ur(r,n);t!==r&&e.setAttribute(o,t)}}}function pr(t){let e=t;const n=[];for(;null!==e.parentNode;){const t=Array.from(e.parentNode.childNodes).indexOf(e);n.unshift(t),e=e.parentNode}return n}function mr(t){const e=[],n=Wt(t);for(const t of n){const n=Ot(t);let o=t;if(t.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==t.parentNode){const e=document.createTextNode("");t.parentNode.replaceChild(e,t),o=e}e.push({nodePath:pr(o),parseBindTextResults:n})}return e}function gr(t){const e=Array.from(t.childNodes);for(const n of e)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&t.removeChild(n)}}const yr=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),br=ar();function wr(t,e){const n=e.outFilters;return{...e,outFilters:[...n,br],bindingType:t}}function vr(t,e,n,o){gr(e),"string"==typeof o&&hr(e,o),Nr(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:mr(e)}}function Nr(t,n,o){const s=e.commentElsePrefix,r=Dt(n),i=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 a=null;const l=[],c=[];for(;i.nextNode();){const t=i.currentNode;c.push(t)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=fr(r,o));let i=Pt(r)[0];const c=yr.get(i.bindingType);if(void 0===c)continue;const d=i.bindingType,u=n.content,f=Ho();let h=null;const p="for"===d?i.statePathName:o;if("else"===d){null===a&&et("'else' binding found without preceding 'if' or 'elseif' binding."),i=wr("else",a.parseBindTextResult),h=vr(t,u,i,p),Mt(f,t,h);const e=l.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:pr(o),parseBindTextResults:Ot(o)})):n.replaceWith(o)}else if("elseif"===d){null===a&&et("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=vr(t,u,i,p),Mt(f,t,h);const e=document.createComment(`@@${c}:${f}`),o=Ho(),r={fragment:document.createDocumentFragment(),parseBindTextResult:wr("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:pr(e),parseBindTextResults:Ot(e)}),Mt(o,t,r);const d=l.at(-1);l.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(n.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:pr(m),parseBindTextResults:Ot(m)})):n.replaceWith(m)}else{h=vr(t,u,i,p),Mt(f,t,h);const e=document.createComment(`@@${c}:${f}`);n.replaceWith(e)}"if"===d?(l.length=0,a=h):"elseif"===d?a=h:"else"===d&&(a=null,l.length=0)}}async function Sr(t){const n=t.querySelectorAll(e.tagNames.state),o=[];await customElements.whenDefined(e.tagNames.state);for(const t of n){if(Rt(t))continue;const e=t;o.push(e.initializePromise)}await Promise.all(o)}async function Ir(t){if(t===document)await Sr(document),sr(document),Nr(document,document),er(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await B(n.host),await Sr(n),sr(n),Nr(n,n),er(n,null)}}const xr="1.28.0",$r="undefined"==typeof HTMLElement?class{}:HTMLElement,Pr=/^@@wcs-(?:for|if|elseif|else):[^-]/,_r=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,Ar=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,kr=/^@@wcs-text-start:(.+)$/;function Cr(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Er extends $r{_stateData=null;_templates=null;_hydrateProps=null;get name(){return this.getAttribute("name")||"default"}get version(){return this.getAttribute("version")||""}get stateData(){return null===this._stateData&&(this._stateData=this._loadStateData()),this._stateData}get templates(){return null===this._templates&&(this._templates=this._loadTemplates()),this._templates}get hydrateProps(){return null===this._hydrateProps&&(this._hydrateProps=this._loadHydrateProps()),this._hydrateProps}getTemplate(t){return this.templates.get(t)??null}verifyVersion(){const t=this.version;if(!t)return!0;const e=t.split("."),n=xr.split(".");return e[0]===n[0]&&e[1]===n[1]}setStateData(t){this._stateData=t}setHydrateProps(t){this._hydrateProps=t}_loadStateData(){const t=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}_loadTemplates(){const t=new Map,e=this.querySelectorAll("template[id]");for(const n of e){const e=n.getAttribute("id");e&&t.set(e,n)}return t}_loadHydrateProps(){const t=this.querySelector("script[data-wcs-ssr-props]");if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}static findByName(t,n){const o=e.tagNames.ssr,s=t instanceof Element?t:t instanceof Document?t.documentElement:null;if(!s)return null;return s.querySelector(`${o}[name="${n}"]`)}static extractStateData(t){const e=t.__state;if(!e||"object"!=typeof e)return{};const n={};for(const[t,o]of Object.entries(e))t.startsWith("$")||"function"==typeof o||(n[t]=o);return n}static buildContent(t,n){const o=document.createElement("script");o.setAttribute("type","application/json"),o.textContent=Cr(JSON.stringify(n)),t.appendChild(o);const s=Array.from(Et.keys());for(const n of s){const o=Tt(n);if(!o)continue;const s=document.createElement("template");s.setAttribute("id",n);const r=o.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(e.bindAttributeName,i);const a=o.fragment.cloneNode(!0);s.content.appendChild(a),t.appendChild(s)}const r=Array.from(Ws);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=Ls(n);if(0===o.length)continue;const s=`wcs-ssr-${t}`;n.setAttribute("data-wcs-ssr-id",s);const i={};for(const t of o)i[t.propName]=t.value;e[s]=i}if(Object.keys(e).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=Cr(JSON.stringify(e)),t.appendChild(n)}}Ws.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(_r.test(t.data)||Ar.test(t.data))&&n.push(t)}for(const t of n)t.remove()}static removeStructuralComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;Pr.test(t.data)&&n.push(t)}for(const t of n)t.remove()}static restoreTextBindings(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode,o=kr.exec(t.data);o&&n.push({comment:t,path:o[1]})}for(const{comment:t,path:e}of n){const n=document.createComment(`@@: ${e}`);t.parentNode.insertBefore(n,t);let o=t.nextSibling;t.remove();const s=`@@wcs-text-end:${e}`;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=t}}}static cleanupDom(t){const n=document.body,o=t.querySelectorAll(e.tagNames.ssr),s=new Map;for(const t of o){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&s.set(e,t)}}const r=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const t=r.currentNode;_r.test(t.data)&&i.push(t)}for(const t of i){const e=_r.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let o=t.nextSibling;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=t}t.remove()}Er.restoreTextBindings(n);const a=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(Pr.test(t.data)){const e=t.data.split(":")[1];l.push({comment:t,uuid:e})}}for(const{comment:t,uuid:n}of l){const o=s.get(n);if(o){const n=document.createElement("template"),s=o.getAttribute(e.bindAttributeName);s&&n.setAttribute(e.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)n.content.appendChild(r);else for(const t of Array.from(o.childNodes))n.content.appendChild(document.importNode(t,!0));t.parentNode.replaceChild(n,t)}}const c=t.querySelectorAll("[data-wcs-ssr-id]");for(const t of c)t.removeAttribute("data-wcs-ssr-id");for(const t of o)t.remove()}}const Mr=new Set(["for","if","elseif","else"]);function Tr(t){const e=new Ro;if(0===t.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:e};const n=t[0].parentNode,o=t[t.length-1].nextSibling,s=document.createElement("div");for(const e of t)s.appendChild(e);const[r,i]=Ft(s),a=e.initialize(i,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:a,subscriberNodes:r,bindingSession:e}}function Or(t,n,o){const s={for:e.commentForPrefix,if:e.commentIfPrefix,elseif:e.commentElseIfPrefix,else:e.commentElsePrefix}[n];if(!s)return null;const r=`@@${s}:${o}`,i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const t=i.currentNode;if(t.data===r)return t}return null}function Rr(t,n){const o=t;let s=null;for(const[t,r]of n.templates){let n=Pt(r.getAttribute(e.bindAttributeName)||"")[0];const i=n.bindingType;"else"===i&&s?n={...s,outFilters:[...s.outFilters,ar()],bindingType:"else"}:"elseif"===i&&s&&(n={...n,stateName:s.stateName}),"if"===i||"elseif"===i?s=n:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?n.statePathName:void 0;gr(a),"string"==typeof l&&hr(a,l),Nr(o,a,l);Mt(t,o,{fragment:a,parseBindTextResult:n,nodeInfos:mr(a)})}}async function Dr(t){await Sr(t);const n=t.querySelectorAll(e.tagNames.ssr);for(const e of n){const n=e;if(!n.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${n.version}", client="${xr}". Falling back to full render.`),Er.cleanupDom(t),!1}for(const e of n)Rr(t,e);const s=function(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o){const n=_r.exec(t.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let i,a,l=null;"for"===o?(i=r[0],a=r[1],l=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const c=[];let d=t.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)c.push(d),d=d.nextSibling;e.push({type:o,uuid:i,path:a,index:l,nodes:c})}return e}(document.body);!function(t,e){const n=new Map;for(const s of e){if(0===s.nodes.length)continue;const e=xs(s.nodes),{bindingInfos:r,subscriberNodes:i,bindingSession:a}=Tr(s.nodes);cs(e,a);for(const t of i)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");is(e,r),fs(e,i);const l=[];for(const t of r)t.statePathName in v&&l.push(t);if(Uo(e,l),"for"===s.type&&null!==s.index){const i=Or(t,"for",s.uuid);if(i){const t=Jo(null,s.index);Es(i,t,e),Ms(i,s.nodes[s.nodes.length-1]),bs(i,e),hs(e,Oe(U(s.path+"."+o),t)),a.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let l=n.get(s.uuid);l||(l=[],n.set(s.uuid,l)),l.push(t)}}else{const n=Or(t,s.type,s.uuid);n&&(bs(n,e),a.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[e,o]of n){const n=Or(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=Tt(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=Br(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&Qo(e,o)})}}(document.body,s),Er.removeBlockBoundaryComments(document.body);const r=[];for(const t of n)t.parentNode&&(r.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());Er.restoreTextBindings(document.body);const[i,a]=Ft(document.body);for(const t of i)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(Ht(t,null),e.setAttribute("data-wcs-completed",""))}else Ht(t,null);const l=[],c=[],d=Do(document.body).initialize(a);for(const t of d)if("event"!==t.bindingType)if(Mr.has(t.bindingType))c.push(t);else{if(t.statePathName.includes(o))continue;l.push(t)}for(const t of c)if("for"===t.bindingType){const e=Ne(t),n=Br(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&Jt(e,o)})}tr(l);for(const{el:t,parent:e,next:n}of r)e.insertBefore(t,n);const u=t.querySelectorAll(e.tagNames.ssr);for(const e of u){const n=e.hydrateProps;for(const[e,o]of Object.entries(n)){const n=t.querySelector(`[data-wcs-ssr-id="${e}"]`);if(n)for(const[t,e]of Object.entries(o))n[t]=e}}const f=t.querySelectorAll("[data-wcs-completed]");for(const t of f)t.removeAttribute("data-wcs-completed");return!0}const Lr=new WeakMap,Wr=new WeakMap,jr=new Set;function Br(t,e){let n=Lr.get(t);return n&&n.get(e)||null}function Fr(t){return Wr.get(t)??Promise.resolve()}function zr(e,n,o){let s=Lr.get(e);if(null===o){if(!s)return;const t=s.get(n);s.delete(n),0===s.size&&Lr.delete(e),void 0!==t&&(jr.delete(t),null!==Ie&&Ie({type:"state:element-unregistered",name:n,rootNode:e,element:t}))}else{if(!s){s=new Map,Lr.set(e,s);const n=!t()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise((t,o)=>{queueMicrotask(async()=>{try{if(n){await Dr(e)||await Ir(e)}else await Ir(e);t()}catch(t){o(t)}})});Wr.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise((t,n)=>{queueMicrotask(async()=>{try{await Ir(e),t()}catch(t){n(t)}})});Wr.set(e,t)}}s.has(n)&&et(`State element with name "${n}" is already registered.`),s.set(n,o),jr.add(o),null!==Ie&&Ie({type:"state:element-registered",name:n,rootNode:e,element:o})}}let qr=0,Ur=0;const Vr=[];function Hr(t,e=0){const n=Vr.findIndex(t=>t.priority>e),o={listener:t,priority:e};-1===n?Vr.push(o):Vr.splice(n,0,o)}const Gr=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(t,e=null){qr>Ur&&(Ur=qr);const n=0===this._queueUpdateRecords.length;this._queueUpdateRecords.push({absoluteAddress:t,context:e}),n&&queueMicrotask(()=>{const t=this._queueUpdateRecords;this._queueUpdateRecords=[],this._applyChange(t)})}testApplyChange(t,e){this._applyChange(t.map((t,n)=>({absoluteAddress:t,context:e?.[n]??null})))}_applyChange(t){const e=new Map;for(const n of t){const t=e.get(n.absoluteAddress);null!==Ie&&null!=t&&null!==n.context&&t.transactionId!==n.context.transactionId&&Ie({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:t.transactionId,winnerTransactionId:n.context.transactionId}),e.set(n.absoluteAddress,n.context)}const n=[],o=new Map;for(const[t,s]of e){if(null!==s&&s.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,stateName:t.absolutePathInfo.stateName,transactionId:s.transactionId,hop:s.hop,maxHops:32}),null!==Ie&&Ie({type:"propagation:hop-limit",absoluteAddress:t,transactionId:s.transactionId,hop:s.hop});continue}const e=Ce(t);if(void 0!==e)if(e instanceof Set)for(const t of e)!1!==t.replaceNode.isConnected&&(n.push(t),null!==s&&o.set(t,s));else!1!==e.replaceNode.isConnected&&(n.push(e),null!==s&&o.set(e,s))}o.size>0?tr(n,o):tr(n),function(t){for(const e of Vr.slice())e.listener(t)}(new Set(e.keys()))}};function Kr(){return Gr}const Jr="__WCSTACK_DEVTOOLS_HOOK__";function Xr(){const t=globalThis,e=t[Jr];if(void 0!==e)return 1!==e.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${e.version}, expected 1. Keeping the existing registry (first-wins).`),e;const n=function(){const t=new Map,e=new Set,n=t=>{if(0===e.size)return void t._setSink(null);const n=t.id;t._setSink(t=>{for(const o of e)o.onEvent?.(n,t)})};return{version:1,sources:t,register(o){if(!t.has(o.id)){t.set(o.id,o),n(o);for(const t of e)t.onSourceRegistered?.(o)}},unregister(n){const o=t.get(n);if(void 0!==o){o._setSink(null),t.delete(n);for(const t of e)t.onSourceUnregistered?.(n)}},addListener(o){e.add(o);for(const e of t.values())n(e),o.onSourceRegistered?.(e);return()=>{if(e.delete(o))for(const e of t.values())n(e)}}}}();return t[Jr]=n,n}const Yr=t=>{null!==Ie&&Ie({type:"state:update-batch",addresses:t})};function Qr(t){const e=null!==Ie;!function(t){Ie=t}(t);const n=null!==t;n&&!e?Hr(Yr,0):!n&&e&&function(t){const e=Vr.findIndex(e=>e.listener===t);-1!==e&&Vr.splice(e,1)}(Yr)}function Zr(t){return{name:t.name,rootNode:t.rootNode,element:t,paths:{list:t.listPaths,element:t.elementPaths,getter:t.getterPaths,setter:t.setterPaths},commandTokenNames:t.commandTokenNames,eventTokenNames:t.eventTokenNames,staticDependency:t.staticDependency,dynamicDependency:t.dynamicDependency}}function ti(t,e){return Br(e,t)??et(`devtools: state element not found: name="${t}"`)}let ei=null;function ni(){if(t())return;if(null!==ei)return;const e={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:xr,getStateElements(){const t=[];for(const e of jr)t.push(Zr(e));return t},keys(t,e){const n=ti(t,e),o=[];return n.createState("readonly",t=>{for(const e of Object.keys(t))if(!e.includes("*")&&!e.startsWith("$")){try{if("function"==typeof t[e])continue}catch{}o.push(e)}}),o},read(t,e,n,o){let s;return ti(t,e).createState("readonly",t=>{s=t.$resolve(n,o??[])}),s},write(t,e,n,o,s){ti(t,e).createState("writable",t=>{void 0!==s&&s.length>0?t.$resolve(n,s,o):t[n]=o})},_setSink:Qr};ei=e,Xr().register(e)}const oi="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";async function si(t,e){let n=null;const o=`\n//# sourceURL=${e}\n`;let s=!1;const r=t=>{t.effectiveDirective.startsWith("script-src")&&(s=!0)};document.addEventListener("securitypolicyviolation",r);try{if("function"==typeof URL.createObjectURL){const e=new Blob([t.text+o],{type:"application/javascript"}),s=URL.createObjectURL(e);try{n=await import(s)}finally{URL.revokeObjectURL(s)}}else{const e=btoa(String.fromCodePoint(...(new TextEncoder).encode(t.text+o)));n=await import(`data:application/javascript;base64,${e}`)}}catch(t){throw new Error(function(t,e,n){const o=e?.message??String(e);return n?`The inline <script> of state "${t}" was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL, so script-src must allow blob:. Prefer moving the state into an external file and loading it with src="./state.js", which requires no extra CSP directive. See ${oi}`:`Failed to evaluate the inline <script> of state "${t}": ${o}. If this page sets a Content-Security-Policy, see ${oi}`}(e,t,s),{cause:t})}finally{document.removeEventListener("securitypolicyviolation",r)}return n&&"object"==typeof n.default?n.default:{}}async function ri(t){try{return(await import(t)).default||{}}catch(t){et(`Failed to load script file: ${t}`)}}class ii{_loopContextStack=Array(s).fill(void 0);_length=0;_getBaseDepth;constructor(t){this._getBaseDepth=t}createLoopContext(t,e){null===t.listIndex&&et("Cannot create loop context for a state address that does not have a list index.");const n=t;this._length>=s&&et("Exceeded maximum loop context stack depth of 128. Possible infinite loop.");const o=this._loopContextStack[this._length-1];if(void 0!==o){o.pathInfo.wildcardCount+1!==n.pathInfo.wildcardCount&&et("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const t=n.pathInfo.wildcardPathInfos[n.pathInfo.wildcardPathInfos.length-2];o.pathInfo!==t&&et("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else if(n.listIndex.length!==n.pathInfo.wildcardCount){const t=this._getBaseDepth();n.listIndex.length!==n.pathInfo.wildcardCount+t&&et(`Cannot push loop context when there is no active loop context: the list index chain (length ${n.listIndex.length}) does not cover the wildcard path (wildcard count ${n.pathInfo.wildcardCount}, base depth ${t}).`)}let r;this._loopContextStack[this._length]=n,this._length++;try{r=e(n)}finally{r instanceof Promise?r.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return r}}const ai=new WeakMap;function li(t,e){let n=ai.get(t);void 0===n&&(n=new Map,ai.set(t,n));let o=n.get(e);return void 0===o&&(o=new Ze(e,t.name),n.set(e,o)),o}const ci=new WeakMap;function di(t){const e=ci.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return li(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:li(t,n)}},set(){et("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){et("$command namespace is read-only; deleting from it is not allowed.")}});return ci.set(t,n),n}const ui=Symbol("wcs-stream-last-notified-uncertain"),fi=new WeakMap;function hi(t,e){const n=fi.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function pi(t,e){const n=fi.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:ui,error:Object.is(o.error,null)?null:ui})}const mi=new Set;function gi(t){mi.delete(t)}const yi=new WeakMap;function bi(t){return yi.get(t)??new Map}function wi(t){gi(t);const e=yi.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,pi(t,n.name)}const vi=(t,e)=>e,Ni=new Set;function Si(t,e){const s=e[E];if(void 0===s)return void hi(t,Ni);"object"==typeof s&&null!==s||et(`${E} must be an object mapping stream names to stream definitions.`);const r=new Map;for(const[i,a]of Object.entries(s)){0===i.length&&et(`${E} entry name must be a non-empty string.`),i.includes(n)&&et(`${E} entry "${i}" must be a flat property name ("${n}" is not allowed).`),i.includes(o)&&et(`${E} entry "${i}" must be a flat property name ("${o}" is not allowed).`),i.startsWith("$")&&et(`${E} entry "${i}" must not start with "$" (reserved namespace).`),i in Object.prototype&&et(`${E} entry "${i}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),t.getterPaths.has(i)&&et(`${E} entry "${i}" conflicts with a getter declared on the state.`),t.setterPaths.has(i)&&et(`${E} entry "${i}" conflicts with a setter declared on the state.`),"object"==typeof a&&null!==a||et(`${E} entry "${i}" must be an object ({ args?, source, fold?, initial? }).`);const s=a;"function"!=typeof s.source&&et(`${E} entry "${i}" source must be a function.`);const l=void 0!==s.fold;l&&"function"!=typeof s.fold&&et(`${E} entry "${i}" fold must be a function.`),l&&!("initial"in s)&&et(`${E} entry "${i}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==s.args&&"function"!=typeof s.args&&et(`${E} entry "${i}" args must be a function.`);const c={name:i,definition:{args:s.args??null,source:s.source,fold:s.fold??vi,initial:s.initial},status:"idle",error:null,controller:null,depAddresses:new Set};i in e||(e[i]=c.definition.initial),r.set(i,c)}!function(t,e){yi.set(t,e)}(t,r),hi(t,new Set(r.keys()))}const Ii=new WeakMap,xi=new WeakMap;function $i(t,e,n){return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;const s=bi(t).get(o);return void 0!==s?n(s):void 0},has:(e,n)=>"string"==typeof n&&bi(t).has(n),ownKeys:()=>Array.from(bi(t).keys()),getOwnPropertyDescriptor(e,o){if("string"!=typeof o)return;const s=bi(t).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){et(`${e} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){et(`${e} namespace is read-only; deleting from it is not allowed.`)}})}function Pi(t){const e=Ii.get(t);if(void 0!==e)return e;const n=$i(t,O,t=>t.status);return Ii.set(t,n),n}function _i(t){const e=xi.get(t);if(void 0!==e)return e;const n=$i(t,R,t=>t.error);return xi.set(t,n),n}function Ai(t){Ii.delete(t),xi.delete(t)}let ki=null;async function Ci(t,e,n,o){let s=null,r=null;const i=()=>{if(s&&s!==r){r=s;try{s.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",i,{once:!0});try{const r=await t(e,n);if(s=function(t,e){if("function"==typeof t?.getReader)return async function*(t,e){const n=t.getReader(),o=()=>{n.cancel().catch(()=>{})};e.addEventListener("abort",o,{once:!0});try{for(;;){const{done:t,value:e}=await n.read();if(t)return;yield e}}finally{e.removeEventListener("abort",o),n.releaseLock()}}(t,e);if("function"==typeof t?.[Symbol.asyncIterator])return t;throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).")}(r,n)[Symbol.asyncIterator](),n.aborted)return void i();for(;;){const t=await s.next();if(t.done)break;if(n.aborted)return;o.fold(t.value)}if(n.aborted)return;o.done()}catch(t){if(n.aborted)return;o.fail(t)}finally{n.removeEventListener("abort",i)}}function Ei(t){const e=bi(t);if(0!==e.size){!function(t){mi.add(t)}(t);for(const n of e.values())Mi(t,n)}}function Mi(t,e){e.controller?.abort();const o=new AbortController;e.controller=o;const s=function(t,e){const o=e.definition.args;if(null===o)return void e.depAddresses.clear();const s=ki,r=new Set;let i;ki=r;try{t.createState("readonly",t=>{i=o(t)})}finally{ki=s}i instanceof Promise&&et(`${E} entry "${e.name}" args must be synchronous (it returned a Promise).`);const a=`${O}${n}${e.name}`,l=`${R}${n}${e.name}`;for(const n of r){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==t||o.path!==e.name&&o.path!==a&&o.path!==l||et(`${E} entry "${e.name}" args must not read the stream itself ("${o.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),o.wildcardCount>0&&et(`${E} entry "${e.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return e.depAddresses=r,i}(t,e);t.createState("writable",t=>{t[e.name]=e.definition.initial}),Ti(t,e,"active",null);const r=e.definition,i={fold(n){t.createState("writable",t=>{t[e.name]=r.fold(t[e.name],n)})},done(){Ti(t,e,"done",null)},fail(n){Ti(t,e,"error",n),o.abort()}};Ci(r.source,s,o.signal,i)}function Ti(t,e,o,s){e.status=o,e.error=s;const r=function(t,e){return fi.get(t)?.get(e)??{status:"idle",error:null}}(t,e.name),i=r.status!==o,a=!Object.is(r.error,s);(i||a)&&(!function(t,e,n,o){let s=fi.get(t);void 0===s&&(s=new Map,fi.set(t,s)),s.set(e,{status:n,error:o})}(t,e.name,o,s),t.createState("writable",t=>{i&&t.$postUpdate(`${O}${n}${e.name}`),a&&t.$postUpdate(`${R}${n}${e.name}`)}))}Hr(function(t){const e=mi;if(0===e.size)return;const n=[];for(const o of e)for(const e of bi(o).values())for(const s of e.depAddresses)if(t.has(s)){n.push({stateElement:o,entry:e});break}for(const{stateElement:t,entry:o}of n)if(e.has(t)&&bi(t).get(o.name)===o)try{Mi(t,o)}catch(n){o.controller?.abort(),e.has(t)&&bi(t).get(o.name)===o&&Ti(t,o,"error",n)}},20);const Oi=new WeakMap,Ri=new Set,Di=new Map;function Li(t){return Oi.get(t)??Di}function Wi(){return Ri}function ji(t,e){const n=e[M];if(void 0===n)return null;"object"==typeof n&&null!==n||et(`[wcs/watch-declaration-invalid] ${M} must be an object mapping state paths to handler functions.`);const o=new Map,s=new Set;let r=0;for(const[e,i]of Object.entries(n)){"function"!=typeof i&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must be a function.${ct}`),0===e.length&&et(`[wcs/watch-declaration-invalid] ${M} entry name must be a non-empty state path.`),e.startsWith("$")&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not start with "$" (reserved namespace).${ct}`),e.includes("@")&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not target another state ("@" is not allowed); watch only paths of its own state.${ct}`),e in Object.prototype&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const n=U(e);for(const t of n.segments)0===t.length&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" has an empty path segment.${ct}`);n.wildcardCount>128&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" exceeds the maximum wildcard depth (128).`),o.set(e,{path:e,pathInfo:n,handler:i,order:r++}),s.add(e),t.setPathInfo(e,"prop")}return function(t,e){Oi.set(t,e)}(t,o),s.size>0?s:null}const Bi=new WeakMap;function Fi(t,e,n){let o=Bi.get(t);void 0===o&&(o=new Map,Bi.set(t,o)),o.set(e,n)}const zi=new Map;function qi(t){0!==Li(t).size&&(function(t){Ri.add(t)}(t),function(t){const e=[];for(const n of Li(t).values())Vi(t,n)&&e.push(n);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{Fi(t,Ui(t,o),n[o.path])}catch(e){Gi(t,o.path,"prime",e)}})}(t))}function Ui(t,e){return ce(se(t,e.pathInfo),null)}function Vi(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const Hi={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Gi(t,e,n,o){console.error(`[@wcstack/state] $watch ${Hi[n]} "${e}" threw.`,o),null!==Ie&&Ie({type:"state:watch-error",phase:n,stateName:t.name,path:e,error:o})}function Ki(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function Ji(t){const{stateElement:e,entry:n,absAddress:o,indexes:s}=t,r=Vi(e,n);try{e.createState("writable",t=>{let i;try{i=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,s)}catch(t){return void Gi(e,n.path,"evaluate",t)}const a=r?function(t,e){return Bi.get(t)?.get(e)}(e,o):function(t){return zi.get(t)}(o);r&&Fi(e,o,i),n.handler.call(t,i,a,...s)})}catch(t){Gi(e,n.path,"handler",t)}}function Xi(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function Yi(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function Qi(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function Zi(t){return t.startsWith("$")}function ta(t){const e=[];let n=t;for(;n&&n!==Object.prototype;)e.push(n),n=Object.getPrototypeOf(n);const o={};for(let t=e.length-1;t>=0;t--)Object.assign(o,Object.getOwnPropertyDescriptors(e[t]));return o}function ea(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function na(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||et(`${e} must be an array of strings.`);const o=[],s=new Set;for(const t of n)"string"==typeof t&&0!==t.length||et(`${e} entries must be non-empty strings.`),t.startsWith("$")&&et(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),s.has(t)&&et(`${e} entry "${t}" is duplicated.`),s.add(t),o.push(t);return o}function oa(t){const e=na(t,$)??[],n=na(t,P)??[],o=ta(t),s=function(t){const e=t[E];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),r=[];for(const t of e){const e=o[t];if(void 0===e){if(s.has(t)){r.push(t);continue}et(`${$} entry "${t}" is not declared on the state.${lt(t,ea(o,"value"))}`)}"function"==typeof e.value&&et(`${$} entry "${t}" is a method. Declare it in ${P} instead.`)}for(const t of n){const e=o[t];void 0===e&&et(`${P} entry "${t}" is not declared on the state.${lt(t,ea(o,"method"))}`),"function"!=typeof e.value&&et(`${P} entry "${t}" is not a method. Declare it in ${$} instead.`)}return{bindables:e,commands:n,streamBackedBindables:r}}Hr(function(t){const e=Wi();try{if(0===e.size)return;const n=function(){const t=Ur;return Ur=0,t}();if(n>32){const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; watch handlers for this batch were skipped.",{maxDepth:32,paths:e}),void(null!==Ie&&Ie({type:"state:watch-chain-limit",maxDepth:32,paths:e}))}const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const s=Li(t).get(n.absolutePathInfo.pathInfo.path);if(void 0===s)continue;let r=[];if(s.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=ge(n.listIndex,s.pathInfo.wildcardCount)}o.push({stateElement:t,entry:s,absAddress:n,indexes:r})}if(0===o.length)return;o.sort(Ki),function(t){qr=t+1}(n);try{for(const t of o)e.has(t.stateElement)&&Li(t.stateElement).get(t.entry.path)===t.entry&&Ji(t)}finally{qr=0}}finally{zi.clear()}},10);const sa=new Map;class ra{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice();let o=0,s=0,r=0,i="none";const a=[];for(let t=0;t<e.length;t++){const i=e[t];if("*"===i)n[t]="*",a.push(null),o++,r++;else{const e=Number(i);Number.isNaN(e)||(n[t]="*",a.push(e),s++,r++)}}const l=U(n.join("."));(o>0||s>0)&&(i=o===r?"context":s===r?"all":"partial"),this.path=t,this.segments=e,this.wildcardCount=r,this.wildcardType=i,this.wildcardIndexes=a,this.pathInfo=l}}function ia(t){let e;return sa.get(t)??(sa.set(t,e=new ra(t)),e)}const aa=new WeakMap;function la(t,e){null===e?aa.delete(t):aa.set(t,e)}function ca(t){const e=aa.get(t);e&&(e.dirty=!0)}const da=[],ua=[];let fa=0;function ha(t,e){da[fa]=t,ua[fa]=e,fa++}function pa(){fa--,da[fa]=void 0,ua[fa]=void 0}function ma(t,e){return!0!==t.hasMappedComponentState&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function ga(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}function ya(t,e,n,s,r){const i=e.pathInfo.segments[0];if(i===A)return ga(di(r),e.pathInfo.segments);if(i===O)return ga(Pi(r),e.pathInfo.segments);if(i===R)return ga(_i(r),e.pathInfo.segments);if(!(e.pathInfo.path in t)){const r=wa(t,e.parentAddress??et(`address.parentAddress is undefined path: ${e.pathInfo.path}`),n,s);if(null==r)return;const i=e.pathInfo.segments[e.pathInfo.segments.length-1];if(i===o){const t=e.listIndex?.index??et(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(r,t)}return Reflect.get(r,i)}if(r.getterPaths.has(e.pathInfo.path)){s.pushAddress(e);try{return Reflect.get(t,e.pathInfo.path,n)}finally{s.popAddress()}}else{if(!0!==r.hasMappedComponentState)return Reflect.get(t,e.pathInfo.path);ha(r,e);try{return Reflect.get(t,e.pathInfo.path)}finally{pa()}}}function ba(t,e,n,o,s){const r=ce(se(s,e.pathInfo),e.listIndex),i=function(t){return aa.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=ya(t,e,n,o,s);return la(r,{value:a,dirty:!1}),a}function wa(t,e,n,o){!function(t,e){if(!t.untracking&&t.addressStackLength>0){const n=t.lastAddressStack,o=n?.pathInfo??null,s=t.stateElement;if(null!==o&&s.getterPaths.has(o.path)&&o.path!==e.pathInfo.path&&(s.addDynamicDependency(e.pathInfo.path,o.path),e.pathInfo.wildcardCount>0&&o.wildcardCount>0)){const t=pe(e.pathInfo,o);if(t>0){let r=!1;const i=e.listIndex??null,a=n.listIndex??null;for(let n=0;n<t;n++)if((null!==i?me(i,n,e.pathInfo.wildcardCount):null)!==(null!==a?me(a,n,o.wildcardCount):null)){r=!0;break}if(r)for(let n=0;n<t;n++)s.addCrossRowListPath?.(e.pathInfo.wildcardParentPaths[n])}}}}(o,e),function(t,e){if(null===ki)return;const n=se(t,e.pathInfo);ki.add(ce(n,e.listIndex))}(o.stateElement,e);const s=o.stateElement;return ma(s,e)?ba(t,e,n,o,s):ya(t,e,n,o,s)}function va(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const o=n.pathInfo.indexByWildcardPath[e];return void 0===o||null===n.listIndex?null:me(n.listIndex,o,n.pathInfo.wildcardCount)}function Na(t,e,n){const o=t.bindableEventMap,s=o[e.path],r="string"==typeof s,i=r?s:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof i)return;const a=t.rootNode;a instanceof ShadowRoot&&a.host.dispatchEvent(new CustomEvent(i,{detail:r&&void 0!==n?n.value:void 0,bubbles:!0}))}function Sa(t,e,n,o){"object"==typeof t&&null!==t||et(`${T} list "${e}": ${n} row at index ${o} must be a plain object (got ${null===t?"null":typeof t}).`);const s=Object.getPrototypeOf(t);s!==Object.prototype&&null!==s&&et(`${T} list "${e}": ${n} row at index ${o} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function Ia(t,e,n,o,s){const r="function"==typeof e?e(t):t[e];return null==r&&et(`${T} list "${n}": ${o} row at index ${s} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(r)}).`),r}function xa(t,e,n,o){const s=new Array(t.length),r=new Set;for(let i=0;i<t.length;i++){const a=t[i];Sa(a,n,o,i);const l=Ia(a,e,n,o,i);r.has(l)&&et(`${T} list "${n}": duplicate key ${JSON.stringify(l)} in ${o} list.`),r.add(l),s[i]=l}return s}function $a(t,e){const n=[];for(const o of Object.keys(e))Object.is(t[o],e[o])||n.push({field:o,value:e[o]});for(const o of Object.keys(t))Object.hasOwn(e,o)||null==t[o]||n.push({field:o,value:null});return n}function Pa(t,e,n,s){if(e.pathInfo.path in t)return!0;const r=e.parentAddress;if(null===r)return!1;const i=wa(t,r,n,s);if(null===i||"object"!=typeof i&&"function"!=typeof i)return!1;const a=e.pathInfo.lastSegment;if(a===o){const t=e.listIndex?.index;return"number"==typeof t&&t in i}return a in i}const _a=new WeakMap;function Aa(t,e){null===e?_a.delete(t):_a.set(t,e)}function ka(t,e,n){const o=U(t.wildcardParentPaths[e]),s=se(t.stateElement,o),r=Oe(o,n),i=Kt(ce(s,n)),a=t.stateProxy[Yt](r),l=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return[]}}(ns(Hn(t.stateElement,r.listIndex),i,a),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...l);else for(const n of l)ka(t,e+1,n)}const Ca=[];function Ea(t,e,n,o,s){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:s.newIndexes,movedRows:null}:0===s.addIndexSet.size&&0===s.changeIndexSet.size?0===s.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Ca,movedRows:null}:{fullRows:s.newIndexes,movedRows:null}:{fullRows:Ca,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const Ma=[];function Ta(t,e,o){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ma;let r=null;const i=e+n;for(const t of s){if(t!==e&&!t.startsWith(i))continue;const n=U(t);if(n.wildcardCount!==o.wildcardCount)return null;(r??=[]).push(n)}return r??Ma}function Oa(t,e,n){const s=e.pathInfo.path,r=t.staticMap.get(s);if(r)for(const i of r){const r=U(i);if(t.listPathSet.has(s)&&r.lastSegment===o){const o=t.stateProxy[Yt](e),a=Kt(ce(se(t.stateElement,e.pathInfo),e.listIndex)),l=Ea(t,s,0,0,ns(Hn(t.stateElement,e.listIndex),a,o));for(const e of l.fullRows){const o=Oe(r,e);t.result.add(o),n.push(o)}if(null!==l.movedRows){const e=Ta(t,i,r);if(null===e)for(const e of l.movedRows){const o=Oe(r,e);t.result.add(o),n.push(o)}else if(e.length>0)for(const o of l.movedRows)for(const s of e){const e=Oe(s,o);t.result.add(e),n.push(e)}}}else{const o=Oe(r,e.listIndex);t.result.add(o),n.push(o)}}const i=t.dynamicMap.get(s);if(i)for(const o of i){const s=U(o),r=[];if(s.wildcardCount>0){const n=pe(e.pathInfo,s);if(s.wildcardCount-n>=1){let o;n>0?(null===e.listIndex&&et(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),o=me(e.listIndex,n-1,e.pathInfo.wildcardCount)):o=null;const i={stateName:t.stateName,stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};ka(i,n,o),r.push(...i.targetListIndexes)}else{null===e.listIndex&&et(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`);const t=me(e.listIndex,n-1,e.pathInfo.wildcardCount);r.push(t)}}else r.push(null);for(const e of r){const o=Oe(s,e);t.result.add(o),n.push(o)}}}function Ra(t,e,n,o,s,r,i,a,l,c){const d=n.pathInfo.path;if(!o.has(d)&&!s.has(d))return l(n),[];const u=function(t,e,n,o){const s=new Map,r=new Map,i=[t];for(r.set(t,0);i.length>0;){const t=i.pop();if(s.has(t))continue;const o=e.get(t),a=n.get(t);let l;l=void 0===o?a??[]:void 0===a?o:o.concat(a),s.set(t,l);for(let t=0;t<l.length;t++){const e=l[t];r.set(e,(r.get(e)??0)+1),s.has(e)||i.push(e)}}const a=new Map,l=new Set,c=[];for(const[t,e]of r)0===e&&(a.set(t,0),l.add(t),c.push(t));for(let t=0;t<c.length;t++){const e=c[t],n=a.get(e)+1;n>o&&et(`Maximum dependency depth of ${o} exceeded. Possible circular dependency detected at path: ${e}`);const i=s.get(e);for(let t=0;t<i.length;t++){const e=i[t];n>(a.get(e)??-1)&&a.set(e,n);const o=r.get(e)-1;r.set(e,o),0===o&&(l.add(e),c.push(e))}}if(l.size!==s.size){let t=-1;for(const e of l){const n=a.get(e);n>t&&(t=n)}const e=t+1;for(const t of s.keys())l.has(t)||a.set(t,e)}return a}(d,o,s,1e3),f={ranks:u,stateName:t,stateElement:e,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:a,listExpansion:c?.listExpansion??"full",keyedMergePath:c?.keyedMergePath??null};return function(t,e,n){const o=[],s=t.ranks,r=(t,e)=>{let n=s.get(t.pathInfo.path)??e;n<e&&(n=e),(o[n]??=[]).push(t)};r(e,0);const i=[];for(let e=0;e<o.length;e++){const s=o[e];if(void 0!==s)for(let o=0;o<s.length;o++){const a=s[o];if(!t.visited.has(a)){t.visited.add(a),n(a),i.length=0,Oa(t,a,i);for(let t=0;t<i.length;t++)r(i[t],e+1)}}}}(f,n,l),Array.from(f.result)}function Da(t,e,n,o,s){const r=t.watchPaths;null!=r&&s&&r.has(e)&&function(t,e){zi.has(t)||zi.set(t,e)}(n,o)}function La(t,e,n,o,s){const r=$n()??Sn(-1),i=Kr();i.enqueueAbsoluteAddress(e,r),Ra(o.stateName,o.stateElement,t,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=ce(se(o.stateElement,e.pathInfo),e.listIndex);ca(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:"diff",keyedMergePath:s})}function Wa(t,e,n,s,r,i,a){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,s);const a=wa(t,n,r,i),l=e.pathInfo.segments[e.pathInfo.segments.length-1];if(l===o){const t=e.listIndex?.index??et(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.set(a,t,s)}return Reflect.set(a,l,s)}if(i.stateElement.setterPaths.has(e.pathInfo.path)){i.pushAddress(e),i.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,s,r)}finally{i.endUntrack(),i.popAddress()}}else{if(!0!==i.stateElement.hasMappedComponentState)return Reflect.set(t,e.pathInfo.path,s);ha(i.stateElement,e);try{return Reflect.set(t,e.pathInfo.path,s)}finally{pa()}}}finally{La(e,n,r,i,a)}}function ja(t,e,n,o,s,r,i){let a=e.parentAddress??et(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return _a.get(t)??null}(a);if(null===l){const e=wa(t,a,s,r)??[],n=Yo(e)??[];l={value:[...e],listIndexes:[...n]},Aa(a,l)}try{return Wa(t,e,n,o,s,r,i)}finally{const n=l.value.indexOf(o),i=wa(t,a,s,r)??[],c=Array.isArray(i)?Yo(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:Jo(a.listIndex,-1);c[d]=u;if(new Set(i).size===l.value.length){for(let t=0;t<c.length;t++)c[t].index=t;Aa(a,null)}}}function Ba(t,e,s,r,i){const a=i.stateElement.listKeys;if(null!=a&&Array.isArray(s)){const l=a.get(e.pathInfo.path);if(void 0!==l){const a=wa(t,e,r,i),c=function(t,e,n,o){const s=xa(o,e,t,"new");if(!Array.isArray(n)||0===n.length||0===o.length)return null;const r=n,i=xa(r,e,t,"current"),a=new Map;for(let t=0;t<r.length;t++)a.set(i[t],r[t]);const l=new Array(o.length),c=[];for(let t=0;t<o.length;t++){const e=o[t],n=a.get(s[t]);void 0!==n&&n!==e?(l[t]=n,c.push({position:t,oldRow:n,newRow:e})):l[t]=e}return c.length>0?{list:l,matched:c}:null}(e.pathInfo.path,l,a,s);if(null!==c)return function(t,e,s,r,i,a){const l=e.pathInfo.path,c=Hn(a.stateElement,e.listIndex);null===Yo(r)&&ns(c,null,r);const d=ns(c,r,s.list),u=Fa(t,e,s.list,i,a,l),f=U(l+n+o);for(const e of s.matched){const o=$a(e.oldRow,e.newRow);if(0===o.length)continue;const s=d.newIndexes[e.position];for(const r of o)void 0!==s?Ba(t,Oe(U(f.path+n+r.field),s),r.value,i,a):e.oldRow[r.field]=r.value}return u}(t,e,c,a,r,i)}}return Fa(t,e,s,r,i,null)}function Fa(t,n,s,r,i,a){const l=i.stateElement,c=n.pathInfo.path,d=!!An&&(An=!1,!0);if(!(c in t)&&null!==n.parentAddress&&!l.elementPaths.has(c)){const u=wa(t,n.parentAddress,r,i);if("object"==typeof u&&null!==u){const t=n.pathInfo.lastSegment,f=t===o?n.listIndex?.index:t;let h,p=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const t=void 0!==f&&f in u,e=void 0!==f?u[f]:void 0;if(t&&Object.is(e,s))return!0;h=e,p=!0}const m=ma(l,n),g=ce(se(l,n.pathInfo),n.listIndex);null!==Ie&&Ie({type:"state:write",absoluteAddress:g,value:s,oldValue:h,hasOldValue:p}),Da(l,c,g,h,p);try{return void 0===f&&et(`address.listIndex?.index is undefined path: ${c}`),Reflect.set(u,f,s)}finally{La(n,g,r,i,a),m&&la(g,{value:s,dirty:!1}),Na(l,n.pathInfo,{value:s})}}}let u,f=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const e=wa(t,n,r,i);if(Pa(t,n,r,i)&&Object.is(e,s))return!0;u=e,f=!0}const h=l.elementPaths.has(n.pathInfo.path),p=ma(l,n),m=ce(se(l,n.pathInfo),n.listIndex);null!==Ie&&Ie({type:"state:write",absoluteAddress:m,value:s,oldValue:u,hasOldValue:f}),Da(l,c,m,u,f);try{return h?ja(t,n,m,s,r,i,a):Wa(t,n,m,s,r,i,a)}finally{p&&la(m,{value:s,dirty:!1}),Na(l,n.pathInfo,{value:s})}}function za(t,e,n,o){return(e,s,r)=>{const i=U(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==i.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(i.path,t.path)}i.wildcardParentPathInfos.length>s.length&&et(`indexes length is insufficient: ${e}`);let a=null;for(let e=0;e<i.wildcardParentPathInfos.length;e++){const r=i.wildcardParentPathInfos[e],l=Oe(r,a),c=Yo(wa(t,l,n,o));null==c&&et(`ListIndexes not found: ${r.path}`);const d=s[e];a=c[d]??et(`ListIndex not found at index ${d} of ${r.path}`)}const l=Oe(i,a);if(!(void 0!==r))return wa(t,l,n,o);Ba(t,l,r,n,o)}}const qa=new WeakMap;function Ua(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return va(o,s.wildcardPaths.at(-1)??et(`lastWildcardPath is null: ${e.pathInfo.path}`))??et(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<e.pathInfo.wildcardCount;r++){const i=e.pathInfo.wildcardParentPathInfos[r]??et(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),a=Yo(wa(t,Oe(i,s),n,o))??et(`ListIndex not found: ${i.path}`),l=e.wildcardIndexes[r]??et(`wildcardIndex is null: ${e.pathInfo.path}`);s=a[l]??et(`ListIndex not found at index ${l} of ${i.path}`)}return s}case"partial":et(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}const Va=`${O}${n}`,Ha=`${R}${n}`,Ga=new WeakMap;function Ka(t,e,n,o){const s=v[e];if(void 0!==s){0===o.addressStackLength&&et(`No active state reference to get list index for "${e.toString()}".`);const t=o.lastAddressStack,n=t?.pathInfo;n&&!o.untracking&&o.stateElement?.getterPaths.has(n.path)&&o.stateElement.addIndexDependentGetterPath?.(n.path);const r=t?.listIndex;null==r&&et(`ListIndex not found: ${e.toString()}`);const i=me(r,s,t.pathInfo.wildcardCount);return i?.index??et(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"===e[0]){switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=za(t,0,n,o);return(e,r)=>{const i=new Map,a=U(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==a.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(a.path,t.path)}if(void 0===r){for(let t=0;t<a.wildcardParentPathInfos.length;t++){const e=a.wildcardParentPathInfos[t],n=va(o,e.path);if(n){r=ge(n,n.length-Un(o.stateElement));break}}void 0===r&&(r=[])}const l=(e,s,r,a,c,d,u)=>{const f=e[s]??null;if(null===f)return void u.push(d);const h=Oe(f,r),p=qa.get(h),m=wa(t,h,n,o),g=ns(Hn(o.stateElement,r),p,m).newIndexes,y=a[c]??null;if(i.set(h,m),null===y)for(let t=0;t<g.length;t++){const n=g[t];l(e,s+1,n,a,c+1,d.concat(n.index),u)}else{const t=g[y]??et(`ListIndex not found at index ${y} of ${f.path}`);s+1<e.length?l(e,s+1,t,a,c+1,d.concat(t.index),u):u.push(d.concat(t.index))}},c=[];l(a.wildcardParentPathInfos,0,null,r,0,[],c);const d=[];for(let t=0;t<c.length;t++)d.push(s(a.path,c[t]));for(const[t,e]of i.entries())qa.set(t,e);return d}}(t,0,n,o)(e,s);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const r=ia(e),i=Ua(t,r,n,o),a=Oe(r.pathInfo,i),l=ce(se(s,a.pathInfo),a.listIndex),c=Kr();c.enqueueAbsoluteAddress(l),Ra(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=ce(se(s,t.pathInfo),t.listIndex);ca(e),c.enqueueAbsoluteAddress(e)}),Na(s,a.pathInfo)}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>za(t,0,n,o)(e,s,r);case"$trackDependency":return t=>function(t,e,n,o){return t=>{0===o.addressStackLength&&et(`No active state reference to track dependency for path "${t}".`);const e=o.lastAddressStack?.pathInfo??et("Internal error: lastAddressStack is null"),n=o.stateElement;o.stateElement.getterPaths.has(e.path)&&e.path!==t&&n.addDynamicDependency(t,e.path)}}(0,0,0,o)(t);case"$untrackDependency":return t=>function(t,e,n,o){return t=>{o.beginUntrack();try{return t()}finally{o.endUntrack()}}}(0,0,0,o)(t);case A:return di(o.stateElement);case O:return Pi(o.stateElement);case R:return _i(o.stateElement)}if(!e.startsWith(Va)&&!e.startsWith(Ha))return}const s=ia(e),r=Ua(t,s,n,o),i=Oe(s.pathInfo,r);return wa(t,i,n,o)}if("symbol"==typeof e){const s=function(t){let e=Ga.get(t);return void 0===e&&(e=new Map,Ga.set(t,e)),e}(o),r=s.get(e);if(void 0!==r)return r;let i;switch(e){case Xt:i=(t,e=()=>{})=>function(t,e,n){void 0!==t.loopContext&&et("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return n()}finally{t.popAddress()}}finally{t.clearLoopContext()}}(o,t,e);break;case Yt:i=e=>wa(t,e,n,o);break;case Qt:i=e=>Pa(t,e,n,o);break;case Zt:i=(e,s)=>Ba(t,e,s,n,o);break;case te:i=()=>async function(t,e,n){const o=Reflect.get(t,N);"function"==typeof o&&await o.call(n)}(t,0,n);break;case ee:i=()=>function(t,e,n){const o=Reflect.get(t,S);"function"==typeof o&&o.call(n)}(t,0,n);break;case ne:i=e=>function(t,e,n,o){const s=Reflect.get(t,I);if("function"==typeof s){const t=new Set,r={};for(const n of e){const e=n.absolutePathInfo.pathInfo;let s;if(s=n.absolutePathInfo.stateName===o.stateName?e.path:e.path+"@"+n.absolutePathInfo.stateName,t.add(s),e.wildcardCount>0){const t=ge(n.listIndex,e.wildcardCount),o=r[s];void 0===o?r[s]=[t]:o.push(t)}}return s.call(n,Array.from(t),r)}}(t,e,n,o);break;default:return Reflect.get(t,e,n)}return s.set(e,i),i}}class Ja{_stateElement;_stateName;_addressStack=Array(s).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(t,e,n){this._stateName=e;const o=Br(t,this._stateName);null===o&&et(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=o,this._mutability=n}get stateName(){return this._stateName}get stateElement(){return this._stateElement}get lastAddressStack(){let t;return this._addressStackIndex>=0&&(t=this._addressStack[this._addressStackIndex]),void 0===t&&et("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex++,this._addressStackIndex>=s&&et("Exceeded maximum address stack depth of 128. Possible infinite loop."),this._addressStack[this._addressStackIndex]=t}popAddress(){if(this._addressStackIndex<0)return null;const t=this._addressStack[this._addressStackIndex];return void 0===t&&et(`Address stack at index ${this._addressStackIndex} is undefined.`),this._addressStack[this._addressStackIndex]=void 0,this._addressStackIndex--,t}setLoopContext(t){this._loopContext=t}clearLoopContext(){this._loopContext=void 0}get untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(t,e,n){return Ka(t,e,n,this)}set(t,e,n,o){return"readonly"===this._mutability&&et(`State "${this._stateName}" is readonly.`),function(t,e,n,o,s){if("string"==typeof e){const r=ia(e),i=Ua(t,r,o,s);return Ba(t,Oe(r.pathInfo,i),n,o,s)}return Reflect.set(t,e,n,o)}(t,e,n,o,this)}has(t,e){return Reflect.has(t,e)}}function Xa(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}class Ya{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=jn(t,e)??et("State element not found for web component.")}_outerLoopContext(t,e){const n=e.pathInfo.wildcardCount,o=Vn(e.stateElement,e.pathInfo),s=Vt(this._webComponent);if(null!==s&&s.listIndex.length===o)return s;if(n>0){const s=function(t,e){if(0===fa)return null;const n=fa-1,o=ua[n];return da[n]!==t||o?.pathInfo.path!==e?null:o}(this._innerStateElement,t.path),r=s?.listIndex??null;if(null!==r&&r.length===o){return Oe(U(e.pathInfo.wildcardPaths[n-1]),r)}}return s}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e,n);{if("then"===e)return;if("$"===e[0])return;if(this._innerStateElement.getterPaths.has(e)&&e in t)return Reflect.get(t,e,n);const o=U(e),s=se(this._innerStateElement,o),r=Qn(this._webComponent,s);if(null!==r){const t=this._outerLoopContext(o,r);let e;return r.stateElement.createState("readonly",n=>{n[Xt](t,()=>{e=n[r.pathInfo.path]})}),e}if(e in t)return Reflect.get(t,e,n);et(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n,o);{if(this._innerStateElement.setterPaths.has(e)&&e in t)return Reflect.set(t,e,n,o);const s=U(e),r=se(this._innerStateElement,s),i=Qn(this._webComponent,r);if(null!==i){const t=this._outerLoopContext(s,i);return i.stateElement.createState("writable",e=>{e[Xt](t,()=>{e[i.pathInfo.path]=n})}),!0}if(e in t)return Reflect.set(t,e,n,o);et(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}has(t,e){if("string"==typeof e){if("$"===e[0])return!1;if((this._innerStateElement.getterPaths.has(e)||this._innerStateElement.setterPaths.has(e))&&e in t)return!0;const n=U(e),o=se(this._innerStateElement,n);return null!==Qn(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class Qa{_innerStateElement;constructor(t,e){this._innerStateElement=jn(t,e)??et("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const Za=t=>()=>t;function tl(t,n,o,s){!function(t,e,n){let o=Wn.get(t);o||(o=new Map,Wn.set(t,o)),o.set(e,n)}(n,o,t);const r=n.hasAttribute(e.bindAttributeName)?(i=n,(rt.get(i)||null)??[]).filter(t=>t.propSegments[0]===o):[];var i;r.length>0?(!function(t,e,n){if(0===n.length)return;const o=jn(t,e);null===o&&et("State element not found for web component.");const s=new Map,r=new Map;for(const e of n){const n=Yn(o,e);let i=Jn.get(t);void 0===i?Jn.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Xn.set(n,e),s.set(a,l),r.set(l,a),Fn(t,l.stateElement)}Gn.set(t,s),Kn.set(t,r)}(n,o,r),t.markComponentStateMapped?.(),t.setInitialState(function(t,e){const n=new Ya(t,e),o=jn(t,e);null===o&&et("State element not found for web component."),null===o.boundComponentStateProp&&et("State element is not bound to any component state prop."),o.boundComponentStateProp in t||et(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=t[o.boundComponentStateProp];return"object"==typeof s&&null!==s||et(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Xa(s),n)}(n,o))):t.setInitialState(Xa(s));const a=function(t,e){const n=new Qa(t,e);return new Proxy({},n)}(n,o);if(Object.defineProperty(n,o,{get:Za(a),enumerable:!0,configurable:!0}),function(t,e){let n=Wo.get(t);n||(n=new Set,Wo.set(t,n)),n.add(e)}(n,o),x in n){const t=n[x];"function"==typeof t?t.call(n,o).catch(t=>{et(`Error in ${x}: ${t instanceof Error?t.message:String(t)}`)}):et(`${x} is not a function.`)}}class el extends $r{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return Fr(t)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(t=()=>0){return new ii(t)}(()=>Un(this));_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_watchPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMappedComponentState=!1;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_dcc=!1;_connectGeneration=0;_streamsStartedGeneration=0;constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise((t,e)=>{this._resolveConnectedCallback=t,this._rejectConnectedCallback=e}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&et(`${e.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(t){const e=new Set,n=t[_];if(void 0===n)return e;Array.isArray(n)||et(`${_} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||et(`${_} entries must be non-empty strings.`),t===A&&et(`${_} entry "${t}" conflicts with the reserved namespace name "${A}".`),e.has(t)&&et(`${_} entry "${t}" is duplicated.`),e.add(t);return e}(e),this._eventTokenNames=function(t){const e=new Set,n=t[k];if(void 0===n)return e;Array.isArray(n)||et(`${k} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||et(`${k} entries must be non-empty strings.`),e.has(t)&&et(`${k} entry "${t}" is duplicated.`),e.add(t);return e}(e),this.__state=e,this._hasUpdatedCallback=I in e,Xe(this),function(t,e,n){const o=e[C];if(void 0!==o){"object"==typeof o&&null!==o||et(`${C} must be an object mapping event-token names to handler functions.`);for(const[e,s]of Object.entries(o))n.has(e)||et(`${C} entry "${e}" is not declared in $eventTokens.${lt(e,n)}`),"function"!=typeof s&&et(`${C} entry "${e}" must be a function.`),Je(t,e).subscribe(s)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const s=function(t){const e=new Set,n=new Set,o=ta(t);for(const[t,s]of Object.entries(o))"function"==typeof s.get&&e.add(t),"function"==typeof s.set&&n.add(t);return{getterPaths:e,setterPaths:n}}(e);for(const t of s.getterPaths)this._getterPaths.add(t);for(const t of s.setterPaths)this._setterPaths.add(t);var r;Ai(this),wi(r=this),gi(r),yi.delete(r),Si(this,e),this._listKeys=function(t){const e=t[T];if(void 0===e)return null;"object"==typeof e&&null!==e||et(`${T} must be an object mapping list paths to key specs.`);const s=new Map;for(const[t,r]of Object.entries(e)){0===t.length&&et(`${T} entry path must be a non-empty string.`);const e=t.split(n);e.some(t=>0===t.length)&&et(`${T} entry "${t}" must not contain empty path segments.`),e[e.length-1]===o&&et(`${T} entry "${t}" must be the list path itself, not the element path (drop the trailing "${n}${o}").`),"function"!=typeof r?("string"!=typeof r&&et(`${T} entry "${t}" key spec must be a field name (string) or a function.`),0===r.length&&et(`${T} entry "${t}" key field name must be a non-empty string.`),(r.includes(n)||r.includes(o))&&et(`${T} entry "${t}" key field name "${r}" must be a flat property name ("${n}" / "${o}" are not allowed).`),r in Object.prototype&&et(`${T} entry "${t}" key field name "${r}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),s.set(t,r)):s.set(t,r)}return s.size>0?s:null}(e),function(t){Ri.delete(t),Oi.delete(t)}(this),function(t){Bi.delete(t)}(this),this._watchPaths=ji(this,e),this._initialized&&null!==this._rootNode&&!t()&&(qi(this),Ei(this),this._streamsStartedGeneration=this._connectGeneration),this._resolveLoading?.()}get name(){return this._name}_loadFromSsrElement(){if(!this.hasAttribute("enable-ssr"))return null;const t=this.getAttribute("name")||"default",e=this.parentNode;if(!e)return null;const n=Er.findByName(e,t);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const n=t()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const t=this.getAttribute("state");this._state=function(t){const e=document.getElementById(t);if(e&&"application/json"===e.type)try{return JSON.parse(e.textContent||"{}")}catch(t){et("Failed to parse JSON from script element:"+t)}return{}}(t)}else if(this.hasAttribute("src")){const t=this.getAttribute("src");t&&t.endsWith(".json")?this._state=await async function(t){try{const e=await fetch(t);return e.ok||et(`Failed to fetch JSON file: ${e.statusText}`),await e.json()}catch(t){return console.error("Failed to load JSON file:",t),{}}}(t):t&&t.endsWith(".js")?this._state=await ri(t):et(`Unsupported src file type: ${t}`)}else if(this.hasAttribute("json")){const t=this.getAttribute("json");this._state=JSON.parse(t)}else{const t=this.querySelector('script[type="module"]');if(t)this._state=await si(t,`${this._name}`);else{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${e.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(t)}}}catch(t){et(`Failed to initialize state: ${t}`)}if(null!==n&&this.__state)for(const[t,e]of Object.entries(n)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=e}await this._loadingPromise,this._name=this.getAttribute("name")||"default",zr(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const t=this.parentNode,n=t instanceof ShadowRoot?t.host:t instanceof Element?t:null,o=n?G(n):null;null!==n&&null!==o||et(`"bind-component" requires <${e.tagNames.state}> to be a direct child of a custom element.`),t instanceof ShadowRoot||this.hasAttribute("name")||et('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=["state","src","json"].filter(t=>this.hasAttribute(t));null!==this.querySelector('script[type="module"]')&&s.push('<script type="module">'),s.length>0&&et(`"bind-component" cannot be combined with ${s.join(", ")}. The component's "${this.getAttribute("bind-component")}" property is the only state source.`);const r=this.getAttribute("bind-component");await customElements.whenDefined(o.toLowerCase()),n.hasAttribute(e.bindAttributeName)&&await B(n),r in n||et(`Component does not have property "${r}" for state binding.`);const i=n[r];"object"==typeof i&&null!==i||et(`Component property "${r}" is not an object for state binding.`),this._boundComponent=n,this._boundComponentStateProp=r,tl(this,this._boundComponent,this._boundComponentStateProp,i)}}_initializeLightDomComponentScope(){const t=this._boundComponent;null!==t&&this.parentNode===t&&t.hasAttribute(e.bindAttributeName)&&(Nr(this._rootNode,t),er(t,null))}_reloadMappedPathsAfterReconnect(){if(!this._hasMappedComponentState||null===this._boundComponent)return;const t=function(t){const e=Jn.get(t);if(void 0===e)return[];const n=[];for(const t of e)n.push(t.innerAbsPathInfo.pathInfo.path);return n}(this._boundComponent);!function(t){const e=Jn.get(t);if(void 0===e)return;const n=new Map,o=new Map;for(const t of e)n.set(t.innerAbsPathInfo,t.outerAbsPathInfo),o.set(t.outerAbsPathInfo,t.innerAbsPathInfo);Gn.set(t,n),Kn.set(t,o)}(this._boundComponent),this.createState("readonly",e=>{for(const n of t)e.$postUpdate(n)})}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{N in t&&await t[te]()})}async _initializeDCC(t,n){let o;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?o=await ri(t):et(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?o=await si(e,t.tagName.toLowerCase()):et(`DCC: No state source found for "${t.tagName.toLowerCase()}".`)}}catch(t){et(`DCC: Failed to load state: ${t}`)}!function(t,n,o){const s=t.tagName.toLowerCase();s.includes("-")||et(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s)&&et(`DCC: "${s}" is already registered. A custom element name can only be defined once.`);const r=document.createElement("template");r.innerHTML=n.innerHTML;const i=n.mode,{bindables:a,commands:l,streamBackedBindables:c}=oa(o),d=a.length>0||l.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const s=n.map(t=>({name:t,async:!0}));return{...o,commands:s}}(s,a,l):null,u=a.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(s,a):{},f=`${e.tagNames.state}:not([name])`,h=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=d;static bindableEventMap=u;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(D))return null;this._shadow=this.attachShadow({mode:h.shadowRootMode}),this._shadow.appendChild(h.template.content.cloneNode(!0));const t=K();return null!==t&&J(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(h.bindableEventMap).length>0){const n=t.querySelector(f);n?n.setBindableEventMap(h.bindableEventMap):console.warn(`[@wcstack/state] DCC: "${s}" declares ${$} but its template has no <${e.tagNames.state}> without a "name" attribute. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(f)??null}},p=ta(o);for(const[t,e]of Object.entries(p)){if(Zi(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=Qi(t,o)}else n.get=Xi(t),n.set=Yi(t);Object.defineProperty(h.prototype,t,n)}for(const t of c)Object.defineProperty(h.prototype,t,{configurable:!0,enumerable:!0,get:Xi(t),set:Yi(t)});customElements.define(s,h)}(t,n,o),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",t=>{S in t&&t[ee]()})}async connectedCallback(){this._rootNode=this.getRootNode();const n=++this._connectGeneration;if(this._initialized)this._dcc||Br(this._rootNode,this._name)===this||(zr(this._rootNode,this._name,this),this._reloadMappedPathsAfterReconnect());else{const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(D))return this.hasAttribute("bind-component")&&et(`"bind-component" cannot be used inside a [${D}] host. DCC state comes from the template, not from a component property.`),void await this._initializeDCC(t.host,t);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._initializeLightDomComponentScope(),this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!t()||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr"))try{await Fr(this.rootNode);const t=this.getAttribute("name")||"default",n=Er.extractStateData(this),o=document.createElement(e.tagNames.ssr);o.setAttribute("name",t),o.setAttribute("version",xr),Er.buildContent(o,n),this.parentNode?.insertBefore(o,this)}catch(t){throw this._rejectConnectedCallback?.(t),t}t()||null===this._rootNode||n!==this._connectGeneration||qi(this),t()||null===this._rootNode||n!==this._connectGeneration||this._streamsStartedGeneration===n||Ei(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{zr(this.rootNode,this._name,null),t=this,ai.delete(t),function(t){ci.delete(t)}(this),Xe(this),wi(this),Ai(this),function(t){Ri.delete(t)}(this),this._rootNode=null}var t}get initialized(){return this._initialized}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get watchPaths(){return this._watchPaths}get elementPaths(){return this._elementPaths}get getterPaths(){return this._getterPaths}get setterPaths(){return this._setterPaths}get loopContextStack(){return this._loopContextStack}get dynamicDependency(){return this._dynamicDependency}get staticDependency(){return this._staticDependency}get version(){return this._version}get rootNode(){return null===this._rootNode&&et("State rootNode is not available."),this._rootNode}get hasRootNode(){return null!==this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get boundComponent(){return this._boundComponent}get hasMappedComponentState(){return this._hasMappedComponentState}markComponentStateMapped(){this._hasMappedComponentState=!0}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(t){this._bindableEventMap=t}_addDependency(t,e,n){const o=t.get(e);return void 0===o?(t.set(e,[n]),!0):!o.includes(n)&&(o.push(n),!0)}addDynamicDependency(t,e){return this._addDependency(this._dynamicDependency,t,e)}addStaticDependency(t,e){return this._addDependency(this._staticDependency,t,e)}setPathInfo(t,e){if("for"===e){const e=!this._listPaths.has(t);this._listPaths.add(t),this._elementPaths.add(t+"."+o),e&&this._hasMappedComponentState&&function(t,e){const n=to(t,U(e));null!==n&&n.stateElement!==t&&n.stateElement.setPathInfo(n.pathInfo.path,"for")}(this,t)}if(!this._pathSet.has(t)){const e=U(t);if(this._pathSet.add(t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=U(t.parentPath)}}}_createState(t,e,n){try{const o=function(t,e,n,o){const s=new Ja(t,n,o);return new Proxy(e,s)}(t,this._state,this._name,e);return n(o)}finally{}}async createStateAsync(t,e){return await this._createState(this.rootNode,t,e)}createState(t,e){this._createState(this.rootNode,t,e)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(t){this._crossRowListPaths.add(t)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(t){this._indexDependentGetterPaths.add(t)}bindProperty(t,e){Object.defineProperty(this._state,t,e),t===I&&(this._hasUpdatedCallback=!0)}setInitialState(t){this._initialized?this._state=t:this._resolveSetState?.(t)}}function nl(){customElements.get(e.tagNames.ssr)||customElements.define(e.tagNames.ssr,Er),customElements.get(e.tagNames.state)||customElements.define(e.tagNames.state,el)}await(nl(),void ni());
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|