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