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