@wcstack/state 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +376 -85
- 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,sameValueGuard:!0},s=n;function o(){return s}const r="1.18.0";function i(e){throw new Error(`[@wcstack/state] ${e}`)}const a=new WeakMap;let c=0;function l(e){let t,n=a.get(e)||null;if(null!==n)return n;const s=new Promise(e=>{t=e});return n={id:++c,promise:s,resolve:t},a.set(e,n),n}async function d(e){const t=l(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="|",g={};for(let e=0;e<128;e++)g[`$${e+1}`]=e;const b=Object.freeze(g),y="$connectedCallback",w="$disconnectedCallback",N="$updatedCallback",x="$stateReadyCallback",S="$bindables",A="$commandTokens",_="$command",v="$eventTokens",I="$on",$="$streams",P="$streamStatus",T="$streamError",E="data-wc-definition",C=new Map;let k=0;function M(e){let t=C.get(e);return void 0!==t||(t=Object.freeze(new O(e)),C.set(e,t)),t}class O{id=++k;path;segments;lastSegment;cumulativePaths;cumulativePathSet;cumulativePathInfos;cumulativePathInfoSet;parentPath;wildcardPaths;wildcardPathSet;indexByWildcardPath;wildcardPathInfos;wildcardPathInfoSet;wildcardParentPaths;wildcardParentPathSet;wildcardParentPathInfos;wildcardParentPathInfoSet;wildcardPositions;lastWildcardPath;lastWildcardInfo;wildcardCount;parentPathInfo;constructor(e){const t=t=>e===t?this:M(t),n=e.split("."),s=[],o=[],r=[],i={},a=[],c=[],l=[],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)),c.push(f),l.push(t(f)),d.push(e),h++),s.push(u),o.push(t(u)),f=u,u+=".";const m=r.length>0?r[r.length-1]:null,g=s.length>1?s[s.length-2]:null;this.path=e,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=s,this.cumulativePathSet=new Set(s),this.cumulativePathInfos=o,this.cumulativePathInfoSet=new Set(o),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=i,this.wildcardPathInfos=a,this.wildcardPathInfoSet=new Set(a),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=l,this.wildcardParentPathInfoSet=new Set(l),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 W=new WeakMap;function L(e){const t=W.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,s=t.tagName.toLowerCase();if(s.includes("-"))return n=s;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{W.set(e,n)}}function D(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 R(e,t,n){const s="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:s,statePathInfo:M(s),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function j(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function F(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 B=new WeakMap;function q(e){return B.get(e)||null}function z(e,t){B.set(e,t)}const H=new Set(["if","elseif","else","for"]);function V(e){i(`filter ${e} requires at least one option`)}function U(e){i(`filter ${e} requires a number as option`)}function G(e){i(`filter ${e} requires a number value`)}function J(e){i(`filter ${e} requires a date value`)}function Y(e){return!(!e||isNaN(Number(e)))}const K={eq:e=>{const t=e?.[0]??V("eq");return e=>"number"==typeof e?(Y(t)||U("eq"),e===Number(t)):e===t},ne:e=>{const t=e?.[0]??V("ne");return e=>"number"==typeof e?(Y(t)||U("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]??V("lt");return Y(t)||U("lt"),e=>("number"!=typeof e&&G("lt"),e<Number(t))},le:e=>{const t=e?.[0]??V("le");return Y(t)||U("le"),e=>("number"!=typeof e&&G("le"),e<=Number(t))},gt:e=>{const t=e?.[0]??V("gt");return Y(t)||U("gt"),e=>("number"!=typeof e&&G("gt"),e>Number(t))},ge:e=>{const t=e?.[0]??V("ge");return Y(t)||U("ge"),e=>("number"!=typeof e&&G("ge"),e>=Number(t))},inc:e=>{const t=e?.[0]??V("inc");return Y(t)||U("inc"),e=>("number"!=typeof e&&G("inc"),e+Number(t))},dec:e=>{const t=e?.[0]??V("dec");return Y(t)||U("dec"),e=>("number"!=typeof e&&G("dec"),e-Number(t))},mul:e=>{const t=e?.[0]??V("mul");return Y(t)||U("mul"),e=>("number"!=typeof e&&G("mul"),e*Number(t))},div:e=>{const t=e?.[0]??V("div");return Y(t)||U("div"),e=>("number"!=typeof e&&G("div"),e/Number(t))},mod:e=>{const t=e?.[0]??V("mod");return Y(t)||U("mod"),e=>("number"!=typeof e&&G("mod"),e%Number(t))},fix:e=>{const t=e?.[0]??"0";return Y(t)||U("fix"),e=>("number"!=typeof e&&G("fix"),e.toFixed(Number(t)))},locale:e=>{const t=e?.[0]??s.locale;return e=>("number"!=typeof e&&G("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]??V("slice");Y(n)||U("slice"),t.push(Number(n));const s=e?.[1];return void 0!==s&&(Y(s)||U("slice"),t.push(Number(s))),e=>String(e).slice(...t)},substr:e=>{const t=e?.[0]??V("substr");Y(t)||U("substr");const n=e?.[1]??V("substr");return Y(n)||U("substr"),e=>String(e).substr(Number(t),Number(n))},pad:e=>{const t=e?.[0]??V("pad");Y(t)||U("pad");const n=e?.[1]??"0";return e=>String(e).padStart(Number(t),n)},rep:e=>{const t=e?.[0]??V("rep");return Y(t)||U("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 Y(t)||U("round"),e=>{"number"!=typeof e&&G("round");const n=Math.pow(10,Number(t));return Math.round(e*n)/n}},floor:e=>{const t=e?.[0]??"0";return Y(t)||U("floor"),e=>{"number"!=typeof e&&G("floor");const n=Math.pow(10,Number(t));return Math.floor(e*n)/n}},ceil:e=>{const t=e?.[0]??"0";return Y(t)||U("ceil"),e=>{"number"!=typeof e&&G("ceil");const n=Math.pow(10,Number(t));return Math.ceil(e*n)/n}},percent:e=>{const t=e?.[0]??"0";return Y(t)||U("percent"),e=>("number"!=typeof e&&G("percent"),`${(100*e).toFixed(Number(t))}%`)},date:e=>{const t=e?.[0]??s.locale;return e=>(e instanceof Date||J("date"),e.toLocaleDateString(t))},time:e=>{const t=e?.[0]??s.locale;return e=>(e instanceof Date||J("time"),e.toLocaleTimeString(t))},datetime:e=>{const t=e?.[0]??s.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(),s=(e.getMonth()+1).toString().padStart(2,"0"),o=e.getDate().toString().padStart(2,"0");return`${n}${t}${s}${t}${o}`}},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]??V("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},X=K,Q={input:K,output:X},Z=(e,t)=>n=>{const s=n[e];return s||i(`filter not found: ${e}`),s(t)};const ee=new Map;function te(e,t){const n=Q[t];return e.map(e=>{const s=e.indexOf("("),o=e.lastIndexOf(")");if(-1!==s&&-1===o&&i(`Invalid filter format: missing closing parenthesis in "${e}"`),-1!==o&&-1===s&&i(`Invalid filter format: missing opening parenthesis in "${e}"`),-1===s){const s=e.trim(),o=`${s}():${t}`;let r=ee.get(o);return void 0===r&&(r=Z(s,[])(n),ee.set(o,r)),{filterName:s,args:[],filterFn:r}}{const r=e.substring(s+1,o),i=e.substring(0,s).trim(),a=function(e){const t=[];let n="",s=null,o=!1;for(let r=0;r<e.length;r++){const i=e[r];s?i===s?s=null:n+=i:'"'===i||"'"===i?(s=i,o=!0):","===i?(t.push(n.trim()),n="",o=!1):n+=i}const r=n.trim();return(r||o)&&t.push(r),t}(r),c=`${i}(${a.join(",")}):${t}`;let l=ee.get(c);return void 0===l&&(l=Z(i,a)(n),ee.set(c,l)),{filterName:i,args:a,filterFn:l}}})}const ne=e=>e.trim(),se=new Map;const oe=new Map;function re(e){const t=e.indexOf(m);let n="",s=[],o="",r=[];-1!==t?(n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),oe.has(o)?r=oe.get(o):(s=o.split(m).map(ne),r=te(s,"output"),oe.set(o,r))):n=e.trim();const[i,a="default"]=n.split("@").map(ne);return{stateName:a,statePathName:i,statePathInfo:M(i),outFilters:r}}function ie(e){const[...t]=e.split(";").map(ne).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(),s=e.slice(t+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:M("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("..."===n){const t=re(s);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:[],...re(s),bindingType:n}}{const e=re(s),t=function(e){const t=e.indexOf(m);let n="",s=[],o="",r=[];-1!==t?(n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),se.has(o)?r=se.get(o):(s=o.split(m).map(ne),r=te(s,"input"),se.set(o,r))):n=e.trim();const[i,a]=n.split("#").map(ne),c=i.split(f).map(ne);return{propName:i,propSegments:c,propModifiers:a?a.split(",").map(ne):[],inFilters:r}}(n);return"eventToken"===t.propSegments[0]||t.propSegments[0].startsWith("on")?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>H.has(e.bindingType))&&i(`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const ae=new WeakMap,ce=new Set([s.commentTextPrefix,s.commentForPrefix,s.commentIfPrefix,s.commentElseIfPrefix,s.commentElsePrefix]),le=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function de(e){const t=ae.get(e);if("string"==typeof t)return t;if(e.nodeType!==Node.COMMENT_NODE)return null;const n=e.data.trim(),o=le.exec(n);if(null===o)return null;const r=o[1]||s.commentTextPrefix;return ce.has(r)?(ae.set(e,o[2]),o[2]):null}function ue(e){if(e.nodeType===Node.ELEMENT_NODE){return ie(e.getAttribute(s.bindAttributeName)||"")}if(e.nodeType===Node.COMMENT_NODE){const t=de(e);null===t&&i("Comment node binding text not found.");const n=Is(t);let s=n?.parseBindTextResult??null,o=null;return null===s?(s={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...re(t),bindingType:"text"},o=null):o=t,[{...s,uuid:o}]}return[]}function fe(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(e){if(e.nodeType===Node.ELEMENT_NODE){return e.hasAttribute(s.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==de(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}const pe=new WeakSet;function he(e,t,n){const o=function(e,t,n={}){const o=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,s=L(t);null===s&&i(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${t.tagName.toLowerCase()}> is not a custom element.`);const c=customElements.get(s);if(void 0===c){o||i(`Spread binding "${n.statePathName}" requires <${s}> to be registered. Define the custom element before initializing this binding.`),r.push(n);continue}const l=c.wcBindable;D(l)||i(`Spread binding "${n.statePathName}" requires <${s}> to declare wcBindable (protocol="wc-bindable", version=1).`);const d=n.statePathName,u=n.stateName,f=new Set;for(const e of l.properties){if(f.has(e.name))continue;f.add(e.name);const t=R(e.name,d,u);a.add(t),r.push(t)}for(const e of l.inputs??[]){if(f.has(e.name))continue;f.add(e.name);const t=R(e.name,d,u);a.add(t),r.push(t)}}const c=new Map;for(let e=0;e<r.length;e++){const t=j(r[e]);null!==t&&c.set(t,e)}const l=[];for(let t=0;t<r.length;t++){const n=j(r[t]);if(null!==n){if(c.get(n)===t)l.push(r[t]);else if(s.debug&&a.has(r[t])){const s=r[c.get(n)],o=e.nodeType===Node.ELEMENT_NODE?`<${e.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${r[t].propName}" of ${o} overridden by explicit binding (statePath: "${s.statePathName}").`)}}else l.push(r[t])}return l}(e,t,{allowDeferred:n.allowDeferred});if(o.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?L(e):null;return null===n&&i("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t}}}pe.add(e);const r=function(e,t){const n=[];for(const s of t)if("text"!==s.bindingType)n.push({...s,node:e,replaceNode:e});else{const t=document.createTextNode("");n.push({...s,node:e,replaceNode:t})}return n}(e,o);return z(e,r),function(e){l(e).resolve()}(e),{bindings:r,deferred:null}}function me(e){const t=fe(e),n=[],s=[];for(const e of t){if(pe.has(e))continue;const t=he(e,ue(e),{allowDeferred:!0});null===t.deferred?n.push(...t.bindings):s.push(t.deferred)}return[t,n,s]}function ge(e){const{node:t,parseResults:n}=e;!function(e){pe.delete(e)}(t);return he(t,n,{allowDeferred:!1}).bindings}const be=new WeakMap,ye=new WeakMap;class we{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=Ne(e,t)}}function Ne(e,t){if(null===t){let t=ye.get(e);return void 0!==t||(t=new we(e,null),ye.set(e,t)),t}{let n=be.get(t);void 0===n&&(n=new WeakMap,be.set(t,n));let s=n.get(e);return void 0!==s||(s=new we(e,t),n.set(e,s)),s}}class xe{_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}}class Se extends xe{}function Ae(e){return e instanceof Se}const _e=new WeakMap;function ve(e){let t=e;for(;t;){const e=_e.get(t);if(e)return e;t=t.parentNode}return null}function Ie(e,t){null!==t?_e.set(e,t):_e.delete(e)}const $e=Symbol("$$setLoopContextAsync"),Pe=Symbol("$$setLoopContext"),Te=Symbol("$$getByAddress"),Ee=Symbol("$$setByAddress"),Ce=Symbol("$$connectedCallback"),ke=Symbol("$$disconnectedCallback"),Me=Symbol("$$updatedCallback");const Oe=new Map,We=new Map;const Le=(e,t,n,s)=>o=>{n.includes("prevent")&&o.preventDefault(),n.includes("stop")&&o.stopPropagation();const r=o.target,a=xs(r.getRootNode(),e);null===a&&i(`State element with name "${e}" not found for event handler.`);const c=ve(r),l=t.startsWith(_+".");a.createStateAsync("writable",async n=>{n[Pe](c,()=>{const r=c?.listIndex.indexes??[];if(l){const e=n[Te](Ne(s,null));return Ae(e)||i(`Event binding "${t}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),e.emit(o,...r)}const a=n[t];return"function"!=typeof a&&i(`Handler "${t}" is not a function on state "${e}".`),Reflect.apply(a,n,[o,...r])})})};function De(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=Oe.get(t);void 0===n&&(n=Le(e.stateName,e.statePathName,e.propModifiers,e.statePathInfo),Oe.set(t,n));const s=e.propName.slice(2);e.node.addEventListener(s,n);let o=We.get(t);return void 0===o?(o=new Set([e]),We.set(t,o)):o.add(e),!0}class Re extends xe{}const je=new WeakMap;function Fe(e,t){let n=je.get(e);void 0===n&&(n=new Map,je.set(e,n));let s=n.get(t);return void 0===s&&(s=new Re(t),n.set(t,s)),s}function Be(e){je.delete(e)}const qe=new WeakMap;function ze(e){if("eventToken"!==e.propSegments[0])return!1;const t=e.node,n=L(t);if(null!==n&&void 0===customElements.get(n))return customElements.whenDefined(n).then(()=>{ze(e)}),!0;if(qe.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||i('eventToken binding requires a property name (e.g., "eventToken.error").');const o=function(e){const t=L(e);if(null===t)return null;const n=customElements.get(t),s=n?.wcBindable;return"wc-bindable"===s?.protocol&&1===s?.version?s:null}(t);null===o&&i(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=o.properties.find(e=>e.name===s);void 0===r&&i(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.`);const a=r.event,c=e.statePathName,l=e.stateName,d=e.propModifiers,u=e=>{d.includes("prevent")&&e.preventDefault(),d.includes("stop")&&e.stopPropagation();const n=xs(t.getRootNode(),l);null===n&&i(`State element with name "${l}" not found for eventToken handler.`),n.eventTokenNames.has(c)||i(`eventToken "${c}" is not declared in $eventTokens of state "${l}".`);const s=ve(t);n.createStateAsync("writable",async t=>{t[Pe](s,()=>{const o=s?.listIndex.indexes??[];return Fe(n,c).emit(t,e,...o)})})};return t.addEventListener(a,u),qe.set(e,{eventName:a,handler:u}),!0}const He=new Set(["radio","checkbox"]),Ve=new Set(["value","valueAsNumber","valueAsDate"]);const Ue=new Map,Ge=new Map,Je=e=>e.detail;function Ye(e){const t=L(e.node);if(null!==t){if(void 0===customElements.get(t))return void customElements.whenDefined(t).then(()=>{Ye(e)})}if(function(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,s=n.tagName.toLowerCase();if("input"===s){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(He.has(e)&&"checked"===t)return!0;if(Ve.has(t))return!0}if("select"===s&&"value"===t)return!0;if("textarea"===s&&"value"===t)return!0;const o=L(n);if(null!==o){const e=customElements.get(o);void 0===e&&i(`Custom element <${o}> 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=L(e.node);if(null!==n){const s=customElements.get(n);void 0===s&&i(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const o=s.wcBindable;if("wc-bindable"===o?.protocol&&1===o?.version){const n=o.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=L(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??Je}}}return null}(e),s=function(e,t,n){const s=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.propName}::${e.statePathName}::${t}::${s}::${n?"g":"n"}`}(e,t,null!==n);let o=Ue.get(s);void 0===o&&(o=((e,t,n,s,o)=>r=>{const a=r.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let c;if(null!==o)c=o(r);else{if(!(t in a))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);c=a[t]}let l=c;for(const e of s)l=e.filterFn(l);const d=xs(a.getRootNode(),e);null===d&&i(`State element with name "${e}" not found for two-way binding.`);const u=ve(a);d.createState("writable",e=>{e[Pe](u,()=>{e[n]=l})})})(e.stateName,e.propName,e.statePathName,e.inFilters,n),Ue.set(s,o)),e.node.addEventListener(t,o);let r=Ge.get(s);void 0===r?(r=new Set([e]),Ge.set(s,r)):r.add(e)}}const Ke=new WeakMap;function Xe(e){return Ke.get(e)??[]}function Qe(e,t){Ke.set(e,t)}const Ze=new WeakMap;function et(e,t){if(Ze.has(e)){const n=Ze.get(e);if(n.has(t))return n.get(t)}else Ze.set(e,new WeakMap);const n=Object.freeze(new tt(e,t));return Ze.get(e).set(t,n),n}class tt{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=et(e,t.parentPathInfo)}}const nt=new WeakMap,st=new WeakMap;class ot{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=rt(e,t)}}function rt(e,t){if(null===t){let t=st.get(e);return void 0!==t||(t=new ot(e,null),st.set(e,t)),t}{let n=nt.get(t);void 0===n&&(n=new WeakMap,nt.set(t,n));let s=n.get(e);return void 0!==s||(s=new ot(e,t),n.set(e,s)),s}}const it=new WeakMap;function at(e,t){null===t?it.delete(e):it.set(e,t)}function ct(e){return it.get(e)||null}const lt=new Map;function dt(e,t){let n,s;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,s=t):(n=t,s=e);const o=`${n.path}\t${s.path}`;let r=lt.get(o);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(s.wildcardPathSet).size,lt.set(o,r),r}const ut=new WeakMap;function ft(e){const t=ve(e.node);if(null===t)return null;let n=ut.get(t);if(void 0===n)n=new WeakMap,ut.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let s=null;try{const n=dt(t.pathInfo,e.statePathInfo);return n>0&&(s=t.listIndex.at(n-1)),s}finally{n.set(e,s)}}const pt=new WeakMap;function ht(e){let t=null;if(t=pt.get(e)||null,null!==t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=ct(n);null===t?i(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}const s=ft(e),o=xs(n,e.stateName);null===o&&i(`State element with name "${e.stateName}" not found for binding.`);return t=rt(et(o,e.statePathInfo),s),pt.set(e,t),t}function mt(e){pt.delete(e)}const gt=new WeakMap;function bt(e,t){const n=gt.get(e);return!!n&&!0===n.get(t)}function yt(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const wt=Object.freeze([]);const Nt=new WeakMap;const xt=new WeakMap;function St(e){return xt.get(e)??[]}function At(e,t){xt.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 _t=0;function vt(){return`u${(_t++).toString(36)}`}let It=0;class $t{uuid=vt();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=It}get index(){return this._index}set index(e){this._index=e,this._version=++It,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=It),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 Pt(e,t){return new $t(e,t)}const Tt=new WeakMap;function Et(e){return Tt.get(e)||null}function Ct(e,t){null!==t?Tt.set(e,t):Tt.delete(e)}const kt=new WeakMap,Mt=Object.freeze([]),Ot=new Set;function Wt(e,t,n){const s=Array.isArray(t)&&t.length>0?t:Mt,o=Array.isArray(n)&&n.length>0?n:Mt,r=function(e,t){const n=Array.isArray(e)&&e.length>0?e:Mt,s=Array.isArray(t)&&t.length>0?t:Mt;let o=kt.get(n);return o&&o.get(s)||null}(s,o);if(r)return r;const i=Et(s)||[];let a;try{if(0===o.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:Ot,deleteIndexSet:new Set(i),addIndexSet:Ot};let t=Et(o);if(0===s.length){if(null===t){t=[];for(let n=0;n<o.length;n++){const s=Pt(e,n);t.push(s)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:Ot,deleteIndexSet:Ot,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}(s,o))return a={oldIndexes:i,newIndexes:i,changeIndexSet:Ot,deleteIndexSet:Ot,addIndexSet:Ot};const n=new Map;for(let e=0;e<s.length;e++){const t=s[e];let o=n.get(t);o||(o=[],n.set(t,o)),o.push(e)}if(null!==t)return function(e,t,n,s,o){const r=new Set(s),i=new Set(n),a=new Set,c=r.difference(i),l=i.difference(r);for(let e=0;e<t.length;e++){const s=t[e],r=o.get(s),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:s,changeIndexSet:a,deleteIndexSet:l,addIndexSet:c}}(0,o,i,t,n);t=[];const r=new Set,c=new Set;for(let s=0;s<o.length;s++){const a=o[s],l=n.get(a),d=l&&l.length>0?l.shift():void 0;if(void 0===d){const n=Pt(e,s);t.push(n),c.add(n)}else{const e=i[d];e.index!==s&&(e.index=s,r.add(e)),t.push(e)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(t)),addIndexSet:c}}finally{void 0!==a&&(!function(e,t,n){let s=kt.get(e);s||(s=new WeakMap,kt.set(e,s)),s.set(t,n)}(s,o,a),Ct(o,a.newIndexes))}}const Lt=new WeakMap;function Dt(e){let t=null;return t=Lt.get(e)||null,null===t&&(t=new Set,Lt.set(e,t)),t}function Rt(e,t){Dt(e).add(t)}function jt(e,t){Dt(e).delete(t)}const Ft=new WeakMap;function Bt(e){Ft.delete(e)}const qt=new WeakMap;function zt(e){return qt.get(e)??[]}function Ht(e,t){qt.set(e,t)}const Vt=new WeakMap;function Ut(e){return Vt.get(e)??[]}function Gt(e,t){Vt.set(e,t)}function Jt(e,t){const n=Ut(e);for(const e of n)Ie(e,t)}function Yt(e,t,n){Jt(e,t);const s=zt(e);for(const e of s){Rt(ht(e),e),Mn(e,n)}}function Kt(e){if(!e.mounted)return;const t=zt(e);for(const e of t){jt(ht(e),e),mt(e),Bt(e)}!function(e){const t=Ut(e);for(const e of t)Ie(e,null)}(e)}const Xt=new WeakMap,Qt=Object.freeze(new Set);function Zt(e,t){const n=Xt.get(e);n?n.add(t):Xt.set(e,new Set([t]))}function en(e){const t=Xt.get(e);return void 0!==t?t:Qt}const tn=new Set(["if","elseif","else","for"]);class nn{_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=zt(this);for(const t of e){if(tn.has(t.bindingType)){const e=en(t.node);for(const t of e)t.unmount()}Bt(t),mt(t)}this._mounted=!1}}function sn(e){const t=document.createDocumentFragment(),n=new nn(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 on(e){void 0!==e.uuid&&null!==e.uuid||i("BindingInfo.uuid is null.");const t=Is(e.uuid);t||i(`Fragment with UUID "${e.uuid}" not found.`);const n=document.importNode(t.fragment,!0),s=function(e,t){const[n,s]=function(e,t){const n=[],s=[];for(const o of t){const t=F(e,o.nodePath);if(null===t&&i(`Node not found by path [${o.nodePath.join(", ")}] in fragment.`),pe.has(t))continue;const r=he(t,o.parseBindTextResults,{allowDeferred:!1});s.push(...r.bindings),n.push(t)}return[n,s]}(e,t);return zn(s),{nodes:n,bindingInfos:s}}(n,t.nodeInfos),o=new nn(n);Ht(o,s.bindingInfos);const r=[];for(const e of s.bindingInfos)e.statePathName in b&&r.push(e);return At(o,r),Gt(o,s.nodes),Zt(e.node,o),o}const rn=new WeakMap,an=new WeakMap,cn=new WeakMap,ln=new WeakMap;function dn(e,t,n){mn(e,t,n)}function un(e,t){rn.set(e,t)}function fn(e){return cn.get(e.node)||[]}function pn(e,t){const n=cn.get(e.node);void 0===n?cn.set(e.node,[t]):n.push(t)}function hn(e,t){let n=an.get(e);if(void 0===n)return null;const s=n.get(t);return void 0===s?null:s}function mn(e,t,n){let s=an.get(e);if(void 0===s){if(null===n)return;s=new WeakMap,an.set(e,s)}null===n?s.delete(t):s.set(t,n)}const gn=new WeakMap;function bn(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function yn(e,n,o){const r=e.node.isConnected,i=Boolean(o);let a;const c=en(e.node);a=0===c.size?on(e):c.values().next().value;const l=t(),d=e.uuid??"",u=e.bindingType;try{if(i||(s.debug&&console.log(`unmount if content : ${bn(e)}`),Kt(a),a.unmount()),i){if(s.debug&&console.log(`mount if content : ${bn(e)}`),l){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}`),s=a.lastNode??t;s.parentNode.insertBefore(n,s.nextSibling)}else a.mountAfter(e.node);Yt(a,ve(e.node),n)}}finally{gn.set(e.node,r)}}const wn=new WeakMap;function Nn(e){return wn.get(e)??[]}const xn=new Set;const Sn={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"),s=Number(t);for(let e=0;e<n.length;e++)e===s?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function An(e,n,o){if(void 0===o)return void(s.debug&&console.debug("Skipped property write: state value is undefined.",{element:e.node,propSegments:e.propSegments,statePathName:e.statePathName}));const r=e.node,i=e.propSegments;if(1===i.length){const e=i[0];if(r[e]!==o){let t=!1;try{r[e]=o,t=!0}catch(t){s.debug&&console.warn(`Failed to set property '${e}' on element.`,{element:r,newValue:o,error:t})}if(t){const t=function(e,t){const n=L(e);if(null===n)return null;const s=customElements.get(n);if(void 0===s)return null;const o=s.wcBindable;if("wc-bindable"!==o?.protocol||1!==o?.version)return null;const r=o.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 s;if("object"==typeof n)try{s=JSON.stringify(n)}catch{s=String(n)}else s=String(n);e.setAttribute(t,s)}(r,t,o)}catch(e){s.debug&&console.warn(`Failed to mirror attribute '${t}' on element.`,{element:r,newValue:o,error:e})}}}if(t()){const t=Sn[e];t?t(r,o):(!function(e,t,n){let s=wn.get(e);s||(s=[],wn.set(e,s));const o=s.find(e=>e.propName===t);o?o.value=n:s.push({propName:t,value:n})}(r,e,o),a=r,xn.add(a))}return}var a;let c=r[i[0]];for(let e=1;e<i.length-1;e++){const t=i[e];if(null==c)return;c=c[t]}const l=c[i[i.length-1]];if(l!==o){if(Object.isFrozen(c))return void(s.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:i,oldValue:l,newValue:o}));try{c[i[i.length-1]]=o}catch(e){s.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:l,newValue:o,error:e})}}}const _n=new WeakSet;function vn(e,t,n){const s=e.node,o=e.propSegments;o.length<=1&&i(`Invalid propSegments for web component binding: ${o.join(".")}`);const[r,...a]=o,c=s[r];void 0===c&&i(`Property "${r}" not found on web component.`),c[a.join(".")]=n}function In(e,t){const n=function(e){let t=null;if(t=Ft.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=ft(e);null===n&&i(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=Ne(e.statePathInfo,n)}else t=Ne(e.statePathInfo,null);return Ft.set(e,t),t}(t);if(n.pathInfo.path in b){const e=ve(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=b[t];void 0===n&&i(`Invalid index name: ${t}`);const s=e.listIndex.at(n);return null===s&&i(`Index not found at position ${n} for loopContext:`),s.index}(e,n.pathInfo.path)}return e[Te](n)}const $n=new WeakSet;const Pn={class:function(e,t,n){const s=e.node,o=e.propSegments[1];"boolean"!=typeof n&&i("Invalid value for class application: expected boolean, got "+typeof n),s.classList.toggle(o,n)},attr:function(e,t,n){const s=e.node,o=e.propSegments[1];s.getAttribute(o)!==n&&s.setAttribute(o,n)},style:function(e,t,n){const s=e.propSegments[1],o=e.node.style;o[s]!==n&&(o[s]=n)},command:function(e,t,n){Ae(n)||i("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const s=n,o=Nt.get(e);if(o&&o.token===s)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 c=function(e){const t=L(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 s=n.wcBindable;return"wc-bindable"===s?.protocol&&1===s?.version?s:null}(r);null===c&&i(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),Array.isArray(c.commands)&&c.commands.some(e=>e.name===a)||i(`Command "${a}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),o&&(o.unsubscribe(),Nt.delete(e));const l=new WeakRef(r);let d=null;d=s.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return d?.(),void Nt.delete(e);const s=n[a];return"function"!=typeof s&&i(`Method "${a}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(s,n,t)}),Nt.set(e,{token:s,unsubscribe:d,elementRef:l})}},Tn={text:function(e,n,s){if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),t()&&!_n.has(e.replaceNode)){_n.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,s=document.createComment(`@@wcs-text-start:${n}`),o=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(s,e.replaceNode),t.insertBefore(o,e.replaceNode.nextSibling)}}},for:function(e,n,s){const o=e.statePathInfo,r=ft(e),a=ht(e),c=Xe(a),l=Wt(r,c,s);if(n.newListValueByAbsAddress.set(a,Array.isArray(s)?s:[]),Array.isArray(c)&&c.length===l.deleteIndexSet.size&&l.deleteIndexSet.size>0&&null!==e.node.parentNode){let t=ln.get(e.node);if(void 0===t){const n=rn.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,s=t.nextSibling,o=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){o=!1;break}n=n.previousSibling}for(;null!==s;){if(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE&&""!==(s.textContent?.trim()??"")){o=!1;break}s=s.nextSibling}return o}(e.node,n),ln.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}for(const t of l.deleteIndexSet){const n=hn(e.node,t);null!==n&&(Kt(n),n.unmount(),pn(e,n),mn(e.node,t,null))}let d=e.node;const u=M(o.path+"."+p),f=n.stateElement.loopContextStack;let h=null;l.newIndexes.length==l.addIndexSet.size&&l.newIndexes.length>0&&d.isConnected&&(h=document.createDocumentFragment(),at(h,n.rootNode));const m=t(),g=e.uuid??"";for(const t of l.newIndexes){let s;if(l.addIndexSet.has(t)){const r=Ne(u,t);f.createLoopContext(r,r=>{const i=fn(e);if(s=i.pop(),void 0===s&&(s=on(e)),null!==h)m&&h.appendChild(document.createComment(`@@wcs-for-start:${g}:${o.path}:${t.index}`)),s.appendTo(h),m&&h.appendChild(document.createComment(`@@wcs-for-end:${g}:${o.path}:${t.index}`));else{if(d.nextSibling!==s.firstNode){if(m){const e=document.createComment(`@@wcs-for-start:${g}:${o.path}:${t.index}`);d.parentNode.insertBefore(e,d.nextSibling),d=e}s.mountAfter(d)}if(m){const e=document.createComment(`@@wcs-for-end:${g}:${o.path}:${t.index}`),n=s.lastNode??d;n.parentNode.insertBefore(e,n.nextSibling)}}Yt(s,r,n)}),void 0===s&&i(`Content not found for ListIndex: ${t.index} at path "${o.path}"`)}else{if(s=hn(e.node,t),l.changeIndexSet.has(t)){const e=St(s);for(const t of e)Mn(t,n)}null===s&&i(`Content not found for ListIndex: ${t.index} at path "${o.path}"`),d.nextSibling!==s.firstNode&&s.mountAfter(d)}d=s.lastNode||d,mn(e.node,t,s)}rn.set(e.node,d),null!==h&&(e.node.parentNode.insertBefore(h,e.node.nextSibling),at(h,null))},if:yn,else:yn,elseif:yn,radio:function(e,t,n){const s=e.node,o=yt(s.value,e.inFilters);s.checked=n===o},checkbox:function(e,t,n){const s=e.node,o=yt(s.value,e.inFilters),r=Array.isArray(n)?n:wt;s.checked=r.includes(o)}},En=new WeakMap,Cn=new WeakMap;function kn(e,t){const n=yt(In(t.state,e),e.outFilters);if(!0===Cn.get(e))return void t.deferredSelectBindings.push({binding:e,value:n});let s=En.get(e);if(void 0===s){if(En.has(e))return bt(e.replaceNode,t.stateElement)?(s=vn,En.set(e,s)):s=An,void s(e,t,n);if(s=Tn[e.bindingType],void 0===s){const n=e.propSegments[0];if(s=Pn[n],En.set(e,s),void 0===s){L(e.replaceNode)?bt(e.replaceNode,t.stateElement)?(s=vn,En.set(e,s)):s=An:(s=An,En.set(e,s))}}if(s===An){if("SELECT"===e.node.tagName){const s=e.propSegments[0];if("value"===s||"selectedIndex"===s)return t.deferredSelectBindings.push({binding:e,value:n}),void Cn.set(e,!0)}}s(e,t,n)}else s(e,t,n)}function Mn(e,t){if(t.appliedBindingSet.has(e))return;t.appliedBindingSet.add(e);const n=ht(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 s=L(e.replaceNode);if(s&&void 0===customElements.get(s))return void function(e,t){$n.has(e)||($n.add(e),customElements.whenDefined(t).then(()=>{$n.delete(e),e.replaceNode.isConnected&&On([e])}).catch(e=>{console.error(`[@wcstack/state] deferred apply failed for <${t}>.`,e)}))}(e,s);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=ct(o),null===o&&i("Root node for fragment not found for binding.")),e.stateName!==t.stateName||o!==t.rootNode){const n=xs(o,e.stateName);null===n&&i(`State element with name "${e.stateName}" not found for binding.`),n.createState("readonly",s=>{const r={stateName:e.stateName,rootNode:o,stateElement:n,state:s,appliedBindingSet:t.appliedBindingSet,newListValueByAbsAddress:t.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:t.updatedAbsAddressSetByStateElement,deferredSelectBindings:t.deferredSelectBindings};kn(e,r)})}else kn(e,t)}function On(e){let t=0;const n=new Set,o=new Map,r=new Map,a=[];for(;t<e.length;){let c=e[t];const l=c.stateName;if(!1===c.replaceNode.isConnected){s.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${c.bindingType} ${c.statePathName} on ${c.node.nodeName}`,c),t++;continue}let d=c.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=ct(d),null===d&&i("Root node for fragment not found for binding."));const u=xs(d,l);null===u&&i(`State element with name "${l}" not found for binding.`),u.createState("readonly",s=>{const i={rootNode:d,stateName:l,stateElement:u,state:s,appliedBindingSet:n,newListValueByAbsAddress:o,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:a};for(;;){Mn(c,i),t++;const n=e[t];if(!n)break;const s=n.replaceNode.getRootNode();if(n.stateName!==l||s!==i.rootNode)break;c=n}})}for(const{binding:e,value:t}of a)An(e,0,t);for(const[e,t]of o.entries())Qe(e,t);for(const[e,t]of r.entries())e.createState("writable",e=>{e[Me](Array.from(t))})}const Wn=new Map,Ln=new Map;const Dn=(e,t,n)=>s=>{const o=s.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==o.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===o.checked)return;let r=o.value;for(const e of n)r=e.filterFn(r);const a=xs(o.getRootNode(),e);null===a&&i(`State element with name "${e}" not found for two-way binding.`);const c=ve(o);a.createState("writable",e=>{e[Pe](c,()=>{e[t]=r})})};function Rn(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 s=Wn.get(n);void 0===s&&(s=Dn(e.stateName,e.statePathName,e.inFilters),Wn.set(n,s)),e.node.addEventListener(t,s);let o=Ln.get(n);return void 0===o?(o=new Set([e]),Ln.set(n,o)):o.add(e),!0}return!1}const jn=new Map,Fn=new Map;const Bn=(e,t,n)=>s=>{const o=s.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==o.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=o.checked;let a=o.value;for(const e of n)a=e.filterFn(a);const c=xs(o.getRootNode(),e);null===c&&i(`State element with name "${e}" not found for two-way binding.`);const l=ve(o);c.createState("writable",e=>{e[Pe](l,()=>{let n=e[t];if(Array.isArray(n))if(r)-1===n.indexOf(a)&&(e[t]=n.concat(a));else{const s=n.indexOf(a);-1!==s&&(e[t]=n.toSpliced(s,1))}else e[t]=r?[a]:[]})})};function qn(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 s=jn.get(n);void 0===s&&(s=Bn(e.stateName,e.statePathName,e.inFilters),jn.set(n,s)),e.node.addEventListener(t,s);let o=Fn.get(n);return void 0===o?(o=new Set([e]),Fn.set(n,o)):o.add(e),!0}return!1}function zn(e){for(const t of e)u(t),De(t)||ze(t)||(Ye(t),Rn(t),qn(t))}function Hn(e){for(const t of e){Rt(ht(t),t);const e=xs(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 Vn(e,t){const[n,s,o]=me(e);for(const e of n)Ie(e,t);zn(s),Hn(s),On(s),function(e,t){for(const n of e)customElements.whenDefined(n.tagName).then(()=>{if(!n.node.isConnected)return;const e=ge(n);0!==e.length&&(Ie(n.node,t),zn(e),Hn(e),On(e))}).catch(e=>{console.error(`[@wcstack/state] deferred spread failed for <${n.tagName}>.`,e)})}(o,t)}const Un=/\{\{\s*(.+?)\s*\}\}/g,Gn=new Set(["SCRIPT","STYLE"]);function Jn(e){if(!s.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&&Gn.has(e.parentElement.tagName)||Yn(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 s=n[e];t.content.appendChild(s)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),Jn(t.content)}else Jn(e.content)}function Yn(e){const t=e.data;if(Un.lastIndex=0,!Un.test(t))return;Un.lastIndex=0;const n=document.createDocumentFragment();let s,o=0;for(;null!==(s=Un.exec(t));){s.index>o&&n.appendChild(document.createTextNode(t.slice(o,s.index)));const e=s[1];n.appendChild(document.createComment(`@@: ${e}`)),o=s.index+s[0].length}o<t.length&&n.appendChild(document.createTextNode(t.slice(o))),e.parentNode.replaceChild(n,e)}let Kn;function Xn(){if(Kn)return Kn;const e=[],t=Z("not",e)(X);return Kn={filterName:"not",args:e,filterFn:t},Kn}const Qn=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Zn(e,t){const n=t+f+p,s=e.indexOf("|"),o=e.indexOf("@");let r,i;if(-1!==s?(r=e.slice(0,s).trim(),i=e.slice(s)):-1!==o?(r=e.slice(0,o).trim(),i=e.slice(o)):(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 es(e,t){const n=Qn.exec(e);if(null===n)return e;const s=n[1],o=n[2],r=n[3];return s+Zn(o,t)+r}function ts(e,t){const n=e.split(";");let s=!1;const o=n.map(e=>{const n=e.trim();if(0===n.length)return e;const o=n.indexOf(":");if(-1===o)return e;const r=n.slice(0,o).trim(),i=n.slice(o+1).trim(),a=Zn(i,t);return a!==i?(s=!0,`${r}: ${a}`):e});return s?o.join(";"):e}function ns(e,t){return ts(e,t)}function ss(e,t){const n=s.bindAttributeName,o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;o.nextNode();){const e=o.currentNode;if(e.nodeType===Node.COMMENT_NODE){const n=e;n.data=es(n.data,t);continue}const s=e;if(s instanceof HTMLTemplateElement)continue;const r=s.getAttribute(n);if(null!==r){const e=ts(r,t);e!==r&&s.setAttribute(n,e)}}}function os(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 rs(e){const t=[],n=fe(e);for(const e of n){const n=ue(e);t.push({nodePath:os(e),parseBindTextResults:n})}return t}function is(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 as=new Map([["for",s.commentForPrefix],["if",s.commentIfPrefix],["elseif",s.commentElseIfPrefix],["else",s.commentElsePrefix]]),cs=Xn();function ls(e,t){const n=t.outFilters;return{...t,outFilters:[...n,cs],bindingType:e}}function ds(e,t,n,s){is(t),"string"==typeof s&&ss(t,s),us(e,t,s);return{fragment:t,parseBindTextResult:n,nodeInfos:rs(t)}}function us(e,t,n){const o=s.commentElsePrefix,r=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode(e){const t=e;if("template"===t.tagName.toLowerCase()){if((t.getAttribute(s.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let a=null;const c=[],l=[];for(;r.nextNode();){const e=r.currentNode;l.push(e)}for(const t of l){let r=t.getAttribute(s.bindAttributeName)||"";"string"==typeof n&&(r=ns(r,n));let l=ie(r)[0];const d=as.get(l.bindingType);if(void 0===d)continue;const u=l.bindingType,f=t.content,p=vt();let h=null;const m="for"===u?l.statePathName:n;if("else"===u){null===a&&i("'else' binding found without preceding 'if' or 'elseif' binding."),l=ls("else",a.parseBindTextResult),h=ds(e,f,l,m),vs(p,e,h);const n=c.at(-1),s=document.createComment(`@@${d}:${p}`);void 0!==n?(t.remove(),n.fragment.appendChild(s),n.nodeInfos.push({nodePath:os(s),parseBindTextResults:ue(s)})):t.replaceWith(s)}else if("elseif"===u){null===a&&i("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=ds(e,f,l,m),vs(p,e,h);const n=document.createComment(`@@${d}:${p}`),s=vt(),r={fragment:document.createDocumentFragment(),parseBindTextResult:ls("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:os(n),parseBindTextResults:ue(n)}),vs(s,e,r);const u=c.at(-1);c.push(r);const g=document.createComment(`@@${o}:${s}`);void 0!==u?(t.remove(),u.fragment.appendChild(g),u.nodeInfos.push({nodePath:os(g),parseBindTextResults:ue(g)})):t.replaceWith(g)}else{h=ds(e,f,l,m),vs(p,e,h);const n=document.createComment(`@@${d}:${p}`);t.replaceWith(n)}"if"===u?(c.length=0,a=h):"elseif"===u?a=h:"else"===u&&(a=null,c.length=0)}}async function fs(e){const t=e.querySelectorAll(s.tagNames.state),n=[];await customElements.whenDefined(s.tagNames.state);for(const e of t){const t=e;n.push(t.initializePromise)}await Promise.all(n)}async function ps(e){if(e===document)await fs(document),Jn(document),us(document,document),Vn(document.body,null);else{const t=e;t.host.hasAttribute(s.bindAttributeName)&&await d(t.host),await fs(t),Jn(t),us(t,t),Vn(t,null)}}const hs=new Set(["for","if","elseif","else"]);function ms(e){if(0===e.length)return{bindingInfos:[],subscriberNodes:[]};const t=e[0].parentNode,n=e[e.length-1].nextSibling,s=document.createElement("div");for(const t of e)s.appendChild(t);const[o,r]=me(s);for(const e of r)u(e),De(e)||ze(e)||(Ye(e),Rn(e),qn(e));if(t)for(;s.firstChild;)t.insertBefore(s.firstChild,n);return{bindingInfos:r,subscriberNodes:o}}function gs(e,t,n){const o={for:s.commentForPrefix,if:s.commentIfPrefix,elseif:s.commentElseIfPrefix,else:s.commentElsePrefix}[t];if(!o)return null;const r=`@@${o}:${n}`,i=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const e=i.currentNode;if(e.data===r)return e}return null}function bs(e,t){const n=e;let o=null;for(const[e,r]of t.templates){let t=ie(r.getAttribute(s.bindAttributeName)||"")[0];const i=t.bindingType;"else"===i&&o?t={...o,outFilters:[...o.outFilters,Xn()],bindingType:"else"}:"elseif"===i&&o&&(t={...t,stateName:o.stateName}),"if"===i||"elseif"===i?o=t:"else"===i&&(o=null);const a=document.importNode(r.content,!0),c="for"===i?t.statePathName:void 0;is(a),"string"==typeof c&&ss(a,c),us(n,a,c);vs(e,n,{fragment:a,parseBindTextResult:t,nodeInfos:rs(a)})}}async function ys(e){await fs(e);const t=e.querySelectorAll(s.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.`),ks.cleanupDom(e),!1}for(const n of t)bs(e,n);const n=function(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),s=[];for(;n.nextNode();)s.push(n.currentNode);for(const e of s){const n=Ps.exec(e.data);if(!n)continue;const s=n[1],o=n[2],r=o.split(":");let i,a,c=null;"for"===s?(i=r[0],a=r[1],c=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const l=[];let d=e.nextSibling;const u=`@@wcs-${s}-end:${o}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)l.push(d),d=d.nextSibling;t.push({type:s,uuid:i,path:a,index:c,nodes:l})}return t}(document.body);!function(e,t){const n=new Map;for(const s of t){if(0===s.nodes.length)continue;const t=sn(s.nodes),{bindingInfos:o,subscriberNodes:r}=ms(s.nodes);for(const e of r)e.nodeType===Node.ELEMENT_NODE&&e.setAttribute("data-wcs-completed","");Ht(t,o),Gt(t,r);const i=[];for(const e of o)e.statePathName in b&&i.push(e);if(At(t,i),"for"===s.type&&null!==s.index){const r=gs(e,"for",s.uuid);if(r){const e=Pt(null,s.index);dn(r,e,t),un(r,s.nodes[s.nodes.length-1]),Zt(r,t),Jt(t,Ne(M(s.path+"."+p),e));for(const e of o)Rt(ht(e),e);let i=n.get(s.uuid);i||(i=[],n.set(s.uuid,i)),i.push(e)}}else{const n=gs(e,s.type,s.uuid);if(n){Zt(n,t);for(const e of o)Rt(ht(e),e)}}}for(const[t,s]of n){const n=gs(e,"for",t);if(!n)continue;const o=n.getRootNode(),r=Is(t);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,c=xs(o,i);c&&c.createState("readonly",e=>{const t=e[a];Array.isArray(t)&&Ct(t,s)})}}(document.body,n),ks.removeBlockBoundaryComments(document.body);const o=[];for(const e of t)e.parentNode&&(o.push({el:e,parent:e.parentNode,next:e.nextSibling}),e.remove());ks.restoreTextBindings(document.body);const[a,c]=me(document.body);for(const e of a)if(e.nodeType===Node.ELEMENT_NODE){const t=e;t.hasAttribute("data-wcs-completed")||(Ie(e,null),t.setAttribute("data-wcs-completed",""))}else Ie(e,null);const l=[],d=[];for(const e of c)if(u(e),!De(e)&&!ze(e))if(Ye(e),Rn(e),qn(e),hs.has(e.bindingType))d.push(e);else{if(e.statePathName.includes(p))continue;l.push(e)}for(const e of[...l,...d]){Rt(ht(e),e);const t=xs(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=ht(e),n=xs(e.replaceNode.getRootNode(),e.stateName);n&&n.createState("readonly",n=>{const s=n[e.statePathName];Array.isArray(s)&&Qe(t,s)})}On(l);for(const{el:e,parent:t,next:n}of o)t.insertBefore(e,n);const f=e.querySelectorAll(s.tagNames.ssr);for(const t of f){const n=t.hydrateProps;for(const[t,s]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[e,t]of Object.entries(s))n[e]=t}}const h=e.querySelectorAll("[data-wcs-completed]");for(const e of h)e.removeAttribute("data-wcs-completed");return!0}const ws=new WeakMap,Ns=new WeakMap;function xs(e,t){let n=ws.get(e);return n&&n.get(t)||null}function Ss(e){return Ns.get(e)??Promise.resolve()}function As(e,n,o){let r=ws.get(e);if(null===o){if(!r)return;r.delete(n),0===r.size&&ws.delete(e),s.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,ws.set(e,r);const n=!t()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise(t=>{queueMicrotask(async()=>{if(n){await ys(e)||await ps(e)}else await ps(e);t()})});Ns.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise(t=>{queueMicrotask(async()=>{await ps(e),t()})});Ns.set(e,t)}}r.has(n)&&i(`State element with name "${n}" is already registered.`),r.set(n,o),s.debug&&console.debug(`State element registered: name="${n}"`,o)}}const _s=new Map;function vs(e,t,n){if(null===n)_s.delete(e);else{_s.set(e,n);const s=n.parseBindTextResult,o=xs(t,s.stateName);null===o&&i(`State element with name "${s.stateName}" not found for fragment info.`),o.setPathInfo(s.statePathName,s.bindingType);for(const e of n.nodeInfos)for(const n of e.parseBindTextResults){const e=xs(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 Is(e){return _s.get(e)||null}const $s=/^@@wcs-(?:for|if|elseif|else):[^-]/,Ps=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,Ts=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,Es=/^@@wcs-text-start:(.+)$/;function Cs(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class ks 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=s.tagNames.ssr,o=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!o)return null;return o.querySelector(`${n}[name="${t}"]`)}static extractStateData(e){const t=e.__state;if(!t||"object"!=typeof t)return{};const n={};for(const[e,s]of Object.entries(t))e.startsWith("$")||"function"==typeof s||(n[e]=s);return n}static buildContent(e,t){const n=document.createElement("script");n.setAttribute("type","application/json"),n.textContent=Cs(JSON.stringify(t)),e.appendChild(n);const o=Array.from(_s.keys());for(const t of o){const n=Is(t);if(!n)continue;const o=document.createElement("template");o.setAttribute("id",t);const r=n.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;o.setAttribute(s.bindAttributeName,i);const a=n.fragment.cloneNode(!0);o.content.appendChild(a),e.appendChild(o)}const r=Array.from(xn);if(r.length>0){const t={};for(let e=0;e<r.length;e++){const n=r[e],s=Nn(n);if(0===s.length)continue;const o=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",o);const i={};for(const e of s)i[e.propName]=e.value;t[o]=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=Cs(JSON.stringify(t)),e.appendChild(n)}}xn.clear()}static removeBlockBoundaryComments(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode;(Ps.test(e.data)||Ts.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;$s.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,s=Es.exec(e.data);s&&n.push({comment:e,path:s[1]})}for(const{comment:e,path:t}of n){const n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let s=e.nextSibling;e.remove();const o=`@@wcs-text-end:${t}`;for(;s;){const e=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===o){s.parentNode.removeChild(s);break}s.parentNode.removeChild(s),s=e}}}static cleanupDom(e){const t=document.body,n=e.querySelectorAll(s.tagNames.ssr),o=new Map;for(const e of n){const t=e.querySelectorAll("template[id]");for(const e of t){const t=e.getAttribute("id");t&&o.set(t,e)}}const r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const e=r.currentNode;Ps.test(e.data)&&i.push(e)}for(const e of i){const t=Ps.exec(e.data),n=`@@wcs-${t[1]}-end:${t[2]}`;let s=e.nextSibling;for(;s;){const e=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===n){s.remove();break}s.remove(),s=e}e.remove()}ks.restoreTextBindings(t);const a=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),c=[];for(;a.nextNode();){const e=a.currentNode;if($s.test(e.data)){const t=e.data.split(":")[1];c.push({comment:e,uuid:t})}}for(const{comment:e,uuid:t}of c){const n=o.get(t);if(n){const t=document.createElement("template"),o=n.getAttribute(s.bindAttributeName);o&&t.setAttribute(s.bindAttributeName,o);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 l=e.querySelectorAll("[data-wcs-ssr-id]");for(const e of l)e.removeAttribute("data-wcs-ssr-id");for(const e of n)e.remove()}}async function Ms(e,t){let n=null;const s=`\n//# sourceURL=${t}\n`;if("function"==typeof URL.createObjectURL){const t=new Blob([e.text+s],{type:"application/javascript"}),o=URL.createObjectURL(t);try{n=await import(o)}finally{URL.revokeObjectURL(o)}}else{const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(e.text+s)));n=await import(`data:application/javascript;base64,${t}`)}return n&&"object"==typeof n.default?n.default:{}}async function Os(e){try{return(await import(e)).default||{}}catch(e){i(`Failed to load script file: ${e}`)}}class Ws{_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 s=this._loopContextStack[this._length-1];if(void 0!==s){s.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];s.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 o;this._loopContextStack[this._length]=n,this._length++;try{o=t(n)}finally{o instanceof Promise?o.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return o}}const Ls=new WeakMap;function Ds(e,t){let n=Ls.get(e);void 0===n&&(n=new Map,Ls.set(e,n));let s=n.get(t);return void 0===s&&(s=new Se(t),n.set(t,s)),s}const Rs=new WeakMap;function js(e){const t=Rs.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 Ds(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:Ds(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 Rs.set(e,n),n}const Fs=Symbol("wcs-stream-last-notified-uncertain"),Bs=new WeakMap;function qs(e,t){const n=Bs.get(e);if(void 0!==n)for(const e of n.keys())t.has(e)||n.delete(e)}function zs(e,t){const n=Bs.get(e);if(void 0===n)return;const s=n.get(t);void 0!==s&&n.set(t,{status:"idle"===s.status?s.status:Fs,error:Object.is(s.error,null)?null:Fs})}const Hs=new Set;function Vs(e){Hs.delete(e)}function Us(){return Hs}const Gs=new WeakMap;function Js(e){return Gs.get(e)??new Map}function Ys(e){Vs(e);const t=Gs.get(e);if(void 0!==t)for(const n of t.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,zs(e,n.name)}const Ks=(e,t)=>t,Xs=new Set;function Qs(e,t){const n=t[$];if(void 0===n)return void qs(e,Xs);"object"==typeof n&&null!==n||i(`${$} must be an object mapping stream names to stream definitions.`);const s=new Map;for(const[o,r]of Object.entries(n)){0===o.length&&i(`${$} entry name must be a non-empty string.`),o.includes(f)&&i(`${$} entry "${o}" must be a flat property name ("${f}" is not allowed).`),o.includes(p)&&i(`${$} entry "${o}" must be a flat property name ("${p}" is not allowed).`),o.startsWith("$")&&i(`${$} entry "${o}" must not start with "$" (reserved namespace).`),o in Object.prototype&&i(`${$} entry "${o}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),e.getterPaths.has(o)&&i(`${$} entry "${o}" conflicts with a getter declared on the state.`),e.setterPaths.has(o)&&i(`${$} entry "${o}" conflicts with a setter declared on the state.`),"object"==typeof r&&null!==r||i(`${$} entry "${o}" must be an object ({ args?, source, fold?, initial? }).`);const n=r;"function"!=typeof n.source&&i(`${$} entry "${o}" source must be a function.`);const a=void 0!==n.fold;a&&"function"!=typeof n.fold&&i(`${$} entry "${o}" fold must be a function.`),a&&!("initial"in n)&&i(`${$} entry "${o}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&i(`${$} entry "${o}" args must be a function.`);const c={name:o,definition:{args:n.args??null,source:n.source,fold:n.fold??Ks,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};o in t||(t[o]=c.definition.initial),s.set(o,c)}!function(e,t){Gs.set(e,t)}(e,s),qs(e,new Set(s.keys()))}const Zs=new WeakMap,eo=new WeakMap;function to(e,t,n){return new Proxy(Object.create(null),{get(t,s){if("string"!=typeof s)return;const o=Js(e).get(s);return void 0!==o?n(o):void 0},has:(t,n)=>"string"==typeof n&&Js(e).has(n),ownKeys:()=>Array.from(Js(e).keys()),getOwnPropertyDescriptor(t,s){if("string"!=typeof s)return;const o=Js(e).get(s);return void 0!==o?{configurable:!0,enumerable:!0,value:n(o)}:void 0},set(){i(`${t} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){i(`${t} namespace is read-only; deleting from it is not allowed.`)}})}function no(e){const t=Zs.get(e);if(void 0!==t)return t;const n=to(e,P,e=>e.status);return Zs.set(e,n),n}function so(e){const t=eo.get(e);if(void 0!==t)return t;const n=to(e,T,e=>e.error);return eo.set(e,n),n}function oo(e){Zs.delete(e),eo.delete(e)}const ro=new Set;const io=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=Dt(e);for(const e of t)!1!==e.replaceNode.isConnected&&n.push(e)}On(n),function(e){for(const t of ro)t(e)}(t)}};function ao(){return io}let co=null;async function lo(e,t,n,s){let o=null,r=null;const i=()=>{if(o&&o!==r){r=o;try{o.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",i,{once:!0});try{const r=await e(t,n);if(o=function(e,t){if("function"==typeof e?.[Symbol.asyncIterator])return e;if("function"!=typeof e?.getReader)throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).");return async function*(e,t){const n=e.getReader(),s=()=>{n.cancel().catch(()=>{})};t.addEventListener("abort",s,{once:!0});try{for(;;){const{done:e,value:t}=await n.read();if(e)return;yield t}}finally{t.removeEventListener("abort",s),n.releaseLock()}}(e,t)}(r,n)[Symbol.asyncIterator](),n.aborted)return void i();for(;;){const e=await o.next();if(e.done)break;if(n.aborted)return;s.fold(e.value)}if(n.aborted)return;s.done()}catch(e){if(n.aborted)return;s.fail(e)}finally{n.removeEventListener("abort",i)}}function uo(e){const t=Js(e);if(0!==t.size){!function(e){Hs.add(e)}(e);for(const n of t.values())fo(e,n)}}function fo(e,t){t.controller?.abort();const n=new AbortController;t.controller=n;const s=function(e,t){const n=t.definition.args;if(null===n)return void t.depAddresses.clear();const s=co,o=new Set;let r;co=o;try{e.createState("readonly",e=>{r=n(e)})}finally{co=s}r instanceof Promise&&i(`${$} entry "${t.name}" args must be synchronous (it returned a Promise).`);const a=`${P}${f}${t.name}`,c=`${T}${f}${t.name}`;for(const n of o){const s=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==e||s.path!==t.name&&s.path!==a&&s.path!==c||i(`${$} entry "${t.name}" args must not read the stream itself ("${s.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),s.wildcardCount>0&&i(`${$} entry "${t.name}" args must not read wildcard paths ("${s.path}"): wildcard dependencies are out of scope.`)}return t.depAddresses=o,r}(e,t);e.createState("writable",e=>{e[t.name]=t.definition.initial}),po(e,t,"active",null);const o=t.definition,r={fold(n){e.createState("writable",e=>{e[t.name]=o.fold(e[t.name],n)})},done(){po(e,t,"done",null)},fail(s){po(e,t,"error",s),n.abort()}};lo(o.source,s,n.signal,r)}function po(e,t,n,s){t.status=n,t.error=s;const o=function(e,t){return Bs.get(e)?.get(t)??{status:"idle",error:null}}(e,t.name),r=o.status!==n,i=!Object.is(o.error,s);(r||i)&&(!function(e,t,n,s){let o=Bs.get(e);void 0===o&&(o=new Map,Bs.set(e,o)),o.set(t,{status:n,error:s})}(e,t.name,n,s),e.createState("writable",e=>{r&&e.$postUpdate(`${P}${f}${t.name}`),i&&e.$postUpdate(`${T}${f}${t.name}`)}))}var ho;function mo(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 go(e){return function(t){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[e]=t})})}}function bo(e,t){return t?function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let s;return n.createStateAsync("writable",async n=>{s=await n[e](...t)}).then(()=>s)})}:function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let s;return n.createState("writable",n=>{s=n[e](...t)}),s})}}function yo(e){return e.startsWith("$")}ho=function(e){const t=Us();if(0===t.size)return;const n=[];for(const s of t)for(const t of Js(s).values())for(const o of t.depAddresses)if(e.has(o)){n.push({stateElement:s,entry:t});break}for(const{stateElement:e,entry:s}of n)if(t.has(e)&&Js(e).get(s.name)===s)try{fo(e,s)}catch(n){s.controller?.abort(),t.has(e)&&Js(e).get(s.name)===s&&po(e,s,"error",n)}},ro.add(ho);const wo=new Map;class No{path;segments;paths;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const t=e.split("."),n=t.slice(),s=[];let o=0,r=0,i="",a=0,c="none";const l=[];for(let e=0;e<t.length;e++){const c=t[e];if("*"===c)n[e]="*",l.push(null),o++,a++;else{const t=Number(c);Number.isNaN(t)||(n[e]="*",l.push(t),r++,a++)}i+=c,s.push(i),i+=e<c.length-1?".":""}const d=M(n.join("."));(o>0||r>0)&&(c=o===a?"context":r===a?"all":"partial"),this.path=e,this.segments=t,this.paths=s,this.wildcardCount=a,this.wildcardType=c,this.wildcardIndexes=l,this.pathInfo=d}}function xo(e){let t;return wo.get(e)??(wo.set(e,t=new No(e)),t)}const So=new WeakMap;function Ao(e,t){null===t?So.delete(e):So.set(e,t)}function _o(e){const t=So.get(e);t&&(t.dirty=!0)}function vo(e,t){let n=e;for(let e=1;e<t.length;e++){if(Object(n)!==n)return;n=Reflect.get(n,t[e])}return n}function Io(e,t,n,s,o){const r=t.pathInfo.segments[0];if(r===_)return vo(js(o),t.pathInfo.segments);if(r===P)return vo(no(o),t.pathInfo.segments);if(r===T)return vo(so(o),t.pathInfo.segments);if(!(t.pathInfo.path in e)){const o=Po(e,t.parentAddress??i(`address.parentAddress is undefined path: ${t.pathInfo.path}`),n,s),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(o,e)}return Reflect.get(o,r)}if(!o.getterPaths.has(t.pathInfo.path))return Reflect.get(e,t.pathInfo.path);s.pushAddress(t);try{return Reflect.get(e,t.pathInfo.path,n)}finally{s.popAddress()}}function $o(e,t,n,s,o){const r=rt(et(o,t.pathInfo),t.listIndex),i=function(e){return So.get(e)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=Io(e,t,n,s,o);return Ao(r,{value:a,dirty:!1}),a}function Po(e,t,n,s){!function(e,t){if(e.addressStackLength>0){const n=e.lastAddressStack?.pathInfo??null,s=e.stateElement;null!==n&&s.getterPaths.has(n.path)&&n.path!==t.pathInfo.path&&s.addDynamicDependency(t.pathInfo.path,n.path)}}(s,t),function(e,t){if(null===co)return;const n=et(e,t.pathInfo);co.add(rt(n,t.listIndex))}(s.stateElement,t);const o=s.stateElement;return t.pathInfo.wildcardCount>0||o.getterPaths.has(t.pathInfo.path)?$o(e,t,n,s,o):Io(e,t,n,s,o)}function To(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[t];return void 0===s?null:n.listIndex?.at(s)??null}const Eo=new WeakMap;function Co(e,t){null===t?Eo.delete(e):Eo.set(e,t)}function ko(e,t,n){const o=M(e.wildcardParentPaths[t]),r=et(e.stateElement,o),i=Ne(o,n),a=Xe(rt(r,n)),c=e.stateProxy[Te](i),l=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 s.debug&&console.log(`Invalid search type: ${t}`),[]}}(Wt(i.listIndex,a,c),e.searchType);if(t===e.wildcardPaths.length-1)e.targetListIndexes.push(...l);else for(const n of l)ko(e,t+1,n)}function Mo(e,t,n,s,o,r,a,c,l){const d={stateElement:t,staticMap:s,dynamicMap:o,result:new Set,listPathSet:r,visited:new Set,stateProxy:a,searchType:c};return function(e,t,n){const s=[{address:t,depth:0}];for(;s.length>0;){const{address:t,depth:o}=s.pop();if(o>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=o+1,c=[],l=e.staticMap.get(r);if(l)for(const n of l){const s=M(n);if(e.listPathSet.has(r)&&s.lastSegment===p){const n=e.stateProxy[Te](t),o=Xe(rt(et(e.stateElement,t.pathInfo),t.listIndex)),r=Wt(t.listIndex,o,n);for(const t of r.newIndexes){const n=Ne(s,t);e.result.add(n),c.push({address:n,depth:a})}}else{const n=Ne(s,t.listIndex);e.result.add(n),c.push({address:n,depth:a})}}const d=e.dynamicMap.get(r);if(d)for(const n of d){const s=M(n),o=[];if(s.wildcardCount>0){const n=dt(t.pathInfo,s);if(s.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:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};ko(a,n,r),o.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);o.push(e)}}else o.push(null);for(const t of o){const n=Ne(s,t);e.result.add(n),c.push({address:n,depth:a})}}for(let e=c.length-1;e>=0;e--)s.push(c[e])}}(d,n,l),Array.from(d.result)}function Oo(e,t,n,s,o,r){try{if(!(t.pathInfo.path in e)){const n=Po(e,t.parentAddress??i(`address.parentAddress is undefined path: ${t.pathInfo.path}`),o,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,s)}return Reflect.set(n,a,s)}if(!r.stateElement.setterPaths.has(t.pathInfo.path))return Reflect.set(e,t.pathInfo.path,s);r.pushAddress(t);try{return Reflect.set(e,t.pathInfo.path,s,o)}finally{r.popAddress()}}finally{const e=ao();e.enqueueAbsoluteAddress(n),Mo(r.stateName,r.stateElement,t,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,o,"new",n=>{if(n===t)return;const s=rt(et(r.stateElement,n.pathInfo),n.listIndex);_o(s),e.enqueueAbsoluteAddress(s)})}}function Wo(e,t,n,s,o,r){let a=t.parentAddress??i(`address.parentAddress is undefined path: ${t.pathInfo.path}`),c=function(e){return Eo.get(e)??null}(a);if(null===c){const t=Po(e,a,o,r)??[],n=Et(t)??[];c={value:[...t],listIndexes:[...n]},Co(a,c)}try{return Oo(e,t,n,s,o,r)}finally{const n=c.value.indexOf(s),i=Po(e,a,o,r)??[],l=Array.isArray(i)?Et(i)??[]:[],d=t.listIndex.index,u=-1!==n?c.listIndexes[n]:Pt(a.listIndex,-1);l[d]=u;if(new Set(i).size===c.value.length){for(let e=0;e<l.length;e++)l[e].index=e;Co(a,null)}}}function Lo(e,t,n,o,r){const i=r.stateElement;if(s.sameValueGuard&&(null===n||"object"!=typeof n)){const s=Po(e,t,o,r);if(Object.is(s,n))return!0}const a=i.elementPaths.has(t.pathInfo.path),c=t.pathInfo.wildcardCount>0||i.getterPaths.has(t.pathInfo.path),l=rt(et(i,t.pathInfo),t.listIndex);try{return a?Wo(e,t,l,n,o,r):Oo(e,t,l,n,o,r)}finally{c&&Ao(l,{value:n,dirty:!1});const e=i.bindableEventMap[t.pathInfo.path];if(e){const t=i.rootNode;t instanceof ShadowRoot&&t.host.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0}))}}}function Do(e,t,n,s){return(t,o,r)=>{const a=M(t);if(s.addressStackLength>0){const e=s.lastAddressStack?.pathInfo??null,t=s.stateElement;null!==e&&e.path!==a.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(a.path,e.path)}a.wildcardParentPathInfos.length>o.length&&i(`indexes length is insufficient: ${t}`);let c=null;for(let t=0;t<a.wildcardParentPathInfos.length;t++){const r=a.wildcardParentPathInfos[t],l=Ne(r,c),d=Et(Po(e,l,n,s));null==d&&i(`ListIndexes not found: ${r.path}`);c=d[o[t]]??i(`ListIndex not found: ${r.path}`)}const l=Ne(a,c);if(!(void 0!==r))return Po(e,l,n,s);Lo(e,l,r,n,s)}}const Ro=new WeakMap;function jo(e,t,n,s){const o=t.pathInfo;switch(t.wildcardType){case"none":return null;case"context":return To(s,o.wildcardPaths.at(-1)??i(`lastWildcardPath is null: ${t.pathInfo.path}`))??i(`ListIndex not found: ${t.pathInfo.path}`);case"all":{let o=null;for(let r=0;r<t.pathInfo.wildcardCount;r++){const a=t.pathInfo.wildcardParentPathInfos[r]??i(`wildcardParentPathInfo is null: ${t.pathInfo.path}`);o=(Et(Po(e,Ne(a,o),n,s))??i(`ListIndex not found: ${a.path}`))[t.wildcardIndexes[r]??i(`wildcardIndex is null: ${t.pathInfo.path}`)]??i(`ListIndex not found: ${a.path}`)}return o}case"partial":i(`Partial wildcard type is not supported yet: ${t.pathInfo.path}`)}}function Fo(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()}}const Bo=`${P}${f}`,qo=`${T}${f}`;function zo(e,t,n,s){const o=b[t];if(void 0!==o){0===s.addressStackLength&&i(`No active state reference to get list index for "${t.toString()}".`);const e=s.lastAddressStack?.listIndex;return e?.indexes[o]??i(`ListIndex not found: ${t.toString()}`)}if("string"==typeof t){if("$"===t[0]){switch(t){case"$stateElement":return s.stateElement;case"$getAll":return(t,o)=>function(e,t,n,s){const o=Do(e,0,n,s);return(t,r)=>{const a=new Map,c=M(t);if(s.addressStackLength>0){const e=s.lastAddressStack?.pathInfo??null,t=s.stateElement;null!==e&&e.path!==c.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(c.path,e.path)}if(void 0===r){for(let e=0;e<c.wildcardParentPathInfos.length;e++){const t=c.wildcardParentPathInfos[e],n=To(s,t.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const l=(t,o,r,c,d,u,f)=>{const p=t[o]??null;if(null===p)return void f.push(u);const h=Ne(p,r),m=Ro.get(h),g=Po(e,h,n,s),b=Wt(r,m,g).newIndexes,y=c[d]??null;if(a.set(h,g),null===y)for(let e=0;e<b.length;e++){const n=b[e];l(t,o+1,n,c,d+1,u.concat(n.index),f)}else{const e=b[y]??i(`ListIndex not found: ${p.path}`);o+1<t.length?l(t,o+1,e,c,d+1,u.concat(e.index),f):f.push(u.concat(e.index))}},d=[];l(c.wildcardParentPathInfos,0,null,r,0,[],d);const u=[];for(let e=0;e<d.length;e++)u.push(o(c.path,d[e]));for(const[e,t]of a.entries())Ro.set(e,t);return u}}(e,0,n,s)(t,o);case"$postUpdate":return t=>function(e,t,n,s){const o=s.stateElement;return t=>{const r=xo(t),i=jo(e,r,n,s),a=Ne(r.pathInfo,i),c=rt(et(o,a.pathInfo),a.listIndex),l=ao();l.enqueueAbsoluteAddress(c),Mo(s.stateName,s.stateElement,a,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{const t=rt(et(o,e.pathInfo),e.listIndex);_o(t),l.enqueueAbsoluteAddress(t)})}}(e,0,n,s)(t);case"$resolve":return(t,o,r)=>Do(e,0,n,s)(t,o,r);case"$trackDependency":return e=>function(e,t,n,s){return e=>{0===s.addressStackLength&&i(`No active state reference to track dependency for path "${e}".`);const t=s.lastAddressStack?.pathInfo??i("Internal error: lastAddressStack is null"),n=s.stateElement;s.stateElement.getterPaths.has(t.path)&&t.path!==e&&n.addDynamicDependency(e,t.path)}}(0,0,0,s)(e);case _:return js(s.stateElement);case P:return no(s.stateElement);case T:return so(s.stateElement)}if(!t.startsWith(Bo)&&!t.startsWith(qo))return}const o=xo(t),r=jo(e,o,n,s),a=Ne(o.pathInfo,r);return Po(e,a,n,s)}if("symbol"==typeof t){switch(t){case $e:return(e,t=async()=>{})=>async function(e,t,n){return await Fo(e,t,n)}(s,e,t);case Pe:return(e,t=()=>{})=>function(e,t,n){return Fo(e,t,n)}(s,e,t);case Te:return t=>Po(e,t,n,s);case Ee:return(t,o)=>Lo(e,t,o,n,s);case Ce:return()=>async function(e,t,n){const s=Reflect.get(e,y);"function"==typeof s&&await s.call(n)}(e,0,n);case ke:return()=>function(e,t,n){const s=Reflect.get(e,w);"function"==typeof s&&s.call(n)}(e,0,n);case Me:return t=>function(e,t,n,s){const o=Reflect.get(e,N);if("function"==typeof o){const e=new Set,r={};for(const n of t){const t=n.absolutePathInfo.pathInfo;let o;if(o=n.absolutePathInfo.stateName===s.stateName?t.path:t.path+"@"+n.absolutePathInfo.stateName,e.add(o),t.wildcardCount>0){const e=n.listIndex.indexes??[],t=r[o];void 0===t?r[o]=[e]:t.push(e)}}return o.call(n,Array.from(e),r)}}(e,t,n,s)}return Reflect.get(e,t,n)}}class Ho{_stateElement;_stateName;_addressStack=Array(h).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(e,t,n){this._stateName=t;const s=xs(e,this._stateName);null===s&&i(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=s,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 zo(e,t,n,this)}set(e,t,n,s){return"readonly"===this._mutability&&i(`State "${this._stateName}" is readonly.`),function(e,t,n,s,o){if("string"==typeof t){const r=xo(t),i=jo(e,r,s,o);return Lo(e,Ne(r.pathInfo,i),n,s,o)}return Reflect.set(e,t,n,s)}(e,t,n,s,this)}has(e,t){return Reflect.has(e,t)}}const Vo=new WeakMap;const Uo=new WeakMap;function Go(e,t){const n=Uo.get(e);return n?n.get(t)??null:null}const Jo=new WeakMap,Yo=new WeakMap,Ko=new WeakMap,Xo=new WeakMap;function Qo(e,t){return{innerAbsPathInfo:et(e,M(t.propSegments.slice(1).join(f))),outerAbsPathInfo:ht(t).absolutePathInfo}}function Zo(e,t){let n=Jo.get(e);if(void 0===n&&(n=new Map,Jo.set(e,n)),n.has(t))return n.get(t);let s=Yo.get(e);void 0===s&&(s=new Map,Yo.set(e,s));const o=Ko.get(e);if(void 0===o)return null;let r=null;for(const e of o)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=Xo.get(r);void 0===a&&i("Binding not found for primary mapping rule on web component.");const c=t.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),l=M(r.outerAbsPathInfo.pathInfo.segments.concat(c).join(f)),d=xs(e.getRootNode(),a.stateName);null===d&&i(`State element with name "${a.stateName}" not found for web component.`);const u=et(d,l);n.set(t,u),s.set(u,t);return function(e,t){const n=q(e);null===n?z(e,[t]):n.push(t)}(e,{...a,propName:t.pathInfo.path,propSegments:t.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function er(e){return function(e){const t=Object.getPrototypeOf(e),n=Object.create(t),s=Object.getOwnPropertyDescriptors(e);for(const e in s){const t=s[e];!1===t.writable&&(t.writable=!0)}return Object.defineProperties(n,s),n}(e)}class tr{_webComponent;_innerStateElement;constructor(e,t){this._webComponent=e,this._innerStateElement=Go(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 s=M(t),o=et(this._innerStateElement,s),r=Zo(this._webComponent,o);if(null!==r){const e=ve(this._webComponent);let t;return r.stateElement.createState("readonly",n=>{n[Pe](e,()=>{t=n[r.pathInfo.path];let s=null;null!==e&&null!==e.listIndex&&r.pathInfo.wildcardCount>0&&(s=e.listIndex.at(r.pathInfo.wildcardCount-1));!function(e,t){Vo.set(e,t)}(rt(r,s),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,s){if("string"!=typeof t)return Reflect.set(e,t,n,s);{if(this._innerStateElement.setterPaths.has(t)&&t in e)return Reflect.set(e,t,n,s);const o=M(t),r=et(this._innerStateElement,o),a=Zo(this._webComponent,r);if(null!==a){const e=ve(this._webComponent);return a.stateElement.createState("writable",t=>{t[Pe](e,()=>{t[a.pathInfo.path]=n})}),!0}if(t in e)return Reflect.set(e,t,n,s);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=M(t),s=et(this._innerStateElement,n);return null!==Zo(this._webComponent,s)||t in e}return Reflect.has(e,t)}}class nr{_innerStateElement;constructor(e,t){this._innerStateElement=Go(e,t)??i("State element not found for web component.")}get(e,t,n){if("string"==typeof t){const e=M(t),n=rt(et(this._innerStateElement,e),null);return s=n,Vo.get(s)}return Reflect.get(e,t,n);var s}set(e,t,n,s){if("string"==typeof t){const e=M(t),n=et(this._innerStateElement,e);return this._innerStateElement.createState("readonly",e=>{e.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(e,t,n,s)}}class sr{_innerStateElement;constructor(e,t){this._innerStateElement=Go(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,s){return"string"==typeof t?(this._innerStateElement.createState("writable",e=>{e[t]=n}),!0):Reflect.set(e,t,n,s)}}const or=e=>()=>e;function rr(e,t,n,o){if(function(e,t,n){let s=Uo.get(e);s||(s=new Map,Uo.set(e,s)),s.set(t,n)}(t,n,e),t.hasAttribute(s.bindAttributeName)){const s=(q(t)??[]).filter(e=>e.propSegments[0]===n);!function(e,t,n){if(0===n.length)return;const s=Go(e,t);null===s&&i("State element not found for web component.");const o=new Map,r=new Map;for(const t of n){const n=Qo(s,t);let i=Ko.get(e);void 0===i?Ko.set(e,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,c=n.outerAbsPathInfo;Xo.set(n,t),o.set(a,c),r.set(c,a)}Jo.set(e,o),Yo.set(e,r)}(t,n,s);const o=function(e,t){const n=new nr(e,t);return new Proxy({},n)}(t,n),r=function(e,t){const n=new tr(e,t),s=Go(e,t);null===s&&i("State element not found for web component."),null===s.boundComponentStateProp&&i("State element is not bound to any component state prop."),s.boundComponentStateProp in e||i(`State element is not bound to a valid component state prop: ${s.boundComponentStateProp}`);const o=e[s.boundComponentStateProp];return"object"==typeof o&&null!==o||i(`Invalid state object for component state prop: ${s.boundComponentStateProp}`),new Proxy(er(o),n)}(t,n);e.setInitialState(r),Object.defineProperty(t,n,{get:or(o),enumerable:!0,configurable:!0})}else{e.setInitialState(er(o));const s=function(e,t){const n=new sr(e,t);return new Proxy({},n)}(t,n);Object.defineProperty(t,n,{get:or(s),enumerable:!0,configurable:!0})}if(function(e,t){let n=gt.get(e);n||(n=new WeakMap,gt.set(e,n)),n.set(t,!0)}(t,e),x in t){const e=t[x];"function"==typeof e?e.call(t,n).catch(e=>{i(`Error in ${x}: ${e instanceof Error?e.message:String(e)}`)}):i(`${x} is not a function.`)}}function ir(e){const t=new Set,n=new Set,s=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,o]of Object.entries(s))"function"==typeof o.get&&t.add(e),"function"==typeof o.set&&n.add(e);return{getterPaths:t,setterPaths:n}}class ar extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(e){return Ss(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 Ws}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_dcc=!1;_connectGeneration=0;_streamsStartedGeneration=0;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(`${s.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(e){const t=new Set,n=e[A];if(void 0===n)return t;Array.isArray(n)||i(`${A} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||i(`${A} entries must be non-empty strings.`),e===_&&i(`${A} entry "${e}" conflicts with the reserved namespace name "${_}".`),t.has(e)&&i(`${A} entry "${e}" is duplicated.`),t.add(e);return t}(e),this._eventTokenNames=function(e){const t=new Set,n=e[v];if(void 0===n)return t;Array.isArray(n)||i(`${v} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||i(`${v} entries must be non-empty strings.`),t.has(e)&&i(`${v} entry "${e}" is duplicated.`),t.add(e);return t}(e),this.__state=e,Be(this),function(e,t,n){const s=t[I];if(void 0!==s){"object"==typeof s&&null!==s||i(`${I} must be an object mapping event-token names to handler functions.`);for(const[t,o]of Object.entries(s))n.has(t)||i(`${I} entry "${t}" is not declared in $eventTokens.`),"function"!=typeof o&&i(`${I} entry "${t}" must be a function.`),Fe(e,t).subscribe(o)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const n=ir(e);for(const e of n.getterPaths)this._getterPaths.add(e);for(const e of n.setterPaths)this._setterPaths.add(e);var s;oo(this),Ys(s=this),Vs(s),Gs.delete(s),Qs(this,e),this._initialized&&null!==this._rootNode&&!t()&&(uo(this),this._streamsStartedGeneration=this._connectGeneration),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=ks.findByName(t,e);if(!n)return null;const s=n.stateData;return Object.keys(s).length>0?s: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 Os(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 Ms(e,`${this._name}`);else{const e=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${s.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",As(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?L(t):null;null!==t&&null!==n||i(`"bind-component" requires <${s.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 o=this.getAttribute("bind-component");await customElements.whenDefined(n.toLowerCase()),t.hasAttribute(s.bindAttributeName)&&await d(t),o in t||i(`Component does not have property "${o}" for state binding.`);const r=t[o];"object"==typeof r&&null!==r||i(`Component property "${o}" is not an object for state binding.`),this._boundComponent=t,this._boundComponentStateProp=o,rr(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async e=>{y in e&&await e[Ce]()})}async _initializeDCC(e,t){let n;try{if(this.hasAttribute("src")){const e=this.getAttribute("src");e.endsWith(".js")?n=await Os(e):i(`DCC: Unsupported src type: ${e}`)}else{const t=this.querySelector('script[type="module"]');t?n=await Ms(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 o=e.tagName.toLowerCase();if(o.includes("-")||i(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`),customElements.get(o))return void console.warn(`[@wcstack/state] DCC: "${o}" is already registered. Skipping redefinition.`);const r=document.createElement("template");r.innerHTML=t.innerHTML;const a=t.mode,c=Array.isArray(n[S])?n[S]:[],l=c.length>0?function(e,t){return{protocol:"wc-bindable",version:1,properties:t.map(t=>({name:t,event:`${e}:${t}-changed`}))}}(o,c):null,d=c.length>0?function(e,t){const n={};for(const s of t)n[s]=`${e}:${s}-changed`;return n}(o,c):{},u=`${s.tagNames.state}:not([name])`,f=class extends HTMLElement{static template=r;static shadowRootMode=a;static wcBindable=l;static bindableEventMap=d;_shadow=null;connectedCallback(){if(!this.hasAttribute(E)&&(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(yo(e))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof t.value){const s="AsyncFunction"===t.value.constructor?.name;n.value=bo(e,s)}else n.get=mo(e),n.set=go(e);Object.defineProperty(f.prototype,e,n)}customElements.define(o,f)}(e,t,n),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",e=>{w in e&&e[ke]()})}async connectedCallback(){this._rootNode=this.getRootNode();const e=++this._connectGeneration;if(this._initialized)this._dcc||xs(this._rootNode,this._name)===this||As(this._rootNode,this._name,this);else{const e=this.parentNode;if(e instanceof ShadowRoot&&e.host.hasAttribute(E))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 Ss(this.rootNode);const e=this.getAttribute("name")||"default",t=ks.extractStateData(this),n=document.createElement(s.tagNames.ssr);n.setAttribute("name",e),n.setAttribute("version",r),ks.buildContent(n,t),this.parentNode?.insertBefore(n,this)}t()||null===this._rootNode||e!==this._connectGeneration||this._streamsStartedGeneration===e||uo(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{As(this.rootNode,this._name,null),e=this,Ls.delete(e),function(e){Rs.delete(e)}(this),Be(this),Ys(this),oo(this),this._rootNode=null}var e}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}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(e){this._bindableEventMap=e}_addDependency(e,t,n){const s=e.get(t);return void 0===s?(e.set(t,[n]),!0):!s.includes(n)&&(s.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=M(e);if(this._pathSet.add(e),null!==t.parentPath){let e=t;for(;null!==e.parentPath&&this.addStaticDependency(e.parentPath,e.path);)e=M(e.parentPath)}}}_createState(e,t,n){try{const s=function(e,t,n,s){const o=new Ho(e,n,s);return new Proxy(t,o)}(e,this._state,this._name,t);return n(s)}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 cr(){customElements.get(s.tagNames.ssr)||customElements.define(s.tagNames.ssr,ks),customElements.get(s.tagNames.state)||customElements.define(s.tagNames.state,ar)}function lr(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),"boolean"==typeof t.sameValueGuard&&(n.sameValueGuard=t.sameValueGuard)),cr()}function dr(e){return e}const ur={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"ブール値を反転",hasArgs:!1,resultType:"boolean",acceptTypes:["boolean"],minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},inc:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},dec:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},fix:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},uc:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lc:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},cap:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},substr:{description:"部分文字列 (pos,len)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},pad:{description:"パディング (length[,char])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},rep:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},rev:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},date:{description:"ロケール形式の日付",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},time:{description:"ロケール形式の時刻",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},datetime:{description:"ロケール形式の日時",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},ymd:{description:"YYYY-MM-DD 形式",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},null:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0}},fr=1;function pr(){return{version:1,syntax:{bindAttribute:s.bindAttributeName,tagName:s.tagNames.state,pathDelimiter:f,wildcard:p,delimiters:{binding:";",propValue:":",modifier:"#",stateName:"@",filter:m},structuralDirectives:Array.from(H)},filters:Object.keys(X),filterMeta:ur,reservedLifecycle:[y,w,N,x],reservedStateApi:[S,A,_,v,I]}}export{ks as Ssr,r as VERSION,fr as WCS_MANIFEST_VERSION,lr as bootstrapState,ps as buildBindings,ur as builtinFilterMeta,dr as defineState,Ss as getBindingsReady,o as getConfig,pr as getWcsManifest};
|
|
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,sameValueGuard:!0},s=n;function o(){return s}const r="1.19.0";function a(e){throw new Error(`[@wcstack/state] ${e}`)}const i=new WeakMap;let c=0;function l(e){let t,n=i.get(e)||null;if(null!==n)return n;const s=new Promise(e=>{t=e});return n={id:++c,promise:s,resolve:t},i.set(e,n),n}async function d(e){const t=l(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="|",g={};for(let e=0;e<128;e++)g[`$${e+1}`]=e;const b=Object.freeze(g),y="$connectedCallback",w="$disconnectedCallback",N="$updatedCallback",x="$stateReadyCallback",S="$bindables",I="$commandTokens",A="$command",_="$eventTokens",v="$on",P="$streams",$="$streamStatus",T="$streamError",E="data-wc-definition",C=new Map;let k=0;function M(e){let t=C.get(e);return void 0!==t||(t=Object.freeze(new O(e)),C.set(e,t)),t}class O{id=++k;path;segments;lastSegment;cumulativePaths;cumulativePathSet;cumulativePathInfos;cumulativePathInfoSet;parentPath;wildcardPaths;wildcardPathSet;indexByWildcardPath;wildcardPathInfos;wildcardPathInfoSet;wildcardParentPaths;wildcardParentPathSet;wildcardParentPathInfos;wildcardParentPathInfoSet;wildcardPositions;lastWildcardPath;lastWildcardInfo;wildcardCount;parentPathInfo;constructor(e){const t=t=>e===t?this:M(t),n=e.split("."),s=[],o=[],r=[],a={},i=[],c=[],l=[],d=[];let u="",f="",h=0;for(let e=0;e<n.length;e++)u+=n[e],n[e]===p&&(r.push(u),a[u]=h,i.push(t(u)),c.push(f),l.push(t(f)),d.push(e),h++),s.push(u),o.push(t(u)),f=u,u+=".";const m=r.length>0?r[r.length-1]:null,g=s.length>1?s[s.length-2]:null;this.path=e,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=s,this.cumulativePathSet=new Set(s),this.cumulativePathInfos=o,this.cumulativePathInfoSet=new Set(o),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=a,this.wildcardPathInfos=i,this.wildcardPathInfoSet=new Set(i),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=l,this.wildcardParentPathInfoSet=new Set(l),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 L=new WeakMap;function D(e){const t=L.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,s=t.tagName.toLowerCase();if(s.includes("-"))return n=s;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{L.set(e,n)}}function W(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 R(e,t,n){const s="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:s,statePathInfo:M(s),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function j(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function F(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 B=new WeakMap;function z(e){return B.get(e)||null}function q(e,t){B.set(e,t)}const U=new Set(["if","elseif","else","for"]);function H(e){a(`filter ${e} requires at least one option`)}function V(e){a(`filter ${e} requires a number as option`)}function G(e){a(`filter ${e} requires a number value`)}function J(e){a(`filter ${e} requires a date value`)}function Y(e){return!(!e||isNaN(Number(e)))}const K={eq:e=>{const t=e?.[0]??H("eq");return e=>"number"==typeof e?(Y(t)||V("eq"),e===Number(t)):e===t},ne:e=>{const t=e?.[0]??H("ne");return e=>"number"==typeof e?(Y(t)||V("ne"),e!==Number(t)):e!==t},not:e=>e=>("boolean"!=typeof e&&a(`filter ${"not"} requires a boolean value`),!e),lt:e=>{const t=e?.[0]??H("lt");return Y(t)||V("lt"),e=>("number"!=typeof e&&G("lt"),e<Number(t))},le:e=>{const t=e?.[0]??H("le");return Y(t)||V("le"),e=>("number"!=typeof e&&G("le"),e<=Number(t))},gt:e=>{const t=e?.[0]??H("gt");return Y(t)||V("gt"),e=>("number"!=typeof e&&G("gt"),e>Number(t))},ge:e=>{const t=e?.[0]??H("ge");return Y(t)||V("ge"),e=>("number"!=typeof e&&G("ge"),e>=Number(t))},inc:e=>{const t=e?.[0]??H("inc");return Y(t)||V("inc"),e=>("number"!=typeof e&&G("inc"),e+Number(t))},dec:e=>{const t=e?.[0]??H("dec");return Y(t)||V("dec"),e=>("number"!=typeof e&&G("dec"),e-Number(t))},mul:e=>{const t=e?.[0]??H("mul");return Y(t)||V("mul"),e=>("number"!=typeof e&&G("mul"),e*Number(t))},div:e=>{const t=e?.[0]??H("div");return Y(t)||V("div"),e=>("number"!=typeof e&&G("div"),e/Number(t))},mod:e=>{const t=e?.[0]??H("mod");return Y(t)||V("mod"),e=>("number"!=typeof e&&G("mod"),e%Number(t))},fix:e=>{const t=e?.[0]??"0";return Y(t)||V("fix"),e=>("number"!=typeof e&&G("fix"),e.toFixed(Number(t)))},locale:e=>{const t=e?.[0]??s.locale;return e=>("number"!=typeof e&&G("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]??H("slice");Y(n)||V("slice"),t.push(Number(n));const s=e?.[1];return void 0!==s&&(Y(s)||V("slice"),t.push(Number(s))),e=>String(e).slice(...t)},substr:e=>{const t=e?.[0]??H("substr");Y(t)||V("substr");const n=e?.[1]??H("substr");return Y(n)||V("substr"),e=>String(e).substr(Number(t),Number(n))},pad:e=>{const t=e?.[0]??H("pad");Y(t)||V("pad");const n=e?.[1]??"0";return e=>String(e).padStart(Number(t),n)},rep:e=>{const t=e?.[0]??H("rep");return Y(t)||V("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 Y(t)||V("round"),e=>{"number"!=typeof e&&G("round");const n=Math.pow(10,Number(t));return Math.round(e*n)/n}},floor:e=>{const t=e?.[0]??"0";return Y(t)||V("floor"),e=>{"number"!=typeof e&&G("floor");const n=Math.pow(10,Number(t));return Math.floor(e*n)/n}},ceil:e=>{const t=e?.[0]??"0";return Y(t)||V("ceil"),e=>{"number"!=typeof e&&G("ceil");const n=Math.pow(10,Number(t));return Math.ceil(e*n)/n}},percent:e=>{const t=e?.[0]??"0";return Y(t)||V("percent"),e=>("number"!=typeof e&&G("percent"),`${(100*e).toFixed(Number(t))}%`)},date:e=>{const t=e?.[0]??s.locale;return e=>(e instanceof Date||J("date"),e.toLocaleDateString(t))},time:e=>{const t=e?.[0]??s.locale;return e=>(e instanceof Date||J("time"),e.toLocaleTimeString(t))},datetime:e=>{const t=e?.[0]??s.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(),s=(e.getMonth()+1).toString().padStart(2,"0"),o=e.getDate().toString().padStart(2,"0");return`${n}${t}${s}${t}${o}`}},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]??H("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},X=K,Q={input:K,output:X},Z=(e,t)=>n=>{const s=n[e];return s||a(`filter not found: ${e}`),s(t)};const ee=new Map;function te(e,t){const n=Q[t];return e.map(e=>{const s=e.indexOf("("),o=e.lastIndexOf(")");if(-1!==s&&-1===o&&a(`Invalid filter format: missing closing parenthesis in "${e}"`),-1!==o&&-1===s&&a(`Invalid filter format: missing opening parenthesis in "${e}"`),-1===s){const s=e.trim(),o=`${s}():${t}`;let r=ee.get(o);return void 0===r&&(r=Z(s,[])(n),ee.set(o,r)),{filterName:s,args:[],filterFn:r}}{const r=e.substring(s+1,o),a=e.substring(0,s).trim(),i=function(e){const t=[];let n="",s=null,o=!1;for(let r=0;r<e.length;r++){const a=e[r];s?a===s?s=null:n+=a:'"'===a||"'"===a?(s=a,o=!0):","===a?(t.push(n.trim()),n="",o=!1):n+=a}const r=n.trim();return(r||o)&&t.push(r),t}(r),c=`${a}(${i.join(",")}):${t}`;let l=ee.get(c);return void 0===l&&(l=Z(a,i)(n),ee.set(c,l)),{filterName:a,args:i,filterFn:l}}})}const ne=e=>e.trim(),se=new Map;const oe=new Map;function re(e){const t=e.indexOf(m);let n="",s=[],o="",r=[];-1!==t?(n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),oe.has(o)?r=oe.get(o):(s=o.split(m).map(ne),r=te(s,"output"),oe.set(o,r))):n=e.trim();const[a,i="default"]=n.split("@").map(ne);return{stateName:i,statePathName:a,statePathInfo:M(a),outFilters:r}}function ae(e){const[...t]=e.split(";").map(ne).filter(e=>e.length>0),n=t.map(e=>{const t=e.indexOf(":");-1===t&&a(`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`);const n=e.slice(0,t).trim(),s=e.slice(t+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:M("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("..."===n){const t=re(s);return t.outFilters.length>0&&a(`Invalid spread binding "${e}": filters are not allowed on spread targets.`),0===t.statePathName.length&&a(`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:[],...re(s),bindingType:n}}{const e=re(s),t=function(e){const t=e.indexOf(m);let n="",s=[],o="",r=[];-1!==t?(n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),se.has(o)?r=se.get(o):(s=o.split(m).map(ne),r=te(s,"input"),se.set(o,r))):n=e.trim();const[a,i]=n.split("#").map(ne),c=a.split(f).map(ne);return{propName:a,propSegments:c,propModifiers:i?i.split(",").map(ne):[],inFilters:r}}(n);return"eventToken"===t.propSegments[0]||t.propSegments[0].startsWith("on")?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>U.has(e.bindingType))&&a(`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const ie=new WeakMap,ce=new Set([s.commentTextPrefix,s.commentForPrefix,s.commentIfPrefix,s.commentElseIfPrefix,s.commentElsePrefix]),le=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function de(e){const t=ie.get(e);if("string"==typeof t)return t;if(e.nodeType!==Node.COMMENT_NODE)return null;const n=e.data.trim(),o=le.exec(n);if(null===o)return null;const r=o[1]||s.commentTextPrefix;return ce.has(r)?(ie.set(e,o[2]),o[2]):null}function ue(e){if(e.nodeType===Node.ELEMENT_NODE){return ae(e.getAttribute(s.bindAttributeName)||"")}if(e.nodeType===Node.COMMENT_NODE){const t=de(e);null===t&&a("Comment node binding text not found.");const n=Ts(t);let s=n?.parseBindTextResult??null,o=null;return null===s?(s={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...re(t),bindingType:"text"},o=null):o=t,[{...s,uuid:o}]}return[]}function fe(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(e){if(e.nodeType===Node.ELEMENT_NODE){return e.hasAttribute(s.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==de(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}const pe=new WeakSet;function he(e,t,n){const o=function(e,t,n={}){const o=n.allowDeferred??!0;if(!t.some(e=>"spread"===e.bindingType))return t;const r=[],i=new WeakSet;for(const n of t){if("spread"!==n.bindingType){r.push(n);continue}e.nodeType!==Node.ELEMENT_NODE&&a("Spread binding requires an element node.");const t=e,s=D(t);null===s&&a(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${t.tagName.toLowerCase()}> is not a custom element.`);const c=customElements.get(s);if(void 0===c){o||a(`Spread binding "${n.statePathName}" requires <${s}> to be registered. Define the custom element before initializing this binding.`),r.push(n);continue}const l=c.wcBindable;W(l)||a(`Spread binding "${n.statePathName}" requires <${s}> to declare wcBindable (protocol="wc-bindable", version=1).`);const d=n.statePathName,u=n.stateName,f=new Set;for(const e of l.properties){if(f.has(e.name))continue;f.add(e.name);const t=R(e.name,d,u);i.add(t),r.push(t)}for(const e of l.inputs??[]){if(f.has(e.name))continue;f.add(e.name);const t=R(e.name,d,u);i.add(t),r.push(t)}}const c=new Map;for(let e=0;e<r.length;e++){const t=j(r[e]);null!==t&&c.set(t,e)}const l=[];for(let t=0;t<r.length;t++){const n=j(r[t]);if(null!==n){if(c.get(n)===t)l.push(r[t]);else if(s.debug&&i.has(r[t])){const s=r[c.get(n)],o=e.nodeType===Node.ELEMENT_NODE?`<${e.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${r[t].propName}" of ${o} overridden by explicit binding (statePath: "${s.statePathName}").`)}}else l.push(r[t])}return l}(e,t,{allowDeferred:n.allowDeferred});if(o.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?D(e):null;return null===n&&a("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t}}}pe.add(e);const r=function(e,t){const n=[];for(const s of t)if("text"!==s.bindingType)n.push({...s,node:e,replaceNode:e});else{const t=document.createTextNode("");n.push({...s,node:e,replaceNode:t})}return n}(e,o);return q(e,r),function(e){l(e).resolve()}(e),{bindings:r,deferred:null}}function me(e){const t=fe(e),n=[],s=[];for(const e of t){if(pe.has(e))continue;const t=he(e,ue(e),{allowDeferred:!0});null===t.deferred?n.push(...t.bindings):s.push(t.deferred)}return[t,n,s]}function ge(e){const{node:t,parseResults:n}=e;!function(e){pe.delete(e)}(t);return he(t,n,{allowDeferred:!1}).bindings}const be=new WeakMap,ye=new WeakMap;class we{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=Ne(e,t)}}function Ne(e,t){if(null===t){let t=ye.get(e);return void 0!==t||(t=new we(e,null),ye.set(e,t)),t}{let n=be.get(t);void 0===n&&(n=new WeakMap,be.set(t,n));let s=n.get(e);return void 0!==s||(s=new we(e,t),n.set(e,s)),s}}class xe{_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}}class Se extends xe{}function Ie(e){return e instanceof Se}const Ae=new WeakMap;function _e(e){let t=e;for(;t;){const e=Ae.get(t);if(e)return e;t=t.parentNode}return null}function ve(e,t){null!==t?Ae.set(e,t):Ae.delete(e)}const Pe=Symbol("$$setLoopContextAsync"),$e=Symbol("$$setLoopContext"),Te=Symbol("$$getByAddress"),Ee=Symbol("$$setByAddress"),Ce=Symbol("$$connectedCallback"),ke=Symbol("$$disconnectedCallback"),Me=Symbol("$$updatedCallback");function Oe(){const e=new Map,t=new Map;return{add(n,s){let o=e.get(n);return void 0===o&&(o=new WeakSet,e.set(n,o)),!o.has(s)&&(o.add(s),t.set(n,(t.get(n)??0)+1),!0)},remove(n,s){const o=e.get(n);if(void 0===o||!o.has(s))return!1;o.delete(s);const r=(t.get(n)??1)-1;return r<=0?(e.delete(n),t.delete(n),!0):(t.set(n,r),!1)},has:(t,n)=>e.get(t)?.has(n)??!1,countOf:e=>t.get(e)??0,get keyCount(){return t.size},clear(){e.clear(),t.clear()}}}const Le=new Map,De=Oe();const We=(e,t,n,s)=>o=>{n.includes("prevent")&&o.preventDefault(),n.includes("stop")&&o.stopPropagation();const r=o.target,i=As(r.getRootNode(),e);null===i&&a(`State element with name "${e}" not found for event handler.`);const c=_e(r),l=t.startsWith(A+".");i.createStateAsync("writable",async n=>{n[$e](c,()=>{const r=c?.listIndex.indexes??[];if(l){const e=n[Te](Ne(s,null));return Ie(e)||a(`Event binding "${t}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),e.emit(o,...r)}const i=n[t];return"function"!=typeof i&&a(`Handler "${t}" is not a function on state "${e}".`),Reflect.apply(i,n,[o,...r])})})};function Re(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=Le.get(t);void 0===n&&(n=We(e.stateName,e.statePathName,e.propModifiers,e.statePathInfo),Le.set(t,n));const s=e.propName.slice(2);return e.node.addEventListener(s,n),De.add(t,e),!0}class je extends xe{}const Fe=new WeakMap;function Be(e,t){let n=Fe.get(e);void 0===n&&(n=new Map,Fe.set(e,n));let s=n.get(t);return void 0===s&&(s=new je(t),n.set(t,s)),s}function ze(e){Fe.delete(e)}const qe=new WeakMap;function Ue(e){if("eventToken"!==e.propSegments[0])return!1;const t=e.node,n=D(t);if(null!==n&&void 0===customElements.get(n))return customElements.whenDefined(n).then(()=>{Ue(e)}),!0;if(qe.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||a('eventToken binding requires a property name (e.g., "eventToken.error").');const o=function(e){const t=D(e);if(null===t)return null;const n=customElements.get(t),s=n?.wcBindable;return"wc-bindable"===s?.protocol&&1===s?.version?s:null}(t);null===o&&a(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const r=o.properties.find(e=>e.name===s);void 0===r&&a(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.`);const i=r.event,c=e.statePathName,l=e.stateName,d=e.propModifiers,u=e=>{d.includes("prevent")&&e.preventDefault(),d.includes("stop")&&e.stopPropagation();const n=As(t.getRootNode(),l);null===n&&a(`State element with name "${l}" not found for eventToken handler.`),n.eventTokenNames.has(c)||a(`eventToken "${c}" is not declared in $eventTokens of state "${l}".`);const s=_e(t);n.createStateAsync("writable",async t=>{t[$e](s,()=>{const o=s?.listIndex.indexes??[];return Be(n,c).emit(t,e,...o)})})};return t.addEventListener(i,u),qe.set(e,{eventName:i,handler:u}),!0}const He=new Set(["radio","checkbox"]),Ve=new Set(["value","valueAsNumber","valueAsDate"]);const Ge=new Map,Je=Oe(),Ye=e=>e.detail;function Ke(e){const t=D(e.node);if(null!==t){if(void 0===customElements.get(t))return void customElements.whenDefined(t).then(()=>{Ke(e)})}if(function(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,s=n.tagName.toLowerCase();if("input"===s){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(He.has(e)&&"checked"===t)return!0;if(Ve.has(t))return!0}if("select"===s&&"value"===t)return!0;if("textarea"===s&&"value"===t)return!0;const o=D(n);if(null!==o){const e=customElements.get(o);void 0===e&&a(`Custom element <${o}> 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=D(e.node);if(null!==n){const s=customElements.get(n);void 0===s&&a(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const o=s.wcBindable;if("wc-bindable"===o?.protocol&&1===o?.version){const n=o.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=D(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??Ye}}}return null}(e),s=function(e,t,n){const s=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.propName}::${e.statePathName}::${t}::${s}::${n?"g":"n"}`}(e,t,null!==n);let o=Ge.get(s);void 0===o&&(o=((e,t,n,s,o)=>r=>{const i=r.target;if(null===i)return void console.warn("[@wcstack/state] event.target is null.");let c;if(null!==o)c=o(r);else{if(!(t in i))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);c=i[t]}let l=c;for(const e of s)l=e.filterFn(l);const d=As(i.getRootNode(),e);null===d&&a(`State element with name "${e}" not found for two-way binding.`);const u=_e(i);d.createState("writable",e=>{e[$e](u,()=>{e[n]=l})})})(e.stateName,e.propName,e.statePathName,e.inFilters,n),Ge.set(s,o)),e.node.addEventListener(t,o),Je.add(s,e)}}const Xe=new WeakMap;function Qe(e){return Xe.get(e)??[]}function Ze(e,t){Xe.set(e,t)}const et=new WeakMap;function tt(e,t){if(et.has(e)){const n=et.get(e);if(n.has(t))return n.get(t)}else et.set(e,new WeakMap);const n=Object.freeze(new nt(e,t));return et.get(e).set(t,n),n}class nt{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=tt(e,t.parentPathInfo)}}const st=new WeakMap,ot=new WeakMap;class rt{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=at(e,t)}}function at(e,t){if(null===t){let t=ot.get(e);return void 0!==t||(t=new rt(e,null),ot.set(e,t)),t}{let n=st.get(t);void 0===n&&(n=new WeakMap,st.set(t,n));let s=n.get(e);return void 0!==s||(s=new rt(e,t),n.set(e,s)),s}}const it=new WeakMap;function ct(e,t){null===t?it.delete(e):it.set(e,t)}function lt(e){return it.get(e)||null}const dt=new Map;function ut(e,t){let n,s;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,s=t):(n=t,s=e);const o=`${n.path}\t${s.path}`;let r=dt.get(o);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(s.wildcardPathSet).size,dt.set(o,r),r}const ft=new WeakMap;function pt(e){const t=_e(e.node);if(null===t)return null;let n=ft.get(t);if(void 0===n)n=new WeakMap,ft.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let s=null;try{const n=ut(t.pathInfo,e.statePathInfo);return n>0&&(s=t.listIndex.at(n-1)),s}finally{n.set(e,s)}}const ht=new WeakMap;function mt(e){let t=null;if(t=ht.get(e)||null,null!==t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=lt(n);null===t?a(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}const s=pt(e),o=As(n,e.stateName);null===o&&a(`State element with name "${e.stateName}" not found for binding.`);return t=at(tt(o,e.statePathInfo),s),ht.set(e,t),t}function gt(e){ht.delete(e)}const bt=new WeakMap;function yt(e,t){const n=bt.get(e);return!!n&&!0===n.get(t)}function wt(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const Nt=Object.freeze([]);const xt=new WeakMap;const St=new WeakMap;function It(e){return St.get(e)??[]}function At(e,t){St.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 _t=0;function vt(){return`u${(_t++).toString(36)}`}let Pt=0;class $t{uuid=vt();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=Pt}get index(){return this._index}set index(e){this._index=e,this._version=++Pt,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=Pt),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 Tt(e,t){return new $t(e,t)}const Et=new WeakMap;function Ct(e){return Et.get(e)||null}function kt(e,t){null!==t?Et.set(e,t):Et.delete(e)}const Mt=new WeakMap,Ot=Object.freeze([]),Lt=new Set;function Dt(e,t,n){const s=Array.isArray(t)&&t.length>0?t:Ot,o=Array.isArray(n)&&n.length>0?n:Ot,r=function(e,t){const n=Array.isArray(e)&&e.length>0?e:Ot,s=Array.isArray(t)&&t.length>0?t:Ot;let o=Mt.get(n);return o&&o.get(s)||null}(s,o);if(r)return r;const a=Ct(s)||[];let i;try{if(0===o.length)return i={oldIndexes:a,newIndexes:[],changeIndexSet:Lt,deleteIndexSet:new Set(a),addIndexSet:Lt};let t=Ct(o);if(0===s.length){if(null===t){t=[];for(let n=0;n<o.length;n++){const s=Tt(e,n);t.push(s)}}return i={oldIndexes:a,newIndexes:t,changeIndexSet:Lt,deleteIndexSet:Lt,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}(s,o))return i={oldIndexes:a,newIndexes:a,changeIndexSet:Lt,deleteIndexSet:Lt,addIndexSet:Lt};const n=new Map;for(let e=0;e<s.length;e++){const t=s[e];let o=n.get(t);o||(o=[],n.set(t,o)),o.push(e)}if(null!==t)return function(e,t,n,s,o){const r=new Set(s),a=new Set(n),i=new Set,c=r.difference(a),l=a.difference(r);for(let e=0;e<t.length;e++){const s=t[e],r=o.get(s),a=r&&r.length>0?r.shift():void 0;if(void 0!==a){const t=n[a];t.index!==e&&i.add(t)}}return{oldIndexes:n,newIndexes:s,changeIndexSet:i,deleteIndexSet:l,addIndexSet:c}}(0,o,a,t,n);t=[];const r=new Set,c=new Set;for(let s=0;s<o.length;s++){const i=o[s],l=n.get(i),d=l&&l.length>0?l.shift():void 0;if(void 0===d){const n=Tt(e,s);t.push(n),c.add(n)}else{const e=a[d];e.index!==s&&(e.index=s,r.add(e)),t.push(e)}}return i={oldIndexes:a,newIndexes:t,changeIndexSet:r,deleteIndexSet:new Set(a).difference(new Set(t)),addIndexSet:c}}finally{void 0!==i&&(!function(e,t,n){let s=Mt.get(e);s||(s=new WeakMap,Mt.set(e,s)),s.set(t,n)}(s,o,i),kt(o,i.newIndexes))}}function Wt(e){if(0===e.changeIndexSet.size||e.addIndexSet.size===e.newIndexes.length)return null;const t=new Map;for(let n=0;n<e.oldIndexes.length;n++)t.set(e.oldIndexes[n],n);const n=[],s=[];let o=-1,r=!0;for(const a of e.newIndexes){if(e.addIndexSet.has(a))continue;const i=t.get(a);if(void 0===i)return null;i<o&&(r=!1),o=i,n.push(a),s.push(i)}if(r)return null;const a=function(e){const t=e.length,n=[],s=new Array(t).fill(-1);for(let o=0;o<t;o++){const t=e[o];let r=0,a=n.length;for(;r<a;){const s=r+a>>1;e[n[s]]<t?r=s+1:a=s}r>0&&(s[o]=n[r-1]),n[r]=o}const o=[];let r=n.length>0?n[n.length-1]:-1;for(;r>=0;)o.push(r),r=s[r];return o.reverse(),o}(s),i=new Set;for(const e of a)i.add(n[e]);return i}const Rt=new WeakMap;function jt(e){return Rt.get(e)}function Ft(e,t){const n=function(e){let t=null;return t=Rt.get(e)||null,null===t&&(t=new Set,Rt.set(e,t)),t}(e);n.add(t)}function Bt(e,t){const n=Rt.get(e);void 0!==n&&n.delete(t)}const zt=new WeakMap;function qt(e){return zt.get(e)??[]}function Ut(e,t){zt.set(e,t)}const Ht=new WeakMap;function Vt(e){return Ht.get(e)??[]}function Gt(e,t){Ht.set(e,t)}function Jt(e,t){const n=Vt(e);for(const e of n)ve(e,t)}function Yt(e,t,n){Jt(e,t);const s=qt(e);for(const e of s){Ft(mt(e),e),Dn(e,n)}}function Kt(e){if(!e.mounted)return;const t=qt(e);for(const e of t){Bt(mt(e),e)}!function(e){const t=Vt(e);for(const e of t)ve(e,null)}(e)}const Xt=new WeakMap,Qt=Object.freeze(new Set);function Zt(e,t){const n=Xt.get(e);n?n.add(t):Xt.set(e,new Set([t]))}function en(e){const t=Xt.get(e);return void 0!==t?t:Qt}const tn=new WeakMap;function nn(e){tn.delete(e)}const sn=new Set(["if","elseif","else","for"]);class on{_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=qt(this);for(const t of e){if(sn.has(t.bindingType)){const e=en(t.node);for(const t of e)t.unmount()}nn(t),gt(t)}this._mounted=!1}}function rn(e){const t=document.createDocumentFragment(),n=new on(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 an(e){void 0!==e.uuid&&null!==e.uuid||a("BindingInfo.uuid is null.");const t=Ts(e.uuid);t||a(`Fragment with UUID "${e.uuid}" not found.`);const n=document.importNode(t.fragment,!0),s=function(e,t){const[n,s]=function(e,t){const n=[],s=[];for(const o of t){const t=F(e,o.nodePath);if(null===t&&a(`Node not found by path [${o.nodePath.join(", ")}] in fragment.`),pe.has(t))continue;const r=he(t,o.parseBindTextResults,{allowDeferred:!1});s.push(...r.bindings),n.push(t)}return[n,s]}(e,t);return Vn(s),{nodes:n,bindingInfos:s}}(n,t.nodeInfos),o=new on(n);Ut(o,s.bindingInfos);const r=[];for(const e of s.bindingInfos)e.statePathName in b&&r.push(e);return At(o,r),Gt(o,s.nodes),Zt(e.node,o),o}const cn=new WeakMap,ln=new WeakMap,dn=new WeakMap,un=new WeakMap;function fn(e,t,n){yn(e,t,n)}function pn(e,t){cn.set(e,t)}function hn(e){return dn.get(e.node)||[]}function mn(e,t){let n=dn.get(e.node);void 0===n&&(n=[],dn.set(e.node,n)),n.length<1e3?n.push(t):function(e,t){const n=Xt.get(e);n&&(n.delete(t),0===n.size&&Xt.delete(e))}(e.node,t)}function gn(e,t){if(null===t)return!1;if(e.nextSibling===t)return!0;const n=e.compareDocumentPosition(t);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}function bn(e,t){let n=ln.get(e);if(void 0===n)return null;const s=n.get(t);return void 0===s?null:s}function yn(e,t,n){let s=ln.get(e);if(void 0===s){if(null===n)return;s=new WeakMap,ln.set(e,s)}null===n?s.delete(t):s.set(t,n)}const wn=new WeakMap;function Nn(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function xn(e,n,o){const r=e.node.isConnected,a=Boolean(o);let i;const c=en(e.node);i=0===c.size?an(e):c.values().next().value;const l=t(),d=e.uuid??"",u=e.bindingType;try{if(a||(s.debug&&console.log(`unmount if content : ${Nn(e)}`),Kt(i),i.unmount()),a){if(s.debug&&console.log(`mount if content : ${Nn(e)}`),l){const t=document.createComment(`@@wcs-${u}-start:${d}:${e.statePathName}`);e.node.parentNode.insertBefore(t,e.node.nextSibling),i.mountAfter(t);const n=document.createComment(`@@wcs-${u}-end:${d}:${e.statePathName}`),s=i.lastNode??t;s.parentNode.insertBefore(n,s.nextSibling)}else i.mountAfter(e.node);Yt(i,_e(e.node),n)}}finally{wn.set(e.node,r)}}const Sn=new WeakMap;function In(e){return Sn.get(e)??[]}const An=new Set;const _n={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"),s=Number(t);for(let e=0;e<n.length;e++)e===s?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function vn(e,n,o){if(void 0===o)return void(s.debug&&console.debug("Skipped property write: state value is undefined.",{element:e.node,propSegments:e.propSegments,statePathName:e.statePathName}));const r=e.node,a=e.propSegments;if(1===a.length){const e=a[0];if(r[e]!==o){let t=!1;try{r[e]=o,t=!0}catch(t){s.debug&&console.warn(`Failed to set property '${e}' on element.`,{element:r,newValue:o,error:t})}if(t){const t=function(e,t){const n=D(e);if(null===n)return null;const s=customElements.get(n);if(void 0===s)return null;const o=s.wcBindable;if("wc-bindable"!==o?.protocol||1!==o?.version)return null;const r=o.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 s;if("object"==typeof n)try{s=JSON.stringify(n)}catch{s=String(n)}else s=String(n);e.setAttribute(t,s)}(r,t,o)}catch(e){s.debug&&console.warn(`Failed to mirror attribute '${t}' on element.`,{element:r,newValue:o,error:e})}}}if(t()){const t=_n[e];t?t(r,o):(!function(e,t,n){let s=Sn.get(e);s||(s=[],Sn.set(e,s));const o=s.find(e=>e.propName===t);o?o.value=n:s.push({propName:t,value:n})}(r,e,o),i=r,An.add(i))}return}var i;let c=r[a[0]];for(let e=1;e<a.length-1;e++){const t=a[e];if(null==c)return;c=c[t]}const l=c[a[a.length-1]];if(l!==o){if(Object.isFrozen(c))return void(s.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:a,oldValue:l,newValue:o}));try{c[a[a.length-1]]=o}catch(e){s.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:a,oldValue:l,newValue:o,error:e})}}}const Pn=new WeakSet;function $n(e,t,n){const s=e.node,o=e.propSegments;o.length<=1&&a(`Invalid propSegments for web component binding: ${o.join(".")}`);const[r,...i]=o,c=s[r];void 0===c&&a(`Property "${r}" not found on web component.`),c[i.join(".")]=n}function Tn(e,t){const n=function(e){let t=null;if(t=tn.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=pt(e);null===n&&a(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=Ne(e.statePathInfo,n)}else t=Ne(e.statePathInfo,null);return tn.set(e,t),t}(t);if(n.pathInfo.path in b){const e=_e(t.node);return null===e&&a(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&a("ListIndex not found for loopContext:");const n=b[t];void 0===n&&a(`Invalid index name: ${t}`);const s=e.listIndex.at(n);return null===s&&a(`Index not found at position ${n} for loopContext:`),s.index}(e,n.pathInfo.path)}return e[Te](n)}const En=new WeakSet;const Cn={class:function(e,t,n){const s=e.node,o=e.propSegments[1];"boolean"!=typeof n&&a("Invalid value for class application: expected boolean, got "+typeof n),s.classList.toggle(o,n)},attr:function(e,t,n){const s=e.node,o=e.propSegments[1];s.getAttribute(o)!==n&&s.setAttribute(o,n)},style:function(e,t,n){const s=e.propSegments[1],o=e.node.style;o[s]!==n&&(o[s]=n)},command:function(e,t,n){Ie(n)||a("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const s=n,o=xt.get(e);if(o&&o.token===s)return;const r=e.node,i=e.propSegments[1];"string"==typeof i&&0!==i.length||a('command binding requires a method name (e.g., "command.fetch").');const c=function(e){const t=D(e);if(null===t)return null;const n=customElements.get(t);void 0===n&&a(`Custom element <${t}> is not defined for command binding.`);const s=n.wcBindable;return"wc-bindable"===s?.protocol&&1===s?.version?s:null}(r);null===c&&a(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),Array.isArray(c.commands)&&c.commands.some(e=>e.name===i)||a(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),o&&(o.unsubscribe(),xt.delete(e));const l=new WeakRef(r);let d=null;d=s.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return d?.(),void xt.delete(e);const s=n[i];return"function"!=typeof s&&a(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(s,n,t)}),xt.set(e,{token:s,unsubscribe:d,elementRef:l})}},kn={text:function(e,n,s){const o=null==s?"":String(s);if(e.replaceNode.nodeValue!==o&&(e.replaceNode.nodeValue=o),t()&&!Pn.has(e.replaceNode)){Pn.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,s=document.createComment(`@@wcs-text-start:${n}`),o=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(s,e.replaceNode),t.insertBefore(o,e.replaceNode.nextSibling)}}},for:function(e,n,s){const o=e.statePathInfo,r=pt(e),i=mt(e),c=Qe(i),l=Dt(r,c,s);if(n.newListValueByAbsAddress.set(i,Array.isArray(s)?s:[]),Array.isArray(c)&&c.length===l.deleteIndexSet.size&&l.deleteIndexSet.size>0&&null!==e.node.parentNode){let t=un.get(e.node);if(void 0===t){const n=cn.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,s=t.nextSibling,o=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){o=!1;break}n=n.previousSibling}for(;null!==s;){if(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE&&""!==(s.textContent?.trim()??"")){o=!1;break}s=s.nextSibling}return o}(e.node,n),un.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}for(const t of l.deleteIndexSet){const n=bn(e.node,t);null!==n&&(Kt(n),n.unmount(),mn(e,n),yn(e.node,t,null))}let d=e.node;const u=M(o.path+"."+p),f=n.stateElement.loopContextStack,h=Wt(l);let m=null;l.newIndexes.length==l.addIndexSet.size&&l.newIndexes.length>0&&d.isConnected&&(m=document.createDocumentFragment(),ct(m,n.rootNode));const g=t(),b=e.uuid??"";for(const t of l.newIndexes){let s;if(l.addIndexSet.has(t)){const r=Ne(u,t);f.createLoopContext(r,r=>{const a=hn(e);if(s=a.pop(),void 0===s&&(s=an(e)),null!==m)g&&m.appendChild(document.createComment(`@@wcs-for-start:${b}:${o.path}:${t.index}`)),s.appendTo(m),g&&m.appendChild(document.createComment(`@@wcs-for-end:${b}:${o.path}:${t.index}`));else{if(d.nextSibling!==s.firstNode){if(g){const e=document.createComment(`@@wcs-for-start:${b}:${o.path}:${t.index}`);d.parentNode.insertBefore(e,d.nextSibling),d=e}s.mountAfter(d)}if(g){const e=document.createComment(`@@wcs-for-end:${b}:${o.path}:${t.index}`),n=s.lastNode??d;n.parentNode.insertBefore(e,n.nextSibling)}}Yt(s,r,n)}),void 0===s&&a(`Content not found for ListIndex: ${t.index} at path "${o.path}"`)}else{if(s=bn(e.node,t),l.changeIndexSet.has(t)){const e=It(s);for(const t of e)Dn(t,n)}null===s&&a(`Content not found for ListIndex: ${t.index} at path "${o.path}"`);null!==h&&h.has(t)&&gn(d,s.firstNode)||d.nextSibling===s.firstNode||s.mountAfter(d)}d=s.lastNode||d,yn(e.node,t,s)}cn.set(e.node,d),null!==m&&(e.node.parentNode.insertBefore(m,e.node.nextSibling),ct(m,null))},if:xn,else:xn,elseif:xn,radio:function(e,t,n){const s=e.node,o=wt(s.value,e.inFilters);s.checked=n===o},checkbox:function(e,t,n){const s=e.node,o=wt(s.value,e.inFilters),r=Array.isArray(n)?n:Nt;s.checked=r.includes(o)}},Mn=new WeakMap,On=new WeakMap;function Ln(e,t){const n=wt(Tn(t.state,e),e.outFilters);if(!0===On.get(e))return void t.deferredSelectBindings.push({binding:e,value:n});let s=Mn.get(e);if(void 0===s){if(Mn.has(e))return yt(e.replaceNode,t.stateElement)?(s=$n,Mn.set(e,s)):s=vn,void s(e,t,n);if(s=kn[e.bindingType],void 0===s){const n=e.propSegments[0];if(s=Cn[n],Mn.set(e,s),void 0===s){D(e.replaceNode)?yt(e.replaceNode,t.stateElement)?(s=$n,Mn.set(e,s)):s=vn:(s=vn,Mn.set(e,s))}}if(s===vn){if("SELECT"===e.node.tagName){const s=e.propSegments[0];if("value"===s||"selectedIndex"===s)return t.deferredSelectBindings.push({binding:e,value:n}),void On.set(e,!0)}}s(e,t,n)}else s(e,t,n)}function Dn(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=mt(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 n=D(e.replaceNode);if(n&&void 0===customElements.get(n))return void function(e,t){En.has(e)||(En.add(e),customElements.whenDefined(t).then(()=>{En.delete(e),e.replaceNode.isConnected&&Wn([e])}).catch(e=>{console.error(`[@wcstack/state] deferred apply failed for <${t}>.`,e)}))}(e,n);if(!0===t.sameRootVerified&&e.stateName===t.stateName)return void Ln(e,t);let s=e.replaceNode.getRootNode();if(s instanceof DocumentFragment&&!(s instanceof ShadowRoot)&&(s=lt(s),null===s&&a("Root node for fragment not found for binding.")),e.stateName!==t.stateName||s!==t.rootNode){const n=As(s,e.stateName);null===n&&a(`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};Ln(e,r)})}else Ln(e,t)}function Wn(e){let t=0;const n=new Set,o=new Map,r=new Map,i=[];for(;t<e.length;){let c=e[t];const l=c.stateName;if(!1===c.replaceNode.isConnected){s.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${c.bindingType} ${c.statePathName} on ${c.node.nodeName}`,c),t++;continue}let d=c.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=lt(d),null===d&&a("Root node for fragment not found for binding."));const u=As(d,l);null===u&&a(`State element with name "${l}" not found for binding.`),u.createState("readonly",s=>{const a={rootNode:d,stateName:l,stateElement:u,state:s,appliedBindingSet:n,newListValueByAbsAddress:o,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:i,sameRootVerified:!0};for(;;){Dn(c,a),t++;const n=e[t];if(!n)break;const s=n.replaceNode.getRootNode();if(n.stateName!==l||s!==a.rootNode)break;c=n}})}for(const{binding:e,value:t}of i)vn(e,0,t);for(const[e,t]of o.entries())Ze(e,t);for(const[e,t]of r.entries())e.createState("writable",e=>{e[Me](Array.from(t))})}const Rn=new Map,jn=Oe();const Fn=(e,t,n)=>s=>{const o=s.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==o.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===o.checked)return;let r=o.value;for(const e of n)r=e.filterFn(r);const i=As(o.getRootNode(),e);null===i&&a(`State element with name "${e}" not found for two-way binding.`);const c=_e(o);i.createState("writable",e=>{e[$e](c,()=>{e[t]=r})})};function Bn(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 s=Rn.get(n);return void 0===s&&(s=Fn(e.stateName,e.statePathName,e.inFilters),Rn.set(n,s)),e.node.addEventListener(t,s),jn.add(n,e),!0}return!1}const zn=new Map,qn=Oe();const Un=(e,t,n)=>s=>{const o=s.target;if(null===o)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==o.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=o.checked;let i=o.value;for(const e of n)i=e.filterFn(i);const c=As(o.getRootNode(),e);null===c&&a(`State element with name "${e}" not found for two-way binding.`);const l=_e(o);c.createState("writable",e=>{e[$e](l,()=>{let n=e[t];if(Array.isArray(n))if(r)-1===n.indexOf(i)&&(e[t]=n.concat(i));else{const s=n.indexOf(i);-1!==s&&(e[t]=n.toSpliced(s,1))}else e[t]=r?[i]:[]})})};function Hn(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 s=zn.get(n);return void 0===s&&(s=Un(e.stateName,e.statePathName,e.inFilters),zn.set(n,s)),e.node.addEventListener(t,s),qn.add(n,e),!0}return!1}function Vn(e){for(const t of e)u(t),Re(t)||Ue(t)||(Ke(t),Bn(t),Hn(t))}function Gn(e){for(const t of e){Ft(mt(t),t);const e=As(t.replaceNode.getRootNode(),t.stateName);null===e&&a(`State element with name "${t.stateName}" not found for binding.`),"event"!==t.bindingType&&e.setPathInfo(t.statePathName,t.bindingType)}}function Jn(e,t){const[n,s,o]=me(e);for(const e of n)ve(e,t);Vn(s),Gn(s),Wn(s),function(e,t){for(const n of e)customElements.whenDefined(n.tagName).then(()=>{if(!n.node.isConnected)return;const e=ge(n);0!==e.length&&(ve(n.node,t),Vn(e),Gn(e),Wn(e))}).catch(e=>{console.error(`[@wcstack/state] deferred spread failed for <${n.tagName}>.`,e)})}(o,t)}const Yn=/\{\{\s*(.+?)\s*\}\}/g,Kn=new Set(["SCRIPT","STYLE"]);function Xn(e){if(!s.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&&Kn.has(e.parentElement.tagName)||Qn(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 s=n[e];t.content.appendChild(s)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),Xn(t.content)}else Xn(e.content)}function Qn(e){const t=e.data;if(Yn.lastIndex=0,!Yn.test(t))return;Yn.lastIndex=0;const n=document.createDocumentFragment();let s,o=0;for(;null!==(s=Yn.exec(t));){s.index>o&&n.appendChild(document.createTextNode(t.slice(o,s.index)));const e=s[1];n.appendChild(document.createComment(`@@: ${e}`)),o=s.index+s[0].length}o<t.length&&n.appendChild(document.createTextNode(t.slice(o))),e.parentNode.replaceChild(n,e)}let Zn;function es(){if(Zn)return Zn;const e=[],t=Z("not",e)(X);return Zn={filterName:"not",args:e,filterFn:t},Zn}const ts=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function ns(e,t){const n=t+f+p,s=e.indexOf("|"),o=e.indexOf("@");let r,a;if(-1!==s?(r=e.slice(0,s).trim(),a=e.slice(s)):-1!==o?(r=e.slice(0,o).trim(),a=e.slice(o)):(r=e.trim(),a=""),"."===r)r=n;else{if(!r.startsWith("."))return e;r=n+f+r.slice(1)}return a.length>0?r+a:r}function ss(e,t){const n=ts.exec(e);if(null===n)return e;const s=n[1],o=n[2],r=n[3];return s+ns(o,t)+r}function os(e,t){const n=e.split(";");let s=!1;const o=n.map(e=>{const n=e.trim();if(0===n.length)return e;const o=n.indexOf(":");if(-1===o)return e;const r=n.slice(0,o).trim(),a=n.slice(o+1).trim(),i=ns(a,t);return i!==a?(s=!0,`${r}: ${i}`):e});return s?o.join(";"):e}function rs(e,t){return os(e,t)}function as(e,t){const n=s.bindAttributeName,o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;o.nextNode();){const e=o.currentNode;if(e.nodeType===Node.COMMENT_NODE){const n=e;n.data=ss(n.data,t);continue}const s=e;if(s instanceof HTMLTemplateElement)continue;const r=s.getAttribute(n);if(null!==r){const e=os(r,t);e!==r&&s.setAttribute(n,e)}}}function is(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 cs(e){const t=[],n=fe(e);for(const e of n){const n=ue(e);t.push({nodePath:is(e),parseBindTextResults:n})}return t}function ls(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 ds=new Map([["for",s.commentForPrefix],["if",s.commentIfPrefix],["elseif",s.commentElseIfPrefix],["else",s.commentElsePrefix]]),us=es();function fs(e,t){const n=t.outFilters;return{...t,outFilters:[...n,us],bindingType:e}}function ps(e,t,n,s){ls(t),"string"==typeof s&&as(t,s),hs(e,t,s);return{fragment:t,parseBindTextResult:n,nodeInfos:cs(t)}}function hs(e,t,n){const o=s.commentElsePrefix,r=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode(e){const t=e;if("template"===t.tagName.toLowerCase()){if((t.getAttribute(s.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let i=null;const c=[],l=[];for(;r.nextNode();){const e=r.currentNode;l.push(e)}for(const t of l){let r=t.getAttribute(s.bindAttributeName)||"";"string"==typeof n&&(r=rs(r,n));let l=ae(r)[0];const d=ds.get(l.bindingType);if(void 0===d)continue;const u=l.bindingType,f=t.content,p=vt();let h=null;const m="for"===u?l.statePathName:n;if("else"===u){null===i&&a("'else' binding found without preceding 'if' or 'elseif' binding."),l=fs("else",i.parseBindTextResult),h=ps(e,f,l,m),$s(p,e,h);const n=c.at(-1),s=document.createComment(`@@${d}:${p}`);void 0!==n?(t.remove(),n.fragment.appendChild(s),n.nodeInfos.push({nodePath:is(s),parseBindTextResults:ue(s)})):t.replaceWith(s)}else if("elseif"===u){null===i&&a("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=ps(e,f,l,m),$s(p,e,h);const n=document.createComment(`@@${d}:${p}`),s=vt(),r={fragment:document.createDocumentFragment(),parseBindTextResult:fs("else",i.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:is(n),parseBindTextResults:ue(n)}),$s(s,e,r);const u=c.at(-1);c.push(r);const g=document.createComment(`@@${o}:${s}`);void 0!==u?(t.remove(),u.fragment.appendChild(g),u.nodeInfos.push({nodePath:is(g),parseBindTextResults:ue(g)})):t.replaceWith(g)}else{h=ps(e,f,l,m),$s(p,e,h);const n=document.createComment(`@@${d}:${p}`);t.replaceWith(n)}"if"===u?(c.length=0,i=h):"elseif"===u?i=h:"else"===u&&(i=null,c.length=0)}}async function ms(e){const t=e.querySelectorAll(s.tagNames.state),n=[];await customElements.whenDefined(s.tagNames.state);for(const e of t){const t=e;n.push(t.initializePromise)}await Promise.all(n)}async function gs(e){if(e===document)await ms(document),Xn(document),hs(document,document),Jn(document.body,null);else{const t=e;t.host.hasAttribute(s.bindAttributeName)&&await d(t.host),await ms(t),Xn(t),hs(t,t),Jn(t,null)}}const bs=new Set(["for","if","elseif","else"]);function ys(e){if(0===e.length)return{bindingInfos:[],subscriberNodes:[]};const t=e[0].parentNode,n=e[e.length-1].nextSibling,s=document.createElement("div");for(const t of e)s.appendChild(t);const[o,r]=me(s);for(const e of r)u(e),Re(e)||Ue(e)||(Ke(e),Bn(e),Hn(e));if(t)for(;s.firstChild;)t.insertBefore(s.firstChild,n);return{bindingInfos:r,subscriberNodes:o}}function ws(e,t,n){const o={for:s.commentForPrefix,if:s.commentIfPrefix,elseif:s.commentElseIfPrefix,else:s.commentElsePrefix}[t];if(!o)return null;const r=`@@${o}:${n}`,a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;a.nextNode();){const e=a.currentNode;if(e.data===r)return e}return null}function Ns(e,t){const n=e;let o=null;for(const[e,r]of t.templates){let t=ae(r.getAttribute(s.bindAttributeName)||"")[0];const a=t.bindingType;"else"===a&&o?t={...o,outFilters:[...o.outFilters,es()],bindingType:"else"}:"elseif"===a&&o&&(t={...t,stateName:o.stateName}),"if"===a||"elseif"===a?o=t:"else"===a&&(o=null);const i=document.importNode(r.content,!0),c="for"===a?t.statePathName:void 0;ls(i),"string"==typeof c&&as(i,c),hs(n,i,c);$s(e,n,{fragment:i,parseBindTextResult:t,nodeInfos:cs(i)})}}async function xs(e){await ms(e);const t=e.querySelectorAll(s.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.`),Ls.cleanupDom(e),!1}for(const n of t)Ns(e,n);const n=function(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),s=[];for(;n.nextNode();)s.push(n.currentNode);for(const e of s){const n=Cs.exec(e.data);if(!n)continue;const s=n[1],o=n[2],r=o.split(":");let a,i,c=null;"for"===s?(a=r[0],i=r[1],c=parseInt(r[2],10)):(a=r[0],i=r.slice(1).join(":"));const l=[];let d=e.nextSibling;const u=`@@wcs-${s}-end:${o}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)l.push(d),d=d.nextSibling;t.push({type:s,uuid:a,path:i,index:c,nodes:l})}return t}(document.body);!function(e,t){const n=new Map;for(const s of t){if(0===s.nodes.length)continue;const t=rn(s.nodes),{bindingInfos:o,subscriberNodes:r}=ys(s.nodes);for(const e of r)e.nodeType===Node.ELEMENT_NODE&&e.setAttribute("data-wcs-completed","");Ut(t,o),Gt(t,r);const a=[];for(const e of o)e.statePathName in b&&a.push(e);if(At(t,a),"for"===s.type&&null!==s.index){const r=ws(e,"for",s.uuid);if(r){const e=Tt(null,s.index);fn(r,e,t),pn(r,s.nodes[s.nodes.length-1]),Zt(r,t),Jt(t,Ne(M(s.path+"."+p),e));for(const e of o)Ft(mt(e),e);let a=n.get(s.uuid);a||(a=[],n.set(s.uuid,a)),a.push(e)}}else{const n=ws(e,s.type,s.uuid);if(n){Zt(n,t);for(const e of o)Ft(mt(e),e)}}}for(const[t,s]of n){const n=ws(e,"for",t);if(!n)continue;const o=n.getRootNode(),r=Ts(t);if(!r)continue;const a=r.parseBindTextResult.stateName,i=r.parseBindTextResult.statePathName,c=As(o,a);c&&c.createState("readonly",e=>{const t=e[i];Array.isArray(t)&&kt(t,s)})}}(document.body,n),Ls.removeBlockBoundaryComments(document.body);const o=[];for(const e of t)e.parentNode&&(o.push({el:e,parent:e.parentNode,next:e.nextSibling}),e.remove());Ls.restoreTextBindings(document.body);const[i,c]=me(document.body);for(const e of i)if(e.nodeType===Node.ELEMENT_NODE){const t=e;t.hasAttribute("data-wcs-completed")||(ve(e,null),t.setAttribute("data-wcs-completed",""))}else ve(e,null);const l=[],d=[];for(const e of c)if(u(e),!Re(e)&&!Ue(e))if(Ke(e),Bn(e),Hn(e),bs.has(e.bindingType))d.push(e);else{if(e.statePathName.includes(p))continue;l.push(e)}for(const e of[...l,...d]){Ft(mt(e),e);const t=As(e.replaceNode.getRootNode(),e.stateName);null===t&&a(`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=mt(e),n=As(e.replaceNode.getRootNode(),e.stateName);n&&n.createState("readonly",n=>{const s=n[e.statePathName];Array.isArray(s)&&Ze(t,s)})}Wn(l);for(const{el:e,parent:t,next:n}of o)t.insertBefore(e,n);const f=e.querySelectorAll(s.tagNames.ssr);for(const t of f){const n=t.hydrateProps;for(const[t,s]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[e,t]of Object.entries(s))n[e]=t}}const h=e.querySelectorAll("[data-wcs-completed]");for(const e of h)e.removeAttribute("data-wcs-completed");return!0}const Ss=new WeakMap,Is=new WeakMap;function As(e,t){let n=Ss.get(e);return n&&n.get(t)||null}function _s(e){return Is.get(e)??Promise.resolve()}function vs(e,n,o){let r=Ss.get(e);if(null===o){if(!r)return;r.delete(n),0===r.size&&Ss.delete(e),s.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,Ss.set(e,r);const n=!t()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise(t=>{queueMicrotask(async()=>{if(n){await xs(e)||await gs(e)}else await gs(e);t()})});Is.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise(t=>{queueMicrotask(async()=>{await gs(e),t()})});Is.set(e,t)}}r.has(n)&&a(`State element with name "${n}" is already registered.`),r.set(n,o),s.debug&&console.debug(`State element registered: name="${n}"`,o)}}const Ps=new Map;function $s(e,t,n){if(null===n)Ps.delete(e);else{Ps.set(e,n);const s=n.parseBindTextResult,o=As(t,s.stateName);null===o&&a(`State element with name "${s.stateName}" not found for fragment info.`),o.setPathInfo(s.statePathName,s.bindingType);for(const e of n.nodeInfos)for(const n of e.parseBindTextResults){const e=As(t,n.stateName);null===e&&a(`State element with name "${n.stateName}" not found for fragment info node.`),e.setPathInfo(n.statePathName,n.bindingType)}}}function Ts(e){return Ps.get(e)||null}const Es=/^@@wcs-(?:for|if|elseif|else):[^-]/,Cs=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,ks=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,Ms=/^@@wcs-text-start:(.+)$/;function Os(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Ls 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=s.tagNames.ssr,o=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!o)return null;return o.querySelector(`${n}[name="${t}"]`)}static extractStateData(e){const t=e.__state;if(!t||"object"!=typeof t)return{};const n={};for(const[e,s]of Object.entries(t))e.startsWith("$")||"function"==typeof s||(n[e]=s);return n}static buildContent(e,t){const n=document.createElement("script");n.setAttribute("type","application/json"),n.textContent=Os(JSON.stringify(t)),e.appendChild(n);const o=Array.from(Ps.keys());for(const t of o){const n=Ts(t);if(!n)continue;const o=document.createElement("template");o.setAttribute("id",t);const r=n.parseBindTextResult,a="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;o.setAttribute(s.bindAttributeName,a);const i=n.fragment.cloneNode(!0);o.content.appendChild(i),e.appendChild(o)}const r=Array.from(An);if(r.length>0){const t={};for(let e=0;e<r.length;e++){const n=r[e],s=In(n);if(0===s.length)continue;const o=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",o);const a={};for(const e of s)a[e.propName]=e.value;t[o]=a}if(Object.keys(t).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=Os(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;(Cs.test(e.data)||ks.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;Es.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,s=Ms.exec(e.data);s&&n.push({comment:e,path:s[1]})}for(const{comment:e,path:t}of n){const n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let s=e.nextSibling;e.remove();const o=`@@wcs-text-end:${t}`;for(;s;){const e=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===o){s.parentNode.removeChild(s);break}s.parentNode.removeChild(s),s=e}}}static cleanupDom(e){const t=document.body,n=e.querySelectorAll(s.tagNames.ssr),o=new Map;for(const e of n){const t=e.querySelectorAll("template[id]");for(const e of t){const t=e.getAttribute("id");t&&o.set(t,e)}}const r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),a=[];for(;r.nextNode();){const e=r.currentNode;Cs.test(e.data)&&a.push(e)}for(const e of a){const t=Cs.exec(e.data),n=`@@wcs-${t[1]}-end:${t[2]}`;let s=e.nextSibling;for(;s;){const e=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===n){s.remove();break}s.remove(),s=e}e.remove()}Ls.restoreTextBindings(t);const i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),c=[];for(;i.nextNode();){const e=i.currentNode;if(Es.test(e.data)){const t=e.data.split(":")[1];c.push({comment:e,uuid:t})}}for(const{comment:e,uuid:t}of c){const n=o.get(t);if(n){const t=document.createElement("template"),o=n.getAttribute(s.bindAttributeName);o&&t.setAttribute(s.bindAttributeName,o);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 l=e.querySelectorAll("[data-wcs-ssr-id]");for(const e of l)e.removeAttribute("data-wcs-ssr-id");for(const e of n)e.remove()}}async function Ds(e,t){let n=null;const s=`\n//# sourceURL=${t}\n`;if("function"==typeof URL.createObjectURL){const t=new Blob([e.text+s],{type:"application/javascript"}),o=URL.createObjectURL(t);try{n=await import(o)}finally{URL.revokeObjectURL(o)}}else{const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(e.text+s)));n=await import(`data:application/javascript;base64,${t}`)}return n&&"object"==typeof n.default?n.default:{}}async function Ws(e){try{return(await import(e)).default||{}}catch(e){a(`Failed to load script file: ${e}`)}}class Rs{_loopContextStack=Array(h).fill(void 0);_length=0;createLoopContext(e,t){null===e.listIndex&&a("Cannot create loop context for a state address that does not have a list index.");const n=e;this._length>=h&&a("Exceeded maximum loop context stack depth of 128. Possible infinite loop.");const s=this._loopContextStack[this._length-1];if(void 0!==s){s.pathInfo.wildcardCount+1!==n.pathInfo.wildcardCount&&a("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];s.pathInfo!==e&&a("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&&a("Cannot push loop context for a list with wildcard positions when there is no active loop context.");let o;this._loopContextStack[this._length]=n,this._length++;try{o=t(n)}finally{o instanceof Promise?o.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return o}}const js=new WeakMap;function Fs(e,t){let n=js.get(e);void 0===n&&(n=new Map,js.set(e,n));let s=n.get(t);return void 0===s&&(s=new Se(t),n.set(t,s)),s}const Bs=new WeakMap;function zs(e){const t=Bs.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 Fs(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:Fs(e,n)}},set(){a("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){a("$command namespace is read-only; deleting from it is not allowed.")}});return Bs.set(e,n),n}const qs=Symbol("wcs-stream-last-notified-uncertain"),Us=new WeakMap;function Hs(e,t){const n=Us.get(e);if(void 0!==n)for(const e of n.keys())t.has(e)||n.delete(e)}function Vs(e,t){const n=Us.get(e);if(void 0===n)return;const s=n.get(t);void 0!==s&&n.set(t,{status:"idle"===s.status?s.status:qs,error:Object.is(s.error,null)?null:qs})}const Gs=new Set;function Js(e){Gs.delete(e)}function Ys(){return Gs}const Ks=new WeakMap;function Xs(e){return Ks.get(e)??new Map}function Qs(e){Js(e);const t=Ks.get(e);if(void 0!==t)for(const n of t.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,Vs(e,n.name)}const Zs=(e,t)=>t,eo=new Set;function to(e,t){const n=t[P];if(void 0===n)return void Hs(e,eo);"object"==typeof n&&null!==n||a(`${P} must be an object mapping stream names to stream definitions.`);const s=new Map;for(const[o,r]of Object.entries(n)){0===o.length&&a(`${P} entry name must be a non-empty string.`),o.includes(f)&&a(`${P} entry "${o}" must be a flat property name ("${f}" is not allowed).`),o.includes(p)&&a(`${P} entry "${o}" must be a flat property name ("${p}" is not allowed).`),o.startsWith("$")&&a(`${P} entry "${o}" must not start with "$" (reserved namespace).`),o in Object.prototype&&a(`${P} entry "${o}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),e.getterPaths.has(o)&&a(`${P} entry "${o}" conflicts with a getter declared on the state.`),e.setterPaths.has(o)&&a(`${P} entry "${o}" conflicts with a setter declared on the state.`),"object"==typeof r&&null!==r||a(`${P} entry "${o}" must be an object ({ args?, source, fold?, initial? }).`);const n=r;"function"!=typeof n.source&&a(`${P} entry "${o}" source must be a function.`);const i=void 0!==n.fold;i&&"function"!=typeof n.fold&&a(`${P} entry "${o}" fold must be a function.`),i&&!("initial"in n)&&a(`${P} entry "${o}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&a(`${P} entry "${o}" args must be a function.`);const c={name:o,definition:{args:n.args??null,source:n.source,fold:n.fold??Zs,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};o in t||(t[o]=c.definition.initial),s.set(o,c)}!function(e,t){Ks.set(e,t)}(e,s),Hs(e,new Set(s.keys()))}const no=new WeakMap,so=new WeakMap;function oo(e,t,n){return new Proxy(Object.create(null),{get(t,s){if("string"!=typeof s)return;const o=Xs(e).get(s);return void 0!==o?n(o):void 0},has:(t,n)=>"string"==typeof n&&Xs(e).has(n),ownKeys:()=>Array.from(Xs(e).keys()),getOwnPropertyDescriptor(t,s){if("string"!=typeof s)return;const o=Xs(e).get(s);return void 0!==o?{configurable:!0,enumerable:!0,value:n(o)}:void 0},set(){a(`${t} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){a(`${t} namespace is read-only; deleting from it is not allowed.`)}})}function ro(e){const t=no.get(e);if(void 0!==t)return t;const n=oo(e,$,e=>e.status);return no.set(e,n),n}function ao(e){const t=so.get(e);if(void 0!==t)return t;const n=oo(e,T,e=>e.error);return so.set(e,n),n}function io(e){no.delete(e),so.delete(e)}const co=new Set;const lo=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=jt(e);if(void 0!==t)for(const e of t)!1!==e.replaceNode.isConnected&&n.push(e)}Wn(n),function(e){for(const t of co)t(e)}(t)}};function uo(){return lo}let fo=null;async function po(e,t,n,s){let o=null,r=null;const a=()=>{if(o&&o!==r){r=o;try{o.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",a,{once:!0});try{const r=await e(t,n);if(o=function(e,t){if("function"==typeof e?.[Symbol.asyncIterator])return e;if("function"!=typeof e?.getReader)throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).");return async function*(e,t){const n=e.getReader(),s=()=>{n.cancel().catch(()=>{})};t.addEventListener("abort",s,{once:!0});try{for(;;){const{done:e,value:t}=await n.read();if(e)return;yield t}}finally{t.removeEventListener("abort",s),n.releaseLock()}}(e,t)}(r,n)[Symbol.asyncIterator](),n.aborted)return void a();for(;;){const e=await o.next();if(e.done)break;if(n.aborted)return;s.fold(e.value)}if(n.aborted)return;s.done()}catch(e){if(n.aborted)return;s.fail(e)}finally{n.removeEventListener("abort",a)}}function ho(e){const t=Xs(e);if(0!==t.size){!function(e){Gs.add(e)}(e);for(const n of t.values())mo(e,n)}}function mo(e,t){t.controller?.abort();const n=new AbortController;t.controller=n;const s=function(e,t){const n=t.definition.args;if(null===n)return void t.depAddresses.clear();const s=fo,o=new Set;let r;fo=o;try{e.createState("readonly",e=>{r=n(e)})}finally{fo=s}r instanceof Promise&&a(`${P} entry "${t.name}" args must be synchronous (it returned a Promise).`);const i=`${$}${f}${t.name}`,c=`${T}${f}${t.name}`;for(const n of o){const s=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==e||s.path!==t.name&&s.path!==i&&s.path!==c||a(`${P} entry "${t.name}" args must not read the stream itself ("${s.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),s.wildcardCount>0&&a(`${P} entry "${t.name}" args must not read wildcard paths ("${s.path}"): wildcard dependencies are out of scope.`)}return t.depAddresses=o,r}(e,t);e.createState("writable",e=>{e[t.name]=t.definition.initial}),go(e,t,"active",null);const o=t.definition,r={fold(n){e.createState("writable",e=>{e[t.name]=o.fold(e[t.name],n)})},done(){go(e,t,"done",null)},fail(s){go(e,t,"error",s),n.abort()}};po(o.source,s,n.signal,r)}function go(e,t,n,s){t.status=n,t.error=s;const o=function(e,t){return Us.get(e)?.get(t)??{status:"idle",error:null}}(e,t.name),r=o.status!==n,a=!Object.is(o.error,s);(r||a)&&(!function(e,t,n,s){let o=Us.get(e);void 0===o&&(o=new Map,Us.set(e,o)),o.set(t,{status:n,error:s})}(e,t.name,n,s),e.createState("writable",e=>{r&&e.$postUpdate(`${$}${f}${t.name}`),a&&e.$postUpdate(`${T}${f}${t.name}`)}))}var bo;function yo(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 wo(e){return function(t){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[e]=t})})}}function No(e,t){return t?function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let s;return n.createStateAsync("writable",async n=>{s=await n[e](...t)}).then(()=>s)})}:function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let s;return n.createState("writable",n=>{s=n[e](...t)}),s})}}function xo(e){return e.startsWith("$")}bo=function(e){const t=Ys();if(0===t.size)return;const n=[];for(const s of t)for(const t of Xs(s).values())for(const o of t.depAddresses)if(e.has(o)){n.push({stateElement:s,entry:t});break}for(const{stateElement:e,entry:s}of n)if(t.has(e)&&Xs(e).get(s.name)===s)try{mo(e,s)}catch(n){s.controller?.abort(),t.has(e)&&Xs(e).get(s.name)===s&&go(e,s,"error",n)}},co.add(bo);const So=new Map;class Io{path;segments;paths;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const t=e.split("."),n=t.slice(),s=[];let o=0,r=0,a="",i=0,c="none";const l=[];for(let e=0;e<t.length;e++){const c=t[e];if("*"===c)n[e]="*",l.push(null),o++,i++;else{const t=Number(c);Number.isNaN(t)||(n[e]="*",l.push(t),r++,i++)}a+=c,s.push(a),a+=e<c.length-1?".":""}const d=M(n.join("."));(o>0||r>0)&&(c=o===i?"context":r===i?"all":"partial"),this.path=e,this.segments=t,this.paths=s,this.wildcardCount=i,this.wildcardType=c,this.wildcardIndexes=l,this.pathInfo=d}}function Ao(e){let t;return So.get(e)??(So.set(e,t=new Io(e)),t)}const _o=new WeakMap;function vo(e,t){null===t?_o.delete(e):_o.set(e,t)}function Po(e){const t=_o.get(e);t&&(t.dirty=!0)}function $o(e,t){let n=e;for(let e=1;e<t.length;e++){if(Object(n)!==n)return;n=Reflect.get(n,t[e])}return n}function To(e,t,n,s,o){const r=t.pathInfo.segments[0];if(r===A)return $o(zs(o),t.pathInfo.segments);if(r===$)return $o(ro(o),t.pathInfo.segments);if(r===T)return $o(ao(o),t.pathInfo.segments);if(!(t.pathInfo.path in e)){const o=Co(e,t.parentAddress??a(`address.parentAddress is undefined path: ${t.pathInfo.path}`),n,s),r=t.pathInfo.segments[t.pathInfo.segments.length-1];if(r===p){const e=t.listIndex?.index??a(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.get(o,e)}return Reflect.get(o,r)}if(!o.getterPaths.has(t.pathInfo.path))return Reflect.get(e,t.pathInfo.path);s.pushAddress(t);try{return Reflect.get(e,t.pathInfo.path,n)}finally{s.popAddress()}}function Eo(e,t,n,s,o){const r=at(tt(o,t.pathInfo),t.listIndex),a=function(e){return _o.get(e)??null}(r);if(null!==a&&!1===a.dirty)return a.value;const i=To(e,t,n,s,o);return vo(r,{value:i,dirty:!1}),i}function Co(e,t,n,s){!function(e,t){if(e.addressStackLength>0){const n=e.lastAddressStack,s=n?.pathInfo??null,o=e.stateElement;if(null!==s&&o.getterPaths.has(s.path)&&s.path!==t.pathInfo.path&&(o.addDynamicDependency(t.pathInfo.path,s.path),t.pathInfo.wildcardCount>0&&s.wildcardCount>0)){const e=ut(t.pathInfo,s);if(e>0){let s=!1;for(let o=0;o<e;o++)if(t.listIndex?.at(o)!==n.listIndex?.at(o)){s=!0;break}if(s)for(let n=0;n<e;n++)o.addCrossRowListPath?.(t.pathInfo.wildcardParentPaths[n])}}}}(s,t),function(e,t){if(null===fo)return;const n=tt(e,t.pathInfo);fo.add(at(n,t.listIndex))}(s.stateElement,t);const o=s.stateElement;return t.pathInfo.wildcardCount>0||o.getterPaths.has(t.pathInfo.path)?Eo(e,t,n,s,o):To(e,t,n,s,o)}function ko(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[t];return void 0===s?null:n.listIndex?.at(s)??null}const Mo=new WeakMap;function Oo(e,t){null===t?Mo.delete(e):Mo.set(e,t)}function Lo(e,t,n){const o=M(e.wildcardParentPaths[t]),r=tt(e.stateElement,o),a=Ne(o,n),i=Qe(at(r,n)),c=e.stateProxy[Te](a),l=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 s.debug&&console.log(`Invalid search type: ${t}`),[]}}(Dt(a.listIndex,i,c),e.searchType);if(t===e.wildcardPaths.length-1)e.targetListIndexes.push(...l);else for(const n of l)Lo(e,t+1,n)}function Do(e,t,n,s,o){return"full"===e.listExpansion||e.stateElement.crossRowListPaths?.has(t)?o.newIndexes:0===o.addIndexSet.size&&0===o.changeIndexSet.size?0===o.deleteIndexSet.size?o.newIndexes:o.changeIndexSet:0===o.addIndexSet.size?o.changeIndexSet:0===o.changeIndexSet.size?o.addIndexSet:[...o.addIndexSet,...o.changeIndexSet]}function Wo(e,t,n,s,o,r,i,c,l,d){const u={stateElement:t,staticMap:s,dynamicMap:o,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:c,listExpansion:d?.listExpansion??"full"};return function(e,t,n){const s=[{address:t,depth:0}];for(;s.length>0;){const{address:t,depth:o}=s.pop();if(o>1e3&&a(`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,i=o+1,c=[],l=e.staticMap.get(r);if(l)for(const n of l){const s=M(n);if(e.listPathSet.has(r)&&s.lastSegment===p){const n=e.stateProxy[Te](t),o=Qe(at(tt(e.stateElement,t.pathInfo),t.listIndex)),a=Dt(t.listIndex,o,n);for(const t of Do(e,r,0,0,a)){const n=Ne(s,t);e.result.add(n),c.push({address:n,depth:i})}}else{const n=Ne(s,t.listIndex);e.result.add(n),c.push({address:n,depth:i})}}const d=e.dynamicMap.get(r);if(d)for(const n of d){const s=M(n),o=[];if(s.wildcardCount>0){const n=ut(t.pathInfo,s);if(s.wildcardCount-n>=1){let r;n>0?(null===t.listIndex&&a(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`),r=t.listIndex.at(n-1)):r=null;const i={stateElement:e.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};Lo(i,n,r),o.push(...i.targetListIndexes)}else{null===t.listIndex&&a(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`);const e=t.listIndex.at(n-1);o.push(e)}}else o.push(null);for(const t of o){const n=Ne(s,t);e.result.add(n),c.push({address:n,depth:i})}}for(let e=c.length-1;e>=0;e--)s.push(c[e])}}(u,n,l),Array.from(u.result)}function Ro(e,t,n,s,o,r){try{if(!(t.pathInfo.path in e)){const n=Co(e,t.parentAddress??a(`address.parentAddress is undefined path: ${t.pathInfo.path}`),o,r),i=t.pathInfo.segments[t.pathInfo.segments.length-1];if(i===p){const e=t.listIndex?.index??a(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.set(n,e,s)}return Reflect.set(n,i,s)}if(!r.stateElement.setterPaths.has(t.pathInfo.path))return Reflect.set(e,t.pathInfo.path,s);r.pushAddress(t);try{return Reflect.set(e,t.pathInfo.path,s,o)}finally{r.popAddress()}}finally{const e=uo();e.enqueueAbsoluteAddress(n),Wo(r.stateName,r.stateElement,t,r.stateElement.staticDependency,r.stateElement.dynamicDependency,r.stateElement.listPaths,o,"new",n=>{if(n===t)return;const s=at(tt(r.stateElement,n.pathInfo),n.listIndex);Po(s),e.enqueueAbsoluteAddress(s)},{listExpansion:"diff"})}}function jo(e,t,n,s,o,r){let i=t.parentAddress??a(`address.parentAddress is undefined path: ${t.pathInfo.path}`),c=function(e){return Mo.get(e)??null}(i);if(null===c){const t=Co(e,i,o,r)??[],n=Ct(t)??[];c={value:[...t],listIndexes:[...n]},Oo(i,c)}try{return Ro(e,t,n,s,o,r)}finally{const n=c.value.indexOf(s),a=Co(e,i,o,r)??[],l=Array.isArray(a)?Ct(a)??[]:[],d=t.listIndex.index,u=-1!==n?c.listIndexes[n]:Tt(i.listIndex,-1);l[d]=u;if(new Set(a).size===c.value.length){for(let e=0;e<l.length;e++)l[e].index=e;Oo(i,null)}}}function Fo(e,t,n,o,r){const a=r.stateElement;if(s.sameValueGuard&&(null===n||"object"!=typeof n)){const s=Co(e,t,o,r);if(Object.is(s,n))return!0}const i=a.elementPaths.has(t.pathInfo.path),c=t.pathInfo.wildcardCount>0||a.getterPaths.has(t.pathInfo.path),l=at(tt(a,t.pathInfo),t.listIndex);try{return i?jo(e,t,l,n,o,r):Ro(e,t,l,n,o,r)}finally{c&&vo(l,{value:n,dirty:!1});const e=a.bindableEventMap[t.pathInfo.path];if(e){const t=a.rootNode;t instanceof ShadowRoot&&t.host.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0}))}}}function Bo(e,t,n,s){return(t,o,r)=>{const i=M(t);if(s.addressStackLength>0){const e=s.lastAddressStack?.pathInfo??null,t=s.stateElement;null!==e&&e.path!==i.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(i.path,e.path)}i.wildcardParentPathInfos.length>o.length&&a(`indexes length is insufficient: ${t}`);let c=null;for(let t=0;t<i.wildcardParentPathInfos.length;t++){const r=i.wildcardParentPathInfos[t],l=Ne(r,c),d=Ct(Co(e,l,n,s));null==d&&a(`ListIndexes not found: ${r.path}`);c=d[o[t]]??a(`ListIndex not found: ${r.path}`)}const l=Ne(i,c);if(!(void 0!==r))return Co(e,l,n,s);Fo(e,l,r,n,s)}}const zo=new WeakMap;function qo(e,t,n,s){const o=t.pathInfo;switch(t.wildcardType){case"none":return null;case"context":return ko(s,o.wildcardPaths.at(-1)??a(`lastWildcardPath is null: ${t.pathInfo.path}`))??a(`ListIndex not found: ${t.pathInfo.path}`);case"all":{let o=null;for(let r=0;r<t.pathInfo.wildcardCount;r++){const i=t.pathInfo.wildcardParentPathInfos[r]??a(`wildcardParentPathInfo is null: ${t.pathInfo.path}`);o=(Ct(Co(e,Ne(i,o),n,s))??a(`ListIndex not found: ${i.path}`))[t.wildcardIndexes[r]??a(`wildcardIndex is null: ${t.pathInfo.path}`)]??a(`ListIndex not found: ${i.path}`)}return o}case"partial":a(`Partial wildcard type is not supported yet: ${t.pathInfo.path}`)}}function Uo(e,t,n){void 0!==e.loopContext&&a("already in loop context"),e.setLoopContext(t);try{e.pushAddress(t);try{return n()}finally{e.popAddress()}}finally{e.clearLoopContext()}}const Ho=`${$}${f}`,Vo=`${T}${f}`;function Go(e,t,n,s){const o=b[t];if(void 0!==o){0===s.addressStackLength&&a(`No active state reference to get list index for "${t.toString()}".`);const e=s.lastAddressStack?.listIndex;return e?.indexes[o]??a(`ListIndex not found: ${t.toString()}`)}if("string"==typeof t){if("$"===t[0]){switch(t){case"$stateElement":return s.stateElement;case"$getAll":return(t,o)=>function(e,t,n,s){const o=Bo(e,0,n,s);return(t,r)=>{const i=new Map,c=M(t);if(s.addressStackLength>0){const e=s.lastAddressStack?.pathInfo??null,t=s.stateElement;null!==e&&e.path!==c.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(c.path,e.path)}if(void 0===r){for(let e=0;e<c.wildcardParentPathInfos.length;e++){const t=c.wildcardParentPathInfos[e],n=ko(s,t.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const l=(t,o,r,c,d,u,f)=>{const p=t[o]??null;if(null===p)return void f.push(u);const h=Ne(p,r),m=zo.get(h),g=Co(e,h,n,s),b=Dt(r,m,g).newIndexes,y=c[d]??null;if(i.set(h,g),null===y)for(let e=0;e<b.length;e++){const n=b[e];l(t,o+1,n,c,d+1,u.concat(n.index),f)}else{const e=b[y]??a(`ListIndex not found: ${p.path}`);o+1<t.length?l(t,o+1,e,c,d+1,u.concat(e.index),f):f.push(u.concat(e.index))}},d=[];l(c.wildcardParentPathInfos,0,null,r,0,[],d);const u=[];for(let e=0;e<d.length;e++)u.push(o(c.path,d[e]));for(const[e,t]of i.entries())zo.set(e,t);return u}}(e,0,n,s)(t,o);case"$postUpdate":return t=>function(e,t,n,s){const o=s.stateElement;return t=>{const r=Ao(t),a=qo(e,r,n,s),i=Ne(r.pathInfo,a),c=at(tt(o,i.pathInfo),i.listIndex),l=uo();l.enqueueAbsoluteAddress(c),Wo(s.stateName,s.stateElement,i,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{const t=at(tt(o,e.pathInfo),e.listIndex);Po(t),l.enqueueAbsoluteAddress(t)})}}(e,0,n,s)(t);case"$resolve":return(t,o,r)=>Bo(e,0,n,s)(t,o,r);case"$trackDependency":return e=>function(e,t,n,s){return e=>{0===s.addressStackLength&&a(`No active state reference to track dependency for path "${e}".`);const t=s.lastAddressStack?.pathInfo??a("Internal error: lastAddressStack is null"),n=s.stateElement;s.stateElement.getterPaths.has(t.path)&&t.path!==e&&n.addDynamicDependency(e,t.path)}}(0,0,0,s)(e);case A:return zs(s.stateElement);case $:return ro(s.stateElement);case T:return ao(s.stateElement)}if(!t.startsWith(Ho)&&!t.startsWith(Vo))return}const o=Ao(t),r=qo(e,o,n,s),i=Ne(o.pathInfo,r);return Co(e,i,n,s)}if("symbol"==typeof t){switch(t){case Pe:return(e,t=async()=>{})=>async function(e,t,n){return await Uo(e,t,n)}(s,e,t);case $e:return(e,t=()=>{})=>function(e,t,n){return Uo(e,t,n)}(s,e,t);case Te:return t=>Co(e,t,n,s);case Ee:return(t,o)=>Fo(e,t,o,n,s);case Ce:return()=>async function(e,t,n){const s=Reflect.get(e,y);"function"==typeof s&&await s.call(n)}(e,0,n);case ke:return()=>function(e,t,n){const s=Reflect.get(e,w);"function"==typeof s&&s.call(n)}(e,0,n);case Me:return t=>function(e,t,n,s){const o=Reflect.get(e,N);if("function"==typeof o){const e=new Set,r={};for(const n of t){const t=n.absolutePathInfo.pathInfo;let o;if(o=n.absolutePathInfo.stateName===s.stateName?t.path:t.path+"@"+n.absolutePathInfo.stateName,e.add(o),t.wildcardCount>0){const e=n.listIndex.indexes??[],t=r[o];void 0===t?r[o]=[e]:t.push(e)}}return o.call(n,Array.from(e),r)}}(e,t,n,s)}return Reflect.get(e,t,n)}}class Jo{_stateElement;_stateName;_addressStack=Array(h).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;constructor(e,t,n){this._stateName=t;const s=As(e,this._stateName);null===s&&a(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=s,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&&a("Last address stack is undefined."),e}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(e){this._addressStackIndex++,this._addressStackIndex>=h&&a("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&&a(`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 Go(e,t,n,this)}set(e,t,n,s){return"readonly"===this._mutability&&a(`State "${this._stateName}" is readonly.`),function(e,t,n,s,o){if("string"==typeof t){const r=Ao(t),a=qo(e,r,s,o);return Fo(e,Ne(r.pathInfo,a),n,s,o)}return Reflect.set(e,t,n,s)}(e,t,n,s,this)}has(e,t){return Reflect.has(e,t)}}const Yo=new WeakMap;const Ko=new WeakMap;function Xo(e,t){const n=Ko.get(e);return n?n.get(t)??null:null}const Qo=new WeakMap,Zo=new WeakMap,er=new WeakMap,tr=new WeakMap;function nr(e,t){return{innerAbsPathInfo:tt(e,M(t.propSegments.slice(1).join(f))),outerAbsPathInfo:mt(t).absolutePathInfo}}function sr(e,t){let n=Qo.get(e);if(void 0===n&&(n=new Map,Qo.set(e,n)),n.has(t))return n.get(t);let s=Zo.get(e);void 0===s&&(s=new Map,Zo.set(e,s));const o=er.get(e);if(void 0===o)return null;let r=null;for(const e of o)if(t.pathInfo.cumulativePathInfoSet.has(e.innerAbsPathInfo.pathInfo)){e.innerAbsPathInfo.pathInfo.segments.length===t.pathInfo.segments.length&&a("Duplicate mapping rule for web component."),r=e;break}if(null===r)return null;const i=tr.get(r);void 0===i&&a("Binding not found for primary mapping rule on web component.");const c=t.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),l=M(r.outerAbsPathInfo.pathInfo.segments.concat(c).join(f)),d=As(e.getRootNode(),i.stateName);null===d&&a(`State element with name "${i.stateName}" not found for web component.`);const u=tt(d,l);n.set(t,u),s.set(u,t);return function(e,t){const n=z(e);null===n?q(e,[t]):n.push(t)}(e,{...i,propName:t.pathInfo.path,propSegments:t.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function or(e){return function(e){const t=Object.getPrototypeOf(e),n=Object.create(t),s=Object.getOwnPropertyDescriptors(e);for(const e in s){const t=s[e];!1===t.writable&&(t.writable=!0)}return Object.defineProperties(n,s),n}(e)}class rr{_webComponent;_innerStateElement;constructor(e,t){this._webComponent=e,this._innerStateElement=Xo(e,t)??a("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 s=M(t),o=tt(this._innerStateElement,s),r=sr(this._webComponent,o);if(null!==r){const e=_e(this._webComponent);let t;return r.stateElement.createState("readonly",n=>{n[$e](e,()=>{t=n[r.pathInfo.path];let s=null;null!==e&&null!==e.listIndex&&r.pathInfo.wildcardCount>0&&(s=e.listIndex.at(r.pathInfo.wildcardCount-1));!function(e,t){Yo.set(e,t)}(at(r,s),t)})}),t}if(t in e)return Reflect.get(e,t,n);a(`Property "${t}" not found in inner state: no mapping rule and no local state property.`)}}set(e,t,n,s){if("string"!=typeof t)return Reflect.set(e,t,n,s);{if(this._innerStateElement.setterPaths.has(t)&&t in e)return Reflect.set(e,t,n,s);const o=M(t),r=tt(this._innerStateElement,o),i=sr(this._webComponent,r);if(null!==i){const e=_e(this._webComponent);return i.stateElement.createState("writable",t=>{t[$e](e,()=>{t[i.pathInfo.path]=n})}),!0}if(t in e)return Reflect.set(e,t,n,s);a(`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=M(t),s=tt(this._innerStateElement,n);return null!==sr(this._webComponent,s)||t in e}return Reflect.has(e,t)}}class ar{_innerStateElement;constructor(e,t){this._innerStateElement=Xo(e,t)??a("State element not found for web component.")}get(e,t,n){if("string"==typeof t){const e=M(t),n=at(tt(this._innerStateElement,e),null);return s=n,Yo.get(s)}return Reflect.get(e,t,n);var s}set(e,t,n,s){if("string"==typeof t){const e=M(t),n=tt(this._innerStateElement,e);return this._innerStateElement.createState("readonly",e=>{e.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(e,t,n,s)}}class ir{_innerStateElement;constructor(e,t){this._innerStateElement=Xo(e,t)??a("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,s){return"string"==typeof t?(this._innerStateElement.createState("writable",e=>{e[t]=n}),!0):Reflect.set(e,t,n,s)}}const cr=e=>()=>e;function lr(e,t,n,o){if(function(e,t,n){let s=Ko.get(e);s||(s=new Map,Ko.set(e,s)),s.set(t,n)}(t,n,e),t.hasAttribute(s.bindAttributeName)){const s=(z(t)??[]).filter(e=>e.propSegments[0]===n);!function(e,t,n){if(0===n.length)return;const s=Xo(e,t);null===s&&a("State element not found for web component.");const o=new Map,r=new Map;for(const t of n){const n=nr(s,t);let a=er.get(e);void 0===a?er.set(e,new Set([n])):a.add(n);const i=n.innerAbsPathInfo,c=n.outerAbsPathInfo;tr.set(n,t),o.set(i,c),r.set(c,i)}Qo.set(e,o),Zo.set(e,r)}(t,n,s);const o=function(e,t){const n=new ar(e,t);return new Proxy({},n)}(t,n),r=function(e,t){const n=new rr(e,t),s=Xo(e,t);null===s&&a("State element not found for web component."),null===s.boundComponentStateProp&&a("State element is not bound to any component state prop."),s.boundComponentStateProp in e||a(`State element is not bound to a valid component state prop: ${s.boundComponentStateProp}`);const o=e[s.boundComponentStateProp];return"object"==typeof o&&null!==o||a(`Invalid state object for component state prop: ${s.boundComponentStateProp}`),new Proxy(or(o),n)}(t,n);e.setInitialState(r),Object.defineProperty(t,n,{get:cr(o),enumerable:!0,configurable:!0})}else{e.setInitialState(or(o));const s=function(e,t){const n=new ir(e,t);return new Proxy({},n)}(t,n);Object.defineProperty(t,n,{get:cr(s),enumerable:!0,configurable:!0})}if(function(e,t){let n=bt.get(e);n||(n=new WeakMap,bt.set(e,n)),n.set(t,!0)}(t,e),x in t){const e=t[x];"function"==typeof e?e.call(t,n).catch(e=>{a(`Error in ${x}: ${e instanceof Error?e.message:String(e)}`)}):a(`${x} is not a function.`)}}function dr(e){const t=new Set,n=new Set,s=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,o]of Object.entries(s))"function"==typeof o.get&&t.add(e),"function"==typeof o.set&&n.add(e);return{getterPaths:t,setterPaths:n}}class ur extends HTMLElement{static hasConnectedCallbackPromise=!0;static getBindingsReady(e){return _s(e)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_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 Rs}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_dcc=!1;_connectGeneration=0;_streamsStartedGeneration=0;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&&a(`${s.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(e){const t=new Set,n=e[I];if(void 0===n)return t;Array.isArray(n)||a(`${I} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||a(`${I} entries must be non-empty strings.`),e===A&&a(`${I} entry "${e}" conflicts with the reserved namespace name "${A}".`),t.has(e)&&a(`${I} entry "${e}" is duplicated.`),t.add(e);return t}(e),this._eventTokenNames=function(e){const t=new Set,n=e[_];if(void 0===n)return t;Array.isArray(n)||a(`${_} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||a(`${_} entries must be non-empty strings.`),t.has(e)&&a(`${_} entry "${e}" is duplicated.`),t.add(e);return t}(e),this.__state=e,this._hasUpdatedCallback=N in e,ze(this),function(e,t,n){const s=t[v];if(void 0!==s){"object"==typeof s&&null!==s||a(`${v} must be an object mapping event-token names to handler functions.`);for(const[t,o]of Object.entries(s))n.has(t)||a(`${v} entry "${t}" is not declared in $eventTokens.`),"function"!=typeof o&&a(`${v} entry "${t}" must be a function.`),Be(e,t).subscribe(o)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const n=dr(e);for(const e of n.getterPaths)this._getterPaths.add(e);for(const e of n.setterPaths)this._setterPaths.add(e);var s;io(this),Qs(s=this),Js(s),Ks.delete(s),to(this,e),this._initialized&&null!==this._rootNode&&!t()&&(ho(this),this._streamsStartedGeneration=this._connectGeneration),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=Ls.findByName(t,e);if(!n)return null;const s=n.stateData;return Object.keys(s).length>0?s: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){a("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||a(`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 Ws(e):a(`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 Ds(e,`${this._name}`);else{const e=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${s.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(e)}}}catch(e){a(`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",vs(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?D(t):null;null!==t&&null!==n||a(`"bind-component" requires <${s.tagNames.state}> to be a direct child of a custom element.`),e instanceof ShadowRoot||this.hasAttribute("name")||a('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const o=this.getAttribute("bind-component");await customElements.whenDefined(n.toLowerCase()),t.hasAttribute(s.bindAttributeName)&&await d(t),o in t||a(`Component does not have property "${o}" for state binding.`);const r=t[o];"object"==typeof r&&null!==r||a(`Component property "${o}" is not an object for state binding.`),this._boundComponent=t,this._boundComponentStateProp=o,lr(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async e=>{y in e&&await e[Ce]()})}async _initializeDCC(e,t){let n;try{if(this.hasAttribute("src")){const e=this.getAttribute("src");e.endsWith(".js")?n=await Ws(e):a(`DCC: Unsupported src type: ${e}`)}else{const t=this.querySelector('script[type="module"]');t?n=await Ds(t,e.tagName.toLowerCase()):a(`DCC: No state source found for "${e.tagName.toLowerCase()}".`)}}catch(e){a(`DCC: Failed to load state: ${e}`)}!function(e,t,n){const o=e.tagName.toLowerCase();if(o.includes("-")||a(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`),customElements.get(o))return void console.warn(`[@wcstack/state] DCC: "${o}" is already registered. Skipping redefinition.`);const r=document.createElement("template");r.innerHTML=t.innerHTML;const i=t.mode,c=Array.isArray(n[S])?n[S]:[],l=c.length>0?function(e,t){return{protocol:"wc-bindable",version:1,properties:t.map(t=>({name:t,event:`${e}:${t}-changed`}))}}(o,c):null,d=c.length>0?function(e,t){const n={};for(const s of t)n[s]=`${e}:${s}-changed`;return n}(o,c):{},u=`${s.tagNames.state}:not([name])`,f=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=l;static bindableEventMap=d;_shadow=null;connectedCallback(){if(!this.hasAttribute(E)&&(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(xo(e))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof t.value){const s="AsyncFunction"===t.value.constructor?.name;n.value=No(e,s)}else n.get=yo(e),n.set=wo(e);Object.defineProperty(f.prototype,e,n)}customElements.define(o,f)}(e,t,n),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",e=>{w in e&&e[ke]()})}async connectedCallback(){this._rootNode=this.getRootNode();const e=++this._connectGeneration;if(this._initialized)this._dcc||As(this._rootNode,this._name)===this||vs(this._rootNode,this._name,this);else{const e=this.parentNode;if(e instanceof ShadowRoot&&e.host.hasAttribute(E))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 _s(this.rootNode);const e=this.getAttribute("name")||"default",t=Ls.extractStateData(this),n=document.createElement(s.tagNames.ssr);n.setAttribute("name",e),n.setAttribute("version",r),Ls.buildContent(n,t),this.parentNode?.insertBefore(n,this)}t()||null===this._rootNode||e!==this._connectGeneration||this._streamsStartedGeneration===e||ho(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{vs(this.rootNode,this._name,null),e=this,js.delete(e),function(e){Bs.delete(e)}(this),ze(this),Qs(this),io(this),this._rootNode=null}var e}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&&a("State rootNode is not available."),this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(e){this._bindableEventMap=e}_addDependency(e,t,n){const s=e.get(t);return void 0===s?(e.set(t,[n]),!0):!s.includes(n)&&(s.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=M(e);if(this._pathSet.add(e),null!==t.parentPath){let e=t;for(;null!==e.parentPath&&this.addStaticDependency(e.parentPath,e.path);)e=M(e.parentPath)}}}_createState(e,t,n){try{const s=function(e,t,n,s){const o=new Jo(e,n,s);return new Proxy(t,o)}(e,this._state,this._name,t);return n(s)}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}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(e){this._crossRowListPaths.add(e)}bindProperty(e,t){Object.defineProperty(this._state,e,t),e===N&&(this._hasUpdatedCallback=!0)}setInitialState(e){this._initialized?this._state=e:this._resolveSetState?.(e)}}function fr(){customElements.get(s.tagNames.ssr)||customElements.define(s.tagNames.ssr,Ls),customElements.get(s.tagNames.state)||customElements.define(s.tagNames.state,ur)}function pr(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),"boolean"==typeof t.sameValueGuard&&(n.sameValueGuard=t.sameValueGuard)),fr()}function hr(e){return e}const mr={eq:{description:"等しいか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},ne:{description:"異なるか比較",hasArgs:!0,resultType:"boolean",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},not:{description:"ブール値を反転",hasArgs:!1,resultType:"boolean",acceptTypes:["boolean"],minArgs:0,maxArgs:0},lt:{description:"より小さいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},le:{description:"以下か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},gt:{description:"より大きいか",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},ge:{description:"以上か",hasArgs:!0,resultType:"boolean",acceptTypes:["number","string"],minArgs:1,maxArgs:1,argTypes:["number"]},inc:{description:"加算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},dec:{description:"減算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},mul:{description:"乗算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},div:{description:"除算",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},mod:{description:"剰余",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:1,maxArgs:1,argTypes:["number"]},fix:{description:"固定小数点表記",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},locale:{description:"ロケール形式で数値フォーマット",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["string"]},uc:{description:"大文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},lc:{description:"小文字に変換",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},cap:{description:"先頭文字を大文字に",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},trim:{description:"前後の空白を削除",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},slice:{description:"部分文字列 (start[,end])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},substr:{description:"部分文字列 (pos,len)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","number"]},pad:{description:"パディング (length[,char])",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:2,argTypes:["number","string"]},rep:{description:"繰り返し (count)",hasArgs:!0,resultType:"string",acceptTypes:["string"],minArgs:1,maxArgs:1,argTypes:["number"]},rev:{description:"文字順を反転",hasArgs:!1,resultType:"string",acceptTypes:["string"],minArgs:0,maxArgs:0},int:{description:"整数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},float:{description:"浮動小数点数にパース",hasArgs:!1,resultType:"number",acceptTypes:["string","number"],minArgs:0,maxArgs:0},round:{description:"四捨五入",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},floor:{description:"切り下げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},ceil:{description:"切り上げ",hasArgs:!0,resultType:"number",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},percent:{description:"パーセンテージ形式",hasArgs:!0,resultType:"string",acceptTypes:["number"],minArgs:0,maxArgs:1,argTypes:["number"]},date:{description:"ロケール形式の日付",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},time:{description:"ロケール形式の時刻",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},datetime:{description:"ロケール形式の日時",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},ymd:{description:"YYYY-MM-DD 形式",hasArgs:!0,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:1,argTypes:["string"]},falsy:{description:"偽値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},truthy:{description:"真値か判定",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},defaults:{description:"偽値の場合デフォルト値",hasArgs:!0,resultType:"passthrough",acceptTypes:"any",minArgs:1,maxArgs:1,argTypes:["any"]},boolean:{description:"ブール値に変換",hasArgs:!1,resultType:"boolean",acceptTypes:"any",minArgs:0,maxArgs:0},number:{description:"数値に変換",hasArgs:!1,resultType:"number",acceptTypes:"any",minArgs:0,maxArgs:0},string:{description:"文字列に変換",hasArgs:!1,resultType:"string",acceptTypes:"any",minArgs:0,maxArgs:0},null:{description:"空文字列をnullに変換",hasArgs:!1,resultType:"passthrough",acceptTypes:["string"],minArgs:0,maxArgs:0}},gr=1;function br(){return{version:1,syntax:{bindAttribute:s.bindAttributeName,tagName:s.tagNames.state,pathDelimiter:f,wildcard:p,delimiters:{binding:";",propValue:":",modifier:"#",stateName:"@",filter:m},structuralDirectives:Array.from(U)},filters:Object.keys(X),filterMeta:mr,reservedLifecycle:[y,w,N,x],reservedStateApi:[S,I,A,_,v]}}export{Ls as Ssr,r as VERSION,gr as WCS_MANIFEST_VERSION,pr as bootstrapState,gs as buildBindings,mr as builtinFilterMeta,hr as defineState,_s as getBindingsReady,o as getConfig,br as getWcsManifest};
|
|
2
2
|
//# sourceMappingURL=index.esm.min.js.map
|