@wcstack/state 1.8.1 → 1.8.4

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.
@@ -1,2 +1,2 @@
1
- let t=null;function e(){if(null!==t)return t;const e=document.querySelector("html");return t=!!e&&e.hasAttribute("data-wcs-server"),t}const n={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},o=n;function s(){return o}const r="1.8.1";function i(t){throw new Error(`[@wcstack/state] ${t}`)}const a=new WeakMap;let l=0;function c(t){let e,n=a.get(t)||null;if(null!==n)return n;const o=new Promise(t=>{e=t});return n={id:++l,promise:o,resolve:e},a.set(t,n),n}async function d(t){const e=c(t);await e.promise}function u(t){c(t).resolve()}function f(t){const e=t.node,n=t.replaceNode;e!==n&&null!==e.parentNode&&e.parentNode.replaceChild(n,e)}function p(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}function h(t,e){const n=[];for(const o of e)if("text"!==o.bindingType)n.push({...o,node:t,replaceNode:t});else{const e=document.createTextNode("");n.push({...o,node:t,replaceNode:e})}return n}const m=new WeakMap;function g(t){return m.get(t)||null}function b(t,e){m.set(t,e)}const w=".",y="*",N=128,x={};for(let t=0;t<128;t++)x[`$${t+1}`]=t;const S=Object.freeze(x),I="$connectedCallback",_="$disconnectedCallback",P="$stateReadyCallback",v="$bindables",A="data-wc-definition",C=new Map;let $=0;function E(t){let e=C.get(t);return void 0!==e||(e=Object.freeze(new k(t)),C.set(t,e)),e}class k{id=++$;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("."),o=[],s=[],r=[],i={},a=[],l=[],c=[],d=[];let u="",f="",p=0;for(let t=0;t<n.length;t++)u+=n[t],n[t]===y&&(r.push(u),i[u]=p,a.push(e(u)),l.push(f),c.push(e(f)),d.push(t),p++),o.push(u),s.push(e(u)),f=u,u+=".";const h=r.length>0?r[r.length-1]:null,m=o.length>1?o[o.length-2]:null;this.path=t,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=o,this.cumulativePathSet=new Set(o),this.cumulativePathInfos=s,this.cumulativePathInfoSet=new Set(s),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=i,this.wildcardPathInfos=a,this.wildcardPathInfoSet=new Set(a),this.wildcardParentPaths=l,this.wildcardParentPathSet=new Set(l),this.wildcardParentPathInfos=c,this.wildcardParentPathInfoSet=new Set(c),this.wildcardPositions=d,this.lastWildcardPath=h,this.lastWildcardInfo=h?e(h):null,this.parentPath=m,this.parentPathInfo=m?e(m):null,this.wildcardCount=p}}const M=new Set(["if","elseif","else","for"]);function T(t){i(`filter ${t} requires at least one option`)}function O(t){i(`filter ${t} requires a number as option`)}function W(t){i(`filter ${t} requires a number value`)}function L(t){i(`filter ${t} requires a date value`)}function D(t){return!(!t||isNaN(Number(t)))}const R={eq:t=>{const e=t?.[0]??T("eq");return t=>"number"==typeof t?(D(e)||O("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??T("ne");return t=>"number"==typeof t?(D(e)||O("ne"),t!==Number(e)):t!==e},not:t=>t=>("boolean"!=typeof t&&i(`filter ${"not"} requires a boolean value`),!t),lt:t=>{const e=t?.[0]??T("lt");return D(e)||O("lt"),t=>("number"!=typeof t&&W("lt"),t<Number(e))},le:t=>{const e=t?.[0]??T("le");return D(e)||O("le"),t=>("number"!=typeof t&&W("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??T("gt");return D(e)||O("gt"),t=>("number"!=typeof t&&W("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??T("ge");return D(e)||O("ge"),t=>("number"!=typeof t&&W("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??T("inc");return D(e)||O("inc"),t=>("number"!=typeof t&&W("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??T("dec");return D(e)||O("dec"),t=>("number"!=typeof t&&W("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??T("mul");return D(e)||O("mul"),t=>("number"!=typeof t&&W("mul"),t*Number(e))},div:t=>{const e=t?.[0]??T("div");return D(e)||O("div"),t=>("number"!=typeof t&&W("div"),t/Number(e))},mod:t=>{const e=t?.[0]??T("mod");return D(e)||O("mod"),t=>("number"!=typeof t&&W("mod"),t%Number(e))},fix:t=>{const e=t?.[0]??"0";return D(e)||O("fix"),t=>("number"!=typeof t&&W("fix"),t.toFixed(Number(e)))},locale:t=>{const e=t?.[0]??o.locale;return t=>("number"!=typeof t&&W("locale"),t.toLocaleString(e))},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]??T("slice");D(n)||O("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(D(o)||O("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??T("substr");D(e)||O("substr");const n=t?.[1]??T("substr");return D(n)||O("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??T("pad");D(e)||O("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??T("rep");return D(e)||O("rep"),t=>String(t).repeat(Number(e))},rev:t=>t=>String(t).split("").reverse().join(""),int:t=>t=>parseInt(String(t),10),float:t=>t=>parseFloat(String(t)),round:t=>{const e=t?.[0]??"0";return D(e)||O("round"),t=>{"number"!=typeof t&&W("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return D(e)||O("floor"),t=>{"number"!=typeof t&&W("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return D(e)||O("ceil"),t=>{"number"!=typeof t&&W("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return D(e)||O("percent"),t=>("number"!=typeof t&&W("percent"),`${(100*t).toFixed(Number(e))}%`)},date:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("date"),t.toLocaleDateString(e))},time:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("time"),t.toLocaleTimeString(e))},datetime:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("datetime"),t.toLocaleString(e))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||L("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}`}},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]??T("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},F=R,B={input:R,output:F},j=(t,e)=>n=>{const o=n[t];return o||i(`filter not found: ${t}`),o(e)};const q=new Map;function z(t,e){const n=B[e];return t.map(t=>{const o=t.indexOf("("),s=t.lastIndexOf(")");if(-1!==o&&-1===s&&i(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==s&&-1===o&&i(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===o){const o=t.trim(),s=`${o}():${e}`;let r=q.get(s);return void 0===r&&(r=j(o,[])(n),q.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;for(let r=0;r<t.length;r++){const i=t[r];o?i===o?o=null:n+=i:'"'===i||"'"===i?(o=i,s=!0):","===i?(e.push(n.trim()),n="",s=!1):n+=i}const r=n.trim();return(r||s)&&e.push(r),e}(r),l=`${i}(${a.join(",")}):${e}`;let c=q.get(l);return void 0===c&&(c=j(i,a)(n),q.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const H=t=>t.trim(),U=new Map;const V=new Map;function J(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),V.has(s)?r=V.get(s):(o=s.split("|").map(H),r=z(o,"output"),V.set(s,r))):n=t.trim();const[i,a="default"]=n.split("@").map(H);return{stateName:a,statePathName:i,statePathInfo:E(i),outFilters:r}}function X(t){const[...e]=t.split(";").map(H).filter(t=>t.length>0),n=e.map(t=>{const e=t.indexOf(":");-1===e&&i(`Invalid bindText: "${t}". Missing ':' separator between propPart and statePart.`);const n=t.slice(0,e).trim(),o=t.slice(e+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:E("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("if"===n||"elseif"===n||"for"===n||"radio"===n||"checkbox"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...J(o),bindingType:n}}{const t=J(o),e=function(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),U.has(s)?r=U.get(s):(o=s.split("|").map(H),r=z(o,"input"),U.set(s,r))):n=t.trim();const[i,a]=n.split("#").map(H),l=i.split(".").map(H);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(H):[],inFilters:r}}(n);return e.propSegments[0].startsWith("on")?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(n.length>1){n.some(t=>M.has(t.bindingType))&&i(`Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const K=new WeakMap,Y=new Set([o.commentTextPrefix,o.commentForPrefix,o.commentIfPrefix,o.commentElseIfPrefix,o.commentElsePrefix]),G=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function Q(t){const e=K.get(t);if("string"==typeof e)return e;if(t.nodeType!==Node.COMMENT_NODE)return null;const n=t.data.trim(),s=G.exec(n);if(null===s)return null;const r=s[1]||o.commentTextPrefix;return Y.has(r)?(K.set(t,s[2]),s[2]):null}function Z(t){if(t.nodeType===Node.ELEMENT_NODE){return X(t.getAttribute(o.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=Q(t);null===e&&i("Comment node binding text not found.");const n=eo(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...J(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function tt(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(o.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==Q(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}const et=new WeakSet;function nt(t){const e=tt(t),n=[];for(const t of e)if(!et.has(t)){et.add(t);const e=h(t,Z(t));b(t,e),u(t),n.push(...e)}return[e,n]}const ot=new WeakMap;function st(t){let e=t;for(;e;){const t=ot.get(e);if(t)return t;e=e.parentNode}return null}function rt(t,e){null!==e?ot.set(t,e):ot.delete(t)}const it=Symbol("$$setLoopContextAsync"),at=Symbol("$$setLoopContext"),lt=Symbol("$$getByAddress"),ct=Symbol("$$setByAddress"),dt=Symbol("$$connectedCallback"),ut=Symbol("$$disconnectedCallback"),ft=Symbol("$$updatedCallback"),pt=new Map,ht=new Map;function mt(t){if(!t.propName.startsWith("on"))return!1;const e=function(t){const e=t.propModifiers.filter(t=>"prevent"===t||"stop"===t).sort().join(",");return`${t.stateName}::${t.statePathName}::${e}`}(t);let n=pt.get(e);var o,s,r;void 0===n&&(o=t.stateName,s=t.statePathName,r=t.propModifiers,n=t=>{r.includes("prevent")&&t.preventDefault(),r.includes("stop")&&t.stopPropagation();const e=t.target,n=Yn(e.getRootNode(),o);null===n&&i(`State element with name "${o}" not found for event handler.`);const a=st(e);n.createStateAsync("writable",async e=>{e[at](a,()=>{const n=e[s];return"function"!=typeof n&&i(`Handler "${s}" is not a function on state "${o}".`),Reflect.apply(n,e,[t,...a?.listIndex.indexes??[]])})})},pt.set(e,n));const a=t.propName.slice(2);t.node.addEventListener(a,n);let l=ht.get(e);return void 0===l?(l=new Set([t]),ht.set(e,l)):l.add(t),!0}const gt=new WeakMap;function bt(t){const e=gt.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{gt.set(t,n)}}const wt=new Set(["radio","checkbox"]),yt=new Set(["value","valueAsNumber","valueAsDate"]);const Nt=new Map,xt=new Map,St=t=>t.detail;function It(t){const e=bt(t.node);if(null!==e){if(void 0===customElements.get(e))return void customElements.whenDefined(e).then(()=>{It(t)})}if(function(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(wt.has(t)&&"checked"===e)return!0;if(yt.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=bt(n);if(null!==s){const t=customElements.get(s);void 0===t&&i(`Custom element <${s}> is not defined. Cannot determine if property "${e}" is suitable for two-way binding.`);const n=t.wcBindable;if("wc-bindable"===n?.protocol&&1===n?.version&&n.properties.some(t=>t.name===e))return!0}return!1}(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";const n=bt(t.node);if(null!==n){const o=customElements.get(n);void 0===o&&i(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=o.wcBindable;if("wc-bindable"===s?.protocol&&1===s?.version){const n=s.properties.find(e=>e.name===t.propName);n&&(e=n.event)}}for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t){const e=bt(t.node);if(null!==e){const n=customElements.get(e);if(n){const e=n.wcBindable;if("wc-bindable"===e?.protocol&&1===e?.version){const n=e.properties.find(e=>e.name===t.propName);if(n)return n.getter??St}}}return null}(t),o=function(t,e,n){const o=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${o}::${n?"g":"n"}`}(t,e,null!==n);let s=Nt.get(o);void 0===s&&(s=((t,e,n,o,s)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(r);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=Yn(a.getRootNode(),t);null===d&&i(`State element with name "${t}" not found for two-way binding.`);const u=st(a);d.createState("writable",t=>{t[at](u,()=>{t[n]=c})})})(t.stateName,t.propName,t.statePathName,t.inFilters,n),Nt.set(o,s)),t.node.addEventListener(e,s);let r=xt.get(o);void 0===r?(r=new Set([t]),xt.set(o,r)):r.add(t)}}const _t=new WeakMap;function Pt(t){return _t.get(t)??[]}function vt(t,e){_t.set(t,e)}const At=new WeakMap;function Ct(t,e){if(At.has(t)){const n=At.get(t);if(n.has(e))return n.get(e)}else At.set(t,new WeakMap);const n=Object.freeze(new $t(t,e));return At.get(t).set(e,n),n}class $t{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=Ct(t,e.parentPathInfo)}}const Et=new WeakMap,kt=new WeakMap;class Mt{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]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=Tt(t,e)}}function Tt(t,e){if(null===e){let e=kt.get(t);return void 0!==e||(e=new Mt(t,null),kt.set(t,e)),e}{let n=Et.get(e);void 0===n&&(n=new WeakMap,Et.set(e,n));let o=n.get(t);return void 0!==o||(o=new Mt(t,e),n.set(t,o)),o}}const Ot=new WeakMap;function Wt(t,e){null===e?Ot.delete(t):Ot.set(t,e)}function Lt(t){return Ot.get(t)||null}const Dt=new Map;function Rt(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=Dt.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Dt.set(s,r),r}const Ft=new WeakMap;function Bt(t){const e=st(t.node);if(null===e)return null;let n=Ft.get(e);if(void 0===n)n=new WeakMap,Ft.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=Rt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const jt=new WeakMap;function qt(t){let e=null;if(e=jt.get(t)||null,null!==e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Lt(n);null===e?i(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}const o=Bt(t),s=Yn(n,t.stateName);null===s&&i(`State element with name "${t.stateName}" not found for binding.`);return e=Tt(Ct(s,t.statePathInfo),o),jt.set(t,e),e}function zt(t){jt.delete(t)}const Ht=new WeakMap;function Ut(t,e){const n=Ht.get(t);return!!n&&!0===n.get(e)}function Vt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Jt=Object.freeze([]);const Xt=new WeakMap,Kt=new WeakMap;class Yt{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]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=Gt(t,e)}}function Gt(t,e){if(null===e){let e=Kt.get(t);return void 0!==e||(e=new Yt(t,null),Kt.set(t,e)),e}{let n=Xt.get(e);void 0===n&&(n=new WeakMap,Xt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Yt(t,e),n.set(t,o)),o}}const Qt=new WeakMap;function Zt(t){return Qt.get(t)??[]}function te(t,e){Qt.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 ee=0;function ne(){return`u${(ee++).toString(36)}`}let oe=0;class se{uuid=ne();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=oe}get index(){return this._index}set index(t){this._index=t,this._version=++oe,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=oe),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 re(t,e){return new se(t,e)}const ie=new WeakMap;function ae(t){return ie.get(t)||null}function le(t,e){null!==e?ie.set(t,e):ie.delete(t)}const ce=new WeakMap,de=Object.freeze([]),ue=new Set;function fe(t,e,n){const o=Array.isArray(e)&&e.length>0?e:de,s=Array.isArray(n)&&n.length>0?n:de,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:de,o=Array.isArray(e)&&e.length>0?e:de;let s=ce.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=ae(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:ue,deleteIndexSet:new Set(i),addIndexSet:ue};let e=ae(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=re(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:ue,deleteIndexSet:ue,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:ue,deleteIndexSet:ue,addIndexSet:ue};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)}if(null!==e)return function(t,e,n,o,s){const r=new Set(o),i=new Set(n),a=new Set,l=r.difference(i),c=i.difference(r);for(let t=0;t<e.length;t++){const o=e[t],r=s.get(o),i=r&&r.length>0?r.shift():void 0;if(void 0!==i){const e=n[i];e.index!==t&&a.add(e)}}return{oldIndexes:n,newIndexes:o,changeIndexSet:a,deleteIndexSet:c,addIndexSet:l}}(0,s,i,e,n);e=[];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=re(t,o);e.push(n),l.add(n)}else{const t=i[d];t.index!==o&&(t.index=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=ce.get(t);o||(o=new WeakMap,ce.set(t,o)),o.set(e,n)}(o,s,a),le(s,a.newIndexes))}}const pe=new WeakMap;function he(t){let e=null;return e=pe.get(t)||null,null===e&&(e=new Set,pe.set(t,e)),e}function me(t,e){he(t).add(e)}function ge(t,e){he(t).delete(e)}const be=new WeakMap;function we(t){be.delete(t)}const ye=new WeakMap;function Ne(t){return ye.get(t)??[]}function xe(t,e){ye.set(t,e)}const Se=new WeakMap;function Ie(t){return Se.get(t)??[]}function _e(t,e){Se.set(t,e)}function Pe(t,e){const n=Ie(t);for(const t of n)rt(t,e)}function ve(t,e,n){Pe(t,e);const o=Ne(t);for(const t of o){me(qt(t),t),cn(t,n)}}function Ae(t){if(!t.mounted)return;const e=Ne(t);for(const t of e){ge(qt(t),t),zt(t),we(t)}!function(t){const e=Ie(t);for(const t of e)rt(t,null)}(t)}const Ce=new WeakMap,$e=Object.freeze(new Set);function Ee(t,e){const n=Ce.get(t);n?n.add(e):Ce.set(t,new Set([e]))}function ke(t){const e=Ce.get(t);return void 0!==e?e:$e}const Me=new Set(["if","elseif","else","for"]);class Te{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;constructor(t){this._content=t,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)t.appendChild(e);this._mounted=!0}mountAfter(t){const e=t.parentNode,n=t.nextSibling;if(e)for(const t of this._childNodeArray)e.insertBefore(t,n);this._mounted=!0}unmount(){for(const t of this._childNodeArray)null!==t.parentNode&&t.parentNode.removeChild(t);const t=Ne(this);for(const e of t){if(Me.has(e.bindingType)){const t=ke(e.node);for(const e of t)e.unmount()}we(e),zt(e)}this._mounted=!1}}function Oe(t){const e=document.createDocumentFragment(),n=new Te(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 We(t){void 0!==t.uuid&&null!==t.uuid||i("BindingInfo.uuid is null.");const e=eo(t.uuid);e||i(`Fragment with UUID "${t.uuid}" not found.`);const n=document.importNode(e.fragment,!0),o=function(t,e){const[n,o]=function(t,e){const n=[],o=[];for(const s of e){const e=p(t,s.nodePath);if(null===e&&i(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),!et.has(e)){et.add(e);const t=h(e,s.parseBindTextResults);b(e,t),u(e),o.push(...t),n.push(e)}}return[n,o]}(t,e);return yn(o),{nodes:n,bindingInfos:o}}(n,e.nodeInfos),s=new Te(n);xe(s,o.bindingInfos);const r=[];for(const t of o.bindingInfos)t.statePathName in S&&r.push(t);return te(s,r),_e(s,o.nodes),Ee(t.node,s),s}const Le=new WeakMap,De=new WeakMap,Re=new WeakMap,Fe=new WeakMap;function Be(t,e,n){Ue(t,e,n)}function je(t,e){Le.set(t,e)}function qe(t){return Re.get(t.node)||[]}function ze(t,e){const n=Re.get(t.node);void 0===n?Re.set(t.node,[e]):n.push(e)}function He(t,e){let n=De.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ue(t,e,n){let o=De.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,De.set(t,o)}null===n?o.delete(e):o.set(e,n)}const Ve=new WeakMap;function Je(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Xe(t,n,s){const r=t.node.isConnected,i=Boolean(s);let a;const l=ke(t.node);a=0===l.size?We(t):l.values().next().value;const c=e(),d=t.uuid??"",u=t.bindingType;try{if(i||(o.debug&&console.log(`unmount if content : ${Je(t)}`),Ae(a),a.unmount()),i){if(o.debug&&console.log(`mount if content : ${Je(t)}`),c){const e=document.createComment(`@@wcs-${u}-start:${d}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),a.mountAfter(e);const n=document.createComment(`@@wcs-${u}-end:${d}:${t.statePathName}`),o=a.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else a.mountAfter(t.node);ve(a,st(t.node),n)}}finally{Ve.set(t.node,r)}}const Ke=new WeakMap;function Ye(t){return Ke.get(t)??[]}const Ge=new Set;const Qe={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 Ze(t,n,s){const r=t.node,i=t.propSegments;if(1===i.length){const t=i[0];if(r[t]!==s)try{r[t]=s}catch(e){o.debug&&console.warn(`Failed to set property '${t}' on element.`,{element:r,newValue:s,error:e})}if(e()){const e=Qe[t];e?e(r,s):(!function(t,e,n){let o=Ke.get(t);o||(o=[],Ke.set(t,o));const s=o.find(t=>t.propName===e);s?s.value=n:o.push({propName:e,value:n})}(r,t,s),a=r,Ge.add(a))}return}var a;let l=r[i[0]];for(let t=1;t<i.length-1;t++){const e=i[t];if(null==l)return;l=l[e]}const c=l[i[i.length-1]];if(c!==s){if(Object.isFrozen(l))return void(o.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:i,oldValue:c,newValue:s}));try{l[i[i.length-1]]=s}catch(t){o.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:c,newValue:s,error:t})}}}const tn=new WeakSet;function en(t,e,n){const o=t.node,s=t.propSegments;s.length<=1&&i(`Invalid propSegments for web component binding: ${s.join(".")}`);const[r,...a]=s,l=o[r];void 0===l&&i(`Property "${r}" not found on web component.`),l[a.join(".")]=n}function nn(t,e){const n=function(t){let e=null;if(e=be.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=Bt(t);null===n&&i(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=Gt(t.statePathInfo,n)}else e=Gt(t.statePathInfo,null);return be.set(t,e),e}(e);if(n.pathInfo.path in S){const t=st(e.node);return null===t&&i(`ListIndex not found for binding: ${e.statePathName}`),function(t,e){null===t.listIndex&&i("ListIndex not found for loopContext:");const n=S[e];void 0===n&&i(`Invalid index name: ${e}`);const o=t.listIndex.at(n);return null===o&&i(`Index not found at position ${n} for loopContext:`),o.index}(t,n.pathInfo.path)}return t[lt](n)}const on={class:function(t,e,n){const o=t.node,s=t.propSegments[1];"boolean"!=typeof n&&i("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)}},sn={text:function(t,n,o){if(t.replaceNode.nodeValue!==o&&(t.replaceNode.nodeValue=o),e()&&!tn.has(t.replaceNode)){tn.add(t.replaceNode);const e=t.replaceNode.parentNode;if(e){const n=t.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);e.insertBefore(o,t.replaceNode),e.insertBefore(s,t.replaceNode.nextSibling)}}},for:function(t,n,o){const s=t.statePathInfo,r=Bt(t),a=qt(t),l=Pt(a),c=fe(r,l,o);if(n.newListValueByAbsAddress.set(a,Array.isArray(o)?o:[]),Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0&&null!==t.node.parentNode){let e=Fe.get(t.node);if(void 0===e){const n=Le.get(t.node)||t.node;e=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}(t.node,n),Fe.set(t.node,e)}if(e){const e=t.node.parentNode;e.textContent="",e.appendChild(t.node)}}for(const e of c.deleteIndexSet){const n=He(t.node,e);null!==n&&(Ae(n),n.unmount(),ze(t,n),Ue(t.node,e,null))}let d=t.node;const u=E(s.path+"."+y),f=n.stateElement.loopContextStack;let p=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&d.isConnected&&(p=document.createDocumentFragment(),Wt(p,n.rootNode));const h=e(),m=t.uuid??"";for(const e of c.newIndexes){let o;if(c.addIndexSet.has(e)){const r=Gt(u,e);f.createLoopContext(r,r=>{const i=qe(t);if(o=i.pop(),void 0===o&&(o=We(t)),null!==p)h&&p.appendChild(document.createComment(`@@wcs-for-start:${m}:${s.path}:${e.index}`)),o.appendTo(p),h&&p.appendChild(document.createComment(`@@wcs-for-end:${m}:${s.path}:${e.index}`));else{if(d.nextSibling!==o.firstNode){if(h){const t=document.createComment(`@@wcs-for-start:${m}:${s.path}:${e.index}`);d.parentNode.insertBefore(t,d.nextSibling),d=t}o.mountAfter(d)}if(h){const t=document.createComment(`@@wcs-for-end:${m}:${s.path}:${e.index}`),n=o.lastNode??d;n.parentNode.insertBefore(t,n.nextSibling)}}ve(o,r,n)}),void 0===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=He(t.node,e),c.changeIndexSet.has(e)){const t=Zt(o);for(const e of t)cn(e,n)}null===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`),d.nextSibling!==o.firstNode&&o.mountAfter(d)}d=o.lastNode||d,Ue(t.node,e,o)}Le.set(t.node,d),null!==p&&(t.node.parentNode.insertBefore(p,t.node.nextSibling),Wt(p,null))},if:Xe,else:Xe,elseif:Xe,radio:function(t,e,n){const o=t.node,s=Vt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Vt(o.value,t.inFilters),r=Array.isArray(n)?n:Jt;o.checked=r.includes(s)}},rn=new WeakMap,an=new WeakMap;function ln(t,e){const n=Vt(nn(e.state,t),t.outFilters);if(!0===an.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=rn.get(t);if(void 0===o){if(rn.has(t))return Ut(t.replaceNode,e.stateElement)?(o=en,rn.set(t,o)):o=Ze,void o(t,e,n);if(o=sn[t.bindingType],void 0===o){const n=t.propSegments[0];if(o=on[n],rn.set(t,o),void 0===o){bt(t.replaceNode)?Ut(t.replaceNode,e.stateElement)?(o=en,rn.set(t,o)):o=Ze:(o=Ze,rn.set(t,o))}}if(o===Ze){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void an.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function cn(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const n=qt(t);if(e.updatedAbsAddressSetByStateElement.has(e.stateElement)){e.updatedAbsAddressSetByStateElement.get(e.stateElement).add(n)}else e.updatedAbsAddressSetByStateElement.set(e.stateElement,new Set([n]));if("event"===t.bindingType)return;const o=bt(t.replaceNode);if(o&&void 0===customElements.get(o))return;let s=t.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=Lt(s),null===s&&i("Root node for fragment not found for binding.")),t.stateName!==e.stateName||s!==e.rootNode){const n=Yn(s,t.stateName);null===n&&i(`State element with name "${t.stateName}" not found for binding.`),n.createState("readonly",o=>{const r={stateName:t.stateName,rootNode:s,stateElement:n,state:o,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};ln(t,r)})}else ln(t,e)}function dn(t){let e=0;const n=new Set,s=new Map,r=new Map,a=[];for(;e<t.length;){let l=t[e];const c=l.stateName;if(!1===l.replaceNode.isConnected){o.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${l.bindingType} ${l.statePathName} on ${l.node.nodeName}`,l),e++;continue}let d=l.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=Lt(d),null===d&&i("Root node for fragment not found for binding."));const u=Yn(d,c);null===u&&i(`State element with name "${c}" not found for binding.`),u.createState("readonly",o=>{const i={rootNode:d,stateName:c,stateElement:u,state:o,appliedBindingSet:n,newListValueByAbsAddress:s,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:a};for(;;){cn(l,i),e++;const n=t[e];if(!n)break;const o=n.replaceNode.getRootNode();if(n.stateName!==c||o!==i.rootNode)break;l=n}})}for(const{binding:t,value:e}of a)Ze(t,0,e);for(const[t,e]of s.entries())vt(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[ft](Array.from(e))})}const un=new Map,fn=new Map;const pn=(t,e,n)=>o=>{const s=o.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 n)r=t.filterFn(r);const a=Yn(s.getRootNode(),t);null===a&&i(`State element with name "${t}" not found for two-way binding.`);const l=st(s);a.createState("writable",t=>{t[at](l,()=>{t[e]=r})})};function hn(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}(t,e);let o=un.get(n);void 0===o&&(o=pn(t.stateName,t.statePathName,t.inFilters),un.set(n,o)),t.node.addEventListener(e,o);let s=fn.get(n);return void 0===s?(s=new Set([t]),fn.set(n,s)):s.add(t),!0}return!1}const mn=new Map,gn=new Map;const bn=(t,e,n)=>o=>{const s=o.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 a=s.value;for(const t of n)a=t.filterFn(a);const l=Yn(s.getRootNode(),t);null===l&&i(`State element with name "${t}" not found for two-way binding.`);const c=st(s);l.createState("writable",t=>{t[at](c,()=>{let n=t[e];if(Array.isArray(n))if(r)-1===n.indexOf(a)&&(t[e]=n.concat(a));else{const o=n.indexOf(a);-1!==o&&(t[e]=n.toSpliced(o,1))}else t[e]=r?[a]:[]})})};function wn(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}(t,e);let o=mn.get(n);void 0===o&&(o=bn(t.stateName,t.statePathName,t.inFilters),mn.set(n,o)),t.node.addEventListener(e,o);let s=gn.get(n);return void 0===s?(s=new Set([t]),gn.set(n,s)):s.add(t),!0}return!1}function yn(t){for(const e of t)f(e),mt(e)||(It(e),hn(e),wn(e))}function Nn(t,e){const[n,o]=nt(t);for(const t of n)rt(t,e);yn(o);for(const t of o){me(qt(t),t);const e=Yn(t.replaceNode.getRootNode(),t.stateName);null===e&&i(`State element with name "${t.stateName}" not found for binding.`),"event"!==t.bindingType&&e.setPathInfo(t.statePathName,t.bindingType)}dn(o)}const xn=/\{\{\s*(.+?)\s*\}\}/g,Sn=new Set(["SCRIPT","STYLE"]);function In(t){if(!o.enableMustache)return;!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&&Sn.has(t.parentElement.tagName)||_n(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),In(e.content)}else In(t.content)}function _n(t){const e=t.data;if(xn.lastIndex=0,!xn.test(e))return;xn.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=xn.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 Pn;function vn(){if(Pn)return Pn;const t=[],e=j("not",t)(F);return Pn={filterName:"not",args:t,filterFn:e},Pn}const An=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Cn(t,e){const n=e+w+y,o=t.indexOf("|"),s=t.indexOf("@");let r,i;if(-1!==o?(r=t.slice(0,o).trim(),i=t.slice(o)):-1!==s?(r=t.slice(0,s).trim(),i=t.slice(s)):(r=t.trim(),i=""),"."===r)r=n;else{if(!r.startsWith("."))return t;r=n+w+r.slice(1)}return i.length>0?r+i:r}function $n(t,e){const n=An.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+Cn(s,e)+r}function En(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=Cn(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function kn(t,e){return En(t,e)}function Mn(t,e){const n=o.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 n=t;n.data=$n(n.data,e);continue}const o=t;if(o instanceof HTMLTemplateElement)continue;const r=o.getAttribute(n);if(null!==r){const t=En(r,e);t!==r&&o.setAttribute(n,t)}}}function Tn(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 On(t){const e=[],n=tt(t);for(const t of n){const n=Z(t);e.push({nodePath:Tn(t),parseBindTextResults:n})}return e}function Wn(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 Ln=new Map([["for",o.commentForPrefix],["if",o.commentIfPrefix],["elseif",o.commentElseIfPrefix],["else",o.commentElsePrefix]]),Dn=vn();function Rn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,Dn],bindingType:t}}function Fn(t,e,n,o){Wn(e),"string"==typeof o&&Mn(e,o),Bn(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:On(e)}}function Bn(t,e,n){const s=o.commentElsePrefix,r=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const e=t;if("template"===e.tagName.toLowerCase()){if((e.getAttribute(o.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let a=null;const l=[],c=[];for(;r.nextNode();){const t=r.currentNode;c.push(t)}for(const e of c){let r=e.getAttribute(o.bindAttributeName)||"";"string"==typeof n&&(r=kn(r,n));let c=X(r)[0];const d=Ln.get(c.bindingType);if(void 0===d)continue;const u=c.bindingType,f=e.content,p=ne();let h=null;const m="for"===u?c.statePathName:n;if("else"===u){null===a&&i("'else' binding found without preceding 'if' or 'elseif' binding."),c=Rn("else",a.parseBindTextResult),h=Fn(t,f,c,m),to(p,t,h);const n=l.at(-1),o=document.createComment(`@@${d}:${p}`);void 0!==n?(e.remove(),n.fragment.appendChild(o),n.nodeInfos.push({nodePath:Tn(o),parseBindTextResults:Z(o)})):e.replaceWith(o)}else if("elseif"===u){null===a&&i("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Fn(t,f,c,m),to(p,t,h);const n=document.createComment(`@@${d}:${p}`),o=ne(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Rn("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:Tn(n),parseBindTextResults:Z(n)}),to(o,t,r);const u=l.at(-1);l.push(r);const g=document.createComment(`@@${s}:${o}`);void 0!==u?(e.remove(),u.fragment.appendChild(g),u.nodeInfos.push({nodePath:Tn(g),parseBindTextResults:Z(g)})):e.replaceWith(g)}else{h=Fn(t,f,c,m),to(p,t,h);const n=document.createComment(`@@${d}:${p}`);e.replaceWith(n)}"if"===u?(l.length=0,a=h):"elseif"===u?a=h:"else"===u&&(a=null,l.length=0)}}async function jn(t){const e=t.querySelectorAll(o.tagNames.state),n=[];await customElements.whenDefined(o.tagNames.state);for(const t of e){const e=t;n.push(e.initializePromise)}await Promise.all(n)}async function qn(t){if(t===document)await jn(document),In(document),Bn(document,document),Nn(document.body,null);else{const e=t;e.host.hasAttribute(o.bindAttributeName)&&await d(e.host),await jn(e),In(e),Bn(e,e),Nn(e,null)}}const zn=new Set(["for","if","elseif","else"]);function Hn(t){if(0===t.length)return{bindingInfos:[],subscriberNodes:[]};const e=t[0].parentNode,n=t[t.length-1].nextSibling,o=document.createElement("div");for(const e of t)o.appendChild(e);const[s,r]=nt(o);for(const t of r)f(t),mt(t)||(It(t),hn(t),wn(t));if(e)for(;o.firstChild;)e.insertBefore(o.firstChild,n);return{bindingInfos:r,subscriberNodes:s}}function Un(t,e,n){const s={for:o.commentForPrefix,if:o.commentIfPrefix,elseif:o.commentElseIfPrefix,else:o.commentElsePrefix}[e];if(!s)return null;const r=`@@${s}:${n}`,i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const t=i.currentNode;if(t.data===r)return t}return null}function Vn(t,e){const n=t;let s=null;for(const[t,r]of e.templates){let e=X(r.getAttribute(o.bindAttributeName)||"")[0];const i=e.bindingType;"else"===i&&s?e={...s,outFilters:[...s.outFilters,vn()],bindingType:"else"}:"elseif"===i&&s&&(e={...e,stateName:s.stateName}),"if"===i||"elseif"===i?s=e:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?e.statePathName:void 0;Wn(a),"string"==typeof l&&Mn(a,l),Bn(n,a,l);to(t,n,{fragment:a,parseBindTextResult:e,nodeInfos:On(a)})}}async function Jn(t){await jn(t);const e=t.querySelectorAll(o.tagNames.ssr);for(const n of e){const e=n;if(!e.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${e.version}", client="${r}". Falling back to full render.`),io.cleanupDom(t),!1}for(const n of e)Vn(t,n);const n=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=oo.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 o of e){if(0===o.nodes.length)continue;const e=Oe(o.nodes),{bindingInfos:s,subscriberNodes:r}=Hn(o.nodes);for(const t of r)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");xe(e,s),_e(e,r);const i=[];for(const t of s)t.statePathName in S&&i.push(t);if(te(e,i),"for"===o.type&&null!==o.index){const r=Un(t,"for",o.uuid);if(r){const t=re(null,o.index);Be(r,t,e),je(r,o.nodes[o.nodes.length-1]),Ee(r,e),Pe(e,Gt(E(o.path+"."+y),t));for(const t of s)me(qt(t),t);let i=n.get(o.uuid);i||(i=[],n.set(o.uuid,i)),i.push(t)}}else{const n=Un(t,o.type,o.uuid);if(n){Ee(n,e);for(const t of s)me(qt(t),t)}}}for(const[e,o]of n){const n=Un(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=eo(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=Yn(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&le(e,o)})}}(document.body,n),io.removeBlockBoundaryComments(document.body);const s=[];for(const t of e)t.parentNode&&(s.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());io.restoreTextBindings(document.body);const[a,l]=nt(document.body);for(const t of a)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(rt(t,null),e.setAttribute("data-wcs-completed",""))}else rt(t,null);const c=[],d=[];for(const t of l)if(f(t),!mt(t))if(It(t),hn(t),wn(t),zn.has(t.bindingType))d.push(t);else{if(t.statePathName.includes(y))continue;c.push(t)}for(const t of[...c,...d]){me(qt(t),t);const e=Yn(t.replaceNode.getRootNode(),t.stateName);null===e&&i(`State element with name "${t.stateName}" not found for binding.`),"event"!==t.bindingType&&e.setPathInfo(t.statePathName,t.bindingType)}for(const t of d)if("for"===t.bindingType){const e=qt(t),n=Yn(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&vt(e,o)})}dn(c);for(const{el:t,parent:e,next:n}of s)e.insertBefore(t,n);const u=t.querySelectorAll(o.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 p=t.querySelectorAll("[data-wcs-completed]");for(const t of p)t.removeAttribute("data-wcs-completed");return!0}const Xn=new WeakMap,Kn=new WeakMap;function Yn(t,e){let n=Xn.get(t);return n&&n.get(e)||null}function Gn(t){return Kn.get(t)??Promise.resolve()}function Qn(t,n,s){let r=Xn.get(t);if(null===s){if(!r)return;r.delete(n),0===r.size&&Xn.delete(t),o.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,Xn.set(t,r);const n=!e()&&s.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{if(n){await Jn(t)||await qn(t)}else await qn(t);e()})});Kn.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await qn(t),e()})});Kn.set(t,e)}}r.has(n)&&i(`State element with name "${n}" is already registered.`),r.set(n,s),o.debug&&console.debug(`State element registered: name="${n}"`,s)}}const Zn=new Map;function to(t,e,n){if(null===n)Zn.delete(t);else{Zn.set(t,n);const o=n.parseBindTextResult,s=Yn(e,o.stateName);null===s&&i(`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=Yn(e,n.stateName);null===t&&i(`State element with name "${n.stateName}" not found for fragment info node.`),t.setPathInfo(n.statePathName,n.bindingType)}}}function eo(t){return Zn.get(t)||null}const no=/^@@wcs-(?:for|if|elseif|else):[^-]/,oo=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,so=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,ro=/^@@wcs-text-start:(.+)$/;class io extends HTMLElement{_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=r.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,e){const n=o.tagNames.ssr,s=t instanceof Element?t:t instanceof Document?t.documentElement:null;if(!s)return null;return s.querySelector(`${n}[name="${e}"]`)}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,e){const n=document.createElement("script");n.setAttribute("type","application/json"),n.textContent=JSON.stringify(e),t.appendChild(n);const s=Array.from(Zn.keys());for(const e of s){const n=eo(e);if(!n)continue;const s=document.createElement("template");s.setAttribute("id",e);const r=n.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(o.bindAttributeName,i);const a=n.fragment.cloneNode(!0);s.content.appendChild(a),t.appendChild(s)}const r=Array.from(Ge);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=Ye(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=JSON.stringify(e),t.appendChild(n)}}Ge.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(oo.test(t.data)||so.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;no.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=ro.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 e=document.body,n=t.querySelectorAll(o.tagNames.ssr),s=new Map;for(const t of n){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(e,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const t=r.currentNode;oo.test(t.data)&&i.push(t)}for(const t of i){const e=oo.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()}io.restoreTextBindings(e);const a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(no.test(t.data)){const e=t.data.split(":")[1];l.push({comment:t,uuid:e})}}for(const{comment:t,uuid:e}of l){const n=s.get(e);if(n){const e=document.createElement("template"),s=n.getAttribute(o.bindAttributeName);s&&e.setAttribute(o.bindAttributeName,s);const r=document.importNode(n.content,!0);if(r.childNodes.length>0)e.content.appendChild(r);else for(const t of Array.from(n.childNodes))e.content.appendChild(document.importNode(t,!0));t.parentNode.replaceChild(e,t)}}const c=t.querySelectorAll("[data-wcs-ssr-id]");for(const t of c)t.removeAttribute("data-wcs-ssr-id");for(const t of n)t.remove()}}async function ao(t,e){let n=null;const o=`\n//# sourceURL=${e}\n`;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}`)}return n&&"object"==typeof n.default?n.default:{}}async function lo(t){try{return(await import(t)).default||{}}catch(t){i(`Failed to load script file: ${t}`)}}class co{_loopContextStack=Array(N).fill(void 0);_length=0;createLoopContext(t,e){null===t.listIndex&&i("Cannot create loop context for a state address that does not have a list index.");const n=t;this._length>=N&&i("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&&i("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&&i("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else 1!==n.pathInfo.wildcardCount&&i("Cannot push loop context for a list with wildcard positions when there is no active loop context.");let s;this._loopContextStack[this._length]=n,this._length++;try{s=e(n)}finally{s instanceof Promise?s.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return s}}function uo(t){return function(){const e=this.stateElement;if(!e)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch{return}return n}}function fo(t){return function(e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})})}}function po(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>n.createStateAsync("writable",async n=>{await n[t](...e)}))}:function(...e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t](...e)})})}}function ho(t){return t.startsWith("$")}const mo=new Map;class go{path;segments;paths;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice(),o=[];let s=0,r=0,i="",a=0,l="none";const c=[];for(let t=0;t<e.length;t++){const l=e[t];if("*"===l)n[t]="*",c.push(null),s++,a++;else{const e=Number(l);Number.isNaN(e)||(n[t]="*",c.push(e),r++,a++)}i+=l,o.push(i),i+=t<l.length-1?".":""}const d=E(n.join("."));(s>0||r>0)&&(l=s===a?"context":r===a?"all":"partial"),this.path=t,this.segments=e,this.paths=o,this.wildcardCount=a,this.wildcardType=l,this.wildcardIndexes=c,this.pathInfo=d}}function bo(t){let e;return mo.get(t)??(mo.set(t,e=new go(t)),e)}const wo=new WeakMap;function yo(t,e){null===e?wo.delete(t):wo.set(t,e)}function No(t){const e=wo.get(t);e&&(e.dirty=!0)}function xo(t,e,n,o,s){if(!(e.pathInfo.path in t)){const s=Io(t,e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),n,o),r=e.pathInfo.segments[e.pathInfo.segments.length-1];if(r===y){const t=e.listIndex?.index??i(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(s,t)}return Reflect.get(s,r)}if(!s.getterPaths.has(e.pathInfo.path))return Reflect.get(t,e.pathInfo.path);o.pushAddress(e);try{return Reflect.get(t,e.pathInfo.path,n)}finally{o.popAddress()}}function So(t,e,n,o,s){const r=Tt(Ct(s,e.pathInfo),e.listIndex),i=function(t){return wo.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=xo(t,e,n,o,s);return yo(r,{value:a,dirty:!1}),a}function Io(t,e,n,o){!function(t,e){if(t.addressStackLength>0){const n=t.lastAddressStack?.pathInfo??null,o=t.stateElement;null!==n&&o.getterPaths.has(n.path)&&n.path!==e.pathInfo.path&&o.addDynamicDependency(e.pathInfo.path,n.path)}}(o,e);const s=o.stateElement;return e.pathInfo.wildcardCount>0||s.getterPaths.has(e.pathInfo.path)?So(t,e,n,o,s):xo(t,e,n,o,s)}function _o(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?.at(o)??null}const Po=new class{_queueAbsoluteAddresses=[];constructor(){}enqueueAbsoluteAddress(t){const e=0===this._queueAbsoluteAddresses.length;this._queueAbsoluteAddresses.push(t),e&&queueMicrotask(()=>{const t=this._queueAbsoluteAddresses;this._queueAbsoluteAddresses=[],this._applyChange(t)})}testApplyChange(t){this._applyChange(t)}_applyChange(t){const e=new Set(t),n=[];for(const t of e){const e=he(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}dn(n)}};function vo(){return Po}const Ao=new WeakMap;function Co(t,e){null===e?Ao.delete(t):Ao.set(t,e)}function $o(t,e,n){const s=E(t.wildcardParentPaths[e]),r=Ct(t.stateElement,s),i=Gt(s,n),a=Pt(Tt(r,n)),l=t.stateProxy[lt](i),c=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 o.debug&&console.log(`Invalid search type: ${e}`),[]}}(fe(i.listIndex,a,l),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...c);else for(const n of c)$o(t,e+1,n)}function Eo(t,e,n,o,s,r,a,l,c){const d={stateElement:e,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:a,searchType:l};return function(t,e,n){const o=[{address:e,depth:0}];for(;o.length>0;){const{address:e,depth:s}=o.pop();if(s>1e3&&i(`Maximum dependency depth of 1000 exceeded. Possible circular dependency detected at path: ${e.pathInfo.path}`),t.visited.has(e))continue;t.visited.add(e),n(e);const r=e.pathInfo.path,a=s+1,l=[],c=t.staticMap.get(r);if(c)for(const n of c){const o=E(n);if(t.listPathSet.has(r)&&o.lastSegment===y){const n=t.stateProxy[lt](e),s=Pt(Tt(Ct(t.stateElement,e.pathInfo),e.listIndex)),r=fe(e.listIndex,s,n);for(const e of r.newIndexes){const n=Gt(o,e);t.result.add(n),l.push({address:n,depth:a})}}else{const n=Gt(o,e.listIndex);t.result.add(n),l.push({address:n,depth:a})}}const d=t.dynamicMap.get(r);if(d)for(const n of d){const o=E(n),s=[];if(o.wildcardCount>0){const n=Rt(e.pathInfo,o);if(o.wildcardCount-n>=1){let r;n>0?(null===e.listIndex&&i(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),r=e.listIndex.at(n-1)):r=null;const a={stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};$o(a,n,r),s.push(...a.targetListIndexes)}else{null===e.listIndex&&i(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`);const t=e.listIndex.at(n-1);s.push(t)}}else s.push(null);for(const e of s){const n=Gt(o,e);t.result.add(n),l.push({address:n,depth:a})}}for(let t=l.length-1;t>=0;t--)o.push(l[t])}}(d,n,c),Array.from(d.result)}function ko(t,e,n,o,s,r){try{if(!(e.pathInfo.path in t)){const n=Io(t,e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),s,r),a=e.pathInfo.segments[e.pathInfo.segments.length-1];if(a===y){const t=e.listIndex?.index??i(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.set(n,t,o)}return Reflect.set(n,a,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e);try{return Reflect.set(t,e.pathInfo.path,o,s)}finally{r.popAddress()}}finally{const t=vo();t.enqueueAbsoluteAddress(n),Eo(r.stateName,r.stateElement,e,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,s,"new",n=>{if(n===e)return;const o=Tt(Ct(r.stateElement,n.pathInfo),n.listIndex);No(o),t.enqueueAbsoluteAddress(o)})}}function Mo(t,e,n,o,s,r){let a=e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Ao.get(t)??null}(a);if(null===l){const e=Io(t,a,s,r)??[],n=ae(e)??[];l={value:[...e],listIndexes:[...n]},Co(a,l)}try{return ko(t,e,n,o,s,r)}finally{const n=l.value.indexOf(o),i=Io(t,a,s,r)??[],c=Array.isArray(i)?ae(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:re(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;Co(a,null)}}}function To(t,e,n,o,s){const r=s.stateElement,i=r.elementPaths.has(e.pathInfo.path),a=e.pathInfo.wildcardCount>0||r.getterPaths.has(e.pathInfo.path),l=Tt(Ct(r,e.pathInfo),e.listIndex);try{return i?Mo(t,e,l,n,o,s):ko(t,e,l,n,o,s)}finally{a&&yo(l,{value:n,dirty:!1});const t=r.bindableEventMap[e.pathInfo.path];if(t){const e=r.rootNode;e instanceof ShadowRoot&&e.host.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0}))}}}function Oo(t,e,n,o){return(e,s,r)=>{const 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)}a.wildcardParentPathInfos.length>s.length&&i(`indexes length is insufficient: ${e}`);let l=null;for(let e=0;e<a.wildcardParentPathInfos.length;e++){const r=a.wildcardParentPathInfos[e],c=Gt(r,l),d=ae(Io(t,c,n,o));null==d&&i(`ListIndexes not found: ${r.path}`);l=d[s[e]]??i(`ListIndex not found: ${r.path}`)}const c=Gt(a,l);if(!(void 0!==r))return Io(t,c,n,o);To(t,c,r,n,o)}}const Wo=new WeakMap;function Lo(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return _o(o,s.wildcardPaths.at(-1)??i(`lastWildcardPath is null: ${e.pathInfo.path}`))??i(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<e.pathInfo.wildcardCount;r++){const a=e.pathInfo.wildcardParentPathInfos[r]??i(`wildcardParentPathInfo is null: ${e.pathInfo.path}`);s=(ae(Io(t,Gt(a,s),n,o))??i(`ListIndex not found: ${a.path}`))[e.wildcardIndexes[r]??i(`wildcardIndex is null: ${e.pathInfo.path}`)]??i(`ListIndex not found: ${a.path}`)}return s}case"partial":i(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Do(t,e,n){void 0!==t.loopContext&&i("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return n()}finally{t.popAddress()}}finally{t.clearLoopContext()}}function Ro(t,e,n,o){const s=S[e];if(void 0!==s){0===o.addressStackLength&&i(`No active state reference to get list index for "${e.toString()}".`);const t=o.lastAddressStack?.listIndex;return t?.indexes[s]??i(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"!==e[0]){const s=bo(e),r=Lo(t,s,n,o),i=Gt(s.pathInfo,r);return Io(t,i,n,o)}switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=Oo(t,0,n,o);return(e,r)=>{const a=new Map,l=E(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==l.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(l.path,t.path)}if(void 0===r){for(let t=0;t<l.wildcardParentPathInfos.length;t++){const e=l.wildcardParentPathInfos[t],n=_o(o,e.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const c=(e,s,r,l,d,u,f)=>{const p=e[s]??null;if(null===p)return void f.push(u);const h=Gt(p,r),m=Wo.get(h),g=Io(t,h,n,o),b=fe(r,m,g).newIndexes,w=l[d]??null;if(a.set(h,g),null===w)for(let t=0;t<b.length;t++){const n=b[t];c(e,s+1,n,l,d+1,u.concat(n.index),f)}else{const t=b[w]??i(`ListIndex not found: ${p.path}`);s+1<e.length?c(e,s+1,t,l,d+1,u.concat(t.index),f):f.push(u.concat(t.index))}},d=[];c(l.wildcardParentPathInfos,0,null,r,0,[],d);const u=[];for(let t=0;t<d.length;t++)u.push(s(l.path,d[t]));for(const[t,e]of a.entries())Wo.set(t,e);return u}}(t,0,n,o)(e,s);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const r=bo(e),i=Lo(t,r,n,o),a=Gt(r.pathInfo,i),l=Tt(Ct(s,a.pathInfo),a.listIndex),c=vo();c.enqueueAbsoluteAddress(l),Eo(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=Tt(Ct(s,t.pathInfo),t.listIndex);No(e),c.enqueueAbsoluteAddress(e)})}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>Oo(t,0,n,o)(e,s,r);case"$trackDependency":return t=>function(t,e,n,o){return t=>{0===o.addressStackLength&&i(`No active state reference to track dependency for path "${t}".`);const e=o.lastAddressStack?.pathInfo??i("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)}}else if("symbol"==typeof e){switch(e){case it:return(t,e=async()=>{})=>async function(t,e,n){return await Do(t,e,n)}(o,t,e);case at:return(t,e=()=>{})=>function(t,e,n){return Do(t,e,n)}(o,t,e);case lt:return e=>Io(t,e,n,o);case ct:return(e,s)=>To(t,e,s,n,o);case dt:return()=>async function(t,e,n){const o=Reflect.get(t,I);"function"==typeof o&&await o.call(n)}(t,0,n);case ut:return()=>function(t,e,n){const o=Reflect.get(t,_);"function"==typeof o&&o.call(n)}(t,0,n);case ft:return e=>function(t,e,n,o){const s=Reflect.get(t,"$updatedCallback");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=n.listIndex.indexes??[],e=r[s];void 0===e?r[s]=[t]:e.push(t)}}return s.call(n,Array.from(t),r)}}(t,e,n,o)}return Reflect.get(t,e,n)}}class Fo{_stateElement;_stateName;_addressStack=Array(N).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,n){this._stateName=e;const o=Yn(t,this._stateName);null===o&&i(`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&&i("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex++,this._addressStackIndex>=N&&i("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&&i(`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(t,e,n){return Ro(t,e,n,this)}set(t,e,n,o){return"readonly"===this._mutability&&i(`State "${this._stateName}" is readonly.`),function(t,e,n,o,s){if("string"==typeof e){const r=bo(e),i=Lo(t,r,o,s);return To(t,Gt(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)}}const Bo=new WeakMap;const jo=new WeakMap;function qo(t,e){const n=jo.get(t);return n?n.get(e)??null:null}const zo=new WeakMap,Ho=new WeakMap,Uo=new WeakMap,Vo=new WeakMap;function Jo(t,e){return{innerAbsPathInfo:Ct(t,E(e.propSegments.slice(1).join(w))),outerAbsPathInfo:qt(e).absolutePathInfo}}function Xo(t,e){let n=zo.get(t);if(void 0===n&&(n=new Map,zo.set(t,n)),n.has(e))return n.get(e);let o=Ho.get(t);void 0===o&&(o=new Map,Ho.set(t,o));const s=Uo.get(t);if(void 0===s)return null;let r=null;for(const t of s)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&i("Duplicate mapping rule for web component."),r=t;break}if(null===r)return null;const a=Vo.get(r);void 0===a&&i("Binding not found for primary mapping rule on web component.");const l=e.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),c=E(r.outerAbsPathInfo.pathInfo.segments.concat(l).join(w)),d=Yn(t.getRootNode(),a.stateName);null===d&&i(`State element with name "${a.stateName}" not found for web component.`);const u=Ct(d,c);n.set(e,u),o.set(u,e);return function(t,e){const n=g(t);null===n?b(t,[e]):n.push(e)}(t,{...a,propName:e.pathInfo.path,propSegments:e.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function Ko(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 Yo{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=qo(t,e)??i("State element not found for web component.")}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=Ct(this._innerStateElement,o),r=Xo(this._webComponent,s);if(null!==r){const t=st(this._webComponent);let e;return r.stateElement.createState("readonly",n=>{n[at](t,()=>{e=n[r.pathInfo.path];let o=null;null!==t&&null!==t.listIndex&&r.pathInfo.wildcardCount>0&&(o=t.listIndex.at(r.pathInfo.wildcardCount-1));!function(t,e){Bo.set(t,e)}(Tt(r,o),e)})}),e}if(e in t)return Reflect.get(t,e,n);i(`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=Ct(this._innerStateElement,s),a=Xo(this._webComponent,r);if(null!==a){const t=st(this._webComponent);return a.stateElement.createState("writable",e=>{e[at](t,()=>{e[a.pathInfo.path]=n})}),!0}if(e in t)return Reflect.set(t,e,n,o);i(`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=Ct(this._innerStateElement,n);return null!==Xo(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class Go{_innerStateElement;constructor(t,e){this._innerStateElement=qo(t,e)??i("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=E(e),n=Tt(Ct(this._innerStateElement,t),null);return o=n,Bo.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=E(e),n=Ct(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class Qo{_innerStateElement;constructor(t,e){this._innerStateElement=qo(t,e)??i("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 Zo=t=>()=>t;function ts(t,e,n,s){if(function(t,e,n){let o=jo.get(t);o||(o=new Map,jo.set(t,o)),o.set(e,n)}(e,n,t),e.hasAttribute(o.bindAttributeName)){const o=(g(e)??[]).filter(t=>t.propSegments[0]===n);!function(t,e,n){if(0===n.length)return;const o=qo(t,e);null===o&&i("State element not found for web component.");const s=new Map,r=new Map;for(const e of n){const n=Jo(o,e);let i=Uo.get(t);void 0===i?Uo.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Vo.set(n,e),s.set(a,l),r.set(l,a)}zo.set(t,s),Ho.set(t,r)}(e,n,o);const s=function(t,e){const n=new Go(t,e);return new Proxy({},n)}(e,n),r=function(t,e){const n=new Yo(t,e),o=qo(t,e);null===o&&i("State element not found for web component."),null===o.boundComponentStateProp&&i("State element is not bound to any component state prop."),o.boundComponentStateProp in t||i(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=t[o.boundComponentStateProp];return"object"==typeof s&&null!==s||i(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Ko(s),n)}(e,n);t.setInitialState(r),Object.defineProperty(e,n,{get:Zo(s),enumerable:!0,configurable:!0})}else{t.setInitialState(Ko(s));const o=function(t,e){const n=new Qo(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:Zo(o),enumerable:!0,configurable:!0})}if(function(t,e){let n=Ht.get(t);n||(n=new WeakMap,Ht.set(t,n)),n.set(e,!0)}(e,t),P in e){const t=e[P];"function"==typeof t?t.call(e,n).catch(t=>{i(`Error in ${P}: ${t instanceof Error?t.message:String(t)}`)}):i(`${P} is not a function.`)}}function es(t){const e=new Set,n=new Set,o=function(t){let e={},n=t;for(;n&&n!==Object.prototype;)Object.assign(e,Object.getOwnPropertyDescriptors(n)),n=Object.getPrototypeOf(n);return e}(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}}class ns extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return Gn(t)}__state;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(){return new co}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise(t=>{this._resolveConnectedCallback=t}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&i(`${o.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){this.__state=t,this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._pathSet.clear();const e=es(t);for(const t of e.getterPaths)this._getterPaths.add(t);for(const t of e.setterPaths)this._setterPaths.add(t);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=io.findByName(e,t);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const t=e()?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){i("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||i(`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 lo(t):i(`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 ao(t,`${this._name}`);else{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${o.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(t)}}}catch(t){i(`Failed to initialize state: ${t}`)}if(null!==t&&this.__state)for(const[e,n]of Object.entries(t)){if(e in this.__state){const t=Object.getOwnPropertyDescriptor(this.__state,e);if(t&&(t.get||t.set))continue;if("function"==typeof this.__state[e])continue}this.__state[e]=n}await this._loadingPromise,this._name=this.getAttribute("name")||"default",Qn(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const t=this.parentNode,e=t instanceof ShadowRoot?t.host:t instanceof Element?t:null,n=e?bt(e):null;null!==e&&null!==n||i(`"bind-component" requires <${o.tagNames.state}> to be a direct child of a custom element.`),t instanceof ShadowRoot||this.hasAttribute("name")||i('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=this.getAttribute("bind-component");await customElements.whenDefined(n.toLowerCase()),e.hasAttribute(o.bindAttributeName)&&await d(e),s in e||i(`Component does not have property "${s}" for state binding.`);const r=e[s];"object"==typeof r&&null!==r||i(`Component property "${s}" is not an object for state binding.`),this._boundComponent=e,this._boundComponentStateProp=s,ts(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{I in t&&await t[dt]()})}async _initializeDCC(t,e){let n;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?n=await lo(t):i(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?n=await ao(e,t.tagName.toLowerCase()):i(`DCC: No state source found for "${t.tagName.toLowerCase()}".`)}}catch(t){i(`DCC: Failed to load state: ${t}`)}!function(t,e,n){const s=t.tagName.toLowerCase();if(s.includes("-")||i(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s))return;const r=document.createElement("template");r.innerHTML=e.innerHTML;const a=e.mode,l=Array.isArray(n[v])?n[v]:[],c=l.length>0?function(t,e){return{protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`}))}}(s,l):null,d=l.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(s,l):{},u=`${o.tagNames.state}:not([name])`,f=class extends HTMLElement{static template=r;static shadowRootMode=a;static wcBindable=c;static bindableEventMap=d;_shadow=null;connectedCallback(){if(!this.hasAttribute(A)&&(this._shadow=this.attachShadow({mode:f.shadowRootMode}),this._shadow.appendChild(f.template.content.cloneNode(!0)),Object.keys(f.bindableEventMap).length>0)){const t=this._shadow.querySelector(u);t&&t.initializePromise.then(()=>{t.setBindableEventMap(f.bindableEventMap)})}}get stateElement(){return this._shadow?.querySelector(u)}},p=Object.getOwnPropertyDescriptors(n);for(const[t,e]of Object.entries(p)){if(ho(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=po(t,o)}else n.get=uo(t),n.set=fo(t);Object.defineProperty(f.prototype,t,n)}customElements.define(s,f)}(t,e,n),this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",t=>{_ in t&&t[ut]()})}async connectedCallback(){if(this._rootNode=this.getRootNode(),!this._initialized){const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(A))return void await this._initializeDCC(t.host,t);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!e()||await this._callStateConnectedCallback(),e()&&this.hasAttribute("enable-ssr")){await Gn(this.rootNode);const t=this.getAttribute("name")||"default",e=io.extractStateData(this),n=document.createElement(o.tagNames.ssr);n.setAttribute("name",t),n.setAttribute("version",r),io.buildContent(n,e),this.parentNode?.insertBefore(n,this)}this._resolveConnectedCallback?.()}disconnectedCallback(){null!==this._rootNode&&(this._callStateDisconnectedCallback(),Qn(this.rootNode,this._name,null),this._rootNode=null)}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}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&&i("State rootNode is not available."),this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get bindableEventMap(){return this._bindableEventMap}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&&(this._listPaths.add(t),this._elementPaths.add(t+"."+y)),!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 Fo(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}bindProperty(t,e){Object.defineProperty(this._state,t,e)}setInitialState(t){this._initialized?this._state=t:this._resolveSetState?.(t)}}function os(){customElements.get(o.tagNames.ssr)||customElements.define(o.tagNames.ssr,io),customElements.get(o.tagNames.state)||customElements.define(o.tagNames.state,ns)}function ss(t){var e;t&&((e=t).tagNames&&Object.assign(n.tagNames,e.tagNames),"string"==typeof e.bindAttributeName&&(n.bindAttributeName=e.bindAttributeName),"string"==typeof e.commentTextPrefix&&(n.commentTextPrefix=e.commentTextPrefix),"string"==typeof e.commentForPrefix&&(n.commentForPrefix=e.commentForPrefix),"string"==typeof e.commentIfPrefix&&(n.commentIfPrefix=e.commentIfPrefix),"string"==typeof e.commentElseIfPrefix&&(n.commentElseIfPrefix=e.commentElseIfPrefix),"string"==typeof e.commentElsePrefix&&(n.commentElsePrefix=e.commentElsePrefix),"string"==typeof e.locale&&(n.locale=e.locale),"boolean"==typeof e.debug&&(n.debug=e.debug),"boolean"==typeof e.enableMustache&&(n.enableMustache=e.enableMustache)),os()}function rs(t){return t}export{io as Ssr,r as VERSION,ss as bootstrapState,qn as buildBindings,rs as defineState,Gn as getBindingsReady,s as getConfig};
1
+ let t=null;function e(){if(null!==t)return t;const e=document.querySelector("html");return t=!!e&&e.hasAttribute("data-wcs-server"),t}const n={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},o=n;function s(){return o}const r="1.8.4";function i(t){throw new Error(`[@wcstack/state] ${t}`)}const a=new WeakMap;let l=0;function c(t){let e,n=a.get(t)||null;if(null!==n)return n;const o=new Promise(t=>{e=t});return n={id:++l,promise:o,resolve:e},a.set(t,n),n}async function d(t){const e=c(t);await e.promise}function u(t){c(t).resolve()}function f(t){const e=t.node,n=t.replaceNode;e!==n&&null!==e.parentNode&&e.parentNode.replaceChild(n,e)}function p(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}function h(t,e){const n=[];for(const o of e)if("text"!==o.bindingType)n.push({...o,node:t,replaceNode:t});else{const e=document.createTextNode("");n.push({...o,node:t,replaceNode:e})}return n}const m=new WeakMap;function g(t){return m.get(t)||null}function b(t,e){m.set(t,e)}const w=".",y="*",N=128,x={};for(let t=0;t<128;t++)x[`$${t+1}`]=t;const S=Object.freeze(x),I="$connectedCallback",_="$disconnectedCallback",P="$stateReadyCallback",v="$bindables",A="data-wc-definition",C=new Map;let $=0;function E(t){let e=C.get(t);return void 0!==e||(e=Object.freeze(new k(t)),C.set(t,e)),e}class k{id=++$;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("."),o=[],s=[],r=[],i={},a=[],l=[],c=[],d=[];let u="",f="",p=0;for(let t=0;t<n.length;t++)u+=n[t],n[t]===y&&(r.push(u),i[u]=p,a.push(e(u)),l.push(f),c.push(e(f)),d.push(t),p++),o.push(u),s.push(e(u)),f=u,u+=".";const h=r.length>0?r[r.length-1]:null,m=o.length>1?o[o.length-2]:null;this.path=t,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=o,this.cumulativePathSet=new Set(o),this.cumulativePathInfos=s,this.cumulativePathInfoSet=new Set(s),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=i,this.wildcardPathInfos=a,this.wildcardPathInfoSet=new Set(a),this.wildcardParentPaths=l,this.wildcardParentPathSet=new Set(l),this.wildcardParentPathInfos=c,this.wildcardParentPathInfoSet=new Set(c),this.wildcardPositions=d,this.lastWildcardPath=h,this.lastWildcardInfo=h?e(h):null,this.parentPath=m,this.parentPathInfo=m?e(m):null,this.wildcardCount=p}}const M=new Set(["if","elseif","else","for"]);function T(t){i(`filter ${t} requires at least one option`)}function O(t){i(`filter ${t} requires a number as option`)}function W(t){i(`filter ${t} requires a number value`)}function L(t){i(`filter ${t} requires a date value`)}function D(t){return!(!t||isNaN(Number(t)))}const R={eq:t=>{const e=t?.[0]??T("eq");return t=>"number"==typeof t?(D(e)||O("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??T("ne");return t=>"number"==typeof t?(D(e)||O("ne"),t!==Number(e)):t!==e},not:t=>t=>("boolean"!=typeof t&&i(`filter ${"not"} requires a boolean value`),!t),lt:t=>{const e=t?.[0]??T("lt");return D(e)||O("lt"),t=>("number"!=typeof t&&W("lt"),t<Number(e))},le:t=>{const e=t?.[0]??T("le");return D(e)||O("le"),t=>("number"!=typeof t&&W("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??T("gt");return D(e)||O("gt"),t=>("number"!=typeof t&&W("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??T("ge");return D(e)||O("ge"),t=>("number"!=typeof t&&W("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??T("inc");return D(e)||O("inc"),t=>("number"!=typeof t&&W("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??T("dec");return D(e)||O("dec"),t=>("number"!=typeof t&&W("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??T("mul");return D(e)||O("mul"),t=>("number"!=typeof t&&W("mul"),t*Number(e))},div:t=>{const e=t?.[0]??T("div");return D(e)||O("div"),t=>("number"!=typeof t&&W("div"),t/Number(e))},mod:t=>{const e=t?.[0]??T("mod");return D(e)||O("mod"),t=>("number"!=typeof t&&W("mod"),t%Number(e))},fix:t=>{const e=t?.[0]??"0";return D(e)||O("fix"),t=>("number"!=typeof t&&W("fix"),t.toFixed(Number(e)))},locale:t=>{const e=t?.[0]??o.locale;return t=>("number"!=typeof t&&W("locale"),t.toLocaleString(e))},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]??T("slice");D(n)||O("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(D(o)||O("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??T("substr");D(e)||O("substr");const n=t?.[1]??T("substr");return D(n)||O("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??T("pad");D(e)||O("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??T("rep");return D(e)||O("rep"),t=>String(t).repeat(Number(e))},rev:t=>t=>String(t).split("").reverse().join(""),int:t=>t=>parseInt(String(t),10),float:t=>t=>parseFloat(String(t)),round:t=>{const e=t?.[0]??"0";return D(e)||O("round"),t=>{"number"!=typeof t&&W("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return D(e)||O("floor"),t=>{"number"!=typeof t&&W("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return D(e)||O("ceil"),t=>{"number"!=typeof t&&W("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return D(e)||O("percent"),t=>("number"!=typeof t&&W("percent"),`${(100*t).toFixed(Number(e))}%`)},date:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("date"),t.toLocaleDateString(e))},time:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("time"),t.toLocaleTimeString(e))},datetime:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||L("datetime"),t.toLocaleString(e))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||L("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}`}},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]??T("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},F=R,B={input:R,output:F},j=(t,e)=>n=>{const o=n[t];return o||i(`filter not found: ${t}`),o(e)};const q=new Map;function z(t,e){const n=B[e];return t.map(t=>{const o=t.indexOf("("),s=t.lastIndexOf(")");if(-1!==o&&-1===s&&i(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==s&&-1===o&&i(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===o){const o=t.trim(),s=`${o}():${e}`;let r=q.get(s);return void 0===r&&(r=j(o,[])(n),q.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;for(let r=0;r<t.length;r++){const i=t[r];o?i===o?o=null:n+=i:'"'===i||"'"===i?(o=i,s=!0):","===i?(e.push(n.trim()),n="",s=!1):n+=i}const r=n.trim();return(r||s)&&e.push(r),e}(r),l=`${i}(${a.join(",")}):${e}`;let c=q.get(l);return void 0===c&&(c=j(i,a)(n),q.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const H=t=>t.trim(),U=new Map;const V=new Map;function J(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),V.has(s)?r=V.get(s):(o=s.split("|").map(H),r=z(o,"output"),V.set(s,r))):n=t.trim();const[i,a="default"]=n.split("@").map(H);return{stateName:a,statePathName:i,statePathInfo:E(i),outFilters:r}}function X(t){const[...e]=t.split(";").map(H).filter(t=>t.length>0),n=e.map(t=>{const e=t.indexOf(":");-1===e&&i(`Invalid bindText: "${t}". Missing ':' separator between propPart and statePart.`);const n=t.slice(0,e).trim(),o=t.slice(e+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:E("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("if"===n||"elseif"===n||"for"===n||"radio"===n||"checkbox"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...J(o),bindingType:n}}{const t=J(o),e=function(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),U.has(s)?r=U.get(s):(o=s.split("|").map(H),r=z(o,"input"),U.set(s,r))):n=t.trim();const[i,a]=n.split("#").map(H),l=i.split(".").map(H);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(H):[],inFilters:r}}(n);return e.propSegments[0].startsWith("on")?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(n.length>1){n.some(t=>M.has(t.bindingType))&&i(`Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const K=new WeakMap,Y=new Set([o.commentTextPrefix,o.commentForPrefix,o.commentIfPrefix,o.commentElseIfPrefix,o.commentElsePrefix]),G=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function Q(t){const e=K.get(t);if("string"==typeof e)return e;if(t.nodeType!==Node.COMMENT_NODE)return null;const n=t.data.trim(),s=G.exec(n);if(null===s)return null;const r=s[1]||o.commentTextPrefix;return Y.has(r)?(K.set(t,s[2]),s[2]):null}function Z(t){if(t.nodeType===Node.ELEMENT_NODE){return X(t.getAttribute(o.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=Q(t);null===e&&i("Comment node binding text not found.");const n=eo(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...J(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function tt(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(o.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==Q(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}const et=new WeakSet;function nt(t){const e=tt(t),n=[];for(const t of e)if(!et.has(t)){et.add(t);const e=h(t,Z(t));b(t,e),u(t),n.push(...e)}return[e,n]}const ot=new WeakMap;function st(t){let e=t;for(;e;){const t=ot.get(e);if(t)return t;e=e.parentNode}return null}function rt(t,e){null!==e?ot.set(t,e):ot.delete(t)}const it=Symbol("$$setLoopContextAsync"),at=Symbol("$$setLoopContext"),lt=Symbol("$$getByAddress"),ct=Symbol("$$setByAddress"),dt=Symbol("$$connectedCallback"),ut=Symbol("$$disconnectedCallback"),ft=Symbol("$$updatedCallback"),pt=new Map,ht=new Map;function mt(t){if(!t.propName.startsWith("on"))return!1;const e=function(t){const e=t.propModifiers.filter(t=>"prevent"===t||"stop"===t).sort().join(",");return`${t.stateName}::${t.statePathName}::${e}`}(t);let n=pt.get(e);var o,s,r;void 0===n&&(o=t.stateName,s=t.statePathName,r=t.propModifiers,n=t=>{r.includes("prevent")&&t.preventDefault(),r.includes("stop")&&t.stopPropagation();const e=t.target,n=Yn(e.getRootNode(),o);null===n&&i(`State element with name "${o}" not found for event handler.`);const a=st(e);n.createStateAsync("writable",async e=>{e[at](a,()=>{const n=e[s];return"function"!=typeof n&&i(`Handler "${s}" is not a function on state "${o}".`),Reflect.apply(n,e,[t,...a?.listIndex.indexes??[]])})})},pt.set(e,n));const a=t.propName.slice(2);t.node.addEventListener(a,n);let l=ht.get(e);return void 0===l?(l=new Set([t]),ht.set(e,l)):l.add(t),!0}const gt=new WeakMap;function bt(t){const e=gt.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{gt.set(t,n)}}const wt=new Set(["radio","checkbox"]),yt=new Set(["value","valueAsNumber","valueAsDate"]);const Nt=new Map,xt=new Map,St=t=>t.detail;function It(t){const e=bt(t.node);if(null!==e){if(void 0===customElements.get(e))return void customElements.whenDefined(e).then(()=>{It(t)})}if(function(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(wt.has(t)&&"checked"===e)return!0;if(yt.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=bt(n);if(null!==s){const t=customElements.get(s);void 0===t&&i(`Custom element <${s}> is not defined. Cannot determine if property "${e}" is suitable for two-way binding.`);const n=t.wcBindable;if("wc-bindable"===n?.protocol&&1===n?.version&&n.properties.some(t=>t.name===e))return!0}return!1}(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";const n=bt(t.node);if(null!==n){const o=customElements.get(n);void 0===o&&i(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=o.wcBindable;if("wc-bindable"===s?.protocol&&1===s?.version){const n=s.properties.find(e=>e.name===t.propName);n&&(e=n.event)}}for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t){const e=bt(t.node);if(null!==e){const n=customElements.get(e);if(n){const e=n.wcBindable;if("wc-bindable"===e?.protocol&&1===e?.version){const n=e.properties.find(e=>e.name===t.propName);if(n)return n.getter??St}}}return null}(t),o=function(t,e,n){const o=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${o}::${n?"g":"n"}`}(t,e,null!==n);let s=Nt.get(o);void 0===s&&(s=((t,e,n,o,s)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==s)l=s(r);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=Yn(a.getRootNode(),t);null===d&&i(`State element with name "${t}" not found for two-way binding.`);const u=st(a);d.createState("writable",t=>{t[at](u,()=>{t[n]=c})})})(t.stateName,t.propName,t.statePathName,t.inFilters,n),Nt.set(o,s)),t.node.addEventListener(e,s);let r=xt.get(o);void 0===r?(r=new Set([t]),xt.set(o,r)):r.add(t)}}const _t=new WeakMap;function Pt(t){return _t.get(t)??[]}function vt(t,e){_t.set(t,e)}const At=new WeakMap;function Ct(t,e){if(At.has(t)){const n=At.get(t);if(n.has(e))return n.get(e)}else At.set(t,new WeakMap);const n=Object.freeze(new $t(t,e));return At.get(t).set(e,n),n}class $t{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=Ct(t,e.parentPathInfo)}}const Et=new WeakMap,kt=new WeakMap;class Mt{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]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=Tt(t,e)}}function Tt(t,e){if(null===e){let e=kt.get(t);return void 0!==e||(e=new Mt(t,null),kt.set(t,e)),e}{let n=Et.get(e);void 0===n&&(n=new WeakMap,Et.set(e,n));let o=n.get(t);return void 0!==o||(o=new Mt(t,e),n.set(t,o)),o}}const Ot=new WeakMap;function Wt(t,e){null===e?Ot.delete(t):Ot.set(t,e)}function Lt(t){return Ot.get(t)||null}const Dt=new Map;function Rt(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=Dt.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Dt.set(s,r),r}const Ft=new WeakMap;function Bt(t){const e=st(t.node);if(null===e)return null;let n=Ft.get(e);if(void 0===n)n=new WeakMap,Ft.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=Rt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const jt=new WeakMap;function qt(t){let e=null;if(e=jt.get(t)||null,null!==e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Lt(n);null===e?i(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}const o=Bt(t),s=Yn(n,t.stateName);null===s&&i(`State element with name "${t.stateName}" not found for binding.`);return e=Tt(Ct(s,t.statePathInfo),o),jt.set(t,e),e}function zt(t){jt.delete(t)}const Ht=new WeakMap;function Ut(t,e){const n=Ht.get(t);return!!n&&!0===n.get(e)}function Vt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Jt=Object.freeze([]);const Xt=new WeakMap,Kt=new WeakMap;class Yt{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]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=Gt(t,e)}}function Gt(t,e){if(null===e){let e=Kt.get(t);return void 0!==e||(e=new Yt(t,null),Kt.set(t,e)),e}{let n=Xt.get(e);void 0===n&&(n=new WeakMap,Xt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Yt(t,e),n.set(t,o)),o}}const Qt=new WeakMap;function Zt(t){return Qt.get(t)??[]}function te(t,e){Qt.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 ee=0;function ne(){return`u${(ee++).toString(36)}`}let oe=0;class se{uuid=ne();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=oe}get index(){return this._index}set index(t){this._index=t,this._version=++oe,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=oe),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 re(t,e){return new se(t,e)}const ie=new WeakMap;function ae(t){return ie.get(t)||null}function le(t,e){null!==e?ie.set(t,e):ie.delete(t)}const ce=new WeakMap,de=Object.freeze([]),ue=new Set;function fe(t,e,n){const o=Array.isArray(e)&&e.length>0?e:de,s=Array.isArray(n)&&n.length>0?n:de,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:de,o=Array.isArray(e)&&e.length>0?e:de;let s=ce.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=ae(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:ue,deleteIndexSet:new Set(i),addIndexSet:ue};let e=ae(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=re(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:ue,deleteIndexSet:ue,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:ue,deleteIndexSet:ue,addIndexSet:ue};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)}if(null!==e)return function(t,e,n,o,s){const r=new Set(o),i=new Set(n),a=new Set,l=r.difference(i),c=i.difference(r);for(let t=0;t<e.length;t++){const o=e[t],r=s.get(o),i=r&&r.length>0?r.shift():void 0;if(void 0!==i){const e=n[i];e.index!==t&&a.add(e)}}return{oldIndexes:n,newIndexes:o,changeIndexSet:a,deleteIndexSet:c,addIndexSet:l}}(0,s,i,e,n);e=[];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=re(t,o);e.push(n),l.add(n)}else{const t=i[d];t.index!==o&&(t.index=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=ce.get(t);o||(o=new WeakMap,ce.set(t,o)),o.set(e,n)}(o,s,a),le(s,a.newIndexes))}}const pe=new WeakMap;function he(t){let e=null;return e=pe.get(t)||null,null===e&&(e=new Set,pe.set(t,e)),e}function me(t,e){he(t).add(e)}function ge(t,e){he(t).delete(e)}const be=new WeakMap;function we(t){be.delete(t)}const ye=new WeakMap;function Ne(t){return ye.get(t)??[]}function xe(t,e){ye.set(t,e)}const Se=new WeakMap;function Ie(t){return Se.get(t)??[]}function _e(t,e){Se.set(t,e)}function Pe(t,e){const n=Ie(t);for(const t of n)rt(t,e)}function ve(t,e,n){Pe(t,e);const o=Ne(t);for(const t of o){me(qt(t),t),cn(t,n)}}function Ae(t){if(!t.mounted)return;const e=Ne(t);for(const t of e){ge(qt(t),t),zt(t),we(t)}!function(t){const e=Ie(t);for(const t of e)rt(t,null)}(t)}const Ce=new WeakMap,$e=Object.freeze(new Set);function Ee(t,e){const n=Ce.get(t);n?n.add(e):Ce.set(t,new Set([e]))}function ke(t){const e=Ce.get(t);return void 0!==e?e:$e}const Me=new Set(["if","elseif","else","for"]);class Te{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;constructor(t){this._content=t,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)t.appendChild(e);this._mounted=!0}mountAfter(t){const e=t.parentNode,n=t.nextSibling;if(e)for(const t of this._childNodeArray)e.insertBefore(t,n);this._mounted=!0}unmount(){for(const t of this._childNodeArray)null!==t.parentNode&&t.parentNode.removeChild(t);const t=Ne(this);for(const e of t){if(Me.has(e.bindingType)){const t=ke(e.node);for(const e of t)e.unmount()}we(e),zt(e)}this._mounted=!1}}function Oe(t){const e=document.createDocumentFragment(),n=new Te(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 We(t){void 0!==t.uuid&&null!==t.uuid||i("BindingInfo.uuid is null.");const e=eo(t.uuid);e||i(`Fragment with UUID "${t.uuid}" not found.`);const n=document.importNode(e.fragment,!0),o=function(t,e){const[n,o]=function(t,e){const n=[],o=[];for(const s of e){const e=p(t,s.nodePath);if(null===e&&i(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),!et.has(e)){et.add(e);const t=h(e,s.parseBindTextResults);b(e,t),u(e),o.push(...t),n.push(e)}}return[n,o]}(t,e);return yn(o),{nodes:n,bindingInfos:o}}(n,e.nodeInfos),s=new Te(n);xe(s,o.bindingInfos);const r=[];for(const t of o.bindingInfos)t.statePathName in S&&r.push(t);return te(s,r),_e(s,o.nodes),Ee(t.node,s),s}const Le=new WeakMap,De=new WeakMap,Re=new WeakMap,Fe=new WeakMap;function Be(t,e,n){Ue(t,e,n)}function je(t,e){Le.set(t,e)}function qe(t){return Re.get(t.node)||[]}function ze(t,e){const n=Re.get(t.node);void 0===n?Re.set(t.node,[e]):n.push(e)}function He(t,e){let n=De.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ue(t,e,n){let o=De.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,De.set(t,o)}null===n?o.delete(e):o.set(e,n)}const Ve=new WeakMap;function Je(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Xe(t,n,s){const r=t.node.isConnected,i=Boolean(s);let a;const l=ke(t.node);a=0===l.size?We(t):l.values().next().value;const c=e(),d=t.uuid??"",u=t.bindingType;try{if(i||(o.debug&&console.log(`unmount if content : ${Je(t)}`),Ae(a),a.unmount()),i){if(o.debug&&console.log(`mount if content : ${Je(t)}`),c){const e=document.createComment(`@@wcs-${u}-start:${d}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),a.mountAfter(e);const n=document.createComment(`@@wcs-${u}-end:${d}:${t.statePathName}`),o=a.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else a.mountAfter(t.node);ve(a,st(t.node),n)}}finally{Ve.set(t.node,r)}}const Ke=new WeakMap;function Ye(t){return Ke.get(t)??[]}const Ge=new Set;const Qe={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 Ze(t,n,s){const r=t.node,i=t.propSegments;if(1===i.length){const t=i[0];if(r[t]!==s)try{r[t]=s}catch(e){o.debug&&console.warn(`Failed to set property '${t}' on element.`,{element:r,newValue:s,error:e})}if(e()){const e=Qe[t];e?e(r,s):(!function(t,e,n){let o=Ke.get(t);o||(o=[],Ke.set(t,o));const s=o.find(t=>t.propName===e);s?s.value=n:o.push({propName:e,value:n})}(r,t,s),a=r,Ge.add(a))}return}var a;let l=r[i[0]];for(let t=1;t<i.length-1;t++){const e=i[t];if(null==l)return;l=l[e]}const c=l[i[i.length-1]];if(c!==s){if(Object.isFrozen(l))return void(o.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:i,oldValue:c,newValue:s}));try{l[i[i.length-1]]=s}catch(t){o.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:c,newValue:s,error:t})}}}const tn=new WeakSet;function en(t,e,n){const o=t.node,s=t.propSegments;s.length<=1&&i(`Invalid propSegments for web component binding: ${s.join(".")}`);const[r,...a]=s,l=o[r];void 0===l&&i(`Property "${r}" not found on web component.`),l[a.join(".")]=n}function nn(t,e){const n=function(t){let e=null;if(e=be.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=Bt(t);null===n&&i(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=Gt(t.statePathInfo,n)}else e=Gt(t.statePathInfo,null);return be.set(t,e),e}(e);if(n.pathInfo.path in S){const t=st(e.node);return null===t&&i(`ListIndex not found for binding: ${e.statePathName}`),function(t,e){null===t.listIndex&&i("ListIndex not found for loopContext:");const n=S[e];void 0===n&&i(`Invalid index name: ${e}`);const o=t.listIndex.at(n);return null===o&&i(`Index not found at position ${n} for loopContext:`),o.index}(t,n.pathInfo.path)}return t[lt](n)}const on={class:function(t,e,n){const o=t.node,s=t.propSegments[1];"boolean"!=typeof n&&i("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)}},sn={text:function(t,n,o){if(t.replaceNode.nodeValue!==o&&(t.replaceNode.nodeValue=o),e()&&!tn.has(t.replaceNode)){tn.add(t.replaceNode);const e=t.replaceNode.parentNode;if(e){const n=t.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);e.insertBefore(o,t.replaceNode),e.insertBefore(s,t.replaceNode.nextSibling)}}},for:function(t,n,o){const s=t.statePathInfo,r=Bt(t),a=qt(t),l=Pt(a),c=fe(r,l,o);if(n.newListValueByAbsAddress.set(a,Array.isArray(o)?o:[]),Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0&&null!==t.node.parentNode){let e=Fe.get(t.node);if(void 0===e){const n=Le.get(t.node)||t.node;e=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}(t.node,n),Fe.set(t.node,e)}if(e){const e=t.node.parentNode;e.textContent="",e.appendChild(t.node)}}for(const e of c.deleteIndexSet){const n=He(t.node,e);null!==n&&(Ae(n),n.unmount(),ze(t,n),Ue(t.node,e,null))}let d=t.node;const u=E(s.path+"."+y),f=n.stateElement.loopContextStack;let p=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&d.isConnected&&(p=document.createDocumentFragment(),Wt(p,n.rootNode));const h=e(),m=t.uuid??"";for(const e of c.newIndexes){let o;if(c.addIndexSet.has(e)){const r=Gt(u,e);f.createLoopContext(r,r=>{const i=qe(t);if(o=i.pop(),void 0===o&&(o=We(t)),null!==p)h&&p.appendChild(document.createComment(`@@wcs-for-start:${m}:${s.path}:${e.index}`)),o.appendTo(p),h&&p.appendChild(document.createComment(`@@wcs-for-end:${m}:${s.path}:${e.index}`));else{if(d.nextSibling!==o.firstNode){if(h){const t=document.createComment(`@@wcs-for-start:${m}:${s.path}:${e.index}`);d.parentNode.insertBefore(t,d.nextSibling),d=t}o.mountAfter(d)}if(h){const t=document.createComment(`@@wcs-for-end:${m}:${s.path}:${e.index}`),n=o.lastNode??d;n.parentNode.insertBefore(t,n.nextSibling)}}ve(o,r,n)}),void 0===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=He(t.node,e),c.changeIndexSet.has(e)){const t=Zt(o);for(const e of t)cn(e,n)}null===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`),d.nextSibling!==o.firstNode&&o.mountAfter(d)}d=o.lastNode||d,Ue(t.node,e,o)}Le.set(t.node,d),null!==p&&(t.node.parentNode.insertBefore(p,t.node.nextSibling),Wt(p,null))},if:Xe,else:Xe,elseif:Xe,radio:function(t,e,n){const o=t.node,s=Vt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Vt(o.value,t.inFilters),r=Array.isArray(n)?n:Jt;o.checked=r.includes(s)}},rn=new WeakMap,an=new WeakMap;function ln(t,e){const n=Vt(nn(e.state,t),t.outFilters);if(!0===an.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=rn.get(t);if(void 0===o){if(rn.has(t))return Ut(t.replaceNode,e.stateElement)?(o=en,rn.set(t,o)):o=Ze,void o(t,e,n);if(o=sn[t.bindingType],void 0===o){const n=t.propSegments[0];if(o=on[n],rn.set(t,o),void 0===o){bt(t.replaceNode)?Ut(t.replaceNode,e.stateElement)?(o=en,rn.set(t,o)):o=Ze:(o=Ze,rn.set(t,o))}}if(o===Ze){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void an.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function cn(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const n=qt(t);if(e.updatedAbsAddressSetByStateElement.has(e.stateElement)){e.updatedAbsAddressSetByStateElement.get(e.stateElement).add(n)}else e.updatedAbsAddressSetByStateElement.set(e.stateElement,new Set([n]));if("event"===t.bindingType)return;const o=bt(t.replaceNode);if(o&&void 0===customElements.get(o))return;let s=t.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=Lt(s),null===s&&i("Root node for fragment not found for binding.")),t.stateName!==e.stateName||s!==e.rootNode){const n=Yn(s,t.stateName);null===n&&i(`State element with name "${t.stateName}" not found for binding.`),n.createState("readonly",o=>{const r={stateName:t.stateName,rootNode:s,stateElement:n,state:o,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};ln(t,r)})}else ln(t,e)}function dn(t){let e=0;const n=new Set,s=new Map,r=new Map,a=[];for(;e<t.length;){let l=t[e];const c=l.stateName;if(!1===l.replaceNode.isConnected){o.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${l.bindingType} ${l.statePathName} on ${l.node.nodeName}`,l),e++;continue}let d=l.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=Lt(d),null===d&&i("Root node for fragment not found for binding."));const u=Yn(d,c);null===u&&i(`State element with name "${c}" not found for binding.`),u.createState("readonly",o=>{const i={rootNode:d,stateName:c,stateElement:u,state:o,appliedBindingSet:n,newListValueByAbsAddress:s,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:a};for(;;){cn(l,i),e++;const n=t[e];if(!n)break;const o=n.replaceNode.getRootNode();if(n.stateName!==c||o!==i.rootNode)break;l=n}})}for(const{binding:t,value:e}of a)Ze(t,0,e);for(const[t,e]of s.entries())vt(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[ft](Array.from(e))})}const un=new Map,fn=new Map;const pn=(t,e,n)=>o=>{const s=o.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 n)r=t.filterFn(r);const a=Yn(s.getRootNode(),t);null===a&&i(`State element with name "${t}" not found for two-way binding.`);const l=st(s);a.createState("writable",t=>{t[at](l,()=>{t[e]=r})})};function hn(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}(t,e);let o=un.get(n);void 0===o&&(o=pn(t.stateName,t.statePathName,t.inFilters),un.set(n,o)),t.node.addEventListener(e,o);let s=fn.get(n);return void 0===s?(s=new Set([t]),fn.set(n,s)):s.add(t),!0}return!1}const mn=new Map,gn=new Map;const bn=(t,e,n)=>o=>{const s=o.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 a=s.value;for(const t of n)a=t.filterFn(a);const l=Yn(s.getRootNode(),t);null===l&&i(`State element with name "${t}" not found for two-way binding.`);const c=st(s);l.createState("writable",t=>{t[at](c,()=>{let n=t[e];if(Array.isArray(n))if(r)-1===n.indexOf(a)&&(t[e]=n.concat(a));else{const o=n.indexOf(a);-1!==o&&(t[e]=n.toSpliced(o,1))}else t[e]=r?[a]:[]})})};function wn(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf("ro")){const e=function(t){let e="input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),n=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}(t,e);let o=mn.get(n);void 0===o&&(o=bn(t.stateName,t.statePathName,t.inFilters),mn.set(n,o)),t.node.addEventListener(e,o);let s=gn.get(n);return void 0===s?(s=new Set([t]),gn.set(n,s)):s.add(t),!0}return!1}function yn(t){for(const e of t)f(e),mt(e)||(It(e),hn(e),wn(e))}function Nn(t,e){const[n,o]=nt(t);for(const t of n)rt(t,e);yn(o);for(const t of o){me(qt(t),t);const e=Yn(t.replaceNode.getRootNode(),t.stateName);null===e&&i(`State element with name "${t.stateName}" not found for binding.`),"event"!==t.bindingType&&e.setPathInfo(t.statePathName,t.bindingType)}dn(o)}const xn=/\{\{\s*(.+?)\s*\}\}/g,Sn=new Set(["SCRIPT","STYLE"]);function In(t){if(!o.enableMustache)return;!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&&Sn.has(t.parentElement.tagName)||_n(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),In(e.content)}else In(t.content)}function _n(t){const e=t.data;if(xn.lastIndex=0,!xn.test(e))return;xn.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=xn.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 Pn;function vn(){if(Pn)return Pn;const t=[],e=j("not",t)(F);return Pn={filterName:"not",args:t,filterFn:e},Pn}const An=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Cn(t,e){const n=e+w+y,o=t.indexOf("|"),s=t.indexOf("@");let r,i;if(-1!==o?(r=t.slice(0,o).trim(),i=t.slice(o)):-1!==s?(r=t.slice(0,s).trim(),i=t.slice(s)):(r=t.trim(),i=""),"."===r)r=n;else{if(!r.startsWith("."))return t;r=n+w+r.slice(1)}return i.length>0?r+i:r}function $n(t,e){const n=An.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+Cn(s,e)+r}function En(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=Cn(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function kn(t,e){return En(t,e)}function Mn(t,e){const n=o.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 n=t;n.data=$n(n.data,e);continue}const o=t;if(o instanceof HTMLTemplateElement)continue;const r=o.getAttribute(n);if(null!==r){const t=En(r,e);t!==r&&o.setAttribute(n,t)}}}function Tn(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 On(t){const e=[],n=tt(t);for(const t of n){const n=Z(t);e.push({nodePath:Tn(t),parseBindTextResults:n})}return e}function Wn(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 Ln=new Map([["for",o.commentForPrefix],["if",o.commentIfPrefix],["elseif",o.commentElseIfPrefix],["else",o.commentElsePrefix]]),Dn=vn();function Rn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,Dn],bindingType:t}}function Fn(t,e,n,o){Wn(e),"string"==typeof o&&Mn(e,o),Bn(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:On(e)}}function Bn(t,e,n){const s=o.commentElsePrefix,r=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const e=t;if("template"===e.tagName.toLowerCase()){if((e.getAttribute(o.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let a=null;const l=[],c=[];for(;r.nextNode();){const t=r.currentNode;c.push(t)}for(const e of c){let r=e.getAttribute(o.bindAttributeName)||"";"string"==typeof n&&(r=kn(r,n));let c=X(r)[0];const d=Ln.get(c.bindingType);if(void 0===d)continue;const u=c.bindingType,f=e.content,p=ne();let h=null;const m="for"===u?c.statePathName:n;if("else"===u){null===a&&i("'else' binding found without preceding 'if' or 'elseif' binding."),c=Rn("else",a.parseBindTextResult),h=Fn(t,f,c,m),to(p,t,h);const n=l.at(-1),o=document.createComment(`@@${d}:${p}`);void 0!==n?(e.remove(),n.fragment.appendChild(o),n.nodeInfos.push({nodePath:Tn(o),parseBindTextResults:Z(o)})):e.replaceWith(o)}else if("elseif"===u){null===a&&i("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Fn(t,f,c,m),to(p,t,h);const n=document.createComment(`@@${d}:${p}`),o=ne(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Rn("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:Tn(n),parseBindTextResults:Z(n)}),to(o,t,r);const u=l.at(-1);l.push(r);const g=document.createComment(`@@${s}:${o}`);void 0!==u?(e.remove(),u.fragment.appendChild(g),u.nodeInfos.push({nodePath:Tn(g),parseBindTextResults:Z(g)})):e.replaceWith(g)}else{h=Fn(t,f,c,m),to(p,t,h);const n=document.createComment(`@@${d}:${p}`);e.replaceWith(n)}"if"===u?(l.length=0,a=h):"elseif"===u?a=h:"else"===u&&(a=null,l.length=0)}}async function jn(t){const e=t.querySelectorAll(o.tagNames.state),n=[];await customElements.whenDefined(o.tagNames.state);for(const t of e){const e=t;n.push(e.initializePromise)}await Promise.all(n)}async function qn(t){if(t===document)await jn(document),In(document),Bn(document,document),Nn(document.body,null);else{const e=t;e.host.hasAttribute(o.bindAttributeName)&&await d(e.host),await jn(e),In(e),Bn(e,e),Nn(e,null)}}const zn=new Set(["for","if","elseif","else"]);function Hn(t){if(0===t.length)return{bindingInfos:[],subscriberNodes:[]};const e=t[0].parentNode,n=t[t.length-1].nextSibling,o=document.createElement("div");for(const e of t)o.appendChild(e);const[s,r]=nt(o);for(const t of r)f(t),mt(t)||(It(t),hn(t),wn(t));if(e)for(;o.firstChild;)e.insertBefore(o.firstChild,n);return{bindingInfos:r,subscriberNodes:s}}function Un(t,e,n){const s={for:o.commentForPrefix,if:o.commentIfPrefix,elseif:o.commentElseIfPrefix,else:o.commentElsePrefix}[e];if(!s)return null;const r=`@@${s}:${n}`,i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const t=i.currentNode;if(t.data===r)return t}return null}function Vn(t,e){const n=t;let s=null;for(const[t,r]of e.templates){let e=X(r.getAttribute(o.bindAttributeName)||"")[0];const i=e.bindingType;"else"===i&&s?e={...s,outFilters:[...s.outFilters,vn()],bindingType:"else"}:"elseif"===i&&s&&(e={...e,stateName:s.stateName}),"if"===i||"elseif"===i?s=e:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?e.statePathName:void 0;Wn(a),"string"==typeof l&&Mn(a,l),Bn(n,a,l);to(t,n,{fragment:a,parseBindTextResult:e,nodeInfos:On(a)})}}async function Jn(t){await jn(t);const e=t.querySelectorAll(o.tagNames.ssr);for(const n of e){const e=n;if(!e.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${e.version}", client="${r}". Falling back to full render.`),io.cleanupDom(t),!1}for(const n of e)Vn(t,n);const n=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=oo.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 o of e){if(0===o.nodes.length)continue;const e=Oe(o.nodes),{bindingInfos:s,subscriberNodes:r}=Hn(o.nodes);for(const t of r)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");xe(e,s),_e(e,r);const i=[];for(const t of s)t.statePathName in S&&i.push(t);if(te(e,i),"for"===o.type&&null!==o.index){const r=Un(t,"for",o.uuid);if(r){const t=re(null,o.index);Be(r,t,e),je(r,o.nodes[o.nodes.length-1]),Ee(r,e),Pe(e,Gt(E(o.path+"."+y),t));for(const t of s)me(qt(t),t);let i=n.get(o.uuid);i||(i=[],n.set(o.uuid,i)),i.push(t)}}else{const n=Un(t,o.type,o.uuid);if(n){Ee(n,e);for(const t of s)me(qt(t),t)}}}for(const[e,o]of n){const n=Un(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=eo(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=Yn(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&le(e,o)})}}(document.body,n),io.removeBlockBoundaryComments(document.body);const s=[];for(const t of e)t.parentNode&&(s.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());io.restoreTextBindings(document.body);const[a,l]=nt(document.body);for(const t of a)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(rt(t,null),e.setAttribute("data-wcs-completed",""))}else rt(t,null);const c=[],d=[];for(const t of l)if(f(t),!mt(t))if(It(t),hn(t),wn(t),zn.has(t.bindingType))d.push(t);else{if(t.statePathName.includes(y))continue;c.push(t)}for(const t of[...c,...d]){me(qt(t),t);const e=Yn(t.replaceNode.getRootNode(),t.stateName);null===e&&i(`State element with name "${t.stateName}" not found for binding.`),"event"!==t.bindingType&&e.setPathInfo(t.statePathName,t.bindingType)}for(const t of d)if("for"===t.bindingType){const e=qt(t),n=Yn(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&vt(e,o)})}dn(c);for(const{el:t,parent:e,next:n}of s)e.insertBefore(t,n);const u=t.querySelectorAll(o.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 p=t.querySelectorAll("[data-wcs-completed]");for(const t of p)t.removeAttribute("data-wcs-completed");return!0}const Xn=new WeakMap,Kn=new WeakMap;function Yn(t,e){let n=Xn.get(t);return n&&n.get(e)||null}function Gn(t){return Kn.get(t)??Promise.resolve()}function Qn(t,n,s){let r=Xn.get(t);if(null===s){if(!r)return;r.delete(n),0===r.size&&Xn.delete(t),o.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,Xn.set(t,r);const n=!e()&&s.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{if(n){await Jn(t)||await qn(t)}else await qn(t);e()})});Kn.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await qn(t),e()})});Kn.set(t,e)}}r.has(n)&&i(`State element with name "${n}" is already registered.`),r.set(n,s),o.debug&&console.debug(`State element registered: name="${n}"`,s)}}const Zn=new Map;function to(t,e,n){if(null===n)Zn.delete(t);else{Zn.set(t,n);const o=n.parseBindTextResult,s=Yn(e,o.stateName);null===s&&i(`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=Yn(e,n.stateName);null===t&&i(`State element with name "${n.stateName}" not found for fragment info node.`),t.setPathInfo(n.statePathName,n.bindingType)}}}function eo(t){return Zn.get(t)||null}const no=/^@@wcs-(?:for|if|elseif|else):[^-]/,oo=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,so=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,ro=/^@@wcs-text-start:(.+)$/;class io extends HTMLElement{_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=r.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,e){const n=o.tagNames.ssr,s=t instanceof Element?t:t instanceof Document?t.documentElement:null;if(!s)return null;return s.querySelector(`${n}[name="${e}"]`)}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,e){const n=document.createElement("script");n.setAttribute("type","application/json"),n.textContent=JSON.stringify(e),t.appendChild(n);const s=Array.from(Zn.keys());for(const e of s){const n=eo(e);if(!n)continue;const s=document.createElement("template");s.setAttribute("id",e);const r=n.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(o.bindAttributeName,i);const a=n.fragment.cloneNode(!0);s.content.appendChild(a),t.appendChild(s)}const r=Array.from(Ge);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=Ye(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=JSON.stringify(e),t.appendChild(n)}}Ge.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(oo.test(t.data)||so.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;no.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=ro.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 e=document.body,n=t.querySelectorAll(o.tagNames.ssr),s=new Map;for(const t of n){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(e,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const t=r.currentNode;oo.test(t.data)&&i.push(t)}for(const t of i){const e=oo.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()}io.restoreTextBindings(e);const a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(no.test(t.data)){const e=t.data.split(":")[1];l.push({comment:t,uuid:e})}}for(const{comment:t,uuid:e}of l){const n=s.get(e);if(n){const e=document.createElement("template"),s=n.getAttribute(o.bindAttributeName);s&&e.setAttribute(o.bindAttributeName,s);const r=document.importNode(n.content,!0);if(r.childNodes.length>0)e.content.appendChild(r);else for(const t of Array.from(n.childNodes))e.content.appendChild(document.importNode(t,!0));t.parentNode.replaceChild(e,t)}}const c=t.querySelectorAll("[data-wcs-ssr-id]");for(const t of c)t.removeAttribute("data-wcs-ssr-id");for(const t of n)t.remove()}}async function ao(t,e){let n=null;const o=`\n//# sourceURL=${e}\n`;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}`)}return n&&"object"==typeof n.default?n.default:{}}async function lo(t){try{return(await import(t)).default||{}}catch(t){i(`Failed to load script file: ${t}`)}}class co{_loopContextStack=Array(N).fill(void 0);_length=0;createLoopContext(t,e){null===t.listIndex&&i("Cannot create loop context for a state address that does not have a list index.");const n=t;this._length>=N&&i("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&&i("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&&i("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else 1!==n.pathInfo.wildcardCount&&i("Cannot push loop context for a list with wildcard positions when there is no active loop context.");let s;this._loopContextStack[this._length]=n,this._length++;try{s=e(n)}finally{s instanceof Promise?s.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return s}}function uo(t){return function(){const e=this.stateElement;if(!e)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch{return}return n}}function fo(t){return function(e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})})}}function po(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>n.createStateAsync("writable",async n=>{await n[t](...e)}))}:function(...e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t](...e)})})}}function ho(t){return t.startsWith("$")}const mo=new Map;class go{path;segments;paths;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice(),o=[];let s=0,r=0,i="",a=0,l="none";const c=[];for(let t=0;t<e.length;t++){const l=e[t];if("*"===l)n[t]="*",c.push(null),s++,a++;else{const e=Number(l);Number.isNaN(e)||(n[t]="*",c.push(e),r++,a++)}i+=l,o.push(i),i+=t<l.length-1?".":""}const d=E(n.join("."));(s>0||r>0)&&(l=s===a?"context":r===a?"all":"partial"),this.path=t,this.segments=e,this.paths=o,this.wildcardCount=a,this.wildcardType=l,this.wildcardIndexes=c,this.pathInfo=d}}function bo(t){let e;return mo.get(t)??(mo.set(t,e=new go(t)),e)}const wo=new WeakMap;function yo(t,e){null===e?wo.delete(t):wo.set(t,e)}function No(t){const e=wo.get(t);e&&(e.dirty=!0)}function xo(t,e,n,o,s){if(!(e.pathInfo.path in t)){const s=Io(t,e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),n,o),r=e.pathInfo.segments[e.pathInfo.segments.length-1];if(r===y){const t=e.listIndex?.index??i(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(s,t)}return Reflect.get(s,r)}if(!s.getterPaths.has(e.pathInfo.path))return Reflect.get(t,e.pathInfo.path);o.pushAddress(e);try{return Reflect.get(t,e.pathInfo.path,n)}finally{o.popAddress()}}function So(t,e,n,o,s){const r=Tt(Ct(s,e.pathInfo),e.listIndex),i=function(t){return wo.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=xo(t,e,n,o,s);return yo(r,{value:a,dirty:!1}),a}function Io(t,e,n,o){!function(t,e){if(t.addressStackLength>0){const n=t.lastAddressStack?.pathInfo??null,o=t.stateElement;null!==n&&o.getterPaths.has(n.path)&&n.path!==e.pathInfo.path&&o.addDynamicDependency(e.pathInfo.path,n.path)}}(o,e);const s=o.stateElement;return e.pathInfo.wildcardCount>0||s.getterPaths.has(e.pathInfo.path)?So(t,e,n,o,s):xo(t,e,n,o,s)}function _o(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?.at(o)??null}const Po=new class{_queueAbsoluteAddresses=[];constructor(){}enqueueAbsoluteAddress(t){const e=0===this._queueAbsoluteAddresses.length;this._queueAbsoluteAddresses.push(t),e&&queueMicrotask(()=>{const t=this._queueAbsoluteAddresses;this._queueAbsoluteAddresses=[],this._applyChange(t)})}testApplyChange(t){this._applyChange(t)}_applyChange(t){const e=new Set(t),n=[];for(const t of e){const e=he(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}dn(n)}};function vo(){return Po}const Ao=new WeakMap;function Co(t,e){null===e?Ao.delete(t):Ao.set(t,e)}function $o(t,e,n){const s=E(t.wildcardParentPaths[e]),r=Ct(t.stateElement,s),i=Gt(s,n),a=Pt(Tt(r,n)),l=t.stateProxy[lt](i),c=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 o.debug&&console.log(`Invalid search type: ${e}`),[]}}(fe(i.listIndex,a,l),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...c);else for(const n of c)$o(t,e+1,n)}function Eo(t,e,n,o,s,r,a,l,c){const d={stateElement:e,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:a,searchType:l};return function(t,e,n){const o=[{address:e,depth:0}];for(;o.length>0;){const{address:e,depth:s}=o.pop();if(s>1e3&&i(`Maximum dependency depth of 1000 exceeded. Possible circular dependency detected at path: ${e.pathInfo.path}`),t.visited.has(e))continue;t.visited.add(e),n(e);const r=e.pathInfo.path,a=s+1,l=[],c=t.staticMap.get(r);if(c)for(const n of c){const o=E(n);if(t.listPathSet.has(r)&&o.lastSegment===y){const n=t.stateProxy[lt](e),s=Pt(Tt(Ct(t.stateElement,e.pathInfo),e.listIndex)),r=fe(e.listIndex,s,n);for(const e of r.newIndexes){const n=Gt(o,e);t.result.add(n),l.push({address:n,depth:a})}}else{const n=Gt(o,e.listIndex);t.result.add(n),l.push({address:n,depth:a})}}const d=t.dynamicMap.get(r);if(d)for(const n of d){const o=E(n),s=[];if(o.wildcardCount>0){const n=Rt(e.pathInfo,o);if(o.wildcardCount-n>=1){let r;n>0?(null===e.listIndex&&i(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),r=e.listIndex.at(n-1)):r=null;const a={stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};$o(a,n,r),s.push(...a.targetListIndexes)}else{null===e.listIndex&&i(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`);const t=e.listIndex.at(n-1);s.push(t)}}else s.push(null);for(const e of s){const n=Gt(o,e);t.result.add(n),l.push({address:n,depth:a})}}for(let t=l.length-1;t>=0;t--)o.push(l[t])}}(d,n,c),Array.from(d.result)}function ko(t,e,n,o,s,r){try{if(!(e.pathInfo.path in t)){const n=Io(t,e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),s,r),a=e.pathInfo.segments[e.pathInfo.segments.length-1];if(a===y){const t=e.listIndex?.index??i(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.set(n,t,o)}return Reflect.set(n,a,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e);try{return Reflect.set(t,e.pathInfo.path,o,s)}finally{r.popAddress()}}finally{const t=vo();t.enqueueAbsoluteAddress(n),Eo(r.stateName,r.stateElement,e,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,s,"new",n=>{if(n===e)return;const o=Tt(Ct(r.stateElement,n.pathInfo),n.listIndex);No(o),t.enqueueAbsoluteAddress(o)})}}function Mo(t,e,n,o,s,r){let a=e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Ao.get(t)??null}(a);if(null===l){const e=Io(t,a,s,r)??[],n=ae(e)??[];l={value:[...e],listIndexes:[...n]},Co(a,l)}try{return ko(t,e,n,o,s,r)}finally{const n=l.value.indexOf(o),i=Io(t,a,s,r)??[],c=Array.isArray(i)?ae(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:re(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;Co(a,null)}}}function To(t,e,n,o,s){const r=s.stateElement,i=r.elementPaths.has(e.pathInfo.path),a=e.pathInfo.wildcardCount>0||r.getterPaths.has(e.pathInfo.path),l=Tt(Ct(r,e.pathInfo),e.listIndex);try{return i?Mo(t,e,l,n,o,s):ko(t,e,l,n,o,s)}finally{a&&yo(l,{value:n,dirty:!1});const t=r.bindableEventMap[e.pathInfo.path];if(t){const e=r.rootNode;e instanceof ShadowRoot&&e.host.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0}))}}}function Oo(t,e,n,o){return(e,s,r)=>{const 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)}a.wildcardParentPathInfos.length>s.length&&i(`indexes length is insufficient: ${e}`);let l=null;for(let e=0;e<a.wildcardParentPathInfos.length;e++){const r=a.wildcardParentPathInfos[e],c=Gt(r,l),d=ae(Io(t,c,n,o));null==d&&i(`ListIndexes not found: ${r.path}`);l=d[s[e]]??i(`ListIndex not found: ${r.path}`)}const c=Gt(a,l);if(!(void 0!==r))return Io(t,c,n,o);To(t,c,r,n,o)}}const Wo=new WeakMap;function Lo(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return _o(o,s.wildcardPaths.at(-1)??i(`lastWildcardPath is null: ${e.pathInfo.path}`))??i(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<e.pathInfo.wildcardCount;r++){const a=e.pathInfo.wildcardParentPathInfos[r]??i(`wildcardParentPathInfo is null: ${e.pathInfo.path}`);s=(ae(Io(t,Gt(a,s),n,o))??i(`ListIndex not found: ${a.path}`))[e.wildcardIndexes[r]??i(`wildcardIndex is null: ${e.pathInfo.path}`)]??i(`ListIndex not found: ${a.path}`)}return s}case"partial":i(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Do(t,e,n){void 0!==t.loopContext&&i("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return n()}finally{t.popAddress()}}finally{t.clearLoopContext()}}function Ro(t,e,n,o){const s=S[e];if(void 0!==s){0===o.addressStackLength&&i(`No active state reference to get list index for "${e.toString()}".`);const t=o.lastAddressStack?.listIndex;return t?.indexes[s]??i(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"!==e[0]){const s=bo(e),r=Lo(t,s,n,o),i=Gt(s.pathInfo,r);return Io(t,i,n,o)}switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=Oo(t,0,n,o);return(e,r)=>{const a=new Map,l=E(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==l.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(l.path,t.path)}if(void 0===r){for(let t=0;t<l.wildcardParentPathInfos.length;t++){const e=l.wildcardParentPathInfos[t],n=_o(o,e.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const c=(e,s,r,l,d,u,f)=>{const p=e[s]??null;if(null===p)return void f.push(u);const h=Gt(p,r),m=Wo.get(h),g=Io(t,h,n,o),b=fe(r,m,g).newIndexes,w=l[d]??null;if(a.set(h,g),null===w)for(let t=0;t<b.length;t++){const n=b[t];c(e,s+1,n,l,d+1,u.concat(n.index),f)}else{const t=b[w]??i(`ListIndex not found: ${p.path}`);s+1<e.length?c(e,s+1,t,l,d+1,u.concat(t.index),f):f.push(u.concat(t.index))}},d=[];c(l.wildcardParentPathInfos,0,null,r,0,[],d);const u=[];for(let t=0;t<d.length;t++)u.push(s(l.path,d[t]));for(const[t,e]of a.entries())Wo.set(t,e);return u}}(t,0,n,o)(e,s);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const r=bo(e),i=Lo(t,r,n,o),a=Gt(r.pathInfo,i),l=Tt(Ct(s,a.pathInfo),a.listIndex),c=vo();c.enqueueAbsoluteAddress(l),Eo(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=Tt(Ct(s,t.pathInfo),t.listIndex);No(e),c.enqueueAbsoluteAddress(e)})}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>Oo(t,0,n,o)(e,s,r);case"$trackDependency":return t=>function(t,e,n,o){return t=>{0===o.addressStackLength&&i(`No active state reference to track dependency for path "${t}".`);const e=o.lastAddressStack?.pathInfo??i("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)}}else if("symbol"==typeof e){switch(e){case it:return(t,e=async()=>{})=>async function(t,e,n){return await Do(t,e,n)}(o,t,e);case at:return(t,e=()=>{})=>function(t,e,n){return Do(t,e,n)}(o,t,e);case lt:return e=>Io(t,e,n,o);case ct:return(e,s)=>To(t,e,s,n,o);case dt:return()=>async function(t,e,n){const o=Reflect.get(t,I);"function"==typeof o&&await o.call(n)}(t,0,n);case ut:return()=>function(t,e,n){const o=Reflect.get(t,_);"function"==typeof o&&o.call(n)}(t,0,n);case ft:return e=>function(t,e,n,o){const s=Reflect.get(t,"$updatedCallback");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=n.listIndex.indexes??[],e=r[s];void 0===e?r[s]=[t]:e.push(t)}}return s.call(n,Array.from(t),r)}}(t,e,n,o)}return Reflect.get(t,e,n)}}class Fo{_stateElement;_stateName;_addressStack=Array(N).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,n){this._stateName=e;const o=Yn(t,this._stateName);null===o&&i(`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&&i("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex++,this._addressStackIndex>=N&&i("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&&i(`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(t,e,n){return Ro(t,e,n,this)}set(t,e,n,o){return"readonly"===this._mutability&&i(`State "${this._stateName}" is readonly.`),function(t,e,n,o,s){if("string"==typeof e){const r=bo(e),i=Lo(t,r,o,s);return To(t,Gt(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)}}const Bo=new WeakMap;const jo=new WeakMap;function qo(t,e){const n=jo.get(t);return n?n.get(e)??null:null}const zo=new WeakMap,Ho=new WeakMap,Uo=new WeakMap,Vo=new WeakMap;function Jo(t,e){return{innerAbsPathInfo:Ct(t,E(e.propSegments.slice(1).join(w))),outerAbsPathInfo:qt(e).absolutePathInfo}}function Xo(t,e){let n=zo.get(t);if(void 0===n&&(n=new Map,zo.set(t,n)),n.has(e))return n.get(e);let o=Ho.get(t);void 0===o&&(o=new Map,Ho.set(t,o));const s=Uo.get(t);if(void 0===s)return null;let r=null;for(const t of s)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&i("Duplicate mapping rule for web component."),r=t;break}if(null===r)return null;const a=Vo.get(r);void 0===a&&i("Binding not found for primary mapping rule on web component.");const l=e.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),c=E(r.outerAbsPathInfo.pathInfo.segments.concat(l).join(w)),d=Yn(t.getRootNode(),a.stateName);null===d&&i(`State element with name "${a.stateName}" not found for web component.`);const u=Ct(d,c);n.set(e,u),o.set(u,e);return function(t,e){const n=g(t);null===n?b(t,[e]):n.push(e)}(t,{...a,propName:e.pathInfo.path,propSegments:e.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function Ko(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 Yo{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=qo(t,e)??i("State element not found for web component.")}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=Ct(this._innerStateElement,o),r=Xo(this._webComponent,s);if(null!==r){const t=st(this._webComponent);let e;return r.stateElement.createState("readonly",n=>{n[at](t,()=>{e=n[r.pathInfo.path];let o=null;null!==t&&null!==t.listIndex&&r.pathInfo.wildcardCount>0&&(o=t.listIndex.at(r.pathInfo.wildcardCount-1));!function(t,e){Bo.set(t,e)}(Tt(r,o),e)})}),e}if(e in t)return Reflect.get(t,e,n);i(`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=Ct(this._innerStateElement,s),a=Xo(this._webComponent,r);if(null!==a){const t=st(this._webComponent);return a.stateElement.createState("writable",e=>{e[at](t,()=>{e[a.pathInfo.path]=n})}),!0}if(e in t)return Reflect.set(t,e,n,o);i(`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=Ct(this._innerStateElement,n);return null!==Xo(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class Go{_innerStateElement;constructor(t,e){this._innerStateElement=qo(t,e)??i("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=E(e),n=Tt(Ct(this._innerStateElement,t),null);return o=n,Bo.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=E(e),n=Ct(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class Qo{_innerStateElement;constructor(t,e){this._innerStateElement=qo(t,e)??i("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 Zo=t=>()=>t;function ts(t,e,n,s){if(function(t,e,n){let o=jo.get(t);o||(o=new Map,jo.set(t,o)),o.set(e,n)}(e,n,t),e.hasAttribute(o.bindAttributeName)){const o=(g(e)??[]).filter(t=>t.propSegments[0]===n);!function(t,e,n){if(0===n.length)return;const o=qo(t,e);null===o&&i("State element not found for web component.");const s=new Map,r=new Map;for(const e of n){const n=Jo(o,e);let i=Uo.get(t);void 0===i?Uo.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Vo.set(n,e),s.set(a,l),r.set(l,a)}zo.set(t,s),Ho.set(t,r)}(e,n,o);const s=function(t,e){const n=new Go(t,e);return new Proxy({},n)}(e,n),r=function(t,e){const n=new Yo(t,e),o=qo(t,e);null===o&&i("State element not found for web component."),null===o.boundComponentStateProp&&i("State element is not bound to any component state prop."),o.boundComponentStateProp in t||i(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=t[o.boundComponentStateProp];return"object"==typeof s&&null!==s||i(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Ko(s),n)}(e,n);t.setInitialState(r),Object.defineProperty(e,n,{get:Zo(s),enumerable:!0,configurable:!0})}else{t.setInitialState(Ko(s));const o=function(t,e){const n=new Qo(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:Zo(o),enumerable:!0,configurable:!0})}if(function(t,e){let n=Ht.get(t);n||(n=new WeakMap,Ht.set(t,n)),n.set(e,!0)}(e,t),P in e){const t=e[P];"function"==typeof t?t.call(e,n).catch(t=>{i(`Error in ${P}: ${t instanceof Error?t.message:String(t)}`)}):i(`${P} is not a function.`)}}function es(t){const e=new Set,n=new Set,o=function(t){let e={},n=t;for(;n&&n!==Object.prototype;)Object.assign(e,Object.getOwnPropertyDescriptors(n)),n=Object.getPrototypeOf(n);return e}(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}}class ns extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return Gn(t)}__state;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(){return new co}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise(t=>{this._resolveConnectedCallback=t}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&i(`${o.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){this.__state=t,this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._pathSet.clear();const e=es(t);for(const t of e.getterPaths)this._getterPaths.add(t);for(const t of e.setterPaths)this._setterPaths.add(t);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=io.findByName(e,t);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const t=e()?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){i("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||i(`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 lo(t):i(`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 ao(t,`${this._name}`);else{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${o.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(t)}}}catch(t){i(`Failed to initialize state: ${t}`)}if(null!==t&&this.__state)for(const[e,n]of Object.entries(t)){if(e in this.__state){const t=Object.getOwnPropertyDescriptor(this.__state,e);if(t&&(t.get||t.set))continue;if("function"==typeof this.__state[e])continue}this.__state[e]=n}await this._loadingPromise,this._name=this.getAttribute("name")||"default",Qn(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const t=this.parentNode,e=t instanceof ShadowRoot?t.host:t instanceof Element?t:null,n=e?bt(e):null;null!==e&&null!==n||i(`"bind-component" requires <${o.tagNames.state}> to be a direct child of a custom element.`),t instanceof ShadowRoot||this.hasAttribute("name")||i('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=this.getAttribute("bind-component");await customElements.whenDefined(n.toLowerCase()),e.hasAttribute(o.bindAttributeName)&&await d(e),s in e||i(`Component does not have property "${s}" for state binding.`);const r=e[s];"object"==typeof r&&null!==r||i(`Component property "${s}" is not an object for state binding.`),this._boundComponent=e,this._boundComponentStateProp=s,ts(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{I in t&&await t[dt]()})}async _initializeDCC(t,e){let n;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?n=await lo(t):i(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?n=await ao(e,t.tagName.toLowerCase()):i(`DCC: No state source found for "${t.tagName.toLowerCase()}".`)}}catch(t){i(`DCC: Failed to load state: ${t}`)}!function(t,e,n){const s=t.tagName.toLowerCase();if(s.includes("-")||i(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s))return;const r=document.createElement("template");r.innerHTML=e.innerHTML;const a=e.mode,l=Array.isArray(n[v])?n[v]:[],c=l.length>0?function(t,e){return{protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`}))}}(s,l):null,d=l.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(s,l):{},u=`${o.tagNames.state}:not([name])`,f=class extends HTMLElement{static template=r;static shadowRootMode=a;static wcBindable=c;static bindableEventMap=d;_shadow=null;connectedCallback(){if(!this.hasAttribute(A)&&(this._shadow=this.attachShadow({mode:f.shadowRootMode}),this._shadow.appendChild(f.template.content.cloneNode(!0)),Object.keys(f.bindableEventMap).length>0)){const t=this._shadow.querySelector(u);t&&t.initializePromise.then(()=>{t.setBindableEventMap(f.bindableEventMap)})}}get stateElement(){return this._shadow?.querySelector(u)}},p=Object.getOwnPropertyDescriptors(n);for(const[t,e]of Object.entries(p)){if(ho(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=po(t,o)}else n.get=uo(t),n.set=fo(t);Object.defineProperty(f.prototype,t,n)}customElements.define(s,f)}(t,e,n),this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",t=>{_ in t&&t[ut]()})}async connectedCallback(){if(this._rootNode=this.getRootNode(),!this._initialized){const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(A))return void await this._initializeDCC(t.host,t);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!e()||await this._callStateConnectedCallback(),e()&&this.hasAttribute("enable-ssr")){await Gn(this.rootNode);const t=this.getAttribute("name")||"default",e=io.extractStateData(this),n=document.createElement(o.tagNames.ssr);n.setAttribute("name",t),n.setAttribute("version",r),io.buildContent(n,e),this.parentNode?.insertBefore(n,this)}this._resolveConnectedCallback?.()}disconnectedCallback(){null!==this._rootNode&&(this._callStateDisconnectedCallback(),Qn(this.rootNode,this._name,null),this._rootNode=null)}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}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&&i("State rootNode is not available."),this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get bindableEventMap(){return this._bindableEventMap}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&&(this._listPaths.add(t),this._elementPaths.add(t+"."+y)),!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 Fo(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}bindProperty(t,e){Object.defineProperty(this._state,t,e)}setInitialState(t){this._initialized?this._state=t:this._resolveSetState?.(t)}}function os(){customElements.get(o.tagNames.ssr)||customElements.define(o.tagNames.ssr,io),customElements.get(o.tagNames.state)||customElements.define(o.tagNames.state,ns)}function ss(t){var e;t&&((e=t).tagNames&&Object.assign(n.tagNames,e.tagNames),"string"==typeof e.bindAttributeName&&(n.bindAttributeName=e.bindAttributeName),"string"==typeof e.commentTextPrefix&&(n.commentTextPrefix=e.commentTextPrefix),"string"==typeof e.commentForPrefix&&(n.commentForPrefix=e.commentForPrefix),"string"==typeof e.commentIfPrefix&&(n.commentIfPrefix=e.commentIfPrefix),"string"==typeof e.commentElseIfPrefix&&(n.commentElseIfPrefix=e.commentElseIfPrefix),"string"==typeof e.commentElsePrefix&&(n.commentElsePrefix=e.commentElsePrefix),"string"==typeof e.locale&&(n.locale=e.locale),"boolean"==typeof e.debug&&(n.debug=e.debug),"boolean"==typeof e.enableMustache&&(n.enableMustache=e.enableMustache)),os()}function rs(t){return t}export{io as Ssr,r as VERSION,ss as bootstrapState,qn as buildBindings,rs as defineState,Gn as getBindingsReady,s as getConfig};
2
2
  //# sourceMappingURL=index.esm.min.js.map