@wcstack/state 1.3.17 → 1.3.18
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 +37 -6
- package/README.md +37 -6
- package/dist/index.esm.js +20 -16
- 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 +1 -1
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 a(t){let e,n=o.get(t)||null;if(null!==n)return n;const a=new Promise(t=>{e=t});return n={id:++s,promise:a,resolve:e},o.set(t,n),n}async function i(t){const e=a(t);await e.promise}function r(t){a(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 h(t,e){u.set(t,e)}const p=".",m="*",g=128,w={};for(let t=0;t<128;t++)w[`$${t+1}`]=t;const b=Object.freeze(w),x="$connectedCallback",I="$disconnectedCallback",y="$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=[],a=[],i={},r=[],l=[],d=[],c=[];let u="",f="",h=0;for(let t=0;t<n.length;t++)u+=n[t],n[t]===m&&(a.push(u),i[u]=h,r.push(e(u)),l.push(f),d.push(e(f)),c.push(t),h++),o.push(u),s.push(e(u)),f=u,u+=".";const p=a.length>0?a[a.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=a,this.wildcardPathSet=new Set(a),this.indexByWildcardPath=i,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=p,this.lastWildcardInfo=p?e(p):null,this.parentPath=g,this.parentPathInfo=g?e(g):null,this.wildcardCount=h}}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 O=new Map;function R(t,e){const o=L[e];return t.map(t=>{const s=t.indexOf("("),a=t.lastIndexOf(")");if(-1!==s&&-1===a&&n(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==a&&-1===s&&n(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===s){const n=t.trim(),s=`${n}():${e}`;let a=O.get(s);return void 0===a&&(a=W(n,[])(o),O.set(s,a)),{filterName:n,args:[],filterFn:a}}{const n=t.substring(s+1,a),i=t.substring(0,s).trim(),r=function(t){const e=[];let n="",o=null;for(let s=0;s<t.length;s++){const a=t[s];o?a===o?o=null:n+=a:'"'===a||"'"===a?o=a:","===a?(e.push(n.trim()),n=""):n+=a}return n.trim()&&e.push(n.trim()),e}(n),l=`${i}(${r.join(",")}):${e}`;let d=O.get(l);return void 0===d&&(d=W(i,r)(o),O.set(l,d)),{filterName:i,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="",a=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),j.has(s)?a=j.get(s):(o=s.split("|").map(F),a=R(o,"output"),j.set(s,a))):n=t.trim();const[i,r="default"]=n.split("@").map(F);return{stateName:r,statePathName:i,statePathInfo:P(i),outFilters:a}}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="",a=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),D.has(s)?a=D.get(s):(o=s.split("|").map(F),a=R(o,"input"),D.set(s,a))):n=t.trim();const[i,r]=n.split("#").map(F),l=i.split(".").map(F);return{propName:i,propSegments:l,propModifiers:r?r.split(",").map(F):[],inFilters:a}}(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]),H=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function V(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=H.exec(o);if(null===s)return null;const a=s[1]||e.commentTextPrefix;return U.has(a)?(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,a=xn(e,s.stateName);null===a&&n(`State element with name "${s.stateName}" not found for fragment info.`),a.setPathInfo(s.statePathName,s.bindingType);for(const t of o.nodeInfos)for(const o of t.parseBindTextResults){const t=xn(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=V(t);null===e&&n("Comment node binding text not found.");const o=K(e);let s=o?.parseBindTextResult??null,a=null;return null===s?(s={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...B(e),bindingType:"text"},a=null):a=e,[{...s,uuid:a}]}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!==V(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"),at=Symbol("$$setByAddress"),it=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,a,i;void 0===o&&(s=t.stateName,a=t.statePathName,i=t.propModifiers,o=t=>{i.includes("prevent")&&t.preventDefault(),i.includes("stop")&&t.stopPropagation();const e=t.target,o=xn(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[a];return"function"!=typeof o&&n(`Handler "${a}" 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 Set(["radio","checkbox"]),ht=new Set(["value","valueAsNumber","valueAsDate"]);const pt=new Map,mt=new Map;function gt(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(ft.has(t)&&"checked"===e)return!0;if(ht.has(e))return!0}return"select"===o&&"value"===e||"textarea"===o&&"value"===e}(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const i=function(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),r=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${n}`}(t,i);let l=pt.get(r);void 0===l&&(e=t.stateName,o=t.propName,s=t.statePathName,a=t.inFilters,l=t=>{const i=t.target;if(null===i)return void console.warn("[@wcstack/state] event.target is null.");if(!(o in i))return void console.warn(`[@wcstack/state] Property "${o}" does not exist on target element.`);let r=i[o];for(const t of a)r=t.filterFn(r);const l=xn(i.getRootNode(),e);null===l&&n(`State element with name "${e}" not found for two-way binding.`);const d=tt(i);l.createState("writable",t=>{t[ot](d,()=>{t[s]=r})})},pt.set(r,l)),t.node.addEventListener(i,l);let d=mt.get(r);return void 0===d?(d=new Set([t]),mt.set(r,d)):d.add(t),!0}var e,o,s,a;return!1}const wt=new WeakMap;function bt(t){return wt.get(t)??[]}function xt(t,e){wt.set(t,e)}const It=new WeakMap;function yt(t,e){if(It.has(t)){const n=It.get(t);if(n.has(e))return n.get(e)}else It.set(t,new WeakMap);const n=Object.freeze(new St(t,e));return It.get(t).set(e,n),n}class St{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=yt(t,e.parentPathInfo)}}const Nt=new WeakMap,Pt=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=vt(t,e)}}function vt(t,e){if(null===e){let e=Pt.get(t);return void 0!==e||(e=new _t(t,null),Pt.set(t,e)),e}{let n=Nt.get(e);void 0===n&&(n=new WeakMap,Nt.set(e,n));let o=n.get(t);return void 0!==o||(o=new _t(t,e),n.set(t,o)),o}}const At=new WeakMap;function $t(t,e){null===e?At.delete(t):At.set(t,e)}function Et(t){return At.get(t)||null}const Ct=new Map;function kt(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 a=Ct.get(s);if(void 0!==a)return a;return a=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Ct.set(s,a),a}const Mt=new WeakMap;function Tt(t){const e=tt(t.node);if(null===e)return null;let n=Mt.get(e);if(void 0===n)n=new WeakMap,Mt.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=kt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const Lt=new WeakMap;function Wt(t){let e=null;if(e=Lt.get(t)||null,null!==e)return e;let o=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Et(o);null===e?n(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):o=e}const s=Tt(t),a=xn(o,t.stateName);null===a&&n(`State element with name "${t.stateName}" not found for binding.`);return e=vt(yt(a,t.statePathInfo),s),Lt.set(t,e),e}function Ot(t){Lt.delete(t)}const Rt=new WeakMap;function Ft(t){let e=Rt.get(t);if(void 0!==e)return e;try{if(t.nodeType!==Node.ELEMENT_NODE)return e=!1;const n=t;return e=n.tagName.includes("-")?!0:!(!n.hasAttribute("is")||!n.getAttribute("is")?.includes("-"))}finally{Rt.set(t,e??!1)}}const Dt=new WeakMap;function jt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Bt=Object.freeze([]);const zt=new WeakMap,qt=new WeakMap;class Ut{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=Ht(t,e)}}function Ht(t,e){if(null===e){let e=qt.get(t);return void 0!==e||(e=new Ut(t,null),qt.set(t,e)),e}{let n=zt.get(e);void 0===n&&(n=new WeakMap,zt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Ut(t,e),n.set(t,o)),o}}const Vt=new WeakMap;function Jt(t){return Vt.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 Xt=0;function Kt(){return`u${(Xt++).toString(36)}`}let Yt=0;class Gt{uuid=Kt();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=Yt}get index(){return this._index}set index(t){this._index=t,this._version=++Yt,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=Yt),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 Qt(t,e){return new Gt(t,e)}const Zt=new WeakMap;function te(t){return Zt.get(t)||null}const ee=new WeakMap,ne=Object.freeze([]),oe=new Set;function se(t,e,n){const o=Array.isArray(e)&&e.length>0?e:ne,s=Array.isArray(n)&&n.length>0?n:ne,a=function(t,e){const n=Array.isArray(t)&&t.length>0?t:ne,o=Array.isArray(e)&&e.length>0?e:ne;let s=ee.get(n);return s&&s.get(o)||null}(o,s);if(a)return a;const i=te(o)||[];let r;try{if(0===s.length)return r={oldIndexes:i,newIndexes:[],changeIndexSet:oe,deleteIndexSet:new Set(i),addIndexSet:oe};let e=te(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=Qt(t,n);e.push(o)}}return r={oldIndexes:i,newIndexes:e,changeIndexSet:oe,deleteIndexSet:oe,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:i,newIndexes:i,changeIndexSet:oe,deleteIndexSet:oe,addIndexSet:oe};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 a=new Set(o),i=new Set(n),r=new Set,l=a.difference(i),d=i.difference(a);for(let t=0;t<e.length;t++){const o=e[t],a=s.get(o),i=a&&a.length>0?a.shift():void 0;if(void 0!==i){const e=n[i];e.index!==t&&r.add(e)}}return{oldIndexes:n,newIndexes:o,changeIndexSet:r,deleteIndexSet:d,addIndexSet:l}}(0,s,i,e,n);e=[];const a=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=Qt(t,o);e.push(n),l.add(n)}else{const t=i[c];t.index!==o&&(t.index=o,a.add(t)),e.push(t)}}return r={oldIndexes:i,newIndexes:e,changeIndexSet:a,deleteIndexSet:new Set(i).difference(new Set(e)),addIndexSet:l}}finally{void 0!==r&&(!function(t,e,n){let o=ee.get(t);o||(o=new WeakMap,ee.set(t,o)),o.set(e,n)}(o,s,r),l=s,null!==(d=r.newIndexes)?Zt.set(l,d):Zt.delete(l))}var l,d}const ae=new WeakMap;function ie(t){let e=null;return e=ae.get(t)||null,null===e&&(e=new Set,ae.set(t,e)),e}function re(t,e){ie(t).add(e)}function le(t,e){ie(t).delete(e)}const de=new WeakMap;function ce(t){de.delete(t)}const ue=new WeakMap;function fe(t){return ue.get(t)??[]}const he=new WeakMap;function pe(t){return he.get(t)??[]}function me(t,e,n){!function(t,e){const n=pe(t);for(const t of n)et(t,e)}(t,e);const o=fe(t);for(const t of o){re(Wt(t),t),je(t,n)}}function ge(t){if(!t.mounted)return;const e=fe(t);for(const t of e){le(Wt(t),t),Ot(t),ce(t)}!function(t){const e=pe(t);for(const t of e)et(t,null)}(t)}const we=new WeakMap,be=Object.freeze(new Set);function xe(t){const e=we.get(t);return void 0!==e?e:be}const Ie=new Set(["if","elseif","else","for"]);class ye{_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=fe(this);for(const e of t){if(Ie.has(e.bindingType)){const t=xe(e.node);for(const e of t)e.unmount()}ce(e),Ot(e)}this._mounted=!1}}function Se(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 a of e){const e=d(t,a.nodePath);if(null===e&&n(`Node not found by path [${a.nodePath.join(", ")}] in fragment.`),!Q.has(e)){Q.add(e);const t=c(e,a.parseBindTextResults);h(e,t),r(e),s.push(...t),o.push(e)}}return[o,s]}(t,e);return Ye(s),{nodes:o,bindingInfos:s}}(o,e.nodeInfos),a=new ye(o);!function(t,e){ue.set(t,e)}(a,s.bindingInfos);const i=[];for(const t of s.bindingInfos)t.statePathName in b&&i.push(t);return function(t,e){Vt.set(t,e)}(a,i),function(t,e){he.set(t,e)}(a,s.nodes),function(t,e){const n=we.get(t);n?n.add(e):we.set(t,new Set([e]))}(t.node,a),a}const Ne=new WeakMap,Pe=new WeakMap,_e=new WeakMap,ve=new WeakMap;function Ae(t){return _e.get(t.node)||[]}function $e(t,e){const n=_e.get(t.node);void 0===n?_e.set(t.node,[e]):n.push(e)}function Ee(t,e){let n=Pe.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ce(t,e,n){let o=Pe.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,Pe.set(t,o)}null===n?o.delete(e):o.set(e,n)}const ke=new WeakMap;function Me(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Te(t,n,o){const s=t.node.isConnected,a=Boolean(o);let i;const r=xe(t.node);i=0===r.size?Se(t):r.values().next().value;try{if(a||(e.debug&&console.log(`unmount if content : ${Me(t)}`),ge(i),i.unmount()),a){e.debug&&console.log(`mount if content : ${Me(t)}`),i.mountAfter(t.node);me(i,tt(t.node),n)}}finally{ke.set(t.node,s)}}function Le(t,n,o){const s=t.node,a=t.propSegments;if(1===a.length){const t=a[0];return void(s[t]!==o&&(s[t]=o))}let i=s[a[0]];for(let t=1;t<a.length-1;t++){const e=a[t];if(null==i)return;i=i[e]}const r=i[a[a.length-1]];if(r!==o){if(Object.isFrozen(i))return void(e.debug&&console.warn("Attempting to set property on frozen object.",{element:s,propSegments:a,oldValue:r,newValue:o}));i[a[a.length-1]]=o}}function We(t,e,o){const s=t.node,a=t.propSegments;a.length<=1&&n(`Invalid propSegments for web component binding: ${a.join(".")}`);const[i,...r]=a,l=s[i];void 0===l&&n(`Property "${i}" not found on web component.`),l[r.join(".")]=o}function Oe(t,e){const o=function(t){let e=null;if(e=de.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const o=Tt(t);null===o&&n(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=Ht(t.statePathInfo,o)}else e=Ht(t.statePathInfo,null);return de.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 Re={class:function(t,e,o){const s=t.node,a=t.propSegments[1];"boolean"!=typeof o&&n("Invalid value for class application: expected boolean, got "+typeof o),s.classList.toggle(a,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)}},Fe={text:function(t,e,n){t.replaceNode.nodeValue!==n&&(t.replaceNode.nodeValue=n)},for:function(t,e,o){const s=t.statePathInfo,a=Tt(t),i=Wt(t),r=bt(i),l=se(a,r,o);if(e.newListValueByAbsAddress.set(i,Array.isArray(o)?o:[]),Array.isArray(r)&&r.length===l.deleteIndexSet.size&&l.deleteIndexSet.size>0&&null!==t.node.parentNode){let e=ve.get(t.node);if(void 0===e){const n=Ne.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),ve.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=Ee(t.node,e);null!==n&&(ge(n),n.unmount(),$e(t,n),Ce(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(),$t(f,e.rootNode));for(const o of l.newIndexes){let a;if(l.addIndexSet.has(o)){const i=Ht(c,o);u.createLoopContext(i,n=>{const o=Ae(t);a=o.pop(),void 0===a&&(a=Se(t)),null!==f?a.appendTo(f):d.nextSibling!==a.firstNode&&a.mountAfter(d),me(a,n,e)}),void 0===a&&n(`Content not found for ListIndex: ${o.index} at path "${s.path}"`)}else{if(a=Ee(t.node,o),l.changeIndexSet.has(o)){const t=Jt(a);for(const n of t)je(n,e)}null===a&&n(`Content not found for ListIndex: ${o.index} at path "${s.path}"`),d.nextSibling!==a.firstNode&&a.mountAfter(d)}d=a.lastNode||d,Ce(t.node,o,a)}Ne.set(t.node,d),null!==f&&(t.node.parentNode.insertBefore(f,t.node.nextSibling),$t(f,null))},if:Te,else:Te,elseif:Te,radio:function(t,e,n){const o=t.node,s=jt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=jt(o.value,t.inFilters),a=Array.isArray(n)?n:Bt;o.checked=a.includes(s)}};function De(t,e){const n=jt(Oe(e.state,t),t.outFilters);let o=Fe[t.bindingType];if(void 0===o){const n=t.propSegments[0];o=Re[n],void 0===o&&(o=function(t,e){const n=Dt.get(t);return!!n&&!0===n.get(e)}(t.replaceNode,e.stateElement)?We:Le)}if(o===Le){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return void e.deferredSelectBindings.push({binding:t,value:n})}}o(t,e,n)}function je(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const o=Wt(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;if(Ft(t.replaceNode)){const e=t.replaceNode;if(void 0===customElements.get(e.tagName.toLowerCase()))return}let s=t.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=Et(s),null===s&&n("Root node for fragment not found for binding.")),t.stateName!==e.stateName||s!==e.rootNode){const o=xn(s,t.stateName);null===o&&n(`State element with name "${t.stateName}" not found for binding.`),o.createState("readonly",n=>{const a={stateName:t.stateName,rootNode:s,stateElement:o,state:n,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};De(t,a)})}else De(t,e)}function Be(t){let o=0;const s=new Set,a=new Map,i=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=Et(c),null===c&&n("Root node for fragment not found for binding."));const u=xn(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:a,updatedAbsAddressSetByStateElement:i,deferredSelectBindings:r};for(;;){je(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)Le(t,0,e);for(const[t,e]of a.entries())xt(t,e);for(const[t,e]of i.entries())t.createState("writable",t=>{t[lt](Array.from(e))})}const ze=new Map,qe=new Map;const Ue=(t,e,o)=>s=>{const a=s.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==a.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===a.checked)return;let i=a.value;for(const t of o)i=t.filterFn(i);const r=xn(a.getRootNode(),t);null===r&&n(`State element with name "${t}" not found for two-way binding.`);const l=tt(a);r.createState("writable",t=>{t[ot](l,()=>{t[e]=i})})};function He(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=ze.get(n);void 0===o&&(o=Ue(t.stateName,t.statePathName,t.inFilters),ze.set(n,o)),t.node.addEventListener(e,o);let s=qe.get(n);return void 0===s?(s=new Set([t]),qe.set(n,s)):s.add(t),!0}return!1}const Ve=new Map,Je=new Map;const Xe=(t,e,o)=>s=>{const a=s.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==a.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const i=a.checked;let r=a.value;for(const t of o)r=t.filterFn(r);const l=xn(a.getRootNode(),t);null===l&&n(`State element with name "${t}" not found for two-way binding.`);const d=tt(a);l.createState("writable",t=>{t[ot](d,()=>{let n=t[e];if(Array.isArray(n))if(i)-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]=i?[r]:[]})})};function Ke(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=Ve.get(n);void 0===o&&(o=Xe(t.stateName,t.statePathName,t.inFilters),Ve.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}function Ye(t){for(const e of t)l(e),ut(e)||(gt(e),He(e),Ke(e))}function Ge(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));h(t,e),r(t),n.push(...e)}return[e,n]}(t);for(const t of o)et(t,e);Ye(s);for(const t of s){re(Wt(t),t);const e=xn(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)}Be(s)}const Qe=/\{\{\s*(.+?)\s*\}\}/g,Ze=new Set(["SCRIPT","STYLE"]);function tn(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&&Ze.has(t.parentElement.tagName)||en(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),tn(e.content)}else tn(t.content)}function en(t){const e=t.data;if(Qe.lastIndex=0,!Qe.test(e))return;Qe.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=Qe.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 nn;const on=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function sn(t,e){const n=e+p+m,o=t.indexOf("|"),s=t.indexOf("@");let a,i;if(-1!==o?(a=t.slice(0,o).trim(),i=t.slice(o)):-1!==s?(a=t.slice(0,s).trim(),i=t.slice(s)):(a=t.trim(),i=""),"."===a)a=n;else{if(!a.startsWith("."))return t;a=n+p+a.slice(1)}return i.length>0?a+i:a}function an(t,e){const n=on.exec(t);if(null===n)return t;const o=n[1],s=n[2],a=n[3];return o+sn(s,e)+a}function rn(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 a=n.slice(0,s).trim(),i=n.slice(s+1).trim(),r=sn(i,e);return r!==i?(o=!0,`${a}: ${r}`):t});return o?s.join(";"):t}function ln(t,e){return rn(t,e)}function dn(t){let e=t;const n=[];for(;null!==e.parentNode;){const t=Array.from(e.parentNode.childNodes).indexOf(e);n.unshift(t),e=e.parentNode}return n}function cn(t){const e=[],n=G(t);for(const t of n){const n=Y(t);e.push({nodePath:dn(t),parseBindTextResults:n})}return e}const un=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),fn=function(){if(nn)return nn;const t=[],e=W("not",t)(T);return nn={filterName:"not",args:t,filterFn:e},nn}();function hn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,fn],bindingType:t}}function pn(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=an(e.data,n);continue}const e=t;if(e instanceof HTMLTemplateElement)continue;const a=e.getAttribute(o);if(null!==a){const t=rn(a,n);t!==a&&e.setAttribute(o,t)}}}(n,s),mn(t,n,s);return{fragment:n,parseBindTextResult:o,nodeInfos:cn(n)}}function mn(t,o,s){const a=e.commentElsePrefix,i=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(;i.nextNode();){const t=i.currentNode;d.push(t)}for(const o of d){let i=o.getAttribute(e.bindAttributeName)||"";"string"==typeof s&&(i=ln(i,s));let d=z(i)[0];const c=un.get(d.bindingType);if(void 0===c)continue;const u=d.bindingType,f=o.content,h=Kt();let p=null;const m="for"===u?d.statePathName:s;if("else"===u){null===r&&n("'else' binding found without preceding 'if' or 'elseif' binding."),d=hn("else",r.parseBindTextResult),p=pn(t,f,d,m),X(h,t,p);const e=l.at(-1),s=document.createComment(`@@${c}:${h}`);void 0!==e?(o.remove(),e.fragment.appendChild(s),e.nodeInfos.push({nodePath:dn(s),parseBindTextResults:Y(s)})):o.replaceWith(s)}else if("elseif"===u){null===r&&n("'elseif' binding found without preceding 'if' or 'elseif' binding."),p=pn(t,f,d,m),X(h,t,p);const e=document.createComment(`@@${c}:${h}`),s=Kt(),i={fragment:document.createDocumentFragment(),parseBindTextResult:hn("else",r.parseBindTextResult),nodeInfos:[]};i.fragment.appendChild(e),i.nodeInfos.push({nodePath:dn(e),parseBindTextResults:Y(e)}),X(s,t,i);const u=l.at(-1);l.push(i);const g=document.createComment(`@@${a}:${s}`);void 0!==u?(o.remove(),u.fragment.appendChild(g),u.nodeInfos.push({nodePath:dn(g),parseBindTextResults:Y(g)})):o.replaceWith(g)}else{p=pn(t,f,d,m),X(h,t,p);const e=document.createComment(`@@${c}:${h}`);o.replaceWith(e)}"if"===u?(l.length=0,r=p):"elseif"===u?r=p:"else"===u&&(r=null,l.length=0)}}async function gn(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 wn(t){if(t===document)await gn(document),tn(document),mn(document,document),Ge(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await i(n.host),await gn(n),tn(n),mn(n,n),Ge(n,null)}}const bn=new WeakMap;function xn(t,e){let n=bn.get(t);return n&&n.get(e)||null}function In(t,o,s){let a=bn.get(t);if(null===s){if(!a)return;a.delete(o),0===a.size&&bn.delete(t),e.debug&&console.debug(`State element unregistered: name="${o}"`)}else a||(a=new Map,bn.set(t,a),("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name||"ShadowRoot"===t.constructor.name)&&queueMicrotask(()=>{wn(t)})),a.has(o)&&n(`State element with name "${o}" is already registered.`),a.set(o,s),e.debug&&console.debug(`State element registered: name="${o}"`,s)}class yn{_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 a;this._loopContextStack[this._length]=o,this._length++;try{a=e(o)}finally{a instanceof Promise?a.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return a}}const Sn=new Map;class Nn{path;segments;paths;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice(),o=[];let s=0,a=0,i="",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),a++,r++)}i+=l,o.push(i),i+=t<l.length-1?".":""}const c=P(n.join("."));(s>0||a>0)&&(l=s===r?"context":a===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 Pn(t){let e;return Sn.get(t)??(Sn.set(t,e=new Nn(t)),e)}const _n=new WeakMap;function vn(t,e){null===e?_n.delete(t):_n.set(t,e)}function An(t){const e=_n.get(t);e&&(e.dirty=!0)}function $n(t,e,o,s,a){if(!(e.pathInfo.path in t)){const a=Cn(t,e.parentAddress??n(`address.parentAddress is undefined path: ${e.pathInfo.path}`),o,s),i=e.pathInfo.segments[e.pathInfo.segments.length-1];if(i===m){const t=e.listIndex?.index??n(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(a,t)}return Reflect.get(a,i)}if(!a.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 En(t,e,n,o,s){const a=vt(yt(s,e.pathInfo),e.listIndex),i=function(t){return _n.get(t)??null}(a);if(null!==i&&!1===i.dirty)return i.value;const r=$n(t,e,n,o,s);return vn(a,{value:r,dirty:!1}),r}function Cn(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)?En(t,e,n,o,s):$n(t,e,n,o,s)}function kn(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 Mn=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=ie(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}Be(n)}};function Tn(){return Mn}const Ln=new WeakMap;function Wn(t,e){null===e?Ln.delete(t):Ln.set(t,e)}function On(t,n,o){const s=P(t.wildcardParentPaths[n]),a=yt(t.stateElement,s),i=Ht(s,o),r=bt(vt(a,o)),l=t.stateProxy[st](i),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}`),[]}}(se(i.listIndex,r,l),t.searchType);if(n===t.wildcardPaths.length-1)t.targetListIndexes.push(...d);else for(const e of d)On(t,n+1,e)}function Rn(t,e,o,s,a,i,r,l,d){const c={stateElement:e,staticMap:s,dynamicMap:a,result:new Set,listPathSet:i,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:a}=s.pop();if(a>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 i=e.pathInfo.path,r=a+1,l=[],d=t.staticMap.get(i);if(d)for(const n of d){const o=P(n);if(t.listPathSet.has(i)&&o.lastSegment===m){const n=t.stateProxy[st](e),s=bt(vt(yt(t.stateElement,e.pathInfo),e.listIndex)),a=se(e.listIndex,s,n);for(const e of a.newIndexes){const n=Ht(o,e);t.result.add(n),l.push({address:n,depth:r})}}else{const n=Ht(o,e.listIndex);t.result.add(n),l.push({address:n,depth:r})}}const c=t.dynamicMap.get(i);if(c)for(const o of c){const s=P(o),a=[];if(s.wildcardCount>0){const o=kt(e.pathInfo,s);if(s.wildcardCount-o>=1){let i;o>0?(null===e.listIndex&&n(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),i=e.listIndex.at(o-1)):i=null;const r={stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};On(r,o,i),a.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);a.push(t)}}else a.push(null);for(const e of a){const n=Ht(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 Fn(t,e,o,s,a,i){try{if(!(e.pathInfo.path in t)){const o=Cn(t,e.parentAddress??n(`address.parentAddress is undefined path: ${e.pathInfo.path}`),a,i),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(!i.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,s);i.pushAddress(e);try{return Reflect.set(t,e.pathInfo.path,s,a)}finally{i.popAddress()}}finally{const t=Tn();t.enqueueAbsoluteAddress(o),Rn(i.stateName,i.stateElement,e,i.stateElement.staticDependency,i.stateElement.dynamicDependency,i.stateElement.listPaths,a,"new",n=>{if(n===e)return;const o=vt(yt(i.stateElement,n.pathInfo),n.listIndex);An(o),t.enqueueAbsoluteAddress(o)})}}function Dn(t,e,o,s,a,i){let r=e.parentAddress??n(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Ln.get(t)??null}(r);if(null===l){const e=Cn(t,r,a,i)??[],n=te(e)??[];l={value:[...e],listIndexes:[...n]},Wn(r,l)}try{return Fn(t,e,o,s,a,i)}finally{const n=l.value.indexOf(s),o=Cn(t,r,a,i)??[],d=Array.isArray(o)?te(o)??[]:[],c=e.listIndex.index,u=-1!==n?l.listIndexes[n]:Qt(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;Wn(r,null)}}}function jn(t,e,n,o,s){const a=s.stateElement,i=a.elementPaths.has(e.pathInfo.path),r=e.pathInfo.wildcardCount>0||a.getterPaths.has(e.pathInfo.path),l=vt(yt(a,e.pathInfo),e.listIndex);try{return i?Dn(t,e,l,n,o,s):Fn(t,e,l,n,o,s)}finally{r&&vn(l,{value:n,dirty:!1})}}function Bn(t,e,o,s){return(e,a,i)=>{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>a.length&&n(`indexes length is insufficient: ${e}`);let l=null;for(let e=0;e<r.wildcardParentPathInfos.length;e++){const i=r.wildcardParentPathInfos[e],d=Ht(i,l),c=te(Cn(t,d,o,s));null==c&&n(`ListIndexes not found: ${i.path}`);l=c[a[e]]??n(`ListIndex not found: ${i.path}`)}const d=Ht(r,l);if(!(void 0!==i))return Cn(t,d,o,s);jn(t,d,i,o,s)}}const zn=new WeakMap;function qn(t,e,o,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return kn(s,a.wildcardPaths.at(-1)??n(`lastWildcardPath is null: ${e.pathInfo.path}`))??n(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let a=null;for(let i=0;i<e.pathInfo.wildcardCount;i++){const r=e.pathInfo.wildcardParentPathInfos[i]??n(`wildcardParentPathInfo is null: ${e.pathInfo.path}`);a=(te(Cn(t,Ht(r,a),o,s))??n(`ListIndex not found: ${r.path}`))[e.wildcardIndexes[i]??n(`wildcardIndex is null: ${e.pathInfo.path}`)]??n(`ListIndex not found: ${r.path}`)}return a}case"partial":n(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Un(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 Hn(t,e,o,s){const a=b[e];if(void 0!==a){0===s.addressStackLength&&n(`No active state reference to get list index for "${e.toString()}".`);const t=s.lastAddressStack?.listIndex;return t?.indexes[a]??n(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"!==e[0]){const n=Pn(e),a=qn(t,n,o,s),i=Ht(n.pathInfo,a);return Cn(t,i,o,s)}switch(e){case"$stateElement":return s.stateElement;case"$getAll":return(e,a)=>function(t,e,o,s){const a=Bn(t,0,o,s);return(e,i)=>{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===i){for(let t=0;t<l.wildcardParentPathInfos.length;t++){const e=l.wildcardParentPathInfos[t],n=kn(s,e.path);if(n){i=n.indexes;break}}void 0===i&&(i=[])}const d=(e,a,i,l,c,u,f)=>{const h=e[a]??null;if(null===h)return void f.push(u);const p=Ht(h,i),m=zn.get(p),g=Cn(t,p,o,s),w=se(i,m,g).newIndexes,b=l[c]??null;if(r.set(p,g),null===b)for(let t=0;t<w.length;t++){const n=w[t];d(e,a+1,n,l,c+1,u.concat(n.index),f)}else{const t=w[b]??n(`ListIndex not found: ${h.path}`);a+1<e.length?d(e,a+1,t,l,c+1,u.concat(t.index),f):f.push(u.concat(t.index))}},c=[];d(l.wildcardParentPathInfos,0,null,i,0,[],c);const u=[];for(let t=0;t<c.length;t++)u.push(a(l.path,c[t]));for(const[t,e]of r.entries())zn.set(t,e);return u}}(t,0,o,s)(e,a);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const a=Pn(e),i=qn(t,a,n,o),r=Ht(a.pathInfo,i),l=vt(yt(s,r.pathInfo),r.listIndex),d=Tn();d.enqueueAbsoluteAddress(l),Rn(o.stateName,o.stateElement,r,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=vt(yt(s,t.pathInfo),t.listIndex);An(e),d.enqueueAbsoluteAddress(e)})}}(t,0,o,s)(e);case"$resolve":return(e,n,a)=>Bn(t,0,o,s)(e,n,a);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 Un(t,e,n)}(s,t,e);case ot:return(t,e=()=>{})=>function(t,e,n){return Un(t,e,n)}(s,t,e);case st:return e=>Cn(t,e,o,s);case at:return(e,n)=>jn(t,e,n,o,s);case it: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,I);"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,a={};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=a[s];void 0===e?a[s]=[t]:e.push(t)}}return s.call(n,Array.from(t),a)}}(t,e,o,s)}return Reflect.get(t,e,o)}}class Vn{_stateElement;_stateName;_addressStack=Array(g).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,o){this._stateName=e;const s=xn(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 Hn(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 a=Pn(e),i=qn(t,a,o,s);return jn(t,Ht(a.pathInfo,i),n,o,s)}return Reflect.set(t,e,n,o)}(t,e,o,s,this)}has(t,e){return Reflect.has(t,e)}}const Jn=new WeakMap;const Xn=new WeakMap;function Kn(t,e){const n=Xn.get(t);return n?n.get(e)??null:null}const Yn=new WeakMap,Gn=new WeakMap,Qn=new WeakMap,Zn=new WeakMap;function to(t,e){return{innerAbsPathInfo:yt(t,P(e.propSegments.slice(1).join(p))),outerAbsPathInfo:Wt(e).absolutePathInfo}}function eo(t,e){let o=Yn.get(t);if(void 0===o&&(o=new Map,Yn.set(t,o)),o.has(e))return o.get(e);let s=Gn.get(t);void 0===s&&(s=new Map,Gn.set(t,s));const a=Qn.get(t);void 0===a&&n("Primary mapping rule set not found for web component.");let i=null;for(const t of a)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&n("Duplicate mapping rule for web component."),i=t;break}null===i&&n(`Mapping rule not found for inner path "${e.pathInfo.path}". Did you forget to bind this property in the component's data-wcs attribute? Available mappings: ${Array.from(a).map(t=>t.innerAbsPathInfo.pathInfo.path).join(", ")}`);const r=Zn.get(i);void 0===r&&n("Binding not found for primary mapping rule on web component.");const l=e.pathInfo.segments.slice(i.innerAbsPathInfo.pathInfo.segments.length),d=P(i.outerAbsPathInfo.pathInfo.segments.concat(l).join(p)),c=xn(t.getRootNode(),r.stateName);null===c&&n(`State element with name "${r.stateName}" not found for web component.`);const u=yt(c,d);o.set(e,u),s.set(u,e);return function(t,e){const n=f(t);null===n?h(t,[e]):n.push(e)}(t,{...r,propName:e.pathInfo.path,propSegments:e.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function no(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 oo{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=Kn(t,e)??n("State element not found for web component.")}get(t,e,o){if("string"==typeof e){if("then"===e)return;if(e in t)return Reflect.get(t,e,o);if("$"===e[0])return;const s=P(e),a=yt(this._innerStateElement,s),i=eo(this._webComponent,a);null===i&&n(`Outer path info not found for inner path "${a.pathInfo.path}" on web component.`);const r=tt(this._webComponent);let l;return i.stateElement.createState("readonly",t=>{t[ot](r,()=>{l=t[i.pathInfo.path];let e=null;null!==r&&null!==r.listIndex&&i.pathInfo.wildcardCount>0&&(e=r.listIndex.at(i.pathInfo.wildcardCount-1));!function(t,e){Jn.set(t,e)}(vt(i,e),l)})}),l}return Reflect.get(t,e,o)}set(t,e,o,s){if("string"==typeof e){const t=P(e),s=yt(this._innerStateElement,t),a=eo(this._webComponent,s);null===a&&n(`Outer path info not found for inner path "${s.pathInfo.path}" on web component.`);const i=tt(this._webComponent);return a.stateElement.createState("writable",t=>{t[ot](i,()=>{t[a.pathInfo.path]=o})}),!0}return Reflect.set(t,e,o,s)}has(t,e){if("string"==typeof e){if(e in t)return Reflect.has(t,e);if("$"===e[0])return!1;const n=P(e),o=yt(this._innerStateElement,n);return null!==eo(this._webComponent,o)}return Reflect.has(t,e)}}class so{_innerStateElement;constructor(t,e){this._innerStateElement=Kn(t,e)??n("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=P(e),n=vt(yt(this._innerStateElement,t),null);return o=n,Jn.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=P(e),n=yt(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class ao{_innerStateElement;constructor(t,e){this._innerStateElement=Kn(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 io=t=>()=>t;function ro(t,o,s,a){if(function(t,e,n){let o=Xn.get(t);o||(o=new Map,Xn.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=Kn(t,e);null===s&&n("State element not found for web component.");const a=new Map,i=new Map;for(const e of o){const n=to(s,e);let o=Qn.get(t);void 0===o?Qn.set(t,new Set([n])):o.add(n);const r=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Zn.set(n,e),a.set(r,l),i.set(l,r)}Yn.set(t,a),Gn.set(t,i)}(o,s,e);const a=function(t,e){const n=new so(t,e);return new Proxy({},n)}(o,s),i=function(t,e){const o=new oo(t,e),s=Kn(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 a=t[s.boundComponentStateProp];return"object"==typeof a&&null!==a||n(`Invalid state object for component state prop: ${s.boundComponentStateProp}`),new Proxy(no(a),o)}(o,s);t.setInitialState(i),Object.defineProperty(o,s,{get:io(a),enumerable:!0,configurable:!0})}else{t.setInitialState(no(a));const e=function(t,e){const n=new ao(t,e);return new Proxy({},n)}(o,s);Object.defineProperty(o,s,{get:io(e),enumerable:!0,configurable:!0})}if(function(t,e){let n=Dt.get(t);n||(n=new WeakMap,Dt.set(t,n)),n.set(e,!0)}(o,t),y in o){const t=o[y];"function"==typeof t?t.call(o,s).catch(t=>{n(`Error in ${y}: ${t instanceof Error?t.message:String(t)}`)}):n(`${y} is not a function.`)}}function lo(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 co 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 yn}();_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=lo(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,`state#${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",In(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;null!==o&&Ft(o)||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 s=this.getAttribute("bind-component");await customElements.whenDefined(o.tagName.toLowerCase()),o.hasAttribute(e.bindAttributeName)&&await i(o),s in o||n(`Component does not have property "${s}" for state binding.`);const a=o[s];"object"==typeof a&&null!==a||n(`Component property "${s}" is not an object for state binding.`),this._boundComponent=o,this._boundComponentStateProp=s,ro(this,this._boundComponent,this._boundComponentStateProp,a)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{x in t&&await t[it]()})}_callStateDisconnectedCallback(){this.createState("writable",t=>{I 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(),In(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 Vn(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 uo(){customElements.get(e.tagNames.state)||customElements.define(e.tagNames.state,co)}function fo(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)),uo()}export{fo as bootstrapState};
|
|
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 h(t,e){u.set(t,e)}const p=".",m="*",g=128,w={};for(let t=0;t<128;t++)w[`$${t+1}`]=t;const b=Object.freeze(w),x="$connectedCallback",I="$disconnectedCallback",y="$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="",h=0;for(let t=0;t<n.length;t++)u+=n[t],n[t]===m&&(i.push(u),a[u]=h,r.push(e(u)),l.push(f),d.push(e(f)),c.push(t),h++),o.push(u),s.push(e(u)),f=u,u+=".";const p=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=p,this.lastWildcardInfo=p?e(p):null,this.parentPath=g,this.parentPathInfo=g?e(g):null,this.wildcardCount=h}}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 O=new Map;function R(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=O.get(s);return void 0===i&&(i=W(n,[])(o),O.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;for(let s=0;s<t.length;s++){const i=t[s];o?i===o?o=null:n+=i:'"'===i||"'"===i?o=i:","===i?(e.push(n.trim()),n=""):n+=i}return n.trim()&&e.push(n.trim()),e}(n),l=`${a}(${r.join(",")}):${e}`;let d=O.get(l);return void 0===d&&(d=W(a,r)(o),O.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=R(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=R(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]),H=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function V(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=H.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=xn(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=xn(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=V(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!==V(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=xn(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 Set(["radio","checkbox"]),ht=new Set(["value","valueAsNumber","valueAsDate"]);const pt=new Map,mt=new Map;function gt(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(ft.has(t)&&"checked"===e)return!0;if(ht.has(e))return!0}return"select"===o&&"value"===e||"textarea"===o&&"value"===e}(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const a=function(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";for(const n of t.propModifiers)n.startsWith("on")&&(e=n.slice(2));return e}(t),r=function(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${n}`}(t,a);let l=pt.get(r);void 0===l&&(e=t.stateName,o=t.propName,s=t.statePathName,i=t.inFilters,l=t=>{const a=t.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");if(!(o in a))return void console.warn(`[@wcstack/state] Property "${o}" does not exist on target element.`);let r=a[o];for(const t of i)r=t.filterFn(r);const l=xn(a.getRootNode(),e);null===l&&n(`State element with name "${e}" not found for two-way binding.`);const d=tt(a);l.createState("writable",t=>{t[ot](d,()=>{t[s]=r})})},pt.set(r,l)),t.node.addEventListener(a,l);let d=mt.get(r);return void 0===d?(d=new Set([t]),mt.set(r,d)):d.add(t),!0}var e,o,s,i;return!1}const wt=new WeakMap;function bt(t){return wt.get(t)??[]}function xt(t,e){wt.set(t,e)}const It=new WeakMap;function yt(t,e){if(It.has(t)){const n=It.get(t);if(n.has(e))return n.get(e)}else It.set(t,new WeakMap);const n=Object.freeze(new St(t,e));return It.get(t).set(e,n),n}class St{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=yt(t,e.parentPathInfo)}}const Nt=new WeakMap,Pt=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=vt(t,e)}}function vt(t,e){if(null===e){let e=Pt.get(t);return void 0!==e||(e=new _t(t,null),Pt.set(t,e)),e}{let n=Nt.get(e);void 0===n&&(n=new WeakMap,Nt.set(e,n));let o=n.get(t);return void 0!==o||(o=new _t(t,e),n.set(t,o)),o}}const At=new WeakMap;function $t(t,e){null===e?At.delete(t):At.set(t,e)}function Et(t){return At.get(t)||null}const Ct=new Map;function kt(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=Ct.get(s);if(void 0!==i)return i;return i=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Ct.set(s,i),i}const Mt=new WeakMap;function Tt(t){const e=tt(t.node);if(null===e)return null;let n=Mt.get(e);if(void 0===n)n=new WeakMap,Mt.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=kt(e.pathInfo,t.statePathInfo);return n>0&&(o=e.listIndex.at(n-1)),o}finally{n.set(t,o)}}const Lt=new WeakMap;function Wt(t){let e=null;if(e=Lt.get(t)||null,null!==e)return e;let o=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=Et(o);null===e?n(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):o=e}const s=Tt(t),i=xn(o,t.stateName);null===i&&n(`State element with name "${t.stateName}" not found for binding.`);return e=vt(yt(i,t.statePathInfo),s),Lt.set(t,e),e}function Ot(t){Lt.delete(t)}const Rt=new WeakMap;function Ft(t){const e=Rt.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{Rt.set(t,n)}}const Dt=new WeakMap;function jt(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const Bt=Object.freeze([]);const zt=new WeakMap,qt=new WeakMap;class Ut{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=Ht(t,e)}}function Ht(t,e){if(null===e){let e=qt.get(t);return void 0!==e||(e=new Ut(t,null),qt.set(t,e)),e}{let n=zt.get(e);void 0===n&&(n=new WeakMap,zt.set(e,n));let o=n.get(t);return void 0!==o||(o=new Ut(t,e),n.set(t,o)),o}}const Vt=new WeakMap;function Jt(t){return Vt.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 Xt=0;function Kt(){return`u${(Xt++).toString(36)}`}let Yt=0;class Gt{uuid=Kt();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=Yt}get index(){return this._index}set index(t){this._index=t,this._version=++Yt,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=Yt),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 Qt(t,e){return new Gt(t,e)}const Zt=new WeakMap;function te(t){return Zt.get(t)||null}const ee=new WeakMap,ne=Object.freeze([]),oe=new Set;function se(t,e,n){const o=Array.isArray(e)&&e.length>0?e:ne,s=Array.isArray(n)&&n.length>0?n:ne,i=function(t,e){const n=Array.isArray(t)&&t.length>0?t:ne,o=Array.isArray(e)&&e.length>0?e:ne;let s=ee.get(n);return s&&s.get(o)||null}(o,s);if(i)return i;const a=te(o)||[];let r;try{if(0===s.length)return r={oldIndexes:a,newIndexes:[],changeIndexSet:oe,deleteIndexSet:new Set(a),addIndexSet:oe};let e=te(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=Qt(t,n);e.push(o)}}return r={oldIndexes:a,newIndexes:e,changeIndexSet:oe,deleteIndexSet:oe,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:oe,deleteIndexSet:oe,addIndexSet:oe};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=Qt(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=ee.get(t);o||(o=new WeakMap,ee.set(t,o)),o.set(e,n)}(o,s,r),l=s,null!==(d=r.newIndexes)?Zt.set(l,d):Zt.delete(l))}var l,d}const ie=new WeakMap;function ae(t){let e=null;return e=ie.get(t)||null,null===e&&(e=new Set,ie.set(t,e)),e}function re(t,e){ae(t).add(e)}function le(t,e){ae(t).delete(e)}const de=new WeakMap;function ce(t){de.delete(t)}const ue=new WeakMap;function fe(t){return ue.get(t)??[]}const he=new WeakMap;function pe(t){return he.get(t)??[]}function me(t,e,n){!function(t,e){const n=pe(t);for(const t of n)et(t,e)}(t,e);const o=fe(t);for(const t of o){re(Wt(t),t),je(t,n)}}function ge(t){if(!t.mounted)return;const e=fe(t);for(const t of e){le(Wt(t),t),Ot(t),ce(t)}!function(t){const e=pe(t);for(const t of e)et(t,null)}(t)}const we=new WeakMap,be=Object.freeze(new Set);function xe(t){const e=we.get(t);return void 0!==e?e:be}const Ie=new Set(["if","elseif","else","for"]);class ye{_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=fe(this);for(const e of t){if(Ie.has(e.bindingType)){const t=xe(e.node);for(const e of t)e.unmount()}ce(e),Ot(e)}this._mounted=!1}}function Se(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);h(e,t),r(e),s.push(...t),o.push(e)}}return[o,s]}(t,e);return Ye(s),{nodes:o,bindingInfos:s}}(o,e.nodeInfos),i=new ye(o);!function(t,e){ue.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){Vt.set(t,e)}(i,a),function(t,e){he.set(t,e)}(i,s.nodes),function(t,e){const n=we.get(t);n?n.add(e):we.set(t,new Set([e]))}(t.node,i),i}const Ne=new WeakMap,Pe=new WeakMap,_e=new WeakMap,ve=new WeakMap;function Ae(t){return _e.get(t.node)||[]}function $e(t,e){const n=_e.get(t.node);void 0===n?_e.set(t.node,[e]):n.push(e)}function Ee(t,e){let n=Pe.get(t);if(void 0===n)return null;const o=n.get(e);return void 0===o?null:o}function Ce(t,e,n){let o=Pe.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,Pe.set(t,o)}null===n?o.delete(e):o.set(e,n)}const ke=new WeakMap;function Me(t){return`${t.bindingType} ${t.statePathName} ${t.outFilters.map(t=>t.filterName).join("|")} ${t.node.isConnected?"(connected)":"(disconnected)"}`}function Te(t,n,o){const s=t.node.isConnected,i=Boolean(o);let a;const r=xe(t.node);a=0===r.size?Se(t):r.values().next().value;try{if(i||(e.debug&&console.log(`unmount if content : ${Me(t)}`),ge(a),a.unmount()),i){e.debug&&console.log(`mount if content : ${Me(t)}`),a.mountAfter(t.node);me(a,tt(t.node),n)}}finally{ke.set(t.node,s)}}function Le(t,n,o){const s=t.node,i=t.propSegments;if(1===i.length){const t=i[0];return void(s[t]!==o&&(s[t]=o))}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}));a[i[i.length-1]]=o}}function We(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 Oe(t,e){const o=function(t){let e=null;if(e=de.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const o=Tt(t);null===o&&n(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=Ht(t.statePathInfo,o)}else e=Ht(t.statePathInfo,null);return de.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 Re={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)}},Fe={text:function(t,e,n){t.replaceNode.nodeValue!==n&&(t.replaceNode.nodeValue=n)},for:function(t,e,o){const s=t.statePathInfo,i=Tt(t),a=Wt(t),r=bt(a),l=se(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=ve.get(t.node);if(void 0===e){const n=Ne.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),ve.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=Ee(t.node,e);null!==n&&(ge(n),n.unmount(),$e(t,n),Ce(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(),$t(f,e.rootNode));for(const o of l.newIndexes){let i;if(l.addIndexSet.has(o)){const a=Ht(c,o);u.createLoopContext(a,n=>{const o=Ae(t);i=o.pop(),void 0===i&&(i=Se(t)),null!==f?i.appendTo(f):d.nextSibling!==i.firstNode&&i.mountAfter(d),me(i,n,e)}),void 0===i&&n(`Content not found for ListIndex: ${o.index} at path "${s.path}"`)}else{if(i=Ee(t.node,o),l.changeIndexSet.has(o)){const t=Jt(i);for(const n of t)je(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,Ce(t.node,o,i)}Ne.set(t.node,d),null!==f&&(t.node.parentNode.insertBefore(f,t.node.nextSibling),$t(f,null))},if:Te,else:Te,elseif:Te,radio:function(t,e,n){const o=t.node,s=jt(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=jt(o.value,t.inFilters),i=Array.isArray(n)?n:Bt;o.checked=i.includes(s)}};function De(t,e){const n=jt(Oe(e.state,t),t.outFilters);let o=Fe[t.bindingType];if(void 0===o){const n=t.propSegments[0];o=Re[n],void 0===o&&(o=function(t,e){const n=Dt.get(t);return!!n&&!0===n.get(e)}(t.replaceNode,e.stateElement)?We:Le)}if(o===Le){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return void e.deferredSelectBindings.push({binding:t,value:n})}}o(t,e,n)}function je(t,e){if(e.appliedBindingSet.has(t))return;e.appliedBindingSet.add(t);const o=Wt(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=Ft(t.replaceNode);if(s&&void 0===customElements.get(s))return;let i=t.replaceNode.getRootNode();if(i instanceof DocumentFragment&&!(i instanceof ShadowRoot)&&(i=Et(i),null===i&&n("Root node for fragment not found for binding.")),t.stateName!==e.stateName||i!==e.rootNode){const o=xn(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};De(t,s)})}else De(t,e)}function Be(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=Et(c),null===c&&n("Root node for fragment not found for binding."));const u=xn(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(;;){je(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)Le(t,0,e);for(const[t,e]of i.entries())xt(t,e);for(const[t,e]of a.entries())t.createState("writable",t=>{t[lt](Array.from(e))})}const ze=new Map,qe=new Map;const Ue=(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=xn(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 He(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=ze.get(n);void 0===o&&(o=Ue(t.stateName,t.statePathName,t.inFilters),ze.set(n,o)),t.node.addEventListener(e,o);let s=qe.get(n);return void 0===s?(s=new Set([t]),qe.set(n,s)):s.add(t),!0}return!1}const Ve=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("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=xn(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 Ke(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=Ve.get(n);void 0===o&&(o=Xe(t.stateName,t.statePathName,t.inFilters),Ve.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}function Ye(t){for(const e of t)l(e),ut(e)||(gt(e),He(e),Ke(e))}function Ge(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));h(t,e),r(t),n.push(...e)}return[e,n]}(t);for(const t of o)et(t,e);Ye(s);for(const t of s){re(Wt(t),t);const e=xn(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)}Be(s)}const Qe=/\{\{\s*(.+?)\s*\}\}/g,Ze=new Set(["SCRIPT","STYLE"]);function tn(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&&Ze.has(t.parentElement.tagName)||en(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),tn(e.content)}else tn(t.content)}function en(t){const e=t.data;if(Qe.lastIndex=0,!Qe.test(e))return;Qe.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=Qe.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 nn;const on=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function sn(t,e){const n=e+p+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+p+i.slice(1)}return a.length>0?i+a:i}function an(t,e){const n=on.exec(t);if(null===n)return t;const o=n[1],s=n[2],i=n[3];return o+sn(s,e)+i}function rn(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=sn(a,e);return r!==a?(o=!0,`${i}: ${r}`):t});return o?s.join(";"):t}function ln(t,e){return rn(t,e)}function dn(t){let e=t;const n=[];for(;null!==e.parentNode;){const t=Array.from(e.parentNode.childNodes).indexOf(e);n.unshift(t),e=e.parentNode}return n}function cn(t){const e=[],n=G(t);for(const t of n){const n=Y(t);e.push({nodePath:dn(t),parseBindTextResults:n})}return e}const un=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),fn=function(){if(nn)return nn;const t=[],e=W("not",t)(T);return nn={filterName:"not",args:t,filterFn:e},nn}();function hn(t,e){const n=e.outFilters;return{...e,outFilters:[...n,fn],bindingType:t}}function pn(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=an(e.data,n);continue}const e=t;if(e instanceof HTMLTemplateElement)continue;const i=e.getAttribute(o);if(null!==i){const t=rn(i,n);t!==i&&e.setAttribute(o,t)}}}(n,s),mn(t,n,s);return{fragment:n,parseBindTextResult:o,nodeInfos:cn(n)}}function mn(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=ln(a,s));let d=z(a)[0];const c=un.get(d.bindingType);if(void 0===c)continue;const u=d.bindingType,f=o.content,h=Kt();let p=null;const m="for"===u?d.statePathName:s;if("else"===u){null===r&&n("'else' binding found without preceding 'if' or 'elseif' binding."),d=hn("else",r.parseBindTextResult),p=pn(t,f,d,m),X(h,t,p);const e=l.at(-1),s=document.createComment(`@@${c}:${h}`);void 0!==e?(o.remove(),e.fragment.appendChild(s),e.nodeInfos.push({nodePath:dn(s),parseBindTextResults:Y(s)})):o.replaceWith(s)}else if("elseif"===u){null===r&&n("'elseif' binding found without preceding 'if' or 'elseif' binding."),p=pn(t,f,d,m),X(h,t,p);const e=document.createComment(`@@${c}:${h}`),s=Kt(),a={fragment:document.createDocumentFragment(),parseBindTextResult:hn("else",r.parseBindTextResult),nodeInfos:[]};a.fragment.appendChild(e),a.nodeInfos.push({nodePath:dn(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:dn(g),parseBindTextResults:Y(g)})):o.replaceWith(g)}else{p=pn(t,f,d,m),X(h,t,p);const e=document.createComment(`@@${c}:${h}`);o.replaceWith(e)}"if"===u?(l.length=0,r=p):"elseif"===u?r=p:"else"===u&&(r=null,l.length=0)}}async function gn(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 wn(t){if(t===document)await gn(document),tn(document),mn(document,document),Ge(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await a(n.host),await gn(n),tn(n),mn(n,n),Ge(n,null)}}const bn=new WeakMap;function xn(t,e){let n=bn.get(t);return n&&n.get(e)||null}function In(t,o,s){let i=bn.get(t);if(null===s){if(!i)return;i.delete(o),0===i.size&&bn.delete(t),e.debug&&console.debug(`State element unregistered: name="${o}"`)}else i||(i=new Map,bn.set(t,i),("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name||"ShadowRoot"===t.constructor.name)&&queueMicrotask(()=>{wn(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 yn{_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 Sn=new Map;class Nn{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 Pn(t){let e;return Sn.get(t)??(Sn.set(t,e=new Nn(t)),e)}const _n=new WeakMap;function vn(t,e){null===e?_n.delete(t):_n.set(t,e)}function An(t){const e=_n.get(t);e&&(e.dirty=!0)}function $n(t,e,o,s,i){if(!(e.pathInfo.path in t)){const i=Cn(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 En(t,e,n,o,s){const i=vt(yt(s,e.pathInfo),e.listIndex),a=function(t){return _n.get(t)??null}(i);if(null!==a&&!1===a.dirty)return a.value;const r=$n(t,e,n,o,s);return vn(i,{value:r,dirty:!1}),r}function Cn(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)?En(t,e,n,o,s):$n(t,e,n,o,s)}function kn(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 Mn=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=ae(t);for(const t of e)!1!==t.replaceNode.isConnected&&n.push(t)}Be(n)}};function Tn(){return Mn}const Ln=new WeakMap;function Wn(t,e){null===e?Ln.delete(t):Ln.set(t,e)}function On(t,n,o){const s=P(t.wildcardParentPaths[n]),i=yt(t.stateElement,s),a=Ht(s,o),r=bt(vt(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}`),[]}}(se(a.listIndex,r,l),t.searchType);if(n===t.wildcardPaths.length-1)t.targetListIndexes.push(...d);else for(const e of d)On(t,n+1,e)}function Rn(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=bt(vt(yt(t.stateElement,e.pathInfo),e.listIndex)),i=se(e.listIndex,s,n);for(const e of i.newIndexes){const n=Ht(o,e);t.result.add(n),l.push({address:n,depth:r})}}else{const n=Ht(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=kt(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};On(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=Ht(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 Fn(t,e,o,s,i,a){try{if(!(e.pathInfo.path in t)){const o=Cn(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=Tn();t.enqueueAbsoluteAddress(o),Rn(a.stateName,a.stateElement,e,a.stateElement.staticDependency,a.stateElement.dynamicDependency,a.stateElement.listPaths,i,"new",n=>{if(n===e)return;const o=vt(yt(a.stateElement,n.pathInfo),n.listIndex);An(o),t.enqueueAbsoluteAddress(o)})}}function Dn(t,e,o,s,i,a){let r=e.parentAddress??n(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Ln.get(t)??null}(r);if(null===l){const e=Cn(t,r,i,a)??[],n=te(e)??[];l={value:[...e],listIndexes:[...n]},Wn(r,l)}try{return Fn(t,e,o,s,i,a)}finally{const n=l.value.indexOf(s),o=Cn(t,r,i,a)??[],d=Array.isArray(o)?te(o)??[]:[],c=e.listIndex.index,u=-1!==n?l.listIndexes[n]:Qt(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;Wn(r,null)}}}function jn(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=vt(yt(i,e.pathInfo),e.listIndex);try{return a?Dn(t,e,l,n,o,s):Fn(t,e,l,n,o,s)}finally{r&&vn(l,{value:n,dirty:!1})}}function Bn(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=Ht(a,l),c=te(Cn(t,d,o,s));null==c&&n(`ListIndexes not found: ${a.path}`);l=c[i[e]]??n(`ListIndex not found: ${a.path}`)}const d=Ht(r,l);if(!(void 0!==a))return Cn(t,d,o,s);jn(t,d,a,o,s)}}const zn=new WeakMap;function qn(t,e,o,s){const i=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return kn(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=(te(Cn(t,Ht(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 Un(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 Hn(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=Pn(e),i=qn(t,n,o,s),a=Ht(n.pathInfo,i);return Cn(t,a,o,s)}switch(e){case"$stateElement":return s.stateElement;case"$getAll":return(e,i)=>function(t,e,o,s){const i=Bn(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=kn(s,e.path);if(n){a=n.indexes;break}}void 0===a&&(a=[])}const d=(e,i,a,l,c,u,f)=>{const h=e[i]??null;if(null===h)return void f.push(u);const p=Ht(h,a),m=zn.get(p),g=Cn(t,p,o,s),w=se(a,m,g).newIndexes,b=l[c]??null;if(r.set(p,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: ${h.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())zn.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=Pn(e),a=qn(t,i,n,o),r=Ht(i.pathInfo,a),l=vt(yt(s,r.pathInfo),r.listIndex),d=Tn();d.enqueueAbsoluteAddress(l),Rn(o.stateName,o.stateElement,r,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=vt(yt(s,t.pathInfo),t.listIndex);An(e),d.enqueueAbsoluteAddress(e)})}}(t,0,o,s)(e);case"$resolve":return(e,n,i)=>Bn(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 Un(t,e,n)}(s,t,e);case ot:return(t,e=()=>{})=>function(t,e,n){return Un(t,e,n)}(s,t,e);case st:return e=>Cn(t,e,o,s);case it:return(e,n)=>jn(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,I);"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 Vn{_stateElement;_stateName;_addressStack=Array(g).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(t,e,o){this._stateName=e;const s=xn(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 Hn(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=Pn(e),a=qn(t,i,o,s);return jn(t,Ht(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 Jn=new WeakMap;const Xn=new WeakMap;function Kn(t,e){const n=Xn.get(t);return n?n.get(e)??null:null}const Yn=new WeakMap,Gn=new WeakMap,Qn=new WeakMap,Zn=new WeakMap;function to(t,e){return{innerAbsPathInfo:yt(t,P(e.propSegments.slice(1).join(p))),outerAbsPathInfo:Wt(e).absolutePathInfo}}function eo(t,e){let o=Yn.get(t);if(void 0===o&&(o=new Map,Yn.set(t,o)),o.has(e))return o.get(e);let s=Gn.get(t);void 0===s&&(s=new Map,Gn.set(t,s));const i=Qn.get(t);void 0===i&&n("Primary mapping rule set not found for web component.");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}null===a&&n(`Mapping rule not found for inner path "${e.pathInfo.path}". Did you forget to bind this property in the component's data-wcs attribute? Available mappings: ${Array.from(i).map(t=>t.innerAbsPathInfo.pathInfo.path).join(", ")}`);const r=Zn.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(p)),c=xn(t.getRootNode(),r.stateName);null===c&&n(`State element with name "${r.stateName}" not found for web component.`);const u=yt(c,d);o.set(e,u),s.set(u,e);return function(t,e){const n=f(t);null===n?h(t,[e]):n.push(e)}(t,{...r,propName:e.pathInfo.path,propSegments:e.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function no(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 oo{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=Kn(t,e)??n("State element not found for web component.")}get(t,e,o){if("string"==typeof e){if("then"===e)return;if(e in t)return Reflect.get(t,e,o);if("$"===e[0])return;const s=P(e),i=yt(this._innerStateElement,s),a=eo(this._webComponent,i);null===a&&n(`Outer path info not found for inner path "${i.pathInfo.path}" on web component.`);const r=tt(this._webComponent);let l;return a.stateElement.createState("readonly",t=>{t[ot](r,()=>{l=t[a.pathInfo.path];let e=null;null!==r&&null!==r.listIndex&&a.pathInfo.wildcardCount>0&&(e=r.listIndex.at(a.pathInfo.wildcardCount-1));!function(t,e){Jn.set(t,e)}(vt(a,e),l)})}),l}return Reflect.get(t,e,o)}set(t,e,o,s){if("string"==typeof e){const t=P(e),s=yt(this._innerStateElement,t),i=eo(this._webComponent,s);null===i&&n(`Outer path info not found for inner path "${s.pathInfo.path}" on web component.`);const a=tt(this._webComponent);return i.stateElement.createState("writable",t=>{t[ot](a,()=>{t[i.pathInfo.path]=o})}),!0}return Reflect.set(t,e,o,s)}has(t,e){if("string"==typeof e){if(e in t)return Reflect.has(t,e);if("$"===e[0])return!1;const n=P(e),o=yt(this._innerStateElement,n);return null!==eo(this._webComponent,o)}return Reflect.has(t,e)}}class so{_innerStateElement;constructor(t,e){this._innerStateElement=Kn(t,e)??n("State element not found for web component.")}get(t,e,n){if("string"==typeof e){const t=P(e),n=vt(yt(this._innerStateElement,t),null);return o=n,Jn.get(o)}return Reflect.get(t,e,n);var o}set(t,e,n,o){if("string"==typeof e){const t=P(e),n=yt(this._innerStateElement,t);return this._innerStateElement.createState("readonly",t=>{t.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(t,e,n,o)}}class io{_innerStateElement;constructor(t,e){this._innerStateElement=Kn(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 ao=t=>()=>t;function ro(t,o,s,i){if(function(t,e,n){let o=Xn.get(t);o||(o=new Map,Xn.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=Kn(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=to(s,e);let o=Qn.get(t);void 0===o?Qn.set(t,new Set([n])):o.add(n);const r=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Zn.set(n,e),i.set(r,l),a.set(l,r)}Yn.set(t,i),Gn.set(t,a)}(o,s,e);const i=function(t,e){const n=new so(t,e);return new Proxy({},n)}(o,s),a=function(t,e){const o=new oo(t,e),s=Kn(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(no(i),o)}(o,s);t.setInitialState(a),Object.defineProperty(o,s,{get:ao(i),enumerable:!0,configurable:!0})}else{t.setInitialState(no(i));const e=function(t,e){const n=new io(t,e);return new Proxy({},n)}(o,s);Object.defineProperty(o,s,{get:ao(e),enumerable:!0,configurable:!0})}if(function(t,e){let n=Dt.get(t);n||(n=new WeakMap,Dt.set(t,n)),n.set(e,!0)}(o,t),y in o){const t=o[y];"function"==typeof t?t.call(o,s).catch(t=>{n(`Error in ${y}: ${t instanceof Error?t.message:String(t)}`)}):n(`${y} is not a function.`)}}function lo(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 co 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 yn}();_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=lo(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,`state#${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",In(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?Ft(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,ro(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=>{I 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(),In(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 Vn(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 uo(){customElements.get(e.tagNames.state)||customElements.define(e.tagNames.state,co)}function fo(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)),uo()}export{fo as bootstrapState};
|
|
2
2
|
//# sourceMappingURL=index.esm.min.js.map
|