@wcstack/state 1.10.0 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.min.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
package/dist/index.esm.min.js
CHANGED
|
@@ -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.10.0";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="$commandTokens",$="$command",C="data-wc-definition",E=new Map;let k=0;function M(t){let e=E.get(t);return void 0!==e||(e=Object.freeze(new T(t)),E.set(t,e)),e}class T{id=++k;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:M(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 O=new Set(["if","elseif","else","for"]);function W(t){i(`filter ${t} requires at least one option`)}function L(t){i(`filter ${t} requires a number as option`)}function D(t){i(`filter ${t} requires a number value`)}function R(t){i(`filter ${t} requires a date value`)}function F(t){return!(!t||isNaN(Number(t)))}const B={eq:t=>{const e=t?.[0]??W("eq");return t=>"number"==typeof t?(F(e)||L("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??W("ne");return t=>"number"==typeof t?(F(e)||L("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]??W("lt");return F(e)||L("lt"),t=>("number"!=typeof t&&D("lt"),t<Number(e))},le:t=>{const e=t?.[0]??W("le");return F(e)||L("le"),t=>("number"!=typeof t&&D("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??W("gt");return F(e)||L("gt"),t=>("number"!=typeof t&&D("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??W("ge");return F(e)||L("ge"),t=>("number"!=typeof t&&D("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??W("inc");return F(e)||L("inc"),t=>("number"!=typeof t&&D("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??W("dec");return F(e)||L("dec"),t=>("number"!=typeof t&&D("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??W("mul");return F(e)||L("mul"),t=>("number"!=typeof t&&D("mul"),t*Number(e))},div:t=>{const e=t?.[0]??W("div");return F(e)||L("div"),t=>("number"!=typeof t&&D("div"),t/Number(e))},mod:t=>{const e=t?.[0]??W("mod");return F(e)||L("mod"),t=>("number"!=typeof t&&D("mod"),t%Number(e))},fix:t=>{const e=t?.[0]??"0";return F(e)||L("fix"),t=>("number"!=typeof t&&D("fix"),t.toFixed(Number(e)))},locale:t=>{const e=t?.[0]??o.locale;return t=>("number"!=typeof t&&D("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]??W("slice");F(n)||L("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(F(o)||L("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??W("substr");F(e)||L("substr");const n=t?.[1]??W("substr");return F(n)||L("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??W("pad");F(e)||L("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??W("rep");return F(e)||L("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 F(e)||L("round"),t=>{"number"!=typeof t&&D("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return F(e)||L("floor"),t=>{"number"!=typeof t&&D("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return F(e)||L("ceil"),t=>{"number"!=typeof t&&D("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return F(e)||L("percent"),t=>("number"!=typeof t&&D("percent"),`${(100*t).toFixed(Number(e))}%`)},date:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("date"),t.toLocaleDateString(e))},time:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("time"),t.toLocaleTimeString(e))},datetime:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("datetime"),t.toLocaleString(e))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||R("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]??W("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},j=B,q={input:B,output:j},z=(t,e)=>n=>{const o=n[t];return o||i(`filter not found: ${t}`),o(e)};const H=new Map;function U(t,e){const n=q[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=H.get(s);return void 0===r&&(r=z(o,[])(n),H.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=H.get(l);return void 0===c&&(c=z(i,a)(n),H.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const V=t=>t.trim(),J=new Map;const X=new Map;function K(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),X.has(s)?r=X.get(s):(o=s.split("|").map(V),r=U(o,"output"),X.set(s,r))):n=t.trim();const[i,a="default"]=n.split("@").map(V);return{stateName:a,statePathName:i,statePathInfo:M(i),outFilters:r}}function Y(t){const[...e]=t.split(";").map(V).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:M("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("if"===n||"elseif"===n||"for"===n||"radio"===n||"checkbox"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...K(o),bindingType:n}}{const t=K(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(),J.has(s)?r=J.get(s):(o=s.split("|").map(V),r=U(o,"input"),J.set(s,r))):n=t.trim();const[i,a]=n.split("#").map(V),l=i.split(".").map(V);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(V):[],inFilters:r}}(n);return e.propSegments[0].startsWith("on")?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(n.length>1){n.some(t=>O.has(t.bindingType))&&i(`Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const G=new WeakMap,Q=new Set([o.commentTextPrefix,o.commentForPrefix,o.commentIfPrefix,o.commentElseIfPrefix,o.commentElsePrefix]),Z=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function tt(t){const e=G.get(t);if("string"==typeof e)return e;if(t.nodeType!==Node.COMMENT_NODE)return null;const n=t.data.trim(),s=Z.exec(n);if(null===s)return null;const r=s[1]||o.commentTextPrefix;return Q.has(r)?(G.set(t,s[2]),s[2]):null}function et(t){if(t.nodeType===Node.ELEMENT_NODE){return Y(t.getAttribute(o.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=tt(t);null===e&&i("Comment node binding text not found.");const n=ro(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...K(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function nt(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!==tt(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}const ot=new WeakSet;function st(t){const e=nt(t),n=[];for(const t of e)if(!ot.has(t)){ot.add(t);const e=h(t,et(t));b(t,e),u(t),n.push(...e)}return[e,n]}const rt=new WeakMap;function it(t){let e=t;for(;e;){const t=rt.get(e);if(t)return t;e=e.parentNode}return null}function at(t,e){null!==e?rt.set(t,e):rt.delete(t)}const lt=Symbol("$$setLoopContextAsync"),ct=Symbol("$$setLoopContext"),dt=Symbol("$$getByAddress"),ut=Symbol("$$setByAddress"),ft=Symbol("$$connectedCallback"),pt=Symbol("$$disconnectedCallback"),ht=Symbol("$$updatedCallback"),mt=new Map,gt=new Map;function bt(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=mt.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=to(e.getRootNode(),o);null===n&&i(`State element with name "${o}" not found for event handler.`);const a=it(e);n.createStateAsync("writable",async e=>{e[ct](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??[]])})})},mt.set(e,n));const a=t.propName.slice(2);t.node.addEventListener(a,n);let l=gt.get(e);return void 0===l?(l=new Set([t]),gt.set(e,l)):l.add(t),!0}const wt=new WeakMap;function yt(t){const e=wt.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{wt.set(t,n)}}const Nt=new Set(["radio","checkbox"]),xt=new Set(["value","valueAsNumber","valueAsDate"]);const St=new Map,It=new Map,_t=t=>t.detail;function Pt(t){const e=yt(t.node);if(null!==e){if(void 0===customElements.get(e))return void customElements.whenDefined(e).then(()=>{Pt(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(Nt.has(t)&&"checked"===e)return!0;if(xt.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=yt(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=yt(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=yt(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??_t}}}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=St.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=to(a.getRootNode(),t);null===d&&i(`State element with name "${t}" not found for two-way binding.`);const u=it(a);d.createState("writable",t=>{t[ct](u,()=>{t[n]=c})})})(t.stateName,t.propName,t.statePathName,t.inFilters,n),St.set(o,s)),t.node.addEventListener(e,s);let r=It.get(o);void 0===r?(r=new Set([t]),It.set(o,r)):r.add(t)}}const vt=new WeakMap;function At(t){return vt.get(t)??[]}function $t(t,e){vt.set(t,e)}const Ct=new WeakMap;function Et(t,e){if(Ct.has(t)){const n=Ct.get(t);if(n.has(e))return n.get(e)}else Ct.set(t,new WeakMap);const n=Object.freeze(new kt(t,e));return Ct.get(t).set(e,n),n}class kt{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=Et(t,e.parentPathInfo)}}const Mt=new WeakMap,Tt=new WeakMap;class Ot{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=Wt(t,e)}}function Wt(t,e){if(null===e){let e=Tt.get(t);return void 0!==e||(e=new Ot(t,null),Tt.set(t,e)),e}{let n=Mt.get(e);void 0===n&&(n=new WeakMap,Mt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Ot(t,e),n.set(t,o)),o}}const Lt=new WeakMap;function Dt(t,e){null===e?Lt.delete(t):Lt.set(t,e)}function Rt(t){return Lt.get(t)||null}const Ft=new Map;function Bt(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=Ft.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Ft.set(s,r),r}const jt=new WeakMap;function qt(t){const e=it(t.node);if(null===e)return null;let n=jt.get(e);if(void 0===n)n=new WeakMap,jt.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=Bt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const zt=new WeakMap;function Ht(t){let e=null;if(e=zt.get(t)||null,null!==e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Rt(n);null===e?i(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}const o=qt(t),s=to(n,t.stateName);null===s&&i(`State element with name "${t.stateName}" not found for binding.`);return e=Wt(Et(s,t.statePathInfo),o),zt.set(t,e),e}function Ut(t){zt.delete(t)}const Vt=new WeakMap;function Jt(t,e){const n=Vt.get(t);return!!n&&!0===n.get(e)}function Xt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Kt=Object.freeze([]);class Yt{_name;_subscribers=new Set;constructor(t){this._name=t}get name(){return this._name}get size(){return this._subscribers.size}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}unsubscribe(t){return this._subscribers.delete(t)}emit(...t){const e=[];for(const n of this._subscribers)e.push(n(...t));return e}}const Gt=new WeakMap;const Qt=new WeakMap,Zt=new WeakMap;class te{pathInfo;listIndex;_parentAddress;constructor(t,e){this.pathInfo=t,this.listIndex=e}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let e=null;return e=this.pathInfo.segments[this.pathInfo.segments.length-1]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=ee(t,e)}}function ee(t,e){if(null===e){let e=Zt.get(t);return void 0!==e||(e=new te(t,null),Zt.set(t,e)),e}{let n=Qt.get(e);void 0===n&&(n=new WeakMap,Qt.set(e,n));let o=n.get(t);return void 0!==o||(o=new te(t,e),n.set(t,o)),o}}const ne=new WeakMap;function oe(t){return ne.get(t)??[]}function se(t,e){ne.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 re=0;function ie(){return`u${(re++).toString(36)}`}let ae=0;class le{uuid=ie();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=ae}get index(){return this._index}set index(t){this._index=t,this._version=++ae,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=ae),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 ce(t,e){return new le(t,e)}const de=new WeakMap;function ue(t){return de.get(t)||null}function fe(t,e){null!==e?de.set(t,e):de.delete(t)}const pe=new WeakMap,he=Object.freeze([]),me=new Set;function ge(t,e,n){const o=Array.isArray(e)&&e.length>0?e:he,s=Array.isArray(n)&&n.length>0?n:he,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:he,o=Array.isArray(e)&&e.length>0?e:he;let s=pe.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=ue(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:me,deleteIndexSet:new Set(i),addIndexSet:me};let e=ue(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=ce(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:me,deleteIndexSet:me,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:me,deleteIndexSet:me,addIndexSet:me};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=ce(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=pe.get(t);o||(o=new WeakMap,pe.set(t,o)),o.set(e,n)}(o,s,a),fe(s,a.newIndexes))}}const be=new WeakMap;function we(t){let e=null;return e=be.get(t)||null,null===e&&(e=new Set,be.set(t,e)),e}function ye(t,e){we(t).add(e)}function Ne(t,e){we(t).delete(e)}const xe=new WeakMap;function Se(t){xe.delete(t)}const Ie=new WeakMap;function _e(t){return Ie.get(t)??[]}function Pe(t,e){Ie.set(t,e)}const ve=new WeakMap;function Ae(t){return ve.get(t)??[]}function $e(t,e){ve.set(t,e)}function Ce(t,e){const n=Ae(t);for(const t of n)at(t,e)}function Ee(t,e,n){Ce(t,e);const o=_e(t);for(const t of o){ye(Ht(t),t),pn(t,n)}}function ke(t){if(!t.mounted)return;const e=_e(t);for(const t of e){Ne(Ht(t),t),Ut(t),Se(t)}!function(t){const e=Ae(t);for(const t of e)at(t,null)}(t)}const Me=new WeakMap,Te=Object.freeze(new Set);function Oe(t,e){const n=Me.get(t);n?n.add(e):Me.set(t,new Set([e]))}function We(t){const e=Me.get(t);return void 0!==e?e:Te}const Le=new Set(["if","elseif","else","for"]);class De{_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=_e(this);for(const e of t){if(Le.has(e.bindingType)){const t=We(e.node);for(const e of t)e.unmount()}Se(e),Ut(e)}this._mounted=!1}}function Re(t){const e=document.createDocumentFragment(),n=new De(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 Fe(t){void 0!==t.uuid&&null!==t.uuid||i("BindingInfo.uuid is null.");const e=ro(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.`),!ot.has(e)){ot.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 In(o),{nodes:n,bindingInfos:o}}(n,e.nodeInfos),s=new De(n);Pe(s,o.bindingInfos);const r=[];for(const t of o.bindingInfos)t.statePathName in S&&r.push(t);return se(s,r),$e(s,o.nodes),Oe(t.node,s),s}const Be=new WeakMap,je=new WeakMap,qe=new WeakMap,ze=new WeakMap;function He(t,e,n){Ke(t,e,n)}function Ue(t,e){Be.set(t,e)}function Ve(t){return qe.get(t.node)||[]}function Je(t,e){const n=qe.get(t.node);void 0===n?qe.set(t.node,[e]):n.push(e)}function Xe(t,e){let n=je.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ke(t,e,n){let o=je.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,je.set(t,o)}null===n?o.delete(e):o.set(e,n)}const Ye=new WeakMap;function Ge(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Qe(t,n,s){const r=t.node.isConnected,i=Boolean(s);let a;const l=We(t.node);a=0===l.size?Fe(t):l.values().next().value;const c=e(),d=t.uuid??"",u=t.bindingType;try{if(i||(o.debug&&console.log(`unmount if content : ${Ge(t)}`),ke(a),a.unmount()),i){if(o.debug&&console.log(`mount if content : ${Ge(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);Ee(a,it(t.node),n)}}finally{Ye.set(t.node,r)}}const Ze=new WeakMap;function tn(t){return Ze.get(t)??[]}const en=new Set;const nn={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 on(t,n,s){const r=t.node,i=t.propSegments;if(1===i.length){const t=i[0];if(r[t]!==s){let e=!1;try{r[t]=s,e=!0}catch(e){o.debug&&console.warn(`Failed to set property '${t}' on element.`,{element:r,newValue:s,error:e})}if(e){const e=function(t,e){const n=yt(t);if(null===n)return null;const o=customElements.get(n);if(void 0===o)return null;const s=o.wcBindable;if("wc-bindable"!==s?.protocol||1!==s?.version)return null;const r=s.inputs;if(!Array.isArray(r))return null;for(const t of r)if(t.name===e&&"string"==typeof t.attribute&&t.attribute.length>0)return t.attribute;return null}(r,t);if(null!==e)try{!function(t,e,n){if(null==n)return void t.removeAttribute(e);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);t.setAttribute(e,o)}(r,e,s)}catch(t){o.debug&&console.warn(`Failed to mirror attribute '${e}' on element.`,{element:r,newValue:s,error:t})}}}if(e()){const e=nn[t];e?e(r,s):(!function(t,e,n){let o=Ze.get(t);o||(o=[],Ze.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,en.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 sn=new WeakSet;function rn(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 an(t,e){const n=function(t){let e=null;if(e=xe.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=qt(t);null===n&&i(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=ee(t.statePathInfo,n)}else e=ee(t.statePathInfo,null);return xe.set(t,e),e}(e);if(n.pathInfo.path in S){const t=it(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[dt](n)}const ln={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)},command:function(t,e,n){n instanceof Yt||i("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Gt.get(t);if(s&&s.token===o)return;const r=t.node,a=t.propSegments[1];"string"==typeof a&&0!==a.length||i('command binding requires a method name (e.g., "command.fetch").');const l=function(t){const e=yt(t);if(null===e)return null;const n=customElements.get(e);void 0===n&&i(`Custom element <${e}> is not defined for command binding.`);const o=n.wcBindable;return"wc-bindable"===o?.protocol&&1===o?.version?o:null}(r);null===l&&i(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),Array.isArray(l.commands)&&l.commands.some(t=>t.name===a)||i(`Command "${a}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),s&&(s.unsubscribe(),Gt.delete(t));const c=new WeakRef(r);let d=null;d=o.subscribe((...e)=>{const n=c.deref();if(!n||!n.isConnected)return d?.(),void Gt.delete(t);const o=n[a];return"function"!=typeof o&&i(`Method "${a}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,e)}),Gt.set(t,{token:o,unsubscribe:d,elementRef:c})}},cn={text:function(t,n,o){if(t.replaceNode.nodeValue!==o&&(t.replaceNode.nodeValue=o),e()&&!sn.has(t.replaceNode)){sn.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=qt(t),a=Ht(t),l=At(a),c=ge(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=ze.get(t.node);if(void 0===e){const n=Be.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),ze.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=Xe(t.node,e);null!==n&&(ke(n),n.unmount(),Je(t,n),Ke(t.node,e,null))}let d=t.node;const u=M(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(),Dt(p,n.rootNode));const h=e(),m=t.uuid??"";for(const e of c.newIndexes){let o;if(c.addIndexSet.has(e)){const r=ee(u,e);f.createLoopContext(r,r=>{const i=Ve(t);if(o=i.pop(),void 0===o&&(o=Fe(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)}}Ee(o,r,n)}),void 0===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=Xe(t.node,e),c.changeIndexSet.has(e)){const t=oe(o);for(const e of t)pn(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,Ke(t.node,e,o)}Be.set(t.node,d),null!==p&&(t.node.parentNode.insertBefore(p,t.node.nextSibling),Dt(p,null))},if:Qe,else:Qe,elseif:Qe,radio:function(t,e,n){const o=t.node,s=Xt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Xt(o.value,t.inFilters),r=Array.isArray(n)?n:Kt;o.checked=r.includes(s)}},dn=new WeakMap,un=new WeakMap;function fn(t,e){const n=Xt(an(e.state,t),t.outFilters);if(!0===un.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=dn.get(t);if(void 0===o){if(dn.has(t))return Jt(t.replaceNode,e.stateElement)?(o=rn,dn.set(t,o)):o=on,void o(t,e,n);if(o=cn[t.bindingType],void 0===o){const n=t.propSegments[0];if(o=ln[n],dn.set(t,o),void 0===o){yt(t.replaceNode)?Jt(t.replaceNode,e.stateElement)?(o=rn,dn.set(t,o)):o=on:(o=on,dn.set(t,o))}}if(o===on){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void un.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function pn(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const n=Ht(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=yt(t.replaceNode);if(o&&void 0===customElements.get(o))return;let s=t.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=Rt(s),null===s&&i("Root node for fragment not found for binding.")),t.stateName!==e.stateName||s!==e.rootNode){const n=to(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};fn(t,r)})}else fn(t,e)}function hn(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=Rt(d),null===d&&i("Root node for fragment not found for binding."));const u=to(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(;;){pn(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)on(t,0,e);for(const[t,e]of s.entries())$t(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[ht](Array.from(e))})}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("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=to(s.getRootNode(),t);null===a&&i(`State element with name "${t}" not found for two-way binding.`);const l=it(s);a.createState("writable",t=>{t[ct](l,()=>{t[e]=r})})};function wn(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=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}const yn=new Map,Nn=new Map;const xn=(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=to(s.getRootNode(),t);null===l&&i(`State element with name "${t}" not found for two-way binding.`);const c=it(s);l.createState("writable",t=>{t[ct](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 Sn(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=yn.get(n);void 0===o&&(o=xn(t.stateName,t.statePathName,t.inFilters),yn.set(n,o)),t.node.addEventListener(e,o);let s=Nn.get(n);return void 0===s?(s=new Set([t]),Nn.set(n,s)):s.add(t),!0}return!1}function In(t){for(const e of t)f(e),bt(e)||(Pt(e),wn(e),Sn(e))}function _n(t,e){const[n,o]=st(t);for(const t of n)at(t,e);In(o);for(const t of o){ye(Ht(t),t);const e=to(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)}hn(o)}const Pn=/\{\{\s*(.+?)\s*\}\}/g,vn=new Set(["SCRIPT","STYLE"]);function An(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&&vn.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),An(e.content)}else An(t.content)}function $n(t){const e=t.data;if(Pn.lastIndex=0,!Pn.test(e))return;Pn.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=Pn.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 Cn;function En(){if(Cn)return Cn;const t=[],e=z("not",t)(j);return Cn={filterName:"not",args:t,filterFn:e},Cn}const kn=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Mn(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 Tn(t,e){const n=kn.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+Mn(s,e)+r}function On(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=Mn(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function Wn(t,e){return On(t,e)}function Ln(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=Tn(n.data,e);continue}const o=t;if(o instanceof HTMLTemplateElement)continue;const r=o.getAttribute(n);if(null!==r){const t=On(r,e);t!==r&&o.setAttribute(n,t)}}}function Dn(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 Rn(t){const e=[],n=nt(t);for(const t of n){const n=et(t);e.push({nodePath:Dn(t),parseBindTextResults:n})}return e}function Fn(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 Bn=new Map([["for",o.commentForPrefix],["if",o.commentIfPrefix],["elseif",o.commentElseIfPrefix],["else",o.commentElsePrefix]]),jn=En();function qn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,jn],bindingType:t}}function zn(t,e,n,o){Fn(e),"string"==typeof o&&Ln(e,o),Hn(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:Rn(e)}}function Hn(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=Wn(r,n));let c=Y(r)[0];const d=Bn.get(c.bindingType);if(void 0===d)continue;const u=c.bindingType,f=e.content,p=ie();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=qn("else",a.parseBindTextResult),h=zn(t,f,c,m),so(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:Dn(o),parseBindTextResults:et(o)})):e.replaceWith(o)}else if("elseif"===u){null===a&&i("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=zn(t,f,c,m),so(p,t,h);const n=document.createComment(`@@${d}:${p}`),o=ie(),r={fragment:document.createDocumentFragment(),parseBindTextResult:qn("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:Dn(n),parseBindTextResults:et(n)}),so(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:Dn(g),parseBindTextResults:et(g)})):e.replaceWith(g)}else{h=zn(t,f,c,m),so(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 Un(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 Vn(t){if(t===document)await Un(document),An(document),Hn(document,document),_n(document.body,null);else{const e=t;e.host.hasAttribute(o.bindAttributeName)&&await d(e.host),await Un(e),An(e),Hn(e,e),_n(e,null)}}const Jn=new Set(["for","if","elseif","else"]);function Xn(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]=st(o);for(const t of r)f(t),bt(t)||(Pt(t),wn(t),Sn(t));if(e)for(;o.firstChild;)e.insertBefore(o.firstChild,n);return{bindingInfos:r,subscriberNodes:s}}function Kn(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 Yn(t,e){const n=t;let s=null;for(const[t,r]of e.templates){let e=Y(r.getAttribute(o.bindAttributeName)||"")[0];const i=e.bindingType;"else"===i&&s?e={...s,outFilters:[...s.outFilters,En()],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;Fn(a),"string"==typeof l&&Ln(a,l),Hn(n,a,l);so(t,n,{fragment:a,parseBindTextResult:e,nodeInfos:Rn(a)})}}async function Gn(t){await Un(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.`),uo.cleanupDom(t),!1}for(const n of e)Yn(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=ao.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=Re(o.nodes),{bindingInfos:s,subscriberNodes:r}=Xn(o.nodes);for(const t of r)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");Pe(e,s),$e(e,r);const i=[];for(const t of s)t.statePathName in S&&i.push(t);if(se(e,i),"for"===o.type&&null!==o.index){const r=Kn(t,"for",o.uuid);if(r){const t=ce(null,o.index);He(r,t,e),Ue(r,o.nodes[o.nodes.length-1]),Oe(r,e),Ce(e,ee(M(o.path+"."+y),t));for(const t of s)ye(Ht(t),t);let i=n.get(o.uuid);i||(i=[],n.set(o.uuid,i)),i.push(t)}}else{const n=Kn(t,o.type,o.uuid);if(n){Oe(n,e);for(const t of s)ye(Ht(t),t)}}}for(const[e,o]of n){const n=Kn(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=ro(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=to(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&fe(e,o)})}}(document.body,n),uo.removeBlockBoundaryComments(document.body);const s=[];for(const t of e)t.parentNode&&(s.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());uo.restoreTextBindings(document.body);const[a,l]=st(document.body);for(const t of a)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(at(t,null),e.setAttribute("data-wcs-completed",""))}else at(t,null);const c=[],d=[];for(const t of l)if(f(t),!bt(t))if(Pt(t),wn(t),Sn(t),Jn.has(t.bindingType))d.push(t);else{if(t.statePathName.includes(y))continue;c.push(t)}for(const t of[...c,...d]){ye(Ht(t),t);const e=to(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=Ht(t),n=to(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&$t(e,o)})}hn(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 Qn=new WeakMap,Zn=new WeakMap;function to(t,e){let n=Qn.get(t);return n&&n.get(e)||null}function eo(t){return Zn.get(t)??Promise.resolve()}function no(t,n,s){let r=Qn.get(t);if(null===s){if(!r)return;r.delete(n),0===r.size&&Qn.delete(t),o.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,Qn.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 Gn(t)||await Vn(t)}else await Vn(t);e()})});Zn.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await Vn(t),e()})});Zn.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 oo=new Map;function so(t,e,n){if(null===n)oo.delete(t);else{oo.set(t,n);const o=n.parseBindTextResult,s=to(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=to(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 ro(t){return oo.get(t)||null}const io=/^@@wcs-(?:for|if|elseif|else):[^-]/,ao=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,lo=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,co=/^@@wcs-text-start:(.+)$/;class uo 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(oo.keys());for(const e of s){const n=ro(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(en);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=tn(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)}}en.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(ao.test(t.data)||lo.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;io.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=co.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;ao.test(t.data)&&i.push(t)}for(const t of i){const e=ao.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()}uo.restoreTextBindings(e);const a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(io.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 fo(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 po(t){try{return(await import(t)).default||{}}catch(t){i(`Failed to load script file: ${t}`)}}class ho{_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}}const mo=new WeakMap;function go(t,e){let n=mo.get(t);void 0===n&&(n=new Map,mo.set(t,n));let o=n.get(e);return void 0===o&&(o=new Yt(e),n.set(e,o)),o}const bo=new WeakMap;function wo(t){const e=bo.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return go(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:go(t,n)}},set(){i("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){i("$command namespace is read-only; deleting from it is not allowed.")}});return bo.set(t,n),n}function yo(t){return function(){const e=this.stateElement;if(!e)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function No(t){return function(e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})})}}function xo(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function So(t){return t.startsWith("$")}const Io=new Map;class _o{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=M(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 Po(t){let e;return Io.get(t)??(Io.set(t,e=new _o(t)),e)}const vo=new WeakMap;function Ao(t,e){null===e?vo.delete(t):vo.set(t,e)}function $o(t){const e=vo.get(t);e&&(e.dirty=!0)}function Co(t,e,n,o,s){if(e.pathInfo.segments[0]===$){let t=wo(s);for(let n=1;n<e.pathInfo.segments.length;n++){if(null==t)return;t=Reflect.get(t,e.pathInfo.segments[n])}return t}if(!(e.pathInfo.path in t)){const s=ko(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 Eo(t,e,n,o,s){const r=Wt(Et(s,e.pathInfo),e.listIndex),i=function(t){return vo.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=Co(t,e,n,o,s);return Ao(r,{value:a,dirty:!1}),a}function ko(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)?Eo(t,e,n,o,s):Co(t,e,n,o,s)}function Mo(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 To=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=we(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}hn(n)}};function Oo(){return To}const Wo=new WeakMap;function Lo(t,e){null===e?Wo.delete(t):Wo.set(t,e)}function Do(t,e,n){const s=M(t.wildcardParentPaths[e]),r=Et(t.stateElement,s),i=ee(s,n),a=At(Wt(r,n)),l=t.stateProxy[dt](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}`),[]}}(ge(i.listIndex,a,l),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...c);else for(const n of c)Do(t,e+1,n)}function Ro(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=M(n);if(t.listPathSet.has(r)&&o.lastSegment===y){const n=t.stateProxy[dt](e),s=At(Wt(Et(t.stateElement,e.pathInfo),e.listIndex)),r=ge(e.listIndex,s,n);for(const e of r.newIndexes){const n=ee(o,e);t.result.add(n),l.push({address:n,depth:a})}}else{const n=ee(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=M(n),s=[];if(o.wildcardCount>0){const n=Bt(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};Do(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=ee(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 Fo(t,e,n,o,s,r){try{if(!(e.pathInfo.path in t)){const n=ko(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=Oo();t.enqueueAbsoluteAddress(n),Ro(r.stateName,r.stateElement,e,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,s,"new",n=>{if(n===e)return;const o=Wt(Et(r.stateElement,n.pathInfo),n.listIndex);$o(o),t.enqueueAbsoluteAddress(o)})}}function Bo(t,e,n,o,s,r){let a=e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Wo.get(t)??null}(a);if(null===l){const e=ko(t,a,s,r)??[],n=ue(e)??[];l={value:[...e],listIndexes:[...n]},Lo(a,l)}try{return Fo(t,e,n,o,s,r)}finally{const n=l.value.indexOf(o),i=ko(t,a,s,r)??[],c=Array.isArray(i)?ue(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:ce(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;Lo(a,null)}}}function jo(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=Wt(Et(r,e.pathInfo),e.listIndex);try{return i?Bo(t,e,l,n,o,s):Fo(t,e,l,n,o,s)}finally{a&&Ao(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 qo(t,e,n,o){return(e,s,r)=>{const a=M(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=ee(r,l),d=ue(ko(t,c,n,o));null==d&&i(`ListIndexes not found: ${r.path}`);l=d[s[e]]??i(`ListIndex not found: ${r.path}`)}const c=ee(a,l);if(!(void 0!==r))return ko(t,c,n,o);jo(t,c,r,n,o)}}const zo=new WeakMap;function Ho(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return Mo(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=(ue(ko(t,ee(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 Uo(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 Vo(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=Po(e),r=Ho(t,s,n,o),i=ee(s.pathInfo,r);return ko(t,i,n,o)}switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=qo(t,0,n,o);return(e,r)=>{const a=new Map,l=M(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=Mo(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=ee(p,r),m=zo.get(h),g=ko(t,h,n,o),b=ge(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())zo.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=Po(e),i=Ho(t,r,n,o),a=ee(r.pathInfo,i),l=Wt(Et(s,a.pathInfo),a.listIndex),c=Oo();c.enqueueAbsoluteAddress(l),Ro(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=Wt(Et(s,t.pathInfo),t.listIndex);$o(e),c.enqueueAbsoluteAddress(e)})}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>qo(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);case $:return wo(o.stateElement)}}else if("symbol"==typeof e){switch(e){case lt:return(t,e=async()=>{})=>async function(t,e,n){return await Uo(t,e,n)}(o,t,e);case ct:return(t,e=()=>{})=>function(t,e,n){return Uo(t,e,n)}(o,t,e);case dt:return e=>ko(t,e,n,o);case ut:return(e,s)=>jo(t,e,s,n,o);case ft:return()=>async function(t,e,n){const o=Reflect.get(t,I);"function"==typeof o&&await o.call(n)}(t,0,n);case pt:return()=>function(t,e,n){const o=Reflect.get(t,_);"function"==typeof o&&o.call(n)}(t,0,n);case ht: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 Jo{_stateElement;_stateName;_addressStack=Array(N).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,n){this._stateName=e;const o=to(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 Vo(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=Po(e),i=Ho(t,r,o,s);return jo(t,ee(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 Xo=new WeakMap;const Ko=new WeakMap;function Yo(t,e){const n=Ko.get(t);return n?n.get(e)??null:null}const Go=new WeakMap,Qo=new WeakMap,Zo=new WeakMap,ts=new WeakMap;function es(t,e){return{innerAbsPathInfo:Et(t,M(e.propSegments.slice(1).join(w))),outerAbsPathInfo:Ht(e).absolutePathInfo}}function ns(t,e){let n=Go.get(t);if(void 0===n&&(n=new Map,Go.set(t,n)),n.has(e))return n.get(e);let o=Qo.get(t);void 0===o&&(o=new Map,Qo.set(t,o));const s=Zo.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=ts.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=M(r.outerAbsPathInfo.pathInfo.segments.concat(l).join(w)),d=to(t.getRootNode(),a.stateName);null===d&&i(`State element with name "${a.stateName}" not found for web component.`);const u=Et(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 os(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 ss{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=Yo(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=M(e),s=Et(this._innerStateElement,o),r=ns(this._webComponent,s);if(null!==r){const t=it(this._webComponent);let e;return r.stateElement.createState("readonly",n=>{n[ct](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){Xo.set(t,e)}(Wt(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=M(e),r=Et(this._innerStateElement,s),a=ns(this._webComponent,r);if(null!==a){const t=it(this._webComponent);return a.stateElement.createState("writable",e=>{e[ct](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=M(e),o=Et(this._innerStateElement,n);return null!==ns(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class rs{_innerStateElement;constructor(t,e){this._innerStateElement=Yo(t,e)??i("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=M(e),n=Wt(Et(this._innerStateElement,t),null);return o=n,Xo.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=M(e),n=Et(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class is{_innerStateElement;constructor(t,e){this._innerStateElement=Yo(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 as=t=>()=>t;function ls(t,e,n,s){if(function(t,e,n){let o=Ko.get(t);o||(o=new Map,Ko.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=Yo(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=es(o,e);let i=Zo.get(t);void 0===i?Zo.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;ts.set(n,e),s.set(a,l),r.set(l,a)}Go.set(t,s),Qo.set(t,r)}(e,n,o);const s=function(t,e){const n=new rs(t,e);return new Proxy({},n)}(e,n),r=function(t,e){const n=new ss(t,e),o=Yo(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(os(s),n)}(e,n);t.setInitialState(r),Object.defineProperty(e,n,{get:as(s),enumerable:!0,configurable:!0})}else{t.setInitialState(os(s));const o=function(t,e){const n=new is(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:as(o),enumerable:!0,configurable:!0})}if(function(t,e){let n=Vt.get(t);n||(n=new WeakMap,Vt.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 cs(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 ds extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return eo(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 ho}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};_commandTokenNames=new Set;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._commandTokenNames=function(t){const e=new Set,n=t[A];if(void 0===n)return e;Array.isArray(n)||i(`${A} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||i(`${A} entries must be non-empty strings.`),t===$&&i(`${A} entry "${t}" conflicts with the reserved namespace name "${$}".`),e.has(t)&&i(`${A} entry "${t}" is duplicated.`),e.add(t);return e}(t),this.__state=t,this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._pathSet.clear();const e=cs(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=uo.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 po(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 fo(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",no(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?yt(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,ls(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{I in t&&await t[ft]()})}async _initializeDCC(t,e){let n;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?n=await po(t):i(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?n=await fo(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 void console.warn(`[@wcstack/state] DCC: "${s}" is already registered. Skipping redefinition.`);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(C)&&(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(So(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=xo(t,o)}else n.get=yo(t),n.set=No(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[pt]()})}async connectedCallback(){if(this._rootNode=this.getRootNode(),!this._initialized){const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(C))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 eo(this.rootNode);const t=this.getAttribute("name")||"default",e=uo.extractStateData(this),n=document.createElement(o.tagNames.ssr);n.setAttribute("name",t),n.setAttribute("version",r),uo.buildContent(n,e),this.parentNode?.insertBefore(n,this)}this._resolveConnectedCallback?.()}disconnectedCallback(){var t;null!==this._rootNode&&(this._callStateDisconnectedCallback(),no(this.rootNode,this._name,null),t=this,mo.delete(t),function(t){bo.delete(t)}(this),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}get commandTokenNames(){return this._commandTokenNames}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=M(t);if(this._pathSet.add(t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=M(t.parentPath)}}}_createState(t,e,n){try{const o=function(t,e,n,o){const s=new Jo(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 us(){customElements.get(o.tagNames.ssr)||customElements.define(o.tagNames.ssr,uo),customElements.get(o.tagNames.state)||customElements.define(o.tagNames.state,ds)}function fs(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)),us()}function ps(t){return t}export{uo as Ssr,r as VERSION,fs as bootstrapState,Vn as buildBindings,ps as defineState,eo 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.10.3";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="$commandTokens",$="$command",C="data-wc-definition",E=new Map;let k=0;function M(t){let e=E.get(t);return void 0!==e||(e=Object.freeze(new T(t)),E.set(t,e)),e}class T{id=++k;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:M(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 O=new Set(["if","elseif","else","for"]);function W(t){i(`filter ${t} requires at least one option`)}function L(t){i(`filter ${t} requires a number as option`)}function D(t){i(`filter ${t} requires a number value`)}function R(t){i(`filter ${t} requires a date value`)}function F(t){return!(!t||isNaN(Number(t)))}const B={eq:t=>{const e=t?.[0]??W("eq");return t=>"number"==typeof t?(F(e)||L("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??W("ne");return t=>"number"==typeof t?(F(e)||L("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]??W("lt");return F(e)||L("lt"),t=>("number"!=typeof t&&D("lt"),t<Number(e))},le:t=>{const e=t?.[0]??W("le");return F(e)||L("le"),t=>("number"!=typeof t&&D("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??W("gt");return F(e)||L("gt"),t=>("number"!=typeof t&&D("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??W("ge");return F(e)||L("ge"),t=>("number"!=typeof t&&D("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??W("inc");return F(e)||L("inc"),t=>("number"!=typeof t&&D("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??W("dec");return F(e)||L("dec"),t=>("number"!=typeof t&&D("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??W("mul");return F(e)||L("mul"),t=>("number"!=typeof t&&D("mul"),t*Number(e))},div:t=>{const e=t?.[0]??W("div");return F(e)||L("div"),t=>("number"!=typeof t&&D("div"),t/Number(e))},mod:t=>{const e=t?.[0]??W("mod");return F(e)||L("mod"),t=>("number"!=typeof t&&D("mod"),t%Number(e))},fix:t=>{const e=t?.[0]??"0";return F(e)||L("fix"),t=>("number"!=typeof t&&D("fix"),t.toFixed(Number(e)))},locale:t=>{const e=t?.[0]??o.locale;return t=>("number"!=typeof t&&D("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]??W("slice");F(n)||L("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(F(o)||L("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??W("substr");F(e)||L("substr");const n=t?.[1]??W("substr");return F(n)||L("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??W("pad");F(e)||L("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??W("rep");return F(e)||L("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 F(e)||L("round"),t=>{"number"!=typeof t&&D("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return F(e)||L("floor"),t=>{"number"!=typeof t&&D("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return F(e)||L("ceil"),t=>{"number"!=typeof t&&D("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return F(e)||L("percent"),t=>("number"!=typeof t&&D("percent"),`${(100*t).toFixed(Number(e))}%`)},date:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("date"),t.toLocaleDateString(e))},time:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("time"),t.toLocaleTimeString(e))},datetime:t=>{const e=t?.[0]??o.locale;return t=>(t instanceof Date||R("datetime"),t.toLocaleString(e))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||R("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]??W("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},j=B,q={input:B,output:j},z=(t,e)=>n=>{const o=n[t];return o||i(`filter not found: ${t}`),o(e)};const H=new Map;function U(t,e){const n=q[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=H.get(s);return void 0===r&&(r=z(o,[])(n),H.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=H.get(l);return void 0===c&&(c=z(i,a)(n),H.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const V=t=>t.trim(),J=new Map;const X=new Map;function K(t){const e=t.indexOf("|");let n="",o=[],s="",r=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),X.has(s)?r=X.get(s):(o=s.split("|").map(V),r=U(o,"output"),X.set(s,r))):n=t.trim();const[i,a="default"]=n.split("@").map(V);return{stateName:a,statePathName:i,statePathInfo:M(i),outFilters:r}}function Y(t){const[...e]=t.split(";").map(V).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:M("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("if"===n||"elseif"===n||"for"===n||"radio"===n||"checkbox"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...K(o),bindingType:n}}{const t=K(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(),J.has(s)?r=J.get(s):(o=s.split("|").map(V),r=U(o,"input"),J.set(s,r))):n=t.trim();const[i,a]=n.split("#").map(V),l=i.split(".").map(V);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(V):[],inFilters:r}}(n);return e.propSegments[0].startsWith("on")?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(n.length>1){n.some(t=>O.has(t.bindingType))&&i(`Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const G=new WeakMap,Q=new Set([o.commentTextPrefix,o.commentForPrefix,o.commentIfPrefix,o.commentElseIfPrefix,o.commentElsePrefix]),Z=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function tt(t){const e=G.get(t);if("string"==typeof e)return e;if(t.nodeType!==Node.COMMENT_NODE)return null;const n=t.data.trim(),s=Z.exec(n);if(null===s)return null;const r=s[1]||o.commentTextPrefix;return Q.has(r)?(G.set(t,s[2]),s[2]):null}function et(t){if(t.nodeType===Node.ELEMENT_NODE){return Y(t.getAttribute(o.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=tt(t);null===e&&i("Comment node binding text not found.");const n=ro(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...K(e),bindingType:"text"},s=null):s=e,[{...o,uuid:s}]}return[]}function nt(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!==tt(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}const ot=new WeakSet;function st(t){const e=nt(t),n=[];for(const t of e)if(!ot.has(t)){ot.add(t);const e=h(t,et(t));b(t,e),u(t),n.push(...e)}return[e,n]}const rt=new WeakMap;function it(t){let e=t;for(;e;){const t=rt.get(e);if(t)return t;e=e.parentNode}return null}function at(t,e){null!==e?rt.set(t,e):rt.delete(t)}const lt=Symbol("$$setLoopContextAsync"),ct=Symbol("$$setLoopContext"),dt=Symbol("$$getByAddress"),ut=Symbol("$$setByAddress"),ft=Symbol("$$connectedCallback"),pt=Symbol("$$disconnectedCallback"),ht=Symbol("$$updatedCallback"),mt=new Map,gt=new Map;function bt(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=mt.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=to(e.getRootNode(),o);null===n&&i(`State element with name "${o}" not found for event handler.`);const a=it(e);n.createStateAsync("writable",async e=>{e[ct](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??[]])})})},mt.set(e,n));const a=t.propName.slice(2);t.node.addEventListener(a,n);let l=gt.get(e);return void 0===l?(l=new Set([t]),gt.set(e,l)):l.add(t),!0}const wt=new WeakMap;function yt(t){const e=wt.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{wt.set(t,n)}}const Nt=new Set(["radio","checkbox"]),xt=new Set(["value","valueAsNumber","valueAsDate"]);const St=new Map,It=new Map,_t=t=>t.detail;function Pt(t){const e=yt(t.node);if(null!==e){if(void 0===customElements.get(e))return void customElements.whenDefined(e).then(()=>{Pt(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(Nt.has(t)&&"checked"===e)return!0;if(xt.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=yt(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=yt(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=yt(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??_t}}}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=St.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=to(a.getRootNode(),t);null===d&&i(`State element with name "${t}" not found for two-way binding.`);const u=it(a);d.createState("writable",t=>{t[ct](u,()=>{t[n]=c})})})(t.stateName,t.propName,t.statePathName,t.inFilters,n),St.set(o,s)),t.node.addEventListener(e,s);let r=It.get(o);void 0===r?(r=new Set([t]),It.set(o,r)):r.add(t)}}const vt=new WeakMap;function At(t){return vt.get(t)??[]}function $t(t,e){vt.set(t,e)}const Ct=new WeakMap;function Et(t,e){if(Ct.has(t)){const n=Ct.get(t);if(n.has(e))return n.get(e)}else Ct.set(t,new WeakMap);const n=Object.freeze(new kt(t,e));return Ct.get(t).set(e,n),n}class kt{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=Et(t,e.parentPathInfo)}}const Mt=new WeakMap,Tt=new WeakMap;class Ot{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=Wt(t,e)}}function Wt(t,e){if(null===e){let e=Tt.get(t);return void 0!==e||(e=new Ot(t,null),Tt.set(t,e)),e}{let n=Mt.get(e);void 0===n&&(n=new WeakMap,Mt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Ot(t,e),n.set(t,o)),o}}const Lt=new WeakMap;function Dt(t,e){null===e?Lt.delete(t):Lt.set(t,e)}function Rt(t){return Lt.get(t)||null}const Ft=new Map;function Bt(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=Ft.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Ft.set(s,r),r}const jt=new WeakMap;function qt(t){const e=it(t.node);if(null===e)return null;let n=jt.get(e);if(void 0===n)n=new WeakMap,jt.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=Bt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const zt=new WeakMap;function Ht(t){let e=null;if(e=zt.get(t)||null,null!==e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Rt(n);null===e?i(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}const o=qt(t),s=to(n,t.stateName);null===s&&i(`State element with name "${t.stateName}" not found for binding.`);return e=Wt(Et(s,t.statePathInfo),o),zt.set(t,e),e}function Ut(t){zt.delete(t)}const Vt=new WeakMap;function Jt(t,e){const n=Vt.get(t);return!!n&&!0===n.get(e)}function Xt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Kt=Object.freeze([]);class Yt{_name;_subscribers=new Set;constructor(t){this._name=t}get name(){return this._name}get size(){return this._subscribers.size}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}unsubscribe(t){return this._subscribers.delete(t)}emit(...t){const e=[];for(const n of this._subscribers)e.push(n(...t));return e}}const Gt=new WeakMap;const Qt=new WeakMap,Zt=new WeakMap;class te{pathInfo;listIndex;_parentAddress;constructor(t,e){this.pathInfo=t,this.listIndex=e}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let e=null;return e=this.pathInfo.segments[this.pathInfo.segments.length-1]===y?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=ee(t,e)}}function ee(t,e){if(null===e){let e=Zt.get(t);return void 0!==e||(e=new te(t,null),Zt.set(t,e)),e}{let n=Qt.get(e);void 0===n&&(n=new WeakMap,Qt.set(e,n));let o=n.get(t);return void 0!==o||(o=new te(t,e),n.set(t,o)),o}}const ne=new WeakMap;function oe(t){return ne.get(t)??[]}function se(t,e){ne.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 re=0;function ie(){return`u${(re++).toString(36)}`}let ae=0;class le{uuid=ie();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=ae}get index(){return this._index}set index(t){this._index=t,this._version=++ae,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=ae),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 ce(t,e){return new le(t,e)}const de=new WeakMap;function ue(t){return de.get(t)||null}function fe(t,e){null!==e?de.set(t,e):de.delete(t)}const pe=new WeakMap,he=Object.freeze([]),me=new Set;function ge(t,e,n){const o=Array.isArray(e)&&e.length>0?e:he,s=Array.isArray(n)&&n.length>0?n:he,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:he,o=Array.isArray(e)&&e.length>0?e:he;let s=pe.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=ue(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:me,deleteIndexSet:new Set(i),addIndexSet:me};let e=ue(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=ce(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:me,deleteIndexSet:me,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:me,deleteIndexSet:me,addIndexSet:me};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=ce(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=pe.get(t);o||(o=new WeakMap,pe.set(t,o)),o.set(e,n)}(o,s,a),fe(s,a.newIndexes))}}const be=new WeakMap;function we(t){let e=null;return e=be.get(t)||null,null===e&&(e=new Set,be.set(t,e)),e}function ye(t,e){we(t).add(e)}function Ne(t,e){we(t).delete(e)}const xe=new WeakMap;function Se(t){xe.delete(t)}const Ie=new WeakMap;function _e(t){return Ie.get(t)??[]}function Pe(t,e){Ie.set(t,e)}const ve=new WeakMap;function Ae(t){return ve.get(t)??[]}function $e(t,e){ve.set(t,e)}function Ce(t,e){const n=Ae(t);for(const t of n)at(t,e)}function Ee(t,e,n){Ce(t,e);const o=_e(t);for(const t of o){ye(Ht(t),t),pn(t,n)}}function ke(t){if(!t.mounted)return;const e=_e(t);for(const t of e){Ne(Ht(t),t),Ut(t),Se(t)}!function(t){const e=Ae(t);for(const t of e)at(t,null)}(t)}const Me=new WeakMap,Te=Object.freeze(new Set);function Oe(t,e){const n=Me.get(t);n?n.add(e):Me.set(t,new Set([e]))}function We(t){const e=Me.get(t);return void 0!==e?e:Te}const Le=new Set(["if","elseif","else","for"]);class De{_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=_e(this);for(const e of t){if(Le.has(e.bindingType)){const t=We(e.node);for(const e of t)e.unmount()}Se(e),Ut(e)}this._mounted=!1}}function Re(t){const e=document.createDocumentFragment(),n=new De(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 Fe(t){void 0!==t.uuid&&null!==t.uuid||i("BindingInfo.uuid is null.");const e=ro(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.`),!ot.has(e)){ot.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 In(o),{nodes:n,bindingInfos:o}}(n,e.nodeInfos),s=new De(n);Pe(s,o.bindingInfos);const r=[];for(const t of o.bindingInfos)t.statePathName in S&&r.push(t);return se(s,r),$e(s,o.nodes),Oe(t.node,s),s}const Be=new WeakMap,je=new WeakMap,qe=new WeakMap,ze=new WeakMap;function He(t,e,n){Ke(t,e,n)}function Ue(t,e){Be.set(t,e)}function Ve(t){return qe.get(t.node)||[]}function Je(t,e){const n=qe.get(t.node);void 0===n?qe.set(t.node,[e]):n.push(e)}function Xe(t,e){let n=je.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ke(t,e,n){let o=je.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,je.set(t,o)}null===n?o.delete(e):o.set(e,n)}const Ye=new WeakMap;function Ge(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Qe(t,n,s){const r=t.node.isConnected,i=Boolean(s);let a;const l=We(t.node);a=0===l.size?Fe(t):l.values().next().value;const c=e(),d=t.uuid??"",u=t.bindingType;try{if(i||(o.debug&&console.log(`unmount if content : ${Ge(t)}`),ke(a),a.unmount()),i){if(o.debug&&console.log(`mount if content : ${Ge(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);Ee(a,it(t.node),n)}}finally{Ye.set(t.node,r)}}const Ze=new WeakMap;function tn(t){return Ze.get(t)??[]}const en=new Set;const nn={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 on(t,n,s){const r=t.node,i=t.propSegments;if(1===i.length){const t=i[0];if(r[t]!==s){let e=!1;try{r[t]=s,e=!0}catch(e){o.debug&&console.warn(`Failed to set property '${t}' on element.`,{element:r,newValue:s,error:e})}if(e){const e=function(t,e){const n=yt(t);if(null===n)return null;const o=customElements.get(n);if(void 0===o)return null;const s=o.wcBindable;if("wc-bindable"!==s?.protocol||1!==s?.version)return null;const r=s.inputs;if(!Array.isArray(r))return null;for(const t of r)if(t.name===e&&"string"==typeof t.attribute&&t.attribute.length>0)return t.attribute;return null}(r,t);if(null!==e)try{!function(t,e,n){if(null==n)return void t.removeAttribute(e);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);t.setAttribute(e,o)}(r,e,s)}catch(t){o.debug&&console.warn(`Failed to mirror attribute '${e}' on element.`,{element:r,newValue:s,error:t})}}}if(e()){const e=nn[t];e?e(r,s):(!function(t,e,n){let o=Ze.get(t);o||(o=[],Ze.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,en.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 sn=new WeakSet;function rn(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 an(t,e){const n=function(t){let e=null;if(e=xe.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=qt(t);null===n&&i(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=ee(t.statePathInfo,n)}else e=ee(t.statePathInfo,null);return xe.set(t,e),e}(e);if(n.pathInfo.path in S){const t=it(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[dt](n)}const ln={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)},command:function(t,e,n){n instanceof Yt||i("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Gt.get(t);if(s&&s.token===o)return;const r=t.node,a=t.propSegments[1];"string"==typeof a&&0!==a.length||i('command binding requires a method name (e.g., "command.fetch").');const l=function(t){const e=yt(t);if(null===e)return null;const n=customElements.get(e);void 0===n&&i(`Custom element <${e}> is not defined for command binding.`);const o=n.wcBindable;return"wc-bindable"===o?.protocol&&1===o?.version?o:null}(r);null===l&&i(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),Array.isArray(l.commands)&&l.commands.some(t=>t.name===a)||i(`Command "${a}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),s&&(s.unsubscribe(),Gt.delete(t));const c=new WeakRef(r);let d=null;d=o.subscribe((...e)=>{const n=c.deref();if(!n||!n.isConnected)return d?.(),void Gt.delete(t);const o=n[a];return"function"!=typeof o&&i(`Method "${a}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,e)}),Gt.set(t,{token:o,unsubscribe:d,elementRef:c})}},cn={text:function(t,n,o){if(t.replaceNode.nodeValue!==o&&(t.replaceNode.nodeValue=o),e()&&!sn.has(t.replaceNode)){sn.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=qt(t),a=Ht(t),l=At(a),c=ge(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=ze.get(t.node);if(void 0===e){const n=Be.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),ze.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=Xe(t.node,e);null!==n&&(ke(n),n.unmount(),Je(t,n),Ke(t.node,e,null))}let d=t.node;const u=M(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(),Dt(p,n.rootNode));const h=e(),m=t.uuid??"";for(const e of c.newIndexes){let o;if(c.addIndexSet.has(e)){const r=ee(u,e);f.createLoopContext(r,r=>{const i=Ve(t);if(o=i.pop(),void 0===o&&(o=Fe(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)}}Ee(o,r,n)}),void 0===o&&i(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=Xe(t.node,e),c.changeIndexSet.has(e)){const t=oe(o);for(const e of t)pn(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,Ke(t.node,e,o)}Be.set(t.node,d),null!==p&&(t.node.parentNode.insertBefore(p,t.node.nextSibling),Dt(p,null))},if:Qe,else:Qe,elseif:Qe,radio:function(t,e,n){const o=t.node,s=Xt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Xt(o.value,t.inFilters),r=Array.isArray(n)?n:Kt;o.checked=r.includes(s)}},dn=new WeakMap,un=new WeakMap;function fn(t,e){const n=Xt(an(e.state,t),t.outFilters);if(!0===un.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=dn.get(t);if(void 0===o){if(dn.has(t))return Jt(t.replaceNode,e.stateElement)?(o=rn,dn.set(t,o)):o=on,void o(t,e,n);if(o=cn[t.bindingType],void 0===o){const n=t.propSegments[0];if(o=ln[n],dn.set(t,o),void 0===o){yt(t.replaceNode)?Jt(t.replaceNode,e.stateElement)?(o=rn,dn.set(t,o)):o=on:(o=on,dn.set(t,o))}}if(o===on){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void un.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function pn(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const n=Ht(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=yt(t.replaceNode);if(o&&void 0===customElements.get(o))return;let s=t.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=Rt(s),null===s&&i("Root node for fragment not found for binding.")),t.stateName!==e.stateName||s!==e.rootNode){const n=to(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};fn(t,r)})}else fn(t,e)}function hn(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=Rt(d),null===d&&i("Root node for fragment not found for binding."));const u=to(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(;;){pn(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)on(t,0,e);for(const[t,e]of s.entries())$t(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[ht](Array.from(e))})}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("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=to(s.getRootNode(),t);null===a&&i(`State element with name "${t}" not found for two-way binding.`);const l=it(s);a.createState("writable",t=>{t[ct](l,()=>{t[e]=r})})};function wn(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=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}const yn=new Map,Nn=new Map;const xn=(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=to(s.getRootNode(),t);null===l&&i(`State element with name "${t}" not found for two-way binding.`);const c=it(s);l.createState("writable",t=>{t[ct](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 Sn(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=yn.get(n);void 0===o&&(o=xn(t.stateName,t.statePathName,t.inFilters),yn.set(n,o)),t.node.addEventListener(e,o);let s=Nn.get(n);return void 0===s?(s=new Set([t]),Nn.set(n,s)):s.add(t),!0}return!1}function In(t){for(const e of t)f(e),bt(e)||(Pt(e),wn(e),Sn(e))}function _n(t,e){const[n,o]=st(t);for(const t of n)at(t,e);In(o);for(const t of o){ye(Ht(t),t);const e=to(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)}hn(o)}const Pn=/\{\{\s*(.+?)\s*\}\}/g,vn=new Set(["SCRIPT","STYLE"]);function An(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&&vn.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),An(e.content)}else An(t.content)}function $n(t){const e=t.data;if(Pn.lastIndex=0,!Pn.test(e))return;Pn.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=Pn.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 Cn;function En(){if(Cn)return Cn;const t=[],e=z("not",t)(j);return Cn={filterName:"not",args:t,filterFn:e},Cn}const kn=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Mn(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 Tn(t,e){const n=kn.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+Mn(s,e)+r}function On(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=Mn(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function Wn(t,e){return On(t,e)}function Ln(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=Tn(n.data,e);continue}const o=t;if(o instanceof HTMLTemplateElement)continue;const r=o.getAttribute(n);if(null!==r){const t=On(r,e);t!==r&&o.setAttribute(n,t)}}}function Dn(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 Rn(t){const e=[],n=nt(t);for(const t of n){const n=et(t);e.push({nodePath:Dn(t),parseBindTextResults:n})}return e}function Fn(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 Bn=new Map([["for",o.commentForPrefix],["if",o.commentIfPrefix],["elseif",o.commentElseIfPrefix],["else",o.commentElsePrefix]]),jn=En();function qn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,jn],bindingType:t}}function zn(t,e,n,o){Fn(e),"string"==typeof o&&Ln(e,o),Hn(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:Rn(e)}}function Hn(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=Wn(r,n));let c=Y(r)[0];const d=Bn.get(c.bindingType);if(void 0===d)continue;const u=c.bindingType,f=e.content,p=ie();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=qn("else",a.parseBindTextResult),h=zn(t,f,c,m),so(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:Dn(o),parseBindTextResults:et(o)})):e.replaceWith(o)}else if("elseif"===u){null===a&&i("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=zn(t,f,c,m),so(p,t,h);const n=document.createComment(`@@${d}:${p}`),o=ie(),r={fragment:document.createDocumentFragment(),parseBindTextResult:qn("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:Dn(n),parseBindTextResults:et(n)}),so(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:Dn(g),parseBindTextResults:et(g)})):e.replaceWith(g)}else{h=zn(t,f,c,m),so(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 Un(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 Vn(t){if(t===document)await Un(document),An(document),Hn(document,document),_n(document.body,null);else{const e=t;e.host.hasAttribute(o.bindAttributeName)&&await d(e.host),await Un(e),An(e),Hn(e,e),_n(e,null)}}const Jn=new Set(["for","if","elseif","else"]);function Xn(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]=st(o);for(const t of r)f(t),bt(t)||(Pt(t),wn(t),Sn(t));if(e)for(;o.firstChild;)e.insertBefore(o.firstChild,n);return{bindingInfos:r,subscriberNodes:s}}function Kn(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 Yn(t,e){const n=t;let s=null;for(const[t,r]of e.templates){let e=Y(r.getAttribute(o.bindAttributeName)||"")[0];const i=e.bindingType;"else"===i&&s?e={...s,outFilters:[...s.outFilters,En()],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;Fn(a),"string"==typeof l&&Ln(a,l),Hn(n,a,l);so(t,n,{fragment:a,parseBindTextResult:e,nodeInfos:Rn(a)})}}async function Gn(t){await Un(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.`),uo.cleanupDom(t),!1}for(const n of e)Yn(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=ao.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=Re(o.nodes),{bindingInfos:s,subscriberNodes:r}=Xn(o.nodes);for(const t of r)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");Pe(e,s),$e(e,r);const i=[];for(const t of s)t.statePathName in S&&i.push(t);if(se(e,i),"for"===o.type&&null!==o.index){const r=Kn(t,"for",o.uuid);if(r){const t=ce(null,o.index);He(r,t,e),Ue(r,o.nodes[o.nodes.length-1]),Oe(r,e),Ce(e,ee(M(o.path+"."+y),t));for(const t of s)ye(Ht(t),t);let i=n.get(o.uuid);i||(i=[],n.set(o.uuid,i)),i.push(t)}}else{const n=Kn(t,o.type,o.uuid);if(n){Oe(n,e);for(const t of s)ye(Ht(t),t)}}}for(const[e,o]of n){const n=Kn(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=ro(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=to(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&fe(e,o)})}}(document.body,n),uo.removeBlockBoundaryComments(document.body);const s=[];for(const t of e)t.parentNode&&(s.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());uo.restoreTextBindings(document.body);const[a,l]=st(document.body);for(const t of a)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(at(t,null),e.setAttribute("data-wcs-completed",""))}else at(t,null);const c=[],d=[];for(const t of l)if(f(t),!bt(t))if(Pt(t),wn(t),Sn(t),Jn.has(t.bindingType))d.push(t);else{if(t.statePathName.includes(y))continue;c.push(t)}for(const t of[...c,...d]){ye(Ht(t),t);const e=to(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=Ht(t),n=to(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&$t(e,o)})}hn(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 Qn=new WeakMap,Zn=new WeakMap;function to(t,e){let n=Qn.get(t);return n&&n.get(e)||null}function eo(t){return Zn.get(t)??Promise.resolve()}function no(t,n,s){let r=Qn.get(t);if(null===s){if(!r)return;r.delete(n),0===r.size&&Qn.delete(t),o.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,Qn.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 Gn(t)||await Vn(t)}else await Vn(t);e()})});Zn.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await Vn(t),e()})});Zn.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 oo=new Map;function so(t,e,n){if(null===n)oo.delete(t);else{oo.set(t,n);const o=n.parseBindTextResult,s=to(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=to(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 ro(t){return oo.get(t)||null}const io=/^@@wcs-(?:for|if|elseif|else):[^-]/,ao=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,lo=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,co=/^@@wcs-text-start:(.+)$/;class uo 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(oo.keys());for(const e of s){const n=ro(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(en);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=tn(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)}}en.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(ao.test(t.data)||lo.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;io.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=co.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;ao.test(t.data)&&i.push(t)}for(const t of i){const e=ao.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()}uo.restoreTextBindings(e);const a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(io.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 fo(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 po(t){try{return(await import(t)).default||{}}catch(t){i(`Failed to load script file: ${t}`)}}class ho{_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}}const mo=new WeakMap;function go(t,e){let n=mo.get(t);void 0===n&&(n=new Map,mo.set(t,n));let o=n.get(e);return void 0===o&&(o=new Yt(e),n.set(e,o)),o}const bo=new WeakMap;function wo(t){const e=bo.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return go(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:go(t,n)}},set(){i("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){i("$command namespace is read-only; deleting from it is not allowed.")}});return bo.set(t,n),n}function yo(t){return function(){const e=this.stateElement;if(!e)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function No(t){return function(e){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})})}}function xo(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function So(t){return t.startsWith("$")}const Io=new Map;class _o{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=M(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 Po(t){let e;return Io.get(t)??(Io.set(t,e=new _o(t)),e)}const vo=new WeakMap;function Ao(t,e){null===e?vo.delete(t):vo.set(t,e)}function $o(t){const e=vo.get(t);e&&(e.dirty=!0)}function Co(t,e,n,o,s){if(e.pathInfo.segments[0]===$){let t=wo(s);for(let n=1;n<e.pathInfo.segments.length;n++){if(null==t)return;t=Reflect.get(t,e.pathInfo.segments[n])}return t}if(!(e.pathInfo.path in t)){const s=ko(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 Eo(t,e,n,o,s){const r=Wt(Et(s,e.pathInfo),e.listIndex),i=function(t){return vo.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=Co(t,e,n,o,s);return Ao(r,{value:a,dirty:!1}),a}function ko(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)?Eo(t,e,n,o,s):Co(t,e,n,o,s)}function Mo(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 To=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=we(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}hn(n)}};function Oo(){return To}const Wo=new WeakMap;function Lo(t,e){null===e?Wo.delete(t):Wo.set(t,e)}function Do(t,e,n){const s=M(t.wildcardParentPaths[e]),r=Et(t.stateElement,s),i=ee(s,n),a=At(Wt(r,n)),l=t.stateProxy[dt](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}`),[]}}(ge(i.listIndex,a,l),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...c);else for(const n of c)Do(t,e+1,n)}function Ro(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=M(n);if(t.listPathSet.has(r)&&o.lastSegment===y){const n=t.stateProxy[dt](e),s=At(Wt(Et(t.stateElement,e.pathInfo),e.listIndex)),r=ge(e.listIndex,s,n);for(const e of r.newIndexes){const n=ee(o,e);t.result.add(n),l.push({address:n,depth:a})}}else{const n=ee(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=M(n),s=[];if(o.wildcardCount>0){const n=Bt(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};Do(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=ee(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 Fo(t,e,n,o,s,r){try{if(!(e.pathInfo.path in t)){const n=ko(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=Oo();t.enqueueAbsoluteAddress(n),Ro(r.stateName,r.stateElement,e,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,s,"new",n=>{if(n===e)return;const o=Wt(Et(r.stateElement,n.pathInfo),n.listIndex);$o(o),t.enqueueAbsoluteAddress(o)})}}function Bo(t,e,n,o,s,r){let a=e.parentAddress??i(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Wo.get(t)??null}(a);if(null===l){const e=ko(t,a,s,r)??[],n=ue(e)??[];l={value:[...e],listIndexes:[...n]},Lo(a,l)}try{return Fo(t,e,n,o,s,r)}finally{const n=l.value.indexOf(o),i=ko(t,a,s,r)??[],c=Array.isArray(i)?ue(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:ce(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;Lo(a,null)}}}function jo(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=Wt(Et(r,e.pathInfo),e.listIndex);try{return i?Bo(t,e,l,n,o,s):Fo(t,e,l,n,o,s)}finally{a&&Ao(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 qo(t,e,n,o){return(e,s,r)=>{const a=M(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=ee(r,l),d=ue(ko(t,c,n,o));null==d&&i(`ListIndexes not found: ${r.path}`);l=d[s[e]]??i(`ListIndex not found: ${r.path}`)}const c=ee(a,l);if(!(void 0!==r))return ko(t,c,n,o);jo(t,c,r,n,o)}}const zo=new WeakMap;function Ho(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return Mo(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=(ue(ko(t,ee(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 Uo(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 Vo(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=Po(e),r=Ho(t,s,n,o),i=ee(s.pathInfo,r);return ko(t,i,n,o)}switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=qo(t,0,n,o);return(e,r)=>{const a=new Map,l=M(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=Mo(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=ee(p,r),m=zo.get(h),g=ko(t,h,n,o),b=ge(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())zo.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=Po(e),i=Ho(t,r,n,o),a=ee(r.pathInfo,i),l=Wt(Et(s,a.pathInfo),a.listIndex),c=Oo();c.enqueueAbsoluteAddress(l),Ro(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=Wt(Et(s,t.pathInfo),t.listIndex);$o(e),c.enqueueAbsoluteAddress(e)})}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>qo(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);case $:return wo(o.stateElement)}}else if("symbol"==typeof e){switch(e){case lt:return(t,e=async()=>{})=>async function(t,e,n){return await Uo(t,e,n)}(o,t,e);case ct:return(t,e=()=>{})=>function(t,e,n){return Uo(t,e,n)}(o,t,e);case dt:return e=>ko(t,e,n,o);case ut:return(e,s)=>jo(t,e,s,n,o);case ft:return()=>async function(t,e,n){const o=Reflect.get(t,I);"function"==typeof o&&await o.call(n)}(t,0,n);case pt:return()=>function(t,e,n){const o=Reflect.get(t,_);"function"==typeof o&&o.call(n)}(t,0,n);case ht: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 Jo{_stateElement;_stateName;_addressStack=Array(N).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,n){this._stateName=e;const o=to(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 Vo(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=Po(e),i=Ho(t,r,o,s);return jo(t,ee(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 Xo=new WeakMap;const Ko=new WeakMap;function Yo(t,e){const n=Ko.get(t);return n?n.get(e)??null:null}const Go=new WeakMap,Qo=new WeakMap,Zo=new WeakMap,ts=new WeakMap;function es(t,e){return{innerAbsPathInfo:Et(t,M(e.propSegments.slice(1).join(w))),outerAbsPathInfo:Ht(e).absolutePathInfo}}function ns(t,e){let n=Go.get(t);if(void 0===n&&(n=new Map,Go.set(t,n)),n.has(e))return n.get(e);let o=Qo.get(t);void 0===o&&(o=new Map,Qo.set(t,o));const s=Zo.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=ts.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=M(r.outerAbsPathInfo.pathInfo.segments.concat(l).join(w)),d=to(t.getRootNode(),a.stateName);null===d&&i(`State element with name "${a.stateName}" not found for web component.`);const u=Et(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 os(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 ss{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=Yo(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=M(e),s=Et(this._innerStateElement,o),r=ns(this._webComponent,s);if(null!==r){const t=it(this._webComponent);let e;return r.stateElement.createState("readonly",n=>{n[ct](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){Xo.set(t,e)}(Wt(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=M(e),r=Et(this._innerStateElement,s),a=ns(this._webComponent,r);if(null!==a){const t=it(this._webComponent);return a.stateElement.createState("writable",e=>{e[ct](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=M(e),o=Et(this._innerStateElement,n);return null!==ns(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class rs{_innerStateElement;constructor(t,e){this._innerStateElement=Yo(t,e)??i("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=M(e),n=Wt(Et(this._innerStateElement,t),null);return o=n,Xo.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=M(e),n=Et(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class is{_innerStateElement;constructor(t,e){this._innerStateElement=Yo(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 as=t=>()=>t;function ls(t,e,n,s){if(function(t,e,n){let o=Ko.get(t);o||(o=new Map,Ko.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=Yo(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=es(o,e);let i=Zo.get(t);void 0===i?Zo.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;ts.set(n,e),s.set(a,l),r.set(l,a)}Go.set(t,s),Qo.set(t,r)}(e,n,o);const s=function(t,e){const n=new rs(t,e);return new Proxy({},n)}(e,n),r=function(t,e){const n=new ss(t,e),o=Yo(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(os(s),n)}(e,n);t.setInitialState(r),Object.defineProperty(e,n,{get:as(s),enumerable:!0,configurable:!0})}else{t.setInitialState(os(s));const o=function(t,e){const n=new is(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:as(o),enumerable:!0,configurable:!0})}if(function(t,e){let n=Vt.get(t);n||(n=new WeakMap,Vt.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 cs(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 ds extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return eo(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 ho}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};_commandTokenNames=new Set;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._commandTokenNames=function(t){const e=new Set,n=t[A];if(void 0===n)return e;Array.isArray(n)||i(`${A} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||i(`${A} entries must be non-empty strings.`),t===$&&i(`${A} entry "${t}" conflicts with the reserved namespace name "${$}".`),e.has(t)&&i(`${A} entry "${t}" is duplicated.`),e.add(t);return e}(t),this.__state=t,this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._pathSet.clear();const e=cs(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=uo.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 po(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 fo(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",no(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?yt(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,ls(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{I in t&&await t[ft]()})}async _initializeDCC(t,e){let n;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?n=await po(t):i(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?n=await fo(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 void console.warn(`[@wcstack/state] DCC: "${s}" is already registered. Skipping redefinition.`);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(C)&&(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(So(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=xo(t,o)}else n.get=yo(t),n.set=No(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[pt]()})}async connectedCallback(){if(this._rootNode=this.getRootNode(),!this._initialized){const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(C))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 eo(this.rootNode);const t=this.getAttribute("name")||"default",e=uo.extractStateData(this),n=document.createElement(o.tagNames.ssr);n.setAttribute("name",t),n.setAttribute("version",r),uo.buildContent(n,e),this.parentNode?.insertBefore(n,this)}this._resolveConnectedCallback?.()}disconnectedCallback(){var t;null!==this._rootNode&&(this._callStateDisconnectedCallback(),no(this.rootNode,this._name,null),t=this,mo.delete(t),function(t){bo.delete(t)}(this),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}get commandTokenNames(){return this._commandTokenNames}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=M(t);if(this._pathSet.add(t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=M(t.parentPath)}}}_createState(t,e,n){try{const o=function(t,e,n,o){const s=new Jo(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 us(){customElements.get(o.tagNames.ssr)||customElements.define(o.tagNames.ssr,uo),customElements.get(o.tagNames.state)||customElements.define(o.tagNames.state,ds)}function fs(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)),us()}function ps(t){return t}export{uo as Ssr,r as VERSION,fs as bootstrapState,Vn as buildBindings,ps as defineState,eo as getBindingsReady,s as getConfig};
|
|
2
2
|
//# sourceMappingURL=index.esm.min.js.map
|
package/package.json
CHANGED